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