Blame SOURCES/gstreamer-inspect-rpm-format.patch

973d1d
From 8dfeddab12777e90f8739f9dab33c62657465854 Mon Sep 17 00:00:00 2001
973d1d
From: Wim Taymans <wtaymans@redhat.com>
973d1d
Date: Mon, 4 Jan 2016 11:39:33 +0100
973d1d
Subject: [PATCH] inspect: Add RPM output format
973d1d
973d1d
---
973d1d
 tools/gst-inspect.c | 276 +++++++++++++++++++++++++++++++++++++++++++++++++---
973d1d
 1 file changed, 261 insertions(+), 15 deletions(-)
973d1d
973d1d
diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
973d1d
index 845f52e..9084949 100644
973d1d
--- a/tools/gst-inspect.c
973d1d
+++ b/tools/gst-inspect.c
973d1d
@@ -1302,9 +1302,225 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
973d1d
   return 0;
973d1d
 }
973d1d
 
973d1d
+static void
973d1d
+print_gst_structure_append_field (GList * strings, const char *field)
973d1d
+{
973d1d
+  GList *s;
973d1d
+
973d1d
+  //g_message ("adding '%s' to the string", field);
973d1d
+
973d1d
+  for (s = strings; s != NULL; s = s->next) {
973d1d
+    g_string_append (s->data, field);
973d1d
+  }
973d1d
+}
973d1d
 
973d1d
 static void
