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