From 2354c5b1521a53649d14b7d528462a1c8d19f3e4 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 20 Oct 2017 11:08:14 +0200 Subject: [PATCH] gst-inspect: simplify the code for printing feature info 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 | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c index 6640b62d25..43fa9e0822 100644 --- a/tools/gst-inspect.c +++ b/tools/gst-inspect.c @@ -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) {