gstfunnel: avoid access of freed pad
[platform/upstream/gstreamer.git] / tools / gst-inspect.c
index bc4c618..9642ea9 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
+ * with newer GLib versions (>= 2.31.0) */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #endif
@@ -177,31 +181,29 @@ get_rank_name (char *s, gint rank)
   return s;
 }
 
-static gboolean
-print_factory_details_metadata (GQuark field_id, const GValue * value,
-    gpointer user_data)
-{
-  gchar *val = g_strdup_value_contents (value);
-  gchar *key = g_strdup (g_quark_to_string (field_id));
-
-  key[0] = g_ascii_toupper (key[0]);
-  n_print ("  %s:\t\t%s\n", key, val);
-  g_free (val);
-  g_free (key);
-  return TRUE;
-}
-
 static void
 print_factory_details_info (GstElementFactory * factory)
 {
+  gchar **keys, **k;
+  GstRank rank;
   char s[20];
 
+  rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
   n_print ("Factory Details:\n");
-  n_print ("  Rank:\t\t%s (%d)\n",
-      get_rank_name (s, GST_PLUGIN_FEATURE (factory)->rank),
-      GST_PLUGIN_FEATURE (factory)->rank);
-  gst_structure_foreach ((GstStructure *) factory->metadata,
-      print_factory_details_metadata, NULL);
+  n_print ("  Rank:\t\t%s (%d)\n", get_rank_name (s, rank), rank);
+
+  keys = gst_element_factory_get_metadata_keys (factory);
+  if (keys != NULL) {
+    for (k = keys; *k != NULL; ++k) {
+      const gchar *val;
+      gchar *key = *k;
+
+      val = gst_element_factory_get_metadata (factory, key);
+      key[0] = g_ascii_toupper (key[0]);
+      n_print ("  %s:\t\t%s\n", key, val);
+    }
+    g_strfreev (keys);
+  }
   n_print ("\n");
 }
 
@@ -387,6 +389,10 @@ print_element_properties_info (GstElement * element)
         n_print ("%-23.23s Unsigned Long. ", "");
         g_print ("Range: %lu - %lu Default: %lu ",
             pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
+
+        GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
+            "uint/uint64", GST_OBJECT_NAME (element),
+            g_param_spec_get_name (param));
         break;
       }
       case G_TYPE_LONG:
@@ -396,6 +402,10 @@ print_element_properties_info (GstElement * element)
         n_print ("%-23.23s Long. ", "");
         g_print ("Range: %ld - %ld Default: %ld ",
             plong->minimum, plong->maximum, g_value_get_long (&value));
+
+        GST_ERROR ("%s: property '%s' of type long: consider changing to "
+            "int/int64", GST_OBJECT_NAME (element),
+            g_param_spec_get_name (param));
         break;
       }
       case G_TYPE_UINT:
@@ -454,6 +464,12 @@ print_element_properties_info (GstElement * element)
             pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
         break;
       }
