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

6ce7fb
From e4a4294f53d25bc3b5699cace74de4f49062a2ee Mon Sep 17 00:00:00 2001
6ce7fb
From: Bastien Nocera <hadess@hadess.net>
6ce7fb
Date: Wed, 11 Nov 2009 13:53:46 +0000
6ce7fb
Subject: [PATCH] Add RPM provides output to gst-inspect
6ce7fb
6ce7fb
---
6ce7fb
 tools/gst-inspect.c |  275 ++++++++++++++++++++++++++++++++++++++++++++++++---
6ce7fb
 1 files changed, 260 insertions(+), 15 deletions(-)
6ce7fb
6ce7fb
diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
6ce7fb
index c86285e..80b2456 100644
6ce7fb
--- a/tools/gst-inspect.c
6ce7fb
+++ b/tools/gst-inspect.c
6ce7fb
@@ -1408,9 +1408,225 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
6ce7fb
   return 0;
6ce7fb
 }
6ce7fb
 
6ce7fb
+static void
6ce7fb
+print_gst_structure_append_field (GList * strings, const char *field)
6ce7fb
+{
6ce7fb
+  GList *s;
6ce7fb
+
6ce7fb
+  //g_message ("adding '%s' to the string", field);
6ce7fb
+
6ce7fb
+  for (s = strings; s != NULL; s = s->next) {
6ce7fb
+    g_string_append (s->data, field);
6ce7fb
+  }
6ce7fb
+}
6ce7fb
+
6ce7fb
+static void
6ce7fb
+print_gst_structure_append_field_index (GList * strings, const char *field,
6ce7fb
+    guint num_items, guint offset)
6ce7fb
+{
6ce7fb
+  GList *s;
6ce7fb
+  guint i;
6ce7fb
+
6ce7fb
+  //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
6ce7fb
+
6ce7fb
+  for (s = strings, i = 0; s != NULL; s = s->next, i++) {
6ce7fb
+    if (i == offset) {
6ce7fb
+      //g_message ("adding '%s' at '%d'", field, i);
6ce7fb
+      g_string_append (s->data, field);
6ce7fb
+    }
6ce7fb
+    if (i == num_items)
6ce7fb
+      i = 0;
6ce7fb
+  }
6ce7fb
+
6ce7fb
+}
6ce7fb
+
6ce7fb
+static GList *
6ce7fb
+print_gst_structure_dup_fields (GList * strings, guint num_items)
6ce7fb
+{
6ce7fb
+  guint new_items, i;
6ce7fb
+
6ce7fb
+  if (num_items == 1)
6ce7fb
+    return strings;
6ce7fb
+
6ce7fb
+  //g_message ("creating %d new items", num_items);
6ce7fb
+
6ce7fb
+  new_items = g_list_length (strings) * (num_items - 1);
6ce7fb
+  for (i = 0; i < new_items; i++) {
6ce7fb
+    GString *s, *first;
6ce7fb
+
6ce7fb
+    first = strings->data;
6ce7fb
+    s = g_string_new_len (first->str, first->len);
6ce7fb
+    strings = g_list_prepend (strings, s);
6ce7fb
+  }
6ce7fb
+
6ce7fb
+  return strings;
6ce7fb
+}
6ce7fb
+
6ce7fb
+enum
6ce7fb
+{
6ce7fb
+  FIELD_VERSION = 0,
6ce7fb
+  FIELD_LAYER,
6ce7fb
+  FIELD_VARIANT,
6ce7fb
+  FIELD_SYSTEMSTREAM
6ce7fb
+};
6ce7fb
+
6ce7fb
+static int
6ce7fb
+field_get_type (const char *field_name)
6ce7fb
+{
6ce7fb
+  if (strstr (field_name, "version") != NULL)
6ce7fb
+    return FIELD_VERSION;
6ce7fb
+  if (strcmp (field_name, "layer") == 0)
6ce7fb
+    return FIELD_LAYER;
6ce7fb
+  if (strcmp (field_name, "systemstream") == 0)
6ce7fb
+    return FIELD_SYSTEMSTREAM;
6ce7fb
+  if (strcmp (field_name, "variant") == 0)
6ce7fb
+    return FIELD_VARIANT;
6ce7fb
+
6ce7fb
+  return -1;
6ce7fb
+}
6ce7fb
+
6ce7fb
+static gint
6ce7fb
+fields_type_compare (const char *a, const char *b)
6ce7fb
+{
6ce7fb
+  gint a_type, b_type;
6ce7fb
+
6ce7fb
+  a_type = field_get_type (a);
6ce7fb
+  b_type = field_get_type (b);
6ce7fb
+  if (a_type < b_type)
6ce7fb
+    return -1;
6ce7fb
+  if (b_type < a_type)
6ce7fb
+    return 1;
6ce7fb
+  return 0;
6ce7fb
+}
6ce7fb
 
