tools/gst-launch.1.in: Give example for network streaming (#351998)
[platform/upstream/gstreamer.git] / tools / gst-xmlinspect.c
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include <string.h>
6 #include <locale.h>
7 #include <glib/gprintf.h>
8
9 #include "tools.h"
10
11 #define PUT_START_TAG(pfx,tag)                                  \
12 G_STMT_START{                                                   \
13   g_print ("%*.*s<%s>\n", pfx, pfx, "", tag);                   \
14 }G_STMT_END
15
16 #define PUT_END_TAG(pfx,tag)                                    \
17 G_STMT_START{                                                   \
18   g_print ("%*.*s</%s>\n", pfx, pfx, "", tag);                  \
19 }G_STMT_END
20
21 #define PUT_ESCAPED(pfx,tag,value)                              \
22 G_STMT_START{                                                   \
23   const gchar *toconv = value;                                  \
24   if (value) {                                                  \
25     gchar *v = g_markup_escape_text (toconv, strlen (toconv));  \
26     g_print ("%*.*s<%s>%s</%s>\n", pfx, pfx, "", tag, v, tag);  \
27     g_free (v);                                                 \
28   }                                                             \
29 }G_STMT_END
30
31 #ifdef G_HAVE_ISO_VARARGS
32
33 #define PUT_STRING(pfx, ...)                                    \
34 G_STMT_START{                                                   \
35   gchar *ps_val = g_strdup_printf(__VA_ARGS__);                 \
36   g_print ("%*.*s%s\n", pfx, pfx, "", ps_val);                  \
37   g_free(ps_val);                                               \
38 }G_STMT_END
39
40 #elif defined(G_HAVE_GNUC_VARARGS)
41
42 #define PUT_STRING(pfx, str, a...)                              \
43 G_STMT_START{                                                   \
44   g_print ("%*.*s"str"\n", pfx, pfx, "" , ##a);                 \
45 }G_STMT_END
46
47 #else
48
49 static inline void
50 PUT_STRING (int pfx, const char *format, ...)
51 {
52   va_list varargs;
53
54   g_print ("%*.*s", pfx, pfx, "");
55   va_start (varargs, format);
56   g_vprintf (format, varargs);
57   va_end (varargs);
58   g_print ("\n");
59 }
60
61 #endif
62
63 static void
64 print_caps (const GstCaps * caps, gint pfx)
65 {
66   char *s;
67
68   if (!caps)
69     return;
70
71   s = gst_caps_to_string (caps);
72   PUT_ESCAPED (pfx, "caps", s);
73   g_free (s);
74 }
75
76 #if 0
77 static void
78 print_formats (const GstFormat * formats, gint pfx)
79 {
80   while (formats && *formats) {
81     const GstFormatDefinition *definition;
82
83     definition = gst_format_get_details (*formats);
84     if (definition)
85       PUT_STRING (pfx, "<format id=\"%d\" nick=\"%s\">%s</format>",
86           *formats, definition->nick, definition->description);
87     else
88       PUT_STRING (pfx, "<format id=\"%d\">unknown</format>", *formats);
89
90     formats++;
91   }
92 }
93 #endif
94
95 static void
96 print_query_types (const GstQueryType * types, gint pfx)
97 {
98   while (types && *types) {
99     const GstQueryTypeDefinition *definition;
100
101     definition = gst_query_type_get_details (*types);
102     if (definition)
103       PUT_STRING (pfx, "<query-type id=\"%d\" nick=\"%s\">%s</query-type>",
104           *types, definition->nick, definition->description);
105     else
106       PUT_STRING (pfx, "<query-type id=\"%d\">unknown</query-type>", *types);
107
108     types++;
109   }
110 }
111
112 #if 0
113 static void
114 print_event_masks (const GstEventMask * masks, gint pfx)
115 {
116 #ifndef GST_DISABLE_ENUMTYPES
117   GType event_type;
118   GEnumClass *klass;
119   GType event_flags;
120   GFlagsClass *flags_class = NULL;
121
122   event_type = gst_event_type_get_type ();
123   klass = (GEnumClass *) g_type_class_ref (event_type);
124
125   while (masks && masks->type) {
126     GEnumValue *value;
127     gint flags = 0, index = 0;
128
129     switch (masks->type) {
130       case GST_EVENT_SEEK:
131         flags = masks->flags;
132         event_flags = gst_seek_type_get_type ();
133         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
134         break;
135       default:
136         break;
137     }
138
139     value = g_enum_get_value (klass, masks->type);
140     PUT_STRING (pfx, "<event type=\"%s\">", value->value_nick);
141
142     while (flags) {
143       GFlagsValue *value;
144
145       if (flags & 1) {
146         value = g_flags_get_first_value (flags_class, 1 << index);
147
148         if (value)
149           PUT_ESCAPED (pfx + 1, "flag", value->value_nick);
150         else
151           PUT_ESCAPED (pfx + 1, "flag", "?");
152       }
153       flags >>= 1;
154       index++;
155     }
156     PUT_END_TAG (pfx, "event");
157
158     masks++;
159   }
160 #endif
161 }
162 #endif
163
164 static void
165 output_hierarchy (GType type, gint level, gint * maxlevel)
166 {
167   GType parent;
168
169   parent = g_type_parent (type);
170
171   *maxlevel = *maxlevel + 1;
172   level++;
173
174   PUT_STRING (level, "<object name=\"%s\">", g_type_name (type));
175
176   if (parent)
177     output_hierarchy (parent, level, maxlevel);
178
179   PUT_END_TAG (level, "object");
180 }
181
182 static void
183 print_element_properties (GstElement * element, gint pfx)
184 {
185   GParamSpec **property_specs;
186   guint num_properties;
187   gint i;
188   gboolean readable;
189
190   property_specs = g_object_class_list_properties
191       (G_OBJECT_GET_CLASS (element), &num_properties);
192
193   PUT_START_TAG (pfx, "element-properties");
194
195   for (i = 0; i < num_properties; i++) {
196     GValue value = { 0, };
197     GParamSpec *param = property_specs[i];
198
199     readable = FALSE;
200
201     g_value_init (&value, param->value_type);
202     if (param->flags & G_PARAM_READABLE) {
203       g_object_get_property (G_OBJECT (element), param->name, &value);
204       readable = TRUE;
205     }
206     PUT_START_TAG (pfx + 1, "element-property");
207     PUT_ESCAPED (pfx + 2, "name", g_param_spec_get_name (param));
208     PUT_ESCAPED (pfx + 2, "type", g_type_name (param->value_type));
209     PUT_ESCAPED (pfx + 2, "nick", g_param_spec_get_nick (param));
210     PUT_ESCAPED (pfx + 2, "blurb", g_param_spec_get_blurb (param));
211     if (readable) {
212       PUT_ESCAPED (pfx + 2, "flags", "RW");
213     } else {
214       PUT_ESCAPED (pfx + 2, "flags", "W");
215     }
216
217     switch (G_VALUE_TYPE (&value)) {
218       case G_TYPE_STRING:
219         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
220         break;
221       case G_TYPE_BOOLEAN:
222         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
223         break;
224       case G_TYPE_ULONG:
225       {
226         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
227
228         PUT_STRING (pfx + 2, "<range min=\"%lu\" max=\"%lu\"/>",
229             pulong->minimum, pulong->maximum);
230         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
231         break;
232       }
233       case G_TYPE_LONG:
234       {
235         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
236
237         PUT_STRING (pfx + 2, "<range min=\"%ld\" max=\"%ld\"/>",
238             plong->minimum, plong->maximum);
239         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
240         break;
241       }
242       case G_TYPE_UINT:
243       {
244         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
245
246         PUT_STRING (pfx + 2, "<range min=\"%u\" max=\"%u\"/>",
247             puint->minimum, puint->maximum);
248         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
249         break;
250       }
251       case G_TYPE_INT:
252       {
253         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
254
255         PUT_STRING (pfx + 2, "<range min=\"%d\" max=\"%d\"/>",
256             pint->minimum, pint->maximum);
257         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
258         break;
259       }
260       case G_TYPE_UINT64:
261       {
262         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
263
264         PUT_STRING (pfx + 2,
265             "<range min=\"%" G_GUINT64_FORMAT "\" max=\"%" G_GUINT64_FORMAT
266             "\"/>", puint64->minimum, puint64->maximum);
267         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
268         break;
269       }
270       case G_TYPE_INT64:
271       {
272         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
273
274         PUT_STRING (pfx + 2,
275             "<range min=\"%" G_GINT64_FORMAT "\" max=\"%" G_GINT64_FORMAT
276             "\"/>", pint64->minimum, pint64->maximum);
277         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
278         break;
279       }
280       case G_TYPE_FLOAT:
281       {
282         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
283
284         PUT_STRING (pfx + 2, "<range min=\"%f\" max=\"%f\"/>",
285             pfloat->minimum, pfloat->maximum);
286         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
287         break;
288       }
289       case G_TYPE_DOUBLE:
290       {
291         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
292
293         PUT_STRING (pfx + 2, "<range min=\"%g\" max=\"%g\"/>",
294             pdouble->minimum, pdouble->maximum);
295         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
296         break;
297       }
298       default:
299         if (param->value_type == GST_TYPE_CAPS) {
300           GstCaps *caps = g_value_peek_pointer (&value);
301
302           if (!caps)
303             PUT_ESCAPED (pfx + 2, "default", "NULL");
304           else {
305             print_caps (caps, 2);
306           }
307         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
308           GEnumValue *values;
309           guint j = 0;
310           gint enum_value;
311
312           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
313           enum_value = g_value_get_enum (&value);
314
315           while (values[j].value_name) {
316             if (values[j].value == enum_value)
317               break;
318             j++;
319           }
320           PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value);
321
322           PUT_START_TAG (pfx + 2, "enum-values");
323           j = 0;
324           while (values[j].value_name) {
325             PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>",
326                 values[j].value, values[j].value_nick);
327             j++;
328           }
329           PUT_END_TAG (pfx + 2, "enum-values");
330         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
331           GFlagsValue *values;
332           guint j = 0;
333           gint flags_value;
334
335           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
336           flags_value = g_value_get_flags (&value);
337
338           PUT_STRING (pfx + 2, "<default>%d</default>", flags_value);
339
340           PUT_START_TAG (pfx + 2, "flags");
341           j = 0;
342           while (values[j].value_name) {
343             PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>",
344                 values[j].value, values[j].value_nick);
345             j++;
346           }
347           PUT_END_TAG (pfx + 2, "flags");
348         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
349           PUT_ESCAPED (pfx + 2, "object-type", g_type_name (param->value_type));
350         }
351         break;
352     }
353
354     PUT_END_TAG (pfx + 1, "element-property");
355   }
356   PUT_END_TAG (pfx, "element-properties");
357   g_free (property_specs);
358 }
359
360 static void
361 print_element_signals (GstElement * element, gint pfx)
362 {
363   guint *signals;
364   guint nsignals;
365   gint i, k;
366   GSignalQuery *query;
367
368   signals = g_signal_list_ids (G_OBJECT_TYPE (element), &nsignals);
369   for (k = 0; k < 2; k++) {
370     gint counted = 0;
371
372     if (k == 0)
373       PUT_START_TAG (pfx, "element-signals");
374     else
375       PUT_START_TAG (pfx, "element-actions");
376
377     for (i = 0; i < nsignals; i++) {
378       gint n_params;
379       GType return_type;
380       const GType *param_types;
381       gint j;
382
383       query = g_new0 (GSignalQuery, 1);
384       g_signal_query (signals[i], query);
385
386       if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
387           (k == 1 && (query->signal_flags & G_SIGNAL_ACTION))) {
388         n_params = query->n_params;
389         return_type = query->return_type;
390         param_types = query->param_types;
391
392         PUT_START_TAG (pfx + 1, "signal");
393         PUT_ESCAPED (pfx + 2, "name", query->signal_name);
394         PUT_ESCAPED (pfx + 2, "return-type", g_type_name (return_type));
395         PUT_ESCAPED (pfx + 2, "object-type",
396             g_type_name (G_OBJECT_TYPE (element)));
397
398         PUT_START_TAG (pfx + 2, "params");
399         for (j = 0; j < n_params; j++) {
400           PUT_ESCAPED (pfx + 3, "type", g_type_name (param_types[j]));
401         }
402
403         PUT_END_TAG (pfx + 2, "params");
404
405         PUT_END_TAG (pfx + 1, "signal");
406
407         counted++;
408       }
409
410       g_free (query);
411     }
412     if (k == 0)
413       PUT_END_TAG (pfx, "element-signals");
414     else
415       PUT_END_TAG (pfx, "element-actions");
416   }
417 }
418
419 static gint
420 print_element_info (GstElementFactory * factory)
421 {
422   GstElement *element;
423   GstObjectClass *gstobject_class;
424   GstElementClass *gstelement_class;
425   GList *pads;
426   GstPad *pad;
427   GstStaticPadTemplate *padtemplate;
428   gint maxlevel = 0;
429
430   element = gst_element_factory_create (factory, "element");
431   if (!element) {
432     g_print ("couldn't construct element for some reason\n");
433     return -1;
434   }
435   PUT_START_TAG (0, "element");
436   PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory));
437
438   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
439   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
440
441   PUT_START_TAG (1, "details");
442   PUT_ESCAPED (2, "long-name", factory->details.longname);
443   PUT_ESCAPED (2, "class", factory->details.klass);
444   PUT_ESCAPED (2, "description", factory->details.description);
445   PUT_ESCAPED (2, "authors", factory->details.author);
446   PUT_END_TAG (1, "details");
447
448   output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
449
450   PUT_START_TAG (1, "pad-templates");
451   if (factory->numpadtemplates) {
452     pads = factory->staticpadtemplates;
453     while (pads) {
454       padtemplate = (GstStaticPadTemplate *) (pads->data);
455       pads = g_list_next (pads);
456
457       PUT_START_TAG (2, "pad-template");
458       PUT_ESCAPED (3, "name", padtemplate->name_template);
459
460       if (padtemplate->direction == GST_PAD_SRC)
461         PUT_ESCAPED (3, "direction", "src");
462       else if (padtemplate->direction == GST_PAD_SINK)
463         PUT_ESCAPED (3, "direction", "sink");
464       else
465         PUT_ESCAPED (3, "direction", "unknown");
466
467       if (padtemplate->presence == GST_PAD_ALWAYS)
468         PUT_ESCAPED (3, "presence", "always");
469       else if (padtemplate->presence == GST_PAD_SOMETIMES)
470         PUT_ESCAPED (3, "presence", "sometimes");
471       else if (padtemplate->presence == GST_PAD_REQUEST) {
472         PUT_ESCAPED (3, "presence", "request");
473         PUT_ESCAPED (3, "request-function",
474             GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
475       } else
476         PUT_ESCAPED (3, "presence", "unknown");
477
478       if (padtemplate->static_caps.string) {
479         print_caps (gst_static_caps_get (&padtemplate->static_caps), 3);
480       }
481       PUT_END_TAG (2, "pad-template");
482     }
483   }
484   PUT_END_TAG (1, "pad-templates");
485
486   PUT_START_TAG (1, "element-flags");
487   PUT_END_TAG (1, "element-flags");
488
489   if (GST_IS_BIN (element)) {
490     PUT_START_TAG (1, "bin-flags");
491
492     PUT_END_TAG (1, "bin-flags");
493   }
494
495
496   PUT_START_TAG (1, "element-implementation");
497
498   PUT_STRING (2, "<state-change function=\"%s\"/>",
499       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
500
501 #ifndef GST_DISABLE_LOADSAVE
502   PUT_STRING (2, "<save function=\"%s\"/>",
503       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
504   PUT_STRING (2, "<load function=\"%s\"/>",
505       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
506 #endif
507   PUT_END_TAG (1, "element-implementation");
508
509   PUT_START_TAG (1, "clocking-interaction");
510   if (gst_element_requires_clock (element)) {
511     PUT_STRING (2, "<requires-clock/>");
512   }
513   if (gst_element_provides_clock (element)) {
514     GstClock *clock;
515
516     clock = gst_element_get_clock (element);
517     if (clock)
518       PUT_STRING (2, "<provides-clock name=\"%s\"/>", GST_OBJECT_NAME (clock));
519   }
520   PUT_END_TAG (1, "clocking-interaction");
521
522 #ifndef GST_DISABLE_INDEX
523   if (gst_element_is_indexable (element)) {
524     PUT_STRING (1, "<indexing-capabilities/>");
525   }
526 #endif
527
528   PUT_START_TAG (1, "pads");
529   if (element->numpads) {
530     const GList *pads;
531
532     pads = element->pads;
533     while (pads) {
534       pad = GST_PAD (pads->data);
535       pads = g_list_next (pads);
536
537       PUT_START_TAG (2, "pad");
538       PUT_ESCAPED (3, "name", gst_pad_get_name (pad));
539
540       if (gst_pad_get_direction (pad) == GST_PAD_SRC)
541         PUT_ESCAPED (3, "direction", "src");
542       else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
543         PUT_ESCAPED (3, "direction", "sink");
544       else
545         PUT_ESCAPED (3, "direction", "unknown");
546
547       if (pad->padtemplate)
548         PUT_ESCAPED (3, "template", pad->padtemplate->name_template);
549
550       PUT_START_TAG (3, "implementation");
551       if (pad->chainfunc)
552         PUT_STRING (4, "<chain-based function=\"%s\"/>",
553             GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
554       if (pad->getrangefunc)
555         PUT_STRING (4, "<get-range-based function=\"%s\"/>",
556             GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
557       if (pad->eventfunc != gst_pad_event_default)
558         PUT_STRING (4, "<event-function function=\"%s\"/>",
559             GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
560       if (pad->queryfunc != gst_pad_query_default)
561         PUT_STRING (4, "<query-function function=\"%s\"/>",
562             GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
563       if (pad->querytypefunc != gst_pad_get_query_types_default) {
564         PUT_STRING (4, "<query-type-func function=\"%s\">",
565             GST_DEBUG_FUNCPTR_NAME (pad->querytypefunc));
566         print_query_types (gst_pad_get_query_types (pad), 5);
567         PUT_END_TAG (4, "query-type-func");
568       }
569
570       if (pad->intlinkfunc != gst_pad_get_internal_links_default)
571         PUT_STRING (4, "<intlink-function function=\"%s\"/>",
572             GST_DEBUG_FUNCPTR_NAME (pad->intlinkfunc));
573
574       if (pad->bufferallocfunc)
575         PUT_STRING (4, "<bufferalloc-function function=\"%s\"/>",
576             GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
577       PUT_END_TAG (3, "implementation");
578
579       if (pad->caps) {
580         print_caps (pad->caps, 3);
581       }
582       PUT_END_TAG (2, "pad");
583     }
584   }
585   PUT_END_TAG (1, "pads");
586
587   print_element_properties (element, 1);
588   print_element_signals (element, 1);
589
590   /* for compound elements */
591   /* FIXME: gst_bin_get_list does not exist anymore
592      if (GST_IS_BIN (element)) {
593      GList *children;
594      GstElement *child;
595      PUT_START_TAG (1, "children");
596      children = (GList *) gst_bin_get_list (GST_BIN (element));
597      while (children) {
598      child = GST_ELEMENT (children->data);
599      children = g_list_next (children);
600
601      PUT_ESCAPED (2, "child", GST_ELEMENT_NAME (child));
602      }
603      PUT_END_TAG (1, "children");
604      }
605    */
606   PUT_END_TAG (0, "element");
607
608   return 0;
609 }
610
611 static void
612 print_element_list (void)
613 {
614   GList *plugins;
615
616   plugins = gst_default_registry_get_plugin_list ();
617   while (plugins) {
618     GList *features;
619     GstPlugin *plugin;
620
621     plugin = (GstPlugin *) (plugins->data);
622     plugins = g_list_next (plugins);
623
624     features =
625         gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
626         plugin->desc.name);
627     while (features) {
628       GstPluginFeature *feature;
629
630       feature = GST_PLUGIN_FEATURE (features->data);
631
632       if (GST_IS_ELEMENT_FACTORY (feature)) {
633         GstElementFactory *factory;
634
635         factory = GST_ELEMENT_FACTORY (feature);
636         g_print ("%s:  %s: %s\n", plugin->desc.name,
637             GST_PLUGIN_FEATURE_NAME (factory), factory->details.longname);
638       }
639 #ifndef GST_DISABLE_INDEX
640       else if (GST_IS_INDEX_FACTORY (feature)) {
641         GstIndexFactory *factory;
642
643         factory = GST_INDEX_FACTORY (feature);
644         g_print ("%s:  %s: %s\n", plugin->desc.name,
645             GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
646       }
647 #endif
648       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
649         GstTypeFindFactory *factory;
650
651         factory = GST_TYPE_FIND_FACTORY (feature);
652         if (factory->extensions) {
653           guint i = 0;
654
655           g_print ("%s type: ", plugin->desc.name);
656           while (factory->extensions[i]) {
657             g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
658             i++;
659           }
660         } else
661           g_print ("%s type: N/A\n", plugin->desc.name);
662       } else {
663         g_print ("%s:  %s (%s)\n", plugin->desc.name,
664             GST_PLUGIN_FEATURE_NAME (feature),
665             g_type_name (G_OBJECT_TYPE (feature)));
666       }
667
668       features = g_list_next (features);
669     }
670   }
671 }
672
673 static void
674 print_plugin_info (GstPlugin * plugin)
675 {
676   GList *features;
677   gint num_features = 0;
678   gint num_elements = 0;
679   gint num_autoplug = 0;
680   gint num_types = 0;
681   gint num_indexes = 0;
682   gint num_other = 0;
683
684   g_print ("Plugin Details:\n");
685   g_print ("  Name:\t\t%s\n", plugin->desc.name);
686   g_print ("  Description:\t%s\n", plugin->desc.description);
687   g_print ("  Filename:\t%s\n", plugin->filename);
688   g_print ("  Version:\t%s\n", plugin->desc.version);
689   g_print ("  License:\t%s\n", plugin->desc.license);
690   g_print ("  Package:\t%s\n", plugin->desc.package);
691   g_print ("  Origin URL:\t%s\n", plugin->desc.origin);
692   g_print ("\n");
693
694   features =
695       gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
696       plugin->desc.name);
697
698   while (features) {
699     GstPluginFeature *feature;
700
701     feature = GST_PLUGIN_FEATURE (features->data);
702
703     if (GST_IS_ELEMENT_FACTORY (feature)) {
704       GstElementFactory *factory;
705
706       factory = GST_ELEMENT_FACTORY (feature);
707       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
708           factory->details.longname);
709       num_elements++;
710     }
711 #ifndef GST_DISABLE_INDEX
712     else if (GST_IS_INDEX_FACTORY (feature)) {
713       GstIndexFactory *factory;
714
715       factory = GST_INDEX_FACTORY (feature);
716       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
717       num_indexes++;
718     }
719 #endif
720     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
721       GstTypeFindFactory *factory;
722
723       factory = GST_TYPE_FIND_FACTORY (feature);
724       if (factory->extensions) {
725         guint i = 0;
726
727         g_print ("%s type: ", plugin->desc.name);
728         while (factory->extensions[i]) {
729           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
730           i++;
731         }
732       } else
733         g_print ("%s type: N/A\n", plugin->desc.name);
734       num_types++;
735     } else {
736       g_print ("  %s (%s)\n", GST_OBJECT_NAME (feature),
737           g_type_name (G_OBJECT_TYPE (feature)));
738       num_other++;
739     }
740     num_features++;
741     features = g_list_next (features);
742   }
743   g_print ("\n  %d features:\n", num_features);
744   if (num_elements > 0)
745     g_print ("  +-- %d elements\n", num_elements);
746   if (num_autoplug > 0)
747     g_print ("  +-- %d autopluggers\n", num_autoplug);
748   if (num_types > 0)
749     g_print ("  +-- %d types\n", num_types);
750   if (num_indexes > 0)
751     g_print ("  +-- %d indexes\n", num_indexes);
752   if (num_other > 0)
753     g_print ("  +-- %d other objects\n", num_other);
754
755   g_print ("\n");
756 }
757
758
759 int
760 main (int argc, char *argv[])
761 {
762   GstElementFactory *factory;
763   GstPlugin *plugin;
764   gchar *so;
765   GOptionEntry options[] = {
766     {"gst-inspect-plugin", 'p', 0, G_OPTION_ARG_STRING,
767         "Show plugin details", NULL},
768     {"gst-inspect-scheduler", 's', 0, G_OPTION_ARG_STRING,
769         "Show scheduler details", NULL},
770     GST_TOOLS_GOPTION_VERSION,
771     {NULL}
772   };
773   GOptionContext *ctx;
774   GError *err = NULL;
775
776   setlocale (LC_ALL, "");
777
778   if (!g_thread_supported ())
779     g_thread_init (NULL);
780
781   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
782   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
783   g_option_context_add_group (ctx, gst_init_get_option_group ());
784   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
785     g_print ("Error initializing: %s\n", err->message);
786     exit (1);
787   }
788   g_option_context_free (ctx);
789
790   gst_tools_print_version ("gst-xmlinspect");
791
792   PUT_STRING (0, "<?xml version=\"1.0\"?>");
793
794   /* if no arguments, print out list of elements */
795   if (argc == 1) {
796     print_element_list ();
797
798     /* else we try to get a factory */
799   } else {
800     /* first check for help */
801     if (strstr (argv[1], "-help")) {
802       g_print ("Usage: %s\t\t\tList all registered elements\n", argv[0]);
803       g_print ("       %s element-name\tShow element details\n", argv[0]);
804       g_print ("       %s plugin-name[.so]\tShow information about plugin\n",
805           argv[0]);
806       return 0;
807     }
808
809     /* only search for a factory if there's not a '.so' */
810     if (!strstr (argv[1], ".so")) {
811       factory = gst_element_factory_find (argv[1]);
812
813       /* if there's a factory, print out the info */
814       if (factory)
815         return print_element_info (factory);
816       else {
817         GstPluginFeature *feature;
818
819         /* FIXME implement other pretty print function for these */
820 #ifndef GST_DISABLE_INDEX
821         feature = gst_default_registry_find_feature (argv[1],
822             GST_TYPE_INDEX_FACTORY);
823         if (feature) {
824           g_print ("%s: an index\n", argv[1]);
825           return 0;
826         }
827 #endif
828         feature = gst_default_registry_find_feature (argv[1],
829             GST_TYPE_TYPE_FIND_FACTORY);
830         if (feature) {
831           g_print ("%s: a type find function\n", argv[1]);
832           return 0;
833         }
834       }
835     } else {
836       /* strip the .so */
837       so = strstr (argv[1], ".so");
838       so[0] = '\0';
839     }
840
841     /* otherwise assume it's a plugin */
842     plugin = gst_default_registry_find_plugin (argv[1]);
843
844     /* if there is such a plugin, print out info */
845
846     if (plugin) {
847       print_plugin_info (plugin);
848     } else {
849       g_print ("no such element or plugin '%s'\n", argv[1]);
850       return -1;
851     }
852   }
853
854   return 0;
855 }