From 8fc42f12f04f8c487eda91adb87e04f200774d86 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 16 May 2016 12:52:50 +0200 Subject: [PATCH] videosink: ensure the debug category is always initialized gst_video_sink_center_rect() can be called without a GstVideoSink having been instantiated so we can't relly on the video sink class_init function to init the category. Fix a warning when running: GST_CHECKS=test_video_center_rect GST_DEBUG=6 G_DEBUG=fatal_warnings make libs/video.check-norepeat https://bugzilla.gnome.org/show_bug.cgi?id=766510 --- gst-libs/gst/video/gstvideosink.c | 56 ++++++++++++------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/gst-libs/gst/video/gstvideosink.c b/gst-libs/gst/video/gstvideosink.c index 26b7df21c3..1b22cb2d73 100644 --- a/gst-libs/gst/video/gstvideosink.c +++ b/gst-libs/gst/video/gstvideosink.c @@ -40,6 +40,8 @@ #include "gstvideosink.h" +G_DEFINE_TYPE (GstVideoSink, gst_video_sink, GST_TYPE_BASE_SINK); + enum { PROP_SHOW_PREROLL_FRAME = 1 @@ -52,8 +54,25 @@ struct _GstVideoSinkPrivate gboolean show_preroll_frame; /* ATOMIC */ }; -GST_DEBUG_CATEGORY_STATIC (video_sink_debug); -#define GST_CAT_DEFAULT video_sink_debug +#ifndef GST_DISABLE_GST_DEBUG +#define GST_CAT_DEFAULT gst_video_sink_ensure_debug_category() + +static GstDebugCategory * +gst_video_sink_ensure_debug_category (void) +{ + static gsize cat_gonce = 0; + + if (g_once_init_enter (&cat_gonce)) { + GstDebugCategory *cat = NULL; + + GST_DEBUG_CATEGORY_INIT (cat, "videosink", 0, "GstVideoSink"); + + g_once_init_leave (&cat_gonce, (gsize) cat); + } + + return (GstDebugCategory *) cat_gonce; +} +#endif /* GST_DISABLE_GST_DEBUG */ static GstBaseSinkClass *parent_class = NULL; @@ -163,12 +182,6 @@ gst_video_sink_class_init (GstVideoSinkClass * klass) g_type_class_add_private (klass, sizeof (GstVideoSinkPrivate)); } -static void -gst_video_sink_base_init (gpointer g_class) -{ - GST_DEBUG_CATEGORY_INIT (video_sink_debug, "videosink", 0, "GstVideoSink"); -} - static GstFlowReturn gst_video_sink_show_preroll_frame (GstBaseSink * bsink, GstBuffer * buf) { @@ -257,30 +270,3 @@ gst_video_sink_get_property (GObject * object, guint prop_id, break; } } - -/* Public methods */ - -GType -gst_video_sink_get_type (void) -{ - static GType videosink_type = 0; - - if (!videosink_type) { - static const GTypeInfo videosink_info = { - sizeof (GstVideoSinkClass), - gst_video_sink_base_init, - NULL, - (GClassInitFunc) gst_video_sink_class_init, - NULL, - NULL, - sizeof (GstVideoSink), - 0, - (GInstanceInitFunc) gst_video_sink_init, - }; - - videosink_type = g_type_register_static (GST_TYPE_BASE_SINK, - "GstVideoSink", &videosink_info, 0); - } - - return videosink_type; -}