tools: gst-inspect: fix double empty line after pad templates
[platform/upstream/gstreamer.git] / tools / gst-inspect.c
index 4d020ad..c49c138 100644 (file)
@@ -30,6 +30,7 @@
 #define GLIB_DISABLE_DEPRECATION_WARNINGS
 
 #include "tools.h"
+#include <gst/gst_private.h>    /* for internal Factories */
 
 #include <string.h>
 #include <locale.h>
 
 static char *_name = NULL;
 
-static int print_element_info (GstElementFactory * factory,
+static int print_element_info (GstPluginFeature * feature,
     gboolean print_names);
+static int print_typefind_info (GstPluginFeature * feature,
+    gboolean print_names);
+static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
 
 /* *INDENT-OFF* */
 G_GNUC_PRINTF (1, 2)
@@ -519,6 +523,15 @@ print_element_properties_info (GstElement * element)
               pfraction->max_num, pfraction->max_den,
               gst_value_get_fraction_numerator (&value),
               gst_value_get_fraction_denominator (&value));
+        } else if (param->value_type == GST_TYPE_ARRAY) {
+          GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
+
+          if (parray->element_spec) {
+            n_print ("%-23.23s GstValueArray of GValues of type \"%s\"", "",
+                g_type_name (parray->element_spec->value_type));
+          } else {
+            n_print ("%-23.23s GstValueArray of GValues", "");
+          }
         } else {
           n_print ("%-23.23s Unknown type %ld \"%s\"", "",
               (glong) param->value_type, g_type_name (param->value_type));
@@ -572,11 +585,15 @@ print_pad_templates_info (GstElement * element, GstElementFactory * factory)
       n_print ("    Availability: UNKNOWN!!!\n");
 
     if (padtemplate->static_caps.string) {
+      GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
+
       n_print ("    Capabilities:\n");
-      print_caps (gst_static_caps_get (&padtemplate->static_caps), "      ");
+      print_caps (caps, "      ");
+      gst_caps_unref (caps);
     }
 
-    n_print ("\n");
+    if (pads != NULL)
+      n_print ("\n");
   }
 }
 
@@ -738,6 +755,19 @@ has_sometimes_template (GstElement * element)
   return FALSE;
 }
 
+static gboolean
+gtype_needs_ptr_marker (GType type)
+{
+  if (type == G_TYPE_POINTER)
+    return FALSE;
+
+  if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
+      || G_TYPE_IS_OBJECT (type))
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 print_signal_info (GstElement * element)
 {
@@ -808,12 +838,7 @@ print_signal_info (GstElement * element)
       indent_len = strlen (query->signal_name) +
           strlen (g_type_name (query->return_type)) + 24;
 
-
-      if (query->return_type == G_TYPE_POINTER) {
-        pmark = "";
-      } else if (G_TYPE_FUNDAMENTAL (query->return_type) == G_TYPE_POINTER
-          || G_TYPE_IS_BOXED (query->return_type)
-          || G_TYPE_IS_OBJECT (query->return_type)) {
+      if (gtype_needs_ptr_marker (query->return_type)) {
         pmark = "* ";
         indent_len += 2;
       } else {
@@ -828,17 +853,13 @@ print_signal_info (GstElement * element)
           g_type_name (type));
 
       for (j = 0; j < query->n_params; j++) {
+        const gchar *type_name, *asterisk;
+
+        type_name = g_type_name (query->param_types[j]);
+        asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
+
         g_print (",\n");
-        if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
-          n_print ("%s%s arg%d", indent,
-              g_type_name (query->param_types[j]), j);
-        } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
-          n_print ("%s%s arg%d", indent,
-              g_type_name (query->param_types[j]), j);
-        } else {
-          n_print ("%s%s* arg%d", indent,
-              g_type_name (query->param_types[j]), j);
-        }
+        n_print ("%s%s%s arg%d", indent, type_name, asterisk, j);
       }
 
       if (k == 0) {
@@ -922,10 +943,31 @@ print_blacklist (void)
 }
 
 static void
