1 From 3f3f59c66d5eaf0efd32b8d6dabb7895cba5dda6 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 | 272 ++++++++++++++++++++++++++++++++++++++++++++++++---
8 1 files changed, 257 insertions(+), 15 deletions(-)
10 diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
11 index b2502f4..dfd2eb4 100644
12 --- a/tools/gst-inspect.c
13 +++ b/tools/gst-inspect.c
14 @@ -1308,9 +1308,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_plugin_automatic_install_info_codecs (GstElementFactory * factory)
32 +print_gst_structure_append_field_index (GList * strings, const char *field,
33 + guint num_items, guint offset)
38 + //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
40 + for (s = strings, i = 0; s != NULL; s = s->next, i++) {
42 + //g_message ("adding '%s' at '%d'", field, i);
43 + g_string_append (s->data, field);
52 +print_gst_structure_dup_fields (GList * strings, guint num_items)
59 + //g_message ("creating %d new items", num_items);
61 + new_items = g_list_length (strings) * (num_items - 1);
62 + for (i = 0; i < new_items; i++) {
65 + first = strings->data;
66 + s = g_string_new_len (first->str, first->len);
67 + strings = g_list_prepend (strings, s);
82 +field_get_type (const char *field_name)
84 + if (strstr (field_name, "version") != NULL)
85 + return FIELD_VERSION;
86 + if (strcmp (field_name, "layer") == 0)
88 + if (strcmp (field_name, "systemstream") == 0)
89 + return FIELD_SYSTEMSTREAM;
90 + if (strcmp (field_name, "variant") == 0)
91 + return FIELD_VARIANT;
97 +fields_type_compare (const char *a, const char *b)
99 + gint a_type, b_type;
101 + a_type = field_get_type (a);
102 + b_type = field_get_type (b);
103 + if (a_type < b_type)
105 + if (b_type < a_type)
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 @@ -1335,6 +1551,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 @@ -1371,15 +1593,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 @@ -1388,11 +1615,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 @@ -1402,7 +1635,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 @@ -1422,11 +1655,12 @@ 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 factory = GST_ELEMENT_FACTORY (feature);
317 - print_plugin_automatic_install_info_protocols (factory);
318 - print_plugin_automatic_install_info_codecs (factory);
319 + print_plugin_automatic_install_info_protocols (factory, rpm_format);
320 + print_plugin_automatic_install_info_codecs (factory, rpm_format);
324 @@ -1446,7 +1680,7 @@ print_all_plugin_automatic_install_info (void)
325 plugin = (GstPlugin *) (plugins->data);
326 plugins = g_list_next (plugins);
328 - print_plugin_automatic_install_info (plugin);
329 + print_plugin_automatic_install_info (plugin, FALSE);
331 gst_plugin_list_free (orig_plugins);
333 @@ -1458,6 +1692,7 @@ main (int argc, char *argv[])
334 gboolean do_print_blacklist = FALSE;
335 gboolean plugin_name = FALSE;
336 gboolean print_aii = FALSE;
337 + gboolean print_aii_rpm = FALSE;
338 gboolean uri_handlers = FALSE;
339 #ifndef GST_DISABLE_OPTION_PARSING
340 GOptionEntry options[] = {
341 @@ -1470,6 +1705,9 @@ main (int argc, char *argv[])
342 "or all plugins provide.\n "
343 "Useful in connection with external automatic plugin "
344 "installation mechanisms"), NULL},
345 + {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
346 + N_("Print the machine-parsable list of features of a plugin in RPM "
347 + "Provides compatible-format"), NULL},
348 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
349 N_("List the plugin contents"), NULL},
350 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
351 @@ -1557,7 +1795,7 @@ main (int argc, char *argv[])
352 /* if there is such a plugin, print out info */
355 - print_plugin_automatic_install_info (plugin);
356 + print_plugin_automatic_install_info (plugin, print_aii_rpm);
358 print_plugin_info (plugin);
359 print_plugin_features (plugin);
360 @@ -1570,13 +1808,17 @@ main (int argc, char *argv[])
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_features (plugin);
371 - g_print (_("Could not load plugin file: %s\n"), error->message);
372 + if (!print_aii_rpm)
373 + g_print (_("Could not load plugin file: %s\n"), error->message);
375 + g_printerr (_("Could not load plugin file: %s\n"),
377 g_error_free (error);