gst-inspect: simplify the code for printing feature info
authorStefan Sauer <ensonic@users.sf.net>
Fri, 20 Oct 2017 09:08:14 +0000 (11:08 +0200)
committerStefan Sauer <ensonic@users.sf.net>
Fri, 20 Oct 2017 09:11:37 +0000 (11:11 +0200)
Rename print_element_features() to print_feature_info() and move the code that
handles the ElementFactory there. This simplifies the calling code and improves
readability.

Also don't leak the features for other factories.

tools/gst-inspect.c

index 6640b62..43fa9e0 100644 (file)
@@ -1269,21 +1269,31 @@ print_plugin_features (GstPlugin * plugin)
 }
 
 static int
-print_element_features (const gchar * element_name)
+print_feature_info (const gchar * feature_name, gboolean print_all)
 {
   GstPluginFeature *feature;
+  GstRegistry *registry = gst_registry_get ();
 
+  feature = gst_registry_find_feature (registry, feature_name,
+      GST_TYPE_ELEMENT_FACTORY);
+  if (feature) {
+    int ret = print_element_info (GST_ELEMENT_FACTORY (feature), print_all);
+    gst_object_unref (feature);
+    return ret;
+  }
   /* FIXME implement other pretty print function for these */
-  feature = gst_registry_find_feature (gst_registry_get (), element_name,
+  feature = gst_registry_find_feature (registry, feature_name,
       GST_TYPE_TYPE_FIND_FACTORY);
   if (feature) {
-    n_print ("%s: a typefind function\n", element_name);
+    n_print ("%s: a typefind function\n", feature_name);
+    gst_object_unref (feature);
     return 0;
   }
-  feature = gst_registry_find_feature (gst_registry_get (), element_name,
+  feature = gst_registry_find_feature (registry, feature_name,
       GST_TYPE_TRACER_FACTORY);
   if (feature) {
-    n_print ("%s: a tracer module\n", element_name);
+    n_print ("%s: a tracer module\n", feature_name);
+    gst_object_unref (feature);
     return 0;
   }
 
@@ -1636,28 +1646,16 @@ main (int argc, char *argv[])
     }
   } else {
     /* else we try to get a factory */
-    GstElementFactory *factory;
-    GstPlugin *plugin;
     const char *arg = argv[argc - 1];
-    int retval;
+    int retval = -1;
 
     if (!plugin_name) {
-      factory = gst_element_factory_find (arg);
-
-      /* if there's a factory, print out the info */
-      if (factory) {
-        retval = print_element_info (factory, print_all);
-        gst_object_unref (factory);
-      } else {
-        retval = print_element_features (arg);
-      }
-    } else {
-      retval = -1;
+      retval = print_feature_info (arg, print_all);
     }
 
     /* otherwise check if it's a plugin */
     if (retval) {
-      plugin = gst_registry_find_plugin (gst_registry_get (), arg);
+      GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
 
       /* if there is such a plugin, print out info */
       if (plugin) {