1 /* GStreamer gst-xmlinspect
2 * Copyright (C) 2003 Wim Taymans <wtay@chello.be>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 /* FIXME 0.11: remove gst-xmlinspect and gst-feedback etc. */
27 #include <glib/gprintf.h>
31 #define PUT_START_TAG(pfx,tag) \
33 g_print ("%*.*s<%s>\n", pfx, pfx, "", tag); \
36 #define PUT_END_TAG(pfx,tag) \
38 g_print ("%*.*s</%s>\n", pfx, pfx, "", tag); \
41 #define PUT_ESCAPED(pfx,tag,value) \
43 const gchar *toconv = value; \
45 gchar *v = g_markup_escape_text (toconv, strlen (toconv)); \
46 g_print ("%*.*s<%s>%s</%s>\n", pfx, pfx, "", tag, v, tag); \
51 #ifdef G_HAVE_ISO_VARARGS
53 #define PUT_STRING(pfx, ...) \
55 gchar *ps_val = g_strdup_printf(__VA_ARGS__); \
56 g_print ("%*.*s%s\n", pfx, pfx, "", ps_val); \
60 #elif defined(G_HAVE_GNUC_VARARGS)
62 #define PUT_STRING(pfx, str, a...) \
64 g_print ("%*.*s"str"\n", pfx, pfx, "" , ##a); \
70 PUT_STRING (int pfx, const char *format, ...)
74 g_print ("%*.*s", pfx, pfx, "");
75 va_start (varargs, format);
76 g_vprintf (format, varargs);
84 print_caps (const GstCaps * caps, gint pfx)
91 s = gst_caps_to_string (caps);
92 PUT_ESCAPED (pfx, "caps", s);
98 print_formats (const GstFormat * formats, gint pfx)
100 while (formats && *formats) {
101 const GstFormatDefinition *definition;
103 definition = gst_format_get_details (*formats);
105 PUT_STRING (pfx, "<format id=\"%d\" nick=\"%s\">%s</format>",
106 *formats, definition->nick, definition->description);
108 PUT_STRING (pfx, "<format id=\"%d\">unknown</format>", *formats);
116 print_query_types (const GstQueryType * types, gint pfx)
118 while (types && *types) {
119 const GstQueryTypeDefinition *definition;
121 definition = gst_query_type_get_details (*types);
123 PUT_STRING (pfx, "<query-type id=\"%d\" nick=\"%s\">%s</query-type>",
124 *types, definition->nick, definition->description);
126 PUT_STRING (pfx, "<query-type id=\"%d\">unknown</query-type>", *types);
134 print_event_masks (const GstEventMask * masks, gint pfx)
139 GFlagsClass *flags_class = NULL;
141 event_type = gst_event_type_get_type ();
142 klass = (GEnumClass *) g_type_class_ref (event_type);
144 while (masks && masks->type) {
146 gint flags = 0, index = 0;
148 switch (masks->type) {
150 flags = masks->flags;
151 event_flags = gst_seek_type_get_type ();
152 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
158 value = g_enum_get_value (klass, masks->type);
159 PUT_STRING (pfx, "<event type=\"%s\">", value->value_nick);
165 value = g_flags_get_first_value (flags_class, 1 << index);
168 PUT_ESCAPED (pfx + 1, "flag", value->value_nick);
170 PUT_ESCAPED (pfx + 1, "flag", "?");
175 PUT_END_TAG (pfx, "event");
183 output_hierarchy (GType type, gint level, gint * maxlevel)
187 parent = g_type_parent (type);
189 *maxlevel = *maxlevel + 1;
192 PUT_STRING (level, "<object name=\"%s\">", g_type_name (type));
195 output_hierarchy (parent, level, maxlevel);
197 PUT_END_TAG (level, "object");
201 print_element_properties (GstElement * element, gint pfx)
203 GParamSpec **property_specs;
204 guint num_properties;
208 property_specs = g_object_class_list_properties
209 (G_OBJECT_GET_CLASS (element), &num_properties);
211 PUT_START_TAG (pfx, "element-properties");
213 for (i = 0; i < num_properties; i++) {
214 GValue value = { 0, };
215 GParamSpec *param = property_specs[i];
219 g_value_init (&value, param->value_type);
220 if (param->flags & G_PARAM_READABLE) {
221 g_object_get_property (G_OBJECT (element), param->name, &value);
224 PUT_START_TAG (pfx + 1, "element-property");
225 PUT_ESCAPED (pfx + 2, "name", g_param_spec_get_name (param));
226 PUT_ESCAPED (pfx + 2, "type", g_type_name (param->value_type));
227 PUT_ESCAPED (pfx + 2, "nick", g_param_spec_get_nick (param));
228 PUT_ESCAPED (pfx + 2, "blurb", g_param_spec_get_blurb (param));
230 PUT_ESCAPED (pfx + 2, "flags", "RW");
232 PUT_ESCAPED (pfx + 2, "flags", "W");
235 switch (G_VALUE_TYPE (&value)) {
237 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
240 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
244 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
246 PUT_STRING (pfx + 2, "<range min=\"%lu\" max=\"%lu\"/>",
247 pulong->minimum, pulong->maximum);
248 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
253 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
255 PUT_STRING (pfx + 2, "<range min=\"%ld\" max=\"%ld\"/>",
256 plong->minimum, plong->maximum);
257 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
262 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
264 PUT_STRING (pfx + 2, "<range min=\"%u\" max=\"%u\"/>",
265 puint->minimum, puint->maximum);
266 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
271 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
273 PUT_STRING (pfx + 2, "<range min=\"%d\" max=\"%d\"/>",
274 pint->minimum, pint->maximum);
275 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
280 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
283 "<range min=\"%" G_GUINT64_FORMAT "\" max=\"%" G_GUINT64_FORMAT
284 "\"/>", puint64->minimum, puint64->maximum);
285 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
290 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
293 "<range min=\"%" G_GINT64_FORMAT "\" max=\"%" G_GINT64_FORMAT
294 "\"/>", pint64->minimum, pint64->maximum);
295 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
300 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
302 PUT_STRING (pfx + 2, "<range min=\"%f\" max=\"%f\"/>",
303 pfloat->minimum, pfloat->maximum);
304 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
309 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
311 PUT_STRING (pfx + 2, "<range min=\"%g\" max=\"%g\"/>",
312 pdouble->minimum, pdouble->maximum);
313 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
317 if (param->value_type == GST_TYPE_CAPS) {
318 GstCaps *caps = g_value_peek_pointer (&value);
321 PUT_ESCAPED (pfx + 2, "default", "NULL");
323 print_caps (caps, 2);
325 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
330 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
331 enum_value = g_value_get_enum (&value);
333 while (values[j].value_name) {
334 if (values[j].value == enum_value)
338 PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value);
340 PUT_START_TAG (pfx + 2, "enum-values");
342 while (values[j].value_name) {
343 PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>",
344 values[j].value, values[j].value_nick);
347 PUT_END_TAG (pfx + 2, "enum-values");
348 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
353 values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
354 flags_value = g_value_get_flags (&value);
356 PUT_STRING (pfx + 2, "<default>%d</default>", flags_value);
358 PUT_START_TAG (pfx + 2, "flags");
360 while (values[j].value_name) {
361 PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>",
362 values[j].value, values[j].value_nick);
365 PUT_END_TAG (pfx + 2, "flags");
366 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
367 PUT_ESCAPED (pfx + 2, "object-type", g_type_name (param->value_type));
372 PUT_END_TAG (pfx + 1, "element-property");
374 PUT_END_TAG (pfx, "element-properties");
375 g_free (property_specs);
379 print_element_signals (GstElement * element, gint pfx)
386 signals = g_signal_list_ids (G_OBJECT_TYPE (element), &nsignals);
387 for (k = 0; k < 2; k++) {
391 PUT_START_TAG (pfx, "element-signals");
393 PUT_START_TAG (pfx, "element-actions");
395 for (i = 0; i < nsignals; i++) {
398 const GType *param_types;
401 query = g_new0 (GSignalQuery, 1);
402 g_signal_query (signals[i], query);
404 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
405 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION))) {
406 n_params = query->n_params;
407 return_type = query->return_type;
408 param_types = query->param_types;
410 PUT_START_TAG (pfx + 1, "signal");
411 PUT_ESCAPED (pfx + 2, "name", query->signal_name);
412 PUT_ESCAPED (pfx + 2, "return-type", g_type_name (return_type));
413 PUT_ESCAPED (pfx + 2, "object-type",
414 g_type_name (G_OBJECT_TYPE (element)));
416 PUT_START_TAG (pfx + 2, "params");
417 for (j = 0; j < n_params; j++) {
418 PUT_ESCAPED (pfx + 3, "type", g_type_name (param_types[j]));
421 PUT_END_TAG (pfx + 2, "params");
423 PUT_END_TAG (pfx + 1, "signal");
431 PUT_END_TAG (pfx, "element-signals");
433 PUT_END_TAG (pfx, "element-actions");
438 print_element_info (GstElementFactory * factory)
441 GstObjectClass *gstobject_class;
442 GstElementClass *gstelement_class;
445 GstStaticPadTemplate *padtemplate;
448 element = gst_element_factory_create (factory, "element");
450 g_print ("couldn't construct element for some reason\n");
453 PUT_START_TAG (0, "element");
454 PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory));
456 gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
457 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
459 PUT_START_TAG (1, "details");
460 PUT_ESCAPED (2, "long-name", factory->details.longname);
461 PUT_ESCAPED (2, "class", factory->details.klass);
462 PUT_ESCAPED (2, "description", factory->details.description);
463 PUT_ESCAPED (2, "authors", factory->details.author);
464 PUT_END_TAG (1, "details");
466 output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
468 PUT_START_TAG (1, "pad-templates");
469 if (factory->numpadtemplates) {
470 pads = factory->staticpadtemplates;
472 padtemplate = (GstStaticPadTemplate *) (pads->data);
473 pads = g_list_next (pads);
475 PUT_START_TAG (2, "pad-template");
476 PUT_ESCAPED (3, "name", padtemplate->name_template);
478 if (padtemplate->direction == GST_PAD_SRC)
479 PUT_ESCAPED (3, "direction", "src");
480 else if (padtemplate->direction == GST_PAD_SINK)
481 PUT_ESCAPED (3, "direction", "sink");
483 PUT_ESCAPED (3, "direction", "unknown");
485 if (padtemplate->presence == GST_PAD_ALWAYS)
486 PUT_ESCAPED (3, "presence", "always");
487 else if (padtemplate->presence == GST_PAD_SOMETIMES)
488 PUT_ESCAPED (3, "presence", "sometimes");
489 else if (padtemplate->presence == GST_PAD_REQUEST) {
490 PUT_ESCAPED (3, "presence", "request");
491 PUT_ESCAPED (3, "request-function",
492 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
494 PUT_ESCAPED (3, "presence", "unknown");
496 if (padtemplate->static_caps.string) {
497 print_caps (gst_static_caps_get (&padtemplate->static_caps), 3);
499 PUT_END_TAG (2, "pad-template");
502 PUT_END_TAG (1, "pad-templates");
504 PUT_START_TAG (1, "element-flags");
505 PUT_END_TAG (1, "element-flags");
507 if (GST_IS_BIN (element)) {
508 PUT_START_TAG (1, "bin-flags");
510 PUT_END_TAG (1, "bin-flags");
514 PUT_START_TAG (1, "element-implementation");
516 PUT_STRING (2, "<state-change function=\"%s\"/>",
517 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
519 #ifndef GST_DISABLE_LOADSAVE
520 PUT_STRING (2, "<save function=\"%s\"/>",
521 GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
522 PUT_STRING (2, "<load function=\"%s\"/>",
523 GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
525 PUT_END_TAG (1, "element-implementation");
527 PUT_START_TAG (1, "clocking-interaction");
528 if (gst_element_requires_clock (element)) {
529 PUT_STRING (2, "<requires-clock/>");
531 if (gst_element_provides_clock (element)) {
534 clock = gst_element_get_clock (element);
536 PUT_STRING (2, "<provides-clock name=\"%s\"/>", GST_OBJECT_NAME (clock));
538 PUT_END_TAG (1, "clocking-interaction");
540 if (gst_element_is_indexable (element)) {
541 PUT_STRING (1, "<indexing-capabilities/>");
544 PUT_START_TAG (1, "pads");
545 if (element->numpads) {
548 pads = element->pads;
550 pad = GST_PAD (pads->data);
551 pads = g_list_next (pads);
553 PUT_START_TAG (2, "pad");
554 PUT_ESCAPED (3, "name", gst_pad_get_name (pad));
556 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
557 PUT_ESCAPED (3, "direction", "src");
558 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
559 PUT_ESCAPED (3, "direction", "sink");
561 PUT_ESCAPED (3, "direction", "unknown");
563 if (pad->padtemplate)
564 PUT_ESCAPED (3, "template", pad->padtemplate->name_template);
566 PUT_START_TAG (3, "implementation");
568 PUT_STRING (4, "<chain-based function=\"%s\"/>",
569 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
570 if (pad->getrangefunc)
571 PUT_STRING (4, "<get-range-based function=\"%s\"/>",
572 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
573 if (pad->eventfunc != gst_pad_event_default)
574 PUT_STRING (4, "<event-function function=\"%s\"/>",
575 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
576 if (pad->queryfunc != gst_pad_query_default)
577 PUT_STRING (4, "<query-function function=\"%s\"/>",
578 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
579 if (pad->querytypefunc != gst_pad_get_query_types_default) {
580 PUT_STRING (4, "<query-type-func function=\"%s\">",
581 GST_DEBUG_FUNCPTR_NAME (pad->querytypefunc));
582 print_query_types (gst_pad_get_query_types (pad), 5);
583 PUT_END_TAG (4, "query-type-func");
586 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
587 PUT_STRING (4, "<iterintlink-function function=\"%s\"/>",
588 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
590 if (pad->bufferallocfunc)
591 PUT_STRING (4, "<bufferalloc-function function=\"%s\"/>",
592 GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
593 PUT_END_TAG (3, "implementation");
596 print_caps (pad->caps, 3);
598 PUT_END_TAG (2, "pad");
601 PUT_END_TAG (1, "pads");
603 print_element_properties (element, 1);
604 print_element_signals (element, 1);
606 /* for compound elements */
607 /* FIXME: gst_bin_get_list does not exist anymore
608 if (GST_IS_BIN (element)) {
611 PUT_START_TAG (1, "children");
612 children = (GList *) gst_bin_get_list (GST_BIN (element));
614 child = GST_ELEMENT (children->data);
615 children = g_list_next (children);
617 PUT_ESCAPED (2, "child", GST_ELEMENT_NAME (child));
619 PUT_END_TAG (1, "children");
622 PUT_END_TAG (0, "element");
628 main (int argc, char *argv[])
630 GstElementFactory *factory;
631 GOptionEntry options[] = {
632 GST_TOOLS_GOPTION_VERSION,
638 setlocale (LC_ALL, "");
640 if (!g_thread_supported ())
641 g_thread_init (NULL);
643 gst_tools_print_version ("gst-xmlinspect");
645 ctx = g_option_context_new ("[ELEMENT-NAME]");
646 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
647 g_option_context_add_group (ctx, gst_init_get_option_group ());
648 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
649 g_print ("Error initializing: %s\n", err->message);
652 g_option_context_free (ctx);
654 /* if no arguments, print out all elements */
658 features = gst_registry_get_feature_list (gst_registry_get_default (),
659 GST_TYPE_ELEMENT_FACTORY);
661 PUT_STRING (0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
663 for (f = features; f != NULL; f = f->next)
664 print_element_info (GST_ELEMENT_FACTORY (f->data));
666 gst_plugin_feature_list_free (features);
670 /* else we try to get a factory */
671 factory = gst_element_factory_find (argv[1]);
673 /* if there's a factory, print out the info */
675 PUT_STRING (0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
676 return print_element_info (factory);
679 /* otherwise, error out */
680 g_printerr ("no such element '%s'\n", argv[1]);