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);
103 print_formats (const GstFormat * formats)
105 while (formats && *formats) {
106 const GstFormatDefinition *definition;
108 definition = gst_format_get_details (*formats);
110 n_print ("\t\t(%d):\t%s (%s)\n", *formats,
111 definition->nick, definition->description);
113 n_print ("\t\t(%d):\tUnknown format\n", *formats);
120 print_event_masks (const GstEventMask * masks)
125 GFlagsClass *flags_class = NULL;
127 event_type = gst_event_type_get_type ();
128 klass = (GEnumClass *) g_type_class_ref (event_type);
130 while (masks && masks->type) {
132 gint flags = 0, index = 0;
134 switch (masks->type) {
136 flags = masks->flags;
137 event_flags = gst_seek_type_get_type ();
138 flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
144 value = g_enum_get_value (klass, masks->type);
145 g_print ("\t\t%s ", value->value_nick);
151 value = g_flags_get_first_value (flags_class, 1 << index);
154 g_print ("| %s ", value->value_nick);
169 get_rank_name (char *s, gint rank)
171 static const int ranks[4] = {
172 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
174 static const char *rank_names[4] = { "none", "marginal", "secondary",
181 for (i = 0; i < 4; i++) {
182 if (rank == ranks[i])
183 return rank_names[i];
184 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
189 sprintf (s, "%s %c %d", rank_names[best_i],
190 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
196 print_factory_details_info (GstElementFactory * factory)
202 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
203 n_print ("Factory Details:\n");
204 n_print (" %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
206 keys = gst_element_factory_get_metadata_keys (factory);
208 for (k = keys; *k != NULL; ++k) {
212 val = gst_element_factory_get_metadata (factory, key);
213 key[0] = g_ascii_toupper (key[0]);
214 n_print (" %-25s%s\n", key, val);
222 print_hierarchy (GType type, gint level, gint * maxlevel)
227 parent = g_type_parent (type);
229 *maxlevel = *maxlevel + 1;
233 print_hierarchy (parent, level, maxlevel);
236 g_print ("%s", _name);
238 for (i = 1; i < *maxlevel - level; i++)
240 if (*maxlevel - level)
243 g_print ("%s\n", g_type_name (type));
250 print_interfaces (GType type)
253 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
258 g_print ("%s", _name);
259 g_print (_("Implemented Interfaces:\n"));
263 g_print ("%s", _name);
264 g_print (" %s\n", g_type_name (*iface));
268 g_print ("%s", _name);
276 flags_to_string (GFlagsValue * vals, guint flags)
281 /* first look for an exact match and count the number of values */
282 for (i = 0; vals[i].value_name != NULL; ++i) {
283 if (vals[i].value == flags)
284 return g_strdup (vals[i].value_nick);
287 s = g_string_new (NULL);
289 /* we assume the values are sorted from lowest to highest value */
293 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
295 g_string_append_c (s, '+');
296 g_string_append (s, vals[i].value_nick);
297 flags_left -= vals[i].value;
304 g_string_assign (s, "(none)");
306 return g_string_free (s, FALSE);
309 #define KNOWN_PARAM_FLAGS \
310 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
311 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
312 G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
313 GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
314 GST_PARAM_MUTABLE_READY)
317 print_element_properties_info (GstElement * element)
319 GParamSpec **property_specs;
320 guint num_properties, i;
324 property_specs = g_object_class_list_properties
325 (G_OBJECT_GET_CLASS (element), &num_properties);
327 n_print ("Element Properties:\n");
329 for (i = 0; i < num_properties; i++) {
330 GValue value = { 0, };
331 GParamSpec *param = property_specs[i];
335 g_value_init (&value, param->value_type);
337 n_print (" %-20s: %s\n", g_param_spec_get_name (param),
338 g_param_spec_get_blurb (param));
341 n_print ("%-23.23s flags: ", "");
342 if (param->flags & G_PARAM_READABLE) {
343 g_object_get_property (G_OBJECT (element), param->name, &value);
345 g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
348 /* if we can't read the property value, assume it's set to the default
349 * (which might not be entirely true for sub-classes, but that's an
350 * unlikely corner-case anyway) */
351 g_param_value_set_default (param, &value);
353 if (param->flags & G_PARAM_WRITABLE) {
354 g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
357 if (param->flags & GST_PARAM_CONTROLLABLE) {
358 g_print (", %s", _("controllable"));
361 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
362 g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
363 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
364 g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
365 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
366 g_print (", %s", _("changeable only in NULL or READY state"));
368 if (param->flags & ~KNOWN_PARAM_FLAGS) {
369 g_print ("%s0x%0x", (first_flag) ? "" : ", ",
370 param->flags & ~KNOWN_PARAM_FLAGS);
374 switch (G_VALUE_TYPE (&value)) {
377 const char *string_val = g_value_get_string (&value);
379 n_print ("%-23.23s String. ", "");
381 if (string_val == NULL)
382 g_print ("Default: null");
384 g_print ("Default: \"%s\"", string_val);
389 gboolean bool_val = g_value_get_boolean (&value);
391 n_print ("%-23.23s Boolean. ", "");
393 g_print ("Default: %s", bool_val ? "true" : "false");
398 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
400 n_print ("%-23.23s Unsigned Long. ", "");
401 g_print ("Range: %lu - %lu Default: %lu ",
402 pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
404 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
405 "uint/uint64", GST_OBJECT_NAME (element),
406 g_param_spec_get_name (param));
411 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
413 n_print ("%-23.23s Long. ", "");
414 g_print ("Range: %ld - %ld Default: %ld ",
415 plong->minimum, plong->maximum, g_value_get_long (&value));
417 GST_ERROR ("%s: property '%s' of type long: consider changing to "
418 "int/int64", GST_OBJECT_NAME (element),
419 g_param_spec_get_name (param));
424 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
426 n_print ("%-23.23s Unsigned Integer. ", "");
427 g_print ("Range: %u - %u Default: %u ",
428 puint->minimum, puint->maximum, g_value_get_uint (&value));
433 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
435 n_print ("%-23.23s Integer. ", "");
436 g_print ("Range: %d - %d Default: %d ",
437 pint->minimum, pint->maximum, g_value_get_int (&value));
442 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
444 n_print ("%-23.23s Unsigned Integer64. ", "");
445 g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
446 " Default: %" G_GUINT64_FORMAT " ",
447 puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
452 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
454 n_print ("%-23.23s Integer64. ", "");
455 g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
456 " Default: %" G_GINT64_FORMAT " ",
457 pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
462 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
464 n_print ("%-23.23s Float. ", "");
465 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
466 pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
471 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
473 n_print ("%-23.23s Double. ", "");
474 g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
475 pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
480 GST_ERROR ("%s: property '%s' of type char: consider changing to "
481 "int/string", GST_OBJECT_NAME (element),
482 g_param_spec_get_name (param));
485 if (param->value_type == GST_TYPE_CAPS) {
486 const GstCaps *caps = gst_value_get_caps (&value);
489 n_print ("%-23.23s Caps (NULL)", "");
491 print_caps (caps, " ");
493 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
497 const gchar *value_nick = "";
499 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
500 enum_value = g_value_get_enum (&value);
502 while (values[j].value_name) {
503 if (values[j].value == enum_value)
504 value_nick = values[j].value_nick;
508 n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
509 g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
512 while (values[j].value_name) {
515 g_print ("%s", _name);
516 g_print ("%-23.23s (%d): %-16s - %s", "",
517 values[j].value, values[j].value_nick, values[j].value_name);
520 /* g_type_class_unref (ec); */
521 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
522 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
526 vals = pflags->flags_class->values;
528 cur = flags_to_string (vals, g_value_get_flags (&value));
530 n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
531 g_type_name (G_VALUE_TYPE (&value)),
532 g_value_get_flags (&value), cur);
534 while (vals[0].value_name) {
537 g_print ("%s", _name);
538 g_print ("%-23.23s (0x%08x): %-16s - %s", "",
539 vals[0].value, vals[0].value_nick, vals[0].value_name);
544 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
545 n_print ("%-23.23s Object of type \"%s\"", "",
546 g_type_name (param->value_type));
547 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
548 n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
549 g_type_name (param->value_type));
550 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
551 if (param->value_type != G_TYPE_POINTER) {
552 n_print ("%-23.23s Pointer of type \"%s\".", "",
553 g_type_name (param->value_type));
555 n_print ("%-23.23s Pointer.", "");
557 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
558 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
560 if (pvarray->element_spec) {
561 n_print ("%-23.23s Array of GValues of type \"%s\"", "",
562 g_type_name (pvarray->element_spec->value_type));
564 n_print ("%-23.23s Array of GValues", "");
566 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
567 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
569 n_print ("%-23.23s Fraction. ", "");
571 g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
572 pfraction->min_num, pfraction->min_den,
573 pfraction->max_num, pfraction->max_den,
574 gst_value_get_fraction_numerator (&value),
575 gst_value_get_fraction_denominator (&value));
577 n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
578 g_type_name (param->value_type));
583 g_print (" Write only\n");
587 g_value_reset (&value);
589 if (num_properties == 0)
592 g_free (property_specs);
596 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
598 GstElementClass *gstelement_class;
600 GstStaticPadTemplate *padtemplate;
602 n_print ("Pad Templates:\n");
603 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
608 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
610 pads = gst_element_factory_get_static_pad_templates (factory);
612 padtemplate = (GstStaticPadTemplate *) (pads->data);
613 pads = g_list_next (pads);
615 if (padtemplate->direction == GST_PAD_SRC)
616 n_print (" SRC template: '%s'\n", padtemplate->name_template);
617 else if (padtemplate->direction == GST_PAD_SINK)
618 n_print (" SINK template: '%s'\n", padtemplate->name_template);
620 n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
622 if (padtemplate->presence == GST_PAD_ALWAYS)
623 n_print (" Availability: Always\n");
624 else if (padtemplate->presence == GST_PAD_SOMETIMES)
625 n_print (" Availability: Sometimes\n");
626 else if (padtemplate->presence == GST_PAD_REQUEST) {
627 n_print (" Availability: On request\n");
628 n_print (" Has request_new_pad() function: %s\n",
629 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
631 n_print (" Availability: UNKNOWN!!!\n");
633 if (padtemplate->static_caps.string) {
634 n_print (" Capabilities:\n");
635 print_caps (gst_static_caps_get (&padtemplate->static_caps), " ");
643 print_element_flag_info (GstElement * element)
645 gboolean have_flags = FALSE;
648 n_print ("Element Flags:\n");
651 n_print (" no flags set\n");
653 if (GST_IS_BIN (element)) {
655 n_print ("Bin Flags:\n");
657 n_print (" no flags set\n");
662 print_implementation_info (GstElement * element)
664 GstElementClass *gstelement_class;
666 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
669 n_print ("Element Implementation:\n");
671 n_print (" Has change_state() function: %s\n",
672 GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
676 print_clocking_info (GstElement * element)
678 gboolean requires_clock, provides_clock;
681 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
683 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
685 if (!requires_clock && !provides_clock) {
687 n_print ("Element has no clocking capabilities.");
692 n_print ("Clocking Interaction:\n");
693 if (requires_clock) {
694 n_print (" element requires a clock\n");
697 if (provides_clock) {
700 clock = gst_element_get_clock (element);
702 n_print (" element provides a clock: %s\n", GST_OBJECT_NAME (clock));
703 gst_object_unref (clock);
705 n_print (" element is supposed to provide a clock but returned NULL\n");
710 print_index_info (GstElement * element)
712 if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
714 n_print ("Indexing capabilities:\n");
715 n_print (" element can do indexing\n");
718 n_print ("Element has no indexing capabilities.\n");
723 print_uri_handler_info (GstElement * element)
725 if (GST_IS_URI_HANDLER (element)) {
726 const gchar *const *uri_protocols;
727 const gchar *uri_type;
729 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
731 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
735 uri_type = "unknown";
737 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
740 n_print ("URI handling capabilities:\n");
741 n_print (" Element can act as %s.\n", uri_type);
743 if (uri_protocols && *uri_protocols) {
744 n_print (" Supported URI protocols:\n");
745 for (; *uri_protocols != NULL; uri_protocols++)
746 n_print (" %s\n", *uri_protocols);
748 n_print (" No supported URI protocols\n");
751 n_print ("Element has no URI handling capabilities.\n");
756 print_pad_info (GstElement * element)
764 if (!element->numpads) {
769 pads = element->pads;
774 pad = GST_PAD (pads->data);
775 pads = g_list_next (pads);
779 name = gst_pad_get_name (pad);
780 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
781 g_print (" SRC: '%s'", name);
782 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
783 g_print (" SINK: '%s'", name);
785 g_print (" UNKNOWN!!!: '%s'", name);
791 n_print (" Implementation:\n");
793 n_print (" Has chainfunc(): %s\n",
794 GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
795 if (pad->getrangefunc)
796 n_print (" Has getrangefunc(): %s\n",
797 GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
798 if (pad->eventfunc != gst_pad_event_default)
799 n_print (" Has custom eventfunc(): %s\n",
800 GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
801 if (pad->queryfunc != gst_pad_query_default)
802 n_print (" Has custom queryfunc(): %s\n",
803 GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
805 if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
806 n_print (" Has custom iterintlinkfunc(): %s\n",
807 GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
809 if (pad->padtemplate)
810 n_print (" Pad Template: '%s'\n", pad->padtemplate->name_template);
812 caps = gst_pad_get_current_caps (pad);
814 n_print (" Capabilities:\n");
815 print_caps (caps, " ");
816 gst_caps_unref (caps);
822 has_sometimes_template (GstElement * element)
824 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
827 for (l = klass->padtemplates; l != NULL; l = l->next) {
828 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
836 print_signal_info (GstElement * element)
838 /* Signals/Actions Block */
842 GSignalQuery *query = NULL;
844 GSList *found_signals, *l;
846 for (k = 0; k < 2; k++) {
847 found_signals = NULL;
849 /* For elements that have sometimes pads, also list a few useful GstElement
850 * signals. Put these first, so element-specific ones come later. */
851 if (k == 0 && has_sometimes_template (element)) {
852 query = g_new0 (GSignalQuery, 1);
853 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
854 found_signals = g_slist_append (found_signals, query);
855 query = g_new0 (GSignalQuery, 1);
856 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
857 found_signals = g_slist_append (found_signals, query);
858 query = g_new0 (GSignalQuery, 1);
859 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
861 found_signals = g_slist_append (found_signals, query);
864 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
865 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
868 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
871 signals = g_signal_list_ids (type, &nsignals);
872 for (i = 0; i < nsignals; i++) {
873 query = g_new0 (GSignalQuery, 1);
874 g_signal_query (signals[i], query);
876 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
877 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
878 found_signals = g_slist_append (found_signals, query);
889 n_print ("Element Signals:\n");
891 n_print ("Element Actions:\n");
896 for (l = found_signals; l; l = l->next) {
901 query = (GSignalQuery *) l->data;
902 indent_len = strlen (query->signal_name) +
903 strlen (g_type_name (query->return_type)) + 24;
906 if (query->return_type == G_TYPE_POINTER) {
908 } else if (G_TYPE_FUNDAMENTAL (query->return_type) == G_TYPE_POINTER
909 || G_TYPE_IS_BOXED (query->return_type)
910 || G_TYPE_IS_OBJECT (query->return_type)) {
917 indent = g_new0 (gchar, indent_len + 1);
918 memset (indent, ' ', indent_len);
920 n_print (" \"%s\" : %s %suser_function (%s* object",
921 query->signal_name, g_type_name (query->return_type), pmark,
924 for (j = 0; j < query->n_params; j++) {
926 if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
927 n_print ("%s%s arg%d", indent,
928 g_type_name (query->param_types[j]), j);
929 } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
930 n_print ("%s%s arg%d", indent,
931 g_type_name (query->param_types[j]), j);
933 n_print ("%s%s* arg%d", indent,
934 g_type_name (query->param_types[j]), j);
940 n_print ("%sgpointer user_data);\n", indent);
948 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
949 g_slist_free (found_signals);
955 print_children_info (GstElement * element)
959 if (!GST_IS_BIN (element))
962 children = (GList *) GST_BIN (element)->children;
965 n_print ("Children:\n");
969 n_print (" %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
970 children = g_list_next (children);
975 print_blacklist (void)
977 GList *plugins, *cur;
980 g_print ("%s\n", _("Blacklisted files:"));
982 plugins = gst_registry_get_plugin_list (gst_registry_get ());
983 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
984 GstPlugin *plugin = (GstPlugin *) (cur->data);
985 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
986 g_print (" %s\n", gst_plugin_get_name (plugin));
992 g_print (_("Total count: "));
993 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
996 gst_plugin_list_free (plugins);
1000 print_element_list (gboolean print_all)
1002 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1003 GList *plugins, *orig_plugins;
1005 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1007 GList *features, *orig_features;
1010 plugin = (GstPlugin *) (plugins->data);
1011 plugins = g_list_next (plugins);
1014 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1019 orig_features = features =
1020 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1021 gst_plugin_get_name (plugin));
1023 GstPluginFeature *feature;
1025 if (G_UNLIKELY (features->data == NULL))
1027 feature = GST_PLUGIN_FEATURE (features->data);
1030 if (GST_IS_ELEMENT_FACTORY (feature)) {
1031 GstElementFactory *factory;
1033 factory = GST_ELEMENT_FACTORY (feature);
1035 print_element_info (factory, TRUE);
1037 g_print ("%s: %s: %s\n", gst_plugin_get_name (plugin),
1038 GST_OBJECT_NAME (factory),
1039 gst_element_factory_get_metadata (factory,
1040 GST_ELEMENT_METADATA_LONGNAME));
1042 } else if (GST_IS_INDEX_FACTORY (feature)) {
1043 GstIndexFactory *factory;
1045 factory = GST_INDEX_FACTORY (feature);
1047 g_print ("%s: %s: %s\n", plugin->desc.name,
1048 GST_OBJECT_NAME (factory), factory->longdesc);
1050 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1051 GstTypeFindFactory *factory;
1052 const gchar *const *extensions;
1054 factory = GST_TYPE_FIND_FACTORY (feature);
1056 g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1057 gst_plugin_feature_get_name (feature));
1059 extensions = gst_type_find_factory_get_extensions (factory);
1060 if (extensions != NULL) {
1063 while (extensions[i]) {
1065 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1072 g_print ("no extensions\n");
1076 n_print ("%s: %s (%s)\n", gst_plugin_get_name (plugin),
1077 GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1081 features = g_list_next (features);
1084 gst_plugin_feature_list_free (orig_features);
1087 gst_plugin_list_free (orig_plugins);
1090 g_print (_("Total count: "));
1091 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1092 if (blacklistcount) {
1094 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1095 blacklistcount), blacklistcount);
1096 g_print (" not shown)");
1099 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1104 print_all_uri_handlers (void)
1106 GList *plugins, *p, *features, *f;
1108 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1110 for (p = plugins; p; p = p->next) {
1111 GstPlugin *plugin = (GstPlugin *) (p->data);
1114 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1115 gst_plugin_get_name (plugin));
1117 for (f = features; f; f = f->next) {
1118 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1120 if (GST_IS_ELEMENT_FACTORY (feature)) {
1121 GstElementFactory *factory;
1122 GstElement *element;
1124 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1126 g_print ("element plugin %s couldn't be loaded\n",
1127 gst_plugin_get_name (plugin));
1131 element = gst_element_factory_create (factory, NULL);
1133 g_print ("couldn't construct element for %s for some reason\n",
1134 GST_OBJECT_NAME (factory));
1135 gst_object_unref (factory);
1139 if (GST_IS_URI_HANDLER (element)) {
1140 const gchar *const *uri_protocols;
1144 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1157 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1158 joined = g_strjoinv (", ", (gchar **) uri_protocols);
1160 g_print ("%s (%s, rank %u): %s\n",
1161 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1162 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1168 gst_object_unref (element);
1169 gst_object_unref (factory);
1173 gst_plugin_feature_list_free (features);
1176 gst_plugin_list_free (plugins);
1180 print_plugin_info (GstPlugin * plugin)
1182 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1183 const gchar *filename = gst_plugin_get_filename (plugin);
1185 n_print ("Plugin Details:\n");
1186 n_print (" %-25s%s\n", "Name", gst_plugin_get_name (plugin));
1187 n_print (" %-25s%s\n", "Description", gst_plugin_get_description (plugin));
1188 n_print (" %-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1189 n_print (" %-25s%s\n", "Version", gst_plugin_get_version (plugin));
1190 n_print (" %-25s%s\n", "License", gst_plugin_get_license (plugin));
1191 n_print (" %-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1193 if (release_date != NULL) {
1194 const gchar *tz = "(UTC)";
1197 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1198 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1199 str = g_strdup (release_date);
1200 sep = strstr (str, "T");
1203 sep = strstr (sep + 1, "Z");
1209 n_print (" %-25s%s%s\n", "Source release date", str, tz);
1212 n_print (" %-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1213 n_print (" %-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1218 print_plugin_features (GstPlugin * plugin)
1220 GList *features, *origlist;
1221 gint num_features = 0;
1222 gint num_elements = 0;
1223 gint num_typefinders = 0;
1224 gint num_indexes = 0;
1227 origlist = features =
1228 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1229 gst_plugin_get_name (plugin));
1232 GstPluginFeature *feature;
1234 feature = GST_PLUGIN_FEATURE (features->data);
1236 if (GST_IS_ELEMENT_FACTORY (feature)) {
1237 GstElementFactory *factory;
1239 factory = GST_ELEMENT_FACTORY (feature);
1240 n_print (" %s: %s\n", GST_OBJECT_NAME (factory),
1241 gst_element_factory_get_metadata (factory,
1242 GST_ELEMENT_METADATA_LONGNAME));
1245 } else if (GST_IS_INDEX_FACTORY (feature)) {
1246 GstIndexFactory *factory;
1248 factory = GST_INDEX_FACTORY (feature);
1249 n_print (" %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1252 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1253 GstTypeFindFactory *factory;
1254 const gchar *const *extensions;
1256 factory = GST_TYPE_FIND_FACTORY (feature);
1257 extensions = gst_type_find_factory_get_extensions (factory);
1261 g_print (" %s: %s: ", gst_plugin_get_name (plugin),
1262 gst_plugin_feature_get_name (feature));
1263 while (extensions[i]) {
1264 g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1269 g_print (" %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1270 gst_plugin_feature_get_name (feature));
1273 } else if (feature) {
1274 n_print (" %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1275 g_type_name (G_OBJECT_TYPE (feature)));
1279 features = g_list_next (features);
1282 gst_plugin_feature_list_free (origlist);
1285 n_print (" %d features:\n", num_features);
1286 if (num_elements > 0)
1287 n_print (" +-- %d elements\n", num_elements);
1288 if (num_typefinders > 0)
1289 n_print (" +-- %d typefinders\n", num_typefinders);
1290 if (num_indexes > 0)
1291 n_print (" +-- %d indexes\n", num_indexes);
1293 n_print (" +-- %d other objects\n", num_other);
1299 print_element_features (const gchar * element_name)
1301 GstPluginFeature *feature;
1303 /* FIXME implement other pretty print function for these */
1305 feature = gst_default_registry_find_feature (element_name,
1306 GST_TYPE_INDEX_FACTORY);
1308 n_print ("%s: an index\n", element_name);
1312 feature = gst_registry_find_feature (gst_registry_get (), element_name,
1313 GST_TYPE_TYPE_FIND_FACTORY);
1315 n_print ("%s: a typefind function\n", element_name);
1323 print_element_info (GstElementFactory * factory, gboolean print_names)
1325 GstElement *element;
1330 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1334 g_print ("element plugin couldn't be loaded\n");
1338 element = gst_element_factory_create (factory, NULL);
1340 gst_object_unref (factory);
1341 g_print ("couldn't construct element for some reason\n");
1346 _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1350 print_factory_details_info (factory);
1352 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1354 print_plugin_info (plugin);
1355 gst_object_unref (plugin);
1358 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1359 print_interfaces (G_OBJECT_TYPE (element));
1361 print_pad_templates_info (element, factory);
1362 print_element_flag_info (element);
1363 print_implementation_info (element);
1364 print_clocking_info (element);
1365 print_index_info (element);
1366 print_uri_handler_info (element);
1367 print_pad_info (element);
1368 print_element_properties_info (element);
1369 print_signal_info (element);
1370 print_children_info (element);
1372 gst_object_unref (element);
1373 gst_object_unref (factory);
1381 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1383 GstPadDirection direction;
1384 const gchar *type_name;
1386 const GList *static_templates, *l;
1387 GstCaps *caps = NULL;
1391 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1392 g_return_if_fail (klass != NULL);
1394 if (strstr (klass, "Demuxer") ||
1395 strstr (klass, "Decoder") ||
1396 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1397 type_name = "decoder";
1398 direction = GST_PAD_SINK;
1399 } else if (strstr (klass, "Muxer") ||
1400 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1401 type_name = "encoder";
1402 direction = GST_PAD_SRC;
1407 /* decoder/demuxer sink pads should always be static and there should only
1408 * be one, the same applies to encoders/muxers and source pads */
1409 static_templates = gst_element_factory_get_static_pad_templates (factory);
1410 for (l = static_templates; l != NULL; l = l->next) {
1411 GstStaticPadTemplate *tmpl = NULL;
1413 tmpl = (GstStaticPadTemplate *) l->data;
1414 if (tmpl->direction == direction) {
1415 caps = gst_static_pad_template_get_caps (tmpl);
1421 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1422 type_name, GST_OBJECT_NAME (factory));
1426 caps = gst_caps_make_writable (caps);
1427 num = gst_caps_get_size (caps);
1428 for (i = 0; i < num; ++i) {
1432 s = gst_caps_get_structure (caps, i);
1433 /* remove fields that are almost always just MIN-MAX of some sort
1434 * in order to make the caps look less messy */
1435 gst_structure_remove_field (s, "pixel-aspect-ratio");
1436 gst_structure_remove_field (s, "framerate");
1437 gst_structure_remove_field (s, "channels");
1438 gst_structure_remove_field (s, "width");
1439 gst_structure_remove_field (s, "height");
1440 gst_structure_remove_field (s, "rate");
1441 gst_structure_remove_field (s, "depth");
1442 gst_structure_remove_field (s, "clock-rate");
1443 s_str = gst_structure_to_string (s);
1444 g_print ("%s-%s\n", type_name, s_str);
1447 gst_caps_unref (caps);
1451 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1453 const gchar *const *protocols;
1455 protocols = gst_element_factory_get_uri_protocols (factory);
1456 if (protocols != NULL && *protocols != NULL) {
1457 switch (gst_element_factory_get_uri_type (factory)) {
1459 while (*protocols != NULL) {
1460 g_print ("urisink-%s\n", *protocols);
1465 while (*protocols != NULL) {
1466 g_print ("urisource-%s\n", *protocols);
1477 print_plugin_automatic_install_info (GstPlugin * plugin)
1479 GList *features, *l;
1481 /* not interested in typefind factories, only element factories */
1482 features = gst_registry_get_feature_list (gst_registry_get (),
1483 GST_TYPE_ELEMENT_FACTORY);
1485 for (l = features; l != NULL; l = l->next) {
1486 GstPluginFeature *feature;
1487 GstPlugin *feature_plugin;
1489 feature = GST_PLUGIN_FEATURE (l->data);
1491 /* only interested in the ones that are in the plugin we just loaded */
1492 feature_plugin = gst_plugin_feature_get_plugin (feature);
1493 if (feature_plugin == plugin) {
1494 GstElementFactory *factory;
1496 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1498 factory = GST_ELEMENT_FACTORY (feature);
1499 print_plugin_automatic_install_info_protocols (factory);
1500 print_plugin_automatic_install_info_codecs (factory);
1503 gst_object_unref (feature_plugin);
1506 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1507 g_list_free (features);
1511 print_all_plugin_automatic_install_info (void)
1513 GList *plugins, *orig_plugins;
1515 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1519 plugin = (GstPlugin *) (plugins->data);
1520 plugins = g_list_next (plugins);
1522 print_plugin_automatic_install_info (plugin);
1524 gst_plugin_list_free (orig_plugins);
1528 main (int argc, char *argv[])
1530 gboolean print_all = FALSE;
1531 gboolean do_print_blacklist = FALSE;
1532 gboolean plugin_name = FALSE;
1533 gboolean print_aii = FALSE;
1534 gboolean uri_handlers = FALSE;
1535 gboolean check_exists = FALSE;
1536 gchar *min_version = NULL;
1537 guint minver_maj = GST_VERSION_MAJOR;
1538 guint minver_min = GST_VERSION_MINOR;
1539 guint minver_micro = 0;
1540 #ifndef GST_DISABLE_OPTION_PARSING
1541 GOptionEntry options[] = {
1542 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1543 N_("Print all elements"), NULL},
1544 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1545 N_("Print list of blacklisted files"), NULL},
1546 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1547 N_("Print a machine-parsable list of features the specified plugin "
1548 "or all plugins provide.\n "
1549 "Useful in connection with external automatic plugin "
1550 "installation mechanisms"), NULL},
1551 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1552 N_("List the plugin contents"), NULL},
1553 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1554 N_("Check if the specified element or plugin exists"), NULL},
1555 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1557 ("When checking if an element or plugin exists, also check that its "
1558 "version is at least the version specified"), NULL},
1559 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1561 ("Print supported URI schemes, with the elements that implement them"),
1563 GST_TOOLS_GOPTION_VERSION,
1566 GOptionContext *ctx;
1571 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1572 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1573 textdomain (GETTEXT_PACKAGE);
1576 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1578 #ifndef GST_DISABLE_OPTION_PARSING
1579 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1580 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1581 g_option_context_add_group (ctx, gst_init_get_option_group ());
1582 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1583 g_printerr ("Error initializing: %s\n", err->message);
1586 g_option_context_free (ctx);
1588 gst_init (&argc, &argv);
1591 gst_tools_print_version ();
1593 if (print_all && argc > 1) {
1594 g_printerr ("-a requires no extra arguments\n");
1598 if (uri_handlers && argc > 1) {
1599 g_printerr ("-u requires no extra arguments\n");
1603 /* --atleast-version implies --exists */
1604 if (min_version != NULL) {
1605 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1606 &minver_micro) < 2) {
1607 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1611 check_exists = TRUE;
1618 g_printerr ("--exists requires an extra command line argument\n");
1622 GstPluginFeature *feature;
1624 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1625 if (feature != NULL && gst_plugin_feature_check_version (feature,
1626 minver_maj, minver_min, minver_micro)) {
1632 /* FIXME: support checking for plugins too */
1633 g_printerr ("Checking for plugins is not supported yet\n");
1640 /* if no arguments, print out list of elements */
1642 print_all_uri_handlers ();
1643 } else if (argc == 1 || print_all) {
1644 if (do_print_blacklist)
1648 print_all_plugin_automatic_install_info ();
1650 print_element_list (print_all);
1653 /* else we try to get a factory */
1654 GstElementFactory *factory;
1656 const char *arg = argv[argc - 1];
1660 factory = gst_element_factory_find (arg);
1662 /* if there's a factory, print out the info */
1664 retval = print_element_info (factory, print_all);
1665 gst_object_unref (factory);
1667 retval = print_element_features (arg);
1673 /* otherwise check if it's a plugin */
1675 plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1677 /* if there is such a plugin, print out info */
1680 print_plugin_automatic_install_info (plugin);
1682 print_plugin_info (plugin);
1683 print_plugin_features (plugin);
1686 GError *error = NULL;
1688 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1689 plugin = gst_plugin_load_file (arg, &error);
1693 print_plugin_automatic_install_info (plugin);
1695 print_plugin_info (plugin);
1696 print_plugin_features (plugin);
1699 g_printerr (_("Could not load plugin file: %s\n"), error->message);
1700 g_error_free (error);
1704 g_printerr (_("No such element or plugin '%s'\n"), arg);