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 if (param->flags & G_PARAM_READABLE && obj != NULL) {
309 g_object_get_property (obj, param->name, &value);
311 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
314 /* if we can't read the property value, assume it's set to the default
315 * (which might not be entirely true for sub-classes, but that's an
316 * unlikely corner-case anyway) */
317 g_param_value_set_default (param, &value);
319 if (param->flags & G_PARAM_WRITABLE) {
320 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
323 if (param->flags & G_PARAM_DEPRECATED) {
324 g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
327 if (param->flags & GST_PARAM_CONTROLLABLE) {
328 g_print (", %s", _("controllable"));
331 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
332 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
333 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
334 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
335 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
336 g_print (", %s", _("changeable only in NULL or READY state"));
338 if (param->flags & ~KNOWN_PARAM_FLAGS) {
339 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
340 param->flags & ~KNOWN_PARAM_FLAGS);
344 switch (G_VALUE_TYPE (&value)) {
347 const char *string_val = g_value_get_string (&value);
349 n_print ("String. ");
351 if (string_val == NULL)
352 g_print ("Default: null");
354 g_print ("Default: \"%s\"", string_val);
359 gboolean bool_val = g_value_get_boolean (&value);
361 n_print ("Boolean. Default: %s", bool_val ? "true" : "false");
366 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
368 n_print ("Unsigned Long. Range: %lu - %lu Default: %lu ",
369 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
371 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
372 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
373 g_param_spec_get_name (param));
378 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
380 n_print ("Long. Range: %ld - %ld Default: %ld ",
381 plong->minimum, plong->maximum, g_value_get_long (&value));
383 GST_ERROR ("%s: property '%s' of type long: consider changing to "
384 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
385 g_param_spec_get_name (param));
390 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
392 n_print ("Unsigned Integer. Range: %u - %u Default: %u ",
393 puint->minimum, puint->maximum, g_value_get_uint (&value));
398 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
400 n_print ("Integer. Range: %d - %d Default: %d ",
401 pint->minimum, pint->maximum, g_value_get_int (&value));
406 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
408 n_print ("Unsigned Integer64. Range: %" G_GUINT64_FORMAT " - "
409 "%" G_GUINT64_FORMAT " Default: %" G_GUINT64_FORMAT " ",
410 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
415 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
417 n_print ("Integer64. Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
418 " Default: %" G_GINT64_FORMAT " ",
419 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
424 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
426 n_print ("Float. Range: %15.7g - %15.7g Default: %15.7g ",
427 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
432 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
434 n_print ("Double. Range: %15.7g - %15.7g Default: %15.7g ",
435 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
440 GST_ERROR ("%s: property '%s' of type char: consider changing to "
441 "int/string", G_OBJECT_CLASS_NAME (obj_class),
442 g_param_spec_get_name (param));
445 if (param->value_type == GST_TYPE_CAPS) {
446 const GstCaps *caps = gst_value_get_caps (&value);
449 n_print ("Caps (NULL)");
451 print_caps (caps, " ");
453 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
457 const gchar *value_nick = "";
459 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
460 enum_value = g_value_get_enum (&value);
462 while (values[j].value_name) {
463 if (values[j].value == enum_value)
464 value_nick = values[j].value_nick;
468 n_print ("Enum \"%s\" Default: %d, \"%s\"",
469 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
472 while (values[j].value_name) {
474 n_print (" (%d): %-16s - %s",
475 values[j].value, values[j].value_nick, values[j].value_name);
478 /* g_type_class_unref (ec); */
479 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
480 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
484 vals = pflags->flags_class->values;
486 cur = flags_to_string (vals, g_value_get_flags (&value));
488 n_print ("Flags \"%s\" Default: 0x%08x, \"%s\"",
489 g_type_name (G_VALUE_TYPE (&value)),
490 g_value_get_flags (&value), cur);
492 while (vals[0].value_name) {
494 n_print (" (0x%08x): %-16s - %s",
495 vals[0].value, vals[0].value_nick, vals[0].value_name);
500 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
501 n_print ("Object of type \"%s\"", g_type_name (param->value_type));
502 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
503 n_print ("Boxed pointer of type \"%s\"",
504 g_type_name (param->value_type));
505 if (param->value_type == GST_TYPE_STRUCTURE) {
506 const GstStructure *s = gst_value_get_structure (&value);
508 gst_structure_foreach (s, print_field,
511 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
512 if (param->value_type != G_TYPE_POINTER) {
513 n_print ("Pointer of type \"%s\".",
514 g_type_name (param->value_type));
516 n_print ("Pointer.");
518 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
519 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
521 if (pvarray->element_spec) {
522 n_print ("Array of GValues of type \"%s\"",
523 g_type_name (pvarray->element_spec->value_type));
525 n_print ("Array of GValues");
527 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
528 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
530 n_print ("Fraction. Range: %d/%d - %d/%d Default: %d/%d ",
531 pfraction->min_num, pfraction->min_den,
532 pfraction->max_num, pfraction->max_den,
533 gst_value_get_fraction_numerator (&value),
534 gst_value_get_fraction_denominator (&value));
535 } else if (param->value_type == GST_TYPE_ARRAY) {
536 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
538 if (parray->element_spec) {
539 n_print ("GstValueArray of GValues of type \"%s\"",
540 g_type_name (parray->element_spec->value_type));
542 n_print ("GstValueArray of GValues");
545 n_print ("Unknown type %ld \"%s\"",
546 (glong) param->value_type, g_type_name (param->value_type));
551 g_print (" Write only\n");
557 g_value_reset (&value);
559 if (num_properties == 0)
564 g_free (property_specs);
568 print_element_properties_info (GstElement * element)
571 print_object_properties_info (G_OBJECT (element),
572 G_OBJECT_GET_CLASS (element), "Element Properties");
576 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
579 GstStaticPadTemplate *padtemplate;
580 GstPadTemplate *tmpl;
582 n_print ("Pad Templates:\n");
586 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
591 pads = gst_element_factory_get_static_pad_templates (factory);
593 padtemplate = (GstStaticPadTemplate *) (pads->data);
594 pads = g_list_next (pads);
596 if (padtemplate->direction == GST_PAD_SRC)
597 n_print ("SRC template: '%s'\n", padtemplate->name_template);
598 else if (padtemplate->direction == GST_PAD_SINK)
599 n_print ("SINK template: '%s'\n", padtemplate->name_template);
601 n_print ("UNKNOWN template: '%s'\n", padtemplate->name_template);
605 if (padtemplate->presence == GST_PAD_ALWAYS)
606 n_print ("Availability: Always\n");
607 else if (padtemplate->presence == GST_PAD_SOMETIMES)
608 n_print ("Availability: Sometimes\n");
609 else if (padtemplate->presence == GST_PAD_REQUEST) {
610 n_print ("Availability: On request\n");
612 n_print ("Availability: UNKNOWN\n");
614 if (padtemplate->static_caps.string) {
615 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
617 n_print ("Capabilities:\n");
620 print_caps (caps, ""); // FIXME
623 gst_caps_unref (caps);
626 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
627 padtemplate->name_template);
629 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
631 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
634 pad_klass = g_type_class_ref (pad_type);
635 n_print ("Type: %s\n", g_type_name (pad_type));
636 print_object_properties_info (NULL, pad_klass, "Pad Properties");
637 g_type_class_unref (pad_klass);
652 print_clocking_info (GstElement * element)
654 gboolean requires_clock, provides_clock;
657 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
659 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
661 if (!requires_clock && !provides_clock) {
663 n_print ("Element has no clocking capabilities.\n");
668 n_print ("Clocking Interaction:\n");
672 if (requires_clock) {
673 n_print ("element requires a clock\n");
676 if (provides_clock) {
679 clock = gst_element_get_clock (element);
681 n_print ("element provides a clock: %s\n", GST_OBJECT_NAME (clock));
682 gst_object_unref (clock);
684 n_print ("element is supposed to provide a clock but returned NULL\n");
691 print_uri_handler_info (GstElement * element)
693 if (GST_IS_URI_HANDLER (element)) {
694 const gchar *const *uri_protocols;
695 const gchar *uri_type;
697 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
699 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
703 uri_type = "unknown";
705 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
708 n_print ("URI handling capabilities:\n");
712 n_print ("Element can act as %s.\n", uri_type);
714 if (uri_protocols && *uri_protocols) {
715 n_print ("Supported URI protocols:\n");
717 for (; *uri_protocols != NULL; uri_protocols++)
718 n_print ("%s\n", *uri_protocols);
721 n_print ("No supported URI protocols\n");
726 n_print ("Element has no URI handling capabilities.\n");
731 print_pad_info (GstElement * element)
741 if (!element->numpads) {
746 pads = element->pads;
751 pad = GST_PAD (pads->data);
752 pads = g_list_next (pads);
754 name = gst_pad_get_name (pad);
755 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
756 n_print ("SRC: '%s'\n", name);
757 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
758 n_print ("SINK: '%s'\n", name);
760 n_print ("UNKNOWN: '%s'\n", name);
764 if (pad->padtemplate) {
766 n_print ("Pad Template: '%s'\n", pad->padtemplate->name_template);
770 caps = gst_pad_get_current_caps (pad);
772 n_print ("Capabilities:\n");
774 print_caps (caps, ""); // FIXME
776 gst_caps_unref (caps);
785 has_sometimes_template (GstElement * element)
787 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
790 for (l = klass->padtemplates; l != NULL; l = l->next) {
791 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
799 gtype_needs_ptr_marker (GType type)
801 if (type == G_TYPE_POINTER)
804 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
805 || G_TYPE_IS_OBJECT (type))
812 print_signal_info (GstElement * element)
814 /* Signals/Actions Block */
818 GSignalQuery *query = NULL;
820 GSList *found_signals, *l;
822 for (k = 0; k < 2; k++) {
823 found_signals = NULL;
825 /* For elements that have sometimes pads, also list a few useful GstElement
826 * signals. Put these first, so element-specific ones come later. */
827 if (k == 0 && has_sometimes_template (element)) {
828 query = g_new0 (GSignalQuery, 1);
829 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
830 found_signals = g_slist_append (found_signals, query);
831 query = g_new0 (GSignalQuery, 1);
832 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
833 found_signals = g_slist_append (found_signals, query);
834 query = g_new0 (GSignalQuery, 1);
835 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
837 found_signals = g_slist_append (found_signals, query);
840 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
841 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
844 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
847 signals = g_signal_list_ids (type, &nsignals);
848 for (i = 0; i < nsignals; i++) {
849 query = g_new0 (GSignalQuery, 1);
850 g_signal_query (signals[i], query);
852 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
853 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
854 found_signals = g_slist_append (found_signals, query);
865 n_print ("Element Signals:\n");
867 n_print ("Element Actions:\n");
872 for (l = found_signals; l; l = l->next) {
877 query = (GSignalQuery *) l->data;
878 indent_len = strlen (query->signal_name) +
879 strlen (g_type_name (query->return_type)) + 24;
881 if (gtype_needs_ptr_marker (query->return_type)) {
888 indent = g_new0 (gchar, indent_len + 1);
889 memset (indent, ' ', indent_len);
891 n_print (" \"%s\" : %s %suser_function (%s* object",
892 query->signal_name, g_type_name (query->return_type), pmark,
895 for (j = 0; j < query->n_params; j++) {
896 const gchar *type_name, *asterisk;
898 type_name = g_type_name (query->param_types[j]);
899 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
902 n_print ("%s%s%s arg%d", indent, type_name, asterisk, j);
907 n_print ("%sgpointer user_data);\n", indent);
915 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
916 g_slist_free (found_signals);
922 print_children_info (GstElement * element)
926 if (!GST_IS_BIN (element))
929 children = (GList *) GST_BIN (element)->children;
932 n_print ("Children:\n");
936 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
937 children = g_list_next (children);
942 print_preset_list (GstElement * element)
944 gchar **presets, **preset;
946 if (!GST_IS_PRESET (element))
949 presets = gst_preset_get_preset_names (GST_PRESET (element));
950 if (presets && *presets) {
952 n_print ("Presets:\n");
953 for (preset = presets; *preset; preset++) {
954 n_print (" \"%s\"\n", *preset);
956 g_strfreev (presets);
961 print_blacklist (void)
963 GList *plugins, *cur;
966 g_print ("%s\n", _("Blacklisted files:"));
968 plugins = gst_registry_get_plugin_list (gst_registry_get ());
969 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
970 GstPlugin *plugin = (GstPlugin *) (cur->data);
971 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
972 g_print (" %s\n", gst_plugin_get_name (plugin));
978 g_print (_("Total count: "));
979 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
982 gst_plugin_list_free (plugins);
986 print_typefind_extensions (const gchar * const *extensions)
990 while (extensions[i]) {
991 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
997 print_element_list (gboolean print_all, gchar * ftypes)
999 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1000 GList *plugins, *orig_plugins;
1001 gchar **types = NULL;
1006 types = g_strsplit (ftypes, "/", -1);
1007 for (i = 0; types[i]; i++)
1008 *types[i] = g_ascii_toupper (*types[i]);
1012 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1014 GList *features, *orig_features;
1017 plugin = (GstPlugin *) (plugins->data);
1018 plugins = g_list_next (plugins);
1021 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1026 orig_features = features =
1027 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1028 gst_plugin_get_name (plugin));
1030 GstPluginFeature *feature;
1032 if (G_UNLIKELY (features->data == NULL))
1034 feature = GST_PLUGIN_FEATURE (features->data);
1037 if (GST_IS_ELEMENT_FACTORY (feature)) {
1039 GstElementFactory *factory;
1041 factory = GST_ELEMENT_FACTORY (feature);
1044 gboolean all_found = TRUE;
1047 gst_element_factory_get_metadata (factory,
1048 GST_ELEMENT_METADATA_KLASS);
1049 for (i = 0; types[i]; i++) {
1050 if (!strstr (klass, types[i])) {
1060 print_element_info (feature, TRUE);
1062 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1063 GST_OBJECT_NAME (factory),
1064 gst_element_factory_get_metadata (factory,
1065 GST_ELEMENT_METADATA_LONGNAME));
1066 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1067 GstTypeFindFactory *factory;
1068 const gchar *const *extensions;
1072 factory = GST_TYPE_FIND_FACTORY (feature);
1074 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1075 gst_plugin_feature_get_name (feature));
1077 extensions = gst_type_find_factory_get_extensions (factory);
1078 if (extensions != NULL) {
1080 print_typefind_extensions (extensions);
1085 g_print ("no extensions\n");
1091 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1092 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1096 features = g_list_next (features);
1099 gst_plugin_feature_list_free (orig_features);
1102 gst_plugin_list_free (orig_plugins);
1106 g_print (_("Total count: "));
1107 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1108 if (blacklistcount) {
1110 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1111 blacklistcount), blacklistcount);
1112 g_print (" not shown)");
1115 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1120 print_all_uri_handlers (void)
1122 GList *plugins, *p, *features, *f;
1124 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1126 for (p = plugins; p; p = p->next) {
1127 GstPlugin *plugin = (GstPlugin *) (p->data);
1130 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1131 gst_plugin_get_name (plugin));
1133 for (f = features; f; f = f->next) {
1134 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1136 if (GST_IS_ELEMENT_FACTORY (feature)) {
1137 GstElementFactory *factory;
1138 GstElement *element;
1140 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1142 g_print ("element plugin %s couldn't be loaded\n",
1143 gst_plugin_get_name (plugin));
1147 element = gst_element_factory_create (factory, NULL);
1149 g_print ("couldn't construct element for %s for some reason\n",
1150 GST_OBJECT_NAME (factory));
1151 gst_object_unref (factory);
1155 if (GST_IS_URI_HANDLER (element)) {
1156 const gchar *const *uri_protocols;
1160 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1173 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1174 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1176 g_print ("%s (%s, rank %u): %s\n",
1177 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1178 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1184 gst_object_unref (element);
1185 gst_object_unref (factory);
1189 gst_plugin_feature_list_free (features);
1192 gst_plugin_list_free (plugins);
1196 print_plugin_info (GstPlugin * plugin)
1198 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1199 const gchar *filename = gst_plugin_get_filename (plugin);
1201 n_print ("Plugin Details:\n");
1205 n_print ("%-25s%s\n", "Name", gst_plugin_get_name (plugin));
1206 n_print ("%-25s%s\n", "Description", gst_plugin_get_description (plugin));
1207 n_print ("%-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1208 n_print ("%-25s%s\n", "Version", gst_plugin_get_version (plugin));
1209 n_print ("%-25s%s\n", "License", gst_plugin_get_license (plugin));
1210 n_print ("%-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1212 if (release_date != NULL) {
1213 const gchar *tz = "(UTC)";
1216 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1217 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1218 str = g_strdup (release_date);
1219 sep = strstr (str, "T");
1222 sep = strstr (sep + 1, "Z");
1228 n_print ("%-25s%s%s\n", "Source release date", str, tz);
1231 n_print ("%-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1232 n_print ("%-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1240 print_plugin_features (GstPlugin * plugin)
1242 GList *features, *origlist;
1243 gint num_features = 0;
1244 gint num_elements = 0;
1245 gint num_tracers = 0;
1246 gint num_typefinders = 0;
1247 gint num_devproviders = 0;
1250 origlist = features =
1251 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1252 gst_plugin_get_name (plugin));
1255 GstPluginFeature *feature;
1257 feature = GST_PLUGIN_FEATURE (features->data);
1259 if (GST_IS_ELEMENT_FACTORY (feature)) {
1260 GstElementFactory *factory;
1262 factory = GST_ELEMENT_FACTORY (feature);
1263 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1264 gst_element_factory_get_metadata (factory,
1265 GST_ELEMENT_METADATA_LONGNAME));
1267 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1268 GstTypeFindFactory *factory;
1269 const gchar *const *extensions;
1271 factory = GST_TYPE_FIND_FACTORY (feature);
1272 extensions = gst_type_find_factory_get_extensions (factory);
1276 g_print (" %s: %s: ", gst_plugin_get_name (plugin),
1277 gst_plugin_feature_get_name (feature));
1278 while (extensions[i]) {
1279 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1284 g_print (" %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1285 gst_plugin_feature_get_name (feature));
1288 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1289 GstDeviceProviderFactory *factory;
1291 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1292 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1293 gst_device_provider_factory_get_metadata (factory,
1294 GST_ELEMENT_METADATA_LONGNAME));
1296 } else if (GST_IS_TRACER_FACTORY (feature)) {
1297 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1298 g_type_name (G_OBJECT_TYPE (feature)));
1300 } else if (feature) {
1301 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1302 g_type_name (G_OBJECT_TYPE (feature)));
1306 features = g_list_next (features);
1309 gst_plugin_feature_list_free (origlist);
1312 n_print (" %d features:\n", num_features);
1313 if (num_elements > 0)
1314 n_print (" +-- %d elements\n", num_elements);
1315 if (num_typefinders > 0)
1316 n_print (" +-- %d typefinders\n", num_typefinders);
1317 if (num_devproviders > 0)
1318 n_print (" +-- %d device providers\n", num_devproviders);
1319 if (num_tracers > 0)
1320 n_print (" +-- %d tracers\n", num_tracers);
1322 n_print (" +-- %d other objects\n", num_other);
1328 print_feature_info (const gchar * feature_name, gboolean print_all)
1330 GstPluginFeature *feature;
1331 GstRegistry *registry = gst_registry_get ();
1334 if ((feature = gst_registry_find_feature (registry, feature_name,
1335 GST_TYPE_ELEMENT_FACTORY))) {
1336 ret = print_element_info (feature, print_all);
1339 if ((feature = gst_registry_find_feature (registry, feature_name,
1340 GST_TYPE_TYPE_FIND_FACTORY))) {
1341 ret = print_typefind_info (feature, print_all);
1344 if ((feature = gst_registry_find_feature (registry, feature_name,
1345 GST_TYPE_TRACER_FACTORY))) {
1346 ret = print_tracer_info (feature, print_all);
1350 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1355 gst_object_unref (feature);
1360 print_element_info (GstPluginFeature * feature, gboolean print_names)
1362 GstElementFactory *factory;
1363 GstElement *element;
1367 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1369 g_print ("element plugin couldn't be loaded\n");
1373 element = gst_element_factory_create (factory, NULL);
1375 gst_object_unref (factory);
1376 g_print ("couldn't construct element for some reason\n");
1381 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1385 print_factory_details_info (factory);
1387 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1389 print_plugin_info (plugin);
1390 gst_object_unref (plugin);
1393 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1394 print_interfaces (G_OBJECT_TYPE (element));
1396 print_pad_templates_info (element, factory);
1397 print_clocking_info (element);
1398 print_uri_handler_info (element);
1399 print_pad_info (element);
1400 print_element_properties_info (element);
1401 print_signal_info (element);
1402 print_children_info (element);
1403 print_preset_list (element);
1405 gst_object_unref (element);
1406 gst_object_unref (factory);
1412 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1414 GstTypeFindFactory *factory;
1419 const gchar *const *extensions;
1421 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1423 g_print ("typefind plugin couldn't be loaded\n");
1428 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1432 n_print ("Factory Details:\n");
1433 rank = gst_plugin_feature_get_rank (feature);
1434 n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
1435 n_print (" %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
1436 caps = gst_type_find_factory_get_caps (factory);
1438 gchar *caps_str = gst_caps_to_string (factory->caps);
1440 n_print (" %-25s%s\n", "Caps", caps_str);
1443 extensions = gst_type_find_factory_get_extensions (factory);
1445 n_print (" %-25s", "Extensions");
1446 print_typefind_extensions (extensions);
1451 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1453 print_plugin_info (plugin);
1454 gst_object_unref (plugin);
1457 gst_object_unref (factory);
1463 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1465 GstTracerFactory *factory;
1470 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1472 g_print ("tracer plugin couldn't be loaded\n");
1476 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1478 gst_object_unref (factory);
1479 g_print ("couldn't construct tracer for some reason\n");
1484 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1488 n_print ("Factory Details:\n");
1489 n_print (" %-25s%s\n", "Name", GST_OBJECT_NAME (factory));
1492 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1494 print_plugin_info (plugin);
1495 gst_object_unref (plugin);
1498 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1499 print_interfaces (G_OBJECT_TYPE (tracer));
1501 /* TODO: list what hooks it registers
1502 * - the data is available in gsttracerutils, we need to iterate the
1503 * _priv_tracers hashtable for each probe and then check the list of hooks
1504 * for each probe whether hook->tracer == tracer :/
1507 /* TODO: list what records it emits
1508 * - in class_init tracers can create GstTracerRecord instances
1509 * - those only get logged right now and there is no association with the
1510 * tracer that created them
1511 * - we'd need to add them to GstTracerFactory
1512 * gst_tracer_class_add_record (klass, record);
1513 * - needs work in gstregistrychunks.
1516 gst_object_unref (tracer);
1517 gst_object_unref (factory);
1523 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1525 GstPadDirection direction;
1526 const gchar *type_name;
1528 const GList *static_templates, *l;
1529 GstCaps *caps = NULL;
1533 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1534 g_return_if_fail (klass != NULL);
1536 if (strstr (klass, "Demuxer") ||
1537 strstr (klass, "Decoder") ||
1538 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1539 type_name = "decoder";
1540 direction = GST_PAD_SINK;
1541 } else if (strstr (klass, "Muxer") ||
1542 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1543 type_name = "encoder";
1544 direction = GST_PAD_SRC;
1549 /* decoder/demuxer sink pads should always be static and there should only
1550 * be one, the same applies to encoders/muxers and source pads */
1551 static_templates = gst_element_factory_get_static_pad_templates (factory);
1552 for (l = static_templates; l != NULL; l = l->next) {
1553 GstStaticPadTemplate *tmpl = NULL;
1555 tmpl = (GstStaticPadTemplate *) l->data;
1556 if (tmpl->direction == direction) {
1557 caps = gst_static_pad_template_get_caps (tmpl);
1563 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1564 type_name, GST_OBJECT_NAME (factory));
1568 caps = gst_caps_make_writable (caps);
1569 num = gst_caps_get_size (caps);
1570 for (i = 0; i < num; ++i) {
1574 s = gst_caps_get_structure (caps, i);
1575 /* remove fields that are almost always just MIN-MAX of some sort
1576 * in order to make the caps look less messy */
1577 gst_structure_remove_field (s, "pixel-aspect-ratio");
1578 gst_structure_remove_field (s, "framerate");
1579 gst_structure_remove_field (s, "channels");
1580 gst_structure_remove_field (s, "width");
1581 gst_structure_remove_field (s, "height");
1582 gst_structure_remove_field (s, "rate");
1583 gst_structure_remove_field (s, "depth");
1584 gst_structure_remove_field (s, "clock-rate");
1585 s_str = gst_structure_to_string (s);
1586 g_print ("%s-%s\n", type_name, s_str);
1589 gst_caps_unref (caps);
1593 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1595 const gchar *const *protocols;
1597 protocols = gst_element_factory_get_uri_protocols (factory);
1598 if (protocols != NULL && *protocols != NULL) {
1599 switch (gst_element_factory_get_uri_type (factory)) {
1601 while (*protocols != NULL) {
1602 g_print ("urisink-%s\n", *protocols);
1607 while (*protocols != NULL) {
1608 g_print ("urisource-%s\n", *protocols);
1619 print_plugin_automatic_install_info (GstPlugin * plugin)
1621 GList *features, *l;
1623 /* not interested in typefind factories, only element factories */
1624 features = gst_registry_get_feature_list (gst_registry_get (),
1625 GST_TYPE_ELEMENT_FACTORY);
1627 for (l = features; l != NULL; l = l->next) {
1628 GstPluginFeature *feature;
1629 GstPlugin *feature_plugin;
1631 feature = GST_PLUGIN_FEATURE (l->data);
1633 /* only interested in the ones that are in the plugin we just loaded */
1634 feature_plugin = gst_plugin_feature_get_plugin (feature);
1635 if (feature_plugin == plugin) {
1636 GstElementFactory *factory;
1638 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1640 factory = GST_ELEMENT_FACTORY (feature);
1641 print_plugin_automatic_install_info_protocols (factory);
1642 print_plugin_automatic_install_info_codecs (factory);
1645 gst_object_unref (feature_plugin);
1648 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1649 g_list_free (features);
1653 print_all_plugin_automatic_install_info (void)
1655 GList *plugins, *orig_plugins;
1657 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1661 plugin = (GstPlugin *) (plugins->data);
1662 plugins = g_list_next (plugins);
1664 print_plugin_automatic_install_info (plugin);
1666 gst_plugin_list_free (orig_plugins);
1670 main (int argc, char *argv[])
1672 gboolean print_all = FALSE;
1673 gboolean do_print_blacklist = FALSE;
1674 gboolean plugin_name = FALSE;
1675 gboolean print_aii = FALSE;
1676 gboolean uri_handlers = FALSE;
1677 gboolean check_exists = FALSE;
1678 gchar *min_version = NULL;
1679 guint minver_maj = GST_VERSION_MAJOR;
1680 guint minver_min = GST_VERSION_MINOR;
1681 guint minver_micro = 0;
1682 gchar *types = NULL;
1683 #ifndef GST_DISABLE_OPTION_PARSING
1684 GOptionEntry options[] = {
1685 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1686 N_("Print all elements"), NULL},
1687 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1688 N_("Print list of blacklisted files"), NULL},
1689 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1690 N_("Print a machine-parsable list of features the specified plugin "
1691 "or all plugins provide.\n "
1692 "Useful in connection with external automatic plugin "
1693 "installation mechanisms"), NULL},
1694 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1695 N_("List the plugin contents"), NULL},
1696 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1697 N_("A slashes ('/') separated list of types of elements (also known "
1698 "as klass) to list. (unordered)"), NULL},
1699 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1700 N_("Check if the specified element or plugin exists"), NULL},
1701 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1703 ("When checking if an element or plugin exists, also check that its "
1704 "version is at least the version specified"), NULL},
1705 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1707 ("Print supported URI schemes, with the elements that implement them"),
1709 GST_TOOLS_GOPTION_VERSION,
1712 GOptionContext *ctx;
1716 setlocale (LC_ALL, "");
1719 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1720 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1721 textdomain (GETTEXT_PACKAGE);
1724 /* avoid glib warnings when inspecting deprecated properties */
1725 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
1727 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1729 #ifndef GST_DISABLE_OPTION_PARSING
1730 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1731 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1732 g_option_context_add_group (ctx, gst_init_get_option_group ());
1733 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1734 g_printerr ("Error initializing: %s\n", err->message);
1735 g_clear_error (&err);
1736 g_option_context_free (ctx);
1739 g_option_context_free (ctx);
1741 gst_init (&argc, &argv);
1744 gst_tools_print_version ();
1746 if (print_all && argc > 1) {
1747 g_printerr ("-a requires no extra arguments\n");
1751 if (uri_handlers && argc > 1) {
1752 g_printerr ("-u requires no extra arguments\n");
1756 /* --atleast-version implies --exists */
1757 if (min_version != NULL) {
1758 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1759 &minver_micro) < 2) {
1760 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1764 check_exists = TRUE;
1771 g_printerr ("--exists requires an extra command line argument\n");
1775 GstPluginFeature *feature;
1777 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1778 if (feature != NULL && gst_plugin_feature_check_version (feature,
1779 minver_maj, minver_min, minver_micro)) {
1786 gst_object_unref (feature);
1788 /* FIXME: support checking for plugins too */
1789 g_printerr ("Checking for plugins is not supported yet\n");
1796 /* if no arguments, print out list of elements */
1798 print_all_uri_handlers ();
1799 } else if (argc == 1 || print_all) {
1800 if (do_print_blacklist)
1804 print_all_plugin_automatic_install_info ();
1806 print_element_list (print_all, types);
1809 /* else we try to get a factory */
1810 const char *arg = argv[argc - 1];
1814 retval = print_feature_info (arg, print_all);
1817 /* otherwise check if it's a plugin */
1819 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1821 /* if there is such a plugin, print out info */
1824 print_plugin_automatic_install_info (plugin);
1826 print_plugin_info (plugin);
1827 print_plugin_features (plugin);
1830 GError *error = NULL;
1832 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1833 plugin = gst_plugin_load_file (arg, &error);
1837 print_plugin_automatic_install_info (plugin);
1839 print_plugin_info (plugin);
1840 print_plugin_features (plugin);
1843 g_printerr (_("Could not load plugin file: %s\n"), error->message);
1844 g_clear_error (&error);
1848 g_printerr (_("No such element or plugin '%s'\n"), arg);