gst-inspect: Print GstValueArray properties nicely
[platform/upstream/gstreamer.git] / tools / gst-inspect.c
index 9b6d503..6640b62 100644 (file)
@@ -25,7 +25,7 @@
 #  include "config.h"
 #endif
 
-/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
+/* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
  * with newer GLib versions (>= 2.31.0) */
 #define GLIB_DISABLE_DEPRECATION_WARNINGS
 
@@ -40,6 +40,9 @@ static char *_name = NULL;
 static int print_element_info (GstElementFactory * factory,
     gboolean print_names);
 
+/* *INDENT-OFF* */
+G_GNUC_PRINTF (1, 2)
+/* *INDENT-ON* */
 static void
 n_print (const char *format, ...)
 {
@@ -242,9 +245,9 @@ flags_to_string (GFlagsValue * vals, guint flags)
 #define KNOWN_PARAM_FLAGS \
   (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
   G_PARAM_LAX_VALIDATION |  G_PARAM_STATIC_STRINGS | \
-  G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
-  GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
-  GST_PARAM_MUTABLE_READY)
+  G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
+  GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
+  GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
 
 static void
 print_element_properties_info (GstElement * element)
@@ -287,6 +290,10 @@ print_element_properties_info (GstElement * element)
       g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
       first_flag = FALSE;
     }
+    if (param->flags & G_PARAM_DEPRECATED) {
+      g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
+      first_flag = FALSE;
+    }
     if (param->flags & GST_PARAM_CONTROLLABLE) {
       g_print (", %s", _("controllable"));
       first_flag = FALSE;
@@ -480,6 +487,12 @@ print_element_properties_info (GstElement * element)
         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
           n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
               g_type_name (param->value_type));
+          if (param->value_type == GST_TYPE_STRUCTURE) {
+            const GstStructure *s = gst_value_get_structure (&value);
+            if (s)
+              gst_structure_foreach (s, print_field,
+                  (gpointer) "                           ");
+          }
         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
           if (param->value_type != G_TYPE_POINTER) {
             n_print ("%-23.23s Pointer of type \"%s\".", "",
@@ -506,9 +519,18 @@ 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\"", "", param->value_type,
-              g_type_name (param->value_type));
+          n_print ("%-23.23s Unknown type %ld \"%s\"", "",
+              (glong) param->value_type, g_type_name (param->value_type));
         }
         break;
     }
@@ -528,7 +550,6 @@ print_element_properties_info (GstElement * element)
 static void
 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
 {
-  GstElementClass *gstelement_class;
   const GList *pads;
   GstStaticPadTemplate *padtemplate;
 
@@ -538,8 +559,6 @@ print_pad_templates_info (GstElement * element, GstElementFactory * factory)
     return;
   }
 
