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

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