2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2004 Thomas Vander Stichele <thomas@apestaart.org>
6 * gst-inspect.c: tool to inspect the GStreamer registry
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
25 * with newer GLib versions (>= 2.31.0) */
26 #define GLIB_DISABLE_DEPRECATION_WARNINGS
36 #include <glib/gprintf.h>
38 static char *_name = NULL;
40 static int print_element_info (GstElementFactory * factory,
41 gboolean print_names);
44 n_print (const char *format, ...)
49 g_print ("%s", _name);
51 va_start (args, format);
52 g_vprintf (format, args);
57 print_field (GQuark field, const GValue * value, gpointer pfx)
59 gchar *str = gst_value_serialize (value);
61 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
67 print_caps (const GstCaps * caps, const gchar * pfx)
71 g_return_if_fail (caps != NULL);
73 if (gst_caps_is_any (caps)) {
74 n_print ("%sANY\n", pfx);
77 if (gst_caps_is_empty (caps)) {
78 n_print ("%sEMPTY\n", pfx);
82 for (i = 0; i < gst_caps_get_size (caps); i++) {
83 GstStructure *structure = gst_caps_get_structure (caps, i);
85 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
86 gst_structure_foreach (structure, print_field, (gpointer) pfx);
92 print_formats (const GstFormat * formats)
94 while (formats && *formats) {
95 const GstFormatDefinition *definition;
97 definition = gst_format_get_details (*formats);
99 n_print ("\t\t(%d):\t%s (%s)\n", *formats,
100 definition->nick, definition->description);
102 n_print ("\t\t(%d):\tUnknown format\n", *formats);
109 print_event_masks (const GstEventMask * masks)
114 GFlagsClass *flags_class = NULL;
116 event_type = gst_event_type_get_type ();
117 klass = (GEnumClass *) g_type_class_ref (event_type);
119 while (masks && masks->type) {
121 gint flags = 0, index = 0;
123 switch (masks->type) {
125 flags = masks->flags;
126 event_flags = gst_seek_type_get_type ();
127 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
133 value = g_enum_get_value (klass, masks->type);
134 g_print ("\t\t%s ", value->value_nick);
140 value = g_flags_get_first_value (flags_class, 1 << index);
143 g_print ("| %s ", value->value_nick);
158 get_rank_name (char *s, gint rank)
160 static const int ranks[4] = {
161 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
163 static const char *rank_names[4] = { "none", "marginal", "secondary",
170 for (i = 0; i < 4; i++) {
171 if (rank == ranks[i])
172 return rank_names[i];
173 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
178 sprintf (s, "%s %c %d", rank_names[best_i],
179 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
185 print_factory_details_metadata (GQuark field_id, const GValue * value,
188 gchar *val = g_strdup_value_contents (value);
189 gchar *key = g_strdup (g_quark_to_string (field_id));
191 key[0] = g_ascii_toupper (key[0]);
192 n_print (" %s:\t\t%s\n", key, val);
199 print_factory_details_info (GstElementFactory * factory)
203 n_print ("Factory Details:\n");
204 n_print (" Rank:\t\t%s (%d)\n",
205 get_rank_name (s, GST_PLUGIN_FEATURE (factory)->rank),
206 GST_PLUGIN_FEATURE (factory)->rank);
207 gst_structure_foreach ((GstStructure *) factory->metadata,
208 print_factory_details_metadata, NULL);
213 print_hierarchy (GType type, gint level, gint * maxlevel)
218 parent = g_type_parent (type);
220 *maxlevel = *maxlevel + 1;
224 print_hierarchy (parent, level, maxlevel);
227 g_print ("%s", _name);
229 for (i = 1; i < *maxlevel - level; i++)
231 if (*maxlevel - level)
234 g_print ("%s\n", g_type_name (type));
241 print_interfaces (GType type)
244 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
249 g_print ("%s", _name);
250 g_print (_("Implemented Interfaces:\n"));
254 g_print ("%s", _name);
255 g_print (" %s\n", g_type_name (*iface));
259 g_print ("%s", _name);
267 flags_to_string (GFlagsValue * vals, guint flags)
272 /* first look for an exact match and count the number of values */
273 for (i = 0; vals[i].value_name != NULL; ++i) {
274 if (vals[i].value == flags)
275 return g_strdup (vals[i].value_nick);
278 s = g_string_new (NULL);
280 /* we assume the values are sorted from lowest to highest value */
284 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
286 g_string_append_c (s, '+');
287 g_string_append (s, vals[i].value_nick);
288 flags_left -= vals[i].value;
295 g_string_assign (s, "(none)");
297 return g_string_free (s, FALSE);
300 #define KNOWN_PARAM_FLAGS \
301 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
302 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
303 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
304 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
305 GST_PARAM_MUTABLE_READY)
308 print_element_properties_info (GstElement * element)
310 GParamSpec **property_specs;
311 guint num_properties, i;
315 property_specs = g_object_class_list_properties
316 (G_OBJECT_GET_CLASS (element), &num_properties);
318 n_print ("Element Properties:\n");
320 for (i = 0; i < num_properties; i++) {
321 GValue value = { 0, };
322 GParamSpec *param = property_specs[i];
326 g_value_init (&value, param->value_type);
328 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
329 g_param_spec_get_blurb (param));
332 n_print ("%-23.23s flags: ", "");
333 if (param->flags & G_PARAM_READABLE) {
334 g_object_get_property (G_OBJECT (element), param->name, &value);
336 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
339 /* if we can't read the property value, assume it's set to the default
340 * (which might not be entirely true for sub-classes, but that's an
341 * unlikely corner-case anyway) */
342 g_param_value_set_default (param, &value);
344 if (param->flags & G_PARAM_WRITABLE) {
345 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
348 if (param->flags & GST_PARAM_CONTROLLABLE) {
349 g_print (", %s", _("controllable"));
352 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
353 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
354 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
355 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
356 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
357 g_print (", %s", _("changeable only in NULL or READY state"));
359 if (param->flags & ~KNOWN_PARAM_FLAGS) {
360 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
361 param->flags & ~KNOWN_PARAM_FLAGS);
365 switch (G_VALUE_TYPE (&value)) {
368 const char *string_val = g_value_get_string (&value);
370 n_print ("%-23.23s String. ", "");
372 if (string_val == NULL)
373 g_print ("Default: null");
375 g_print ("Default: \"%s\"", string_val);
380 gboolean bool_val = g_value_get_boolean (&value);
382 n_print ("%-23.23s Boolean. ", "");
384 g_print ("Default: %s", bool_val ? "true" : "false");
389 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
391 n_print ("%-23.23s Unsigned Long. ", "");
392 g_print ("Range: %lu - %lu Default: %lu ",
393 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
395 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
396 "uint/uint64", GST_OBJECT_NAME (element),
397 g_param_spec_get_name (param));
402 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
404 n_print ("%-23.23s Long. ", "");
405 g_print ("Range: %ld - %ld Default: %ld ",
406 plong->minimum, plong->maximum, g_value_get_long (&value));
408 GST_ERROR ("%s: property '%s' of type long: consider changing to "
409 "int/int64", GST_OBJECT_NAME (element),
410 g_param_spec_get_name (param));
415 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
417 n_print ("%-23.23s Unsigned Integer. ", "");
418 g_print ("Range: %u - %u Default: %u ",
419 puint->minimum, puint->maximum, g_value_get_uint (&value));
424 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
426 n_print ("%-23.23s Integer. ", "");
427 g_print ("Range: %d - %d Default: %d ",
428 pint->minimum, pint->maximum, g_value_get_int (&value));
433 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
435 n_print ("%-23.23s Unsigned Integer64. ", "");
436 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
437 " Default: %" G_GUINT64_FORMAT " ",
438 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
443 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
445 n_print ("%-23.23s Integer64. ", "");
446 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
447 " Default: %" G_GINT64_FORMAT " ",
448 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
453 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
455 n_print ("%-23.23s Float. ", "");
456 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
457 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
462 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
464 n_print ("%-23.23s Double. ", "");
465 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
466 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
471 GST_ERROR ("%s: property '%s' of type char: consider changing to "
472 "int/string", GST_OBJECT_NAME (element),
473 g_param_spec_get_name (param));
476 if (param->value_type == GST_TYPE_CAPS) {
477 const GstCaps *caps = gst_value_get_caps (&value);
480 n_print ("%-23.23s Caps (NULL)", "");
482 print_caps (caps, " ");
484 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
488 const gchar *value_nick = "";
490 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
491 enum_value = g_value_get_enum (&value);
493 while (values[j].value_name) {
494 if (values[j].value == enum_value)
495 value_nick = values[j].value_nick;
499 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
500 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
503 while (values[j].value_name) {
506 g_print ("%s", _name);
507 g_print ("%-23.23s (%d): %-16s - %s", "",
508 values[j].value, values[j].value_nick, values[j].value_name);
511 /* g_type_class_unref (ec); */
512 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
513 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
517 vals = pflags->flags_class->values;
519 cur = flags_to_string (vals, g_value_get_flags (&value));
521 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
522 g_type_name (G_VALUE_TYPE (&value)),
523 g_value_get_flags (&value), cur);
525 while (vals[0].value_name) {
528 g_print ("%s", _name);
529 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
530 vals[0].value, vals[0].value_nick, vals[0].value_name);
535 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
536 n_print ("%-23.23s Object of type \"%s\"", "",
537 g_type_name (param->value_type));
538 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
539 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
540 g_type_name (param->value_type));
541 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
542 if (param->value_type != G_TYPE_POINTER) {
543 n_print ("%-23.23s Pointer of type \"%s\".", "",
544 g_type_name (param->value_type));
546 n_print ("%-23.23s Pointer.", "");
548 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
549 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
551 if (pvarray->element_spec) {
552 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
553 g_type_name (pvarray->element_spec->value_type));
555 n_print ("%-23.23s Array of GValues", "");
557 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
558 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
560 n_print ("%-23.23s Fraction. ", "");
562 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
563 pfraction->min_num, pfraction->min_den,
564 pfraction->max_num, pfraction->max_den,
565 gst_value_get_fraction_numerator (&value),
566 gst_value_get_fraction_denominator (&value));
568 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
569 g_type_name (param->value_type));
574 g_print (" Write only\n");
578 g_value_reset (&value);
580 if (num_properties == 0)
583 g_free (property_specs);
587 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
589 GstElementClass *gstelement_class;
591 GstStaticPadTemplate *padtemplate;
593 n_print ("Pad Templates:\n");
594 if (!factory->numpadtemplates) {
599 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
601 pads = factory->staticpadtemplates;
603 padtemplate = (GstStaticPadTemplate *) (pads->data);
604 pads = g_list_next (pads);
606 if (padtemplate->direction == GST_PAD_SRC)
607 n_print (" SRC template: '%s'\n", padtemplate->name_template);
608 else if (padtemplate->direction == GST_PAD_SINK)
609 n_print (" SINK template: '%s'\n", padtemplate->name_template);
611 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
613 if (padtemplate->presence == GST_PAD_ALWAYS)
614 n_print (" Availability: Always\n");
615 else if (padtemplate->presence == GST_PAD_SOMETIMES)
616 n_print (" Availability: Sometimes\n");
617 else if (padtemplate->presence == GST_PAD_REQUEST) {
618 n_print (" Availability: On request\n");
619 n_print (" Has request_new_pad() function: %s\n",
620 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
622 n_print (" Availability: UNKNOWN!!!\n");
624 if (padtemplate->static_caps.string) {
625 n_print (" Capabilities:\n");
626 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
634 print_element_flag_info (GstElement * element)
636 gboolean have_flags = FALSE;
639 n_print ("Element Flags:\n");
642 n_print (" no flags set\n");
644 if (GST_IS_BIN (element)) {
646 n_print ("Bin Flags:\n");
648 n_print (" no flags set\n");
653 print_implementation_info (GstElement * element)
655 GstElementClass *gstelement_class;
657 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
660 n_print ("Element Implementation:\n");
662 n_print (" Has change_state() function: %s\n",
663 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
667 print_clocking_info (GstElement * element)
669 gboolean requires_clock, provides_clock;
672 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
674 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
676 if (!requires_clock && !provides_clock) {
678 n_print ("Element has no clocking capabilities.");
683 n_print ("Clocking Interaction:\n");
684 if (requires_clock) {
685 n_print (" element requires a clock\n");
688 if (provides_clock) {
691 clock = gst_element_get_clock (element);
693 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
694 gst_object_unref (clock);
696 n_print (" element is supposed to provide a clock but returned NULL\n");
701 print_index_info (GstElement * element)
703 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
705 n_print ("Indexing capabilities:\n");
706 n_print (" element can do indexing\n");
709 n_print ("Element has no indexing capabilities.\n");
714 print_uri_handler_info (GstElement * element)
716 if (GST_IS_URI_HANDLER (element)) {
717 const gchar *const *uri_protocols;
718 const gchar *uri_type;
720 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
722 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
726 uri_type = "unknown";
728 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
731 n_print ("URI handling capabilities:\n");
732 n_print (" Element can act as %s.\n", uri_type);
734 if (uri_protocols && *uri_protocols) {
735 n_print (" Supported URI protocols:\n");
736 for (; *uri_protocols != NULL; uri_protocols++)
737 n_print (" %s\n", *uri_protocols);
739 n_print (" No supported URI protocols\n");
742 n_print ("Element has no URI handling capabilities.\n");
747 print_pad_info (GstElement * element)
755 if (!element->numpads) {
760 pads = element->pads;
765 pad = GST_PAD (pads->data);
766 pads = g_list_next (pads);
770 name = gst_pad_get_name (pad);
771 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
772 g_print (" SRC: '%s'", name);
773 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
774 g_print (" SINK: '%s'", name);
776 g_print (" UNKNOWN!!!: '%s'", name);
782 n_print (" Implementation:\n");
784 n_print (" Has chainfunc(): %s\n",
785 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
786 if (pad->getrangefunc)
787 n_print (" Has getrangefunc(): %s\n",
788 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
789 if (pad->eventfunc != gst_pad_event_default)
790 n_print (" Has custom eventfunc(): %s\n",
791 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
792 if (pad->queryfunc != gst_pad_query_default)
793 n_print (" Has custom queryfunc(): %s\n",
794 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
796 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
797 n_print (" Has custom iterintlinkfunc(): %s\n",
798 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
800 if (pad->padtemplate)
801 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
803 caps = gst_pad_get_current_caps (pad);
805 n_print (" Capabilities:\n");
806 print_caps (caps, " ");
807 gst_caps_unref (caps);
813 has_sometimes_template (GstElement * element)
815 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
818 for (l = klass->padtemplates; l != NULL; l = l->next) {
819 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
827 print_signal_info (GstElement * element)
829 /* Signals/Actions Block */
833 GSignalQuery *query = NULL;
835 GSList *found_signals, *l;
837 for (k = 0; k < 2; k++) {
838 found_signals = NULL;
840 /* For elements that have sometimes pads, also list a few useful GstElement
841 * signals. Put these first, so element-specific ones come later. */
842 if (k == 0 && has_sometimes_template (element)) {
843 query = g_new0 (GSignalQuery, 1);
844 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
845 found_signals = g_slist_append (found_signals, query);
846 query = g_new0 (GSignalQuery, 1);
847 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
848 found_signals = g_slist_append (found_signals, query);
849 query = g_new0 (GSignalQuery, 1);
850 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
852 found_signals = g_slist_append (found_signals, query);
855 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
856 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
859 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
862 signals = g_signal_list_ids (type, &nsignals);
863 for (i = 0; i < nsignals; i++) {
864 query = g_new0 (GSignalQuery, 1);
865 g_signal_query (signals[i], query);
867 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
868 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
869 found_signals = g_slist_append (found_signals, query);
880 n_print ("Element Signals:\n");
882 n_print ("Element Actions:\n");
887 for (l = found_signals; l; l = l->next) {
891 query = (GSignalQuery *) l->data;
892 indent_len = strlen (query->signal_name) +
893 strlen (g_type_name (query->return_type)) + 24;
895 indent = g_new0 (gchar, indent_len + 1);
896 memset (indent, ' ', indent_len);
898 n_print (" \"%s\" : %s user_function (%s* object",
900 g_type_name (query->return_type), g_type_name (type));
902 for (j = 0; j < query->n_params; j++) {
904 g_print ("%s", _name);
905 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
906 g_print (",\n%s%s arg%d", indent,
907 g_type_name (query->param_types[j]), j);
908 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
909 g_print (",\n%s%s arg%d", indent,
910 g_type_name (query->param_types[j]), j);
912 g_print (",\n%s%s* arg%d", indent,
913 g_type_name (query->param_types[j]), j);
919 g_print ("%s", _name);
920 g_print (",\n%sgpointer user_data);\n", indent);
928 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
929 g_slist_free (found_signals);
935 print_children_info (GstElement * element)
939 if (!GST_IS_BIN (element))
942 children = (GList *) GST_BIN (element)->children;
945 g_print ("Children:\n");
949 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
950 children = g_list_next (children);
955 print_blacklist (void)
957 GList *plugins, *cur;
960 g_print ("%s\n", _("Blacklisted files:"));
962 plugins = gst_registry_get_plugin_list (gst_registry_get ());
963 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
964 GstPlugin *plugin = (GstPlugin *) (cur->data);
965 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
966 g_print (" %s\n", plugin->desc.name);
972 g_print (_("Total count: "));
973 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
976 gst_plugin_list_free (plugins);
980 print_element_list (gboolean print_all)
982 int plugincount = 0, featurecount = 0, blacklistcount = 0;
983 GList *plugins, *orig_plugins;
985 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
987 GList *features, *orig_features;
990 plugin = (GstPlugin *) (plugins->data);
991 plugins = g_list_next (plugins);
994 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
999 orig_features = features =
1000 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1003 GstPluginFeature *feature;
1005 if (G_UNLIKELY (features->data == NULL))
1007 feature = GST_PLUGIN_FEATURE (features->data);
1010 if (GST_IS_ELEMENT_FACTORY (feature)) {
1011 GstElementFactory *factory;
1013 factory = GST_ELEMENT_FACTORY (feature);
1015 print_element_info (factory, TRUE);
1017 g_print ("%s: %s: %s\n", plugin->desc.name,
1018 GST_OBJECT_NAME (factory),
1019 gst_element_factory_get_longname (factory));
1021 } else if (GST_IS_INDEX_FACTORY (feature)) {
1022 GstIndexFactory *factory;
1024 factory = GST_INDEX_FACTORY (feature);
1026 g_print ("%s: %s: %s\n", plugin->desc.name,
1027 GST_OBJECT_NAME (factory), factory->longdesc);
1029 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1030 GstTypeFindFactory *factory;
1032 factory = GST_TYPE_FIND_FACTORY (feature);
1034 g_print ("%s: %s: ", plugin->desc.name,
1035 gst_plugin_feature_get_name (feature));
1036 if (factory->extensions) {
1039 while (factory->extensions[i]) {
1041 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1048 g_print ("no extensions\n");
1052 n_print ("%s: %s (%s)\n", plugin->desc.name,
1053 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1057 features = g_list_next (features);
1060 gst_plugin_feature_list_free (orig_features);
1063 gst_plugin_list_free (orig_plugins);
1066 g_print (_("Total count: "));
1067 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1068 if (blacklistcount) {
1070 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1071 blacklistcount), blacklistcount);
1072 g_print (" not shown)");
1075 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1080 print_all_uri_handlers (void)
1082 GList *plugins, *p, *features, *f;
1084 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1086 for (p = plugins; p; p = p->next) {
1087 GstPlugin *plugin = (GstPlugin *) (p->data);
1090 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1093 for (f = features; f; f = f->next) {
1094 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1096 if (GST_IS_ELEMENT_FACTORY (feature)) {
1097 GstElementFactory *factory;
1098 GstElement *element;
1100 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1102 g_print ("element plugin %s couldn't be loaded\n", plugin->desc.name);
1106 element = gst_element_factory_create (factory, NULL);
1108 g_print ("couldn't construct element for %s for some reason\n",
1109 GST_OBJECT_NAME (factory));
1110 gst_object_unref (factory);
1114 if (GST_IS_URI_HANDLER (element)) {
1115 const gchar *const *uri_protocols;
1119 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1132 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1133 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1135 g_print ("%s (%s, rank %u): %s\n",
1136 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1137 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1143 gst_object_unref (element);
1144 gst_object_unref (factory);
1148 gst_plugin_feature_list_free (features);
1151 gst_plugin_list_free (plugins);
1155 print_plugin_info (GstPlugin * plugin)
1157 n_print ("Plugin Details:\n");
1158 n_print (" Name:\t\t\t%s\n", plugin->desc.name);
1159 n_print (" Description:\t\t%s\n", plugin->desc.description);
1160 n_print (" Filename:\t\t%s\n",
1161 plugin->filename ? plugin->filename : "(null)");
1162 n_print (" Version:\t\t%s\n", plugin->desc.version);
1163 n_print (" License:\t\t%s\n", plugin->desc.license);
1164 n_print (" Source module:\t%s\n", plugin->desc.source);
1165 if (plugin->desc.release_datetime != NULL) {
1166 const gchar *tz = "(UTC)";
1169 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1170 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1171 str = g_strdup (plugin->desc.release_datetime);
1172 sep = strstr (str, "T");
1175 sep = strstr (sep + 1, "Z");
1181 n_print (" Source release date:\t%s%s\n", str, tz);
1184 n_print (" Binary package:\t%s\n", plugin->desc.package);
1185 n_print (" Origin URL:\t\t%s\n", plugin->desc.origin);
1190 print_plugin_features (GstPlugin * plugin)
1192 GList *features, *origlist;
1193 gint num_features = 0;
1194 gint num_elements = 0;
1195 gint num_typefinders = 0;
1196 gint num_indexes = 0;
1199 origlist = features =
1200 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1204 GstPluginFeature *feature;
1206 feature = GST_PLUGIN_FEATURE (features->data);
1208 if (GST_IS_ELEMENT_FACTORY (feature)) {
1209 GstElementFactory *factory;
1211 factory = GST_ELEMENT_FACTORY (feature);
1212 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1213 gst_element_factory_get_longname (factory));
1216 } else if (GST_IS_INDEX_FACTORY (feature)) {
1217 GstIndexFactory *factory;
1219 factory = GST_INDEX_FACTORY (feature);
1220 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1223 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1224 GstTypeFindFactory *factory;
1226 factory = GST_TYPE_FIND_FACTORY (feature);
1227 if (factory->extensions) {
1230 g_print ("%s: %s: ", plugin->desc.name,
1231 gst_plugin_feature_get_name (feature));
1232 while (factory->extensions[i]) {
1233 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1238 g_print ("%s: %s: no extensions\n", plugin->desc.name,
1239 gst_plugin_feature_get_name (feature));
1242 } else if (feature) {
1243 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1244 g_type_name (G_OBJECT_TYPE (feature)));
1248 features = g_list_next (features);
1251 gst_plugin_feature_list_free (origlist);
1254 n_print (" %d features:\n", num_features);
1255 if (num_elements > 0)
1256 n_print (" +-- %d elements\n", num_elements);
1257 if (num_typefinders > 0)
1258 n_print (" +-- %d typefinders\n", num_typefinders);
1259 if (num_indexes > 0)
1260 n_print (" +-- %d indexes\n", num_indexes);
1262 n_print (" +-- %d other objects\n", num_other);
1268 print_element_features (const gchar * element_name)
1270 GstPluginFeature *feature;
1272 /* FIXME implement other pretty print function for these */
1274 feature = gst_default_registry_find_feature (element_name,
1275 GST_TYPE_INDEX_FACTORY);
1277 n_print ("%s: an index\n", element_name);
1281 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1282 GST_TYPE_TYPE_FIND_FACTORY);
1284 n_print ("%s: a typefind function\n", element_name);
1292 print_element_info (GstElementFactory * factory, gboolean print_names)
1294 GstElement *element;
1298 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1302 g_print ("element plugin couldn't be loaded\n");
1306 element = gst_element_factory_create (factory, NULL);
1308 gst_object_unref (factory);
1309 g_print ("couldn't construct element for some reason\n");
1314 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1318 print_factory_details_info (factory);
1319 if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
1322 plugin = gst_registry_find_plugin (gst_registry_get (),
1323 GST_PLUGIN_FEATURE (factory)->plugin_name);
1325 print_plugin_info (plugin);
1329 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1330 print_interfaces (G_OBJECT_TYPE (element));
1332 print_pad_templates_info (element, factory);
1333 print_element_flag_info (element);
1334 print_implementation_info (element);
1335 print_clocking_info (element);
1336 print_index_info (element);
1337 print_uri_handler_info (element);
1338 print_pad_info (element);
1339 print_element_properties_info (element);
1340 print_signal_info (element);
1341 print_children_info (element);
1343 gst_object_unref (element);
1344 gst_object_unref (factory);
1352 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1354 GstPadDirection direction;
1355 const gchar *type_name;
1357 const GList *static_templates, *l;
1358 GstCaps *caps = NULL;
1361 klass = gst_element_factory_get_klass (factory);
1362 g_return_if_fail (klass != NULL);
1364 if (strstr (klass, "Demuxer") ||
1365 strstr (klass, "Decoder") ||
1366 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1367 type_name = "decoder";
1368 direction = GST_PAD_SINK;
1369 } else if (strstr (klass, "Muxer") ||
1370 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1371 type_name = "encoder";
1372 direction = GST_PAD_SRC;
1377 /* decoder/demuxer sink pads should always be static and there should only
1378 * be one, the same applies to encoders/muxers and source pads */
1379 static_templates = gst_element_factory_get_static_pad_templates (factory);
1380 for (l = static_templates; l != NULL; l = l->next) {
1381 GstStaticPadTemplate *tmpl = NULL;
1383 tmpl = (GstStaticPadTemplate *) l->data;
1384 if (tmpl->direction == direction) {
1385 caps = gst_static_pad_template_get_caps (tmpl);
1391 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1392 type_name, GST_OBJECT_NAME (factory));
1396 caps = gst_caps_make_writable (caps);
1397 num = gst_caps_get_size (caps);
1398 for (i = 0; i < num; ++i) {
1402 s = gst_caps_get_structure (caps, i);
1403 /* remove fields that are almost always just MIN-MAX of some sort
1404 * in order to make the caps look less messy */
1405 gst_structure_remove_field (s, "pixel-aspect-ratio");
1406 gst_structure_remove_field (s, "framerate");
1407 gst_structure_remove_field (s, "channels");
1408 gst_structure_remove_field (s, "width");
1409 gst_structure_remove_field (s, "height");
1410 gst_structure_remove_field (s, "rate");
1411 gst_structure_remove_field (s, "depth");
1412 gst_structure_remove_field (s, "clock-rate");
1413 s_str = gst_structure_to_string (s);
1414 g_print ("%s-%s\n", type_name, s_str);
1417 gst_caps_unref (caps);
1421 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1423 const gchar *const *protocols;
1425 protocols = gst_element_factory_get_uri_protocols (factory);
1426 if (protocols != NULL && *protocols != NULL) {
1427 switch (gst_element_factory_get_uri_type (factory)) {
1429 while (*protocols != NULL) {
1430 g_print ("urisink-%s\n", *protocols);
1435 while (*protocols != NULL) {
1436 g_print ("urisource-%s\n", *protocols);
1447 print_plugin_automatic_install_info (GstPlugin * plugin)
1449 const gchar *plugin_name;
1450 GList *features, *l;
1452 plugin_name = gst_plugin_get_name (plugin);
1454 /* not interested in typefind factories, only element factories */
1455 features = gst_registry_get_feature_list (gst_registry_get (),
1456 GST_TYPE_ELEMENT_FACTORY);
1458 for (l = features; l != NULL; l = l->next) {
1459 GstPluginFeature *feature;
1461 feature = GST_PLUGIN_FEATURE (l->data);
1463 /* only interested in the ones that are in the plugin we just loaded */
1464 if (g_str_equal (plugin_name, feature->plugin_name)) {
1465 GstElementFactory *factory;
1467 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1469 factory = GST_ELEMENT_FACTORY (feature);
1470 print_plugin_automatic_install_info_protocols (factory);
1471 print_plugin_automatic_install_info_codecs (factory);
1475 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1476 g_list_free (features);
1480 print_all_plugin_automatic_install_info (void)
1482 GList *plugins, *orig_plugins;
1484 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1488 plugin = (GstPlugin *) (plugins->data);
1489 plugins = g_list_next (plugins);
1491 print_plugin_automatic_install_info (plugin);
1493 gst_plugin_list_free (orig_plugins);
1497 main (int argc, char *argv[])
1499 gboolean print_all = FALSE;
1500 gboolean do_print_blacklist = FALSE;
1501 gboolean plugin_name = FALSE;
1502 gboolean print_aii = FALSE;
1503 gboolean uri_handlers = FALSE;
1504 #ifndef GST_DISABLE_OPTION_PARSING
1505 GOptionEntry options[] = {
1506 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1507 N_("Print all elements"), NULL},
1508 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1509 N_("Print list of blacklisted files"), NULL},
1510 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1511 N_("Print a machine-parsable list of features the specified plugin "
1512 "or all plugins provide.\n "
1513 "Useful in connection with external automatic plugin "
1514 "installation mechanisms"), NULL},
1515 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1516 N_("List the plugin contents"), NULL},
1517 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1519 ("Print supported URI schemes, with the elements that implement them"),
1521 GST_TOOLS_GOPTION_VERSION,
1524 GOptionContext *ctx;
1529 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1530 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1531 textdomain (GETTEXT_PACKAGE);
1534 gst_tools_set_prgname ("gst-inspect");
1536 #ifndef GST_DISABLE_OPTION_PARSING
1537 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1538 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1539 g_option_context_add_group (ctx, gst_init_get_option_group ());
1540 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1541 g_print ("Error initializing: %s\n", err->message);
1544 g_option_context_free (ctx);
1546 gst_init (&argc, &argv);
1549 gst_tools_print_version ("gst-inspect");
1551 if (print_all && argc > 1) {
1552 g_print ("-a requires no extra arguments\n");
1556 if (uri_handlers && argc > 1) {
1557 g_print ("-u requires no extra arguments\n");
1561 /* if no arguments, print out list of elements */
1563 print_all_uri_handlers ();
1564 } else if (argc == 1 || print_all) {
1565 if (do_print_blacklist)
1569 print_all_plugin_automatic_install_info ();
1571 print_element_list (print_all);
1574 /* else we try to get a factory */
1575 GstElementFactory *factory;
1577 const char *arg = argv[argc - 1];
1581 factory = gst_element_factory_find (arg);
1583 /* if there's a factory, print out the info */
1585 retval = print_element_info (factory, print_all);
1586 gst_object_unref (factory);
1588 retval = print_element_features (arg);
1594 /* otherwise check if it's a plugin */
1596 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1598 /* if there is such a plugin, print out info */
1601 print_plugin_automatic_install_info (plugin);
1603 print_plugin_info (plugin);
1604 print_plugin_features (plugin);
1607 GError *error = NULL;
1609 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1610 plugin = gst_plugin_load_file (arg, &error);
1614 print_plugin_automatic_install_info (plugin);
1616 print_plugin_info (plugin);
1617 print_plugin_features (plugin);
1620 g_print (_("Could not load plugin file: %s\n"), error->message);
1621 g_error_free (error);
1625 g_print (_("No such element or plugin '%s'\n"), arg);