]> git.pld-linux.org Git - packages/gstreamer.git/blob - gstreamer-inspect-rpm-format.patch
c1894a5e7b96b9a2166b60e5d3974f2ed8098e6b
[packages/gstreamer.git] / gstreamer-inspect-rpm-format.patch
1 diff -urp gstreamer-0.11.94.orig/tools/gst-inspect.c gstreamer-0.11.94/tools/gst-inspect.c
2 --- gstreamer-0.11.94.orig/tools/gst-inspect.c  2012-09-01 18:02:10.000000000 -0400
3 +++ gstreamer-0.11.94/tools/gst-inspect.c       2012-09-14 08:04:52.690369047 -0400
4 @@ -1350,8 +1350,225 @@ print_element_info (GstElementFactory *
5    return 0;
6  }
7  
8 +static void
9 +print_gst_structure_append_field (GList * strings, const char *field)
10 +{
11 +  GList *s;
12 +
13 +  //g_message ("adding '%s' to the string", field);
14 +
15 +  for (s = strings; s != NULL; s = s->next) {
16 +    g_string_append (s->data, field);
17 +  }
18 +}
19 +
20 +static void
21 +print_gst_structure_append_field_index (GList * strings, const char *field,
22 +    guint num_items, guint offset)
23 +{
24 +  GList *s;
25 +  guint i;
26 +
27 +  //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
28 +
29 +  for (s = strings, i = 0; s != NULL; s = s->next, i++) {
30 +    if (i == offset) {
31 +      //g_message ("adding '%s' at '%d'", field, i);
32 +      g_string_append (s->data, field);
33 +    }
34 +    if (i == num_items)
35 +      i = 0;
36 +  }
37 +
38 +}
39 +
40 +static GList *
41 +print_gst_structure_dup_fields (GList * strings, guint num_items)
42 +{
43 +  guint new_items, i;
44 +
45 +  if (num_items == 1)
46 +    return strings;
47 +
48 +  //g_message ("creating %d new items", num_items);
49 +
50 +  new_items = g_list_length (strings) * (num_items - 1);
51 +  for (i = 0; i < new_items; i++) {
52 +    GString *s, *first;
53 +
54 +    first = strings->data;
55 +    s = g_string_new_len (first->str, first->len);
56 +    strings = g_list_prepend (strings, s);
57 +  }
58 +
59 +  return strings;
60 +}
61 +
62 +enum
63 +{
64 +  FIELD_VERSION = 0,
65 +  FIELD_LAYER,
66 +  FIELD_VARIANT,
67 +  FIELD_SYSTEMSTREAM
68 +};
69 +
70 +static int
71 +field_get_type (const char *field_name)
72 +{
73 +  if (strstr (field_name, "version") != NULL)
74 +    return FIELD_VERSION;
75 +  if (strcmp (field_name, "layer") == 0)
76 +    return FIELD_LAYER;
77 +  if (strcmp (field_name, "systemstream") == 0)
78 +    return FIELD_SYSTEMSTREAM;
79 +  if (strcmp (field_name, "variant") == 0)
80 +    return FIELD_VARIANT;
81 +
82 +  return -1;
83 +}
84 +
85 +static gint
86 +fields_type_compare (const char *a, const char *b)
87 +{
88 +  gint a_type, b_type;
89 +
90 +  a_type = field_get_type (a);
91 +  b_type = field_get_type (b);
92 +  if (a_type < b_type)
93 +    return -1;
94 +  if (b_type < a_type)
95 +    return 1;
96 +  return 0;
97 +}
98 +
99 +static void
100 +print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
101 +{
102 +  guint i, num_fields;
103 +  const char *name;
104 +  GList *fields, *l, *strings;
105 +  GString *string;
106 +
107 +  name = gst_structure_get_name (s);
108 +  strings = NULL;
109 +  num_fields = gst_structure_n_fields (s);
110 +  fields = NULL;
111 +
112 +  for (i = 0; i < num_fields; i++) {
113 +    const char *field_name;
114 +
115 +    field_name = gst_structure_nth_field_name (s, i);
116 +    if (field_get_type (field_name) < 0) {
117 +      //g_message ("ignoring field named %s", field_name);
118 +      continue;
119 +    }
120 +
121 +    fields =
122 +        g_list_insert_sorted (fields, g_strdup (field_name),
123 +        (GCompareFunc) fields_type_compare);
124 +  }
125 +
126 +  /* Example:
127 +   * gstreamer1(decoder-video/mpeg)(mpegversion=1)()(64bit) */
128 +  string = g_string_new ("gstreamer1");
129 +  g_string_append_c (string, '(');
130 +  g_string_append (string, type_name);
131 +  g_string_append_c (string, '-');
132 +  g_string_append (string, name);
133 +  g_string_append_c (string, ')');
134 +
135 +  strings = g_list_append (strings, string);
136 +
137 +  for (l = fields; l != NULL; l = l->next) {
138 +    char *field_name;
139 +    GType type;
140 +
141 +    field_name = l->data;
142 +
143 +    type = gst_structure_get_field_type (s, field_name);
144 +    //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
145 +
146 +    if (type == G_TYPE_INT) {
147 +      char *field;
148 +      int value;
149 +
150 +      gst_structure_get_int (s, field_name, &value);
151 +      field = g_strdup_printf ("(%s=%d)", field_name, value);
152 +      print_gst_structure_append_field (strings, field);
153 +      g_free (field);
154 +    } else if (type == G_TYPE_BOOLEAN) {
155 +      char *field;
156 +      int value;
157 +
158 +      gst_structure_get_boolean (s, field_name, &value);
159 +      field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
160 +      print_gst_structure_append_field (strings, field);
161 +      g_free (field);
162 +    } else if (type == GST_TYPE_INT_RANGE) {
163 +      const GValue *value;
164 +      int min, max;
165 +
166 +      value = gst_structure_get_value (s, field_name);
167 +      min = gst_value_get_int_range_min (value);
168 +      max = gst_value_get_int_range_max (value);
169 +
170 +      strings = print_gst_structure_dup_fields (strings, max - min + 1);
171 +
172 +      for (i = min; i <= max; i++) {
173 +        char *field;
174 +
175 +        field = g_strdup_printf ("(%s=%d)", field_name, i);
176 +        print_gst_structure_append_field_index (strings, field, max - min + 1,
177 +            i - min);
178 +        g_free (field);
179 +      }
180 +    } else if (type == GST_TYPE_LIST) {
181 +      const GValue *value;
182 +      int num_items;
183 +
184 +      value = gst_structure_get_value (s, field_name);
185 +      num_items = gst_value_list_get_size (value);
186 +
187 +      strings = print_gst_structure_dup_fields (strings, num_items);
188 +
189 +      for (i = 0; i < num_items; i++) {
190 +        char *field;
191 +        const GValue *item_value;
192 +
193 +        item_value = gst_value_list_get_value (value, i);
194 +        field = g_strdup_printf ("(%s=%d)", field_name,
195 +            g_value_get_int (item_value));
196 +        print_gst_structure_append_field_index (strings, field, num_items, i);
197 +        g_free (field);
198 +      }
199 +    } else if (type == G_TYPE_STRING) {
200 +      char *field;
201 +      const char *value;
202 +
203 +      value = gst_structure_get_string (s, field_name);
204 +      field = g_strdup_printf ("(%s=%s)", field_name, value);
205 +      print_gst_structure_append_field (strings, field);
206 +      g_free (field);
207 +    } else {
208 +      g_warning ("unhandled type! %s", g_type_name (type));
209 +    }
210 +
211 +    g_free (field_name);
212 +  }
213 +
214 +  g_list_free (fields);
215 +
216 +  for (l = strings; l != NULL; l = l->next) {
217 +    string = l->data;
218 +    g_print ("%s\n", string->str);
219 +    g_string_free (string, TRUE);
220 +  }
221 +  g_list_free (strings);
222 +}
223 +
224  static void
225 -print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
226 +print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
227 +    gboolean rpm_format)
228  {
229    GstPadDirection direction;
230    const gchar *type_name;
231 @@ -1377,6 +1593,12 @@ print_plugin_automatic_install_info_code
232      return;
233    }
234  
235 +  if (rpm_format) {
236 +    /* Ignore NONE ranked plugins */
237 +       if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) == GST_RANK_NONE)
238 +      return;
239 +  }
240 +
241    /* decoder/demuxer sink pads should always be static and there should only
242     * be one, the same applies to encoders/muxers and source pads */
243    static_templates = gst_element_factory_get_static_pad_templates (factory);
244 @@ -1413,15 +1635,20 @@ print_plugin_automatic_install_info_code
245      gst_structure_remove_field (s, "rate");
246      gst_structure_remove_field (s, "depth");
247      gst_structure_remove_field (s, "clock-rate");
248 -    s_str = gst_structure_to_string (s);
249 -    g_print ("%s-%s\n", type_name, s_str);
250 -    g_free (s_str);
251 +    if (!rpm_format) {
252 +      s_str = gst_structure_to_string (s);
253 +      g_print ("%s-%s\n", type_name, s_str);
254 +      g_free (s_str);
255 +    } else {
256 +      print_gst_structure_for_rpm (type_name, s);
257 +    }
258    }
259    gst_caps_unref (caps);
260  }
261  
262  static void
263 -print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
264 +print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
265 +    gboolean rpm_format)
266  {
267    const gchar *const *protocols;
268  
269 @@ -1430,13 +1657,19 @@ print_plugin_automatic_install_info_prot
270      switch (gst_element_factory_get_uri_type (factory)) {
271        case GST_URI_SINK:
272          while (*protocols != NULL) {
273 -          g_print ("urisink-%s\n", *protocols);
274 +          if (!rpm_format)
275 +            g_print ("urisink-%s\n", *protocols);
276 +          else
277 +            g_print ("gstreamer1(urisink-%s)\n", *protocols);
278            ++protocols;
279          }
280          break;
281        case GST_URI_SRC:
282          while (*protocols != NULL) {
283 -          g_print ("urisource-%s\n", *protocols);
284 +          if (!rpm_format)
285 +            g_print ("urisource-%s\n", *protocols);
286 +          else
287 +            g_print ("gstreamer1(urisource-%s)\n", *protocols);
288            ++protocols;
289          }
290          break;
291 @@ -1447,7 +1680,7 @@ print_plugin_automatic_install_info_prot
292  }
293  
294  static void
295 -print_plugin_automatic_install_info (GstPlugin * plugin)
296 +print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
297  {
298    GList *features, *l;
299  
300 @@ -1466,11 +1699,15 @@ print_plugin_automatic_install_info (Gst
301      if (feature_plugin == plugin) {
302        GstElementFactory *factory;
303  
304 -      g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
305 +      if (!rpm_format)
306 +        g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
307 +      else
308 +        g_print ("gstreamer1(element-%s)\n",
309 +            gst_plugin_feature_get_name (feature));
310  
311        factory = GST_ELEMENT_FACTORY (feature);
312 -      print_plugin_automatic_install_info_protocols (factory);
313 -      print_plugin_automatic_install_info_codecs (factory);
314 +      print_plugin_automatic_install_info_protocols (factory, rpm_format);
315 +      print_plugin_automatic_install_info_codecs (factory, rpm_format);
316      }
317      if (feature_plugin)
318        gst_object_unref (feature_plugin);
319 @@ -1492,7 +1729,7 @@ print_all_plugin_automatic_install_info
320      plugin = (GstPlugin *) (plugins->data);
321      plugins = g_list_next (plugins);
322  
323 -    print_plugin_automatic_install_info (plugin);
324 +    print_plugin_automatic_install_info (plugin, FALSE);
325    }
326    gst_plugin_list_free (orig_plugins);
327  }
328 @@ -1504,6 +1741,7 @@ main (int argc, char *argv[])
329    gboolean do_print_blacklist = FALSE;
330    gboolean plugin_name = FALSE;
331    gboolean print_aii = FALSE;
332 +  gboolean print_aii_rpm = FALSE;
333    gboolean uri_handlers = FALSE;
334    gboolean check_exists = FALSE;
335    gchar *min_version = NULL;
336 @@ -1521,6 +1759,9 @@ main (int argc, char *argv[])
337                "or all plugins provide.\n                                       "
338                "Useful in connection with external automatic plugin "
339                "installation mechanisms"), NULL},
340 +    {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
341 +        N_("Print the machine-parsable list of features of a plugin in RPM "
342 +              "Provides compatible-format"), NULL},
343      {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
344          N_("List the plugin contents"), NULL},
345      {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
346 @@ -1650,7 +1891,7 @@ main (int argc, char *argv[])
347        /* if there is such a plugin, print out info */
348        if (plugin) {
349          if (print_aii) {
350 -          print_plugin_automatic_install_info (plugin);
351 +          print_plugin_automatic_install_info (plugin, print_aii_rpm);
352          } else {
353            print_plugin_info (plugin);
354            print_plugin_features (plugin);
355 @@ -1663,13 +1904,17 @@ main (int argc, char *argv[])
356  
357            if (plugin) {
358              if (print_aii) {
359 -              print_plugin_automatic_install_info (plugin);
360 +              print_plugin_automatic_install_info (plugin, print_aii_rpm);
361              } else {
362                print_plugin_info (plugin);
363                print_plugin_features (plugin);
364              }
365            } else {
366 -            g_printerr (_("Could not load plugin file: %s\n"), error->message);
367 +            if (!print_aii_rpm)
368 +              g_print (_("Could not load plugin file: %s\n"), error->message);
369 +            else
370 +              g_printerr (_("Could not load plugin file: %s\n"),
371 +                  error->message);
372              g_clear_error (&error);
373              return -1;
374            }
This page took 0.090416 seconds and 2 git commands to generate.