6ce7fb
 static void
6ce7fb
-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
6ce7fb
+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
6ce7fb
+{
6ce7fb
+  guint i, num_fields;
6ce7fb
+  const char *name;
6ce7fb
+  GList *fields, *l, *strings;
6ce7fb
+  GString *string;
6ce7fb
+
6ce7fb
+  name = gst_structure_get_name (s);
6ce7fb
+  strings = NULL;
6ce7fb
+  num_fields = gst_structure_n_fields (s);
6ce7fb
+  fields = NULL;
6ce7fb
+
6ce7fb
+  for (i = 0; i < num_fields; i++) {
6ce7fb
+    const char *field_name;
6ce7fb
+
6ce7fb
+    field_name = gst_structure_nth_field_name (s, i);
6ce7fb
+    if (field_get_type (field_name) < 0) {
6ce7fb
+      //g_message ("ignoring field named %s", field_name);
6ce7fb
+      continue;
6ce7fb
+    }
6ce7fb
+
6ce7fb
+    fields =
6ce7fb
+        g_list_insert_sorted (fields, g_strdup (field_name),
6ce7fb
+        (GCompareFunc) fields_type_compare);
6ce7fb
+  }
6ce7fb
+
6ce7fb
+  /* Example:
6ce7fb
+   * gstreamer0.10(decoder-video/mpeg)(mpegversion=1)()(64bit) */
6ce7fb
+  string = g_string_new ("gstreamer0.10");
6ce7fb
+  g_string_append_c (string, '(');
6ce7fb
+  g_string_append (string, type_name);
6ce7fb
+  g_string_append_c (string, '-');
6ce7fb
+  g_string_append (string, name);
6ce7fb
+  g_string_append_c (string, ')');
6ce7fb
+
6ce7fb
+  strings = g_list_append (strings, string);
6ce7fb
+
6ce7fb
+  for (l = fields; l != NULL; l = l->next) {
6ce7fb
+    char *field_name;
6ce7fb
+    GType type;
6ce7fb
+
6ce7fb
+    field_name = l->data;
6ce7fb
+
6ce7fb
+    type = gst_structure_get_field_type (s, field_name);
6ce7fb
+    //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
6ce7fb
+
6ce7fb
+    if (type == G_TYPE_INT) {
6ce7fb
+      char *field;
6ce7fb
+      int value;
6ce7fb
+
6ce7fb
+      gst_structure_get_int (s, field_name, &value);
6ce7fb
+      field = g_strdup_printf ("(%s=%d)", field_name, value);
6ce7fb
+      print_gst_structure_append_field (strings, field);
6ce7fb
+      g_free (field);
6ce7fb
+    } else if (type == G_TYPE_BOOLEAN) {
6ce7fb
+      char *field;
6ce7fb
+      int value;
6ce7fb
+
6ce7fb
+      gst_structure_get_boolean (s, field_name, &value);
6ce7fb
+      field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
6ce7fb
+      print_gst_structure_append_field (strings, field);
6ce7fb
+      g_free (field);
6ce7fb
+    } else if (type == GST_TYPE_INT_RANGE) {
6ce7fb
+      const GValue *value;
6ce7fb
+      int min, max;
6ce7fb
+
6ce7fb
+      value = gst_structure_get_value (s, field_name);
6ce7fb
+      min = gst_value_get_int_range_min (value);
6ce7fb
+      max = gst_value_get_int_range_max (value);
6ce7fb
+
6ce7fb
+      strings = print_gst_structure_dup_fields (strings, max - min + 1);
6ce7fb
+
6ce7fb
+      for (i = min; i <= max; i++) {
6ce7fb
+        char *field;
6ce7fb
+
6ce7fb
+        field = g_strdup_printf ("(%s=%d)", field_name, i);
6ce7fb
+        print_gst_structure_append_field_index (strings, field, max - min + 1,
6ce7fb
+            i - min);
6ce7fb
+        g_free (field);
6ce7fb
+      }
6ce7fb
+    } else if (type == GST_TYPE_LIST) {
6ce7fb
+      const GValue *value;
6ce7fb
+      int num_items;
6ce7fb
+
6ce7fb
+      value = gst_structure_get_value (s, field_name);
6ce7fb
+      num_items = gst_value_list_get_size (value);
6ce7fb
+
6ce7fb
+      strings = print_gst_structure_dup_fields (strings, num_items);
6ce7fb
+
6ce7fb
+      for (i = 0; i < num_items; i++) {
6ce7fb
+        char *field;
6ce7fb
+        const GValue *item_value;
6ce7fb
+
6ce7fb
+        item_value = gst_value_list_get_value (value, i);
6ce7fb
+        field = g_strdup_printf ("(%s=%d)", field_name,
6ce7fb
+            g_value_get_int (item_value));
6ce7fb
+        print_gst_structure_append_field_index (strings, field, num_items, i);
6ce7fb
+        g_free (field);
6ce7fb
+      }
6ce7fb
+    } else if (type == G_TYPE_STRING) {
6ce7fb
+      char *field;
6ce7fb
+      const char *value;
6ce7fb
+
6ce7fb
+      value = gst_structure_get_string (s, field_name);
6ce7fb
+      field = g_strdup_printf ("(%s=%s)", field_name, value);
6ce7fb
+      print_gst_structure_append_field (strings, field);
6ce7fb
+      g_free (field);
6ce7fb
+    } else {
6ce7fb
+      g_warning ("unhandled type! %s", g_type_name (type));
6ce7fb
+    }
6ce7fb
+
6ce7fb
+    g_free (field_name);
6ce7fb
+  }
6ce7fb
+
6ce7fb
+  g_list_free (fields);
6ce7fb
+
6ce7fb
+  for (l = strings; l != NULL; l = l->next) {
6ce7fb
+    string = l->data;
6ce7fb
+    g_print ("%s\n", string->str);
6ce7fb
+    g_string_free (string, TRUE);
6ce7fb
+  }
6ce7fb
+  g_list_free (strings);
6ce7fb
+}
6ce7fb
+
6ce7fb
+static void
6ce7fb
+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
6ce7fb
+    gboolean rpm_format)
6ce7fb
 {
6ce7fb
   GstPadDirection direction;
6ce7fb
   const gchar *type_name;
6ce7fb
@@ -1435,6 +1651,12 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
6ce7fb
     return;
6ce7fb
   }