973d1d
-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
973d1d
+print_gst_structure_append_field_index (GList * strings, const char *field,
973d1d
+    guint num_items, guint offset)
973d1d
+{
973d1d
+  GList *s;
973d1d
+  guint i;
973d1d
+
973d1d
+  //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
973d1d
+
973d1d
+  for (s = strings, i = 0; s != NULL; s = s->next, i++) {
973d1d
+    if (i == offset) {
973d1d
+      //g_message ("adding '%s' at '%d'", field, i);
973d1d
+      g_string_append (s->data, field);
973d1d
+    }
973d1d
+    if (i == num_items)
973d1d
+      i = 0;
973d1d
+  }
973d1d
+
973d1d
+}
973d1d
+
973d1d
+static GList *
973d1d
+print_gst_structure_dup_fields (GList * strings, guint num_items)
973d1d
+{
973d1d
+  guint new_items, i;
973d1d
+
973d1d
+  if (num_items == 1)
973d1d
+    return strings;
973d1d
+
973d1d
+  //g_message ("creating %d new items", num_items);
973d1d
+
973d1d
+  new_items = g_list_length (strings) * (num_items - 1);
973d1d
+  for (i = 0; i < new_items; i++) {
973d1d
+    GString *s, *first;
973d1d
+
973d1d
+    first = strings->data;
973d1d
+    s = g_string_new_len (first->str, first->len);
973d1d
+    strings = g_list_prepend (strings, s);
973d1d
+  }
973d1d
+
973d1d
+  return strings;
973d1d
+}
973d1d
+
973d1d
+enum
973d1d
+{
973d1d
+  FIELD_VERSION = 0,
973d1d
+  FIELD_LAYER,
973d1d
+  FIELD_VARIANT,
973d1d
+  FIELD_SYSTEMSTREAM
973d1d
+};
973d1d
+
973d1d
+static int
973d1d
+field_get_type (const char *field_name)
973d1d
+{
973d1d
+  if (strstr (field_name, "version") != NULL)
973d1d
+    return FIELD_VERSION;
973d1d
+  if (strcmp (field_name, "layer") == 0)
973d1d
+    return FIELD_LAYER;
973d1d
+  if (strcmp (field_name, "systemstream") == 0)
973d1d
+    return FIELD_SYSTEMSTREAM;
973d1d
+  if (strcmp (field_name, "variant") == 0)
973d1d
+    return FIELD_VARIANT;
973d1d
+
973d1d
+  return -1;
973d1d
+}
973d1d
+
973d1d
+static gint
973d1d
+fields_type_compare (const char *a, const char *b)
973d1d
+{
973d1d
+  gint a_type, b_type;
973d1d
+
973d1d
+  a_type = field_get_type (a);
973d1d
+  b_type = field_get_type (b);
973d1d
+  if (a_type < b_type)
973d1d
+    return -1;
973d1d
+  if (b_type < a_type)
973d1d
+    return 1;
973d1d
+  return 0;
973d1d
+}
973d1d
+
973d1d
+static void
973d1d
+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
973d1d
+{
973d1d
+  guint i, num_fields;
973d1d
+  const char *name;
973d1d
+  GList *fields, *l, *strings;
973d1d
+  GString *string;
973d1d
+
973d1d
+  name = gst_structure_get_name (s);
973d1d
+  strings = NULL;
973d1d
+  num_fields = gst_structure_n_fields (s);
973d1d
+  fields = NULL;
973d1d
+
973d1d
+  for (i = 0; i < num_fields; i++) {
973d1d
+    const char *field_name;
973d1d
+
973d1d
+    field_name = gst_structure_nth_field_name (s, i);
973d1d
+    if (field_get_type (field_name) < 0) {
973d1d
+      //g_message ("ignoring field named %s", field_name);
973d1d
+      continue;
973d1d
+    }
973d1d
+
973d1d
+    fields =
973d1d
+        g_list_insert_sorted (fields, g_strdup (field_name),
973d1d
+        (GCompareFunc) fields_type_compare);
973d1d
+  }
973d1d
+
973d1d
+  /* Example:
973d1d
+   * gstreamer1(decoder-video/mpeg)(mpegversion=1)()(64bit) */
973d1d
+  string = g_string_new ("gstreamer1");
973d1d
+  g_string_append_c (string, '(');
973d1d
+  g_string_append (string, type_name);
973d1d
+  g_string_append_c (string, '-');
973d1d
+  g_string_append (string, name);
973d1d
+  g_string_append_c (string, ')');
973d1d
+
973d1d
+  strings = g_list_append (strings, string);
973d1d
+
973d1d
+  for (l = fields; l != NULL; l = l->next) {
973d1d
+    char *field_name;
973d1d
+    GType type;
973d1d
+
973d1d
+    field_name = l->data;
973d1d
+
973d1d
+    type = gst_structure_get_field_type (s, field_name);
973d1d
+    //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
973d1d
+
973d1d
+    if (type == G_TYPE_INT) {
973d1d
+      char *field;
973d1d
+      int value;
973d1d
+
973d1d
+      gst_structure_get_int (s, field_name, &value);
973d1d
+      field = g_strdup_printf ("(%s=%d)", field_name, value);
973d1d
+      print_gst_structure_append_field (strings, field);
973d1d
+      g_free (field);
973d1d
+    } else if (type == G_TYPE_BOOLEAN) {
973d1d
+      char *field;
973d1d
+      int value;
973d1d
+
973d1d
+      gst_structure_get_boolean (s, field_name, &value);
973d1d
+      field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
973d1d
+      print_gst_structure_append_field (strings, field);
973d1d
+      g_free (field);
973d1d
+    } else if (type == GST_TYPE_INT_RANGE) {
973d1d
+      const GValue *value;
973d1d
+      int min, max;
973d1d
+
973d1d
+      value = gst_structure_get_value (s, field_name);
973d1d
+      min = gst_value_get_int_range_min (value);
973d1d
+      max = gst_value_get_int_range_max (value);
973d1d
+
973d1d
+      strings = print_gst_structure_dup_fields (strings, max - min + 1);
973d1d
+
973d1d
+      for (i = min; i <= max; i++) {
973d1d
+        char *field;
973d1d
+
973d1d
+        field = g_strdup_printf ("(%s=%d)", field_name, i);
973d1d
+        print_gst_structure_append_field_index (strings, field, max - min + 1,
973d1d
+            i - min);
973d1d
+        g_free (field);
973d1d
+      }
973d1d
+    } else if (type == GST_TYPE_LIST) {
973d1d
+      const GValue *value;
973d1d
+      int num_items;
973d1d
+
973d1d
+      value = gst_structure_get_value (s, field_name);
973d1d
+      num_items = gst_value_list_get_size (value);
973d1d
+
973d1d
+      strings = print_gst_structure_dup_fields (strings, num_items);
973d1d
+
973d1d
+      for (i = 0; i < num_items; i++) {
973d1d
+        char *field;
973d1d
+        const GValue *item_value;
973d1d
+
973d1d
+        item_value = gst_value_list_get_value (value, i);
973d1d
+        field = g_strdup_printf ("(%s=%d)", field_name,
973d1d
+            g_value_get_int (item_value));
973d1d
+        print_gst_structure_append_field_index (strings, field, num_items, i);
973d1d
+        g_free (field);
973d1d
+      }
973d1d
+    } else if (type == G_TYPE_STRING) {
973d1d
+      char *field;
973d1d
+      const char *value;
973d1d
+
973d1d
+      value = gst_structure_get_string (s, field_name);
973d1d
+      field = g_strdup_printf ("(%s=%s)", field_name, value);
973d1d
+      print_gst_structure_append_field (strings, field);
973d1d
+      g_free (field);
973d1d
+    } else {
973d1d
+      g_warning ("unhandled type! %s", g_type_name (type));
973d1d
+    }
973d1d
+
973d1d
+    g_free (field_name);
973d1d
+  }
973d1d
+
973d1d
+  g_list_free (fields);
973d1d
+
973d1d
+  for (l = strings; l != NULL; l = l->next) {
973d1d
+    string = l->data;
973d1d
+    g_print ("%s\n", string->str);
973d1d
+    g_string_free (string, TRUE);
973d1d
+  }
973d1d
+  g_list_free (strings);
973d1d
+}
973d1d
+
973d1d
+static void
973d1d
+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
973d1d
+    gboolean rpm_format)
973d1d
 {
973d1d
   GstPadDirection direction;
973d1d
   const gchar *type_name;
973d1d
@@ -1330,6 +1546,13 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
973d1d
     return;
973d1d
   }