-print_element_list (gboolean print_all)
+print_typefind_extensions (const gchar * const *extensions)
+{
+  guint i = 0;
+
+  while (extensions[i]) {
+    g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
+    i++;
+  }
+}
+
+static void
+print_element_list (gboolean print_all, gchar * ftypes)
 {
   int plugincount = 0, featurecount = 0, blacklistcount = 0;
   GList *plugins, *orig_plugins;
+  gchar **types = NULL;
+
+  if (ftypes) {
+    gint i;
+
+    types = g_strsplit (ftypes, "/", -1);
+    for (i = 0; types[i]; i++)
+      *types[i] = g_ascii_toupper (*types[i]);
+
+  }
 
   orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
   while (plugins) {
@@ -953,11 +995,29 @@ print_element_list (gboolean print_all)
       featurecount++;
 
       if (GST_IS_ELEMENT_FACTORY (feature)) {
+        const gchar *klass;
         GstElementFactory *factory;
 
         factory = GST_ELEMENT_FACTORY (feature);
+        if (types) {
+          gint i;
+          gboolean all_found = TRUE;
+
+          klass =
+              gst_element_factory_get_metadata (factory,
+              GST_ELEMENT_METADATA_KLASS);
+          for (i = 0; types[i]; i++) {
+            if (!strstr (klass, types[i])) {
+              all_found = FALSE;
+              break;
+            }
+          }
+
+          if (!all_found)
+            goto next;
+        }
         if (print_all)
-          print_element_info (factory, TRUE);
+          print_element_info (feature, TRUE);
         else
           g_print ("%s:  %s: %s\n", gst_plugin_get_name (plugin),
               GST_OBJECT_NAME (factory),
@@ -967,6 +1027,8 @@ print_element_list (gboolean print_all)
         GstTypeFindFactory *factory;
         const gchar *const *extensions;
 
+        if (types)
+          goto next;
         factory = GST_TYPE_FIND_FACTORY (feature);
         if (!print_all)
           g_print ("%s: %s: ", gst_plugin_get_name (plugin),
@@ -974,20 +1036,17 @@ print_element_list (gboolean print_all)
 
         extensions = gst_type_find_factory_get_extensions (factory);
         if (extensions != NULL) {
-          guint i = 0;
-
-          while (extensions[i]) {
-            if (!print_all)
-              g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
-            i++;
-          }
-          if (!print_all)
+          if (!print_all) {
+            print_typefind_extensions (extensions);
             g_print ("\n");
+          }
         } else {
           if (!print_all)
             g_print ("no extensions\n");
         }
       } else {
+        if (types)
+          goto next;
         if (!print_all)
           n_print ("%s:  %s (%s)\n", gst_plugin_get_name (plugin),
               GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
@@ -1001,6 +1060,7 @@ print_element_list (gboolean print_all)
   }
 
   gst_plugin_list_free (orig_plugins);
+  g_strfreev (types);
 
   g_print ("\n");
   g_print (_("Total count: "));
@@ -1219,38 +1279,46 @@ 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 ();
+  int ret;
 
-  /* FIXME implement other pretty print function for these */
-  feature = gst_registry_find_feature (gst_registry_get (), element_name,
-      GST_TYPE_TYPE_FIND_FACTORY);
-  if (feature) {
-    n_print ("%s: a typefind function\n", element_name);
-    return 0;
+  if ((feature = gst_registry_find_feature (registry, feature_name,
+              GST_TYPE_ELEMENT_FACTORY))) {
+    ret = print_element_info (feature, print_all);
+    goto handled;
+  }
+  if ((feature = gst_registry_find_feature (registry, feature_name,
+              GST_TYPE_TYPE_FIND_FACTORY))) {
+    ret = print_typefind_info (feature, print_all);
+    goto handled;
   }
-  feature = gst_registry_find_feature (gst_registry_get (), element_name,
-      GST_TYPE_TRACER_FACTORY);
-  if (feature) {
-    n_print ("%s: a tracer module\n", element_name);
-    return 0;
+  if ((feature = gst_registry_find_feature (registry, feature_name,
+              GST_TYPE_TRACER_FACTORY))) {
+    ret = print_tracer_info (feature, print_all);
+    goto handled;
   }
 
+  /* TODO: handle DEVICE_PROVIDER_FACTORY */
+
   return -1;
+
+handled:
+  gst_object_unref (feature);
+  return ret;
 }
 
 static int
-print_element_info (GstElementFactory * factory, gboolean print_names)
+print_element_info (GstPluginFeature * feature, gboolean print_names)
 {
+  GstElementFactory *factory;
   GstElement *element;
   GstPlugin *plugin;
   gint maxlevel = 0;
 
-  factory =
-      GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
-          (factory)));
-
+  factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
   if (!factory) {
     g_print ("element plugin couldn't be loaded\n");
     return -1;
@@ -1293,10 +1361,119 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
   gst_object_unref (element);
   gst_object_unref (factory);
   g_free (_name);
+  return 0;
+}
+
+static int
+print_typefind_info (GstPluginFeature * feature, gboolean print_names)
+{
+  GstTypeFindFactory *factory;
+  GstPlugin *plugin;
+  GstCaps *caps;
+  GstRank rank;
+  char s[20];
+  const gchar *const *extensions;
+
+  factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
+  if (!factory) {
+    g_print ("typefind plugin couldn't be loaded\n");
+    return -1;
+  }
 
+  if (print_names)
+    _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
+  else
+    _name = NULL;
+
+  n_print ("Factory Details:\n");
+  rank = gst_plugin_feature_get_rank (feature);
+  n_print ("  %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
+  n_print ("  %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
+  caps = gst_type_find_factory_get_caps (factory);
+  if (caps) {
+    gchar *caps_str = gst_caps_to_string (factory->caps);
+
+    n_print ("  %-25s%s\n", "Caps", caps_str);
+    g_free (caps_str);
+  }
+  extensions = gst_type_find_factory_get_extensions (factory);
+  if (extensions) {
+    n_print ("  %-25s", "Extensions");
+    print_typefind_extensions (extensions);
+    n_print ("\n");
+  }
+  n_print ("\n");
+
+  plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
+  if (plugin) {
+    print_plugin_info (plugin);
+    gst_object_unref (plugin);
+  }
+
+  gst_object_unref (factory);
+  g_free (_name);
   return 0;
 }
 
+static int
+print_tracer_info (GstPluginFeature * feature, gboolean print_names)
+{
+  GstTracerFactory *factory;
+  GstTracer *tracer;
+  GstPlugin *plugin;
+  gint maxlevel = 0;
+
+  factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
+  if (!factory) {
+    g_print ("tracer plugin couldn't be loaded\n");
+    return -1;
+  }
+
+  tracer = (GstTracer *) g_object_new (factory->type, NULL);
+  if (!tracer) {
+    gst_object_unref (factory);
+    g_print ("couldn't construct tracer for some reason\n");
+    return -1;
+  }
+
+  if (print_names)
+    _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
+  else
+    _name = NULL;
+
+  n_print ("Factory Details:\n");
+  n_print ("  %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
+  n_print ("\n");
+
+  plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
+  if (plugin) {
+    print_plugin_info (plugin);
+    gst_object_unref (plugin);
+  }
+
+  print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
+  print_interfaces (G_OBJECT_TYPE (tracer));
+
+  /* TODO: list what hooks it registers
+   * - the data is available in gsttracerutils, we need to iterate the
+   *   _priv_tracers hashtable for each probe and then check the list of hooks
+   *  for each probe whether hook->tracer == tracer :/
+   */
+
+  /* TODO: list what records it emits
+   * - in class_init tracers can create GstTracerRecord instances
+   * - those only get logged right now and there is no association with the
+   *   tracer that created them
+   * - we'd need to add them to GstTracerFactory
+   *   gst_tracer_class_add_record (klass, record);
+   *   - needs work in gstregistrychunks.
+   */
+
+  gst_object_unref (tracer);
+  gst_object_unref (factory);
+  g_free (_name);
+  return 0;
+}
 
 static void
 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
@@ -1458,6 +1635,7 @@ main (int argc, char *argv[])
   guint minver_maj = GST_VERSION_MAJOR;
   guint minver_min = GST_VERSION_MINOR;
   guint minver_micro = 0;
+  gchar *types = NULL;
 #ifndef GST_DISABLE_OPTION_PARSING
   GOptionEntry options[] = {
     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
@@ -1471,6 +1649,9 @@ main (int argc, char *argv[])
               "installation mechanisms"), NULL},
     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
         N_("List the plugin contents"), NULL},
+    {"types", 't', 0, G_OPTION_ARG_STRING, &types,
+        N_("A slashes ('/') separated list of types of elements (also known "
+              "as klass) to list. (unordered)"), NULL},
     {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
         N_("Check if the specified element or plugin exists"), NULL},
     {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
@@ -1578,32 +1759,20 @@ main (int argc, char *argv[])
       if (print_aii)
         print_all_plugin_automatic_install_info ();
       else
-        print_element_list (print_all);
+        print_element_list (print_all, types);
     }
   } 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) {