]> git.pld-linux.org Git - packages/gstreamer.git/blame - gstreamer-inspect-rpm-format.patch
- updated to 1.24.2
[packages/gstreamer.git] / gstreamer-inspect-rpm-format.patch
CommitLineData
dfdf0fe8
JR
1From 642d0d6fef226fb89eaecf0016f8e5e333b9023e Mon Sep 17 00:00:00 2001
2From: Wim Taymans <wtaymans@redhat.com>
3Date: Tue, 23 Jun 2015 10:28:29 +0200
4Subject: [PATCH] gst-inspect: add mode to output RPM requires format
5
6---
7 tools/gst-inspect.c | 279 +++++++++++++++++++++++++++++++++++++++++---
8 1 file changed, 263 insertions(+), 16 deletions(-)
9
10diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
11index 8da042946..a057cba09 100644
12--- a/tools/gst-inspect.c
13+++ b/tools/gst-inspect.c
89762de1 14@@ -1934,11 +1934,228 @@ print_tracer_info (GstPluginFeature * fe
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+}
555f3e2e
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+}
c44ba6d0
ŁK
108+
109+static void
92400a1b 110+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
5ab189e4
PZ
111+{
112+ guint i, num_fields;
113+ const char *name;
114+ GList *fields, *l, *strings;
115+ GString *string;
116+
117+ name = gst_structure_get_name (s);
118+ strings = NULL;
119+ num_fields = gst_structure_n_fields (s);
120+ fields = NULL;
121+
122+ for (i = 0; i < num_fields; i++) {
123+ const char *field_name;
124+
125+ field_name = gst_structure_nth_field_name (s, i);
126+ if (field_get_type (field_name) < 0) {
92400a1b
MB
127+ //g_message ("ignoring field named %s", field_name);
128+ continue;
5ab189e4
PZ
129+ }
130+
92400a1b
MB
131+ fields =
132+ g_list_insert_sorted (fields, g_strdup (field_name),
133+ (GCompareFunc) fields_type_compare);
5ab189e4
PZ
134+ }
135+
136+ /* Example:
555f3e2e
MB
137+ * gstreamer1(decoder-video/mpeg)(mpegversion=1)()(64bit) */
138+ string = g_string_new ("gstreamer1");
5ab189e4
PZ
139+ g_string_append_c (string, '(');
140+ g_string_append (string, type_name);
141+ g_string_append_c (string, '-');
142+ g_string_append (string, name);
143+ g_string_append_c (string, ')');
144+
145+ strings = g_list_append (strings, string);
146+
147+ for (l = fields; l != NULL; l = l->next) {
148+ char *field_name;
149+ GType type;
150+
151+ field_name = l->data;
152+
153+ type = gst_structure_get_field_type (s, field_name);
154+ //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
155+
156+ if (type == G_TYPE_INT) {
157+ char *field;
158+ int value;
159+
160+ gst_structure_get_int (s, field_name, &value);
161+ field = g_strdup_printf ("(%s=%d)", field_name, value);
162+ print_gst_structure_append_field (strings, field);
163+ g_free (field);
164+ } else if (type == G_TYPE_BOOLEAN) {
165+ char *field;
166+ int value;
167+
168+ gst_structure_get_boolean (s, field_name, &value);
169+ field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
170+ print_gst_structure_append_field (strings, field);
171+ g_free (field);
172+ } else if (type == GST_TYPE_INT_RANGE) {
173+ const GValue *value;
174+ int min, max;
175+
176+ value = gst_structure_get_value (s, field_name);
177+ min = gst_value_get_int_range_min (value);
178+ max = gst_value_get_int_range_max (value);
179+
180+ strings = print_gst_structure_dup_fields (strings, max - min + 1);
181+
182+ for (i = min; i <= max; i++) {
183+ char *field;
184+
185+ field = g_strdup_printf ("(%s=%d)", field_name, i);
92400a1b
MB
186+ print_gst_structure_append_field_index (strings, field, max - min + 1,
187+ i - min);
5ab189e4
PZ
188+ g_free (field);
189+ }
190+ } else if (type == GST_TYPE_LIST) {
191+ const GValue *value;
192+ int num_items;
193+
194+ value = gst_structure_get_value (s, field_name);
195+ num_items = gst_value_list_get_size (value);
196+
197+ strings = print_gst_structure_dup_fields (strings, num_items);
198+
199+ for (i = 0; i < num_items; i++) {
200+ char *field;
201+ const GValue *item_value;
202+
92400a1b 203+ item_value = gst_value_list_get_value (value, i);
5ab189e4 204+ field = g_strdup_printf ("(%s=%d)", field_name,
92400a1b 205+ g_value_get_int (item_value));
5ab189e4
PZ
206+ print_gst_structure_append_field_index (strings, field, num_items, i);
207+ g_free (field);
208+ }
209+ } else if (type == G_TYPE_STRING) {
210+ char *field;
211+ const char *value;
212+
213+ value = gst_structure_get_string (s, field_name);
214+ field = g_strdup_printf ("(%s=%s)", field_name, value);
215+ print_gst_structure_append_field (strings, field);
216+ g_free (field);
217+ } else {
218+ g_warning ("unhandled type! %s", g_type_name (type));
219+ }
220+
221+ g_free (field_name);
222+ }
223+
224+ g_list_free (fields);
225+
226+ for (l = strings; l != NULL; l = l->next) {
227+ string = l->data;
228+ g_print ("%s\n", string->str);
229+ g_string_free (string, TRUE);
230+ }
231+ g_list_free (strings);
232+}
b7b90bc5 233+
205d484a
BS
234 /* NOTE: Not coloring output from automatic install functions, as their output
235 * is meant for machines, not humans.
236 */
555f3e2e
MB
237 static void
238-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
92400a1b
MB
239+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
240+ gboolean rpm_format)
5ab189e4
PZ
241 {
242 GstPadDirection direction;
243 const gchar *type_name;
89762de1 244@@ -1966,6 +2183,13 @@ print_plugin_automatic_install_info_code
92400a1b
MB
245 return;
246 }
247
248+ if (rpm_format) {
249+ /* Ignore NONE ranked plugins */
dfdf0fe8
JR
250+ if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) ==
251+ GST_RANK_NONE)
92400a1b
MB
252+ return;
253+ }
254+
255 /* decoder/demuxer sink pads should always be static and there should only
256 * be one, the same applies to encoders/muxers and source pads */
257 static_templates = gst_element_factory_get_static_pad_templates (factory);
89762de1 258@@ -2002,15 +2226,20 @@ print_plugin_automatic_install_info_code
5ab189e4
PZ
259 gst_structure_remove_field (s, "rate");
260 gst_structure_remove_field (s, "depth");
261 gst_structure_remove_field (s, "clock-rate");
262- s_str = gst_structure_to_string (s);
263- g_print ("%s-%s\n", type_name, s_str);
264- g_free (s_str);
265+ if (!rpm_format) {
266+ s_str = gst_structure_to_string (s);
267+ g_print ("%s-%s\n", type_name, s_str);
268+ g_free (s_str);
269+ } else {
270+ print_gst_structure_for_rpm (type_name, s);
271+ }
272 }
273 gst_caps_unref (caps);
274 }
275
276 static void
277-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
92400a1b
MB
278+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
279+ gboolean rpm_format)
5ab189e4 280 {
c44ba6d0 281 const gchar *const *protocols;
5ab189e4 282
89762de1 283@@ -2019,13 +2248,19 @@ print_plugin_automatic_install_info_prot
5ab189e4
PZ
284 switch (gst_element_factory_get_uri_type (factory)) {
285 case GST_URI_SINK:
c44ba6d0
ŁK
286 while (*protocols != NULL) {
287- g_print ("urisink-%s\n", *protocols);
5ab189e4 288+ if (!rpm_format)
c44ba6d0 289+ g_print ("urisink-%s\n", *protocols);
5ab189e4 290+ else
555f3e2e 291+ g_print ("gstreamer1(urisink-%s)\n", *protocols);
c44ba6d0
ŁK
292 ++protocols;
293 }
5ab189e4
PZ
294 break;
295 case GST_URI_SRC:
c44ba6d0
ŁK
296 while (*protocols != NULL) {
297- g_print ("urisource-%s\n", *protocols);
5ab189e4 298+ if (!rpm_format)
c44ba6d0 299+ g_print ("urisource-%s\n", *protocols);
5ab189e4 300+ else
555f3e2e 301+ g_print ("gstreamer1(urisource-%s)\n", *protocols);
c44ba6d0
ŁK
302 ++protocols;
303 }
5ab189e4 304 break;
89762de1 305@@ -2036,7 +2271,7 @@ print_plugin_automatic_install_info_prot
5ab189e4
PZ
306 }
307
308 static void
309-print_plugin_automatic_install_info (GstPlugin * plugin)
310+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
311 {
5ab189e4 312 GList *features, *l;
c44ba6d0 313
89762de1 314@@ -2055,11 +2290,15 @@ print_plugin_automatic_install_info (Gst
c44ba6d0 315 if (feature_plugin == plugin) {
5ab189e4
PZ
316 GstElementFactory *factory;
317
318- g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
319+ if (!rpm_format)
320+ g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
7ac0ad7d 321+ else
555f3e2e 322+ g_print ("gstreamer1(element-%s)\n",
7ac0ad7d 323+ gst_plugin_feature_get_name (feature));
5ab189e4
PZ
324
325 factory = GST_ELEMENT_FACTORY (feature);
326- print_plugin_automatic_install_info_protocols (factory);
327- print_plugin_automatic_install_info_codecs (factory);
328+ print_plugin_automatic_install_info_protocols (factory, rpm_format);
329+ print_plugin_automatic_install_info_codecs (factory, rpm_format);
330 }
c44ba6d0
ŁK
331 if (feature_plugin)
332 gst_object_unref (feature_plugin);
89762de1 333@@ -2083,7 +2322,7 @@ print_all_plugin_automatic_install_info
92400a1b
MB
334 plugin = (GstPlugin *) (plugins->data);
335 plugins = g_list_next (plugins);
336
337- print_plugin_automatic_install_info (plugin);
338+ print_plugin_automatic_install_info (plugin, FALSE);
339 }
340 gst_plugin_list_free (orig_plugins);
341 }
89762de1 342@@ -2169,6 +2408,7 @@ real_main (int argc, char *argv[])
92400a1b 343 gboolean do_print_blacklist = FALSE;
41357b36 344 gboolean plugin_name = FALSE;
5ab189e4
PZ
345 gboolean print_aii = FALSE;
346+ gboolean print_aii_rpm = FALSE;
41357b36 347 gboolean uri_handlers = FALSE;
555f3e2e 348 gboolean check_exists = FALSE;
64c0a87d
JB
349 gboolean check_version = FALSE;
350@@ -2191,6 +2431,9 @@ real_main (int argc, char *argv[])
92400a1b 351 "or all plugins provide.\n "
5ab189e4
PZ
352 "Useful in connection with external automatic plugin "
353 "installation mechanisms"), NULL},
354+ {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
92400a1b
MB
355+ N_("Print the machine-parsable list of features of a plugin in RPM "
356+ "Provides compatible-format"), NULL},
41357b36
MB
357 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
358 N_("List the plugin contents"), NULL},
205d484a 359 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
64c0a87d 360@@ -2370,7 +2613,7 @@ real_main (int argc, char *argv[])
5ab189e4
PZ
361 /* if there is such a plugin, print out info */
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);
89762de1 368 print_plugin_status (plugin);
64c0a87d 369@@ -2384,13 +2627,16 @@ real_main (int argc, char *argv[])
5ab189e4
PZ
370
371 if (plugin) {
372 if (print_aii) {
373- print_plugin_automatic_install_info (plugin);
374+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
375 } else {
376 print_plugin_info (plugin);
89762de1 377 print_plugin_status (plugin);
5ab189e4
PZ
378 print_plugin_features (plugin);
379 }
380 } else {
5ab189e4
PZ
381+ if (!print_aii_rpm)
382+ g_print (_("Could not load plugin file: %s\n"), error->message);
92400a1b 383+ else
89762de1 384 g_printerr (_("Could not load plugin file: %s\n"), error->message);
3dcbbc36 385 g_clear_error (&error);
205d484a 386 exit_code = -1;
This page took 0.21757 seconds and 4 git commands to generate.