]> git.pld-linux.org Git - packages/gstreamer.git/blame - gstreamer-inspect-rpm-format.patch
- up to 1.19.3
[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
14@@ -394,7 +394,7 @@ print_object_properties_info (GObject * obj, GObjectClass * obj_class,
15
16 first_flag = TRUE;
17 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
18- readable = ! !(param->flags & G_PARAM_READABLE);
19+ readable = !!(param->flags & G_PARAM_READABLE);
20 if (readable && obj != NULL) {
21 g_object_get_property (obj, param->name, &value);
22 } else {
23@@ -1739,11 +1739,228 @@ print_tracer_info (GstPluginFeature * feature, gboolean print_names)
5ab189e4
PZ
24 return 0;
25 }
26
27+static void
92400a1b 28+print_gst_structure_append_field (GList * strings, const char *field)
5ab189e4 29+{
92400a1b 30+ GList *s;
5ab189e4 31+
92400a1b 32+ //g_message ("adding '%s' to the string", field);
5ab189e4 33+
92400a1b
MB
34+ for (s = strings; s != NULL; s = s->next) {
35+ g_string_append (s->data, field);
36+ }
5ab189e4 37+}
555f3e2e
MB
38+
39+static void
92400a1b
MB
40+print_gst_structure_append_field_index (GList * strings, const char *field,
41+ guint num_items, guint offset)
5ab189e4 42+{
92400a1b
MB
43+ GList *s;
44+ guint i;
5ab189e4 45+
92400a1b 46+ //g_message ("adding '%s' to the string (num: %d offset: %d)", field, num_items, offset);
5ab189e4 47+
92400a1b
MB
48+ for (s = strings, i = 0; s != NULL; s = s->next, i++) {
49+ if (i == offset) {
50+ //g_message ("adding '%s' at '%d'", field, i);
51+ g_string_append (s->data, field);
52+ }
53+ if (i == num_items)
54+ i = 0;
55+ }
5ab189e4
PZ
56+
57+}
58+
59+static GList *
92400a1b 60+print_gst_structure_dup_fields (GList * strings, guint num_items)
5ab189e4 61+{
92400a1b 62+ guint new_items, i;
5ab189e4 63+
92400a1b
MB
64+ if (num_items == 1)
65+ return strings;
5ab189e4 66+
92400a1b 67+ //g_message ("creating %d new items", num_items);
5ab189e4 68+
92400a1b
MB
69+ new_items = g_list_length (strings) * (num_items - 1);
70+ for (i = 0; i < new_items; i++) {
71+ GString *s, *first;
5ab189e4 72+
92400a1b
MB
73+ first = strings->data;
74+ s = g_string_new_len (first->str, first->len);
75+ strings = g_list_prepend (strings, s);
76+ }
5ab189e4 77+
92400a1b 78+ return strings;
5ab189e4
PZ
79+}
80+
92400a1b
MB
81+enum
82+{
83+ FIELD_VERSION = 0,
84+ FIELD_LAYER,
85+ FIELD_VARIANT,
86+ FIELD_SYSTEMSTREAM
5ab189e4
PZ
87+};
88+
89+static int
90+field_get_type (const char *field_name)
91+{
92400a1b
MB
92+ if (strstr (field_name, "version") != NULL)
93+ return FIELD_VERSION;
94+ if (strcmp (field_name, "layer") == 0)
95+ return FIELD_LAYER;
96+ if (strcmp (field_name, "systemstream") == 0)
97+ return FIELD_SYSTEMSTREAM;
98+ if (strcmp (field_name, "variant") == 0)
99+ return FIELD_VARIANT;
100+
101+ return -1;
5ab189e4
PZ
102+}
103+
104+static gint
105+fields_type_compare (const char *a, const char *b)
106+{
92400a1b
MB
107+ gint a_type, b_type;
108+
109+ a_type = field_get_type (a);
110+ b_type = field_get_type (b);
111+ if (a_type < b_type)
112+ return -1;
113+ if (b_type < a_type)
114+ return 1;
115+ return 0;
5ab189e4 116+}
c44ba6d0
ŁK
117+
118+static void
92400a1b 119+print_gst_structure_for_rpm (const char *type_name, GstStructure * s)
5ab189e4
PZ
120+{
121+ guint i, num_fields;
122+ const char *name;
123+ GList *fields, *l, *strings;
124+ GString *string;
125+
126+ name = gst_structure_get_name (s);
127+ strings = NULL;
128+ num_fields = gst_structure_n_fields (s);
129+ fields = NULL;
130+
131+ for (i = 0; i < num_fields; i++) {
132+ const char *field_name;
133+
134+ field_name = gst_structure_nth_field_name (s, i);
135+ if (field_get_type (field_name) < 0) {
92400a1b
MB
136+ //g_message ("ignoring field named %s", field_name);
137+ continue;
5ab189e4
PZ
138+ }
139+
92400a1b
MB
140+ fields =
141+ g_list_insert_sorted (fields, g_strdup (field_name),
142+ (GCompareFunc) fields_type_compare);
5ab189e4
PZ
143+ }
144+
145+ /* Example:
555f3e2e
MB
146+ * gstreamer1(decoder-video/mpeg)(mpegversion=1)()(64bit) */
147+ string = g_string_new ("gstreamer1");
5ab189e4
PZ
148+ g_string_append_c (string, '(');
149+ g_string_append (string, type_name);
150+ g_string_append_c (string, '-');
151+ g_string_append (string, name);
152+ g_string_append_c (string, ')');
153+
154+ strings = g_list_append (strings, string);
155+
156+ for (l = fields; l != NULL; l = l->next) {
157+ char *field_name;
158+ GType type;
159+
160+ field_name = l->data;
161+
162+ type = gst_structure_get_field_type (s, field_name);
163+ //g_message ("field is: %s, type: %s", field_name, g_type_name (type));
164+
165+ if (type == G_TYPE_INT) {
166+ char *field;
167+ int value;
168+
169+ gst_structure_get_int (s, field_name, &value);
170+ field = g_strdup_printf ("(%s=%d)", field_name, value);
171+ print_gst_structure_append_field (strings, field);
172+ g_free (field);
173+ } else if (type == G_TYPE_BOOLEAN) {
174+ char *field;
175+ int value;
176+
177+ gst_structure_get_boolean (s, field_name, &value);
178+ field = g_strdup_printf ("(%s=%s)", field_name, value ? "true" : "false");
179+ print_gst_structure_append_field (strings, field);
180+ g_free (field);
181+ } else if (type == GST_TYPE_INT_RANGE) {
182+ const GValue *value;
183+ int min, max;
184+
185+ value = gst_structure_get_value (s, field_name);
186+ min = gst_value_get_int_range_min (value);
187+ max = gst_value_get_int_range_max (value);
188+
189+ strings = print_gst_structure_dup_fields (strings, max - min + 1);
190+
191+ for (i = min; i <= max; i++) {
192+ char *field;
193+
194+ field = g_strdup_printf ("(%s=%d)", field_name, i);
92400a1b
MB
195+ print_gst_structure_append_field_index (strings, field, max - min + 1,
196+ i - min);
5ab189e4
PZ
197+ g_free (field);
198+ }
199+ } else if (type == GST_TYPE_LIST) {
200+ const GValue *value;
201+ int num_items;
202+
203+ value = gst_structure_get_value (s, field_name);
204+ num_items = gst_value_list_get_size (value);
205+
206+ strings = print_gst_structure_dup_fields (strings, num_items);
207+
208+ for (i = 0; i < num_items; i++) {
209+ char *field;
210+ const GValue *item_value;
211+
92400a1b 212+ item_value = gst_value_list_get_value (value, i);
5ab189e4 213+ field = g_strdup_printf ("(%s=%d)", field_name,
92400a1b 214+ g_value_get_int (item_value));
5ab189e4
PZ
215+ print_gst_structure_append_field_index (strings, field, num_items, i);
216+ g_free (field);
217+ }
218+ } else if (type == G_TYPE_STRING) {
219+ char *field;
220+ const char *value;
221+
222+ value = gst_structure_get_string (s, field_name);
223+ field = g_strdup_printf ("(%s=%s)", field_name, value);
224+ print_gst_structure_append_field (strings, field);
225+ g_free (field);
226+ } else {
227+ g_warning ("unhandled type! %s", g_type_name (type));
228+ }
229+
230+ g_free (field_name);
231+ }
232+
233+ g_list_free (fields);
234+
235+ for (l = strings; l != NULL; l = l->next) {
236+ string = l->data;
237+ g_print ("%s\n", string->str);
238+ g_string_free (string, TRUE);
239+ }
240+ g_list_free (strings);
241+}
b7b90bc5 242+
205d484a
BS
243 /* NOTE: Not coloring output from automatic install functions, as their output
244 * is meant for machines, not humans.
245 */
555f3e2e
MB
246 static void
247-print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
92400a1b
MB
248+print_plugin_automatic_install_info_codecs (GstElementFactory * factory,
249+ gboolean rpm_format)
5ab189e4
PZ
250 {
251 GstPadDirection direction;
252 const gchar *type_name;
dfdf0fe8 253@@ -1769,6 +1986,13 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
92400a1b
MB
254 return;
255 }
256
257+ if (rpm_format) {
258+ /* Ignore NONE ranked plugins */
dfdf0fe8
JR
259+ if ((gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))) ==
260+ GST_RANK_NONE)
92400a1b
MB
261+ return;
262+ }
263+
264 /* decoder/demuxer sink pads should always be static and there should only
265 * be one, the same applies to encoders/muxers and source pads */
266 static_templates = gst_element_factory_get_static_pad_templates (factory);
dfdf0fe8 267@@ -1805,15 +2029,20 @@ print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
5ab189e4
PZ
268 gst_structure_remove_field (s, "rate");
269 gst_structure_remove_field (s, "depth");
270 gst_structure_remove_field (s, "clock-rate");
271- s_str = gst_structure_to_string (s);
272- g_print ("%s-%s\n", type_name, s_str);
273- g_free (s_str);
274+ if (!rpm_format) {
275+ s_str = gst_structure_to_string (s);
276+ g_print ("%s-%s\n", type_name, s_str);
277+ g_free (s_str);
278+ } else {
279+ print_gst_structure_for_rpm (type_name, s);
280+ }
281 }
282 gst_caps_unref (caps);
283 }
284
285 static void
286-print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
92400a1b
MB
287+print_plugin_automatic_install_info_protocols (GstElementFactory * factory,
288+ gboolean rpm_format)
5ab189e4 289 {
c44ba6d0 290 const gchar *const *protocols;
5ab189e4 291
dfdf0fe8 292@@ -1822,13 +2051,19 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
5ab189e4
PZ
293 switch (gst_element_factory_get_uri_type (factory)) {
294 case GST_URI_SINK:
c44ba6d0
ŁK
295 while (*protocols != NULL) {
296- g_print ("urisink-%s\n", *protocols);
5ab189e4 297+ if (!rpm_format)
c44ba6d0 298+ g_print ("urisink-%s\n", *protocols);
5ab189e4 299+ else
555f3e2e 300+ g_print ("gstreamer1(urisink-%s)\n", *protocols);
c44ba6d0
ŁK
301 ++protocols;
302 }
5ab189e4
PZ
303 break;
304 case GST_URI_SRC:
c44ba6d0
ŁK
305 while (*protocols != NULL) {
306- g_print ("urisource-%s\n", *protocols);
5ab189e4 307+ if (!rpm_format)
c44ba6d0 308+ g_print ("urisource-%s\n", *protocols);
5ab189e4 309+ else
555f3e2e 310+ g_print ("gstreamer1(urisource-%s)\n", *protocols);
c44ba6d0
ŁK
311 ++protocols;
312 }
5ab189e4 313 break;
dfdf0fe8 314@@ -1839,7 +2074,7 @@ print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
5ab189e4
PZ
315 }
316
317 static void
318-print_plugin_automatic_install_info (GstPlugin * plugin)
319+print_plugin_automatic_install_info (GstPlugin * plugin, gboolean rpm_format)
320 {
5ab189e4 321 GList *features, *l;
c44ba6d0 322
dfdf0fe8 323@@ -1858,11 +2093,15 @@ print_plugin_automatic_install_info (GstPlugin * plugin)
c44ba6d0 324 if (feature_plugin == plugin) {
5ab189e4
PZ
325 GstElementFactory *factory;
326
327- g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
328+ if (!rpm_format)
329+ g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
7ac0ad7d 330+ else
555f3e2e 331+ g_print ("gstreamer1(element-%s)\n",
7ac0ad7d 332+ gst_plugin_feature_get_name (feature));
5ab189e4
PZ
333
334 factory = GST_ELEMENT_FACTORY (feature);
335- print_plugin_automatic_install_info_protocols (factory);
336- print_plugin_automatic_install_info_codecs (factory);
337+ print_plugin_automatic_install_info_protocols (factory, rpm_format);
338+ print_plugin_automatic_install_info_codecs (factory, rpm_format);
339 }
c44ba6d0
ŁK
340 if (feature_plugin)
341 gst_object_unref (feature_plugin);
dfdf0fe8 342@@ -1884,7 +2123,7 @@ print_all_plugin_automatic_install_info (void)
92400a1b
MB
343 plugin = (GstPlugin *) (plugins->data);
344 plugins = g_list_next (plugins);
345
346- print_plugin_automatic_install_info (plugin);
347+ print_plugin_automatic_install_info (plugin, FALSE);
348 }
349 gst_plugin_list_free (orig_plugins);
350 }
dfdf0fe8 351@@ -1951,6 +2190,7 @@ main (int argc, char *argv[])
92400a1b 352 gboolean do_print_blacklist = FALSE;
41357b36 353 gboolean plugin_name = FALSE;
5ab189e4
PZ
354 gboolean print_aii = FALSE;
355+ gboolean print_aii_rpm = FALSE;
41357b36 356 gboolean uri_handlers = FALSE;
555f3e2e 357 gboolean check_exists = FALSE;
dfdf0fe8
JR
358 gboolean color_always = FALSE;
359@@ -1972,6 +2212,9 @@ main (int argc, char *argv[])
92400a1b 360 "or all plugins provide.\n "
5ab189e4
PZ
361 "Useful in connection with external automatic plugin "
362 "installation mechanisms"), NULL},
363+ {"rpm", '\0', 0, G_OPTION_ARG_NONE, &print_aii_rpm,
92400a1b
MB
364+ N_("Print the machine-parsable list of features of a plugin in RPM "
365+ "Provides compatible-format"), NULL},
41357b36
MB
366 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
367 N_("List the plugin contents"), NULL},
205d484a 368 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
dfdf0fe8 369@@ -2135,7 +2378,7 @@ main (int argc, char *argv[])
5ab189e4
PZ
370 /* if there is such a plugin, print out info */
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);
377 print_plugin_features (plugin);
dfdf0fe8 378@@ -2148,13 +2391,17 @@ main (int argc, char *argv[])
5ab189e4
PZ
379
380 if (plugin) {
381 if (print_aii) {
382- print_plugin_automatic_install_info (plugin);
383+ print_plugin_automatic_install_info (plugin, print_aii_rpm);
384 } else {
385 print_plugin_info (plugin);
386 print_plugin_features (plugin);
387 }
388 } else {
555f3e2e 389- g_printerr (_("Could not load plugin file: %s\n"), error->message);
5ab189e4
PZ
390+ if (!print_aii_rpm)
391+ g_print (_("Could not load plugin file: %s\n"), error->message);
92400a1b
MB
392+ else
393+ g_printerr (_("Could not load plugin file: %s\n"),
394+ error->message);
3dcbbc36 395 g_clear_error (&error);
205d484a
BS
396 exit_code = -1;
397 goto done;
dfdf0fe8
JR
398--
3992.26.2
400
This page took 0.100918 seconds and 4 git commands to generate.