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

7d8976
From 642d0d6fef226fb89eaecf0016f8e5e333b9023e Mon Sep 17 00:00:00 2001
7d8976
From: Wim Taymans <wtaymans@redhat.com>
7d8976
Date: Tue, 23 Jun 2015 10:28:29 +0200
7d8976
Subject: [PATCH] gst-inspect: add mode to output RPM requires format
7d8976
7d8976
---
7d8976
 tools/gst-inspect.c | 279 +++++++++++++++++++++++++++++++++++++++++---
7d8976
 1 file changed, 263 insertions(+), 16 deletions(-)
7d8976
7d8976
diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
7d8976
index 8da042946..a057cba09 100644
7d8976
--- a/tools/gst-inspect.c
7d8976
+++ b/tools/gst-inspect.c
7d8976
@@ -394,7 +394,7 @@ print_object_properties_info (GObject * obj, GObjectClass * obj_class,
7d8976
 
7d8976
     first_flag = TRUE;
7d8976
     n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
7d8976
-    readable = ! !(param->flags & G_PARAM_READABLE);
7d8976
+    readable = !!(param->flags & G_PARAM_READABLE);
7d8976
     if (readable && obj != NULL) {
7d8976
       g_object_get_property (obj, param->name, &value);
7d8976
     } else {
7d8976
@@ -1739,11 +1739,228 @@ print_tracer_info (GstPluginFeature * feature, gboolean print_names)
7d8976
   return 0;
7d8976
 }
7d8976
 
7d8976
+static void
7d8976
+print_gst_structure_append_field (GList * strings, const char *field)
7d8976
+{
7d8976
+  GList *s;
7d8976
+
7d8976
+  //g_message ("adding '%s' to the string", field);
7d8976
+
7d8976
+  for (s = strings; s != NULL; s = s->next) {
7d8976
+    g_string_append (s->data, field);
7d8976
+  }
7d8976
+}
7d8976
+
7d8976
+static void
7d8976
+print_gst_structure_append_field_index (GList * strings, const char *field,
7d8976
+    guint num_items, guint offset)
7d8976
+{
7d8976
+  GList *s;
7d8976
+  guint i;
7d8976
+
7d8976
+  //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
7d8976
+
7d8976
+  for (s = strings, i = 0; s != NULL; s = s->next, i++) {
7d8976
+    if (i == offset) {
7d8976
+      //g_message ("adding '%s' at '%d'", field, i);
7d8976
+      g_string_append (s->data, field);
7d8976
+    }
7d8976
+    if (i == num_items)
7d8976
+      i = 0;
7d8976
+  }
7d8976
+
7d8976
+}
7d8976
+
7d8976
+static GList *
7d8976
+print_gst_structure_dup_fields (GList * strings, guint num_items)
7d8976
+{
7d8976
+  guint new_items, i;
7d8976
+
7d8976
+  if (num_items == 1)
7d8976
+    return strings;
7d8976
+
7d8976
+  //g_message ("creating %d new items", num_items);
7d8976
+
7d8976
+  new_items = g_list_length (strings) * (num_items - 1);
7d8976
+  for (i = 0; i < new_items; i++) {
7d8976
+    GString *s, *first;
7d8976
+
7d8976
+    first = strings->data;
7d8976
+    s = g_string_new_len (first->str, first->len);
7d8976
+    strings = g_list_prepend (strings, s);
7d8976
+  }
7d8976
+
7d8976
+  return strings;
7d8976
+}
7d8976
+
7d8976
+enum
7d8976
+{
7d8976
+  FIELD_VERSION = 0,
7d8976
+  FIELD_LAYER,
7d8976
+  FIELD_VARIANT,
7d8976
+  FIELD_SYSTEMSTREAM
7d8976
+};
7d8976
+
7d8976
+static int
7d8976
+field_get_type (const char *field_name)
7d8976
+{
7d8976
+  if (strstr (field_name, "version") != NULL)
7d8976
+    return FIELD_VERSION;
7d8976
+  if (strcmp (field_name, "layer") == 0)
7d8976
+    return FIELD_LAYER;
7d8976
+  if (strcmp (field_name, "systemstream") == 0)
7d8976
+    return FIELD_SYSTEMSTREAM;
7d8976
+  if (strcmp (field_name, "variant") == 0)
7d8976
+    return FIELD_VARIANT;
7d8976
+
7d8976
+  return -1;
7d8976
+}
7d8976
+
7d8976
+static gint
7d8976
+fields_type_compare (const char *a, const char *b)
7d8976
+{
7d8976
+  gint a_type, b_type;
7d8976
+
7d8976
+  a_type = field_get_type (a);
7d8976
+  b_type = field_get_type (b);
7d8976
+  if (a_type < b_type)
7d8976
+    return -1;
7d8976
+  if (b_type < a_type)
7d8976
+    return 1;
7d8976
+  return 0;
7d8976
+}
7d8976
+
7d8976
+static void
7d8976
+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
7d8976
+{
7d8976
+  guint i, num_fields;
7d8976
+  const char *name;
7d8976
+  GList *fields, *l, *strings;
7d8976
+  GString *string;
7d8976
+
7d8976
+  name = gst_structure_get_name (s);
7d8976
+  strings = NULL;
7d8976
+  num_fields = gst_structure_n_fields (s);
7d8976
+  fields = NULL;
7d8976
+
7d8976
+  for (i = 0; i < num_fields; i++) {
7d8976
+    const char *field_name;
7d8976
+
7d8976
+    field_name = gst_structure_nth_field_name (s, i);
7d8976
+    if (field_get_type (field_name) < 0) {
7d8976
+      //g_message ("ignoring field named %s", field_name);
7d8976
+      continue;
7d8976
+    }
7d8976
+
7d8976
+    fields =
7d8976
+        g_list_insert_sorted (fields, g_strdup (field_name),
7d8976
+        (GCompareFunc) fields_type_compare);
7d8976
+  }
7d8976
+
7d8976
+  /* Example:
7d8976
+   * gstreamer1(decoder-video/mpeg)(mpegversion=1)()(64bit) */
7d8976
+  string = g_string_new ("gstreamer1");
7d8976
+  g_string_append_c (string, '(');
7d8976
+  g_string_append (string, type_name);
7d8976
+  g_string_append_c (string, '-');
7d8976
+  g_string_append (string, name);
7d8976
+  g_string_append_c (string, ')');
7d8976
+
7d8976
+  strings = g_list_append (strings, string);
7d8976
+
7d8976
+  for (l = fields; l != NULL; l = l->next) {
7d8976
+    char *field_name;
7d8976
+    GType type;
7d8976
+
7d8976
+    field_name = l->data;
7d8976
+
7d8976
+    type = gst_structure_get_field_type (s, field_name);
7d8976
+    //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
7d8976
+
7d8976
+    if (type == G_TYPE_INT) {
7d8976
+      char *field;
7d8976
+      int value;
7d8976
+
7d8976
+      gst_structure_get_int (s, field_name, &value);
7d8976
+      field = g_strdup_printf ("(%s=%d)", field_name, value);
7d8976
+      print_gst_structure_append_field (strings, field);
7d8976
+      g_free (field);
7d8976
+    } else if (type == G_TYPE_BOOLEAN) {
7d8976
+      char *field;
7d8976
+      int value;
7d8976
+
7d8976
+      gst_structure_get_boolean (s, field_name, &value);
7d8976
+      field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
7d8976
+      print_gst_structure_append_field (strings, field);
7d8976
+      g_free (field);
7d8976
+    } else if (type == GST_TYPE_INT_RANGE) {
7d8976
+      const GValue *value;
7d8976
+      int min, max;
7d8976
+
7d8976
+      value = gst_structure_get_value (s, field_name);
7d8976
+      min = gst_value_get_int_range_min (value);
7d8976
+      max = gst_value_get_int_range_max (value);
7d8976
+
7d8976
+      strings = print_gst_structure_dup_fields (strings, max - min + 1);
7d8976
+
7d8976
+      for (i = min; i <= max; i++) {
7d8976
+        char *field;
7d8976
+
7d8976
+        field = g_strdup_printf ("(%s=%d)", field_name, i);
7d8976
+        print_gst_structure_append_field_index (strings, field, max - min + 1,
7d8976
+            i - min);
7d8976
+        g_free (field);
7d8976
+      }
7d8976
+    } else if (type == GST_TYPE_LIST) {
7d8976
+      const GValue *value;
7d8976
+      int num_items;
7d8976
+
7d8976
+      value = gst_structure_get_value (s, field_name);
7d8976
+      num_items = gst_value_list_get_size (value);
7d8976
+
7d8976
+      strings = print_gst_structure_dup_fields (strings, num_items);
7d8976
+
7d8976
+      for (i = 0; i < num_items; i++) {
7d8976
+        char *field;
7d8976
+        const GValue *item_value;
7d8976
+
7d8976
+        item_value = gst_value_list_get_value (value, i);
7d8976
+        field = g_strdup_printf ("(%s=%d)", field_name,
7d8976
+            g_value_get_int (item_value));
7d8976
+        print_gst_structure_append_field_index (strings, field, num_items, i);
7d8976
+        g_free (field);
7d8976
+      }
7d8976
+    } else if (type == G_TYPE_STRING) {
7d8976
+      char *field;
7d8976
+      const char *value;
7d8976
+
7d8976
+      value = gst_structure_get_string (s, field_name);
7d8976
+      field = g_strdup_printf ("(%s=%s)", field_name, value);
7d8976
+      print_gst_structure_append_field (strings, field);
7d8976
+      g_free (field);
7d8976
+    } else {
7d8976
+      g_warning ("unhandled type! %s", g_type_name (type));
7d8976
+    }
7d8976
+
7d8976
+    g_free (field_name);
7d8976
+  }
7d8976
+
7d8976
+  g_list_free (fields);
7d8976
+
7d8976
+  for (l = strings; l != NULL; l = l->next) {
7d8976
+    string = l->data;
7d8976
+    g_print ("%s\n", string->str);
7d8976
+    g_string_free (string, TRUE);
7d8976
+  }
7d8976
+  g_list_free (strings);
7d8976
+}
7d8976
+
7d8976
 /* NOTE: Not coloring output from automatic install functions, as their output
7d8976
  * is meant for machines, not humans.
7d8976
  */
7d8976
 static void
7d8976
-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
7d8976
+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
7d8976
+    gboolean rpm_format)
7d8976
 {
7d8976
   GstPadDirection direction;
7d8976
   const gchar *type_name;
7d8976
@@ -1769,6 +1986,13 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
7d8976
     return;
7d8976
   }