+      case G_TYPE_CHAR:
+      case G_TYPE_UCHAR:
+        GST_ERROR ("%s: property '%s' of type char: consider changing to "
+            "int/string", GST_OBJECT_NAME (element),
+            g_param_spec_get_name (param));
+        /* fall through */
       default:
         if (param->value_type == GST_TYPE_CAPS) {
           const GstCaps *caps = gst_value_get_caps (&value);
@@ -573,14 +589,14 @@ print_pad_templates_info (GstElement * element, GstElementFactory * factory)
   GstStaticPadTemplate *padtemplate;
 
   n_print ("Pad Templates:\n");
-  if (!factory->numpadtemplates) {
+  if (gst_element_factory_get_num_pad_templates (factory) == 0) {
     n_print ("  none\n");
     return;
   }
 
   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
 
-  pads = factory->staticpadtemplates;
+  pads = gst_element_factory_get_static_pad_templates (factory);
   while (pads) {
     padtemplate = (GstStaticPadTemplate *) (pads->data);
     pads = g_list_next (pads);
@@ -648,9 +664,14 @@ print_implementation_info (GstElement * element)
 static void
 print_clocking_info (GstElement * element)
 {
-  if (!gst_element_requires_clock (element) &&
-      !(gst_element_provides_clock (element) &&
-          gst_element_get_clock (element))) {
+  gboolean requires_clock, provides_clock;
+
+  requires_clock =
+      GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
+  provides_clock =
+      GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
+
+  if (!requires_clock && !provides_clock) {
     n_print ("\n");
     n_print ("Element has no clocking capabilities.");
     return;
@@ -658,17 +679,18 @@ print_clocking_info (GstElement * element)
 
   n_print ("\n");
   n_print ("Clocking Interaction:\n");
-  if (gst_element_requires_clock (element)) {
+  if (requires_clock) {
     n_print ("  element requires a clock\n");
   }
 
-  if (gst_element_provides_clock (element)) {
+  if (provides_clock) {
     GstClock *clock;
 
     clock = gst_element_get_clock (element);
-    if (clock)
+    if (clock) {
       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
-    else
+      gst_object_unref (clock);
+    } else
       n_print ("  element is supposed to provide a clock but returned NULL\n");
   }
 }
@@ -676,7 +698,7 @@ print_clocking_info (GstElement * element)
 static void
 print_index_info (GstElement * element)
 {
-  if (gst_element_is_indexable (element)) {
+  if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
     n_print ("\n");
     n_print ("Indexing capabilities:\n");
     n_print ("  element can do indexing\n");
@@ -690,8 +712,8 @@ static void
 print_uri_handler_info (GstElement * element)
 {
   if (GST_IS_URI_HANDLER (element)) {
+    const gchar *const *uri_protocols;
     const gchar *uri_type;
-    gchar **uri_protocols;
 
     if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
       uri_type = "source";
@@ -773,10 +795,6 @@ print_pad_info (GstElement * element)
       n_print ("      Has custom iterintlinkfunc(): %s\n",
           GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
 
-    if (pad->getcapsfunc)
-      n_print ("      Has getcapsfunc(): %s\n",
-          GST_DEBUG_FUNCPTR_NAME (pad->getcapsfunc));
-
     if (pad->padtemplate)
       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
 
@@ -880,24 +898,22 @@ print_signal_info (GstElement * element)
           g_type_name (query->return_type), g_type_name (type));
 
       for (j = 0; j < query->n_params; j++) {
-        if (_name)
-          g_print ("%s", _name);
+        g_print (",\n");
         if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
-          g_print (",\n%s%s arg%d", indent,
+          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])) {
-          g_print (",\n%s%s arg%d", indent,
+          n_print ("%s%s arg%d", indent,
               g_type_name (query->param_types[j]), j);
         } else {
-          g_print (",\n%s%s* arg%d", indent,
+          n_print ("%s%s* arg%d", indent,
               g_type_name (query->param_types[j]), j);
         }
       }
 
       if (k == 0) {
-        if (_name)
-          g_print ("%s", _name);
-        g_print (",\n%sgpointer user_data);\n", indent);
+        g_print (",\n");
+        n_print ("%sgpointer user_data);\n", indent);
       } else
         g_print (");\n");
 
@@ -922,7 +938,7 @@ print_children_info (GstElement * element)
   children = (GList *) GST_BIN (element)->children;
   if (children) {
     n_print ("\n");
-    g_print ("Children:\n");
+    n_print ("Children:\n");
   }
 
   while (children) {
@@ -939,11 +955,11 @@ print_blacklist (void)
 
   g_print ("%s\n", _("Blacklisted files:"));
 
-  plugins = gst_default_registry_get_plugin_list ();
+  plugins = gst_registry_get_plugin_list (gst_registry_get ());
   for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
     GstPlugin *plugin = (GstPlugin *) (cur->data);
-    if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
-      g_print ("  %s\n", plugin->desc.name);
+    if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
+      g_print ("  %s\n", gst_plugin_get_name (plugin));
       count++;
     }
   }
@@ -962,7 +978,7 @@ print_element_list (gboolean print_all)
   int plugincount = 0, featurecount = 0, blacklistcount = 0;
   GList *plugins, *orig_plugins;
 
-  orig_plugins = plugins = gst_default_registry_get_plugin_list ();
+  orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
   while (plugins) {
     GList *features, *orig_features;
     GstPlugin *plugin;
@@ -971,14 +987,14 @@ print_element_list (gboolean print_all)
     plugins = g_list_next (plugins);
     plugincount++;
 
-    if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
+    if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
       blacklistcount++;
       continue;
     }
 
     orig_features = features =
-        gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
-        plugin->desc.name);
+        gst_registry_get_feature_list_by_plugin (gst_registry_get (),
+        gst_plugin_get_name (plugin));
     while (features) {
       GstPluginFeature *feature;
 
@@ -994,9 +1010,10 @@ print_element_list (gboolean print_all)
         if (print_all)
           print_element_info (factory, TRUE);
         else
-          g_print ("%s:  %s: %s\n", plugin->desc.name,
+          g_print ("%s:  %s: %s\n", gst_plugin_get_name (plugin),
               GST_OBJECT_NAME (factory),
               gst_element_factory_get_longname (factory));
+#if 0
       } else if (GST_IS_INDEX_FACTORY (feature)) {
         GstIndexFactory *factory;
 
@@ -1004,19 +1021,23 @@ print_element_list (gboolean print_all)
         if (!print_all)
           g_print ("%s:  %s: %s\n", plugin->desc.name,
               GST_OBJECT_NAME (factory), factory->longdesc);
+#endif
       } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
         GstTypeFindFactory *factory;
+        const gchar *const *extensions;
 
         factory = GST_TYPE_FIND_FACTORY (feature);
         if (!print_all)
-          g_print ("%s: %s: ", plugin->desc.name,
+          g_print ("%s: %s: ", gst_plugin_get_name (plugin),
               gst_plugin_feature_get_name (feature));
-        if (factory->extensions) {
+
+        extensions = gst_type_find_factory_get_extensions (factory);
+        if (extensions != NULL) {
           guint i = 0;
 
-          while (factory->extensions[i]) {
+          while (extensions[i]) {
             if (!print_all)
-              g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
+              g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
             i++;
           }
           if (!print_all)
@@ -1027,7 +1048,7 @@ print_element_list (gboolean print_all)
         }
       } else {
         if (!print_all)
-          n_print ("%s:  %s (%s)\n", plugin->desc.name,
+          n_print ("%s:  %s (%s)\n", gst_plugin_get_name (plugin),
               GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
       }
 
@@ -1059,14 +1080,14 @@ print_all_uri_handlers (void)
 {
   GList *plugins, *p, *features, *f;
 
-  plugins = gst_default_registry_get_plugin_list ();
+  plugins = gst_registry_get_plugin_list (gst_registry_get ());
 
   for (p = plugins; p; p = p->next) {
     GstPlugin *plugin = (GstPlugin *) (p->data);
 
     features =
-        gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
-        plugin->desc.name);
+        gst_registry_get_feature_list_by_plugin (gst_registry_get (),
+        gst_plugin_get_name (plugin));
 
     for (f = features; f; f = f->next) {
       GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
@@ -1077,7 +1098,8 @@ print_all_uri_handlers (void)
 
         factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
         if (!factory) {
-          g_print ("element plugin %s couldn't be loaded\n", plugin->desc.name);
+          g_print ("element plugin %s couldn't be loaded\n",
+              gst_plugin_get_name (plugin));
           continue;
         }
 
@@ -1090,8 +1112,9 @@ print_all_uri_handlers (void)
         }
 
         if (GST_IS_URI_HANDLER (element)) {
+          const gchar *const *uri_protocols;
           const gchar *dir;
-          gchar **uri_protocols, *joined;
+          gchar *joined;
 
           switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
             case GST_URI_SRC:
@@ -1107,7 +1130,7 @@ print_all_uri_handlers (void)
 
           uri_protocols =
               gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
-          joined = g_strjoinv (", ", uri_protocols);
+          joined = g_strjoinv (", ", (gchar **) uri_protocols);
 
           g_print ("%s (%s, rank %u): %s\n",
               gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
@@ -1131,21 +1154,24 @@ print_all_uri_handlers (void)
 static void
 print_plugin_info (GstPlugin * plugin)
 {
+  const gchar *release_date = gst_plugin_get_release_date_string (plugin);
+  const gchar *filename = gst_plugin_get_filename (plugin);
+
   n_print ("Plugin Details:\n");
-  n_print ("  Name:\t\t\t%s\n", plugin->desc.name);
-  n_print ("  Description:\t\t%s\n", plugin->desc.description);
-  n_print ("  Filename:\t\t%s\n",
-      plugin->filename ? plugin->filename : "(null)");
-  n_print ("  Version:\t\t%s\n", plugin->desc.version);
-  n_print ("  License:\t\t%s\n", plugin->desc.license);
-  n_print ("  Source module:\t%s\n", plugin->desc.source);
-  if (plugin->desc.release_datetime != NULL) {
+  n_print ("  Name:\t\t\t%s\n", gst_plugin_get_name (plugin));
+  n_print ("  Description:\t\t%s\n", gst_plugin_get_description (plugin));
+  n_print ("  Filename:\t\t%s\n", (filename != NULL) ? filename : "(null)");
+  n_print ("  Version:\t\t%s\n", gst_plugin_get_version (plugin));
+  n_print ("  License:\t\t%s\n", gst_plugin_get_license (plugin));
+  n_print ("  Source module:\t%s\n", gst_plugin_get_source (plugin));
+
+  if (release_date != NULL) {
     const gchar *tz = "(UTC)";
     gchar *str, *sep;
 
     /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
     /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
-    str = g_strdup (plugin->desc.release_datetime);
+    str = g_strdup (release_date);
     sep = strstr (str, "T");
     if (sep != NULL) {
       *sep = ' ';
@@ -1158,8 +1184,8 @@ print_plugin_info (GstPlugin * plugin)
     n_print ("  Source release date:\t%s%s\n", str, tz);
     g_free (str);
   }
-  n_print ("  Binary package:\t%s\n", plugin->desc.package);
-  n_print ("  Origin URL:\t\t%s\n", plugin->desc.origin);
+  n_print ("  Binary package:\t%s\n", gst_plugin_get_package (plugin));
+  n_print ("  Origin URL:\t\t%s\n", gst_plugin_get_origin (plugin));
   n_print ("\n");
 }
 
@@ -1174,8 +1200,8 @@ print_plugin_features (GstPlugin * plugin)
   gint num_other = 0;
 
   origlist = features =
-      gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
-      plugin->desc.name);
+      gst_registry_get_feature_list_by_plugin (gst_registry_get (),
+      gst_plugin_get_name (plugin));
 
   while (features) {
     GstPluginFeature *feature;
@@ -1189,28 +1215,32 @@ print_plugin_features (GstPlugin * plugin)
       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
           gst_element_factory_get_longname (factory));
       num_elements++;
+#if 0
     } else if (GST_IS_INDEX_FACTORY (feature)) {
       GstIndexFactory *factory;
 
       factory = GST_INDEX_FACTORY (feature);
       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
       num_indexes++;
+#endif
     } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
       GstTypeFindFactory *factory;
+      const gchar *const *extensions;
 
       factory = GST_TYPE_FIND_FACTORY (feature);
-      if (factory->extensions) {
+      extensions = gst_type_find_factory_get_extensions (factory);
+      if (extensions) {
         guint i = 0;
 
-        g_print ("%s: %s: ", plugin->desc.name,
+        g_print ("%s: %s: ", gst_plugin_get_name (plugin),
             gst_plugin_feature_get_name (feature));
-        while (factory->extensions[i]) {
-          g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
+        while (extensions[i]) {
+          g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
           i++;
         }
         g_print ("\n");
       } else
-        g_print ("%s: %s: no extensions\n", plugin->desc.name,
+        g_print ("%s: %s: no extensions\n", gst_plugin_get_name (plugin),
             gst_plugin_feature_get_name (feature));
 
       num_typefinders++;
@@ -1245,13 +1275,15 @@ print_element_features (const gchar * element_name)
   GstPluginFeature *feature;
 
   /* FIXME implement other pretty print function for these */
+#if 0
   feature = gst_default_registry_find_feature (element_name,
       GST_TYPE_INDEX_FACTORY);
   if (feature) {
     n_print ("%s: an index\n", element_name);
     return 0;
   }
-  feature = gst_default_registry_find_feature (element_name,
+#endif
+  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);
@@ -1265,6 +1297,7 @@ static int
 print_element_info (GstElementFactory * factory, gboolean print_names)
 {
   GstElement *element;
+  GstPlugin *plugin;
   gint maxlevel = 0;
 
   factory =
@@ -1278,6 +1311,7 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
 
   element = gst_element_factory_create (factory, NULL);
   if (!element) {
+    gst_object_unref (factory);
     g_print ("couldn't construct element for some reason\n");
     return -1;
   }
@@ -1288,14 +1322,11 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
     _name = NULL;
 
   print_factory_details_info (factory);
-  if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
-    GstPlugin *plugin;
 
-    plugin = gst_registry_find_plugin (gst_registry_get_default (),
-        GST_PLUGIN_FEATURE (factory)->plugin_name);
-    if (plugin) {
-      print_plugin_info (plugin);
-    }
+  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 (element), 0, &maxlevel);
@@ -1392,45 +1423,47 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
 static void
 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
 {
-  gchar **protocols, **p;
+  const gchar *const *protocols;
 
   protocols = gst_element_factory_get_uri_protocols (factory);
   if (protocols != NULL && *protocols != NULL) {
     switch (gst_element_factory_get_uri_type (factory)) {
       case GST_URI_SINK:
-        for (p = protocols; *p != NULL; ++p)
-          g_print ("urisink-%s\n", *p);
+        while (*protocols != NULL) {
+          g_print ("urisink-%s\n", *protocols);
+          ++protocols;
+        }
         break;
       case GST_URI_SRC:
-        for (p = protocols; *p != NULL; ++p)
-          g_print ("urisource-%s\n", *p);
+        while (*protocols != NULL) {
+          g_print ("urisource-%s\n", *protocols);
+          ++protocols;
+        }
         break;
       default:
         break;
     }
-    g_strfreev (protocols);
   }
 }
 
 static void
 print_plugin_automatic_install_info (GstPlugin * plugin)
 {
-  const gchar *plugin_name;
   GList *features, *l;
 
-  plugin_name = gst_plugin_get_name (plugin);
-
   /* not interested in typefind factories, only element factories */
-  features = gst_registry_get_feature_list (gst_registry_get_default (),
+  features = gst_registry_get_feature_list (gst_registry_get (),
       GST_TYPE_ELEMENT_FACTORY);
 
   for (l = features; l != NULL; l = l->next) {
     GstPluginFeature *feature;
+    GstPlugin *feature_plugin;
 
     feature = GST_PLUGIN_FEATURE (l->data);
 
     /* only interested in the ones that are in the plugin we just loaded */
-    if (g_str_equal (plugin_name, feature->plugin_name)) {
+    feature_plugin = gst_plugin_feature_get_plugin (feature);
+    if (feature_plugin == plugin) {
       GstElementFactory *factory;
 
       g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
@@ -1439,6 +1472,8 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
       print_plugin_automatic_install_info_protocols (factory);
       print_plugin_automatic_install_info_codecs (factory);
     }
+    if (feature_plugin)
+      gst_object_unref (feature_plugin);
   }
 
   g_list_foreach (features, (GFunc) gst_object_unref, NULL);
@@ -1450,7 +1485,7 @@ print_all_plugin_automatic_install_info (void)
 {
   GList *plugins, *orig_plugins;
 
-  orig_plugins = plugins = gst_default_registry_get_plugin_list ();
+  orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
   while (plugins) {
     GstPlugin *plugin;
 
@@ -1500,8 +1535,6 @@ main (int argc, char *argv[])
   textdomain (GETTEXT_PACKAGE);
 #endif
 
-  g_thread_init (NULL);
-
   gst_tools_set_prgname ("gst-inspect");
 
 #ifndef GST_DISABLE_OPTION_PARSING
@@ -1564,7 +1597,7 @@ main (int argc, char *argv[])
 
     /* otherwise check if it's a plugin */
     if (retval) {
-      plugin = gst_default_registry_find_plugin (arg);
+      plugin = gst_registry_find_plugin (gst_registry_get (), arg);
 
       /* if there is such a plugin, print out info */
       if (plugin) {