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_info (GstElementFactory * factory)
190 n_print ("Factory Details:\n");
191 n_print (" Rank:\t\t%s (%d)\n",
192 get_rank_name (s, GST_PLUGIN_FEATURE (factory)->rank),
193 GST_PLUGIN_FEATURE (factory)->rank);
195 keys = gst_element_factory_get_metadata_keys (factory);
197 for (k = keys; *k != NULL; ++k) {
201 val = gst_element_factory_get_metadata (factory, key);
202 key[0] = g_ascii_toupper (key[0]);
203 n_print (" %s:\t\t%s\n", key, val);
211 print_hierarchy (GType type, gint level, gint * maxlevel)
216 parent = g_type_parent (type);
218 *maxlevel = *maxlevel + 1;
222 print_hierarchy (parent, level, maxlevel);
225 g_print ("%s", _name);
227 for (i = 1; i < *maxlevel - level; i++)
229 if (*maxlevel - level)
232 g_print ("%s\n", g_type_name (type));
239 print_interfaces (GType type)
242 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
247 g_print ("%s", _name);
248 g_print (_("Implemented Interfaces:\n"));
252 g_print ("%s", _name);
253 g_print (" %s\n", g_type_name (*iface));
257 g_print ("%s", _name);
265 flags_to_string (GFlagsValue * vals, guint flags)
270 /* first look for an exact match and count the number of values */
271 for (i = 0; vals[i].value_name != NULL; ++i) {
272 if (vals[i].value == flags)
273 return g_strdup (vals[i].value_nick);
276 s = g_string_new (NULL);
278 /* we assume the values are sorted from lowest to highest value */
282 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
284 g_string_append_c (s, '+');
285 g_string_append (s, vals[i].value_nick);
286 flags_left -= vals[i].value;
293 g_string_assign (s, "(none)");
295 return g_string_free (s, FALSE);
298 #define KNOWN_PARAM_FLAGS \
299 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
300 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
301 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
302 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
303 GST_PARAM_MUTABLE_READY)
306 print_element_properties_info (GstElement * element)
308 GParamSpec **property_specs;
309 guint num_properties, i;
313 property_specs = g_object_class_list_properties
314 (G_OBJECT_GET_CLASS (element), &num_properties);
316 n_print ("Element Properties:\n");
318 for (i = 0; i < num_properties; i++) {
319 GValue value = { 0, };
320 GParamSpec *param = property_specs[i];
324 g_value_init (&value, param->value_type);
326 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
327 g_param_spec_get_blurb (param));
330 n_print ("%-23.23s flags: ", "");
331 if (param->flags & G_PARAM_READABLE) {
332 g_object_get_property (G_OBJECT (element), param->name, &value);
334 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
337 /* if we can't read the property value, assume it's set to the default
338 * (which might not be entirely true for sub-classes, but that's an
339 * unlikely corner-case anyway) */
340 g_param_value_set_default (param, &value);
342 if (param->flags & G_PARAM_WRITABLE) {
343 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
346 if (param->flags & GST_PARAM_CONTROLLABLE) {
347 g_print (", %s", _("controllable"));
350 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
351 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
352 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
353 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
354 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
355 g_print (", %s", _("changeable only in NULL or READY state"));
357 if (param->flags & ~KNOWN_PARAM_FLAGS) {
358 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
359 param->flags & ~KNOWN_PARAM_FLAGS);
363 switch (G_VALUE_TYPE (&value)) {
366 const char *string_val = g_value_get_string (&value);
368 n_print ("%-23.23s String. ", "");
370 if (string_val == NULL)
371 g_print ("Default: null");
373 g_print ("Default: \"%s\"", string_val);
378 gboolean bool_val = g_value_get_boolean (&value);
380 n_print ("%-23.23s Boolean. ", "");
382 g_print ("Default: %s", bool_val ? "true" : "false");
387 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
389 n_print ("%-23.23s Unsigned Long. ", "");
390 g_print ("Range: %lu - %lu Default: %lu ",
391 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
393 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
394 "uint/uint64", GST_OBJECT_NAME (element),
395 g_param_spec_get_name (param));
400 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
402 n_print ("%-23.23s Long. ", "");
403 g_print ("Range: %ld - %ld Default: %ld ",
404 plong->minimum, plong->maximum, g_value_get_long (&value));
406 GST_ERROR ("%s: property '%s' of type long: consider changing to "
407 "int/int64", GST_OBJECT_NAME (element),
408 g_param_spec_get_name (param));
413 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
415 n_print ("%-23.23s Unsigned Integer. ", "");
416 g_print ("Range: %u - %u Default: %u ",
417 puint->minimum, puint->maximum, g_value_get_uint (&value));
422 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
424 n_print ("%-23.23s Integer. ", "");
425 g_print ("Range: %d - %d Default: %d ",
426 pint->minimum, pint->maximum, g_value_get_int (&value));
431 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
433 n_print ("%-23.23s Unsigned Integer64. ", "");
434 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
435 " Default: %" G_GUINT64_FORMAT " ",
436 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
441 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
443 n_print ("%-23.23s Integer64. ", "");
444 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
445 " Default: %" G_GINT64_FORMAT " ",
446 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
451 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
453 n_print ("%-23.23s Float. ", "");
454 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
455 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
460 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
462 n_print ("%-23.23s Double. ", "");
463 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
464 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
469 GST_ERROR ("%s: property '%s' of type char: consider changing to "
470 "int/string", GST_OBJECT_NAME (element),
471 g_param_spec_get_name (param));
474 if (param->value_type == GST_TYPE_CAPS) {
475 const GstCaps *caps = gst_value_get_caps (&value);
478 n_print ("%-23.23s Caps (NULL)", "");
480 print_caps (caps, " ");
482 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
486 const gchar *value_nick = "";
488 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
489 enum_value = g_value_get_enum (&value);
491 while (values[j].value_name) {
492 if (values[j].value == enum_value)
493 value_nick = values[j].value_nick;
497 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
498 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
501 while (values[j].value_name) {
504 g_print ("%s", _name);
505 g_print ("%-23.23s (%d): %-16s - %s", "",
506 values[j].value, values[j].value_nick, values[j].value_name);
509 /* g_type_class_unref (ec); */
510 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
511 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
515 vals = pflags->flags_class->values;
517 cur = flags_to_string (vals, g_value_get_flags (&value));
519 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
520 g_type_name (G_VALUE_TYPE (&value)),
521 g_value_get_flags (&value), cur);
523 while (vals[0].value_name) {
526 g_print ("%s", _name);
527 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
528 vals[0].value, vals[0].value_nick, vals[0].value_name);
533 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
534 n_print ("%-23.23s Object of type \"%s\"", "",
535 g_type_name (param->value_type));
536 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
537 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
538 g_type_name (param->value_type));
539 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
540 if (param->value_type != G_TYPE_POINTER) {
541 n_print ("%-23.23s Pointer of type \"%s\".", "",
542 g_type_name (param->value_type));
544 n_print ("%-23.23s Pointer.", "");
546 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
547 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
549 if (pvarray->element_spec) {
550 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
551 g_type_name (pvarray->element_spec->value_type));
553 n_print ("%-23.23s Array of GValues", "");
555 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
556 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
558 n_print ("%-23.23s Fraction. ", "");
560 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
561 pfraction->min_num, pfraction->min_den,
562 pfraction->max_num, pfraction->max_den,
563 gst_value_get_fraction_numerator (&value),
564 gst_value_get_fraction_denominator (&value));
566 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
567 g_type_name (param->value_type));
572 g_print (" Write only\n");
576 g_value_reset (&value);
578 if (num_properties == 0)
581 g_free (property_specs);
585 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
587 GstElementClass *gstelement_class;
589 GstStaticPadTemplate *padtemplate;
591 n_print ("Pad Templates:\n");
592 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
597 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
599 pads = gst_element_factory_get_static_pad_templates (factory);
601 padtemplate = (GstStaticPadTemplate *) (pads->data);
602 pads = g_list_next (pads);
604 if (padtemplate->direction == GST_PAD_SRC)
605 n_print (" SRC template: '%s'\n", padtemplate->name_template);
606 else if (padtemplate->direction == GST_PAD_SINK)
607 n_print (" SINK template: '%s'\n", padtemplate->name_template);
609 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
611 if (padtemplate->presence == GST_PAD_ALWAYS)
612 n_print (" Availability: Always\n");
613 else if (padtemplate->presence == GST_PAD_SOMETIMES)
614 n_print (" Availability: Sometimes\n");
615 else if (padtemplate->presence == GST_PAD_REQUEST) {
616 n_print (" Availability: On request\n");
617 n_print (" Has request_new_pad() function: %s\n",
618 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
620 n_print (" Availability: UNKNOWN!!!\n");
622 if (padtemplate->static_caps.string) {
623 n_print (" Capabilities:\n");
624 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
632 print_element_flag_info (GstElement * element)
634 gboolean have_flags = FALSE;
637 n_print ("Element Flags:\n");
640 n_print (" no flags set\n");
642 if (GST_IS_BIN (element)) {
644 n_print ("Bin Flags:\n");
646 n_print (" no flags set\n");
651 print_implementation_info (GstElement * element)
653 GstElementClass *gstelement_class;
655 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
658 n_print ("Element Implementation:\n");
660 n_print (" Has change_state() function: %s\n",
661 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
665 print_clocking_info (GstElement * element)
667 gboolean requires_clock, provides_clock;
670 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
672 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
674 if (!requires_clock && !provides_clock) {
676 n_print ("Element has no clocking capabilities.");
681 n_print ("Clocking Interaction:\n");
682 if (requires_clock) {
683 n_print (" element requires a clock\n");
686 if (provides_clock) {
689 clock = gst_element_get_clock (element);
691 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
692 gst_object_unref (clock);
694 n_print (" element is supposed to provide a clock but returned NULL\n");
699 print_index_info (GstElement * element)
701 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
703 n_print ("Indexing capabilities:\n");
704 n_print (" element can do indexing\n");
707 n_print ("Element has no indexing capabilities.\n");
712 print_uri_handler_info (GstElement * element)
714 if (GST_IS_URI_HANDLER (element)) {
715 const gchar *const *uri_protocols;
716 const gchar *uri_type;
718 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
720 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
724 uri_type = "unknown";
726 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
729 n_print ("URI handling capabilities:\n");
730 n_print (" Element can act as %s.\n", uri_type);
732 if (uri_protocols && *uri_protocols) {
733 n_print (" Supported URI protocols:\n");
734 for (; *uri_protocols != NULL; uri_protocols++)
735 n_print (" %s\n", *uri_protocols);
737 n_print (" No supported URI protocols\n");
740 n_print ("Element has no URI handling capabilities.\n");
745 print_pad_info (GstElement * element)
753 if (!element->numpads) {
758 pads = element->pads;
763 pad = GST_PAD (pads->data);
764 pads = g_list_next (pads);
768 name = gst_pad_get_name (pad);
769 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
770 g_print (" SRC: '%s'", name);
771 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
772 g_print (" SINK: '%s'", name);
774 g_print (" UNKNOWN!!!: '%s'", name);
780 n_print (" Implementation:\n");
782 n_print (" Has chainfunc(): %s\n",
783 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
784 if (pad->getrangefunc)
785 n_print (" Has getrangefunc(): %s\n",
786 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
787 if (pad->eventfunc != gst_pad_event_default)
788 n_print (" Has custom eventfunc(): %s\n",
789 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
790 if (pad->queryfunc != gst_pad_query_default)
791 n_print (" Has custom queryfunc(): %s\n",
792 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
794 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
795 n_print (" Has custom iterintlinkfunc(): %s\n",
796 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
798 if (pad->padtemplate)
799 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
801 caps = gst_pad_get_current_caps (pad);
803 n_print (" Capabilities:\n");
804 print_caps (caps, " ");
805 gst_caps_unref (caps);
811 has_sometimes_template (GstElement * element)
813 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
816 for (l = klass->padtemplates; l != NULL; l = l->next) {
817 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
825 print_signal_info (GstElement * element)
827 /* Signals/Actions Block */
831 GSignalQuery *query = NULL;
833 GSList *found_signals, *l;
835 for (k = 0; k < 2; k++) {
836 found_signals = NULL;
838 /* For elements that have sometimes pads, also list a few useful GstElement
839 * signals. Put these first, so element-specific ones come later. */
840 if (k == 0 && has_sometimes_template (element)) {
841 query = g_new0 (GSignalQuery, 1);
842 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
843 found_signals = g_slist_append (found_signals, query);
844 query = g_new0 (GSignalQuery, 1);
845 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
846 found_signals = g_slist_append (found_signals, query);
847 query = g_new0 (GSignalQuery, 1);
848 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
850 found_signals = g_slist_append (found_signals, query);
853 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
854 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
857 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
860 signals = g_signal_list_ids (type, &nsignals);
861 for (i = 0; i < nsignals; i++) {
862 query = g_new0 (GSignalQuery, 1);
863 g_signal_query (signals[i], query);
865 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
866 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
867 found_signals = g_slist_append (found_signals, query);
878 n_print ("Element Signals:\n");
880 n_print ("Element Actions:\n");
885 for (l = found_signals; l; l = l->next) {
889 query = (GSignalQuery *) l->data;
890 indent_len = strlen (query->signal_name) +
891 strlen (g_type_name (query->return_type)) + 24;
893 indent = g_new0 (gchar, indent_len + 1);
894 memset (indent, ' ', indent_len);
896 n_print (" \"%s\" : %s user_function (%s* object",
898 g_type_name (query->return_type), g_type_name (type));
900 for (j = 0; j < query->n_params; j++) {
902 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
903 n_print ("%s%s arg%d", indent,
904 g_type_name (query->param_types[j]), j);
905 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
906 n_print ("%s%s arg%d", indent,
907 g_type_name (query->param_types[j]), j);
909 n_print ("%s%s* arg%d", indent,
910 g_type_name (query->param_types[j]), j);
916 n_print ("%sgpointer user_data);\n", indent);
924 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
925 g_slist_free (found_signals);
931 print_children_info (GstElement * element)
935 if (!GST_IS_BIN (element))
938 children = (GList *) GST_BIN (element)->children;
941 n_print ("Children:\n");
945 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
946 children = g_list_next (children);
951 print_blacklist (void)
953 GList *plugins, *cur;
956 g_print ("%s\n", _("Blacklisted files:"));
958 plugins = gst_registry_get_plugin_list (gst_registry_get ());
959 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
960 GstPlugin *plugin = (GstPlugin *) (cur->data);
961 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
962 g_print (" %s\n", gst_plugin_get_name (plugin));
968 g_print (_("Total count: "));
969 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
972 gst_plugin_list_free (plugins);
976 print_element_list (gboolean print_all)
978 int plugincount = 0, featurecount = 0, blacklistcount = 0;
979 GList *plugins, *orig_plugins;
981 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
983 GList *features, *orig_features;
986 plugin = (GstPlugin *) (plugins->data);
987 plugins = g_list_next (plugins);
990 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
995 orig_features = features =
996 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
997 gst_plugin_get_name (plugin));
999 GstPluginFeature *feature;
1001 if (G_UNLIKELY (features->data == NULL))
1003 feature = GST_PLUGIN_FEATURE (features->data);
1006 if (GST_IS_ELEMENT_FACTORY (feature)) {
1007 GstElementFactory *factory;
1009 factory = GST_ELEMENT_FACTORY (feature);
1011 print_element_info (factory, TRUE);
1013 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1014 GST_OBJECT_NAME (factory),
1015 gst_element_factory_get_longname (factory));
1017 } else if (GST_IS_INDEX_FACTORY (feature)) {
1018 GstIndexFactory *factory;
1020 factory = GST_INDEX_FACTORY (feature);
1022 g_print ("%s: %s: %s\n", plugin->desc.name,
1023 GST_OBJECT_NAME (factory), factory->longdesc);
1025 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1026 GstTypeFindFactory *factory;
1027 const gchar *const *extensions;
1029 factory = GST_TYPE_FIND_FACTORY (feature);
1031 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1032 gst_plugin_feature_get_name (feature));
1034 extensions = gst_type_find_factory_get_extensions (factory);
1035 if (extensions != NULL) {
1038 while (extensions[i]) {
1040 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1047 g_print ("no extensions\n");
1051 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1052 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1056 features = g_list_next (features);
1059 gst_plugin_feature_list_free (orig_features);
1062 gst_plugin_list_free (orig_plugins);
1065 g_print (_("Total count: "));
1066 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1067 if (blacklistcount) {
1069 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1070 blacklistcount), blacklistcount);
1071 g_print (" not shown)");
1074 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1079 print_all_uri_handlers (void)
1081 GList *plugins, *p, *features, *f;
1083 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1085 for (p = plugins; p; p = p->next) {
1086 GstPlugin *plugin = (GstPlugin *) (p->data);
1089 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1090 gst_plugin_get_name (plugin));
1092 for (f = features; f; f = f->next) {
1093 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1095 if (GST_IS_ELEMENT_FACTORY (feature)) {
1096 GstElementFactory *factory;
1097 GstElement *element;
1099 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1101 g_print ("element plugin %s couldn't be loaded\n",
1102 gst_plugin_get_name (plugin));
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 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1158 const gchar *filename = gst_plugin_get_filename (plugin);
1160 n_print ("Plugin Details:\n");
1161 n_print (" Name:\t\t\t%s\n", gst_plugin_get_name (plugin));
1162 n_print (" Description:\t\t%s\n", gst_plugin_get_description (plugin));
1163 n_print (" Filename:\t\t%s\n", (filename != NULL) ? filename : "(null)");
1164 n_print (" Version:\t\t%s\n", gst_plugin_get_version (plugin));
1165 n_print (" License:\t\t%s\n", gst_plugin_get_license (plugin));
1166 n_print (" Source module:\t%s\n", gst_plugin_get_source (plugin));
1168 if (release_date != NULL) {
1169 const gchar *tz = "(UTC)";
1172 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1173 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1174 str = g_strdup (release_date);
1175 sep = strstr (str, "T");
1178 sep = strstr (sep + 1, "Z");
1184 n_print (" Source release date:\t%s%s\n", str, tz);
1187 n_print (" Binary package:\t%s\n", gst_plugin_get_package (plugin));
1188 n_print (" Origin URL:\t\t%s\n", gst_plugin_get_origin (plugin));
1193 print_plugin_features (GstPlugin * plugin)
1195 GList *features, *origlist;
1196 gint num_features = 0;
1197 gint num_elements = 0;
1198 gint num_typefinders = 0;
1199 gint num_indexes = 0;
1202 origlist = features =
1203 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1204 gst_plugin_get_name (plugin));
1207 GstPluginFeature *feature;
1209 feature = GST_PLUGIN_FEATURE (features->data);
1211 if (GST_IS_ELEMENT_FACTORY (feature)) {
1212 GstElementFactory *factory;
1214 factory = GST_ELEMENT_FACTORY (feature);
1215 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1216 gst_element_factory_get_longname (factory));
1219 } else if (GST_IS_INDEX_FACTORY (feature)) {
1220 GstIndexFactory *factory;
1222 factory = GST_INDEX_FACTORY (feature);
1223 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1226 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1227 GstTypeFindFactory *factory;
1228 const gchar *const *extensions;
1230 factory = GST_TYPE_FIND_FACTORY (feature);
1231 extensions = gst_type_find_factory_get_extensions (factory);
1235 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1236 gst_plugin_feature_get_name (feature));
1237 while (extensions[i]) {
1238 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1243 g_print ("%s: %s: no extensions\n", gst_plugin_get_name (plugin),
1244 gst_plugin_feature_get_name (feature));
1247 } else if (feature) {
1248 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1249 g_type_name (G_OBJECT_TYPE (feature)));
1253 features = g_list_next (features);
1256 gst_plugin_feature_list_free (origlist);
1259 n_print (" %d features:\n", num_features);
1260 if (num_elements > 0)
1261 n_print (" +-- %d elements\n", num_elements);
1262 if (num_typefinders > 0)
1263 n_print (" +-- %d typefinders\n", num_typefinders);
1264 if (num_indexes > 0)
1265 n_print (" +-- %d indexes\n", num_indexes);
1267 n_print (" +-- %d other objects\n", num_other);
1273 print_element_features (const gchar * element_name)
1275 GstPluginFeature *feature;
1277 /* FIXME implement other pretty print function for these */
1279 feature = gst_default_registry_find_feature (element_name,
1280 GST_TYPE_INDEX_FACTORY);
1282 n_print ("%s: an index\n", element_name);
1286 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1287 GST_TYPE_TYPE_FIND_FACTORY);
1289 n_print ("%s: a typefind function\n", element_name);
1297 print_element_info (GstElementFactory * factory, gboolean print_names)
1299 GstElement *element;
1303 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1307 g_print ("element plugin couldn't be loaded\n");
1311 element = gst_element_factory_create (factory, NULL);
1313 gst_object_unref (factory);
1314 g_print ("couldn't construct element for some reason\n");
1319 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1323 print_factory_details_info (factory);
1324 if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
1327 plugin = gst_registry_find_plugin (gst_registry_get (),
1328 GST_PLUGIN_FEATURE (factory)->plugin_name);
1330 print_plugin_info (plugin);
1334 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1335 print_interfaces (G_OBJECT_TYPE (element));
1337 print_pad_templates_info (element, factory);
1338 print_element_flag_info (element);
1339 print_implementation_info (element);
1340 print_clocking_info (element);
1341 print_index_info (element);
1342 print_uri_handler_info (element);
1343 print_pad_info (element);
1344 print_element_properties_info (element);
1345 print_signal_info (element);
1346 print_children_info (element);
1348 gst_object_unref (element);
1349 gst_object_unref (factory);
1357 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1359 GstPadDirection direction;
1360 const gchar *type_name;
1362 const GList *static_templates, *l;
1363 GstCaps *caps = NULL;
1366 klass = gst_element_factory_get_klass (factory);
1367 g_return_if_fail (klass != NULL);
1369 if (strstr (klass, "Demuxer") ||
1370 strstr (klass, "Decoder") ||
1371 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1372 type_name = "decoder";
1373 direction = GST_PAD_SINK;
1374 } else if (strstr (klass, "Muxer") ||
1375 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1376 type_name = "encoder";
1377 direction = GST_PAD_SRC;
1382 /* decoder/demuxer sink pads should always be static and there should only
1383 * be one, the same applies to encoders/muxers and source pads */
1384 static_templates = gst_element_factory_get_static_pad_templates (factory);
1385 for (l = static_templates; l != NULL; l = l->next) {
1386 GstStaticPadTemplate *tmpl = NULL;
1388 tmpl = (GstStaticPadTemplate *) l->data;
1389 if (tmpl->direction == direction) {
1390 caps = gst_static_pad_template_get_caps (tmpl);
1396 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1397 type_name, GST_OBJECT_NAME (factory));
1401 caps = gst_caps_make_writable (caps);
1402 num = gst_caps_get_size (caps);
1403 for (i = 0; i < num; ++i) {
1407 s = gst_caps_get_structure (caps, i);
1408 /* remove fields that are almost always just MIN-MAX of some sort
1409 * in order to make the caps look less messy */
1410 gst_structure_remove_field (s, "pixel-aspect-ratio");
1411 gst_structure_remove_field (s, "framerate");
1412 gst_structure_remove_field (s, "channels");
1413 gst_structure_remove_field (s, "width");
1414 gst_structure_remove_field (s, "height");
1415 gst_structure_remove_field (s, "rate");
1416 gst_structure_remove_field (s, "depth");
1417 gst_structure_remove_field (s, "clock-rate");
1418 s_str = gst_structure_to_string (s);
1419 g_print ("%s-%s\n", type_name, s_str);
1422 gst_caps_unref (caps);
1426 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1428 const gchar *const *protocols;
1430 protocols = gst_element_factory_get_uri_protocols (factory);
1431 if (protocols != NULL && *protocols != NULL) {
1432 switch (gst_element_factory_get_uri_type (factory)) {
1434 while (*protocols != NULL) {
1435 g_print ("urisink-%s\n", *protocols);
1440 while (*protocols != NULL) {
1441 g_print ("urisource-%s\n", *protocols);
1452 print_plugin_automatic_install_info (GstPlugin * plugin)
1454 const gchar *plugin_name;
1455 GList *features, *l;
1457 plugin_name = gst_plugin_get_name (plugin);
1459 /* not interested in typefind factories, only element factories */
1460 features = gst_registry_get_feature_list (gst_registry_get (),
1461 GST_TYPE_ELEMENT_FACTORY);
1463 for (l = features; l != NULL; l = l->next) {
1464 GstPluginFeature *feature;
1466 feature = GST_PLUGIN_FEATURE (l->data);
1468 /* only interested in the ones that are in the plugin we just loaded */
1469 if (g_str_equal (plugin_name, feature->plugin_name)) {
1470 GstElementFactory *factory;
1472 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1474 factory = GST_ELEMENT_FACTORY (feature);
1475 print_plugin_automatic_install_info_protocols (factory);
1476 print_plugin_automatic_install_info_codecs (factory);
1480 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1481 g_list_free (features);
1485 print_all_plugin_automatic_install_info (void)
1487 GList *plugins, *orig_plugins;
1489 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1493 plugin = (GstPlugin *) (plugins->data);
1494 plugins = g_list_next (plugins);
1496 print_plugin_automatic_install_info (plugin);
1498 gst_plugin_list_free (orig_plugins);
1502 main (int argc, char *argv[])
1504 gboolean print_all = FALSE;
1505 gboolean do_print_blacklist = FALSE;
1506 gboolean plugin_name = FALSE;
1507 gboolean print_aii = FALSE;
1508 gboolean uri_handlers = FALSE;
1509 #ifndef GST_DISABLE_OPTION_PARSING
1510 GOptionEntry options[] = {
1511 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1512 N_("Print all elements"), NULL},
1513 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1514 N_("Print list of blacklisted files"), NULL},
1515 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1516 N_("Print a machine-parsable list of features the specified plugin "
1517 "or all plugins provide.\n "
1518 "Useful in connection with external automatic plugin "
1519 "installation mechanisms"), NULL},
1520 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1521 N_("List the plugin contents"), NULL},
1522 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1524 ("Print supported URI schemes, with the elements that implement them"),
1526 GST_TOOLS_GOPTION_VERSION,
1529 GOptionContext *ctx;
1534 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1535 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1536 textdomain (GETTEXT_PACKAGE);
1539 gst_tools_set_prgname ("gst-inspect");
1541 #ifndef GST_DISABLE_OPTION_PARSING
1542 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1543 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1544 g_option_context_add_group (ctx, gst_init_get_option_group ());
1545 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1546 g_print ("Error initializing: %s\n", err->message);
1549 g_option_context_free (ctx);
1551 gst_init (&argc, &argv);
1554 gst_tools_print_version ("gst-inspect");
1556 if (print_all && argc > 1) {
1557 g_print ("-a requires no extra arguments\n");
1561 if (uri_handlers && argc > 1) {
1562 g_print ("-u requires no extra arguments\n");
1566 /* if no arguments, print out list of elements */
1568 print_all_uri_handlers ();
1569 } else if (argc == 1 || print_all) {
1570 if (do_print_blacklist)
1574 print_all_plugin_automatic_install_info ();
1576 print_element_list (print_all);
1579 /* else we try to get a factory */
1580 GstElementFactory *factory;
1582 const char *arg = argv[argc - 1];
1586 factory = gst_element_factory_find (arg);
1588 /* if there's a factory, print out the info */
1590 retval = print_element_info (factory, print_all);
1591 gst_object_unref (factory);
1593 retval = print_element_features (arg);
1599 /* otherwise check if it's a plugin */
1601 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1603 /* if there is such a plugin, print out info */
1606 print_plugin_automatic_install_info (plugin);
1608 print_plugin_info (plugin);
1609 print_plugin_features (plugin);
1612 GError *error = NULL;
1614 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1615 plugin = gst_plugin_load_file (arg, &error);
1619 print_plugin_automatic_install_info (plugin);
1621 print_plugin_info (plugin);
1622 print_plugin_features (plugin);
1625 g_print (_("Could not load plugin file: %s\n"), error->message);
1626 g_error_free (error);
1630 g_print (_("No such element or plugin '%s'\n"), arg);