973d1d
 
973d1d
+  if (rpm_format) {
973d1d
+    /* Ignore NONE ranked plugins */
973d1d
+    if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) ==
973d1d
+        GST_RANK_NONE)
973d1d
+      return;
973d1d
+  }
973d1d
+
973d1d
   /* decoder/demuxer sink pads should always be static and there should only
973d1d
    * be one, the same applies to encoders/muxers and source pads */
973d1d
   static_templates = gst_element_factory_get_static_pad_templates (factory);
973d1d
@@ -1366,15 +1589,20 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
973d1d
     gst_structure_remove_field (s, "rate");
973d1d
     gst_structure_remove_field (s, "depth");
973d1d
     gst_structure_remove_field (s, "clock-rate");
973d1d
-    s_str = gst_structure_to_string (s);
973d1d
-    g_print ("%s-%s\n", type_name, s_str);
973d1d
-    g_free (s_str);
973d1d
+    if (!rpm_format) {
973d1d
+      s_str = gst_structure_to_string (s);
973d1d
+      g_print ("%s-%s\n", type_name, s_str);
973d1d
+      g_free (s_str);
973d1d
+    } else {
973d1d
+      print_gst_structure_for_rpm (type_name, s);
973d1d
+    }
973d1d
   }
973d1d
   gst_caps_unref (caps);
973d1d
 }
973d1d
 
973d1d
 static void
