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
33 #include <gst/gst_private.h> /* for internal Factories */
37 #include <glib/gprintf.h>
39 static char *_name = NULL;
40 static int indent = 0;
42 static int print_element_info (GstPluginFeature * feature,
43 gboolean print_names);
44 static int print_typefind_info (GstPluginFeature * feature,
45 gboolean print_names);
46 static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
48 #define push_indent() push_indent_n(1)
49 #define pop_indent() push_indent_n(-1)
50 #define pop_indent_n(n) push_indent_n(-n)
55 g_assert (n > 0 || indent > 0);
64 n_print (const char *format, ...)
70 g_print ("%s", _name);
72 for (i = 0; i < indent; ++i)
75 va_start (args, format);
76 g_vprintf (format, args);
81 print_field (GQuark field, const GValue * value, gpointer pfx)
83 gchar *str = gst_value_serialize (value);
85 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
91 print_caps (const GstCaps * caps, const gchar * pfx)
95 g_return_if_fail (caps != NULL);
97 if (gst_caps_is_any (caps)) {
98 n_print ("%sANY\n", pfx);
101 if (gst_caps_is_empty (caps)) {
102 n_print ("%sEMPTY\n", pfx);
106 for (i = 0; i < gst_caps_get_size (caps); i++) {
107 GstStructure *structure = gst_caps_get_structure (caps, i);
108 GstCapsFeatures *features = gst_caps_get_features (caps, i);
110 if (features && (gst_caps_features_is_any (features) ||
111 !gst_caps_features_is_equal (features,
112 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
113 gchar *features_string = gst_caps_features_to_string (features);
115 n_print ("%s%s(%s)\n", pfx, gst_structure_get_name (structure),
117 g_free (features_string);
119 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
121 gst_structure_foreach (structure, print_field, (gpointer) pfx);
126 get_rank_name (char *s, gint rank)
128 static const int ranks[4] = {
129 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
131 static const char *rank_names[4] = { "none", "marginal", "secondary",
138 for (i = 0; i < 4; i++) {
139 if (rank == ranks[i])
140 return rank_names[i];
141 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
146 sprintf (s, "%s %c %d", rank_names[best_i],
147 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
153 print_factory_details_info (GstElementFactory * factory)
159 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
160 n_print ("Factory Details:\n");
163 n_print ("%-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
165 keys = gst_element_factory_get_metadata_keys (factory);
167 for (k = keys; *k != NULL; ++k) {
171 val = gst_element_factory_get_metadata (factory, key);
172 key[0] = g_ascii_toupper (key[0]);
173 n_print ("%-25s%s\n", key, val);
182 print_hierarchy (GType type, gint level, gint * maxlevel)
187 parent = g_type_parent (type);
189 *maxlevel = *maxlevel + 1;
193 print_hierarchy (parent, level, maxlevel);
196 g_print ("%s", _name);
198 for (i = 1; i < *maxlevel - level; i++)
200 if (*maxlevel - level)
203 g_print ("%s\n", g_type_name (type));
210 print_interfaces (GType type)
213 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
217 n_print (_("Implemented Interfaces:\n"));
221 n_print ("%s\n", g_type_name (*iface));
232 flags_to_string (GFlagsValue * vals, guint flags)
237 /* first look for an exact match and count the number of values */
238 for (i = 0; vals[i].value_name != NULL; ++i) {
239 if (vals[i].value == flags)
240 return g_strdup (vals[i].value_nick);
243 s = g_string_new (NULL);
245 /* we assume the values are sorted from lowest to highest value */
249 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
251 g_string_append_c (s, '+');
252 g_string_append (s, vals[i].value_nick);
253 flags_left -= vals[i].value;
260 g_string_assign (s, "(none)");
262 return g_string_free (s, FALSE);
265 #define KNOWN_PARAM_FLAGS \
266 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
267 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
268 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
269 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
270 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
272 /* obj will be NULL if we're printing properties of pad template pads */
274 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
277 GParamSpec **property_specs;
278 guint num_properties, i;
282 property_specs = g_object_class_list_properties (obj_class, &num_properties);
283 n_print ("%s:\n", desc);
287 for (i = 0; i < num_properties; i++) {
288 GValue value = { 0, };
289 GParamSpec *param = property_specs[i];
290 GType owner_type = param->owner_type;
292 /* We're printing pad properties */
293 if (obj == NULL && (owner_type == G_TYPE_OBJECT
294 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
299 g_value_init (&value, param->value_type);
301 n_print ("%-20s: %s\n", g_param_spec_get_name (param),
302 g_param_spec_get_blurb (param));
308 readable = ! !(param->flags & G_PARAM_READABLE);
309 if (readable && obj != NULL) {
310 g_object_get_property (obj, param->name, &value);
312 /* if we can't read the property value, assume it's set to the default
313 * (which might not be entirely true for sub-classes, but that's an
314 * unlikely corner-case anyway) */
315 g_param_value_set_default (param, &value);
318 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
321 if (param->flags & G_PARAM_WRITABLE) {
322 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
325 if (param->flags & G_PARAM_DEPRECATED) {
326 g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
329 if (param->flags & GST_PARAM_CONTROLLABLE) {
330 g_print (", %s", _("controllable"));
333 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
334 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
335 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
336 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
337 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
338 g_print (", %s", _("changeable only in NULL or READY state"));
340 if (param->flags & ~KNOWN_PARAM_FLAGS) {
341 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
342 param->flags & ~KNOWN_PARAM_FLAGS);
346 switch (G_VALUE_TYPE (&value)) {
349 const char *string_val = g_value_get_string (&value);
351 n_print ("String. ");
353 if (string_val == NULL)
354 g_print ("Default: null");
356 g_print ("Default: \"%s\"", string_val);
361 gboolean bool_val = g_value_get_boolean (&value);
363 n_print ("Boolean. Default: %s", bool_val ? "true" : "false");
368 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
370 n_print ("Unsigned Long. Range: %lu - %lu Default: %lu ",
371 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
373 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
374 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
375 g_param_spec_get_name (param));
380 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
382 n_print ("Long. Range: %ld - %ld Default: %ld ",
383 plong->minimum, plong->maximum, g_value_get_long (&value));
385 GST_ERROR ("%s: property '%s' of type long: consider changing to "
386 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
387 g_param_spec_get_name (param));
392 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
394 n_print ("Unsigned Integer. Range: %u - %u Default: %u ",
395 puint->minimum, puint->maximum, g_value_get_uint (&value));
400 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
402 n_print ("Integer. Range: %d - %d Default: %d ",
403 pint->minimum, pint->maximum, g_value_get_int (&value));
408 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
410 n_print ("Unsigned Integer64. Range: %" G_GUINT64_FORMAT " - "
411 "%" G_GUINT64_FORMAT " Default: %" G_GUINT64_FORMAT " ",
412 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
417 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
419 n_print ("Integer64. Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
420 " Default: %" G_GINT64_FORMAT " ",
421 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
426 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
428 n_print ("Float. Range: %15.7g - %15.7g Default: %15.7g ",
429 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
434 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
436 n_print ("Double. Range: %15.7g - %15.7g Default: %15.7g ",
437 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
442 GST_ERROR ("%s: property '%s' of type char: consider changing to "
443 "int/string", G_OBJECT_CLASS_NAME (obj_class),
444 g_param_spec_get_name (param));
447 if (param->value_type == GST_TYPE_CAPS) {
448 const GstCaps *caps = gst_value_get_caps (&value);
451 n_print ("Caps (NULL)");
453 print_caps (caps, " ");
455 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
459 const gchar *value_nick = "";
461 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
462 enum_value = g_value_get_enum (&value);
464 while (values[j].value_name) {
465 if (values[j].value == enum_value)
466 value_nick = values[j].value_nick;
470 n_print ("Enum \"%s\" Default: %d, \"%s\"",
471 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
474 while (values[j].value_name) {
476 n_print (" (%d): %-16s - %s",
477 values[j].value, values[j].value_nick, values[j].value_name);
480 /* g_type_class_unref (ec); */
481 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
482 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
486 vals = pflags->flags_class->values;
488 cur = flags_to_string (vals, g_value_get_flags (&value));
490 n_print ("Flags \"%s\" Default: 0x%08x, \"%s\"",
491 g_type_name (G_VALUE_TYPE (&value)),
492 g_value_get_flags (&value), cur);
494 while (vals[0].value_name) {
496 n_print (" (0x%08x): %-16s - %s",
497 vals[0].value, vals[0].value_nick, vals[0].value_name);
502 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
503 n_print ("Object of type \"%s\"", g_type_name (param->value_type));
504 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
505 n_print ("Boxed pointer of type \"%s\"",
506 g_type_name (param->value_type));
507 if (param->value_type == GST_TYPE_STRUCTURE) {
508 const GstStructure *s = gst_value_get_structure (&value);
510 gst_structure_foreach (s, print_field,
513 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
514 if (param->value_type != G_TYPE_POINTER) {
515 n_print ("Pointer of type \"%s\".",
516 g_type_name (param->value_type));
518 n_print ("Pointer.");
520 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
521 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
523 if (pvarray->element_spec) {
524 n_print ("Array of GValues of type \"%s\"",
525 g_type_name (pvarray->element_spec->value_type));
527 n_print ("Array of GValues");
529 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
530 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
532 n_print ("Fraction. Range: %d/%d - %d/%d Default: %d/%d ",
533 pfraction->min_num, pfraction->min_den,
534 pfraction->max_num, pfraction->max_den,
535 gst_value_get_fraction_numerator (&value),
536 gst_value_get_fraction_denominator (&value));
537 } else if (param->value_type == GST_TYPE_ARRAY) {
538 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
540 if (parray->element_spec) {
541 n_print ("GstValueArray of GValues of type \"%s\"",
542 g_type_name (parray->element_spec->value_type));
544 n_print ("GstValueArray of GValues");
547 n_print ("Unknown type %ld \"%s\"",
548 (glong) param->value_type, g_type_name (param->value_type));
553 g_print (" Write only\n");
559 g_value_reset (&value);
561 if (num_properties == 0)
566 g_free (property_specs);
570 print_element_properties_info (GstElement * element)
573 print_object_properties_info (G_OBJECT (element),
574 G_OBJECT_GET_CLASS (element), "Element Properties");
578 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
581 GstStaticPadTemplate *padtemplate;
582 GstPadTemplate *tmpl;
584 n_print ("Pad Templates:\n");
588 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
593 pads = gst_element_factory_get_static_pad_templates (factory);
595 padtemplate = (GstStaticPadTemplate *) (pads->data);
596 pads = g_list_next (pads);
598 if (padtemplate->direction == GST_PAD_SRC)
599 n_print ("SRC template: '%s'\n", padtemplate->name_template);
600 else if (padtemplate->direction == GST_PAD_SINK)
601 n_print ("SINK template: '%s'\n", padtemplate->name_template);
603 n_print ("UNKNOWN template: '%s'\n", padtemplate->name_template);
607 if (padtemplate->presence == GST_PAD_ALWAYS)
608 n_print ("Availability: Always\n");
609 else if (padtemplate->presence == GST_PAD_SOMETIMES)
610 n_print ("Availability: Sometimes\n");
611 else if (padtemplate->presence == GST_PAD_REQUEST) {
612 n_print ("Availability: On request\n");
614 n_print ("Availability: UNKNOWN\n");
616 if (padtemplate->static_caps.string) {
617 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
619 n_print ("Capabilities:\n");
622 print_caps (caps, ""); // FIXME
625 gst_caps_unref (caps);
628 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
629 padtemplate->name_template);
631 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
633 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
636 pad_klass = g_type_class_ref (pad_type);
637 n_print ("Type: %s\n", g_type_name (pad_type));
638 print_object_properties_info (NULL, pad_klass, "Pad Properties");
639 g_type_class_unref (pad_klass);
654 print_clocking_info (GstElement * element)
656 gboolean requires_clock, provides_clock;
659 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
661 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
663 if (!requires_clock && !provides_clock) {
665 n_print ("Element has no clocking capabilities.\n");
670 n_print ("Clocking Interaction:\n");
674 if (requires_clock) {
675 n_print ("element requires a clock\n");
678 if (provides_clock) {
681 clock = gst_element_get_clock (element);
683 n_print ("element provides a clock: %s\n", GST_OBJECT_NAME (clock));
684 gst_object_unref (clock);
686 n_print ("element is supposed to provide a clock but returned NULL\n");
693 print_uri_handler_info (GstElement * element)
695 if (GST_IS_URI_HANDLER (element)) {
696 const gchar *const *uri_protocols;
697 const gchar *uri_type;
699 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
701 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
705 uri_type = "unknown";
707 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
710 n_print ("URI handling capabilities:\n");
714 n_print ("Element can act as %s.\n", uri_type);
716 if (uri_protocols && *uri_protocols) {
717 n_print ("Supported URI protocols:\n");
719 for (; *uri_protocols != NULL; uri_protocols++)
720 n_print ("%s\n", *uri_protocols);
723 n_print ("No supported URI protocols\n");
728 n_print ("Element has no URI handling capabilities.\n");
733 print_pad_info (GstElement * element)
743 if (!element->numpads) {
748 pads = element->pads;
753 pad = GST_PAD (pads->data);
754 pads = g_list_next (pads);
756 name = gst_pad_get_name (pad);
757 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
758 n_print ("SRC: '%s'\n", name);
759 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
760 n_print ("SINK: '%s'\n", name);
762 n_print ("UNKNOWN: '%s'\n", name);
766 if (pad->padtemplate) {
768 n_print ("Pad Template: '%s'\n", pad->padtemplate->name_template);
772 caps = gst_pad_get_current_caps (pad);
774 n_print ("Capabilities:\n");
776 print_caps (caps, ""); // FIXME
778 gst_caps_unref (caps);
787 has_sometimes_template (GstElement * element)
789 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
792 for (l = klass->padtemplates; l != NULL; l = l->next) {
793 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
801 gtype_needs_ptr_marker (GType type)
803 if (type == G_TYPE_POINTER)
806 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
807 || G_TYPE_IS_OBJECT (type))
814 print_signal_info (GstElement * element)
816 /* Signals/Actions Block */
820 GSignalQuery *query = NULL;
822 GSList *found_signals, *l;
824 for (k = 0; k < 2; k++) {
825 found_signals = NULL;
827 /* For elements that have sometimes pads, also list a few useful GstElement
828 * signals. Put these first, so element-specific ones come later. */
829 if (k == 0 && has_sometimes_template (element)) {
830 query = g_new0 (GSignalQuery, 1);
831 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
832 found_signals = g_slist_append (found_signals, query);
833 query = g_new0 (GSignalQuery, 1);
834 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
835 found_signals = g_slist_append (found_signals, query);
836 query = g_new0 (GSignalQuery, 1);
837 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
839 found_signals = g_slist_append (found_signals, query);
842 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
843 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
846 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
849 signals = g_signal_list_ids (type, &nsignals);
850 for (i = 0; i < nsignals; i++) {
851 query = g_new0 (GSignalQuery, 1);
852 g_signal_query (signals[i], query);
854 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
855 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
856 found_signals = g_slist_append (found_signals, query);
867 n_print ("Element Signals:\n");
869 n_print ("Element Actions:\n");
874 for (l = found_signals; l; l = l->next) {
879 query = (GSignalQuery *) l->data;
880 indent_len = strlen (query->signal_name) +
881 strlen (g_type_name (query->return_type)) + 24;
883 if (gtype_needs_ptr_marker (query->return_type)) {
890 indent = g_new0 (gchar, indent_len + 1);
891 memset (indent, ' ', indent_len);
893 n_print (" \"%s\" : %s %suser_function (%s* object",
894 query->signal_name, g_type_name (query->return_type), pmark,
897 for (j = 0; j < query->n_params; j++) {
898 const gchar *type_name, *asterisk;
900 type_name = g_type_name (query->param_types[j]);
901 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
904 n_print ("%s%s%s arg%d", indent, type_name, asterisk, j);
909 n_print ("%sgpointer user_data);\n", indent);
917 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
918 g_slist_free (found_signals);
924 print_children_info (GstElement * element)
928 if (!GST_IS_BIN (element))
931 children = (GList *) GST_BIN (element)->children;
934 n_print ("Children:\n");
938 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
939 children = g_list_next (children);
944 print_preset_list (GstElement * element)
946 gchar **presets, **preset;
948 if (!GST_IS_PRESET (element))
951 presets = gst_preset_get_preset_names (GST_PRESET (element));
952 if (presets && *presets) {
954 n_print ("Presets:\n");
955 for (preset = presets; *preset; preset++) {
956 n_print (" \"%s\"\n", *preset);
958 g_strfreev (presets);
963 print_blacklist (void)
965 GList *plugins, *cur;
968 g_print ("%s\n", _("Blacklisted files:"));
970 plugins = gst_registry_get_plugin_list (gst_registry_get ());
971 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
972 GstPlugin *plugin = (GstPlugin *) (cur->data);
973 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
974 g_print (" %s\n", gst_plugin_get_name (plugin));
980 g_print (_("Total count: "));
981 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
984 gst_plugin_list_free (plugins);
988 print_typefind_extensions (const gchar * const *extensions)
992 while (extensions[i]) {
993 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
999 print_element_list (gboolean print_all, gchar * ftypes)
1001 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1002 GList *plugins, *orig_plugins;
1003 gchar **types = NULL;
1008 types = g_strsplit (ftypes, "/", -1);
1009 for (i = 0; types[i]; i++)
1010 *types[i] = g_ascii_toupper (*types[i]);
1014 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1016 GList *features, *orig_features;
1019 plugin = (GstPlugin *) (plugins->data);
1020 plugins = g_list_next (plugins);
1023 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1028 orig_features = features =
1029 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1030 gst_plugin_get_name (plugin));
1032 GstPluginFeature *feature;
1034 if (G_UNLIKELY (features->data == NULL))
1036 feature = GST_PLUGIN_FEATURE (features->data);
1039 if (GST_IS_ELEMENT_FACTORY (feature)) {
1041 GstElementFactory *factory;
1043 factory = GST_ELEMENT_FACTORY (feature);
1046 gboolean all_found = TRUE;
1049 gst_element_factory_get_metadata (factory,
1050 GST_ELEMENT_METADATA_KLASS);
1051 for (i = 0; types[i]; i++) {
1052 if (!strstr (klass, types[i])) {
1062 print_element_info (feature, TRUE);
1064 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1065 GST_OBJECT_NAME (factory),
1066 gst_element_factory_get_metadata (factory,
1067 GST_ELEMENT_METADATA_LONGNAME));
1068 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1069 GstTypeFindFactory *factory;
1070 const gchar *const *extensions;
1074 factory = GST_TYPE_FIND_FACTORY (feature);
1076 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1077 gst_plugin_feature_get_name (feature));
1079 extensions = gst_type_find_factory_get_extensions (factory);
1080 if (extensions != NULL) {
1082 print_typefind_extensions (extensions);
1087 g_print ("no extensions\n");
1093 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1094 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1098 features = g_list_next (features);
1101 gst_plugin_feature_list_free (orig_features);
1104 gst_plugin_list_free (orig_plugins);
1108 g_print (_("Total count: "));
1109 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1110 if (blacklistcount) {
1112 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1113 blacklistcount), blacklistcount);
1114 g_print (" not shown)");
1117 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1122 print_all_uri_handlers (void)
1124 GList *plugins, *p, *features, *f;
1126 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1128 for (p = plugins; p; p = p->next) {
1129 GstPlugin *plugin = (GstPlugin *) (p->data);
1132 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1133 gst_plugin_get_name (plugin));
1135 for (f = features; f; f = f->next) {
1136 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1138 if (GST_IS_ELEMENT_FACTORY (feature)) {
1139 GstElementFactory *factory;
1140 GstElement *element;
1142 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1144 g_print ("element plugin %s couldn't be loaded\n",
1145 gst_plugin_get_name (plugin));
1149 element = gst_element_factory_create (factory, NULL);
1151 g_print ("couldn't construct element for %s for some reason\n",
1152 GST_OBJECT_NAME (factory));
1153 gst_object_unref (factory);
1157 if (GST_IS_URI_HANDLER (element)) {
1158 const gchar *const *uri_protocols;
1162 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1175 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1176 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1178 g_print ("%s (%s, rank %u): %s\n",
1179 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1180 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1186 gst_object_unref (element);
1187 gst_object_unref (factory);
1191 gst_plugin_feature_list_free (features);
1194 gst_plugin_list_free (plugins);
1198 print_plugin_info (GstPlugin * plugin)
1200 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1201 const gchar *filename = gst_plugin_get_filename (plugin);
1203 n_print ("Plugin Details:\n");
1207 n_print ("%-25s%s\n", "Name", gst_plugin_get_name (plugin));
1208 n_print ("%-25s%s\n", "Description", gst_plugin_get_description (plugin));
1209 n_print ("%-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1210 n_print ("%-25s%s\n", "Version", gst_plugin_get_version (plugin));
1211 n_print ("%-25s%s\n", "License", gst_plugin_get_license (plugin));
1212 n_print ("%-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1214 if (release_date != NULL) {
1215 const gchar *tz = "(UTC)";
1218 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1219 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1220 str = g_strdup (release_date);
1221 sep = strstr (str, "T");
1224 sep = strstr (sep + 1, "Z");
1230 n_print ("%-25s%s%s\n", "Source release date", str, tz);
1233 n_print ("%-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1234 n_print ("%-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1242 print_plugin_features (GstPlugin * plugin)
1244 GList *features, *origlist;
1245 gint num_features = 0;
1246 gint num_elements = 0;
1247 gint num_tracers = 0;
1248 gint num_typefinders = 0;
1249 gint num_devproviders = 0;
1252 origlist = features =
1253 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1254 gst_plugin_get_name (plugin));
1257 GstPluginFeature *feature;
1259 feature = GST_PLUGIN_FEATURE (features->data);
1261 if (GST_IS_ELEMENT_FACTORY (feature)) {
1262 GstElementFactory *factory;
1264 factory = GST_ELEMENT_FACTORY (feature);
1265 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1266 gst_element_factory_get_metadata (factory,
1267 GST_ELEMENT_METADATA_LONGNAME));
1269 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1270 GstTypeFindFactory *factory;
1271 const gchar *const *extensions;
1273 factory = GST_TYPE_FIND_FACTORY (feature);
1274 extensions = gst_type_find_factory_get_extensions (factory);
1278 g_print (" %s: %s: ", gst_plugin_get_name (plugin),
1279 gst_plugin_feature_get_name (feature));
1280 while (extensions[i]) {
1281 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1286 g_print (" %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1287 gst_plugin_feature_get_name (feature));
1290 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1291 GstDeviceProviderFactory *factory;
1293 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1294 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1295 gst_device_provider_factory_get_metadata (factory,
1296 GST_ELEMENT_METADATA_LONGNAME));
1298 } else if (GST_IS_TRACER_FACTORY (feature)) {
1299 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1300 g_type_name (G_OBJECT_TYPE (feature)));
1302 } else if (feature) {
1303 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1304 g_type_name (G_OBJECT_TYPE (feature)));
1308 features = g_list_next (features);
1311 gst_plugin_feature_list_free (origlist);
1314 n_print (" %d features:\n", num_features);
1315 if (num_elements > 0)
1316 n_print (" +-- %d elements\n", num_elements);
1317 if (num_typefinders > 0)
1318 n_print (" +-- %d typefinders\n", num_typefinders);
1319 if (num_devproviders > 0)
1320 n_print (" +-- %d device providers\n", num_devproviders);
1321 if (num_tracers > 0)
1322 n_print (" +-- %d tracers\n", num_tracers);
1324 n_print (" +-- %d other objects\n", num_other);
1330 print_feature_info (const gchar * feature_name, gboolean print_all)
1332 GstPluginFeature *feature;
1333 GstRegistry *registry = gst_registry_get ();
1336 if ((feature = gst_registry_find_feature (registry, feature_name,
1337 GST_TYPE_ELEMENT_FACTORY))) {
1338 ret = print_element_info (feature, print_all);
1341 if ((feature = gst_registry_find_feature (registry, feature_name,
1342 GST_TYPE_TYPE_FIND_FACTORY))) {
1343 ret = print_typefind_info (feature, print_all);
1346 if ((feature = gst_registry_find_feature (registry, feature_name,
1347 GST_TYPE_TRACER_FACTORY))) {
1348 ret = print_tracer_info (feature, print_all);
1352 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1357 gst_object_unref (feature);
1362 print_element_info (GstPluginFeature * feature, gboolean print_names)
1364 GstElementFactory *factory;
1365 GstElement *element;
1369 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1371 g_print ("element plugin couldn't be loaded\n");
1375 element = gst_element_factory_create (factory, NULL);
1377 gst_object_unref (factory);
1378 g_print ("couldn't construct element for some reason\n");
1383 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1387 print_factory_details_info (factory);
1389 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1391 print_plugin_info (plugin);
1392 gst_object_unref (plugin);
1395 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1396 print_interfaces (G_OBJECT_TYPE (element));
1398 print_pad_templates_info (element, factory);
1399 print_clocking_info (element);
1400 print_uri_handler_info (element);
1401 print_pad_info (element);
1402 print_element_properties_info (element);
1403 print_signal_info (element);
1404 print_children_info (element);
1405 print_preset_list (element);
1407 gst_object_unref (element);
1408 gst_object_unref (factory);
1414 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1416 GstTypeFindFactory *factory;
1421 const gchar *const *extensions;
1423 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1425 g_print ("typefind plugin couldn't be loaded\n");
1430 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1434 n_print ("Factory Details:\n");
1435 rank = gst_plugin_feature_get_rank (feature);
1436 n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
1437 n_print (" %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
1438 caps = gst_type_find_factory_get_caps (factory);
1440 gchar *caps_str = gst_caps_to_string (factory->caps);
1442 n_print (" %-25s%s\n", "Caps", caps_str);
1445 extensions = gst_type_find_factory_get_extensions (factory);
1447 n_print (" %-25s", "Extensions");
1448 print_typefind_extensions (extensions);
1453 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1455 print_plugin_info (plugin);
1456 gst_object_unref (plugin);
1459 gst_object_unref (factory);
1465 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1467 GstTracerFactory *factory;
1472 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1474 g_print ("tracer plugin couldn't be loaded\n");
1478 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1480 gst_object_unref (factory);
1481 g_print ("couldn't construct tracer for some reason\n");
1486 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1490 n_print ("Factory Details:\n");
1491 n_print (" %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
1494 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1496 print_plugin_info (plugin);
1497 gst_object_unref (plugin);
1500 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1501 print_interfaces (G_OBJECT_TYPE (tracer));
1503 /* TODO: list what hooks it registers
1504 * - the data is available in gsttracerutils, we need to iterate the
1505 * _priv_tracers hashtable for each probe and then check the list of hooks
1506 * for each probe whether hook->tracer == tracer :/
1509 /* TODO: list what records it emits
1510 * - in class_init tracers can create GstTracerRecord instances
1511 * - those only get logged right now and there is no association with the
1512 * tracer that created them
1513 * - we'd need to add them to GstTracerFactory
1514 * gst_tracer_class_add_record (klass, record);
1515 * - needs work in gstregistrychunks.
1518 gst_object_unref (tracer);
1519 gst_object_unref (factory);
1525 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1527 GstPadDirection direction;
1528 const gchar *type_name;
1530 const GList *static_templates, *l;
1531 GstCaps *caps = NULL;
1535 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1536 g_return_if_fail (klass != NULL);
1538 if (strstr (klass, "Demuxer") ||
1539 strstr (klass, "Decoder") ||
1540 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1541 type_name = "decoder";
1542 direction = GST_PAD_SINK;
1543 } else if (strstr (klass, "Muxer") ||
1544 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1545 type_name = "encoder";
1546 direction = GST_PAD_SRC;
1551 /* decoder/demuxer sink pads should always be static and there should only
1552 * be one, the same applies to encoders/muxers and source pads */
1553 static_templates = gst_element_factory_get_static_pad_templates (factory);
1554 for (l = static_templates; l != NULL; l = l->next) {
1555 GstStaticPadTemplate *tmpl = NULL;
1557 tmpl = (GstStaticPadTemplate *) l->data;
1558 if (tmpl->direction == direction) {
1559 caps = gst_static_pad_template_get_caps (tmpl);
1565 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1566 type_name, GST_OBJECT_NAME (factory));
1570 caps = gst_caps_make_writable (caps);
1571 num = gst_caps_get_size (caps);
1572 for (i = 0; i < num; ++i) {
1576 s = gst_caps_get_structure (caps, i);
1577 /* remove fields that are almost always just MIN-MAX of some sort
1578 * in order to make the caps look less messy */
1579 gst_structure_remove_field (s, "pixel-aspect-ratio");
1580 gst_structure_remove_field (s, "framerate");
1581 gst_structure_remove_field (s, "channels");
1582 gst_structure_remove_field (s, "width");
1583 gst_structure_remove_field (s, "height");
1584 gst_structure_remove_field (s, "rate");
1585 gst_structure_remove_field (s, "depth");
1586 gst_structure_remove_field (s, "clock-rate");
1587 s_str = gst_structure_to_string (s);
1588 g_print ("%s-%s\n", type_name, s_str);
1591 gst_caps_unref (caps);
1595 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1597 const gchar *const *protocols;
1599 protocols = gst_element_factory_get_uri_protocols (factory);
1600 if (protocols != NULL && *protocols != NULL) {
1601 switch (gst_element_factory_get_uri_type (factory)) {
1603 while (*protocols != NULL) {
1604 g_print ("urisink-%s\n", *protocols);
1609 while (*protocols != NULL) {
1610 g_print ("urisource-%s\n", *protocols);
1621 print_plugin_automatic_install_info (GstPlugin * plugin)
1623 GList *features, *l;
1625 /* not interested in typefind factories, only element factories */
1626 features = gst_registry_get_feature_list (gst_registry_get (),
1627 GST_TYPE_ELEMENT_FACTORY);
1629 for (l = features; l != NULL; l = l->next) {
1630 GstPluginFeature *feature;
1631 GstPlugin *feature_plugin;
1633 feature = GST_PLUGIN_FEATURE (l->data);
1635 /* only interested in the ones that are in the plugin we just loaded */
1636 feature_plugin = gst_plugin_feature_get_plugin (feature);
1637 if (feature_plugin == plugin) {
1638 GstElementFactory *factory;
1640 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1642 factory = GST_ELEMENT_FACTORY (feature);
1643 print_plugin_automatic_install_info_protocols (factory);
1644 print_plugin_automatic_install_info_codecs (factory);
1647 gst_object_unref (feature_plugin);
1650 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1651 g_list_free (features);
1655 print_all_plugin_automatic_install_info (void)
1657 GList *plugins, *orig_plugins;
1659 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1663 plugin = (GstPlugin *) (plugins->data);
1664 plugins = g_list_next (plugins);
1666 print_plugin_automatic_install_info (plugin);
1668 gst_plugin_list_free (orig_plugins);
1672 main (int argc, char *argv[])
1674 gboolean print_all = FALSE;
1675 gboolean do_print_blacklist = FALSE;
1676 gboolean plugin_name = FALSE;
1677 gboolean print_aii = FALSE;
1678 gboolean uri_handlers = FALSE;
1679 gboolean check_exists = FALSE;
1680 gchar *min_version = NULL;
1681 guint minver_maj = GST_VERSION_MAJOR;
1682 guint minver_min = GST_VERSION_MINOR;
1683 guint minver_micro = 0;
1684 gchar *types = NULL;
1685 #ifndef GST_DISABLE_OPTION_PARSING
1686 GOptionEntry options[] = {
1687 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1688 N_("Print all elements"), NULL},
1689 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1690 N_("Print list of blacklisted files"), NULL},
1691 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1692 N_("Print a machine-parsable list of features the specified plugin "
1693 "or all plugins provide.\n "
1694 "Useful in connection with external automatic plugin "
1695 "installation mechanisms"), NULL},
1696 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1697 N_("List the plugin contents"), NULL},
1698 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1699 N_("A slashes ('/') separated list of types of elements (also known "
1700 "as klass) to list. (unordered)"), NULL},
1701 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1702 N_("Check if the specified element or plugin exists"), NULL},
1703 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1705 ("When checking if an element or plugin exists, also check that its "
1706 "version is at least the version specified"), NULL},
1707 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1709 ("Print supported URI schemes, with the elements that implement them"),
1711 GST_TOOLS_GOPTION_VERSION,
1714 GOptionContext *ctx;
1718 setlocale (LC_ALL, "");
1721 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1722 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1723 textdomain (GETTEXT_PACKAGE);
1726 /* avoid glib warnings when inspecting deprecated properties */
1727 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
1729 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1731 #ifndef GST_DISABLE_OPTION_PARSING
1732 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1733 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1734 g_option_context_add_group (ctx, gst_init_get_option_group ());
1735 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1736 g_printerr ("Error initializing: %s\n", err->message);
1737 g_clear_error (&err);
1738 g_option_context_free (ctx);
1741 g_option_context_free (ctx);
1743 gst_init (&argc, &argv);
1746 gst_tools_print_version ();
1748 if (print_all && argc > 1) {
1749 g_printerr ("-a requires no extra arguments\n");
1753 if (uri_handlers && argc > 1) {
1754 g_printerr ("-u requires no extra arguments\n");
1758 /* --atleast-version implies --exists */
1759 if (min_version != NULL) {
1760 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1761 &minver_micro) < 2) {
1762 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1766 check_exists = TRUE;
1773 g_printerr ("--exists requires an extra command line argument\n");
1777 GstPluginFeature *feature;
1779 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1780 if (feature != NULL && gst_plugin_feature_check_version (feature,
1781 minver_maj, minver_min, minver_micro)) {
1788 gst_object_unref (feature);
1790 /* FIXME: support checking for plugins too */
1791 g_printerr ("Checking for plugins is not supported yet\n");
1798 /* if no arguments, print out list of elements */
1800 print_all_uri_handlers ();
1801 } else if (argc == 1 || print_all) {
1802 if (do_print_blacklist)
1806 print_all_plugin_automatic_install_info ();
1808 print_element_list (print_all, types);
1811 /* else we try to get a factory */
1812 const char *arg = argv[argc - 1];
1816 retval = print_feature_info (arg, print_all);
1819 /* otherwise check if it's a plugin */
1821 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1823 /* if there is such a plugin, print out info */
1826 print_plugin_automatic_install_info (plugin);
1828 print_plugin_info (plugin);
1829 print_plugin_features (plugin);
1832 GError *error = NULL;
1834 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1835 plugin = gst_plugin_load_file (arg, &error);
1839 print_plugin_automatic_install_info (plugin);
1841 print_plugin_info (plugin);
1842 print_plugin_features (plugin);
1845 g_printerr (_("Could not load plugin file: %s\n"), error->message);
1846 g_clear_error (&error);
1850 g_printerr (_("No such element or plugin '%s'\n"), arg);