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_metadata (GQuark field_id, const GValue * value,
184 gchar *val = g_strdup_value_contents (value);
185 gchar *key = g_strdup (g_quark_to_string (field_id));
187 key[0] = g_ascii_toupper (key[0]);
188 n_print (" %s:\t\t%s\n", key, val);
195 print_factory_details_info (GstElementFactory * factory)
199 n_print ("Factory Details:\n");
200 n_print (" Rank:\t\t%s (%d)\n",
201 get_rank_name (s, GST_PLUGIN_FEATURE (factory)->rank),
202 GST_PLUGIN_FEATURE (factory)->rank);
203 gst_structure_foreach ((GstStructure *) factory->metadata,
204 print_factory_details_metadata, NULL);
209 print_hierarchy (GType type, gint level, gint * maxlevel)
214 parent = g_type_parent (type);
216 *maxlevel = *maxlevel + 1;
220 print_hierarchy (parent, level, maxlevel);
223 g_print ("%s", _name);
225 for (i = 1; i < *maxlevel - level; i++)
227 if (*maxlevel - level)
230 g_print ("%s\n", g_type_name (type));
237 print_interfaces (GType type)
240 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
245 g_print ("%s", _name);
246 g_print (_("Implemented Interfaces:\n"));
250 g_print ("%s", _name);
251 g_print (" %s\n", g_type_name (*iface));
255 g_print ("%s", _name);
263 flags_to_string (GFlagsValue * vals, guint flags)
268 /* first look for an exact match and count the number of values */
269 for (i = 0; vals[i].value_name != NULL; ++i) {
270 if (vals[i].value == flags)
271 return g_strdup (vals[i].value_nick);
274 s = g_string_new (NULL);
276 /* we assume the values are sorted from lowest to highest value */
280 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
282 g_string_append_c (s, '+');
283 g_string_append (s, vals[i].value_nick);
284 flags_left -= vals[i].value;
291 g_string_assign (s, "(none)");
293 return g_string_free (s, FALSE);
296 #define KNOWN_PARAM_FLAGS \
297 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
298 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
299 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
300 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
301 GST_PARAM_MUTABLE_READY)
304 print_element_properties_info (GstElement * element)
306 GParamSpec **property_specs;
307 guint num_properties, i;
311 property_specs = g_object_class_list_properties
312 (G_OBJECT_GET_CLASS (element), &num_properties);
314 n_print ("Element Properties:\n");
316 for (i = 0; i < num_properties; i++) {
317 GValue value = { 0, };
318 GParamSpec *param = property_specs[i];
322 g_value_init (&value, param->value_type);
324 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
325 g_param_spec_get_blurb (param));
328 n_print ("%-23.23s flags: ", "");
329 if (param->flags & G_PARAM_READABLE) {
330 g_object_get_property (G_OBJECT (element), param->name, &value);
332 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
335 /* if we can't read the property value, assume it's set to the default
336 * (which might not be entirely true for sub-classes, but that's an
337 * unlikely corner-case anyway) */
338 g_param_value_set_default (param, &value);
340 if (param->flags & G_PARAM_WRITABLE) {
341 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
344 if (param->flags & GST_PARAM_CONTROLLABLE) {
345 g_print (", %s", _("controllable"));
348 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
349 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
350 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
351 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
352 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
353 g_print (", %s", _("changeable only in NULL or READY state"));
355 if (param->flags & ~KNOWN_PARAM_FLAGS) {
356 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
357 param->flags & ~KNOWN_PARAM_FLAGS);
361 switch (G_VALUE_TYPE (&value)) {
364 const char *string_val = g_value_get_string (&value);
366 n_print ("%-23.23s String. ", "");
368 if (string_val == NULL)
369 g_print ("Default: null");
371 g_print ("Default: \"%s\"", string_val);
376 gboolean bool_val = g_value_get_boolean (&value);
378 n_print ("%-23.23s Boolean. ", "");
380 g_print ("Default: %s", bool_val ? "true" : "false");
385 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
387 n_print ("%-23.23s Unsigned Long. ", "");
388 g_print ("Range: %lu - %lu Default: %lu ",
389 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
391 GST_ERROR ("%s: property '%s' of type char: consider changing to "
392 "uint/uint64", GST_OBJECT_NAME (element),
393 g_param_spec_get_name (param));
398 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
400 n_print ("%-23.23s Long. ", "");
401 g_print ("Range: %ld - %ld Default: %ld ",
402 plong->minimum, plong->maximum, g_value_get_long (&value));
404 GST_ERROR ("%s: property '%s' of type long: consider changing to "
405 "int/int64", GST_OBJECT_NAME (element),
406 g_param_spec_get_name (param));
411 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
413 n_print ("%-23.23s Unsigned Integer. ", "");
414 g_print ("Range: %u - %u Default: %u ",
415 puint->minimum, puint->maximum, g_value_get_uint (&value));
420 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
422 n_print ("%-23.23s Integer. ", "");
423 g_print ("Range: %d - %d Default: %d ",
424 pint->minimum, pint->maximum, g_value_get_int (&value));
429 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
431 n_print ("%-23.23s Unsigned Integer64. ", "");
432 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
433 " Default: %" G_GUINT64_FORMAT " ",
434 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
439 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
441 n_print ("%-23.23s Integer64. ", "");
442 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
443 " Default: %" G_GINT64_FORMAT " ",
444 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
449 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
451 n_print ("%-23.23s Float. ", "");
452 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
453 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
458 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
460 n_print ("%-23.23s Double. ", "");
461 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
462 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
467 GST_ERROR ("%s: property '%s' of type char: consider changing to "
468 "int/string", GST_OBJECT_NAME (element),
469 g_param_spec_get_name (param));
472 if (param->value_type == GST_TYPE_CAPS) {
473 const GstCaps *caps = gst_value_get_caps (&value);
476 n_print ("%-23.23s Caps (NULL)", "");
478 print_caps (caps, " ");
480 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
484 const gchar *value_nick = "";
486 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
487 enum_value = g_value_get_enum (&value);
489 while (values[j].value_name) {
490 if (values[j].value == enum_value)
491 value_nick = values[j].value_nick;
495 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
496 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
499 while (values[j].value_name) {
502 g_print ("%s", _name);
503 g_print ("%-23.23s (%d): %-16s - %s", "",
504 values[j].value, values[j].value_nick, values[j].value_name);
507 /* g_type_class_unref (ec); */
508 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
509 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
513 vals = pflags->flags_class->values;
515 cur = flags_to_string (vals, g_value_get_flags (&value));
517 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
518 g_type_name (G_VALUE_TYPE (&value)),
519 g_value_get_flags (&value), cur);
521 while (vals[0].value_name) {
524 g_print ("%s", _name);
525 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
526 vals[0].value, vals[0].value_nick, vals[0].value_name);
531 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
532 n_print ("%-23.23s Object of type \"%s\"", "",
533 g_type_name (param->value_type));
534 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
535 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
536 g_type_name (param->value_type));
537 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
538 if (param->value_type != G_TYPE_POINTER) {
539 n_print ("%-23.23s Pointer of type \"%s\".", "",
540 g_type_name (param->value_type));
542 n_print ("%-23.23s Pointer.", "");
544 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
545 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
547 if (pvarray->element_spec) {
548 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
549 g_type_name (pvarray->element_spec->value_type));
551 n_print ("%-23.23s Array of GValues", "");
553 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
554 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
556 n_print ("%-23.23s Fraction. ", "");
558 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
559 pfraction->min_num, pfraction->min_den,
560 pfraction->max_num, pfraction->max_den,
561 gst_value_get_fraction_numerator (&value),
562 gst_value_get_fraction_denominator (&value));
564 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
565 g_type_name (param->value_type));
570 g_print (" Write only\n");
574 g_value_reset (&value);
576 if (num_properties == 0)
579 g_free (property_specs);
583 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
585 GstElementClass *gstelement_class;
587 GstStaticPadTemplate *padtemplate;
589 n_print ("Pad Templates:\n");
590 if (!factory->numpadtemplates) {
595 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
597 pads = factory->staticpadtemplates;
599 padtemplate = (GstStaticPadTemplate *) (pads->data);
600 pads = g_list_next (pads);
602 if (padtemplate->direction == GST_PAD_SRC)
603 n_print (" SRC template: '%s'\n", padtemplate->name_template);
604 else if (padtemplate->direction == GST_PAD_SINK)
605 n_print (" SINK template: '%s'\n", padtemplate->name_template);
607 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
609 if (padtemplate->presence == GST_PAD_ALWAYS)
610 n_print (" Availability: Always\n");
611 else if (padtemplate->presence == GST_PAD_SOMETIMES)
612 n_print (" Availability: Sometimes\n");
613 else if (padtemplate->presence == GST_PAD_REQUEST) {
614 n_print (" Availability: On request\n");
615 n_print (" Has request_new_pad() function: %s\n",
616 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
618 n_print (" Availability: UNKNOWN!!!\n");
620 if (padtemplate->static_caps.string) {
621 n_print (" Capabilities:\n");
622 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
630 print_element_flag_info (GstElement * element)
632 gboolean have_flags = FALSE;
635 n_print ("Element Flags:\n");
638 n_print (" no flags set\n");
640 if (GST_IS_BIN (element)) {
642 n_print ("Bin Flags:\n");
644 n_print (" no flags set\n");
649 print_implementation_info (GstElement * element)
651 GstElementClass *gstelement_class;
653 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
656 n_print ("Element Implementation:\n");
658 n_print (" Has change_state() function: %s\n",
659 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
663 print_clocking_info (GstElement * element)
665 gboolean requires_clock, provides_clock;
668 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
670 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
672 if (!requires_clock && !provides_clock) {
674 n_print ("Element has no clocking capabilities.");
679 n_print ("Clocking Interaction:\n");
680 if (requires_clock) {
681 n_print (" element requires a clock\n");
684 if (provides_clock) {
687 clock = gst_element_get_clock (element);
689 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
690 gst_object_unref (clock);
692 n_print (" element is supposed to provide a clock but returned NULL\n");
697 print_index_info (GstElement * element)
699 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
701 n_print ("Indexing capabilities:\n");
702 n_print (" element can do indexing\n");
705 n_print ("Element has no indexing capabilities.\n");
710 print_uri_handler_info (GstElement * element)
712 if (GST_IS_URI_HANDLER (element)) {
713 const gchar *const *uri_protocols;
714 const gchar *uri_type;
716 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
718 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
722 uri_type = "unknown";
724 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
727 n_print ("URI handling capabilities:\n");
728 n_print (" Element can act as %s.\n", uri_type);
730 if (uri_protocols && *uri_protocols) {
731 n_print (" Supported URI protocols:\n");
732 for (; *uri_protocols != NULL; uri_protocols++)
733 n_print (" %s\n", *uri_protocols);
735 n_print (" No supported URI protocols\n");
738 n_print ("Element has no URI handling capabilities.\n");
743 print_pad_info (GstElement * element)
751 if (!element->numpads) {
756 pads = element->pads;
761 pad = GST_PAD (pads->data);
762 pads = g_list_next (pads);
766 name = gst_pad_get_name (pad);
767 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
768 g_print (" SRC: '%s'", name);
769 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
770 g_print (" SINK: '%s'", name);
772 g_print (" UNKNOWN!!!: '%s'", name);
778 n_print (" Implementation:\n");
780 n_print (" Has chainfunc(): %s\n",
781 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
782 if (pad->getrangefunc)
783 n_print (" Has getrangefunc(): %s\n",
784 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
785 if (pad->eventfunc != gst_pad_event_default)
786 n_print (" Has custom eventfunc(): %s\n",
787 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
788 if (pad->queryfunc != gst_pad_query_default)
789 n_print (" Has custom queryfunc(): %s\n",
790 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
792 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
793 n_print (" Has custom iterintlinkfunc(): %s\n",
794 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
796 if (pad->padtemplate)
797 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
799 caps = gst_pad_get_current_caps (pad);
801 n_print (" Capabilities:\n");
802 print_caps (caps, " ");
803 gst_caps_unref (caps);
809 has_sometimes_template (GstElement * element)
811 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
814 for (l = klass->padtemplates; l != NULL; l = l->next) {
815 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
823 print_signal_info (GstElement * element)
825 /* Signals/Actions Block */
829 GSignalQuery *query = NULL;
831 GSList *found_signals, *l;
833 for (k = 0; k < 2; k++) {
834 found_signals = NULL;
836 /* For elements that have sometimes pads, also list a few useful GstElement
837 * signals. Put these first, so element-specific ones come later. */
838 if (k == 0 && has_sometimes_template (element)) {
839 query = g_new0 (GSignalQuery, 1);
840 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
841 found_signals = g_slist_append (found_signals, query);
842 query = g_new0 (GSignalQuery, 1);
843 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
844 found_signals = g_slist_append (found_signals, query);
845 query = g_new0 (GSignalQuery, 1);
846 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
848 found_signals = g_slist_append (found_signals, query);
851 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
852 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
855 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
858 signals = g_signal_list_ids (type, &nsignals);
859 for (i = 0; i < nsignals; i++) {
860 query = g_new0 (GSignalQuery, 1);
861 g_signal_query (signals[i], query);
863 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
864 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
865 found_signals = g_slist_append (found_signals, query);
876 n_print ("Element Signals:\n");
878 n_print ("Element Actions:\n");
883 for (l = found_signals; l; l = l->next) {
887 query = (GSignalQuery *) l->data;
888 indent_len = strlen (query->signal_name) +
889 strlen (g_type_name (query->return_type)) + 24;
891 indent = g_new0 (gchar, indent_len + 1);
892 memset (indent, ' ', indent_len);
894 n_print (" \"%s\" : %s user_function (%s* object",
896 g_type_name (query->return_type), g_type_name (type));
898 for (j = 0; j < query->n_params; j++) {
900 g_print ("%s", _name);
901 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
902 g_print (",\n%s%s arg%d", indent,
903 g_type_name (query->param_types[j]), j);
904 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
905 g_print (",\n%s%s arg%d", indent,
906 g_type_name (query->param_types[j]), j);
908 g_print (",\n%s%s* arg%d", indent,
909 g_type_name (query->param_types[j]), j);
915 g_print ("%s", _name);
916 g_print (",\n%sgpointer user_data);\n", indent);
924 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
925 g_slist_free (found_signals);
931 print_children_info (GstElement * element)
935 if (!GST_IS_BIN (element))
938 children = (GList *) GST_BIN (element)->children;
941 g_print ("Children:\n");
945 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
946 children = g_list_next (children);
951 print_blacklist (void)
953 GList *plugins, *cur;
956 g_print ("%s\n", _("Blacklisted files:"));
958 plugins = gst_registry_get_plugin_list (gst_registry_get ());
959 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
960 GstPlugin *plugin = (GstPlugin *) (cur->data);
961 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
962 g_print (" %s\n", plugin->desc.name);
968 g_print (_("Total count: "));
969 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
972 gst_plugin_list_free (plugins);
976 print_element_list (gboolean print_all)
978 int plugincount = 0, featurecount = 0, blacklistcount = 0;
979 GList *plugins, *orig_plugins;
981 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
983 GList *features, *orig_features;
986 plugin = (GstPlugin *) (plugins->data);
987 plugins = g_list_next (plugins);
990 if (plugin->flags & GST_PLUGIN_FLAG_BLACKLISTED) {
995 orig_features = features =
996 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
999 GstPluginFeature *feature;
1001 if (G_UNLIKELY (features->data == NULL))
1003 feature = GST_PLUGIN_FEATURE (features->data);
1006 if (GST_IS_ELEMENT_FACTORY (feature)) {
1007 GstElementFactory *factory;
1009 factory = GST_ELEMENT_FACTORY (feature);
1011 print_element_info (factory, TRUE);
1013 g_print ("%s: %s: %s\n", plugin->desc.name,
1014 GST_OBJECT_NAME (factory),
1015 gst_element_factory_get_longname (factory));
1017 } else if (GST_IS_INDEX_FACTORY (feature)) {
1018 GstIndexFactory *factory;
1020 factory = GST_INDEX_FACTORY (feature);
1022 g_print ("%s: %s: %s\n", plugin->desc.name,
1023 GST_OBJECT_NAME (factory), factory->longdesc);
1025 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1026 GstTypeFindFactory *factory;
1028 factory = GST_TYPE_FIND_FACTORY (feature);
1030 g_print ("%s: %s: ", plugin->desc.name,
1031 gst_plugin_feature_get_name (feature));
1032 if (factory->extensions) {
1035 while (factory->extensions[i]) {
1037 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1044 g_print ("no extensions\n");
1048 n_print ("%s: %s (%s)\n", plugin->desc.name,
1049 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1053 features = g_list_next (features);
1056 gst_plugin_feature_list_free (orig_features);
1059 gst_plugin_list_free (orig_plugins);
1062 g_print (_("Total count: "));
1063 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1064 if (blacklistcount) {
1066 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1067 blacklistcount), blacklistcount);
1068 g_print (" not shown)");
1071 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1076 print_all_uri_handlers (void)
1078 GList *plugins, *p, *features, *f;
1080 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1082 for (p = plugins; p; p = p->next) {
1083 GstPlugin *plugin = (GstPlugin *) (p->data);
1086 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1089 for (f = features; f; f = f->next) {
1090 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1092 if (GST_IS_ELEMENT_FACTORY (feature)) {
1093 GstElementFactory *factory;
1094 GstElement *element;
1096 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1098 g_print ("element plugin %s couldn't be loaded\n", plugin->desc.name);
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 n_print ("Plugin Details:\n");
1154 n_print (" Name:\t\t\t%s\n", plugin->desc.name);
1155 n_print (" Description:\t\t%s\n", plugin->desc.description);
1156 n_print (" Filename:\t\t%s\n",
1157 plugin->filename ? plugin->filename : "(null)");
1158 n_print (" Version:\t\t%s\n", plugin->desc.version);
1159 n_print (" License:\t\t%s\n", plugin->desc.license);
1160 n_print (" Source module:\t%s\n", plugin->desc.source);
1161 if (plugin->desc.release_datetime != NULL) {
1162 const gchar *tz = "(UTC)";
1165 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1166 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1167 str = g_strdup (plugin->desc.release_datetime);
1168 sep = strstr (str, "T");
1171 sep = strstr (sep + 1, "Z");
1177 n_print (" Source release date:\t%s%s\n", str, tz);
1180 n_print (" Binary package:\t%s\n", plugin->desc.package);
1181 n_print (" Origin URL:\t\t%s\n", plugin->desc.origin);
1186 print_plugin_features (GstPlugin * plugin)
1188 GList *features, *origlist;
1189 gint num_features = 0;
1190 gint num_elements = 0;
1191 gint num_typefinders = 0;
1192 gint num_indexes = 0;
1195 origlist = features =
1196 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1200 GstPluginFeature *feature;
1202 feature = GST_PLUGIN_FEATURE (features->data);
1204 if (GST_IS_ELEMENT_FACTORY (feature)) {
1205 GstElementFactory *factory;
1207 factory = GST_ELEMENT_FACTORY (feature);
1208 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1209 gst_element_factory_get_longname (factory));
1212 } else if (GST_IS_INDEX_FACTORY (feature)) {
1213 GstIndexFactory *factory;
1215 factory = GST_INDEX_FACTORY (feature);
1216 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1219 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1220 GstTypeFindFactory *factory;
1222 factory = GST_TYPE_FIND_FACTORY (feature);
1223 if (factory->extensions) {
1226 g_print ("%s: %s: ", plugin->desc.name,
1227 gst_plugin_feature_get_name (feature));
1228 while (factory->extensions[i]) {
1229 g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1234 g_print ("%s: %s: no extensions\n", plugin->desc.name,
1235 gst_plugin_feature_get_name (feature));
1238 } else if (feature) {
1239 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1240 g_type_name (G_OBJECT_TYPE (feature)));
1244 features = g_list_next (features);
1247 gst_plugin_feature_list_free (origlist);
1250 n_print (" %d features:\n", num_features);
1251 if (num_elements > 0)
1252 n_print (" +-- %d elements\n", num_elements);
1253 if (num_typefinders > 0)
1254 n_print (" +-- %d typefinders\n", num_typefinders);
1255 if (num_indexes > 0)
1256 n_print (" +-- %d indexes\n", num_indexes);
1258 n_print (" +-- %d other objects\n", num_other);
1264 print_element_features (const gchar * element_name)
1266 GstPluginFeature *feature;
1268 /* FIXME implement other pretty print function for these */
1270 feature = gst_default_registry_find_feature (element_name,
1271 GST_TYPE_INDEX_FACTORY);
1273 n_print ("%s: an index\n", element_name);
1277 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1278 GST_TYPE_TYPE_FIND_FACTORY);
1280 n_print ("%s: a typefind function\n", element_name);
1288 print_element_info (GstElementFactory * factory, gboolean print_names)
1290 GstElement *element;
1294 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1298 g_print ("element plugin couldn't be loaded\n");
1302 element = gst_element_factory_create (factory, NULL);
1304 g_print ("couldn't construct element for some reason\n");
1309 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1313 print_factory_details_info (factory);
1314 if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
1317 plugin = gst_registry_find_plugin (gst_registry_get (),
1318 GST_PLUGIN_FEATURE (factory)->plugin_name);
1320 print_plugin_info (plugin);
1324 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1325 print_interfaces (G_OBJECT_TYPE (element));
1327 print_pad_templates_info (element, factory);
1328 print_element_flag_info (element);
1329 print_implementation_info (element);
1330 print_clocking_info (element);
1331 print_index_info (element);
1332 print_uri_handler_info (element);
1333 print_pad_info (element);
1334 print_element_properties_info (element);
1335 print_signal_info (element);
1336 print_children_info (element);
1338 gst_object_unref (element);
1339 gst_object_unref (factory);
1347 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1349 GstPadDirection direction;
1350 const gchar *type_name;
1352 const GList *static_templates, *l;
1353 GstCaps *caps = NULL;
1356 klass = gst_element_factory_get_klass (factory);
1357 g_return_if_fail (klass != NULL);
1359 if (strstr (klass, "Demuxer") ||
1360 strstr (klass, "Decoder") ||
1361 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1362 type_name = "decoder";
1363 direction = GST_PAD_SINK;
1364 } else if (strstr (klass, "Muxer") ||
1365 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1366 type_name = "encoder";
1367 direction = GST_PAD_SRC;
1372 /* decoder/demuxer sink pads should always be static and there should only
1373 * be one, the same applies to encoders/muxers and source pads */
1374 static_templates = gst_element_factory_get_static_pad_templates (factory);
1375 for (l = static_templates; l != NULL; l = l->next) {
1376 GstStaticPadTemplate *tmpl = NULL;
1378 tmpl = (GstStaticPadTemplate *) l->data;
1379 if (tmpl->direction == direction) {
1380 caps = gst_static_pad_template_get_caps (tmpl);
1386 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1387 type_name, GST_OBJECT_NAME (factory));
1391 caps = gst_caps_make_writable (caps);
1392 num = gst_caps_get_size (caps);
1393 for (i = 0; i < num; ++i) {
1397 s = gst_caps_get_structure (caps, i);
1398 /* remove fields that are almost always just MIN-MAX of some sort
1399 * in order to make the caps look less messy */
1400 gst_structure_remove_field (s, "pixel-aspect-ratio");
1401 gst_structure_remove_field (s, "framerate");
1402 gst_structure_remove_field (s, "channels");
1403 gst_structure_remove_field (s, "width");
1404 gst_structure_remove_field (s, "height");
1405 gst_structure_remove_field (s, "rate");
1406 gst_structure_remove_field (s, "depth");
1407 gst_structure_remove_field (s, "clock-rate");
1408 s_str = gst_structure_to_string (s);
1409 g_print ("%s-%s\n", type_name, s_str);
1412 gst_caps_unref (caps);
1416 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1418 const gchar *const *protocols;
1420 protocols = gst_element_factory_get_uri_protocols (factory);
1421 if (protocols != NULL && *protocols != NULL) {
1422 switch (gst_element_factory_get_uri_type (factory)) {
1424 while (*protocols != NULL) {
1425 g_print ("urisink-%s\n", *protocols);
1430 while (*protocols != NULL) {
1431 g_print ("urisource-%s\n", *protocols);
1442 print_plugin_automatic_install_info (GstPlugin * plugin)
1444 const gchar *plugin_name;
1445 GList *features, *l;
1447 plugin_name = gst_plugin_get_name (plugin);
1449 /* not interested in typefind factories, only element factories */
1450 features = gst_registry_get_feature_list (gst_registry_get (),
1451 GST_TYPE_ELEMENT_FACTORY);
1453 for (l = features; l != NULL; l = l->next) {
1454 GstPluginFeature *feature;
1456 feature = GST_PLUGIN_FEATURE (l->data);
1458 /* only interested in the ones that are in the plugin we just loaded */
1459 if (g_str_equal (plugin_name, feature->plugin_name)) {
1460 GstElementFactory *factory;
1462 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1464 factory = GST_ELEMENT_FACTORY (feature);
1465 print_plugin_automatic_install_info_protocols (factory);
1466 print_plugin_automatic_install_info_codecs (factory);
1470 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1471 g_list_free (features);
1475 print_all_plugin_automatic_install_info (void)
1477 GList *plugins, *orig_plugins;
1479 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1483 plugin = (GstPlugin *) (plugins->data);
1484 plugins = g_list_next (plugins);
1486 print_plugin_automatic_install_info (plugin);
1488 gst_plugin_list_free (orig_plugins);
1492 main (int argc, char *argv[])
1494 gboolean print_all = FALSE;
1495 gboolean do_print_blacklist = FALSE;
1496 gboolean plugin_name = FALSE;
1497 gboolean print_aii = FALSE;
1498 gboolean uri_handlers = FALSE;
1499 #ifndef GST_DISABLE_OPTION_PARSING
1500 GOptionEntry options[] = {
1501 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1502 N_("Print all elements"), NULL},
1503 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1504 N_("Print list of blacklisted files"), NULL},
1505 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1506 N_("Print a machine-parsable list of features the specified plugin "
1507 "or all plugins provide.\n "
1508 "Useful in connection with external automatic plugin "
1509 "installation mechanisms"), NULL},
1510 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1511 N_("List the plugin contents"), NULL},
1512 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1514 ("Print supported URI schemes, with the elements that implement them"),
1516 GST_TOOLS_GOPTION_VERSION,
1519 GOptionContext *ctx;
1524 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1525 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1526 textdomain (GETTEXT_PACKAGE);
1529 #if !GLIB_CHECK_VERSION (2, 31, 0)
1530 g_thread_init (NULL);
1533 gst_tools_set_prgname ("gst-inspect");
1535 #ifndef GST_DISABLE_OPTION_PARSING
1536 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1537 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1538 g_option_context_add_group (ctx, gst_init_get_option_group ());
1539 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1540 g_print ("Error initializing: %s\n", err->message);
1543 g_option_context_free (ctx);
1545 gst_init (&argc, &argv);
1548 gst_tools_print_version ("gst-inspect");
1550 if (print_all && argc > 1) {
1551 g_print ("-a requires no extra arguments\n");
1555 if (uri_handlers && argc > 1) {
1556 g_print ("-u requires no extra arguments\n");
1560 /* if no arguments, print out list of elements */
1562 print_all_uri_handlers ();
1563 } else if (argc == 1 || print_all) {
1564 if (do_print_blacklist)
1568 print_all_plugin_automatic_install_info ();
1570 print_element_list (print_all);
1573 /* else we try to get a factory */
1574 GstElementFactory *factory;
1576 const char *arg = argv[argc - 1];
1580 factory = gst_element_factory_find (arg);
1582 /* if there's a factory, print out the info */
1584 retval = print_element_info (factory, print_all);
1585 gst_object_unref (factory);
1587 retval = print_element_features (arg);
1593 /* otherwise check if it's a plugin */
1595 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1597 /* if there is such a plugin, print out info */
1600 print_plugin_automatic_install_info (plugin);
1602 print_plugin_info (plugin);
1603 print_plugin_features (plugin);
1606 GError *error = NULL;
1608 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1609 plugin = gst_plugin_load_file (arg, &error);
1613 print_plugin_automatic_install_info (plugin);
1615 print_plugin_info (plugin);
1616 print_plugin_features (plugin);
1619 g_print (_("Could not load plugin file: %s\n"), error->message);
1620 g_error_free (error);
1624 g_print (_("No such element or plugin '%s'\n"), arg);