973d1d
-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
973d1d
+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
973d1d
+    gboolean rpm_format)
973d1d
 {
973d1d
   const gchar *const *protocols;
973d1d
 
973d1d
@@ -1383,13 +1611,19 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
973d1d
     switch (gst_element_factory_get_uri_type (factory)) {
973d1d
       case GST_URI_SINK:
973d1d
         while (*protocols != NULL) {
973d1d
-          g_print ("urisink-%s\n", *protocols);
973d1d
+          if (!rpm_format)
973d1d
+            g_print ("urisink-%s\n", *protocols);
973d1d
+          else
973d1d
+            g_print ("gstreamer1(urisink-%s)\n", *protocols);
973d1d
           ++protocols;
973d1d
         }
973d1d
         break;
973d1d
       case GST_URI_SRC:
973d1d
         while (*protocols != NULL) {
973d1d
-          g_print ("urisource-%s\n", *protocols);
973d1d
+          if (!rpm_format)
973d1d
+            g_print ("urisource-%s\n", *protocols);
973d1d
+          else
973d1d
+            g_print ("gstreamer1(urisource-%s)\n", *protocols);
973d1d
           ++protocols;
973d1d
         }
973d1d
         break;
973d1d
@@ -1400,7 +1634,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
973d1d
 }
973d1d
 
973d1d
 static void
973d1d
-print_plugin_automatic_install_info (GstPlugin * plugin)
973d1d
+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
973d1d
 {
973d1d
   GList *features, *l;
973d1d
 
973d1d
@@ -1419,11 +1653,15 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
973d1d
     if (feature_plugin == plugin) {
973d1d
       GstElementFactory *factory;
973d1d
 
973d1d
-      g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
973d1d
+      if (!rpm_format)
973d1d
+        g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
973d1d
+      else
973d1d
+        g_print ("gstreamer1(element-%s)\n",
973d1d
+            gst_plugin_feature_get_name (feature));
973d1d
 
973d1d
       factory = GST_ELEMENT_FACTORY (feature);
973d1d
-      print_plugin_automatic_install_info_protocols (factory);
973d1d
-      print_plugin_automatic_install_info_codecs (factory);
973d1d
+      print_plugin_automatic_install_info_protocols (factory, rpm_format);
973d1d
+      print_plugin_automatic_install_info_codecs (factory, rpm_format);
973d1d
     }
973d1d
     if (feature_plugin)
973d1d
       gst_object_unref (feature_plugin);
973d1d
@@ -1445,7 +1683,7 @@ print_all_plugin_automatic_install_info (void)
973d1d
     plugin = (GstPlugin *) (plugins->data);
973d1d
     plugins = g_list_next (plugins);
973d1d
 
973d1d
-    print_plugin_automatic_install_info (plugin);
973d1d
+    print_plugin_automatic_install_info (plugin, FALSE);
973d1d
   }
973d1d
   gst_plugin_list_free (orig_plugins);
973d1d
 }
973d1d
@@ -1457,6 +1695,7 @@ main (int argc, char *argv[])
973d1d
   gboolean do_print_blacklist = FALSE;
973d1d
   gboolean plugin_name = FALSE;
973d1d
   gboolean print_aii = FALSE;
973d1d
+  gboolean print_aii_rpm = FALSE;
973d1d
   gboolean uri_handlers = FALSE;
973d1d
   gboolean check_exists = FALSE;
973d1d
   gchar *min_version = NULL;
973d1d
@@ -1474,6 +1713,9 @@ main (int argc, char *argv[])
973d1d
               "or all plugins provide.\n                                       "
973d1d
               "Useful in connection with external automatic plugin "
973d1d
               "installation mechanisms"), NULL},
973d1d
+    {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
973d1d
+        N_("Print the machine-parsable list of features of a plugin in RPM "
973d1d
+              "Provides compatible-format"), NULL},
973d1d
     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
973d1d
         N_("List the plugin contents"), NULL},
973d1d
     {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
973d1d
@@ -1610,7 +1852,7 @@ main (int argc, char *argv[])
973d1d
       /* if there is such a plugin, print out info */
973d1d
       if (plugin) {
973d1d
         if (print_aii) {
973d1d
-          print_plugin_automatic_install_info (plugin);
973d1d
+          print_plugin_automatic_install_info (plugin, print_aii_rpm);
973d1d
         } else {
973d1d
           print_plugin_info (plugin);
973d1d
           print_plugin_features (plugin);
973d1d
@@ -1623,13 +1865,17 @@ main (int argc, char *argv[])
973d1d
 
973d1d
           if (plugin) {
973d1d
             if (print_aii) {
973d1d
-              print_plugin_automatic_install_info (plugin);
973d1d
+              print_plugin_automatic_install_info (plugin, print_aii_rpm);
973d1d
             } else {
973d1d
               print_plugin_info (plugin);
973d1d
               print_plugin_features (plugin);
973d1d
             }
973d1d
           } else {
973d1d
-            g_printerr (_("Could not load plugin file: %s\n"), error->message);
973d1d
+            if (!print_aii_rpm)
973d1d
+              g_print (_("Could not load plugin file: %s\n"), error->message);
973d1d
+            else
973d1d
+              g_printerr (_("Could not load plugin file: %s\n"),
973d1d
+                  error->message);
973d1d
             g_clear_error (&error);
973d1d
             return -1;
973d1d
           }
973d1d
-- 
973d1d
2.5.0
973d1d