debug: Instantiate GType when dumping debug categories.
authorJan Schmidt <jan@centricular.com>
Fri, 1 Apr 2016 14:05:39 +0000 (01:05 +1100)
committerJan Schmidt <jan@centricular.com>
Fri, 13 May 2016 08:05:39 +0000 (18:05 +1000)
A lot of debug categories are declared in element class_init
functions, which don't get run until the element is first created
(not just registered in the plugin load function). This means
that --gst-debug-help doesn't print out a lot of categories.

Creating an instance of each element from the element factory
makes them visible, at some extra cost - 2-3 times longer, which can
be a full second or two of extra waiting. Yikes!

https://bugzilla.gnome.org/show_bug.cgi?id=741001

gst/gst.c

index 43abeb1..d508390 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -763,8 +763,41 @@ gst_debug_help (void)
   /* FIXME this is gross.  why don't debug have categories PluginFeatures? */
   for (g = list2; g; g = g_list_next (g)) {
     GstPlugin *plugin = GST_PLUGIN_CAST (g->data);
+    GList *features, *orig_features;
+
+    if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED))
+      continue;
 
     gst_plugin_load (plugin);
+    /* Now create one of each feature so the class_init functions
+     * are called, as that's where most debug categories are
+     * registered. FIXME: If debug categories were a plugin feature,
+     * this would be unneeded */
+    orig_features = features =
+        gst_registry_get_feature_list_by_plugin (gst_registry_get (),
+        gst_plugin_get_name (plugin));
+    while (features) {
+      GstPluginFeature *feature;
+
+      if (G_UNLIKELY (features->data == NULL))
+        goto next;
+
+      feature = GST_PLUGIN_FEATURE (features->data);
+      if (GST_IS_ELEMENT_FACTORY (feature)) {
+        GstElementFactory *factory;
+        GstElement *e;
+
+        factory = GST_ELEMENT_FACTORY (feature);
+        e = gst_element_factory_create (factory, NULL);
+        if (e)
+          gst_object_unref (e);
+      }
+
+    next:
+      features = g_list_next (features);
+    }
+
+    gst_plugin_feature_list_free (orig_features);
   }
   g_list_free (list2);