7 #include <glib/gprintf.h>
11 #define PUT_START_TAG(pfx,tag) \
13 g_print ("%*.*s<%s>\n", pfx, pfx, "", tag); \
16 #define PUT_END_TAG(pfx,tag) \
18 g_print ("%*.*s</%s>\n", pfx, pfx, "", tag); \
21 #define PUT_ESCAPED(pfx,tag,value) \
23 const gchar *toconv = value; \
25 gchar *v = g_markup_escape_text (toconv, strlen (toconv)); \
26 g_print ("%*.*s<%s>%s</%s>\n", pfx, pfx, "", tag, v, tag); \
31 #ifdef G_HAVE_ISO_VARARGS
33 #define PUT_STRING(pfx, ...) \
35 gchar *ps_val = g_strdup_printf(__VA_ARGS__); \
36 g_print ("%*.*s%s\n", pfx, pfx, "", ps_val); \
40 #elif defined(G_HAVE_GNUC_VARARGS)
42 #define PUT_STRING(pfx, str, a...) \
44 g_print ("%*.*s"str"\n", pfx, pfx, "" , ##a); \
50 PUT_STRING (int pfx, const char *format, ...)
54 g_print ("%*.*s", pfx, pfx, "");
55 va_start (varargs, format);
56 g_vprintf (format, varargs);
64 print_caps (const GstCaps * caps, gint pfx)
71 s = gst_caps_to_string (caps);
72 PUT_ESCAPED (pfx, "caps", s);
78 print_formats (const GstFormat * formats, gint pfx)
80 while (formats && *formats) {
81 const GstFormatDefinition *definition;
83 definition = gst_format_get_details (*formats);
85 PUT_STRING (pfx, "<format id=\"%d\" nick=\"%s\">%s</format>",
86 *formats, definition->nick, definition->description);
88 PUT_STRING (pfx, "<format id=\"%d\">unknown</format>", *formats);
96 print_query_types (const GstQueryType * types, gint pfx)
98 while (types && *types) {
99 const GstQueryTypeDefinition *definition;
101 definition = gst_query_type_get_details (*types);
103 PUT_STRING (pfx, "<query-type id=\"%d\" nick=\"%s\">%s</query-type>",
104 *types, definition->nick, definition->description);
106 PUT_STRING (pfx, "<query-type id=\"%d\">unknown</query-type>", *types);
114 print_event_masks (const GstEventMask * masks, gint pfx)
116 #ifndef GST_DISABLE_ENUMTYPES
120 GFlagsClass *flags_class = NULL;
122 event_type = gst_event_type_get_type ();
123 klass = (GEnumClass *) g_type_class_ref (event_type);
125 while (masks && masks->type) {
127 gint flags = 0, index = 0;
129 switch (masks->type) {
131 flags = masks->flags;
132 event_flags = gst_seek_type_get_type ();
133 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
139 value = g_enum_get_value (klass, masks->type);
140 PUT_STRING (pfx, "<event type=\"%s\">", value->value_nick);
146 value = g_flags_get_first_value (flags_class, 1 << index);
149 PUT_ESCAPED (pfx + 1, "flag", value->value_nick);
151 PUT_ESCAPED (pfx + 1, "flag", "?");
156 PUT_END_TAG (pfx, "event");
165 output_hierarchy (GType type, gint level, gint * maxlevel)
169 parent = g_type_parent (type);
171 *maxlevel = *maxlevel + 1;
174 PUT_STRING (level, "<object name=\"%s\">", g_type_name (type));
177 output_hierarchy (parent, level, maxlevel);
179 PUT_END_TAG (level, "object");
183 print_element_properties (GstElement * element, gint pfx)
185 GParamSpec **property_specs;
186 guint num_properties;
190 property_specs = g_object_class_list_properties
191 (G_OBJECT_GET_CLASS (element), &num_properties);
193 PUT_START_TAG (pfx, "element-properties");
195 for (i = 0; i < num_properties; i++) {
196 GValue value = { 0, };
197 GParamSpec *param = property_specs[i];
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);
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));
212 PUT_ESCAPED (pfx + 2, "flags", "RW");
214 PUT_ESCAPED (pfx + 2, "flags", "W");
217 switch (G_VALUE_TYPE (&value)) {
219 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
222 PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
226 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
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));
235 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
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));
244 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
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));
253 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
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));
262 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
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));
272 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
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));
282 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
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));
291 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
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));
299 if (param->value_type == GST_TYPE_CAPS) {
300 GstCaps *caps = g_value_peek_pointer (&value);
303 PUT_ESCAPED (pfx + 2, "default", "NULL");
305 print_caps (caps, 2);
307 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
312 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
313 enum_value = g_value_get_enum (&value);
315 while (values[j].value_name) {
316 if (values[j].value == enum_value)
320 PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value);
322 PUT_START_TAG (pfx + 2, "enum-values");
324 while (values[j].value_name) {
325 PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>",
326 values[j].value, values[j].value_nick);
329 PUT_END_TAG (pfx + 2, "enum-values");
330 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
335 values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
336 flags_value = g_value_get_flags (&value);
338 PUT_STRING (pfx + 2, "<default>%d</default>", flags_value);
340 PUT_START_TAG (pfx + 2, "flags");
342 while (values[j].value_name) {
343 PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>",
344 values[j].value, values[j].value_nick);
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));
354 PUT_END_TAG (pfx + 1, "element-property");
356 PUT_END_TAG (pfx, "element-properties");
357 g_free (property_specs);
361 print_element_signals (GstElement * element, gint pfx)
368 signals = g_signal_list_ids (G_OBJECT_TYPE (element), &nsignals);
369 for (k = 0; k < 2; k++) {
373 PUT_START_TAG (pfx, "element-signals");
375 PUT_START_TAG (pfx, "element-actions");
377 for (i = 0; i < nsignals; i++) {
380 const GType *param_types;
383 query = g_new0 (GSignalQuery, 1);
384 g_signal_query (signals[i], query);
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;
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)));
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]));
403 PUT_END_TAG (pfx + 2, "params");
405 PUT_END_TAG (pfx + 1, "signal");
413 PUT_END_TAG (pfx, "element-signals");
415 PUT_END_TAG (pfx, "element-actions");
420 print_element_info (GstElementFactory * factory)
423 GstObjectClass *gstobject_class;
424 GstElementClass *gstelement_class;
427 GstStaticPadTemplate *padtemplate;
430 element = gst_element_factory_create (factory, "element");
432 g_print ("couldn't construct element for some reason\n");
435 PUT_START_TAG (0, "element");
436 PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory));
438 gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
439 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
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");
448 output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
450 PUT_START_TAG (1, "pad-templates");
451 if (factory->numpadtemplates) {
452 pads = factory->staticpadtemplates;
454 padtemplate = (GstStaticPadTemplate *) (pads->data);
455 pads = g_list_next (pads);
457 PUT_START_TAG (2, "pad-template");
458 PUT_ESCAPED (3, "name", padtemplate->name_template);
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");
465 PUT_ESCAPED (3, "direction", "unknown");
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));
476 PUT_ESCAPED (3, "presence", "unknown");
478 if (padtemplate->static_caps.string) {
479 print_caps (gst_static_caps_get (&padtemplate->static_caps), 3);
481 PUT_END_TAG (2, "pad-template");
484 PUT_END_TAG (1, "pad-templates");
486 PUT_START_TAG (1, "element-flags");
487 PUT_END_TAG (1, "element-flags");
489 if (GST_IS_BIN (element)) {
490 PUT_START_TAG (1, "bin-flags");
492 PUT_END_TAG (1, "bin-flags");
496 PUT_START_TAG (1, "element-implementation");
498 PUT_STRING (2, "<state-change function=\"%s\"/>",
499 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
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));
507 PUT_END_TAG (1, "element-implementation");
509 PUT_START_TAG (1, "clocking-interaction");
510 if (gst_element_requires_clock (element)) {
511 PUT_STRING (2, "<requires-clock/>");
513 if (gst_element_provides_clock (element)) {
516 clock = gst_element_get_clock (element);
518 PUT_STRING (2, "<provides-clock name=\"%s\"/>", GST_OBJECT_NAME (clock));
520 PUT_END_TAG (1, "clocking-interaction");
522 #ifndef GST_DISABLE_INDEX
523 if (gst_element_is_indexable (element)) {
524 PUT_STRING (1, "<indexing-capabilities/>");
528 PUT_START_TAG (1, "pads");
529 if (element->numpads) {
532 pads = element->pads;
534 pad = GST_PAD (pads->data);
535 pads = g_list_next (pads);
537 PUT_START_TAG (2, "pad");
538 PUT_ESCAPED (3, "name", gst_pad_get_name (pad));
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");
545 PUT_ESCAPED (3, "direction", "unknown");
547 if (pad->padtemplate)
548 PUT_ESCAPED (3, "template", pad->padtemplate->name_template);
550 PUT_START_TAG (3, "implementation");
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");
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));
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");
580 print_caps (pad->caps, 3);
582 PUT_END_TAG (2, "pad");
585 PUT_END_TAG (1, "pads");
587 print_element_properties (element, 1);
588 print_element_signals (element, 1);
590 /* for compound elements */
591 /* FIXME: gst_bin_get_list does not exist anymore
592 if (GST_IS_BIN (element)) {
595 PUT_START_TAG (1, "children");
596 children = (GList *) gst_bin_get_list (GST_BIN (element));
598 child = GST_ELEMENT (children->data);
599 children = g_list_next (children);
601 PUT_ESCAPED (2, "child", GST_ELEMENT_NAME (child));
603 PUT_END_TAG (1, "children");
606 PUT_END_TAG (0, "element");
612 print_element_list (void)
616 plugins = gst_default_registry_get_plugin_list ();
621 plugin = (GstPlugin *) (plugins->data);
622 plugins = g_list_next (plugins);
625 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
628 GstPluginFeature *feature;
630 feature = GST_PLUGIN_FEATURE (features->data);
632 if (GST_IS_ELEMENT_FACTORY (feature)) {
633 GstElementFactory *factory;
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);
639 #ifndef GST_DISABLE_INDEX
640 else if (GST_IS_INDEX_FACTORY (feature)) {
641 GstIndexFactory *factory;
643 factory = GST_INDEX_FACTORY (feature);
644 g_print ("%s: %s: %s\n", plugin->desc.name,
645 GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
648 else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
649 GstTypeFindFactory *factory;
651 factory = GST_TYPE_FIND_FACTORY (feature);
652 if (factory->extensions) {
655 g_print ("%s type: ", plugin->desc.name);
656 while (factory->extensions[i]) {
657 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
661 g_print ("%s type: N/A\n", plugin->desc.name);
663 g_print ("%s: %s (%s)\n", plugin->desc.name,
664 GST_PLUGIN_FEATURE_NAME (feature),
665 g_type_name (G_OBJECT_TYPE (feature)));
668 features = g_list_next (features);
674 print_plugin_info (GstPlugin * plugin)
677 gint num_features = 0;
678 gint num_elements = 0;
679 gint num_autoplug = 0;
681 gint num_indexes = 0;
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);
695 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
699 GstPluginFeature *feature;
701 feature = GST_PLUGIN_FEATURE (features->data);
703 if (GST_IS_ELEMENT_FACTORY (feature)) {
704 GstElementFactory *factory;
706 factory = GST_ELEMENT_FACTORY (feature);
707 g_print (" %s: %s\n", GST_OBJECT_NAME (factory),
708 factory->details.longname);
711 #ifndef GST_DISABLE_INDEX
712 else if (GST_IS_INDEX_FACTORY (feature)) {
713 GstIndexFactory *factory;
715 factory = GST_INDEX_FACTORY (feature);
716 g_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
720 else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
721 GstTypeFindFactory *factory;
723 factory = GST_TYPE_FIND_FACTORY (feature);
724 if (factory->extensions) {
727 g_print ("%s type: ", plugin->desc.name);
728 while (factory->extensions[i]) {
729 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
733 g_print ("%s type: N/A\n", plugin->desc.name);
736 g_print (" %s (%s)\n", GST_OBJECT_NAME (feature),
737 g_type_name (G_OBJECT_TYPE (feature)));
741 features = g_list_next (features);
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);
749 g_print (" +-- %d types\n", num_types);
751 g_print (" +-- %d indexes\n", num_indexes);
753 g_print (" +-- %d other objects\n", num_other);
760 main (int argc, char *argv[])
762 GstElementFactory *factory;
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,
776 setlocale (LC_ALL, "");
778 if (!g_thread_supported ())
779 g_thread_init (NULL);
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);
788 g_option_context_free (ctx);
790 gst_tools_print_version ("gst-xmlinspect");
792 PUT_STRING (0, "<?xml version=\"1.0\"?>");
794 /* if no arguments, print out list of elements */
796 print_element_list ();
798 /* else we try to get a factory */
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",
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]);
813 /* if there's a factory, print out the info */
815 return print_element_info (factory);
817 GstPluginFeature *feature;
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);
824 g_print ("%s: an index\n", argv[1]);
828 feature = gst_default_registry_find_feature (argv[1],
829 GST_TYPE_TYPE_FIND_FACTORY);
831 g_print ("%s: a type find function\n", argv[1]);
837 so = strstr (argv[1], ".so");
841 /* otherwise assume it's a plugin */
842 plugin = gst_default_registry_find_plugin (argv[1]);
844 /* if there is such a plugin, print out info */
847 print_plugin_info (plugin);
849 g_print ("no such element or plugin '%s'\n", argv[1]);