]> git.pld-linux.org Git - packages/gstreamer.git/blame - gstreamer-inspect-rpm-format.patch
- release 3
[packages/gstreamer.git] / gstreamer-inspect-rpm-format.patch
CommitLineData
7ac0ad7d 1From e4a4294f53d25bc3b5699cace74de4f49062a2ee Mon Sep 17 00:00:00 2001
92400a1b
MB
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---
7ac0ad7d
MB
7 tools/gst-inspect.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++---
8 1 files changed, 260 insertions(+), 15 deletions(-)
92400a1b
MB
9
10diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
7ac0ad7d 11index c86285e..80b2456 100644
92400a1b
MB
12--- a/tools/gst-inspect.c
13+++ b/tools/gst-inspect.c
7ac0ad7d 14@@ -1408,9 +1408,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+}
7ac0ad7d
MB
29+
30+static void
92400a1b
MB
31+print_gst_structure_append_field_index (GList * strings, const char *field,
32+ guint num_items, guint offset)
5ab189e4 33+{
92400a1b
MB
34+ GList *s;
35+ guint i;
5ab189e4 36+
92400a1b 37+ //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
5ab189e4 38+
92400a1b
MB
39+ for (s = strings, i = 0; s != NULL; s = s->next, i++) {
40+ if (i == offset) {
41+ //g_message ("adding '%s' at '%d'", field, i);
42+ g_string_append (s->data, field);
43+ }
44+ if (i == num_items)
45+ i = 0;
46+ }
5ab189e4
PZ
47+
48+}
49+
50+static GList *
92400a1b 51+print_gst_structure_dup_fields (GList * strings, guint num_items)
5ab189e4 52+{
92400a1b 53+ guint new_items, i;
5ab189e4 54+
92400a1b
MB
55+ if (num_items == 1)
56+ return strings;
5ab189e4 57+
92400a1b 58+ //g_message ("creating %d new items", num_items);
5ab189e4 59+
92400a1b
MB
60+ new_items = g_list_length (strings) * (num_items - 1);
61+ for (i = 0; i < new_items; i++) {
62+ GString *s, *first;
5ab189e4 63+
92400a1b
MB
64+ first = strings->data;
65+ s = g_string_new_len (first->str, first->len);
66+ strings = g_list_prepend (strings, s);
67+ }
5ab189e4 68+
92400a1b 69+ return strings;
5ab189e4
PZ
70+}
71+
92400a1b
MB
72+enum
73+{
74+ FIELD_VERSION = 0,
75+ FIELD_LAYER,
76+ FIELD_VARIANT,
77+ FIELD_SYSTEMSTREAM
5ab189e4
PZ
78+};
79+
80+static int
81+field_get_type (const char *field_name)
82+{
92400a1b
MB
83+ if (strstr (field_name, "version") != NULL)
84+ return FIELD_VERSION;
85+ if (strcmp (field_name, "layer") == 0)
86+ return FIELD_LAYER;
87+ if (strcmp (field_name, "systemstream") == 0)
88+ return FIELD_SYSTEMSTREAM;
89+ if (strcmp (field_name, "variant") == 0)
90+ return FIELD_VARIANT;
91+
92+ return -1;
5ab189e4
PZ
93+}
94+
95+static gint
96+fields_type_compare (const char *a, const char *b)
97+{
92400a1b
MB
98+ gint a_type, b_type;
99+
100+ a_type = field_get_type (a);
101+ b_type = field_get_type (b);
102+ if (a_type < b_type)
103+ return -1;
104+ if (b_type < a_type)
105+ return 1;
106+ return 0;
5ab189e4 107+}
7ac0ad7d
MB
108
109 static void
110-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
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;
7ac0ad7d 241@@ -1435,6 +1651,12 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
92400a1b
MB
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);
7ac0ad7d 254@@ -1471,15 +1693,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
7ac0ad7d 279@@ -1488,11 +1715,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;
7ac0ad7d 299@@ -1502,7 +1735,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;
7ac0ad7d 308@@ -1522,11 +1755,15 @@ 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));
7ac0ad7d
MB
315+ else
316+ g_print ("gstreamer0.10(element-%s)\n",
317+ gst_plugin_feature_get_name (feature));
5ab189e4
PZ
318
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);
324 }
325 }
326
7ac0ad7d 327@@ -1546,7 +1783,7 @@ print_all_plugin_automatic_install_info (void)
92400a1b
MB
328 plugin = (GstPlugin *) (plugins->data);
329 plugins = g_list_next (plugins);
330
331- print_plugin_automatic_install_info (plugin);
332+ print_plugin_automatic_install_info (plugin, FALSE);
333 }
334 gst_plugin_list_free (orig_plugins);
335 }
7ac0ad7d 336@@ -1558,6 +1795,7 @@ main (int argc, char *argv[])
92400a1b 337 gboolean do_print_blacklist = FALSE;
41357b36 338 gboolean plugin_name = FALSE;
5ab189e4
PZ
339 gboolean print_aii = FALSE;
340+ gboolean print_aii_rpm = FALSE;
41357b36 341 gboolean uri_handlers = FALSE;
92400a1b 342 #ifndef GST_DISABLE_OPTION_PARSING
5ab189e4 343 GOptionEntry options[] = {
7ac0ad7d 344@@ -1570,6 +1808,9 @@ main (int argc, char *argv[])
92400a1b 345 "or all plugins provide.\n "
5ab189e4
PZ
346 "Useful in connection with external automatic plugin "
347 "installation mechanisms"), NULL},
348+ {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
92400a1b
MB
349+ N_("Print the machine-parsable list of features of a plugin in RPM "
350+ "Provides compatible-format"), NULL},
41357b36
MB
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,
7ac0ad7d 354@@ -1658,7 +1899,7 @@ main (int argc, char *argv[])
5ab189e4
PZ
355 /* if there is such a plugin, print out info */
356 if (plugin) {
357 if (print_aii) {
358- print_plugin_automatic_install_info (plugin);
359+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
360 } else {
361 print_plugin_info (plugin);
362 print_plugin_features (plugin);
7ac0ad7d 363@@ -1671,13 +1912,17 @@ main (int argc, char *argv[])
5ab189e4
PZ
364
365 if (plugin) {
366 if (print_aii) {
367- print_plugin_automatic_install_info (plugin);
368+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
369 } else {
370 print_plugin_info (plugin);
371 print_plugin_features (plugin);
372 }
373 } else {
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);
92400a1b
MB
377+ else
378+ g_printerr (_("Could not load plugin file: %s\n"),
379+ error->message);
5ab189e4
PZ
380 g_error_free (error);
381 return -1;
382 }
92400a1b 383--
7ac0ad7d 3841.7.4.1
92400a1b 385
This page took 0.164404 seconds and 4 git commands to generate.