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