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