7d8976
 
7d8976
+  if (rpm_format) {
7d8976
+    /* Ignore NONE ranked plugins */
7d8976
+    if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) ==
7d8976
+        GST_RANK_NONE)
7d8976
+      return;
7d8976
+  }
7d8976
+
7d8976
   /* decoder/demuxer sink pads should always be static and there should only
7d8976
    * be one, the same applies to encoders/muxers and source pads */
7d8976
   static_templates = gst_element_factory_get_static_pad_templates (factory);
7d8976
@@ -1805,15 +2029,20 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
7d8976
     gst_structure_remove_field (s, "rate");
7d8976
     gst_structure_remove_field (s, "depth");
7d8976
     gst_structure_remove_field (s, "clock-rate");
7d8976
-    s_str = gst_structure_to_string (s);
7d8976
-    g_print ("%s-%s\n", type_name, s_str);
7d8976
-    g_free (s_str);
7d8976
+    if (!rpm_format) {
7d8976
+      s_str = gst_structure_to_string (s);
7d8976
+      g_print ("%s-%s\n", type_name, s_str);
7d8976
+      g_free (s_str);
7d8976
+    } else {
7d8976
+      print_gst_structure_for_rpm (type_name, s);
7d8976
+    }
7d8976
   }
7d8976
   gst_caps_unref (caps);
