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