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 /* FIXME: shouldn't have to access private API */
39 #include "gst/gst_private.h"
41 static char *_name = NULL;
43 static int print_element_info (GstElementFactory * factory,
44 gboolean print_names);
47 n_print (const char *format, ...)
52 g_print ("%s", _name);
54 va_start (args, format);
55 g_vprintf (format, args);
60 print_field (GQuark field, const GValue * value, gpointer pfx)
62 gchar *str = gst_value_serialize (value);
64 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
70 print_caps (const GstCaps * caps, const gchar * pfx)
74 g_return_if_fail (caps != NULL);
76 if (gst_caps_is_any (caps)) {
77 n_print ("%sANY\n", pfx);
80 if (gst_caps_is_empty (caps)) {
81 n_print ("%sEMPTY\n", pfx);
85 for (i = 0; i < gst_caps_get_size (caps); i++) {
86 GstStructure *structure = gst_caps_get_structure (caps, i);
88 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
89 gst_structure_foreach (structure, print_field, (gpointer) pfx);
95 print_formats (const GstFormat * formats)
97 while (formats && *formats) {
98 const GstFormatDefinition *definition;
100 definition = gst_format_get_details (*formats);
102 n_print ("\t\t(%d):\t%s (%s)\n", *formats,
103 definition->nick, definition->description);
105 n_print ("\t\t(%d):\tUnknown format\n", *formats);
112 print_event_masks (const GstEventMask * masks)
117 GFlagsClass *flags_class = NULL;
119 event_type = gst_event_type_get_type ();
120 klass = (GEnumClass *) g_type_class_ref (event_type);
122 while (masks && masks->type) {
124 gint flags = 0, index = 0;
126 switch (masks->type) {
128 flags = masks->flags;
129 event_flags = gst_seek_type_get_type ();
130 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
136 value = g_enum_get_value (klass, masks->type);
137 g_print ("\t\t%s ", value->value_nick);
143 value = g_flags_get_first_value (flags_class, 1 << index);
146 g_print ("| %s ", value->value_nick);
161 get_rank_name (char *s, gint rank)
163 static const int ranks[4] = {
164 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
166 static const char *rank_names[4] = { "none", "marginal", "secondary",
173 for (i = 0; i < 4; i++) {
174 if (rank == ranks[i])
175 return rank_names[i];
176 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
181 sprintf (s, "%s %c %d", rank_names[best_i],
182 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
188 print_factory_details_metadata (GQuark field_id, const GValue * value,
191 gchar *val = g_strdup_value_contents (value);
192 gchar *key = g_strdup (g_quark_to_string (field_id));
194 key[0] = g_ascii_toupper (key[0]);
195 n_print (" %s:\t\t%s\n", key, val);
202 print_factory_details_info (GstElementFactory * factory)
206 n_print ("Factory Details:\n");
207 n_print (" Rank:\t\t%s (%d)\n",
208 get_rank_name (s, GST_PLUGIN_FEATURE (factory)->rank),
209 GST_PLUGIN_FEATURE (factory)->rank);
210 gst_structure_foreach ((GstStructure *) factory->metadata,
211 print_factory_details_metadata, NULL);
216 print_hierarchy (GType type, gint level, gint * maxlevel)
221 parent = g_type_parent (type);
223 *maxlevel = *maxlevel + 1;
227 print_hierarchy (parent, level, maxlevel);
230 g_print ("%s", _name);
232 for (i = 1; i < *maxlevel - level; i++)
234 if (*maxlevel - level)
237 g_print ("%s\n", g_type_name (type));
244 print_interfaces (GType type)
247 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
252 g_print ("%s", _name);
253 g_print (_("Implemented Interfaces:\n"));
257 g_print ("%s", _name);
258 g_print (" %s\n", g_type_name (*iface));
262 g_print ("%s", _name);
270 flags_to_string (GFlagsValue * vals, guint flags)
275 /* first look for an exact match and count the number of values */
276 for (i = 0; vals[i].value_name != NULL; ++i) {
277 if (vals[i].value == flags)
278 return g_strdup (vals[i].value_nick);
281 s = g_string_new (NULL);
283 /* we assume the values are sorted from lowest to highest value */
287 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
289 g_string_append_c (s, '+');
290 g_string_append (s, vals[i].value_nick);
291 flags_left -= vals[i].value;
298 g_string_assign (s, "(none)");
300 return g_string_free (s, FALSE);
303 #define KNOWN_PARAM_FLAGS \
304 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
305 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
306 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
307 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
308 GST_PARAM_MUTABLE_READY)
311 print_element_properties_info (GstElement * element)
313 GParamSpec **property_specs;
314 guint num_properties, i;
318 property_specs = g_object_class_list_properties
319 (G_OBJECT_GET_CLASS (element), &num_properties);
321 n_print ("Element Properties:\n");
323 for (i = 0; i < num_properties; i++) {
324 GValue value = { 0, };
325 GParamSpec *param = property_specs[i];
329 g_value_init (&value, param->value_type);
331 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
332 g_param_spec_get_blurb (param));
335 n_print ("%-23.23s flags: ", "");
336 if (param->flags & G_PARAM_READABLE) {
337 g_object_get_property (G_OBJECT (element), param->name, &value);
339 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
342 /* if we can't read the property value, assume it's set to the default
343 * (which might not be entirely true for sub-classes, but that's an
344 * unlikely corner-case anyway) */
345 g_param_value_set_default (param, &value);
347 if (param->flags & G_PARAM_WRITABLE) {
348 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
351 if (param->flags & GST_PARAM_CONTROLLABLE) {
352 g_print (", %s", _("controllable"));
355 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
356 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
357 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
358 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
359 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
360 g_print (", %s", _("changeable only in NULL or READY state"));
362 if (param->flags & ~KNOWN_PARAM_FLAGS) {
363 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
364 param->flags & ~KNOWN_PARAM_FLAGS);
368 switch (G_VALUE_TYPE (&value)) {
371 const char *string_val = g_value_get_string (&value);
373 n_print ("%-23.23s String. ", "");
375 if (string_val == NULL)
376 g_print ("Default: null");
378 g_print ("Default: \"%s\"", string_val);
383 gboolean bool_val = g_value_get_boolean (&value);
385 n_print ("%-23.23s Boolean. ", "");
387 g_print ("Default: %s", bool_val ? "true" : "false");
392 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
394 n_print ("%-23.23s Unsigned Long. ", "");
395 g_print ("Range: %lu - %lu Default: %lu ",
396 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
398 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
399 "uint/uint64", GST_OBJECT_NAME (element),
400 g_param_spec_get_name (param));
405 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
407 n_print ("%-23.23s Long. ", "");
408 g_print ("Range: %ld - %ld Default: %ld ",
409 plong->minimum, plong->maximum, g_value_get_long (&value));
411 GST_ERROR ("%s: property '%s' of type long: consider changing to "
412 "int/int64", GST_OBJECT_NAME (element),
413 g_param_spec_get_name (param));
418 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
420 n_print ("%-23.23s Unsigned Integer. ", "");
421 g_print ("Range: %u - %u Default: %u ",
422 puint->minimum, puint->maximum, g_value_get_uint (&value));
427 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
429 n_print ("%-23.23s Integer. ", "");
430 g_print ("Range: %d - %d Default: %d ",
431 pint->minimum, pint->maximum, g_value_get_int (&value));
436 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
438 n_print ("%-23.23s Unsigned Integer64. ", "");
439 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
440 " Default: %" G_GUINT64_FORMAT " ",
441 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
446 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
448 n_print ("%-23.23s Integer64. ", "");
449 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
450 " Default: %" G_GINT64_FORMAT " ",
451 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
456 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
458 n_print ("%-23.23s Float. ", "");
459 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
460 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
465 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
467 n_print ("%-23.23s Double. ", "");
468 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
469 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
474 GST_ERROR ("%s: property '%s' of type char: consider changing to "
475 "int/string", GST_OBJECT_NAME (element),
476 g_param_spec_get_name (param));
479 if (param->value_type == GST_TYPE_CAPS) {
480 const GstCaps *caps = gst_value_get_caps (&value);
483 n_print ("%-23.23s Caps (NULL)", "");
485 print_caps (caps, " ");
487 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
491 const gchar *value_nick = "";
493 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
494 enum_value = g_value_get_enum (&value);
496 while (values[j].value_name) {
497 if (values[j].value == enum_value)
498 value_nick = values[j].value_nick;
502 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
503 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
506 while (values[j].value_name) {
509 g_print ("%s", _name);
510 g_print ("%-23.23s (%d): %-16s - %s", "",
511 values[j].value, values[j].value_nick, values[j].value_name);
514 /* g_type_class_unref (ec); */
515 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
516 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
520 vals = pflags->flags_class->values;
522 cur = flags_to_string (vals, g_value_get_flags (&value));
524 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
525 g_type_name (G_VALUE_TYPE (&value)),
526 g_value_get_flags (&value), cur);
528 while (vals[0].value_name) {
531 g_print ("%s", _name);
532 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
533 vals[0].value, vals[0].value_nick, vals[0].value_name);
538 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
539 n_print ("%-23.23s Object of type \"%s\"", "",
540 g_type_name (param->value_type));
541 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
542 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
543 g_type_name (param->value_type));
544 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
545 if (param->value_type != G_TYPE_POINTER) {
546 n_print ("%-23.23s Pointer of type \"%s\".", "",
547 g_type_name (param->value_type));
549 n_print ("%-23.23s Pointer.", "");
551 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
552 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
554 if (pvarray->element_spec) {
555 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
556 g_type_name (pvarray->element_spec->value_type));
558 n_print ("%-23.23s Array of GValues", "");
560 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
561 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
563 n_print ("%-23.23s Fraction. ", "");
565 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
566 pfraction->min_num, pfraction->min_den,
567 pfraction->max_num, pfraction->max_den,
568 gst_value_get_fraction_numerator (&value),
569 gst_value_get_fraction_denominator (&value));
571 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
572 g_type_name (param->value_type));
577 g_print (" Write only\n");
581 g_value_reset (&value);
583 if (num_properties == 0)
586 g_free (property_specs);
590 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
592 GstElementClass *gstelement_class;
594 GstStaticPadTemplate *padtemplate;
596 n_print ("Pad Templates:\n");
597 if (!factory->numpadtemplates) {
602 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
604 pads = factory->staticpadtemplates;
606 padtemplate = (GstStaticPadTemplate *) (pads->data);
607 pads = g_list_next (pads);
609 if (padtemplate->direction == GST_PAD_SRC)
610 n_print (" SRC template: '%s'\n", padtemplate->name_template);
611 else if (padtemplate->direction == GST_PAD_SINK)
612 n_print (" SINK template: '%s'\n", padtemplate->name_template);
614 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
616 if (padtemplate->presence == GST_PAD_ALWAYS)
617 n_print (" Availability: Always\n");
618 else if (padtemplate->presence == GST_PAD_SOMETIMES)
619 n_print (" Availability: Sometimes\n");
620 else if (padtemplate->presence == GST_PAD_REQUEST) {
621 n_print (" Availability: On request\n");
622 n_print (" Has request_new_pad() function: %s\n",
623 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
625 n_print (" Availability: UNKNOWN!!!\n");
627 if (padtemplate->static_caps.string) {
628 n_print (" Capabilities:\n");
629 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
637 print_element_flag_info (GstElement * element)
639 gboolean have_flags = FALSE;
642 n_print ("Element Flags:\n");
645 n_print (" no flags set\n");
647 if (GST_IS_BIN (element)) {
649 n_print ("Bin Flags:\n");
651 n_print (" no flags set\n");
656 print_implementation_info (GstElement * element)
658 GstElementClass *gstelement_class;
660 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
663 n_print ("Element Implementation:\n");
665 n_print (" Has change_state() function: %s\n",
666 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
670 print_clocking_info (GstElement * element)
672 gboolean requires_clock, provides_clock;
675 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
677 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
679 if (!requires_clock && !provides_clock) {
681 n_print ("Element has no clocking capabilities.");
686 n_print ("Clocking Interaction:\n");
687 if (requires_clock) {
688 n_print (" element requires a clock\n");
691 if (provides_clock) {
694 clock = gst_element_get_clock (element);
696 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
697 gst_object_unref (clock);
699 n_print (" element is supposed to provide a clock but returned NULL\n");
704 print_index_info (GstElement * element)
706 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
708 n_print ("Indexing capabilities:\n");
709 n_print (" element can do indexing\n");
712 n_print ("Element has no indexing capabilities.\n");
717 print_uri_handler_info (GstElement * element)
719 if (GST_IS_URI_HANDLER (element)) {
720 const gchar *const *uri_protocols;
721 const gchar *uri_type;
723 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
725 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
729 uri_type = "unknown";
731 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
734 n_print ("URI handling capabilities:\n");
735 n_print (" Element can act as %s.\n", uri_type);
737 if (uri_protocols && *uri_protocols) {
738 n_print (" Supported URI protocols:\n");
739 for (; *uri_protocols != NULL; uri_protocols++)
740 n_print (" %s\n", *uri_protocols);
742 n_print (" No supported URI protocols\n");
745 n_print ("Element has no URI handling capabilities.\n");
750 print_pad_info (GstElement * element)
758 if (!element->numpads) {
763 pads = element->pads;
768 pad = GST_PAD (pads->data);
769 pads = g_list_next (pads);
773 name = gst_pad_get_name (pad);
774 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
775 g_print (" SRC: '%s'", name);
776 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
777 g_print (" SINK: '%s'", name);
779 g_print (" UNKNOWN!!!: '%s'", name);
785 n_print (" Implementation:\n");
787 n_print (" Has chainfunc(): %s\n",
788 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
789 if (pad->getrangefunc)
790 n_print (" Has getrangefunc(): %s\n",
791 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
792 if (pad->eventfunc != gst_pad_event_default)
793 n_print (" Has custom eventfunc(): %s\n",
794 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
795 if (pad->queryfunc != gst_pad_query_default)
796 n_print (" Has custom queryfunc(): %s\n",
797 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
799 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
800 n_print (" Has custom iterintlinkfunc(): %s\n",
801 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
803 if (pad->padtemplate)
804 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
806 caps = gst_pad_get_current_caps (pad);
808 n_print (" Capabilities:\n");
809 print_caps (caps, " ");
810 gst_caps_unref (caps);
816 has_sometimes_template (GstElement * element)
818 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
821 for (l = klass->padtemplates; l != NULL; l = l->next) {
822 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
830 print_signal_info (GstElement * element)
832 /* Signals/Actions Block */
836 GSignalQuery *query = NULL;
838 GSList *found_signals, *l;
840 for (k = 0; k < 2; k++) {
841 found_signals = NULL;
843 /* For elements that have sometimes pads, also list a few useful GstElement
844 * signals. Put these first, so element-specific ones come later. */
845 if (k == 0 && has_sometimes_template (element)) {
846 query = g_new0 (GSignalQuery, 1);
847 g_signal_query (g_signal_lookup ("pad-added", 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 ("pad-removed", GST_TYPE_ELEMENT), query);
851 found_signals = g_slist_append (found_signals, query);
852 query = g_new0 (GSignalQuery, 1);
853 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
855 found_signals = g_slist_append (found_signals, query);
858 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
859 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
862 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
865 signals = g_signal_list_ids (type, &nsignals);
866 for (i = 0; i < nsignals; i++) {
867 query = g_new0 (GSignalQuery, 1);
868 g_signal_query (signals[i], query);
870 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
871 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
872 found_signals = g_slist_append (found_signals, query);
883 n_print ("Element Signals:\n");
885 n_print ("Element Actions:\n");
890 for (l = found_signals; l; l = l->next) {
894 query = (GSignalQuery *) l->data;
895 indent_len = strlen (query->signal_name) +
896 strlen (g_type_name (query->return_type)) + 24;
898 indent = g_new0 (gchar, indent_len + 1);
899 memset (indent, ' ', indent_len);
901 n_print (" \"%s\" : %s user_function (%s* object",
903 g_type_name (query->return_type), g_type_name (type));
905 for (j = 0; j < query->n_params; j++) {
907 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
908 n_print ("%s%s arg%d", indent,
909 g_type_name (query->param_types[j]), j);
910 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
911 n_print ("%s%s arg%d", indent,
912 g_type_name (query->param_types[j]), j);
914 n_print ("%s%s* arg%d", indent,
915 g_type_name (query->param_types[j]), j);
921 n_print ("%sgpointer user_data);\n", indent);
929 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
930 g_slist_free (found_signals);
936 print_children_info (GstElement * element)
940 if (!GST_IS_BIN (element))
943 children = (GList *) GST_BIN (element)->children;
946 n_print ("Children:\n");
950 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
951 children = g_list_next (children);
956 print_blacklist (void)
958 GList *plugins, *cur;
961 g_print ("%s\n", _("Blacklisted files:"));
963 plugins = gst_registry_get_plugin_list (gst_registry_get ());
964 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
965 GstPlugin *plugin = (GstPlugin *) (cur->data);
966 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
967 g_print (" %s\n", gst_plugin_get_name (plugin));
973 g_print (_("Total count: "));
974 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
977 gst_plugin_list_free (plugins);
981 print_element_list (gboolean print_all)
983 int plugincount = 0, featurecount = 0, blacklistcount = 0;
984 GList *plugins, *orig_plugins;
986 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
988 GList *features, *orig_features;
991 plugin = (GstPlugin *) (plugins->data);
992 plugins = g_list_next (plugins);
995 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
1000 orig_features = features =
1001 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1002 gst_plugin_get_name (plugin));
1004 GstPluginFeature *feature;
1006 if (G_UNLIKELY (features->data == NULL))
1008 feature = GST_PLUGIN_FEATURE (features->data);
1011 if (GST_IS_ELEMENT_FACTORY (feature)) {
1012 GstElementFactory *factory;
1014 factory = GST_ELEMENT_FACTORY (feature);
1016 print_element_info (factory, TRUE);
1018 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1019 GST_OBJECT_NAME (factory),
1020 gst_element_factory_get_longname (factory));
1022 } else if (GST_IS_INDEX_FACTORY (feature)) {
1023 GstIndexFactory *factory;
1025 factory = GST_INDEX_FACTORY (feature);
1027 g_print ("%s: %s: %s\n", plugin->desc.name,
1028 GST_OBJECT_NAME (factory), factory->longdesc);
1030 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1031 GstTypeFindFactory *factory;
1033 factory = GST_TYPE_FIND_FACTORY (feature);
1035 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1036 gst_plugin_feature_get_name (feature));
1037 if (factory->extensions) {
1040 while (factory->extensions[i]) {
1042 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1049 g_print ("no extensions\n");
1053 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1054 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1058 features = g_list_next (features);
1061 gst_plugin_feature_list_free (orig_features);
1064 gst_plugin_list_free (orig_plugins);
1067 g_print (_("Total count: "));
1068 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1069 if (blacklistcount) {
1071 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1072 blacklistcount), blacklistcount);
1073 g_print (" not shown)");
1076 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1081 print_all_uri_handlers (void)
1083 GList *plugins, *p, *features, *f;
1085 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1087 for (p = plugins; p; p = p->next) {
1088 GstPlugin *plugin = (GstPlugin *) (p->data);
1091 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1092 gst_plugin_get_name (plugin));
1094 for (f = features; f; f = f->next) {
1095 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1097 if (GST_IS_ELEMENT_FACTORY (feature)) {
1098 GstElementFactory *factory;
1099 GstElement *element;
1101 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1103 g_print ("element plugin %s couldn't be loaded\n",
1104 gst_plugin_get_name (plugin));
1108 element = gst_element_factory_create (factory, NULL);
1110 g_print ("couldn't construct element for %s for some reason\n",
1111 GST_OBJECT_NAME (factory));
1112 gst_object_unref (factory);
1116 if (GST_IS_URI_HANDLER (element)) {
1117 const gchar *const *uri_protocols;
1121 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1134 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1135 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1137 g_print ("%s (%s, rank %u): %s\n",
1138 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1139 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1145 gst_object_unref (element);
1146 gst_object_unref (factory);
1150 gst_plugin_feature_list_free (features);
1153 gst_plugin_list_free (plugins);
1157 print_plugin_info (GstPlugin * plugin)
1159 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1160 const gchar *filename = gst_plugin_get_filename (plugin);
1162 n_print ("Plugin Details:\n");
1163 n_print (" Name:\t\t\t%s\n", gst_plugin_get_name (plugin));
1164 n_print (" Description:\t\t%s\n", gst_plugin_get_description (plugin));
1165 n_print (" Filename:\t\t%s\n", (filename != NULL) ? filename : "(null)");
1166 n_print (" Version:\t\t%s\n", gst_plugin_get_version (plugin));
1167 n_print (" License:\t\t%s\n", gst_plugin_get_license (plugin));
1168 n_print (" Source module:\t%s\n", gst_plugin_get_source (plugin));
1170 if (release_date != NULL) {
1171 const gchar *tz = "(UTC)";
1174 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1175 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1176 str = g_strdup (release_date);
1177 sep = strstr (str, "T");
1180 sep = strstr (sep + 1, "Z");
1186 n_print (" Source release date:\t%s%s\n", str, tz);
1189 n_print (" Binary package:\t%s\n", gst_plugin_get_package (plugin));
1190 n_print (" Origin URL:\t\t%s\n", gst_plugin_get_origin (plugin));
1195 print_plugin_features (GstPlugin * plugin)
1197 GList *features, *origlist;
1198 gint num_features = 0;
1199 gint num_elements = 0;
1200 gint num_typefinders = 0;
1201 gint num_indexes = 0;
1204 origlist = features =
1205 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1206 gst_plugin_get_name (plugin));
1209 GstPluginFeature *feature;
1211 feature = GST_PLUGIN_FEATURE (features->data);
1213 if (GST_IS_ELEMENT_FACTORY (feature)) {
1214 GstElementFactory *factory;
1216 factory = GST_ELEMENT_FACTORY (feature);
1217 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1218 gst_element_factory_get_longname (factory));
1221 } else if (GST_IS_INDEX_FACTORY (feature)) {
1222 GstIndexFactory *factory;
1224 factory = GST_INDEX_FACTORY (feature);
1225 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1228 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1229 GstTypeFindFactory *factory;
1231 factory = GST_TYPE_FIND_FACTORY (feature);
1232 if (factory->extensions) {
1235 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1236 gst_plugin_feature_get_name (feature));
1237 while (factory->extensions[i]) {
1238 g_print ("%s%s", i > 0 ? ", " : "", factory->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);