7d8976
 }
7d8976
 
7d8976
 static void
7d8976
-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
7d8976
+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
7d8976
+    gboolean rpm_format)
7d8976
 {
7d8976
   const gchar *const *protocols;
7d8976
 
7d8976
@@ -1822,13 +2051,19 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
7d8976
     switch (gst_element_factory_get_uri_type (factory)) {
7d8976
       case GST_URI_SINK:
7d8976
         while (*protocols != NULL) {
7d8976
-          g_print ("urisink-%s\n", *protocols);
7d8976
+          if (!rpm_format)
7d8976
+            g_print ("urisink-%s\n", *protocols);
7d8976
+          else
7d8976
+            g_print ("gstreamer1(urisink-%s)\n", *protocols);
7d8976
           ++protocols;
7d8976
         }
7d8976
         break;
7d8976
       case GST_URI_SRC:
7d8976
         while (*protocols != NULL) {
7d8976
-          g_print ("urisource-%s\n", *protocols);
7d8976
+          if (!rpm_format)
7d8976
+            g_print ("urisource-%s\n", *protocols);
7d8976
+          else
7d8976
+            g_print ("gstreamer1(urisource-%s)\n", *protocols);
7d8976
           ++protocols;
7d8976
         }
7d8976
         break;
7d8976
@@ -1839,7 +2074,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
7d8976
 }
7d8976
 
7d8976
 static void
7d8976
-print_plugin_automatic_install_info (GstPlugin * plugin)
7d8976
+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
7d8976
 {
7d8976
   GList *features, *l;
7d8976
 
7d8976
@@ -1858,11 +2093,15 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
7d8976
     if (feature_plugin == plugin) {
7d8976
       GstElementFactory *factory;
7d8976
 
7d8976
-      g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
7d8976
+      if (!rpm_format)
7d8976
+        g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
7d8976
+      else
7d8976
+        g_print ("gstreamer1(element-%s)\n",
7d8976
+            gst_plugin_feature_get_name (feature));
7d8976
 
7d8976
       factory = GST_ELEMENT_FACTORY (feature);
7d8976
-      print_plugin_automatic_install_info_protocols (factory);
7d8976
-      print_plugin_automatic_install_info_codecs (factory);
7d8976
+      print_plugin_automatic_install_info_protocols (factory, rpm_format);
7d8976
+      print_plugin_automatic_install_info_codecs (factory, rpm_format);
7d8976
     }
7d8976
     if (feature_plugin)
7d8976
       gst_object_unref (feature_plugin);
7d8976
@@ -1884,7 +2123,7 @@ print_all_plugin_automatic_install_info (void)
7d8976
     plugin = (GstPlugin *) (plugins->data);
7d8976
     plugins = g_list_next (plugins);
7d8976
 
7d8976
-    print_plugin_automatic_install_info (plugin);
7d8976
+    print_plugin_automatic_install_info (plugin, FALSE);
7d8976
   }
7d8976
   gst_plugin_list_free (orig_plugins);
7d8976
 }
