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

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