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.
32 #include <glib/gprintf.h>
34 static char *_name = NULL;
36 static int print_element_info (GstElementFactory * factory,
37 gboolean print_names);
40 n_print (const char *format, ...)
45 g_print ("%s", _name);
47 va_start (args, format);
48 g_vprintf (format, args);
53 print_field (GQuark field, const GValue * value, gpointer pfx)
55 gchar *str = gst_value_serialize (value);
57 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
63 print_caps (const GstCaps * caps, const gchar * pfx)
67 g_return_if_fail (caps != NULL);
69 if (gst_caps_is_any (caps)) {
70 n_print ("%sANY\n", pfx);
73 if (gst_caps_is_empty (caps)) {
74 n_print ("%sEMPTY\n", pfx);
78 for (i = 0; i < gst_caps_get_size (caps); i++) {
79 GstStructure *structure = gst_caps_get_structure (caps, i);
81 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
82 gst_structure_foreach (structure, print_field, (gpointer) pfx);
88 print_formats (const GstFormat * formats)
90 while (formats && *formats) {
91 const GstFormatDefinition *definition;
93 definition = gst_format_get_details (*formats);
95 n_print ("\t\t(%d):\t%s (%s)\n", *formats,
96 definition->nick, definition->description);
98 n_print ("\t\t(%d):\tUnknown format\n", *formats);
105 print_event_masks (const GstEventMask * masks)
110 GFlagsClass *flags_class = NULL;
112 event_type = gst_event_type_get_type ();
113 klass = (GEnumClass *) g_type_class_ref (event_type);
115 while (masks && masks->type) {
117 gint flags = 0, index = 0;
119 switch (masks->type) {
121 flags = masks->flags;
122 event_flags = gst_seek_type_get_type ();
123 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
129 value = g_enum_get_value (klass, masks->type);
130 g_print ("\t\t%s ", value->value_nick);
136 value = g_flags_get_first_value (flags_class, 1 << index);
139 g_print ("| %s ", value->value_nick);
154 get_rank_name (char *s, gint rank)
156 static const int ranks[4] = {
157 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
159 static const char *rank_names[4] = { "none", "marginal", "secondary",
166 for (i = 0; i < 4; i++) {
167 if (rank == ranks[i])
168 return rank_names[i];
169 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
174 sprintf (s, "%s %c %d", rank_names[best_i],
175 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
181 print_factory_details_info (GstElementFactory * factory)
187 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
188 n_print ("Factory Details:\n");
189 n_print (" Rank:\t\t%s (%d)\n", get_rank_name (s, rank), rank);
191 keys = gst_element_factory_get_metadata_keys (factory);
193 for (k = keys; *k != NULL; ++k) {
197 val = gst_element_factory_get_metadata (factory, key);
198 key[0] = g_ascii_toupper (key[0]);
199 n_print (" %s:\t\t%s\n", key, val);
207 print_hierarchy (GType type, gint level, gint * maxlevel)
212 parent = g_type_parent (type);
214 *maxlevel = *maxlevel + 1;
218 print_hierarchy (parent, level, maxlevel);
221 g_print ("%s", _name);
223 for (i = 1; i < *maxlevel - level; i++)
225 if (*maxlevel - level)
228 g_print ("%s\n", g_type_name (type));
235 print_interfaces (GType type)
238 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
243 g_print ("%s", _name);
244 g_print (_("Implemented Interfaces:\n"));
248 g_print ("%s", _name);
249 g_print (" %s\n", g_type_name (*iface));
253 g_print ("%s", _name);
261 flags_to_string (GFlagsValue * vals, guint flags)
266 /* first look for an exact match and count the number of values */
267 for (i = 0; vals[i].value_name != NULL; ++i) {
268 if (vals[i].value == flags)
269 return g_strdup (vals[i].value_nick);
272 s = g_string_new (NULL);
274 /* we assume the values are sorted from lowest to highest value */
278 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
280 g_string_append_c (s, '+');
281 g_string_append (s, vals[i].value_nick);
282 flags_left -= vals[i].value;
289 g_string_assign (s, "(none)");
291 return g_string_free (s, FALSE);
294 #define KNOWN_PARAM_FLAGS \
295 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
296 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
297 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
298 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
299 GST_PARAM_MUTABLE_READY)
302 print_element_properties_info (GstElement * element)
304 GParamSpec **property_specs;
305 guint num_properties, i;
309 property_specs = g_object_class_list_properties
310 (G_OBJECT_GET_CLASS (element), &num_properties);
312 n_print ("Element Properties:\n");
314 for (i = 0; i < num_properties; i++) {
315 GValue value = { 0, };
316 GParamSpec *param = property_specs[i];
320 g_value_init (&value, param->value_type);
322 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
323 g_param_spec_get_blurb (param));
326 n_print ("%-23.23s flags: ", "");
327 if (param->flags & G_PARAM_READABLE) {
328 g_object_get_property (G_OBJECT (element), param->name, &value);
330 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
333 /* if we can't read the property value, assume it's set to the default
334 * (which might not be entirely true for sub-classes, but that's an
335 * unlikely corner-case anyway) */
336 g_param_value_set_default (param, &value);
338 if (param->flags & G_PARAM_WRITABLE) {
339 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
342 if (param->flags & GST_PARAM_CONTROLLABLE) {
343 g_print (", %s", _("controllable"));
346 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
347 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
348 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
349 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
350 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
351 g_print (", %s", _("changeable only in NULL or READY state"));
353 if (param->flags & ~KNOWN_PARAM_FLAGS) {
354 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
355 param->flags & ~KNOWN_PARAM_FLAGS);
359 switch (G_VALUE_TYPE (&value)) {
362 const char *string_val = g_value_get_string (&value);
364 n_print ("%-23.23s String. ", "");
366 if (string_val == NULL)
367 g_print ("Default: null");
369 g_print ("Default: \"%s\"", string_val);
374 gboolean bool_val = g_value_get_boolean (&value);
376 n_print ("%-23.23s Boolean. ", "");
378 g_print ("Default: %s", bool_val ? "true" : "false");
383 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
385 n_print ("%-23.23s Unsigned Long. ", "");
386 g_print ("Range: %lu - %lu Default: %lu ",
387 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
389 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
390 "uint/uint64", GST_OBJECT_NAME (element),
391 g_param_spec_get_name (param));
396 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
398 n_print ("%-23.23s Long. ", "");
399 g_print ("Range: %ld - %ld Default: %ld ",
400 plong->minimum, plong->maximum, g_value_get_long (&value));
402 GST_ERROR ("%s: property '%s' of type long: consider changing to "
403 "int/int64", GST_OBJECT_NAME (element),
404 g_param_spec_get_name (param));
409 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
411 n_print ("%-23.23s Unsigned Integer. ", "");
412 g_print ("Range: %u - %u Default: %u ",
413 puint->minimum, puint->maximum, g_value_get_uint (&value));
418 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
420 n_print ("%-23.23s Integer. ", "");
421 g_print ("Range: %d - %d Default: %d ",
422 pint->minimum, pint->maximum, g_value_get_int (&value));
427 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
429 n_print ("%-23.23s Unsigned Integer64. ", "");
430 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
431 " Default: %" G_GUINT64_FORMAT " ",
432 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
437 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
439 n_print ("%-23.23s Integer64. ", "");
440 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
441 " Default: %" G_GINT64_FORMAT " ",
442 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
447 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
449 n_print ("%-23.23s Float. ", "");
450 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
451 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
456 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
458 n_print ("%-23.23s Double. ", "");
459 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
460 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
465 GST_ERROR ("%s: property '%s' of type char: consider changing to "
466 "int/string", GST_OBJECT_NAME (element),
467 g_param_spec_get_name (param));
470 if (param->value_type == GST_TYPE_CAPS) {
471 const GstCaps *caps = gst_value_get_caps (&value);
474 n_print ("%-23.23s Caps (NULL)", "");
476 print_caps (caps, " ");
478 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
482 const gchar *value_nick = "";
484 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
485 enum_value = g_value_get_enum (&value);
487 while (values[j].value_name) {
488 if (values[j].value == enum_value)
489 value_nick = values[j].value_nick;
493 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
494 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
497 while (values[j].value_name) {
500 g_print ("%s", _name);
501 g_print ("%-23.23s (%d): %-16s - %s", "",
502 values[j].value, values[j].value_nick, values[j].value_name);
505 /* g_type_class_unref (ec); */
506 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
507 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
511 vals = pflags->flags_class->values;
513 cur = flags_to_string (vals, g_value_get_flags (&value));
515 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
516 g_type_name (G_VALUE_TYPE (&value)),
517 g_value_get_flags (&value), cur);
519 while (vals[0].value_name) {
522 g_print ("%s", _name);
523 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
524 vals[0].value, vals[0].value_nick, vals[0].value_name);
529 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
530 n_print ("%-23.23s Object of type \"%s\"", "",
531 g_type_name (param->value_type));
532 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
533 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
534 g_type_name (param->value_type));
535 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
536 if (param->value_type != G_TYPE_POINTER) {
537 n_print ("%-23.23s Pointer of type \"%s\".", "",
538 g_type_name (param->value_type));
540 n_print ("%-23.23s Pointer.", "");
542 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
543 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
545 if (pvarray->element_spec) {
546 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
547 g_type_name (pvarray->element_spec->value_type));
549 n_print ("%-23.23s Array of GValues", "");
551 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
552 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
554 n_print ("%-23.23s Fraction. ", "");
556 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
557 pfraction->min_num, pfraction->min_den,
558 pfraction->max_num, pfraction->max_den,
559 gst_value_get_fraction_numerator (&value),
560 gst_value_get_fraction_denominator (&value));
562 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
563 g_type_name (param->value_type));
568 g_print (" Write only\n");
572 g_value_reset (&value);
574 if (num_properties == 0)
577 g_free (property_specs);
581 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
583 GstElementClass *gstelement_class;
585 GstStaticPadTemplate *padtemplate;
587 n_print ("Pad Templates:\n");
588 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
593 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
595 pads = gst_element_factory_get_static_pad_templates (factory);
597 padtemplate = (GstStaticPadTemplate *) (pads->data);
598 pads = g_list_next (pads);
600 if (padtemplate->direction == GST_PAD_SRC)
601 n_print (" SRC template: '%s'\n", padtemplate->name_template);
602 else if (padtemplate->direction == GST_PAD_SINK)
603 n_print (" SINK template: '%s'\n", padtemplate->name_template);
605 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
607 if (padtemplate->presence == GST_PAD_ALWAYS)
608 n_print (" Availability: Always\n");
609 else if (padtemplate->presence == GST_PAD_SOMETIMES)
610 n_print (" Availability: Sometimes\n");
611 else if (padtemplate->presence == GST_PAD_REQUEST) {
612 n_print (" Availability: On request\n");
613 n_print (" Has request_new_pad() function: %s\n",
614 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
616 n_print (" Availability: UNKNOWN!!!\n");
618 if (padtemplate->static_caps.string) {
619 n_print (" Capabilities:\n");
620 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
628 print_element_flag_info (GstElement * element)
630 gboolean have_flags = FALSE;
633 n_print ("Element Flags:\n");
636 n_print (" no flags set\n");
638 if (GST_IS_BIN (element)) {
640 n_print ("Bin Flags:\n");
642 n_print (" no flags set\n");
647 print_implementation_info (GstElement * element)
649 GstElementClass *gstelement_class;
651 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
654 n_print ("Element Implementation:\n");
656 n_print (" Has change_state() function: %s\n",
657 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
661 print_clocking_info (GstElement * element)
663 gboolean requires_clock, provides_clock;
666 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
668 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
670 if (!requires_clock && !provides_clock) {
672 n_print ("Element has no clocking capabilities.");
677 n_print ("Clocking Interaction:\n");
678 if (requires_clock) {
679 n_print (" element requires a clock\n");
682 if (provides_clock) {
685 clock = gst_element_get_clock (element);
687 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
688 gst_object_unref (clock);
690 n_print (" element is supposed to provide a clock but returned NULL\n");
695 print_index_info (GstElement * element)
697 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
699 n_print ("Indexing capabilities:\n");
700 n_print (" element can do indexing\n");
703 n_print ("Element has no indexing capabilities.\n");
708 print_uri_handler_info (GstElement * element)
710 if (GST_IS_URI_HANDLER (element)) {
711 const gchar *const *uri_protocols;
712 const gchar *uri_type;
714 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
716 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
720 uri_type = "unknown";
722 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
725 n_print ("URI handling capabilities:\n");
726 n_print (" Element can act as %s.\n", uri_type);
728 if (uri_protocols && *uri_protocols) {
729 n_print (" Supported URI protocols:\n");
730 for (; *uri_protocols != NULL; uri_protocols++)
731 n_print (" %s\n", *uri_protocols);
733 n_print (" No supported URI protocols\n");
736 n_print ("Element has no URI handling capabilities.\n");
741 print_pad_info (GstElement * element)
749 if (!element->numpads) {
754 pads = element->pads;
759 pad = GST_PAD (pads->data);
760 pads = g_list_next (pads);
764 name = gst_pad_get_name (pad);
765 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
766 g_print (" SRC: '%s'", name);
767 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
768 g_print (" SINK: '%s'", name);
770 g_print (" UNKNOWN!!!: '%s'", name);
776 n_print (" Implementation:\n");
778 n_print (" Has chainfunc(): %s\n",
779 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
780 if (pad->getrangefunc)
781 n_print (" Has getrangefunc(): %s\n",
782 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
783 if (pad->eventfunc != gst_pad_event_default)
784 n_print (" Has custom eventfunc(): %s\n",
785 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
786 if (pad->queryfunc != gst_pad_query_default)
787 n_print (" Has custom queryfunc(): %s\n",
788 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
790 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
791 n_print (" Has custom iterintlinkfunc(): %s\n",
792 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
794 if (pad->padtemplate)
795 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
797 caps = gst_pad_get_current_caps (pad);
799 n_print (" Capabilities:\n");
800 print_caps (caps, " ");
801 gst_caps_unref (caps);
807 has_sometimes_template (GstElement * element)
809 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
812 for (l = klass->padtemplates; l != NULL; l = l->next) {
813 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
821 print_signal_info (GstElement * element)
823 /* Signals/Actions Block */
827 GSignalQuery *query = NULL;
829 GSList *found_signals, *l;
831 for (k = 0; k < 2; k++) {
832 found_signals = NULL;
834 /* For elements that have sometimes pads, also list a few useful GstElement
835 * signals. Put these first, so element-specific ones come later. */
836 if (k == 0 && has_sometimes_template (element)) {
837 query = g_new0 (GSignalQuery, 1);
838 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
839 found_signals = g_slist_append (found_signals, query);
840 query = g_new0 (GSignalQuery, 1);
841 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
842 found_signals = g_slist_append (found_signals, query);
843 query = g_new0 (GSignalQuery, 1);
844 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
846 found_signals = g_slist_append (found_signals, query);
849 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
850 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
853 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
856 signals = g_signal_list_ids (type, &nsignals);
857 for (i = 0; i < nsignals; i++) {
858 query = g_new0 (GSignalQuery, 1);
859 g_signal_query (signals[i], query);
861 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
862 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
863 found_signals = g_slist_append (found_signals, query);
874 n_print ("Element Signals:\n");
876 n_print ("Element Actions:\n");
881 for (l = found_signals; l; l = l->next) {
885 query = (GSignalQuery *) l->data;
886 indent_len = strlen (query->signal_name) +
887 strlen (g_type_name (query->return_type)) + 24;
889 indent = g_new0 (gchar, indent_len + 1);
890 memset (indent, ' ', indent_len);
892 n_print (" \"%s\" : %s user_function (%s* object",
894 g_type_name (query->return_type), g_type_name (type));
896 for (j = 0; j < query->n_params; j++) {
898 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
899 n_print ("%s%s arg%d", indent,
900 g_type_name (query->param_types[j]), j);
901 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
902 n_print ("%s%s arg%d", indent,
903 g_type_name (query->param_types[j]), j);
905 n_print ("%s%s* arg%d", indent,
906 g_type_name (query->param_types[j]), j);
912 n_print ("%sgpointer user_data);\n", indent);
920 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
921 g_slist_free (found_signals);
927 print_children_info (GstElement * element)
931 if (!GST_IS_BIN (element))
934 children = (GList *) GST_BIN (element)->children;
937 n_print ("Children:\n");
941 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
942 children = g_list_next (children);
947 print_blacklist (void)
949 GList *plugins, *cur;
952 g_print ("%s\n", _("Blacklisted files:"));
954 plugins = gst_registry_get_plugin_list (gst_registry_get ());
955 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
956 GstPlugin *plugin = (GstPlugin *) (cur->data);
957 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
958 g_print (" %s\n", gst_plugin_get_name (plugin));
964 g_print (_("Total count: "));
965 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
968 gst_plugin_list_free (plugins);
972 print_element_list (gboolean print_all)
974 int plugincount = 0, featurecount = 0, blacklistcount = 0;
975 GList *plugins, *orig_plugins;
977 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
979 GList *features, *orig_features;
982 plugin = (GstPlugin *) (plugins->data);
983 plugins = g_list_next (plugins);
986 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
991 orig_features = features =
992 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
993 gst_plugin_get_name (plugin));
995 GstPluginFeature *feature;
997 if (G_UNLIKELY (features->data == NULL))
999 feature = GST_PLUGIN_FEATURE (features->data);
1002 if (GST_IS_ELEMENT_FACTORY (feature)) {
1003 GstElementFactory *factory;
1005 factory = GST_ELEMENT_FACTORY (feature);
1007 print_element_info (factory, TRUE);
1009 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1010 GST_OBJECT_NAME (factory),
1011 gst_element_factory_get_longname (factory));
1013 } else if (GST_IS_INDEX_FACTORY (feature)) {
1014 GstIndexFactory *factory;
1016 factory = GST_INDEX_FACTORY (feature);
1018 g_print ("%s: %s: %s\n", plugin->desc.name,
1019 GST_OBJECT_NAME (factory), factory->longdesc);
1021 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1022 GstTypeFindFactory *factory;
1023 const gchar *const *extensions;
1025 factory = GST_TYPE_FIND_FACTORY (feature);
1027 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1028 gst_plugin_feature_get_name (feature));
1030 extensions = gst_type_find_factory_get_extensions (factory);
1031 if (extensions != NULL) {
1034 while (extensions[i]) {
1036 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1043 g_print ("no extensions\n");
1047 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1048 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1052 features = g_list_next (features);
1055 gst_plugin_feature_list_free (orig_features);
1058 gst_plugin_list_free (orig_plugins);
1061 g_print (_("Total count: "));
1062 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1063 if (blacklistcount) {
1065 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1066 blacklistcount), blacklistcount);
1067 g_print (" not shown)");
1070 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1075 print_all_uri_handlers (void)
1077 GList *plugins, *p, *features, *f;
1079 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1081 for (p = plugins; p; p = p->next) {
1082 GstPlugin *plugin = (GstPlugin *) (p->data);
1085 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1086 gst_plugin_get_name (plugin));
1088 for (f = features; f; f = f->next) {
1089 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1091 if (GST_IS_ELEMENT_FACTORY (feature)) {
1092 GstElementFactory *factory;
1093 GstElement *element;
1095 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1097 g_print ("element plugin %s couldn't be loaded\n",
1098 gst_plugin_get_name (plugin));
1102 element = gst_element_factory_create (factory, NULL);
1104 g_print ("couldn't construct element for %s for some reason\n",
1105 GST_OBJECT_NAME (factory));
1106 gst_object_unref (factory);
1110 if (GST_IS_URI_HANDLER (element)) {
1111 const gchar *const *uri_protocols;
1115 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1128 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1129 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1131 g_print ("%s (%s, rank %u): %s\n",
1132 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1133 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1139 gst_object_unref (element);
1140 gst_object_unref (factory);
1144 gst_plugin_feature_list_free (features);
1147 gst_plugin_list_free (plugins);
1151 print_plugin_info (GstPlugin * plugin)
1153 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1154 const gchar *filename = gst_plugin_get_filename (plugin);
1156 n_print ("Plugin Details:\n");
1157 n_print (" Name:\t\t\t%s\n", gst_plugin_get_name (plugin));
1158 n_print (" Description:\t\t%s\n", gst_plugin_get_description (plugin));
1159 n_print (" Filename:\t\t%s\n", (filename != NULL) ? filename : "(null)");
1160 n_print (" Version:\t\t%s\n", gst_plugin_get_version (plugin));
1161 n_print (" License:\t\t%s\n", gst_plugin_get_license (plugin));
1162 n_print (" Source module:\t%s\n", gst_plugin_get_source (plugin));
1164 if (release_date != NULL) {
1165 const gchar *tz = "(UTC)";
1168 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1169 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1170 str = g_strdup (release_date);
1171 sep = strstr (str, "T");
1174 sep = strstr (sep + 1, "Z");
1180 n_print (" Source release date:\t%s%s\n", str, tz);
1183 n_print (" Binary package:\t%s\n", gst_plugin_get_package (plugin));
1184 n_print (" Origin URL:\t\t%s\n", gst_plugin_get_origin (plugin));
1189 print_plugin_features (GstPlugin * plugin)
1191 GList *features, *origlist;
1192 gint num_features = 0;
1193 gint num_elements = 0;
1194 gint num_typefinders = 0;
1195 gint num_indexes = 0;
1198 origlist = features =
1199 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1200 gst_plugin_get_name (plugin));
1203 GstPluginFeature *feature;
1205 feature = GST_PLUGIN_FEATURE (features->data);
1207 if (GST_IS_ELEMENT_FACTORY (feature)) {
1208 GstElementFactory *factory;
1210 factory = GST_ELEMENT_FACTORY (feature);
1211 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1212 gst_element_factory_get_longname (factory));
1215 } else if (GST_IS_INDEX_FACTORY (feature)) {
1216 GstIndexFactory *factory;
1218 factory = GST_INDEX_FACTORY (feature);
1219 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1222 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1223 GstTypeFindFactory *factory;
1224 const gchar *const *extensions;
1226 factory = GST_TYPE_FIND_FACTORY (feature);
1227 extensions = gst_type_find_factory_get_extensions (factory);
1231 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1232 gst_plugin_feature_get_name (feature));
1233 while (extensions[i]) {
1234 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1239 g_print ("%s: %s: no extensions\n", gst_plugin_get_name (plugin),
1240 gst_plugin_feature_get_name (feature));
1243 } else if (feature) {
1244 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1245 g_type_name (G_OBJECT_TYPE (feature)));
1249 features = g_list_next (features);
1252 gst_plugin_feature_list_free (origlist);
1255 n_print (" %d features:\n", num_features);
1256 if (num_elements > 0)
1257 n_print (" +-- %d elements\n", num_elements);
1258 if (num_typefinders > 0)
1259 n_print (" +-- %d typefinders\n", num_typefinders);
1260 if (num_indexes > 0)
1261 n_print (" +-- %d indexes\n", num_indexes);
1263 n_print (" +-- %d other objects\n", num_other);
1269 print_element_features (const gchar * element_name)
1271 GstPluginFeature *feature;
1273 /* FIXME implement other pretty print function for these */
1275 feature = gst_default_registry_find_feature (element_name,
1276 GST_TYPE_INDEX_FACTORY);
1278 n_print ("%s: an index\n", element_name);
1282 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1283 GST_TYPE_TYPE_FIND_FACTORY);
1285 n_print ("%s: a typefind function\n", element_name);
1293 print_element_info (GstElementFactory * factory, gboolean print_names)
1295 GstElement *element;
1300 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1304 g_print ("element plugin couldn't be loaded\n");
1308 element = gst_element_factory_create (factory, NULL);
1310 gst_object_unref (factory);
1311 g_print ("couldn't construct element for some reason\n");
1316 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1320 print_factory_details_info (factory);
1322 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1324 print_plugin_info (plugin);
1325 gst_object_unref (plugin);
1328 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1329 print_interfaces (G_OBJECT_TYPE (element));
1331 print_pad_templates_info (element, factory);
1332 print_element_flag_info (element);
1333 print_implementation_info (element);
1334 print_clocking_info (element);
1335 print_index_info (element);
1336 print_uri_handler_info (element);
1337 print_pad_info (element);
1338 print_element_properties_info (element);
1339 print_signal_info (element);
1340 print_children_info (element);
1342 gst_object_unref (element);
1343 gst_object_unref (factory);
1351 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1353 GstPadDirection direction;
1354 const gchar *type_name;
1356 const GList *static_templates, *l;
1357 GstCaps *caps = NULL;
1360 klass = gst_element_factory_get_klass (factory);
1361 g_return_if_fail (klass != NULL);
1363 if (strstr (klass, "Demuxer") ||
1364 strstr (klass, "Decoder") ||
1365 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1366 type_name = "decoder";
1367 direction = GST_PAD_SINK;
1368 } else if (strstr (klass, "Muxer") ||
1369 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1370 type_name = "encoder";
1371 direction = GST_PAD_SRC;
1376 /* decoder/demuxer sink pads should always be static and there should only
1377 * be one, the same applies to encoders/muxers and source pads */
1378 static_templates = gst_element_factory_get_static_pad_templates (factory);
1379 for (l = static_templates; l != NULL; l = l->next) {
1380 GstStaticPadTemplate *tmpl = NULL;
1382 tmpl = (GstStaticPadTemplate *) l->data;
1383 if (tmpl->direction == direction) {
1384 caps = gst_static_pad_template_get_caps (tmpl);
1390 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1391 type_name, GST_OBJECT_NAME (factory));
1395 caps = gst_caps_make_writable (caps);
1396 num = gst_caps_get_size (caps);
1397 for (i = 0; i < num; ++i) {
1401 s = gst_caps_get_structure (caps, i);
1402 /* remove fields that are almost always just MIN-MAX of some sort
1403 * in order to make the caps look less messy */
1404 gst_structure_remove_field (s, "pixel-aspect-ratio");
1405 gst_structure_remove_field (s, "framerate");
1406 gst_structure_remove_field (s, "channels");
1407 gst_structure_remove_field (s, "width");
1408 gst_structure_remove_field (s, "height");
1409 gst_structure_remove_field (s, "rate");
1410 gst_structure_remove_field (s, "depth");
1411 gst_structure_remove_field (s, "clock-rate");
1412 s_str = gst_structure_to_string (s);
1413 g_print ("%s-%s\n", type_name, s_str);
1416 gst_caps_unref (caps);
1420 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1422 const gchar *const *protocols;
1424 protocols = gst_element_factory_get_uri_protocols (factory);
1425 if (protocols != NULL && *protocols != NULL) {
1426 switch (gst_element_factory_get_uri_type (factory)) {
1428 while (*protocols != NULL) {
1429 g_print ("urisink-%s\n", *protocols);
1434 while (*protocols != NULL) {
1435 g_print ("urisource-%s\n", *protocols);
1446 print_plugin_automatic_install_info (GstPlugin * plugin)
1448 GList *features, *l;
1450 /* not interested in typefind factories, only element factories */
1451 features = gst_registry_get_feature_list (gst_registry_get (),
1452 GST_TYPE_ELEMENT_FACTORY);
1454 for (l = features; l != NULL; l = l->next) {
1455 GstPluginFeature *feature;
1456 GstPlugin *feature_plugin;
1458 feature = GST_PLUGIN_FEATURE (l->data);
1460 /* only interested in the ones that are in the plugin we just loaded */
1461 feature_plugin = gst_plugin_feature_get_plugin (feature);
1462 if (feature_plugin == plugin) {
1463 GstElementFactory *factory;
1465 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1467 factory = GST_ELEMENT_FACTORY (feature);
1468 print_plugin_automatic_install_info_protocols (factory);
1469 print_plugin_automatic_install_info_codecs (factory);
1472 gst_object_unref (feature_plugin);
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 g_set_prgname ("gst-inspect-" GST_API_VERSION);
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 ();
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);