7d8976
@@ -1951,6 +2190,7 @@ main (int argc, char *argv[])
7d8976
   gboolean do_print_blacklist = FALSE;
7d8976
   gboolean plugin_name = FALSE;
7d8976
   gboolean print_aii = FALSE;
7d8976
+  gboolean print_aii_rpm = FALSE;
7d8976
   gboolean uri_handlers = FALSE;
7d8976
   gboolean check_exists = FALSE;
7d8976
   gboolean color_always = FALSE;
7d8976
@@ -1972,6 +2212,9 @@ main (int argc, char *argv[])
7d8976
               "or all plugins provide.\n                                       "
7d8976
               "Useful in connection with external automatic plugin "
7d8976
               "installation mechanisms"), NULL},
7d8976
+    {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
7d8976
+        N_("Print the machine-parsable list of features of a plugin in RPM "
7d8976
+              "Provides compatible-format"), NULL},
7d8976
     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
7d8976
         N_("List the plugin contents"), NULL},
7d8976
     {"types", 't', 0, G_OPTION_ARG_STRING, &types,
7d8976
@@ -2135,7 +2378,7 @@ main (int argc, char *argv[])
7d8976
       /* if there is such a plugin, print out info */
7d8976
       if (plugin) {
7d8976
         if (print_aii) {
7d8976
-          print_plugin_automatic_install_info (plugin);
7d8976
+          print_plugin_automatic_install_info (plugin, print_aii_rpm);
7d8976
         } else {
7d8976
           print_plugin_info (plugin);
7d8976
           print_plugin_features (plugin);
7d8976
@@ -2148,13 +2391,17 @@ main (int argc, char *argv[])
7d8976
 
7d8976
           if (plugin) {
7d8976
             if (print_aii) {
7d8976
-              print_plugin_automatic_install_info (plugin);
7d8976
+              print_plugin_automatic_install_info (plugin, print_aii_rpm);
7d8976
             } else {
7d8976
               print_plugin_info (plugin);
7d8976
               print_plugin_features (plugin);
7d8976
             }
7d8976
           } else {
7d8976
-            g_printerr (_("Could not load plugin file: %s\n"), error->message);
7d8976
+            if (!print_aii_rpm)
7d8976
+              g_print (_("Could not load plugin file: %s\n"), error->message);
7d8976
+            else
7d8976
+              g_printerr (_("Could not load plugin file: %s\n"),
7d8976
+                  error->message);
7d8976
             g_clear_error (&error);
7d8976
             exit_code = -1;
7d8976
             goto done;
7d8976
-- 
7d8976
2.26.2
7d8976