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