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 0.11: 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);
44 n_print (const char *format, ...)
49 g_print ("%s", _name);
51 va_start (args, format);
52 g_vprintf (format, args);
57 print_field (GQuark field, const GValue * value, gpointer pfx)
59 gchar *str = gst_value_serialize (value);
61 n_print ("%s %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
67 print_caps (const GstCaps * caps, const gchar * pfx)
71 g_return_if_fail (caps != NULL);
73 if (gst_caps_is_any (caps)) {
74 n_print ("%sANY\n", pfx);
77 if (gst_caps_is_empty (caps)) {
78 n_print ("%sEMPTY\n", pfx);
82 for (i = 0; i < gst_caps_get_size (caps); i++) {
83 GstStructure *structure = gst_caps_get_structure (caps, i);
84 GstCapsFeatures *features = gst_caps_get_features (caps, i);
86 if (features && (gst_caps_features_is_any (features) ||
87 !gst_caps_features_is_equal (features,
88 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
89 gchar *features_string = gst_caps_features_to_string (features);
91 n_print ("%s%s(%s)\n", pfx, gst_structure_get_name (structure),
93 g_free (features_string);
95 n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
97 gst_structure_foreach (structure, print_field, (gpointer) pfx);
102 get_rank_name (char *s, gint rank)
104 static const int ranks[4] = {
105 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
107 static const char *rank_names[4] = { "none", "marginal", "secondary",
114 for (i = 0; i < 4; i++) {
115 if (rank == ranks[i])
116 return rank_names[i];
117 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
122 sprintf (s, "%s %c %d", rank_names[best_i],
123 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
129 print_factory_details_info (GstElementFactory * factory)
135 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
136 n_print ("Factory Details:\n");
137 n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
139 keys = gst_element_factory_get_metadata_keys (factory);
141 for (k = keys; *k != NULL; ++k) {
145 val = gst_element_factory_get_metadata (factory, key);
146 key[0] = g_ascii_toupper (key[0]);
147 n_print (" %-25s%s\n", key, val);
155 print_hierarchy (GType type, gint level, gint * maxlevel)
160 parent = g_type_parent (type);
162 *maxlevel = *maxlevel + 1;
166 print_hierarchy (parent, level, maxlevel);
169 g_print ("%s", _name);
171 for (i = 1; i < *maxlevel - level; i++)
173 if (*maxlevel - level)
176 g_print ("%s\n", g_type_name (type));
183 print_interfaces (GType type)
186 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
191 g_print ("%s", _name);
192 g_print (_("Implemented Interfaces:\n"));
196 g_print ("%s", _name);
197 g_print (" %s\n", g_type_name (*iface));
201 g_print ("%s", _name);
209 flags_to_string (GFlagsValue * vals, guint flags)
214 /* first look for an exact match and count the number of values */
215 for (i = 0; vals[i].value_name != NULL; ++i) {
216 if (vals[i].value == flags)
217 return g_strdup (vals[i].value_nick);
220 s = g_string_new (NULL);
222 /* we assume the values are sorted from lowest to highest value */
226 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
228 g_string_append_c (s, '+');
229 g_string_append (s, vals[i].value_nick);
230 flags_left -= vals[i].value;
237 g_string_assign (s, "(none)");
239 return g_string_free (s, FALSE);
242 #define KNOWN_PARAM_FLAGS \
243 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
244 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
245 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
246 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
247 GST_PARAM_MUTABLE_READY)
250 print_element_properties_info (GstElement * element)
252 GParamSpec **property_specs;
253 guint num_properties, i;
257 property_specs = g_object_class_list_properties
258 (G_OBJECT_GET_CLASS (element), &num_properties);
260 n_print ("Element Properties:\n");
262 for (i = 0; i < num_properties; i++) {
263 GValue value = { 0, };
264 GParamSpec *param = property_specs[i];
268 g_value_init (&value, param->value_type);
270 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
271 g_param_spec_get_blurb (param));
274 n_print ("%-23.23s flags: ", "");
275 if (param->flags & G_PARAM_READABLE) {
276 g_object_get_property (G_OBJECT (element), param->name, &value);
278 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
281 /* if we can't read the property value, assume it's set to the default
282 * (which might not be entirely true for sub-classes, but that's an
283 * unlikely corner-case anyway) */
284 g_param_value_set_default (param, &value);
286 if (param->flags & G_PARAM_WRITABLE) {
287 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
290 if (param->flags & GST_PARAM_CONTROLLABLE) {
291 g_print (", %s", _("controllable"));
294 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
295 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
296 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
297 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
298 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
299 g_print (", %s", _("changeable only in NULL or READY state"));
301 if (param->flags & ~KNOWN_PARAM_FLAGS) {
302 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
303 param->flags & ~KNOWN_PARAM_FLAGS);
307 switch (G_VALUE_TYPE (&value)) {
310 const char *string_val = g_value_get_string (&value);
312 n_print ("%-23.23s String. ", "");
314 if (string_val == NULL)
315 g_print ("Default: null");
317 g_print ("Default: \"%s\"", string_val);
322 gboolean bool_val = g_value_get_boolean (&value);
324 n_print ("%-23.23s Boolean. ", "");
326 g_print ("Default: %s", bool_val ? "true" : "false");
331 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
333 n_print ("%-23.23s Unsigned Long. ", "");
334 g_print ("Range: %lu - %lu Default: %lu ",
335 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
337 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
338 "uint/uint64", GST_OBJECT_NAME (element),
339 g_param_spec_get_name (param));
344 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
346 n_print ("%-23.23s Long. ", "");
347 g_print ("Range: %ld - %ld Default: %ld ",
348 plong->minimum, plong->maximum, g_value_get_long (&value));
350 GST_ERROR ("%s: property '%s' of type long: consider changing to "
351 "int/int64", GST_OBJECT_NAME (element),
352 g_param_spec_get_name (param));
357 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
359 n_print ("%-23.23s Unsigned Integer. ", "");
360 g_print ("Range: %u - %u Default: %u ",
361 puint->minimum, puint->maximum, g_value_get_uint (&value));
366 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
368 n_print ("%-23.23s Integer. ", "");
369 g_print ("Range: %d - %d Default: %d ",
370 pint->minimum, pint->maximum, g_value_get_int (&value));
375 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
377 n_print ("%-23.23s Unsigned Integer64. ", "");
378 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
379 " Default: %" G_GUINT64_FORMAT " ",
380 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
385 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
387 n_print ("%-23.23s Integer64. ", "");
388 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
389 " Default: %" G_GINT64_FORMAT " ",
390 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
395 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
397 n_print ("%-23.23s Float. ", "");
398 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
399 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
404 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
406 n_print ("%-23.23s Double. ", "");
407 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
408 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
413 GST_ERROR ("%s: property '%s' of type char: consider changing to "
414 "int/string", GST_OBJECT_NAME (element),
415 g_param_spec_get_name (param));
418 if (param->value_type == GST_TYPE_CAPS) {
419 const GstCaps *caps = gst_value_get_caps (&value);
422 n_print ("%-23.23s Caps (NULL)", "");
424 print_caps (caps, " ");
426 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
430 const gchar *value_nick = "";
432 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
433 enum_value = g_value_get_enum (&value);
435 while (values[j].value_name) {
436 if (values[j].value == enum_value)
437 value_nick = values[j].value_nick;
441 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
442 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
445 while (values[j].value_name) {
448 g_print ("%s", _name);
449 g_print ("%-23.23s (%d): %-16s - %s", "",
450 values[j].value, values[j].value_nick, values[j].value_name);
453 /* g_type_class_unref (ec); */
454 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
455 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
459 vals = pflags->flags_class->values;
461 cur = flags_to_string (vals, g_value_get_flags (&value));
463 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
464 g_type_name (G_VALUE_TYPE (&value)),
465 g_value_get_flags (&value), cur);
467 while (vals[0].value_name) {
470 g_print ("%s", _name);
471 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
472 vals[0].value, vals[0].value_nick, vals[0].value_name);
477 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
478 n_print ("%-23.23s Object of type \"%s\"", "",
479 g_type_name (param->value_type));
480 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
481 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
482 g_type_name (param->value_type));
483 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
484 if (param->value_type != G_TYPE_POINTER) {
485 n_print ("%-23.23s Pointer of type \"%s\".", "",
486 g_type_name (param->value_type));
488 n_print ("%-23.23s Pointer.", "");
490 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
491 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
493 if (pvarray->element_spec) {
494 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
495 g_type_name (pvarray->element_spec->value_type));
497 n_print ("%-23.23s Array of GValues", "");
499 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
500 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
502 n_print ("%-23.23s Fraction. ", "");
504 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
505 pfraction->min_num, pfraction->min_den,
506 pfraction->max_num, pfraction->max_den,
507 gst_value_get_fraction_numerator (&value),
508 gst_value_get_fraction_denominator (&value));
510 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
511 g_type_name (param->value_type));
516 g_print (" Write only\n");
520 g_value_reset (&value);
522 if (num_properties == 0)
525 g_free (property_specs);
529 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
531 GstElementClass *gstelement_class;
533 GstStaticPadTemplate *padtemplate;
535 n_print ("Pad Templates:\n");
536 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
541 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
543 pads = gst_element_factory_get_static_pad_templates (factory);
545 padtemplate = (GstStaticPadTemplate *) (pads->data);
546 pads = g_list_next (pads);
548 if (padtemplate->direction == GST_PAD_SRC)
549 n_print (" SRC template: '%s'\n", padtemplate->name_template);
550 else if (padtemplate->direction == GST_PAD_SINK)
551 n_print (" SINK template: '%s'\n", padtemplate->name_template);
553 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
555 if (padtemplate->presence == GST_PAD_ALWAYS)
556 n_print (" Availability: Always\n");
557 else if (padtemplate->presence == GST_PAD_SOMETIMES)
558 n_print (" Availability: Sometimes\n");
559 else if (padtemplate->presence == GST_PAD_REQUEST) {
560 n_print (" Availability: On request\n");
561 n_print (" Has request_new_pad() function: %s\n",
562 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
564 n_print (" Availability: UNKNOWN!!!\n");
566 if (padtemplate->static_caps.string) {
567 n_print (" Capabilities:\n");
568 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
576 print_element_flag_info (GstElement * element)
578 gboolean have_flags = FALSE;
581 n_print ("Element Flags:\n");
584 n_print (" no flags set\n");
586 if (GST_IS_BIN (element)) {
588 n_print ("Bin Flags:\n");
590 n_print (" no flags set\n");
595 print_implementation_info (GstElement * element)
597 GstElementClass *gstelement_class;
599 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
602 n_print ("Element Implementation:\n");
604 n_print (" Has change_state() function: %s\n",
605 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
609 print_clocking_info (GstElement * element)
611 gboolean requires_clock, provides_clock;
614 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
616 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
618 if (!requires_clock && !provides_clock) {
620 n_print ("Element has no clocking capabilities.");
625 n_print ("Clocking Interaction:\n");
626 if (requires_clock) {
627 n_print (" element requires a clock\n");
630 if (provides_clock) {
633 clock = gst_element_get_clock (element);
635 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
636 gst_object_unref (clock);
638 n_print (" element is supposed to provide a clock but returned NULL\n");
643 print_index_info (GstElement * element)
645 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
647 n_print ("Indexing capabilities:\n");
648 n_print (" element can do indexing\n");
651 n_print ("Element has no indexing capabilities.\n");
656 print_uri_handler_info (GstElement * element)
658 if (GST_IS_URI_HANDLER (element)) {
659 const gchar *const *uri_protocols;
660 const gchar *uri_type;
662 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
664 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
668 uri_type = "unknown";
670 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
673 n_print ("URI handling capabilities:\n");
674 n_print (" Element can act as %s.\n", uri_type);
676 if (uri_protocols && *uri_protocols) {
677 n_print (" Supported URI protocols:\n");
678 for (; *uri_protocols != NULL; uri_protocols++)
679 n_print (" %s\n", *uri_protocols);
681 n_print (" No supported URI protocols\n");
684 n_print ("Element has no URI handling capabilities.\n");
689 print_pad_info (GstElement * element)
697 if (!element->numpads) {
702 pads = element->pads;
707 pad = GST_PAD (pads->data);
708 pads = g_list_next (pads);
712 name = gst_pad_get_name (pad);
713 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
714 g_print (" SRC: '%s'", name);
715 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
716 g_print (" SINK: '%s'", name);
718 g_print (" UNKNOWN!!!: '%s'", name);
724 n_print (" Implementation:\n");
726 n_print (" Has chainfunc(): %s\n",
727 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
728 if (pad->getrangefunc)
729 n_print (" Has getrangefunc(): %s\n",
730 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
731 if (pad->eventfunc != gst_pad_event_default)
732 n_print (" Has custom eventfunc(): %s\n",
733 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
734 if (pad->queryfunc != gst_pad_query_default)
735 n_print (" Has custom queryfunc(): %s\n",
736 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
738 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
739 n_print (" Has custom iterintlinkfunc(): %s\n",
740 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
742 if (pad->padtemplate)
743 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
745 caps = gst_pad_get_current_caps (pad);
747 n_print (" Capabilities:\n");
748 print_caps (caps, " ");
749 gst_caps_unref (caps);
755 has_sometimes_template (GstElement * element)
757 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
760 for (l = klass->padtemplates; l != NULL; l = l->next) {
761 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
769 print_signal_info (GstElement * element)
771 /* Signals/Actions Block */
775 GSignalQuery *query = NULL;
777 GSList *found_signals, *l;
779 for (k = 0; k < 2; k++) {
780 found_signals = NULL;
782 /* For elements that have sometimes pads, also list a few useful GstElement
783 * signals. Put these first, so element-specific ones come later. */
784 if (k == 0 && has_sometimes_template (element)) {
785 query = g_new0 (GSignalQuery, 1);
786 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
787 found_signals = g_slist_append (found_signals, query);
788 query = g_new0 (GSignalQuery, 1);
789 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
790 found_signals = g_slist_append (found_signals, query);
791 query = g_new0 (GSignalQuery, 1);
792 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
794 found_signals = g_slist_append (found_signals, query);
797 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
798 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
801 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
804 signals = g_signal_list_ids (type, &nsignals);
805 for (i = 0; i < nsignals; i++) {
806 query = g_new0 (GSignalQuery, 1);
807 g_signal_query (signals[i], query);
809 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
810 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
811 found_signals = g_slist_append (found_signals, query);
822 n_print ("Element Signals:\n");
824 n_print ("Element Actions:\n");
829 for (l = found_signals; l; l = l->next) {
834 query = (GSignalQuery *) l->data;
835 indent_len = strlen (query->signal_name) +
836 strlen (g_type_name (query->return_type)) + 24;
839 if (query->return_type == G_TYPE_POINTER) {
841 } else if (G_TYPE_FUNDAMENTAL (query->return_type) == G_TYPE_POINTER
842 || G_TYPE_IS_BOXED (query->return_type)
843 || G_TYPE_IS_OBJECT (query->return_type)) {
850 indent = g_new0 (gchar, indent_len + 1);
851 memset (indent, ' ', indent_len);
853 n_print (" \"%s\" : %s %suser_function (%s* object",
854 query->signal_name, g_type_name (query->return_type), pmark,
857 for (j = 0; j < query->n_params; j++) {
859 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
860 n_print ("%s%s arg%d", indent,
861 g_type_name (query->param_types[j]), j);
862 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
863 n_print ("%s%s arg%d", indent,
864 g_type_name (query->param_types[j]), j);
866 n_print ("%s%s* arg%d", indent,
867 g_type_name (query->param_types[j]), j);
873 n_print ("%sgpointer user_data);\n", indent);
881 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
882 g_slist_free (found_signals);
888 print_children_info (GstElement * element)
892 if (!GST_IS_BIN (element))
895 children = (GList *) GST_BIN (element)->children;
898 n_print ("Children:\n");
902 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
903 children = g_list_next (children);
908 print_blacklist (void)
910 GList *plugins, *cur;
913 g_print ("%s\n", _("Blacklisted files:"));
915 plugins = gst_registry_get_plugin_list (gst_registry_get ());
916 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
917 GstPlugin *plugin = (GstPlugin *) (cur->data);
918 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
919 g_print (" %s\n", gst_plugin_get_name (plugin));
925 g_print (_("Total count: "));
926 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
929 gst_plugin_list_free (plugins);
933 print_element_list (gboolean print_all)
935 int plugincount = 0, featurecount = 0, blacklistcount = 0;
936 GList *plugins, *orig_plugins;
938 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
940 GList *features, *orig_features;
943 plugin = (GstPlugin *) (plugins->data);
944 plugins = g_list_next (plugins);
947 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
952 orig_features = features =
953 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
954 gst_plugin_get_name (plugin));
956 GstPluginFeature *feature;
958 if (G_UNLIKELY (features->data == NULL))
960 feature = GST_PLUGIN_FEATURE (features->data);
963 if (GST_IS_ELEMENT_FACTORY (feature)) {
964 GstElementFactory *factory;
966 factory = GST_ELEMENT_FACTORY (feature);
968 print_element_info (factory, TRUE);
970 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
971 GST_OBJECT_NAME (factory),
972 gst_element_factory_get_metadata (factory,
973 GST_ELEMENT_METADATA_LONGNAME));
974 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
975 GstTypeFindFactory *factory;
976 const gchar *const *extensions;
978 factory = GST_TYPE_FIND_FACTORY (feature);
980 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
981 gst_plugin_feature_get_name (feature));
983 extensions = gst_type_find_factory_get_extensions (factory);
984 if (extensions != NULL) {
987 while (extensions[i]) {
989 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
996 g_print ("no extensions\n");
1000 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1001 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1005 features = g_list_next (features);
1008 gst_plugin_feature_list_free (orig_features);
1011 gst_plugin_list_free (orig_plugins);
1014 g_print (_("Total count: "));
1015 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1016 if (blacklistcount) {
1018 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1019 blacklistcount), blacklistcount);
1020 g_print (" not shown)");
1023 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1028 print_all_uri_handlers (void)
1030 GList *plugins, *p, *features, *f;
1032 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1034 for (p = plugins; p; p = p->next) {
1035 GstPlugin *plugin = (GstPlugin *) (p->data);
1038 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1039 gst_plugin_get_name (plugin));
1041 for (f = features; f; f = f->next) {
1042 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1044 if (GST_IS_ELEMENT_FACTORY (feature)) {
1045 GstElementFactory *factory;
1046 GstElement *element;
1048 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1050 g_print ("element plugin %s couldn't be loaded\n",
1051 gst_plugin_get_name (plugin));
1055 element = gst_element_factory_create (factory, NULL);
1057 g_print ("couldn't construct element for %s for some reason\n",
1058 GST_OBJECT_NAME (factory));
1059 gst_object_unref (factory);
1063 if (GST_IS_URI_HANDLER (element)) {
1064 const gchar *const *uri_protocols;
1068 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1081 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1082 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1084 g_print ("%s (%s, rank %u): %s\n",
1085 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1086 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1092 gst_object_unref (element);
1093 gst_object_unref (factory);
1097 gst_plugin_feature_list_free (features);
1100 gst_plugin_list_free (plugins);
1104 print_plugin_info (GstPlugin * plugin)
1106 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1107 const gchar *filename = gst_plugin_get_filename (plugin);
1109 n_print ("Plugin Details:\n");
1110 n_print (" %-25s%s\n", "Name", gst_plugin_get_name (plugin));
1111 n_print (" %-25s%s\n", "Description", gst_plugin_get_description (plugin));
1112 n_print (" %-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1113 n_print (" %-25s%s\n", "Version", gst_plugin_get_version (plugin));
1114 n_print (" %-25s%s\n", "License", gst_plugin_get_license (plugin));
1115 n_print (" %-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1117 if (release_date != NULL) {
1118 const gchar *tz = "(UTC)";
1121 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1122 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1123 str = g_strdup (release_date);
1124 sep = strstr (str, "T");
1127 sep = strstr (sep + 1, "Z");
1133 n_print (" %-25s%s%s\n", "Source release date", str, tz);
1136 n_print (" %-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1137 n_print (" %-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1142 print_plugin_features (GstPlugin * plugin)
1144 GList *features, *origlist;
1145 gint num_features = 0;
1146 gint num_elements = 0;
1147 gint num_typefinders = 0;
1148 gint num_indexes = 0;
1151 origlist = features =
1152 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1153 gst_plugin_get_name (plugin));
1156 GstPluginFeature *feature;
1158 feature = GST_PLUGIN_FEATURE (features->data);
1160 if (GST_IS_ELEMENT_FACTORY (feature)) {
1161 GstElementFactory *factory;
1163 factory = GST_ELEMENT_FACTORY (feature);
1164 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1165 gst_element_factory_get_metadata (factory,
1166 GST_ELEMENT_METADATA_LONGNAME));
1168 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1169 GstTypeFindFactory *factory;
1170 const gchar *const *extensions;
1172 factory = GST_TYPE_FIND_FACTORY (feature);
1173 extensions = gst_type_find_factory_get_extensions (factory);
1177 g_print (" %s: %s: ", gst_plugin_get_name (plugin),
1178 gst_plugin_feature_get_name (feature));
1179 while (extensions[i]) {
1180 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1185 g_print (" %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1186 gst_plugin_feature_get_name (feature));
1189 } else if (feature) {
1190 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1191 g_type_name (G_OBJECT_TYPE (feature)));
1195 features = g_list_next (features);
1198 gst_plugin_feature_list_free (origlist);
1201 n_print (" %d features:\n", num_features);
1202 if (num_elements > 0)
1203 n_print (" +-- %d elements\n", num_elements);
1204 if (num_typefinders > 0)
1205 n_print (" +-- %d typefinders\n", num_typefinders);
1206 if (num_indexes > 0)
1207 n_print (" +-- %d indexes\n", num_indexes);
1209 n_print (" +-- %d other objects\n", num_other);
1215 print_element_features (const gchar * element_name)
1217 GstPluginFeature *feature;
1219 /* FIXME implement other pretty print function for these */
1220 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1221 GST_TYPE_TYPE_FIND_FACTORY);
1223 n_print ("%s: a typefind function\n", element_name);
1231 print_element_info (GstElementFactory * factory, gboolean print_names)
1233 GstElement *element;
1238 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1242 g_print ("element plugin couldn't be loaded\n");
1246 element = gst_element_factory_create (factory, NULL);
1248 gst_object_unref (factory);
1249 g_print ("couldn't construct element for some reason\n");
1254 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1258 print_factory_details_info (factory);
1260 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1262 print_plugin_info (plugin);
1263 gst_object_unref (plugin);
1266 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1267 print_interfaces (G_OBJECT_TYPE (element));
1269 print_pad_templates_info (element, factory);
1270 print_element_flag_info (element);
1271 print_implementation_info (element);
1272 print_clocking_info (element);
1273 print_index_info (element);
1274 print_uri_handler_info (element);
1275 print_pad_info (element);
1276 print_element_properties_info (element);
1277 print_signal_info (element);
1278 print_children_info (element);
1280 gst_object_unref (element);
1281 gst_object_unref (factory);
1289 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1291 GstPadDirection direction;
1292 const gchar *type_name;
1294 const GList *static_templates, *l;
1295 GstCaps *caps = NULL;
1299 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1300 g_return_if_fail (klass != NULL);
1302 if (strstr (klass, "Demuxer") ||
1303 strstr (klass, "Decoder") ||
1304 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1305 type_name = "decoder";
1306 direction = GST_PAD_SINK;
1307 } else if (strstr (klass, "Muxer") ||
1308 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1309 type_name = "encoder";
1310 direction = GST_PAD_SRC;
1315 /* decoder/demuxer sink pads should always be static and there should only
1316 * be one, the same applies to encoders/muxers and source pads */
1317 static_templates = gst_element_factory_get_static_pad_templates (factory);
1318 for (l = static_templates; l != NULL; l = l->next) {
1319 GstStaticPadTemplate *tmpl = NULL;
1321 tmpl = (GstStaticPadTemplate *) l->data;
1322 if (tmpl->direction == direction) {
1323 caps = gst_static_pad_template_get_caps (tmpl);
1329 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1330 type_name, GST_OBJECT_NAME (factory));
1334 caps = gst_caps_make_writable (caps);
1335 num = gst_caps_get_size (caps);
1336 for (i = 0; i < num; ++i) {
1340 s = gst_caps_get_structure (caps, i);
1341 /* remove fields that are almost always just MIN-MAX of some sort
1342 * in order to make the caps look less messy */
1343 gst_structure_remove_field (s, "pixel-aspect-ratio");
1344 gst_structure_remove_field (s, "framerate");
1345 gst_structure_remove_field (s, "channels");
1346 gst_structure_remove_field (s, "width");
1347 gst_structure_remove_field (s, "height");
1348 gst_structure_remove_field (s, "rate");
1349 gst_structure_remove_field (s, "depth");
1350 gst_structure_remove_field (s, "clock-rate");
1351 s_str = gst_structure_to_string (s);
1352 g_print ("%s-%s\n", type_name, s_str);
1355 gst_caps_unref (caps);
1359 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1361 const gchar *const *protocols;
1363 protocols = gst_element_factory_get_uri_protocols (factory);
1364 if (protocols != NULL && *protocols != NULL) {
1365 switch (gst_element_factory_get_uri_type (factory)) {
1367 while (*protocols != NULL) {
1368 g_print ("urisink-%s\n", *protocols);
1373 while (*protocols != NULL) {
1374 g_print ("urisource-%s\n", *protocols);
1385 print_plugin_automatic_install_info (GstPlugin * plugin)
1387 GList *features, *l;
1389 /* not interested in typefind factories, only element factories */
1390 features = gst_registry_get_feature_list (gst_registry_get (),
1391 GST_TYPE_ELEMENT_FACTORY);
1393 for (l = features; l != NULL; l = l->next) {
1394 GstPluginFeature *feature;
1395 GstPlugin *feature_plugin;
1397 feature = GST_PLUGIN_FEATURE (l->data);
1399 /* only interested in the ones that are in the plugin we just loaded */
1400 feature_plugin = gst_plugin_feature_get_plugin (feature);
1401 if (feature_plugin == plugin) {
1402 GstElementFactory *factory;
1404 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1406 factory = GST_ELEMENT_FACTORY (feature);
1407 print_plugin_automatic_install_info_protocols (factory);
1408 print_plugin_automatic_install_info_codecs (factory);
1411 gst_object_unref (feature_plugin);
1414 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1415 g_list_free (features);
1419 print_all_plugin_automatic_install_info (void)
1421 GList *plugins, *orig_plugins;
1423 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1427 plugin = (GstPlugin *) (plugins->data);
1428 plugins = g_list_next (plugins);
1430 print_plugin_automatic_install_info (plugin);
1432 gst_plugin_list_free (orig_plugins);
1436 main (int argc, char *argv[])
1438 gboolean print_all = FALSE;
1439 gboolean do_print_blacklist = FALSE;
1440 gboolean plugin_name = FALSE;
1441 gboolean print_aii = FALSE;
1442 gboolean uri_handlers = FALSE;
1443 gboolean check_exists = FALSE;
1444 gchar *min_version = NULL;
1445 guint minver_maj = GST_VERSION_MAJOR;
1446 guint minver_min = GST_VERSION_MINOR;
1447 guint minver_micro = 0;
1448 #ifndef GST_DISABLE_OPTION_PARSING
1449 GOptionEntry options[] = {
1450 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1451 N_("Print all elements"), NULL},
1452 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1453 N_("Print list of blacklisted files"), NULL},
1454 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1455 N_("Print a machine-parsable list of features the specified plugin "
1456 "or all plugins provide.\n "
1457 "Useful in connection with external automatic plugin "
1458 "installation mechanisms"), NULL},
1459 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1460 N_("List the plugin contents"), NULL},
1461 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1462 N_("Check if the specified element or plugin exists"), NULL},
1463 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1465 ("When checking if an element or plugin exists, also check that its "
1466 "version is at least the version specified"), NULL},
1467 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1469 ("Print supported URI schemes, with the elements that implement them"),
1471 GST_TOOLS_GOPTION_VERSION,
1474 GOptionContext *ctx;
1479 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1480 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1481 textdomain (GETTEXT_PACKAGE);
1484 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1486 #ifndef GST_DISABLE_OPTION_PARSING
1487 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1488 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1489 g_option_context_add_group (ctx, gst_init_get_option_group ());
1490 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1491 g_printerr ("Error initializing: %s\n", err->message);
1494 g_option_context_free (ctx);
1496 gst_init (&argc, &argv);
1499 gst_tools_print_version ();
1501 if (print_all && argc > 1) {
1502 g_printerr ("-a requires no extra arguments\n");
1506 if (uri_handlers && argc > 1) {
1507 g_printerr ("-u requires no extra arguments\n");
1511 /* --atleast-version implies --exists */
1512 if (min_version != NULL) {
1513 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1514 &minver_micro) < 2) {
1515 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1519 check_exists = TRUE;
1526 g_printerr ("--exists requires an extra command line argument\n");
1530 GstPluginFeature *feature;
1532 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1533 if (feature != NULL && gst_plugin_feature_check_version (feature,
1534 minver_maj, minver_min, minver_micro)) {
1540 /* FIXME: support checking for plugins too */
1541 g_printerr ("Checking for plugins is not supported yet\n");
1548 /* if no arguments, print out list of elements */
1550 print_all_uri_handlers ();
1551 } else if (argc == 1 || print_all) {
1552 if (do_print_blacklist)
1556 print_all_plugin_automatic_install_info ();
1558 print_element_list (print_all);
1561 /* else we try to get a factory */
1562 GstElementFactory *factory;
1564 const char *arg = argv[argc - 1];
1568 factory = gst_element_factory_find (arg);
1570 /* if there's a factory, print out the info */
1572 retval = print_element_info (factory, print_all);
1573 gst_object_unref (factory);
1575 retval = print_element_features (arg);
1581 /* otherwise check if it's a plugin */
1583 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1585 /* if there is such a plugin, print out info */
1588 print_plugin_automatic_install_info (plugin);
1590 print_plugin_info (plugin);
1591 print_plugin_features (plugin);
1594 GError *error = NULL;
1596 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1597 plugin = gst_plugin_load_file (arg, &error);
1601 print_plugin_automatic_install_info (plugin);
1603 print_plugin_info (plugin);
1604 print_plugin_features (plugin);
1607 g_printerr (_("Could not load plugin file: %s\n"), error->message);
1608 g_error_free (error);
1612 g_printerr (_("No such element or plugin '%s'\n"), arg);