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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 /* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
29 * with newer GLib versions (>= 2.31.0) */
30 #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);
47 n_print (const char *format, ...)
52 g_print ("%s", _name);
54 va_start (args, format);
55 g_vprintf (format, args);
60 print_field (GQuark field, const GValue * value, gpointer pfx)
62 gchar *str = gst_value_serialize (value);
64 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
70 print_caps (const GstCaps * caps, const gchar * pfx)
74 g_return_if_fail (caps != NULL);
76 if (gst_caps_is_any (caps)) {
77 n_print ("%sANY\n", pfx);
80 if (gst_caps_is_empty (caps)) {
81 n_print ("%sEMPTY\n", pfx);
85 for (i = 0; i < gst_caps_get_size (caps); i++) {
86 GstStructure *structure = gst_caps_get_structure (caps, i);
87 GstCapsFeatures *features = gst_caps_get_features (caps, i);
89 if (features && (gst_caps_features_is_any (features) ||
90 !gst_caps_features_is_equal (features,
91 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
92 gchar *features_string = gst_caps_features_to_string (features);
94 n_print ("%s%s(%s)\n", pfx, gst_structure_get_name (structure),
96 g_free (features_string);
98 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
100 gst_structure_foreach (structure, print_field, (gpointer) pfx);
105 get_rank_name (char *s, gint rank)
107 static const int ranks[4] = {
108 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
110 static const char *rank_names[4] = { "none", "marginal", "secondary",
117 for (i = 0; i < 4; i++) {
118 if (rank == ranks[i])
119 return rank_names[i];
120 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
125 sprintf (s, "%s %c %d", rank_names[best_i],
126 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
132 print_factory_details_info (GstElementFactory * factory)
138 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
139 n_print ("Factory Details:\n");
140 n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
142 keys = gst_element_factory_get_metadata_keys (factory);
144 for (k = keys; *k != NULL; ++k) {
148 val = gst_element_factory_get_metadata (factory, key);
149 key[0] = g_ascii_toupper (key[0]);
150 n_print (" %-25s%s\n", key, val);
158 print_hierarchy (GType type, gint level, gint * maxlevel)
163 parent = g_type_parent (type);
165 *maxlevel = *maxlevel + 1;
169 print_hierarchy (parent, level, maxlevel);
172 g_print ("%s", _name);
174 for (i = 1; i < *maxlevel - level; i++)
176 if (*maxlevel - level)
179 g_print ("%s\n", g_type_name (type));
186 print_interfaces (GType type)
189 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
194 g_print ("%s", _name);
195 g_print (_("Implemented Interfaces:\n"));
199 g_print ("%s", _name);
200 g_print (" %s\n", g_type_name (*iface));
204 g_print ("%s", _name);
212 flags_to_string (GFlagsValue * vals, guint flags)
217 /* first look for an exact match and count the number of values */
218 for (i = 0; vals[i].value_name != NULL; ++i) {
219 if (vals[i].value == flags)
220 return g_strdup (vals[i].value_nick);
223 s = g_string_new (NULL);
225 /* we assume the values are sorted from lowest to highest value */
229 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
231 g_string_append_c (s, '+');
232 g_string_append (s, vals[i].value_nick);
233 flags_left -= vals[i].value;
240 g_string_assign (s, "(none)");
242 return g_string_free (s, FALSE);
245 #define KNOWN_PARAM_FLAGS \
246 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
247 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
248 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
249 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
250 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
253 print_element_properties_info (GstElement * element)
255 GParamSpec **property_specs;
256 guint num_properties, i;
260 property_specs = g_object_class_list_properties
261 (G_OBJECT_GET_CLASS (element), &num_properties);
263 n_print ("Element Properties:\n");
265 for (i = 0; i < num_properties; i++) {
266 GValue value = { 0, };
267 GParamSpec *param = property_specs[i];
271 g_value_init (&value, param->value_type);
273 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
274 g_param_spec_get_blurb (param));
277 n_print ("%-23.23s flags: ", "");
278 if (param->flags & G_PARAM_READABLE) {
279 g_object_get_property (G_OBJECT (element), param->name, &value);
281 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
284 /* if we can't read the property value, assume it's set to the default
285 * (which might not be entirely true for sub-classes, but that's an
286 * unlikely corner-case anyway) */
287 g_param_value_set_default (param, &value);
289 if (param->flags & G_PARAM_WRITABLE) {
290 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
293 if (param->flags & G_PARAM_DEPRECATED) {
294 g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
297 if (param->flags & GST_PARAM_CONTROLLABLE) {
298 g_print (", %s", _("controllable"));
301 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
302 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
303 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
304 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
305 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
306 g_print (", %s", _("changeable only in NULL or READY state"));
308 if (param->flags & ~KNOWN_PARAM_FLAGS) {
309 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
310 param->flags & ~KNOWN_PARAM_FLAGS);
314 switch (G_VALUE_TYPE (&value)) {
317 const char *string_val = g_value_get_string (&value);
319 n_print ("%-23.23s String. ", "");
321 if (string_val == NULL)
322 g_print ("Default: null");
324 g_print ("Default: \"%s\"", string_val);
329 gboolean bool_val = g_value_get_boolean (&value);
331 n_print ("%-23.23s Boolean. ", "");
333 g_print ("Default: %s", bool_val ? "true" : "false");
338 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
340 n_print ("%-23.23s Unsigned Long. ", "");
341 g_print ("Range: %lu - %lu Default: %lu ",
342 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
344 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
345 "uint/uint64", GST_OBJECT_NAME (element),
346 g_param_spec_get_name (param));
351 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
353 n_print ("%-23.23s Long. ", "");
354 g_print ("Range: %ld - %ld Default: %ld ",
355 plong->minimum, plong->maximum, g_value_get_long (&value));
357 GST_ERROR ("%s: property '%s' of type long: consider changing to "
358 "int/int64", GST_OBJECT_NAME (element),
359 g_param_spec_get_name (param));
364 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
366 n_print ("%-23.23s Unsigned Integer. ", "");
367 g_print ("Range: %u - %u Default: %u ",
368 puint->minimum, puint->maximum, g_value_get_uint (&value));
373 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
375 n_print ("%-23.23s Integer. ", "");
376 g_print ("Range: %d - %d Default: %d ",
377 pint->minimum, pint->maximum, g_value_get_int (&value));
382 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
384 n_print ("%-23.23s Unsigned Integer64. ", "");
385 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
386 " Default: %" G_GUINT64_FORMAT " ",
387 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
392 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
394 n_print ("%-23.23s Integer64. ", "");
395 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
396 " Default: %" G_GINT64_FORMAT " ",
397 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
402 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
404 n_print ("%-23.23s Float. ", "");
405 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
406 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
411 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
413 n_print ("%-23.23s Double. ", "");
414 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
415 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
420 GST_ERROR ("%s: property '%s' of type char: consider changing to "
421 "int/string", GST_OBJECT_NAME (element),
422 g_param_spec_get_name (param));
425 if (param->value_type == GST_TYPE_CAPS) {
426 const GstCaps *caps = gst_value_get_caps (&value);
429 n_print ("%-23.23s Caps (NULL)", "");
431 print_caps (caps, " ");
433 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
437 const gchar *value_nick = "";
439 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
440 enum_value = g_value_get_enum (&value);
442 while (values[j].value_name) {
443 if (values[j].value == enum_value)
444 value_nick = values[j].value_nick;
448 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
449 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
452 while (values[j].value_name) {
455 g_print ("%s", _name);
456 g_print ("%-23.23s (%d): %-16s - %s", "",
457 values[j].value, values[j].value_nick, values[j].value_name);
460 /* g_type_class_unref (ec); */
461 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
462 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
466 vals = pflags->flags_class->values;
468 cur = flags_to_string (vals, g_value_get_flags (&value));
470 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
471 g_type_name (G_VALUE_TYPE (&value)),
472 g_value_get_flags (&value), cur);
474 while (vals[0].value_name) {
477 g_print ("%s", _name);
478 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
479 vals[0].value, vals[0].value_nick, vals[0].value_name);
484 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
485 n_print ("%-23.23s Object of type \"%s\"", "",
486 g_type_name (param->value_type));
487 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
488 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
489 g_type_name (param->value_type));
490 if (param->value_type == GST_TYPE_STRUCTURE) {
491 const GstStructure *s = gst_value_get_structure (&value);
493 gst_structure_foreach (s, print_field,
496 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
497 if (param->value_type != G_TYPE_POINTER) {
498 n_print ("%-23.23s Pointer of type \"%s\".", "",
499 g_type_name (param->value_type));
501 n_print ("%-23.23s Pointer.", "");
503 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
504 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
506 if (pvarray->element_spec) {
507 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
508 g_type_name (pvarray->element_spec->value_type));
510 n_print ("%-23.23s Array of GValues", "");
512 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
513 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
515 n_print ("%-23.23s Fraction. ", "");
517 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
518 pfraction->min_num, pfraction->min_den,
519 pfraction->max_num, pfraction->max_den,
520 gst_value_get_fraction_numerator (&value),
521 gst_value_get_fraction_denominator (&value));
523 n_print ("%-23.23s Unknown type %ld \"%s\"", "",
524 (glong) param->value_type, g_type_name (param->value_type));
529 g_print (" Write only\n");
533 g_value_reset (&value);
535 if (num_properties == 0)
538 g_free (property_specs);
542 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
545 GstStaticPadTemplate *padtemplate;
547 n_print ("Pad Templates:\n");
548 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
553 pads = gst_element_factory_get_static_pad_templates (factory);
555 padtemplate = (GstStaticPadTemplate *) (pads->data);
556 pads = g_list_next (pads);
558 if (padtemplate->direction == GST_PAD_SRC)
559 n_print (" SRC template: '%s'\n", padtemplate->name_template);
560 else if (padtemplate->direction == GST_PAD_SINK)
561 n_print (" SINK template: '%s'\n", padtemplate->name_template);
563 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
565 if (padtemplate->presence == GST_PAD_ALWAYS)
566 n_print (" Availability: Always\n");
567 else if (padtemplate->presence == GST_PAD_SOMETIMES)
568 n_print (" Availability: Sometimes\n");
569 else if (padtemplate->presence == GST_PAD_REQUEST) {
570 n_print (" Availability: On request\n");
572 n_print (" Availability: UNKNOWN!!!\n");
574 if (padtemplate->static_caps.string) {
575 n_print (" Capabilities:\n");
576 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
584 print_element_flag_info (GstElement * element)
586 gboolean have_flags = FALSE;
589 n_print ("Element Flags:\n");
592 n_print (" no flags set\n");
594 if (GST_IS_BIN (element)) {
596 n_print ("Bin Flags:\n");
598 n_print (" no flags set\n");
603 print_implementation_info (GstElement * element)
605 GstElementClass *gstelement_class;
607 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
610 n_print ("Element Implementation:\n");
612 n_print (" Has change_state() function: %s\n",
613 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
617 print_clocking_info (GstElement * element)
619 gboolean requires_clock, provides_clock;
622 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
624 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
626 if (!requires_clock && !provides_clock) {
628 n_print ("Element has no clocking capabilities.\n");
633 n_print ("Clocking Interaction:\n");
634 if (requires_clock) {
635 n_print (" element requires a clock\n");
638 if (provides_clock) {
641 clock = gst_element_get_clock (element);
643 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
644 gst_object_unref (clock);
646 n_print (" element is supposed to provide a clock but returned NULL\n");
651 print_uri_handler_info (GstElement * element)
653 if (GST_IS_URI_HANDLER (element)) {
654 const gchar *const *uri_protocols;
655 const gchar *uri_type;
657 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
659 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
663 uri_type = "unknown";
665 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
668 n_print ("URI handling capabilities:\n");
669 n_print (" Element can act as %s.\n", uri_type);
671 if (uri_protocols && *uri_protocols) {
672 n_print (" Supported URI protocols:\n");
673 for (; *uri_protocols != NULL; uri_protocols++)
674 n_print (" %s\n", *uri_protocols);
676 n_print (" No supported URI protocols\n");
679 n_print ("Element has no URI handling capabilities.\n");
684 print_pad_info (GstElement * element)
692 if (!element->numpads) {
697 pads = element->pads;
702 pad = GST_PAD (pads->data);
703 pads = g_list_next (pads);
705 name = gst_pad_get_name (pad);
706 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
707 n_print (" SRC: '%s'\n", name);
708 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
709 n_print (" SINK: '%s'\n", name);
711 n_print (" UNKNOWN!!!: '%s'\n", name);
715 if (pad->padtemplate)
716 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
718 caps = gst_pad_get_current_caps (pad);
720 n_print (" Capabilities:\n");
721 print_caps (caps, " ");
722 gst_caps_unref (caps);
728 has_sometimes_template (GstElement * element)
730 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
733 for (l = klass->padtemplates; l != NULL; l = l->next) {
734 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
742 gtype_needs_ptr_marker (GType type)
744 if (type == G_TYPE_POINTER)
747 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
748 || G_TYPE_IS_OBJECT (type))
755 print_signal_info (GstElement * element)
757 /* Signals/Actions Block */
761 GSignalQuery *query = NULL;
763 GSList *found_signals, *l;
765 for (k = 0; k < 2; k++) {
766 found_signals = NULL;
768 /* For elements that have sometimes pads, also list a few useful GstElement
769 * signals. Put these first, so element-specific ones come later. */
770 if (k == 0 && has_sometimes_template (element)) {
771 query = g_new0 (GSignalQuery, 1);
772 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
773 found_signals = g_slist_append (found_signals, query);
774 query = g_new0 (GSignalQuery, 1);
775 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
776 found_signals = g_slist_append (found_signals, query);
777 query = g_new0 (GSignalQuery, 1);
778 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
780 found_signals = g_slist_append (found_signals, query);
783 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
784 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
787 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
790 signals = g_signal_list_ids (type, &nsignals);
791 for (i = 0; i < nsignals; i++) {
792 query = g_new0 (GSignalQuery, 1);
793 g_signal_query (signals[i], query);
795 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
796 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
797 found_signals = g_slist_append (found_signals, query);
808 n_print ("Element Signals:\n");
810 n_print ("Element Actions:\n");
815 for (l = found_signals; l; l = l->next) {
820 query = (GSignalQuery *) l->data;
821 indent_len = strlen (query->signal_name) +
822 strlen (g_type_name (query->return_type)) + 24;
824 if (gtype_needs_ptr_marker (query->return_type)) {
831 indent = g_new0 (gchar, indent_len + 1);
832 memset (indent, ' ', indent_len);
834 n_print (" \"%s\" : %s %suser_function (%s* object",
835 query->signal_name, g_type_name (query->return_type), pmark,
838 for (j = 0; j < query->n_params; j++) {
839 const gchar *type_name, *asterisk;
841 type_name = g_type_name (query->param_types[j]);
842 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
845 n_print ("%s%s%s arg%d", indent, type_name, asterisk, j);
850 n_print ("%sgpointer user_data);\n", indent);
858 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
859 g_slist_free (found_signals);
865 print_children_info (GstElement * element)
869 if (!GST_IS_BIN (element))
872 children = (GList *) GST_BIN (element)->children;
875 n_print ("Children:\n");
879 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
880 children = g_list_next (children);
885 print_preset_list (GstElement * element)
887 gchar **presets, **preset;
889 if (!GST_IS_PRESET (element))
892 presets = gst_preset_get_preset_names (GST_PRESET (element));
893 if (presets && *presets) {
895 n_print ("Presets:\n");
896 for (preset = presets; *preset; preset++) {
897 n_print (" \"%s\"\n", *preset);
899 g_strfreev (presets);
904 print_blacklist (void)
906 GList *plugins, *cur;
909 g_print ("%s\n", _("Blacklisted files:"));
911 plugins = gst_registry_get_plugin_list (gst_registry_get ());
912 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
913 GstPlugin *plugin = (GstPlugin *) (cur->data);
914 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
915 g_print (" %s\n", gst_plugin_get_name (plugin));
921 g_print (_("Total count: "));
922 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
925 gst_plugin_list_free (plugins);
929 print_element_list (gboolean print_all)
931 int plugincount = 0, featurecount = 0, blacklistcount = 0;
932 GList *plugins, *orig_plugins;
934 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
936 GList *features, *orig_features;
939 plugin = (GstPlugin *) (plugins->data);
940 plugins = g_list_next (plugins);
943 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
948 orig_features = features =
949 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
950 gst_plugin_get_name (plugin));
952 GstPluginFeature *feature;
954 if (G_UNLIKELY (features->data == NULL))
956 feature = GST_PLUGIN_FEATURE (features->data);
959 if (GST_IS_ELEMENT_FACTORY (feature)) {
960 GstElementFactory *factory;
962 factory = GST_ELEMENT_FACTORY (feature);
964 print_element_info (factory, TRUE);
966 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
967 GST_OBJECT_NAME (factory),
968 gst_element_factory_get_metadata (factory,
969 GST_ELEMENT_METADATA_LONGNAME));
970 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
971 GstTypeFindFactory *factory;
972 const gchar *const *extensions;
974 factory = GST_TYPE_FIND_FACTORY (feature);
976 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
977 gst_plugin_feature_get_name (feature));
979 extensions = gst_type_find_factory_get_extensions (factory);
980 if (extensions != NULL) {
983 while (extensions[i]) {
985 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
992 g_print ("no extensions\n");
996 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
997 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1001 features = g_list_next (features);
1004 gst_plugin_feature_list_free (orig_features);
1007 gst_plugin_list_free (orig_plugins);
1010 g_print (_("Total count: "));
1011 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1012 if (blacklistcount) {
1014 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1015 blacklistcount), blacklistcount);
1016 g_print (" not shown)");
1019 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1024 print_all_uri_handlers (void)
1026 GList *plugins, *p, *features, *f;
1028 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1030 for (p = plugins; p; p = p->next) {
1031 GstPlugin *plugin = (GstPlugin *) (p->data);
1034 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1035 gst_plugin_get_name (plugin));
1037 for (f = features; f; f = f->next) {
1038 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1040 if (GST_IS_ELEMENT_FACTORY (feature)) {
1041 GstElementFactory *factory;
1042 GstElement *element;
1044 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1046 g_print ("element plugin %s couldn't be loaded\n",
1047 gst_plugin_get_name (plugin));
1051 element = gst_element_factory_create (factory, NULL);
1053 g_print ("couldn't construct element for %s for some reason\n",
1054 GST_OBJECT_NAME (factory));
1055 gst_object_unref (factory);
1059 if (GST_IS_URI_HANDLER (element)) {
1060 const gchar *const *uri_protocols;
1064 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1077 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1078 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1080 g_print ("%s (%s, rank %u): %s\n",
1081 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1082 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1088 gst_object_unref (element);
1089 gst_object_unref (factory);
1093 gst_plugin_feature_list_free (features);
1096 gst_plugin_list_free (plugins);
1100 print_plugin_info (GstPlugin * plugin)
1102 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1103 const gchar *filename = gst_plugin_get_filename (plugin);
1105 n_print ("Plugin Details:\n");
1106 n_print (" %-25s%s\n", "Name", gst_plugin_get_name (plugin));
1107 n_print (" %-25s%s\n", "Description", gst_plugin_get_description (plugin));
1108 n_print (" %-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1109 n_print (" %-25s%s\n", "Version", gst_plugin_get_version (plugin));
1110 n_print (" %-25s%s\n", "License", gst_plugin_get_license (plugin));
1111 n_print (" %-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1113 if (release_date != NULL) {
1114 const gchar *tz = "(UTC)";
1117 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1118 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1119 str = g_strdup (release_date);
1120 sep = strstr (str, "T");
1123 sep = strstr (sep + 1, "Z");
1129 n_print (" %-25s%s%s\n", "Source release date", str, tz);
1132 n_print (" %-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1133 n_print (" %-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1138 print_plugin_features (GstPlugin * plugin)
1140 GList *features, *origlist;
1141 gint num_features = 0;
1142 gint num_elements = 0;
1143 gint num_tracers = 0;
1144 gint num_typefinders = 0;
1145 gint num_devproviders = 0;
1148 origlist = features =
1149 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1150 gst_plugin_get_name (plugin));
1153 GstPluginFeature *feature;
1155 feature = GST_PLUGIN_FEATURE (features->data);
1157 if (GST_IS_ELEMENT_FACTORY (feature)) {
1158 GstElementFactory *factory;
1160 factory = GST_ELEMENT_FACTORY (feature);
1161 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1162 gst_element_factory_get_metadata (factory,
1163 GST_ELEMENT_METADATA_LONGNAME));
1165 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1166 GstTypeFindFactory *factory;
1167 const gchar *const *extensions;
1169 factory = GST_TYPE_FIND_FACTORY (feature);
1170 extensions = gst_type_find_factory_get_extensions (factory);
1174 g_print (" %s: %s: ", gst_plugin_get_name (plugin),
1175 gst_plugin_feature_get_name (feature));
1176 while (extensions[i]) {
1177 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1182 g_print (" %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1183 gst_plugin_feature_get_name (feature));
1186 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1187 GstDeviceProviderFactory *factory;
1189 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1190 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1191 gst_device_provider_factory_get_metadata (factory,
1192 GST_ELEMENT_METADATA_LONGNAME));
1194 } else if (GST_IS_TRACER_FACTORY (feature)) {
1195 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1196 g_type_name (G_OBJECT_TYPE (feature)));
1198 } else if (feature) {
1199 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1200 g_type_name (G_OBJECT_TYPE (feature)));
1204 features = g_list_next (features);
1207 gst_plugin_feature_list_free (origlist);
1210 n_print (" %d features:\n", num_features);
1211 if (num_elements > 0)
1212 n_print (" +-- %d elements\n", num_elements);
1213 if (num_typefinders > 0)
1214 n_print (" +-- %d typefinders\n", num_typefinders);
1215 if (num_devproviders > 0)
1216 n_print (" +-- %d device providers\n", num_devproviders);
1217 if (num_tracers > 0)
1218 n_print (" +-- %d tracers\n", num_tracers);
1220 n_print (" +-- %d other objects\n", num_other);
1226 print_element_features (const gchar * element_name)
1228 GstPluginFeature *feature;
1230 /* FIXME implement other pretty print function for these */
1231 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1232 GST_TYPE_TYPE_FIND_FACTORY);
1234 n_print ("%s: a typefind function\n", element_name);
1237 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1238 GST_TYPE_TRACER_FACTORY);
1240 n_print ("%s: a tracer module\n", element_name);
1248 print_element_info (GstElementFactory * factory, gboolean print_names)
1250 GstElement *element;
1255 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1259 g_print ("element plugin couldn't be loaded\n");
1263 element = gst_element_factory_create (factory, NULL);
1265 gst_object_unref (factory);
1266 g_print ("couldn't construct element for some reason\n");
1271 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1275 print_factory_details_info (factory);
1277 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1279 print_plugin_info (plugin);
1280 gst_object_unref (plugin);
1283 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1284 print_interfaces (G_OBJECT_TYPE (element));
1286 print_pad_templates_info (element, factory);
1287 print_element_flag_info (element);
1288 print_implementation_info (element);
1289 print_clocking_info (element);
1290 print_uri_handler_info (element);
1291 print_pad_info (element);
1292 print_element_properties_info (element);
1293 print_signal_info (element);
1294 print_children_info (element);
1295 print_preset_list (element);
1297 gst_object_unref (element);
1298 gst_object_unref (factory);
1306 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1308 GstPadDirection direction;
1309 const gchar *type_name;
1311 const GList *static_templates, *l;
1312 GstCaps *caps = NULL;
1316 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1317 g_return_if_fail (klass != NULL);
1319 if (strstr (klass, "Demuxer") ||
1320 strstr (klass, "Decoder") ||
1321 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1322 type_name = "decoder";
1323 direction = GST_PAD_SINK;
1324 } else if (strstr (klass, "Muxer") ||
1325 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1326 type_name = "encoder";
1327 direction = GST_PAD_SRC;
1332 /* decoder/demuxer sink pads should always be static and there should only
1333 * be one, the same applies to encoders/muxers and source pads */
1334 static_templates = gst_element_factory_get_static_pad_templates (factory);
1335 for (l = static_templates; l != NULL; l = l->next) {
1336 GstStaticPadTemplate *tmpl = NULL;
1338 tmpl = (GstStaticPadTemplate *) l->data;
1339 if (tmpl->direction == direction) {
1340 caps = gst_static_pad_template_get_caps (tmpl);
1346 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1347 type_name, GST_OBJECT_NAME (factory));
1351 caps = gst_caps_make_writable (caps);
1352 num = gst_caps_get_size (caps);
1353 for (i = 0; i < num; ++i) {
1357 s = gst_caps_get_structure (caps, i);
1358 /* remove fields that are almost always just MIN-MAX of some sort
1359 * in order to make the caps look less messy */
1360 gst_structure_remove_field (s, "pixel-aspect-ratio");
1361 gst_structure_remove_field (s, "framerate");
1362 gst_structure_remove_field (s, "channels");
1363 gst_structure_remove_field (s, "width");
1364 gst_structure_remove_field (s, "height");
1365 gst_structure_remove_field (s, "rate");
1366 gst_structure_remove_field (s, "depth");
1367 gst_structure_remove_field (s, "clock-rate");
1368 s_str = gst_structure_to_string (s);
1369 g_print ("%s-%s\n", type_name, s_str);
1372 gst_caps_unref (caps);
1376 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1378 const gchar *const *protocols;
1380 protocols = gst_element_factory_get_uri_protocols (factory);
1381 if (protocols != NULL && *protocols != NULL) {
1382 switch (gst_element_factory_get_uri_type (factory)) {
1384 while (*protocols != NULL) {
1385 g_print ("urisink-%s\n", *protocols);
1390 while (*protocols != NULL) {
1391 g_print ("urisource-%s\n", *protocols);
1402 print_plugin_automatic_install_info (GstPlugin * plugin)
1404 GList *features, *l;
1406 /* not interested in typefind factories, only element factories */
1407 features = gst_registry_get_feature_list (gst_registry_get (),
1408 GST_TYPE_ELEMENT_FACTORY);
1410 for (l = features; l != NULL; l = l->next) {
1411 GstPluginFeature *feature;
1412 GstPlugin *feature_plugin;
1414 feature = GST_PLUGIN_FEATURE (l->data);
1416 /* only interested in the ones that are in the plugin we just loaded */
1417 feature_plugin = gst_plugin_feature_get_plugin (feature);
1418 if (feature_plugin == plugin) {
1419 GstElementFactory *factory;
1421 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1423 factory = GST_ELEMENT_FACTORY (feature);
1424 print_plugin_automatic_install_info_protocols (factory);
1425 print_plugin_automatic_install_info_codecs (factory);
1428 gst_object_unref (feature_plugin);
1431 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1432 g_list_free (features);
1436 print_all_plugin_automatic_install_info (void)
1438 GList *plugins, *orig_plugins;
1440 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1444 plugin = (GstPlugin *) (plugins->data);
1445 plugins = g_list_next (plugins);
1447 print_plugin_automatic_install_info (plugin);
1449 gst_plugin_list_free (orig_plugins);
1453 main (int argc, char *argv[])
1455 gboolean print_all = FALSE;
1456 gboolean do_print_blacklist = FALSE;
1457 gboolean plugin_name = FALSE;
1458 gboolean print_aii = FALSE;
1459 gboolean uri_handlers = FALSE;
1460 gboolean check_exists = FALSE;
1461 gchar *min_version = NULL;
1462 guint minver_maj = GST_VERSION_MAJOR;
1463 guint minver_min = GST_VERSION_MINOR;
1464 guint minver_micro = 0;
1465 #ifndef GST_DISABLE_OPTION_PARSING
1466 GOptionEntry options[] = {
1467 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1468 N_("Print all elements"), NULL},
1469 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1470 N_("Print list of blacklisted files"), NULL},
1471 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1472 N_("Print a machine-parsable list of features the specified plugin "
1473 "or all plugins provide.\n "
1474 "Useful in connection with external automatic plugin "
1475 "installation mechanisms"), NULL},
1476 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1477 N_("List the plugin contents"), NULL},
1478 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1479 N_("Check if the specified element or plugin exists"), NULL},
1480 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1482 ("When checking if an element or plugin exists, also check that its "
1483 "version is at least the version specified"), NULL},
1484 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1486 ("Print supported URI schemes, with the elements that implement them"),
1488 GST_TOOLS_GOPTION_VERSION,
1491 GOptionContext *ctx;
1495 setlocale (LC_ALL, "");
1498 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1499 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1500 textdomain (GETTEXT_PACKAGE);
1503 /* avoid glib warnings when inspecting deprecated properties */
1504 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
1506 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1508 #ifndef GST_DISABLE_OPTION_PARSING
1509 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1510 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1511 g_option_context_add_group (ctx, gst_init_get_option_group ());
1512 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1513 g_printerr ("Error initializing: %s\n", err->message);
1514 g_clear_error (&err);
1515 g_option_context_free (ctx);
1518 g_option_context_free (ctx);
1520 gst_init (&argc, &argv);
1523 gst_tools_print_version ();
1525 if (print_all && argc > 1) {
1526 g_printerr ("-a requires no extra arguments\n");
1530 if (uri_handlers && argc > 1) {
1531 g_printerr ("-u requires no extra arguments\n");
1535 /* --atleast-version implies --exists */
1536 if (min_version != NULL) {
1537 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1538 &minver_micro) < 2) {
1539 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1543 check_exists = TRUE;
1550 g_printerr ("--exists requires an extra command line argument\n");
1554 GstPluginFeature *feature;
1556 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1557 if (feature != NULL && gst_plugin_feature_check_version (feature,
1558 minver_maj, minver_min, minver_micro)) {
1565 gst_object_unref (feature);
1567 /* FIXME: support checking for plugins too */
1568 g_printerr ("Checking for plugins is not supported yet\n");
1575 /* if no arguments, print out list of elements */
1577 print_all_uri_handlers ();
1578 } else if (argc == 1 || print_all) {
1579 if (do_print_blacklist)
1583 print_all_plugin_automatic_install_info ();
1585 print_element_list (print_all);
1588 /* else we try to get a factory */
1589 GstElementFactory *factory;
1591 const char *arg = argv[argc - 1];
1595 factory = gst_element_factory_find (arg);
1597 /* if there's a factory, print out the info */
1599 retval = print_element_info (factory, print_all);
1600 gst_object_unref (factory);
1602 retval = print_element_features (arg);
1608 /* otherwise check if it's a plugin */
1610 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1612 /* if there is such a plugin, print out info */
1615 print_plugin_automatic_install_info (plugin);
1617 print_plugin_info (plugin);
1618 print_plugin_features (plugin);
1621 GError *error = NULL;
1623 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1624 plugin = gst_plugin_load_file (arg, &error);
1628 print_plugin_automatic_install_info (plugin);
1630 print_plugin_info (plugin);
1631 print_plugin_features (plugin);
1634 g_printerr (_("Could not load plugin file: %s\n"), error->message);
1635 g_clear_error (&error);
1639 g_printerr (_("No such element or plugin '%s'\n"), arg);