-  gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
-
   pads = gst_element_factory_get_static_pad_templates (factory);
   while (pads) {
     padtemplate = (GstStaticPadTemplate *) (pads->data);
@@ -558,14 +577,15 @@ print_pad_templates_info (GstElement * element, GstElementFactory * factory)
       n_print ("    Availability: Sometimes\n");
     else if (padtemplate->presence == GST_PAD_REQUEST) {
       n_print ("    Availability: On request\n");
-      n_print ("      Has request_new_pad() function: %s\n",
-          GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
     } else
       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");
@@ -617,7 +637,7 @@ print_clocking_info (GstElement * element)
 
   if (!requires_clock && !provides_clock) {
     n_print ("\n");
-    n_print ("Element has no clocking capabilities.");
+    n_print ("Element has no clocking capabilities.\n");
     return;
   }
 
@@ -694,38 +714,16 @@ print_pad_info (GstElement * element)
     pad = GST_PAD (pads->data);
     pads = g_list_next (pads);
 
-    n_print ("");
-
     name = gst_pad_get_name (pad);
     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
-      g_print ("  SRC: '%s'", name);
+      n_print ("  SRC: '%s'\n", name);
     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
-      g_print ("  SINK: '%s'", name);
+      n_print ("  SINK: '%s'\n", name);
     else
-      g_print ("  UNKNOWN!!!: '%s'", name);
+      n_print ("  UNKNOWN!!!: '%s'\n", name);
 
     g_free (name);
 
-    g_print ("\n");
-
-    n_print ("    Implementation:\n");
-    if (pad->chainfunc)
-      n_print ("      Has chainfunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
-    if (pad->getrangefunc)
-      n_print ("      Has getrangefunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
-    if (pad->eventfunc != gst_pad_event_default)
-      n_print ("      Has custom eventfunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
-    if (pad->queryfunc != gst_pad_query_default)
-      n_print ("      Has custom queryfunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
-
-    if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
-      n_print ("      Has custom iterintlinkfunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
-
     if (pad->padtemplate)
       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
 
@@ -752,6 +750,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)
 {
@@ -822,12 +833,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 {
@@ -842,17 +848,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) {
@@ -892,6 +894,25 @@ print_children_info (GstElement * element)
 }
 
 static void
+print_preset_list (GstElement * element)
+{
+  gchar **presets, **preset;
+
+  if (!GST_IS_PRESET (element))
+    return;
+
+  presets = gst_preset_get_preset_names (GST_PRESET (element));
+  if (presets && *presets) {
+    n_print ("\n");
+    n_print ("Presets:\n");
+    for (preset = presets; *preset; preset++) {
+      n_print ("  \"%s\"\n", *preset);
+    }
+    g_strfreev (presets);
+  }
+}
+
+static void
 print_blacklist (void)
 {
   GList *plugins, *cur;
@@ -917,10 +938,21 @@ print_blacklist (void)
 }
 
 static void
-print_element_list (gboolean print_all)
+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) {
@@ -948,9 +980,27 @@ 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);
         else
@@ -962,6 +1012,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),
@@ -983,6 +1035,8 @@ print_element_list (gboolean 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)));
@@ -996,6 +1050,7 @@ print_element_list (gboolean print_all)
   }
 
   gst_plugin_list_free (orig_plugins);
+  g_strfreev (types);
 
   g_print ("\n");
   g_print (_("Total count: "));
@@ -1131,7 +1186,9 @@ print_plugin_features (GstPlugin * plugin)
   GList *features, *origlist;
   gint num_features = 0;
   gint num_elements = 0;
+  gint num_tracers = 0;
   gint num_typefinders = 0;
+  gint num_devproviders = 0;
   gint num_other = 0;
 
   origlist = features =
@@ -1172,6 +1229,18 @@ print_plugin_features (GstPlugin * plugin)
             gst_plugin_feature_get_name (feature));
 
       num_typefinders++;
+    } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
+      GstDeviceProviderFactory *factory;
+
+      factory = GST_DEVICE_PROVIDER_FACTORY (feature);
+      n_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
+          gst_device_provider_factory_get_metadata (factory,
+              GST_ELEMENT_METADATA_LONGNAME));
+      num_devproviders++;
+    } else if (GST_IS_TRACER_FACTORY (feature)) {
+      n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
+          g_type_name (G_OBJECT_TYPE (feature)));
+      num_tracers++;
     } else if (feature) {
       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
           g_type_name (G_OBJECT_TYPE (feature)));
@@ -1189,6 +1258,10 @@ print_plugin_features (GstPlugin * plugin)
     n_print ("  +-- %d elements\n", num_elements);
   if (num_typefinders > 0)
     n_print ("  +-- %d typefinders\n", num_typefinders);
+  if (num_devproviders > 0)
+    n_print ("  +-- %d device providers\n", num_devproviders);
+  if (num_tracers > 0)
+    n_print ("  +-- %d tracers\n", num_tracers);
   if (num_other > 0)
     n_print ("  +-- %d other objects\n", num_other);
 
@@ -1207,6 +1280,12 @@ print_element_features (const gchar * element_name)
     n_print ("%s: a typefind function\n", element_name);
     return 0;
   }
+  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;
+  }
 
   return -1;
 }
@@ -1259,6 +1338,7 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
   print_element_properties_info (element);
   print_signal_info (element);
   print_children_info (element);
+  print_preset_list (element);
 
   gst_object_unref (element);
   gst_object_unref (factory);
@@ -1428,6 +1508,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,
@@ -1441,6 +1522,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,
@@ -1466,6 +1550,9 @@ main (int argc, char *argv[])
   textdomain (GETTEXT_PACKAGE);
 #endif
 
+  /* avoid glib warnings when inspecting deprecated properties */
+  g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
+
   g_set_prgname ("gst-inspect-" GST_API_VERSION);
 
 #ifndef GST_DISABLE_OPTION_PARSING
@@ -1474,6 +1561,8 @@ main (int argc, char *argv[])
   g_option_context_add_group (ctx, gst_init_get_option_group ());
   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
     g_printerr ("Error initializing: %s\n", err->message);
+    g_clear_error (&err);
+    g_option_context_free (ctx);
     return -1;
   }
   g_option_context_free (ctx);
@@ -1521,6 +1610,9 @@ main (int argc, char *argv[])
         } else {
           exit_code = 1;
         }
+
+        if (feature)
+          gst_object_unref (feature);
       } else {
         /* FIXME: support checking for plugins too */
         g_printerr ("Checking for plugins is not supported yet\n");
@@ -1540,7 +1632,7 @@ 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 */
@@ -1590,7 +1682,7 @@ main (int argc, char *argv[])
             }
           } else {
             g_printerr (_("Could not load plugin file: %s\n"), error->message);
-            g_error_free (error);
+            g_clear_error (&error);
             return -1;
           }
         } else {