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
7 tools/gst-inspect.c | 279 +++++++++++++++++++++++++++++++++++++++++---
8 1 file changed, 263 insertions(+), 16 deletions(-)
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
19 +print_gst_structure_append_field (GList * strings, const char *field)
23 + //g_message ("adding '%s' to the string", field);
25 + for (s = strings; s != NULL; s = s->next) {
26 + g_string_append (s->data, field);
31 +print_gst_structure_append_field_index (GList * strings, const char *field,
32 + guint num_items, guint offset)
37 + //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
39 + for (s = strings, i = 0; s != NULL; s = s->next, i++) {
41 + //g_message ("adding '%s' at '%d'", field, i);
42 + g_string_append (s->data, field);
51 +print_gst_structure_dup_fields (GList * strings, guint num_items)
58 + //g_message ("creating %d new items", num_items);
60 + new_items = g_list_length (strings) * (num_items - 1);
61 + for (i = 0; i < new_items; i++) {
64 + first = strings->data;
65 + s = g_string_new_len (first->str, first->len);
66 + strings = g_list_prepend (strings, s);
81 +field_get_type (const char *field_name)
83 + if (strstr (field_name, "version") != NULL)
84 + return FIELD_VERSION;
85 + if (strcmp (field_name, "layer") == 0)
87 + if (strcmp (field_name, "systemstream") == 0)
88 + return FIELD_SYSTEMSTREAM;
89 + if (strcmp (field_name, "variant") == 0)
90 + return FIELD_VARIANT;
96 +fields_type_compare (const char *a, const char *b)
98 + gint a_type, b_type;
100 + a_type = field_get_type (a);
101 + b_type = field_get_type (b);
102 + if (a_type < b_type)
104 + if (b_type < a_type)
110 +print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
112 + guint i, num_fields;
114 + GList *fields, *l, *strings;
117 + name = gst_structure_get_name (s);
119 + num_fields = gst_structure_n_fields (s);
122 + for (i = 0; i < num_fields; i++) {
123 + const char *field_name;
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);
132 + g_list_insert_sorted (fields, g_strdup (field_name),
133 + (GCompareFunc) fields_type_compare);
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, ')');
145 + strings = g_list_append (strings, string);
147 + for (l = fields; l != NULL; l = l->next) {
151 + field_name = l->data;
153 + type = gst_structure_get_field_type (s, field_name);
154 + //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
156 + if (type == G_TYPE_INT) {
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);
164 + } else if (type == G_TYPE_BOOLEAN) {
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);
172 + } else if (type == GST_TYPE_INT_RANGE) {
173 + const GValue *value;
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);
180 + strings = print_gst_structure_dup_fields (strings, max - min + 1);
182 + for (i = min; i <= max; i++) {
185 + field = g_strdup_printf ("(%s=%d)", field_name, i);
186 + print_gst_structure_append_field_index (strings, field, max - min + 1,
190 + } else if (type == GST_TYPE_LIST) {
191 + const GValue *value;
194 + value = gst_structure_get_value (s, field_name);
195 + num_items = gst_value_list_get_size (value);
197 + strings = print_gst_structure_dup_fields (strings, num_items);
199 + for (i = 0; i < num_items; i++) {
201 + const GValue *item_value;
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);
209 + } else if (type == G_TYPE_STRING) {
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);
218 + g_warning ("unhandled type! %s", g_type_name (type));
221 + g_free (field_name);
224 + g_list_free (fields);
226 + for (l = strings; l != NULL; l = l->next) {
228 + g_print ("%s\n", string->str);
229 + g_string_free (string, TRUE);
231 + g_list_free (strings);
234 /* NOTE: Not coloring output from automatic install functions, as their output
235 * is meant for machines, not humans.
238 -print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
239 +print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
240 + gboolean rpm_format)
242 GstPadDirection direction;
243 const gchar *type_name;
244 @@ -1966,6 +2183,13 @@ print_plugin_automatic_install_info_code
249 + /* Ignore NONE ranked plugins */
250 + if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) ==
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);
266 + s_str = gst_structure_to_string (s);
267 + g_print ("%s-%s\n", type_name, s_str);
270 + print_gst_structure_for_rpm (type_name, s);
273 gst_caps_unref (caps);
277 -print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
278 +print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
279 + gboolean rpm_format)
281 const gchar *const *protocols;
283 @@ -2019,13 +2248,19 @@ print_plugin_automatic_install_info_prot
284 switch (gst_element_factory_get_uri_type (factory)) {
286 while (*protocols != NULL) {
287 - g_print ("urisink-%s\n", *protocols);
289 + g_print ("urisink-%s\n", *protocols);
291 + g_print ("gstreamer1(urisink-%s)\n", *protocols);
296 while (*protocols != NULL) {
297 - g_print ("urisource-%s\n", *protocols);
299 + g_print ("urisource-%s\n", *protocols);
301 + g_print ("gstreamer1(urisource-%s)\n", *protocols);
305 @@ -2036,7 +2271,7 @@ print_plugin_automatic_install_info_prot
309 -print_plugin_automatic_install_info (GstPlugin * plugin)
310 +print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
314 @@ -2055,11 +2290,15 @@ print_plugin_automatic_install_info (Gst
315 if (feature_plugin == plugin) {
316 GstElementFactory *factory;
318 - g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
320 + g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
322 + g_print ("gstreamer1(element-%s)\n",
323 + gst_plugin_feature_get_name (feature));
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);
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);
337 - print_plugin_automatic_install_info (plugin);
338 + print_plugin_automatic_install_info (plugin, FALSE);
340 gst_plugin_list_free (orig_plugins);
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 */
364 - print_plugin_automatic_install_info (plugin);
365 + print_plugin_automatic_install_info (plugin, print_aii_rpm);
367 print_plugin_info (plugin);
368 print_plugin_status (plugin);
369 @@ -2378,13 +2621,16 @@ real_main (int argc, char *argv[])
373 - print_plugin_automatic_install_info (plugin);
374 + print_plugin_automatic_install_info (plugin, print_aii_rpm);
376 print_plugin_info (plugin);
377 print_plugin_status (plugin);
378 print_plugin_features (plugin);
381 + if (!print_aii_rpm)
382 + g_print (_("Could not load plugin file: %s\n"), error->message);
384 g_printerr (_("Could not load plugin file: %s\n"), error->message);
385 g_clear_error (&error);