1 From e4a4294f53d25bc3b5699cace74de4f49062a2ee Mon Sep 17 00:00:00 2001
2 From: Bastien Nocera <hadess@hadess.net>
3 Date: Wed, 11 Nov 2009 13:53:46 +0000
4 Subject: [PATCH] Add RPM provides output to gst-inspect
7 tools/gst-inspect.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++---
8 1 files changed, 260 insertions(+), 15 deletions(-)
10 diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
11 index c86285e..80b2456 100644
12 --- a/tools/gst-inspect.c
13 +++ b/tools/gst-inspect.c
14 @@ -1408,9 +1408,225 @@ print_element_info (GstElementFactory * factory, gboolean print_names)
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_plugin_automatic_install_info_codecs (GstElementFactory * factory)
111 +print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
113 + guint i, num_fields;
115 + GList *fields, *l, *strings;
118 + name = gst_structure_get_name (s);
120 + num_fields = gst_structure_n_fields (s);
123 + for (i = 0; i < num_fields; i++) {
124 + const char *field_name;
126 + field_name = gst_structure_nth_field_name (s, i);
127 + if (field_get_type (field_name) < 0) {
128 + //g_message ("ignoring field named %s", field_name);
133 + g_list_insert_sorted (fields, g_strdup (field_name),
134 + (GCompareFunc) fields_type_compare);
138 + * gstreamer0.10(decoder-video/mpeg)(mpegversion=1)()(64bit) */
139 + string = g_string_new ("gstreamer0.10");
140 + g_string_append_c (string, '(');
141 + g_string_append (string, type_name);
142 + g_string_append_c (string, '-');
143 + g_string_append (string, name);
144 + g_string_append_c (string, ')');
146 + strings = g_list_append (strings, string);
148 + for (l = fields; l != NULL; l = l->next) {
152 + field_name = l->data;
154 + type = gst_structure_get_field_type (s, field_name);
155 + //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
157 + if (type == G_TYPE_INT) {
161 + gst_structure_get_int (s, field_name, &value);
162 + field = g_strdup_printf ("(%s=%d)", field_name, value);
163 + print_gst_structure_append_field (strings, field);
165 + } else if (type == G_TYPE_BOOLEAN) {
169 + gst_structure_get_boolean (s, field_name, &value);
170 + field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
171 + print_gst_structure_append_field (strings, field);
173 + } else if (type == GST_TYPE_INT_RANGE) {
174 + const GValue *value;
177 + value = gst_structure_get_value (s, field_name);
178 + min = gst_value_get_int_range_min (value);
179 + max = gst_value_get_int_range_max (value);
181 + strings = print_gst_structure_dup_fields (strings, max - min + 1);
183 + for (i = min; i <= max; i++) {
186 + field = g_strdup_printf ("(%s=%d)", field_name, i);
187 + print_gst_structure_append_field_index (strings, field, max - min + 1,
191 + } else if (type == GST_TYPE_LIST) {
192 + const GValue *value;
195 + value = gst_structure_get_value (s, field_name);
196 + num_items = gst_value_list_get_size (value);
198 + strings = print_gst_structure_dup_fields (strings, num_items);
200 + for (i = 0; i < num_items; i++) {
202 + const GValue *item_value;
204 + item_value = gst_value_list_get_value (value, i);
205 + field = g_strdup_printf ("(%s=%d)", field_name,
206 + g_value_get_int (item_value));
207 + print_gst_structure_append_field_index (strings, field, num_items, i);
210 + } else if (type == G_TYPE_STRING) {
214 + value = gst_structure_get_string (s, field_name);
215 + field = g_strdup_printf ("(%s=%s)", field_name, value);
216 + print_gst_structure_append_field (strings, field);
219 + g_warning ("unhandled type! %s", g_type_name (type));
222 + g_free (field_name);
225 + g_list_free (fields);
227 + for (l = strings; l != NULL; l = l->next) {
229 + g_print ("%s\n", string->str);
230 + g_string_free (string, TRUE);
232 + g_list_free (strings);
236 +print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
237 + gboolean rpm_format)
239 GstPadDirection direction;
240 const gchar *type_name;
241 @@ -1435,6 +1651,12 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
246 + /* Ignore NONE ranked plugins */
247 + if (GST_PLUGIN_FEATURE (factory)->rank == GST_RANK_NONE)
251 /* decoder/demuxer sink pads should always be static and there should only
252 * be one, the same applies to encoders/muxers and source pads */
253 static_templates = gst_element_factory_get_static_pad_templates (factory);
254 @@ -1471,15 +1693,20 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
255 gst_structure_remove_field (s, "rate");
256 gst_structure_remove_field (s, "depth");
257 gst_structure_remove_field (s, "clock-rate");
258 - s_str = gst_structure_to_string (s);
259 - g_print ("%s-%s\n", type_name, s_str);
262 + s_str = gst_structure_to_string (s);
263 + g_print ("%s-%s\n", type_name, s_str);
266 + print_gst_structure_for_rpm (type_name, s);
269 gst_caps_unref (caps);
273 -print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
274 +print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
275 + gboolean rpm_format)
277 gchar **protocols, **p;
279 @@ -1488,11 +1715,17 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
280 switch (gst_element_factory_get_uri_type (factory)) {
282 for (p = protocols; *p != NULL; ++p)
283 - g_print ("urisink-%s\n", *p);
285 + g_print ("urisink-%s\n", *p);
287 + g_print ("gstreamer0.10(urisink-%s)\n", *p);
290 for (p = protocols; *p != NULL; ++p)
291 - g_print ("urisource-%s\n", *p);
293 + g_print ("urisource-%s\n", *p);
295 + g_print ("gstreamer0.10(urisource-%s)\n", *p);
299 @@ -1502,7 +1735,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
303 -print_plugin_automatic_install_info (GstPlugin * plugin)
304 +print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
306 const gchar *plugin_name;
308 @@ -1522,11 +1755,15 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
309 if (g_str_equal (plugin_name, feature->plugin_name)) {
310 GstElementFactory *factory;
312 - g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
314 + g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
316 + g_print ("gstreamer0.10(element-%s)\n",
317 + gst_plugin_feature_get_name (feature));
319 factory = GST_ELEMENT_FACTORY (feature);
320 - print_plugin_automatic_install_info_protocols (factory);
321 - print_plugin_automatic_install_info_codecs (factory);
322 + print_plugin_automatic_install_info_protocols (factory, rpm_format);
323 + print_plugin_automatic_install_info_codecs (factory, rpm_format);
327 @@ -1546,7 +1783,7 @@ print_all_plugin_automatic_install_info (void)
328 plugin = (GstPlugin *) (plugins->data);
329 plugins = g_list_next (plugins);
331 - print_plugin_automatic_install_info (plugin);
332 + print_plugin_automatic_install_info (plugin, FALSE);
334 gst_plugin_list_free (orig_plugins);
336 @@ -1558,6 +1795,7 @@ main (int argc, char *argv[])
337 gboolean do_print_blacklist = FALSE;
338 gboolean plugin_name = FALSE;
339 gboolean print_aii = FALSE;
340 + gboolean print_aii_rpm = FALSE;
341 gboolean uri_handlers = FALSE;
342 #ifndef GST_DISABLE_OPTION_PARSING
343 GOptionEntry options[] = {
344 @@ -1570,6 +1808,9 @@ main (int argc, char *argv[])
345 "or all plugins provide.\n "
346 "Useful in connection with external automatic plugin "
347 "installation mechanisms"), NULL},
348 + {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
349 + N_("Print the machine-parsable list of features of a plugin in RPM "
350 + "Provides compatible-format"), NULL},
351 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
352 N_("List the plugin contents"), NULL},
353 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
354 @@ -1658,7 +1899,7 @@ main (int argc, char *argv[])
355 /* if there is such a plugin, print out info */
358 - print_plugin_automatic_install_info (plugin);
359 + print_plugin_automatic_install_info (plugin, print_aii_rpm);
361 print_plugin_info (plugin);
362 print_plugin_features (plugin);
363 @@ -1671,13 +1912,17 @@ main (int argc, char *argv[])
367 - print_plugin_automatic_install_info (plugin);
368 + print_plugin_automatic_install_info (plugin, print_aii_rpm);
370 print_plugin_info (plugin);
371 print_plugin_features (plugin);
374 - g_print (_("Could not load plugin file: %s\n"), error->message);
375 + if (!print_aii_rpm)
376 + g_print (_("Could not load plugin file: %s\n"), error->message);
378 + g_printerr (_("Could not load plugin file: %s\n"),
380 g_error_free (error);