ges: Hide internal debug category behind a GOnce
authorSebastian Dröge <sebastian@centricular.com>
Tue, 1 Oct 2019 15:02:27 +0000 (18:02 +0300)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 4 Oct 2019 23:23:03 +0000 (00:23 +0100)
Otherwise it might be used (e.g. by the plugin loader via the GES
plugin!) before ges_init() is called.

ges/ges-internal.h
ges/ges.c

index e0c4eda..cc99998 100644 (file)
 
 G_BEGIN_DECLS
 
-GST_DEBUG_CATEGORY_EXTERN (_ges_debug);
 #ifndef GST_CAT_DEFAULT
-#define GST_CAT_DEFAULT _ges_debug
+#define GST_CAT_DEFAULT (_ges_debug ())
 #endif
 
+G_GNUC_INTERNAL
+GstDebugCategory * _ges_debug (void);
+
 /*  The first 2 NLE priorities are used for:
  *    0- The Mixing element
  *    1- The Gaps
index 7b48c32..ac89662 100644 (file)
--- a/ges/ges.c
+++ b/ges/ges.c
@@ -43,7 +43,7 @@
 #define GES_GNONLIN_VERSION_NEEDED_MINOR 2
 #define GES_GNONLIN_VERSION_NEEDED_MICRO 0
 
-GST_DEBUG_CATEGORY (_ges_debug);
+GST_DEBUG_CATEGORY (_ges_debug_category);
 
 G_LOCK_DEFINE_STATIC (init_lock);
 
@@ -52,6 +52,35 @@ G_LOCK_DEFINE_STATIC (init_lock);
  */
 static GThread *initialized_thread = NULL;
 
+#ifndef GST_DISABLE_GST_DEBUG
+static gpointer
+init_debug_category (gpointer data)
+{
+  /* initialize debugging category */
+  GST_DEBUG_CATEGORY_INIT (_ges_debug_category, "ges", GST_DEBUG_FG_YELLOW,
+      "GStreamer Editing Services");
+
+  return _ges_debug_category;
+}
+
+GstDebugCategory *
+_ges_debug (void)
+{
+  static GOnce my_once = G_ONCE_INIT;
+
+  g_once (&my_once, init_debug_category, NULL);
+
+  return my_once.retval;
+}
+#else
+GstDebugCategory *
+_ges_debug (void)
+{
+  return NULL;
+}
+
+#endif
+
 static gboolean
 ges_init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
     GError ** error)
@@ -61,10 +90,6 @@ ges_init_pre (GOptionContext * context, GOptionGroup * group, gpointer data,
     return TRUE;
   }
 
-  /* initialize debugging category */
-  GST_DEBUG_CATEGORY_INIT (_ges_debug, "ges", GST_DEBUG_FG_YELLOW,
-      "GStreamer Editing Services");
-
   return TRUE;
 }