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

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