]> git.pld-linux.org Git - packages/gstreamer.git/blame - gstreamer-inspect-rpm-format.patch
- updated to 0.10.26
[packages/gstreamer.git] / gstreamer-inspect-rpm-format.patch
CommitLineData
41357b36
MB
1--- a/tools/gst-inspect.c 17 Nov 2008 15:48:14 -0000 1.144
2+++ b/tools/gst-inspect.c 20 Jan 2009 16:11:05 -0000
3@@ -1262,9 +1262,219 @@ print_element_info (GstElementFactory *
5ab189e4
PZ
4 return 0;
5 }
6
7+static void
8+print_gst_structure_append_field (GList *strings, const char *field)
9+{
10+ GList *s;
11+
12+ //g_message ("adding '%s' to the string", field);
13+
14+ for (s = strings; s != NULL; s = s->next) {
15+ g_string_append (s->data, field);
16+ }
17+}
18+
19+static void
20+print_gst_structure_append_field_index (GList *strings, const char *field, guint num_items, guint offset)
21+{
22+ GList *s;
23+ guint i;
24+
25+ //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
26+
27+ for (s = strings, i = 0; s != NULL; s = s->next, i++) {
28+ if (i == offset) {
29+ //g_message ("adding '%s' at '%d'", field, i);
30+ g_string_append (s->data, field);
31+ }
32+ if (i == num_items)
33+ i = 0;
34+ }
35+
36+}
37+
38+static GList *
39+print_gst_structure_dup_fields (GList *strings, guint num_items)
40+{
41+ guint new_items, i;
42+
43+ if (num_items == 1)
44+ return strings;
45+
46+ //g_message ("creating %d new items", num_items);
47+
48+ new_items = g_list_length (strings) * (num_items - 1);
49+ for (i = 0; i < new_items; i++) {
50+ GString *s, *first;
51+
52+ first = strings->data;
53+ s = g_string_new_len (first->str, first->len);
54+ strings = g_list_prepend (strings, s);
55+ }
56+
57+ return strings;
58+}
59+
60+enum {
61+ FIELD_VERSION = 0,
62+ FIELD_LAYER,
63+ FIELD_VARIANT,
64+ FIELD_SYSTEMSTREAM
65+};
66+
67+static int
68+field_get_type (const char *field_name)
69+{
70+ if (strstr (field_name, "version") != NULL)
71+ return FIELD_VERSION;
72+ if (strcmp (field_name, "layer") == 0)
73+ return FIELD_LAYER;
74+ if (strcmp (field_name, "systemstream") == 0)
75+ return FIELD_SYSTEMSTREAM;
76+ if (strcmp (field_name, "variant") == 0)
77+ return FIELD_VARIANT;
78+
79+ return -1;
80+}
81+
82+static gint
83+fields_type_compare (const char *a, const char *b)
84+{
85+ gint a_type, b_type;
86+
87+ a_type = field_get_type (a);
88+ b_type = field_get_type (b);
89+ if (a_type < b_type)
90+ return -1;
91+ if (b_type < a_type)
92+ return 1;
93+ return 0;
94+}
95+
96+static void
97+print_gst_structure_for_rpm (const char *type_name, GstStructure *s)
98+{
99+ guint i, num_fields;
100+ const char *name;
101+ GList *fields, *l, *strings;
102+ GString *string;
103+
104+ name = gst_structure_get_name (s);
105+ strings = NULL;
106+ num_fields = gst_structure_n_fields (s);
107+ fields = NULL;
108+
109+ for (i = 0; i < num_fields; i++) {
110+ const char *field_name;
111+
112+ field_name = gst_structure_nth_field_name (s, i);
113+ if (field_get_type (field_name) < 0) {
114+ //g_message ("ignoring field named %s", field_name);
115+ continue;
116+ }
117+
118+ fields = g_list_insert_sorted (fields, g_strdup (field_name), (GCompareFunc) fields_type_compare);
119+ }
120+
121+ /* Example:
122+ * gstreamer0.10(decoder-video/mpeg)(mpegversion=1)()(64bit) */
123+ string = g_string_new ("gstreamer0.10");
124+ g_string_append_c (string, '(');
125+ g_string_append (string, type_name);
126+ g_string_append_c (string, '-');
127+ g_string_append (string, name);
128+ g_string_append_c (string, ')');
129+
130+ strings = g_list_append (strings, string);
131+
132+ for (l = fields; l != NULL; l = l->next) {
133+ char *field_name;
134+ GType type;
135+
136+ field_name = l->data;
137+
138+ type = gst_structure_get_field_type (s, field_name);
139+ //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
140+
141+ if (type == G_TYPE_INT) {
142+ char *field;
143+ int value;
144+
145+ gst_structure_get_int (s, field_name, &value);
146+ field = g_strdup_printf ("(%s=%d)", field_name, value);
147+ print_gst_structure_append_field (strings, field);
148+ g_free (field);
149+ } else if (type == G_TYPE_BOOLEAN) {
150+ char *field;
151+ int value;
152+
153+ gst_structure_get_boolean (s, field_name, &value);
154+ field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
155+ print_gst_structure_append_field (strings, field);
156+ g_free (field);
157+ } else if (type == GST_TYPE_INT_RANGE) {
158+ const GValue *value;
159+ int min, max;
160+
161+ value = gst_structure_get_value (s, field_name);
162+ min = gst_value_get_int_range_min (value);
163+ max = gst_value_get_int_range_max (value);
164+
165+ strings = print_gst_structure_dup_fields (strings, max - min + 1);
166+
167+ for (i = min; i <= max; i++) {
168+ char *field;
169+
170+ field = g_strdup_printf ("(%s=%d)", field_name, i);
171+ print_gst_structure_append_field_index (strings, field, max - min + 1, i - min);
172+ g_free (field);
173+ }
174+ } else if (type == GST_TYPE_LIST) {
175+ const GValue *value;
176+ int num_items;
177+
178+ value = gst_structure_get_value (s, field_name);
179+ num_items = gst_value_list_get_size (value);
180+
181+ strings = print_gst_structure_dup_fields (strings, num_items);
182+
183+ for (i = 0; i < num_items; i++) {
184+ char *field;
185+ const GValue *item_value;
186+
187+ item_value = gst_value_list_get_value (value, i);
188+ field = g_strdup_printf ("(%s=%d)", field_name,
189+ g_value_get_int (item_value));
190+ print_gst_structure_append_field_index (strings, field, num_items, i);
191+ g_free (field);
192+ }
193+ } else if (type == G_TYPE_STRING) {
194+ char *field;
195+ const char *value;
196+
197+ value = gst_structure_get_string (s, field_name);
198+ field = g_strdup_printf ("(%s=%s)", field_name, value);
199+ print_gst_structure_append_field (strings, field);
200+ g_free (field);
201+ } else {
202+ g_warning ("unhandled type! %s", g_type_name (type));
203+ }
204+
205+ g_free (field_name);
206+ }
207+
208+ g_list_free (fields);
209+
210+ for (l = strings; l != NULL; l = l->next) {
211+ string = l->data;
212+ g_print ("%s\n", string->str);
213+ g_string_free (string, TRUE);
214+ }
215+ g_list_free (strings);
216+}
217
218 static void
219-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
220+print_plugin_automatic_install_info_codecs (GstElementFactory * factory, gboolean rpm_format)
221 {
222 GstPadDirection direction;
223 const gchar *type_name;
41357b36 224@@ -1325,15 +1535,19 @@ print_plugin_automatic_install_info_code
5ab189e4
PZ
225 gst_structure_remove_field (s, "rate");
226 gst_structure_remove_field (s, "depth");
227 gst_structure_remove_field (s, "clock-rate");
228- s_str = gst_structure_to_string (s);
229- g_print ("%s-%s\n", type_name, s_str);
230- g_free (s_str);
231+ if (!rpm_format) {
232+ s_str = gst_structure_to_string (s);
233+ g_print ("%s-%s\n", type_name, s_str);
234+ g_free (s_str);
235+ } else {
236+ print_gst_structure_for_rpm (type_name, s);
237+ }
238 }
239 gst_caps_unref (caps);
240 }
241
242 static void
243-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
244+print_plugin_automatic_install_info_protocols (GstElementFactory * factory, gboolean rpm_format)
245 {
246 gchar **protocols, **p;
247
41357b36 248@@ -1342,11 +1556,17 @@ print_plugin_automatic_install_info_prot
5ab189e4
PZ
249 switch (gst_element_factory_get_uri_type (factory)) {
250 case GST_URI_SINK:
251 for (p = protocols; *p != NULL; ++p)
252- g_print ("urisink-%s\n", *p);
253+ if (!rpm_format)
254+ g_print ("urisink-%s\n", *p);
255+ else
256+ g_print ("gstreamer0.10(urisink-%s)\n", *p);
257 break;
258 case GST_URI_SRC:
259 for (p = protocols; *p != NULL; ++p)
260- g_print ("urisource-%s\n", *p);
261+ if (!rpm_format)
262+ g_print ("urisource-%s\n", *p);
263+ else
264+ g_print ("gstreamer0.10(urisource-%s)\n", *p);
265 break;
266 default:
267 break;
41357b36 268@@ -1356,7 +1576,7 @@ print_plugin_automatic_install_info_prot
5ab189e4
PZ
269 }
270
271 static void
272-print_plugin_automatic_install_info (GstPlugin * plugin)
273+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
274 {
275 const gchar *plugin_name;
276 GList *features, *l;
41357b36 277@@ -1376,11 +1596,12 @@ print_plugin_automatic_install_info (Gst
5ab189e4
PZ
278 if (g_str_equal (plugin_name, feature->plugin_name)) {
279 GstElementFactory *factory;
280
281- g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
282+ if (!rpm_format)
283+ g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
284
285 factory = GST_ELEMENT_FACTORY (feature);
286- print_plugin_automatic_install_info_protocols (factory);
287- print_plugin_automatic_install_info_codecs (factory);
288+ print_plugin_automatic_install_info_protocols (factory, rpm_format);
289+ print_plugin_automatic_install_info_codecs (factory, rpm_format);
290 }
291 }
292
41357b36 293@@ -1394,6 +1615,7 @@ main (int argc, char *argv[])
5ab189e4 294 gboolean print_all = FALSE;
41357b36 295 gboolean plugin_name = FALSE;
5ab189e4
PZ
296 gboolean print_aii = FALSE;
297+ gboolean print_aii_rpm = FALSE;
41357b36 298 gboolean uri_handlers = FALSE;
5ab189e4
PZ
299 GOptionEntry options[] = {
300 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
41357b36 301@@ -1403,6 +1625,9 @@ main (int argc, char *argv[])
5ab189e4
PZ
302 "provides.\n "
303 "Useful in connection with external automatic plugin "
304 "installation mechanisms"), NULL},
305+ {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
306+ N_("Print the machine-parsable list of features of a plugin in RPM "
307+ "Provides compatible-format"), NULL},
41357b36
MB
308 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
309 N_("List the plugin contents"), NULL},
310 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
311@@ -1478,7 +1703,7 @@ main (int argc, char *argv[])
5ab189e4
PZ
312 /* if there is such a plugin, print out info */
313 if (plugin) {
314 if (print_aii) {
315- print_plugin_automatic_install_info (plugin);
316+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
317 } else {
318 print_plugin_info (plugin);
319 print_plugin_features (plugin);
41357b36 320@@ -1491,13 +1716,16 @@ main (int argc, char *argv[])
5ab189e4
PZ
321
322 if (plugin) {
323 if (print_aii) {
324- print_plugin_automatic_install_info (plugin);
325+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
326 } else {
327 print_plugin_info (plugin);
328 print_plugin_features (plugin);
329 }
330 } else {
331- g_print (_("Could not load plugin file: %s\n"), error->message);
332+ if (!print_aii_rpm)
333+ g_print (_("Could not load plugin file: %s\n"), error->message);
334+ else
335+ g_printerr (_("Could not load plugin file: %s\n"), error->message);
336 g_error_free (error);
337 return -1;
338 }
This page took 0.057125 seconds and 4 git commands to generate.