6ce7fb
 
6ce7fb
+  if (rpm_format) {
6ce7fb
+    /* Ignore NONE ranked plugins */
6ce7fb
+    if (GST_PLUGIN_FEATURE (factory)->rank == GST_RANK_NONE)
6ce7fb
+      return;
6ce7fb
+  }
6ce7fb
+
6ce7fb
   /* decoder/demuxer sink pads should always be static and there should only
6ce7fb
    * be one, the same applies to encoders/muxers and source pads */
6ce7fb
   static_templates = gst_element_factory_get_static_pad_templates (factory);
6ce7fb
@@ -1471,15 +1693,20 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
6ce7fb
     gst_structure_remove_field (s, "rate");
6ce7fb
     gst_structure_remove_field (s, "depth");
6ce7fb
     gst_structure_remove_field (s, "clock-rate");
6ce7fb
-    s_str = gst_structure_to_string (s);
6ce7fb
-    g_print ("%s-%s\n", type_name, s_str);
6ce7fb
-    g_free (s_str);
6ce7fb
+    if (!rpm_format) {
6ce7fb
+      s_str = gst_structure_to_string (s);
6ce7fb
+      g_print ("%s-%s\n", type_name, s_str);
6ce7fb
+      g_free (s_str);
6ce7fb
+    } else {
6ce7fb
+      print_gst_structure_for_rpm (type_name, s);
6ce7fb
+    }
6ce7fb
   }
6ce7fb
   gst_caps_unref (caps);
6ce7fb
 }
6ce7fb
 
6ce7fb
 static void
