]> git.pld-linux.org Git - packages/gstreamer.git/blame - gstreamer-inspect-rpm-format.patch
- updated for 0.10.26
[packages/gstreamer.git] / gstreamer-inspect-rpm-format.patch
CommitLineData
92400a1b
MB
1From 3f3f59c66d5eaf0efd32b8d6dabb7895cba5dda6 Mon Sep 17 00:00:00 2001
2From: Bastien Nocera <hadess@hadess.net>
3Date: Wed, 11 Nov 2009 13:53:46 +0000
4Subject: [PATCH] Add RPM provides output to gst-inspect
5
6---
7 tools/gst-inspect.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++---
8 1 files changed, 257 insertions(+), 15 deletions(-)
9
10diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
11index 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)
5ab189e4
PZ
15 return 0;
16 }
17
18+static void
92400a1b 19+print_gst_structure_append_field (GList * strings, const char *field)
5ab189e4 20+{
92400a1b 21+ GList *s;
5ab189e4 22+
92400a1b 23+ //g_message ("adding '%s' to the string", field);
5ab189e4 24+
92400a1b
MB
25+ for (s = strings; s != NULL; s = s->next) {
26+ g_string_append (s->data, field);
27+ }
5ab189e4 28+}
92400a1b
MB
29
30 static void
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)
5ab189e4 34+{
92400a1b
MB
35+ GList *s;
36+ guint i;
5ab189e4 37+
92400a1b 38+ //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
5ab189e4 39+
92400a1b
MB
40+ for (s = strings, i = 0; s != NULL; s = s->next, i++) {
41+ if (i == offset) {
42+ //g_message ("adding '%s' at '%d'", field, i);
43+ g_string_append (s->data, field);
44+ }
45+ if (i == num_items)
46+ i = 0;
47+ }
5ab189e4
PZ
48+
49+}
50+
51+static GList *
92400a1b 52+print_gst_structure_dup_fields (GList * strings, guint num_items)
5ab189e4 53+{
92400a1b 54+ guint new_items, i;
5ab189e4 55+
92400a1b
MB
56+ if (num_items == 1)
57+ return strings;
5ab189e4 58+
92400a1b 59+ //g_message ("creating %d new items", num_items);
5ab189e4 60+
92400a1b
MB
61+ new_items = g_list_length (strings) * (num_items - 1);
62+ for (i = 0; i < new_items; i++) {
63+ GString *s, *first;
5ab189e4 64+
92400a1b
MB
65+ first = strings->data;
66+ s = g_string_new_len (first->str, first->len);
67+ strings = g_list_prepend (strings, s);
68+ }
5ab189e4 69+
92400a1b 70+ return strings;
5ab189e4
PZ
71+}
72+
92400a1b
MB
73+enum
74+{
75+ FIELD_VERSION = 0,
76+ FIELD_LAYER,
77+ FIELD_VARIANT,
78+ FIELD_SYSTEMSTREAM
5ab189e4
PZ
79+};
80+
81+static int
82+field_get_type (const char *field_name)
83+{
92400a1b
MB
84+ if (strstr (field_name, "version") != NULL)
85+ return FIELD_VERSION;
86+ if (strcmp (field_name, "layer") == 0)
87+ return FIELD_LAYER;
88+ if (strcmp (field_name, "systemstream") == 0)
89+ return FIELD_SYSTEMSTREAM;
90+ if (strcmp (field_name, "variant") == 0)
91+ return FIELD_VARIANT;
92+
93+ return -1;
5ab189e4
PZ
94+}
95+
96+static gint
97+fields_type_compare (const char *a, const char *b)
98+{
92400a1b
MB
99+ gint a_type, b_type;
100+
101+ a_type = field_get_type (a);
102+ b_type = field_get_type (b);
103+ if (a_type < b_type)
104+ return -1;
105+ if (b_type < a_type)
106+ return 1;
107+ return 0;
5ab189e4
PZ
108+}
109+
110+static void
92400a1b 111+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
5ab189e4
PZ
112+{
113+ guint i, num_fields;
114+ const char *name;
115+ GList *fields, *l, *strings;
116+ GString *string;
117+
118+ name = gst_structure_get_name (s);
119+ strings = NULL;
120+ num_fields = gst_structure_n_fields (s);
121+ fields = NULL;
122+
123+ for (i = 0; i < num_fields; i++) {
124+ const char *field_name;
125+
126+ field_name = gst_structure_nth_field_name (s, i);
127+ if (field_get_type (field_name) < 0) {
92400a1b
MB
128+ //g_message ("ignoring field named %s", field_name);
129+ continue;
5ab189e4
PZ
130+ }
131+
92400a1b
MB
132+ fields =
133+ g_list_insert_sorted (fields, g_strdup (field_name),
134+ (GCompareFunc) fields_type_compare);
5ab189e4
PZ
135+ }
136+
137+ /* Example:
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, ')');
145+
146+ strings = g_list_append (strings, string);
147+
148+ for (l = fields; l != NULL; l = l->next) {
149+ char *field_name;
150+ GType type;
151+
152+ field_name = l->data;
153+
154+ type = gst_structure_get_field_type (s, field_name);
155+ //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
156+
157+ if (type == G_TYPE_INT) {
158+ char *field;
159+ int value;
160+
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);
164+ g_free (field);
165+ } else if (type == G_TYPE_BOOLEAN) {
166+ char *field;
167+ int value;
168+
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);
172+ g_free (field);
173+ } else if (type == GST_TYPE_INT_RANGE) {
174+ const GValue *value;
175+ int min, max;
176+
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);
180+
181+ strings = print_gst_structure_dup_fields (strings, max - min + 1);
182+
183+ for (i = min; i <= max; i++) {
184+ char *field;
185+
186+ field = g_strdup_printf ("(%s=%d)", field_name, i);
92400a1b
MB
187+ print_gst_structure_append_field_index (strings, field, max - min + 1,
188+ i - min);
5ab189e4
PZ
189+ g_free (field);
190+ }
191+ } else if (type == GST_TYPE_LIST) {
192+ const GValue *value;
193+ int num_items;
194+
195+ value = gst_structure_get_value (s, field_name);
196+ num_items = gst_value_list_get_size (value);
197+
198+ strings = print_gst_structure_dup_fields (strings, num_items);
199+
200+ for (i = 0; i < num_items; i++) {
201+ char *field;
202+ const GValue *item_value;
203+
92400a1b 204+ item_value = gst_value_list_get_value (value, i);
5ab189e4 205+ field = g_strdup_printf ("(%s=%d)", field_name,
92400a1b 206+ g_value_get_int (item_value));
5ab189e4
PZ
207+ print_gst_structure_append_field_index (strings, field, num_items, i);
208+ g_free (field);
209+ }
210+ } else if (type == G_TYPE_STRING) {
211+ char *field;
212+ const char *value;
213+
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);
217+ g_free (field);
218+ } else {
219+ g_warning ("unhandled type! %s", g_type_name (type));
220+ }
221+
222+ g_free (field_name);
223+ }
224+
225+ g_list_free (fields);
226+
227+ for (l = strings; l != NULL; l = l->next) {
228+ string = l->data;
229+ g_print ("%s\n", string->str);
230+ g_string_free (string, TRUE);
231+ }
232+ g_list_free (strings);
233+}
92400a1b
MB
234+
235+static void
236+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
237+ gboolean rpm_format)
5ab189e4
PZ
238 {
239 GstPadDirection direction;
240 const gchar *type_name;
92400a1b
MB
241@@ -1335,6 +1551,12 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
242 return;
243 }
244
245+ if (rpm_format) {
246+ /* Ignore NONE ranked plugins */
247+ if (GST_PLUGIN_FEATURE (factory)->rank == GST_RANK_NONE)
248+ return;
249+ }
250+
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)
5ab189e4
PZ
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);
260- g_free (s_str);
261+ if (!rpm_format) {
262+ s_str = gst_structure_to_string (s);
263+ g_print ("%s-%s\n", type_name, s_str);
264+ g_free (s_str);
265+ } else {
266+ print_gst_structure_for_rpm (type_name, s);
267+ }
268 }
269 gst_caps_unref (caps);
270 }
271
272 static void
273-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
92400a1b
MB
274+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
275+ gboolean rpm_format)
5ab189e4
PZ
276 {
277 gchar **protocols, **p;
278
92400a1b 279@@ -1388,11 +1615,17 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
5ab189e4
PZ
280 switch (gst_element_factory_get_uri_type (factory)) {
281 case GST_URI_SINK:
282 for (p = protocols; *p != NULL; ++p)
283- g_print ("urisink-%s\n", *p);
284+ if (!rpm_format)
285+ g_print ("urisink-%s\n", *p);
286+ else
287+ g_print ("gstreamer0.10(urisink-%s)\n", *p);
288 break;
289 case GST_URI_SRC:
290 for (p = protocols; *p != NULL; ++p)
291- g_print ("urisource-%s\n", *p);
292+ if (!rpm_format)
293+ g_print ("urisource-%s\n", *p);
294+ else
295+ g_print ("gstreamer0.10(urisource-%s)\n", *p);
296 break;
297 default:
298 break;
92400a1b 299@@ -1402,7 +1635,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
5ab189e4
PZ
300 }
301
302 static void
303-print_plugin_automatic_install_info (GstPlugin * plugin)
304+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
305 {
306 const gchar *plugin_name;
307 GList *features, *l;
92400a1b 308@@ -1422,11 +1655,12 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
5ab189e4
PZ
309 if (g_str_equal (plugin_name, feature->plugin_name)) {
310 GstElementFactory *factory;
311
312- g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
313+ if (!rpm_format)
314+ g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
315
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);
321 }
322 }
323
92400a1b
MB
324@@ -1446,7 +1680,7 @@ print_all_plugin_automatic_install_info (void)
325 plugin = (GstPlugin *) (plugins->data);
326 plugins = g_list_next (plugins);
327
328- print_plugin_automatic_install_info (plugin);
329+ print_plugin_automatic_install_info (plugin, FALSE);
330 }
331 gst_plugin_list_free (orig_plugins);
332 }
333@@ -1458,6 +1692,7 @@ main (int argc, char *argv[])
334 gboolean do_print_blacklist = FALSE;
41357b36 335 gboolean plugin_name = FALSE;
5ab189e4
PZ
336 gboolean print_aii = FALSE;
337+ gboolean print_aii_rpm = FALSE;
41357b36 338 gboolean uri_handlers = FALSE;
92400a1b 339 #ifndef GST_DISABLE_OPTION_PARSING
5ab189e4 340 GOptionEntry options[] = {
92400a1b
MB
341@@ -1470,6 +1705,9 @@ main (int argc, char *argv[])
342 "or all plugins provide.\n "
5ab189e4
PZ
343 "Useful in connection with external automatic plugin "
344 "installation mechanisms"), NULL},
345+ {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
92400a1b
MB
346+ N_("Print the machine-parsable list of features of a plugin in RPM "
347+ "Provides compatible-format"), NULL},
41357b36
MB
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,
92400a1b 351@@ -1557,7 +1795,7 @@ main (int argc, char *argv[])
5ab189e4
PZ
352 /* if there is such a plugin, print out info */
353 if (plugin) {
354 if (print_aii) {
355- print_plugin_automatic_install_info (plugin);
356+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
357 } else {
358 print_plugin_info (plugin);
359 print_plugin_features (plugin);
92400a1b 360@@ -1570,13 +1808,17 @@ main (int argc, char *argv[])
5ab189e4
PZ
361
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_features (plugin);
369 }
370 } else {
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);
92400a1b
MB
374+ else
375+ g_printerr (_("Could not load plugin file: %s\n"),
376+ error->message);
5ab189e4
PZ
377 g_error_free (error);
378 return -1;
379 }
92400a1b
MB
380--
3811.6.5.2
382
This page took 0.923195 seconds and 4 git commands to generate.