6ce7fb
-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
6ce7fb
+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
6ce7fb
+    gboolean rpm_format)
6ce7fb
 {
6ce7fb
   gchar **protocols, **p;
6ce7fb
 
6ce7fb
@@ -1488,11 +1715,17 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
6ce7fb
     switch (gst_element_factory_get_uri_type (factory)) {
6ce7fb
       case GST_URI_SINK:
6ce7fb
         for (p = protocols; *p != NULL; ++p)
6ce7fb
-          g_print ("urisink-%s\n", *p);
6ce7fb
+          if (!rpm_format)
6ce7fb
+            g_print ("urisink-%s\n", *p);
6ce7fb
+          else
6ce7fb
+            g_print ("gstreamer0.10(urisink-%s)\n", *p);
6ce7fb
         break;
6ce7fb
       case GST_URI_SRC:
6ce7fb
         for (p = protocols; *p != NULL; ++p)
6ce7fb
-          g_print ("urisource-%s\n", *p);
6ce7fb
+          if (!rpm_format)
6ce7fb
+            g_print ("urisource-%s\n", *p);
6ce7fb
+          else
6ce7fb
+            g_print ("gstreamer0.10(urisource-%s)\n", *p);
6ce7fb
         break;
6ce7fb
       default:
6ce7fb
         break;
6ce7fb
@@ -1502,7 +1735,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
6ce7fb
 }
6ce7fb
 
6ce7fb
 static void
6ce7fb
-print_plugin_automatic_install_info (GstPlugin * plugin)
6ce7fb
+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
6ce7fb
 {
6ce7fb
   const gchar *plugin_name;
6ce7fb
   GList *features, *l;
6ce7fb
@@ -1522,11 +1755,15 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
6ce7fb
     if (g_str_equal (plugin_name, feature->plugin_name)) {
6ce7fb
       GstElementFactory *factory;
6ce7fb
 
6ce7fb
-      g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
6ce7fb
+      if (!rpm_format)
6ce7fb
+        g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
6ce7fb
+      else
6ce7fb
+        g_print ("gstreamer0.10(element-%s)\n",
6ce7fb
+            gst_plugin_feature_get_name (feature));
6ce7fb
 
6ce7fb
       factory = GST_ELEMENT_FACTORY (feature);
6ce7fb
-      print_plugin_automatic_install_info_protocols (factory);
6ce7fb
-      print_plugin_automatic_install_info_codecs (factory);
6ce7fb
+      print_plugin_automatic_install_info_protocols (factory, rpm_format);
6ce7fb
+      print_plugin_automatic_install_info_codecs (factory, rpm_format);
6ce7fb
     }
6ce7fb
   }
6ce7fb
 
6ce7fb
@@ -1546,7 +1783,7 @@ print_all_plugin_automatic_install_info (void)
6ce7fb
     plugin = (GstPlugin *) (plugins->data);
6ce7fb
     plugins = g_list_next (plugins);
6ce7fb
 
6ce7fb
-    print_plugin_automatic_install_info (plugin);
6ce7fb
+    print_plugin_automatic_install_info (plugin, FALSE);
6ce7fb
   }
6ce7fb
   gst_plugin_list_free (orig_plugins);
6ce7fb
 }
6ce7fb
@@ -1558,6 +1795,7 @@ main (int argc, char *argv[])
6ce7fb
   gboolean do_print_blacklist = FALSE;
6ce7fb
   gboolean plugin_name = FALSE;
6ce7fb
   gboolean print_aii = FALSE;
6ce7fb
+  gboolean print_aii_rpm = FALSE;
6ce7fb
   gboolean uri_handlers = FALSE;
6ce7fb
 #ifndef GST_DISABLE_OPTION_PARSING
6ce7fb
   GOptionEntry options[] = {
6ce7fb
@@ -1570,6 +1808,9 @@ main (int argc, char *argv[])
6ce7fb
               "or all plugins provide.\n                                       "
6ce7fb
               "Useful in connection with external automatic plugin "
6ce7fb
               "installation mechanisms"), NULL},
6ce7fb
+    {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
6ce7fb
+        N_("Print the machine-parsable list of features of a plugin in RPM "
6ce7fb
+              "Provides compatible-format"), NULL},
6ce7fb
     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
6ce7fb
         N_("List the plugin contents"), NULL},
6ce7fb
     {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
6ce7fb
@@ -1658,7 +1899,7 @@ main (int argc, char *argv[])
6ce7fb
       /* if there is such a plugin, print out info */
6ce7fb
       if (plugin) {
6ce7fb
         if (print_aii) {
6ce7fb
-          print_plugin_automatic_install_info (plugin);
6ce7fb
+          print_plugin_automatic_install_info (plugin, print_aii_rpm);
6ce7fb
         } else {
6ce7fb
           print_plugin_info (plugin);
6ce7fb
           print_plugin_features (plugin);
6ce7fb
@@ -1671,13 +1912,17 @@ main (int argc, char *argv[])
6ce7fb
 
6ce7fb
           if (plugin) {
6ce7fb
             if (print_aii) {
6ce7fb
-              print_plugin_automatic_install_info (plugin);
6ce7fb
+              print_plugin_automatic_install_info (plugin, print_aii_rpm);
6ce7fb
             } else {
6ce7fb
               print_plugin_info (plugin);
6ce7fb
               print_plugin_features (plugin);
6ce7fb
             }
6ce7fb
           } else {
6ce7fb
-            g_print (_("Could not load plugin file: %s\n"), error->message);
6ce7fb
+            if (!print_aii_rpm)
6ce7fb
+              g_print (_("Could not load plugin file: %s\n"), error->message);
6ce7fb
+            else
6ce7fb
+              g_printerr (_("Could not load plugin file: %s\n"),
6ce7fb
+                  error->message);
6ce7fb
             g_error_free (error);
6ce7fb
             return -1;
6ce7fb
           }
6ce7fb
-- 
6ce7fb
1.7.4.1
6ce7fb