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>
7 * gst-inspect.c: tool to inspect the GStreamer registry
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
29 /* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
30 * with newer GLib versions (>= 2.31.0) */
31 #define GLIB_DISABLE_DEPRECATION_WARNINGS
34 #include <gst/gst_private.h> /* for internal Factories */
38 #include <glib/gprintf.h>
41 # include <sys/wait.h>
44 #define DEFAULT_PAGER "less"
46 /* "R" : support color
47 * "X" : do not clear the screen when leaving the pager
48 * "F" : skip the pager if content fit into the screen
50 #define DEFAULT_LESS_OPTS "RXF"
52 gboolean colored_output = TRUE;
57 GMainLoop *loop = NULL;
61 /* Escape values for colors */
62 #define BLUE "\033[34m"
63 #define BRBLUE "\033[94m"
64 #define BRCYAN "\033[96m"
65 #define BRMAGENTA "\033[95m"
66 #define BRYELLOW "\033[33m"
67 #define CYAN "\033[36m"
68 #define GREEN "\033[32m"
69 #define MAGENTA "\033[35m"
70 #define YELLOW "\033[33m"
73 #define RESET_COLOR (colored_output? "\033[0m": "")
74 #define HEADING_COLOR (colored_output? BRYELLOW : "")
75 #define PROP_NAME_COLOR (colored_output? BRBLUE : "")
76 #define PROP_VALUE_COLOR (colored_output? RESET_COLOR: "")
77 #define PROP_ATTR_NAME_COLOR (colored_output? BRYELLOW : "")
78 #define PROP_ATTR_VALUE_COLOR (colored_output? CYAN: "")
79 /* FIXME: find a good color that works on both dark & light bg. */
80 #define DESC_COLOR (colored_output? RESET_COLOR: "")
82 /* Datatype-related colors */
83 #define DATATYPE_COLOR (colored_output? GREEN : "")
84 #define CHILD_LINK_COLOR (colored_output? BRMAGENTA : "")
87 #define FIELD_NAME_COLOR (colored_output? CYAN: "")
88 #define FIELD_VALUE_COLOR (colored_output? BRBLUE : "")
89 #define CAPS_TYPE_COLOR (colored_output? YELLOW : "")
90 #define STRUCT_NAME_COLOR (colored_output? YELLOW : "")
91 #define CAPS_FEATURE_COLOR (colored_output? GREEN : "")
93 /* Plugin listing colors */
94 #define PLUGIN_NAME_COLOR (colored_output? BRBLUE : "")
95 #define ELEMENT_NAME_COLOR (colored_output? GREEN : "")
96 /* FIXME: find a good color that works on both dark & light bg. */
97 #define ELEMENT_DETAIL_COLOR (colored_output? RESET_COLOR : "")
98 #define PLUGIN_FEATURE_COLOR (colored_output? BRBLUE: "")
100 /* Feature listing colors */
101 #define FEATURE_NAME_COLOR (colored_output? GREEN : "")
102 #define FEATURE_DIR_COLOR (colored_output? BRMAGENTA : "")
103 #define FEATURE_RANK_COLOR (colored_output? CYAN : "")
104 #define FEATURE_PROTO_COLOR (colored_output? BRYELLOW : "")
106 static char *_name = NULL;
107 static int indent = 0;
109 static int print_element_info (GstPluginFeature * feature,
110 gboolean print_names);
111 static int print_typefind_info (GstPluginFeature * feature,
112 gboolean print_names);
113 static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
115 #define push_indent() push_indent_n(1)
116 #define pop_indent() push_indent_n(-1)
117 #define pop_indent_n(n) push_indent_n(-n)
120 push_indent_n (int n)
122 g_assert (n > 0 || indent > 0);
131 n_print (const char *format, ...)
137 g_print ("%s", _name);
139 for (i = 0; i < indent; ++i)
142 va_start (args, format);
143 g_vprintf (format, args);
148 print_field (GQuark field, const GValue * value, gpointer pfx)
150 gchar *str = gst_value_serialize (value);
152 n_print ("%s %s%15s%s: %s%s%s\n",
153 (gchar *) pfx, FIELD_NAME_COLOR, g_quark_to_string (field), RESET_COLOR,
154 FIELD_VALUE_COLOR, str, RESET_COLOR);
160 print_caps (const GstCaps * caps, const gchar * pfx)
164 g_return_if_fail (caps != NULL);
166 if (gst_caps_is_any (caps)) {
167 n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
170 if (gst_caps_is_empty (caps)) {
171 n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
175 for (i = 0; i < gst_caps_get_size (caps); i++) {
176 GstStructure *structure = gst_caps_get_structure (caps, i);
177 GstCapsFeatures *features = gst_caps_get_features (caps, i);
179 if (features && (gst_caps_features_is_any (features) ||
180 !gst_caps_features_is_equal (features,
181 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
182 gchar *features_string = gst_caps_features_to_string (features);
184 n_print ("%s%s%s%s(%s%s%s)\n", pfx, STRUCT_NAME_COLOR,
185 gst_structure_get_name (structure), RESET_COLOR,
186 CAPS_FEATURE_COLOR, features_string, RESET_COLOR);
187 g_free (features_string);
189 n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
190 gst_structure_get_name (structure), RESET_COLOR);
192 gst_structure_foreach (structure, print_field, (gpointer) pfx);
197 get_rank_name (char *s, gint rank)
199 static const int ranks[4] = {
200 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
202 static const char *rank_names[4] = { "none", "marginal", "secondary",
209 for (i = 0; i < 4; i++) {
210 if (rank == ranks[i])
211 return rank_names[i];
212 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
217 sprintf (s, "%s %c %d", rank_names[best_i],
218 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
224 print_factory_details_info (GstElementFactory * factory)
230 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
231 n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
234 n_print ("%s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
235 get_rank_name (s, rank), rank, RESET_COLOR);
237 keys = gst_element_factory_get_metadata_keys (factory);
239 for (k = keys; *k != NULL; ++k) {
243 val = gst_element_factory_get_metadata (factory, key);
244 key[0] = g_ascii_toupper (key[0]);
245 n_print ("%s%-25s%s%s%s\n", PROP_NAME_COLOR, key, PROP_VALUE_COLOR, val,
255 print_hierarchy (GType type, gint level, gint * maxlevel)
260 parent = g_type_parent (type);
262 *maxlevel = *maxlevel + 1;
266 print_hierarchy (parent, level, maxlevel);
269 g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
271 for (i = 1; i < *maxlevel - level; i++)
273 if (*maxlevel - level)
274 g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
276 g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
283 print_interfaces (GType type)
286 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
290 n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
294 n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
305 flags_to_string (GFlagsValue * vals, guint flags)
310 /* first look for an exact match and count the number of values */
311 for (i = 0; vals[i].value_name != NULL; ++i) {
312 if (vals[i].value == flags)
313 return g_strdup (vals[i].value_nick);
316 s = g_string_new (NULL);
318 /* we assume the values are sorted from lowest to highest value */
322 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
324 g_string_append_c (s, '+');
325 g_string_append (s, vals[i].value_nick);
326 flags_left -= vals[i].value;
333 g_string_assign (s, "(none)");
335 return g_string_free (s, FALSE);
338 #define KNOWN_PARAM_FLAGS \
339 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
340 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
341 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
342 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
343 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
346 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
348 return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
351 /* obj will be NULL if we're printing properties of pad template pads */
353 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
356 GParamSpec **property_specs;
357 guint num_properties, i;
361 property_specs = g_object_class_list_properties (obj_class, &num_properties);
362 g_qsort_with_data (property_specs, num_properties, sizeof (gpointer),
363 (GCompareDataFunc) sort_gparamspecs, NULL);
365 n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
369 for (i = 0; i < num_properties; i++) {
370 GValue value = { 0, };
371 GParamSpec *param = property_specs[i];
372 GType owner_type = param->owner_type;
374 /* We're printing pad properties */
375 if (obj == NULL && (owner_type == G_TYPE_OBJECT
376 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
379 g_value_init (&value, param->value_type);
381 n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
382 g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
383 g_param_spec_get_blurb (param), RESET_COLOR);
388 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
389 readable = ! !(param->flags & G_PARAM_READABLE);
390 if (readable && obj != NULL) {
391 g_object_get_property (obj, param->name, &value);
393 /* if we can't read the property value, assume it's set to the default
394 * (which might not be entirely true for sub-classes, but that's an
395 * unlikely corner-case anyway) */
396 g_param_value_set_default (param, &value);
399 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
400 _("readable"), RESET_COLOR);
403 if (param->flags & G_PARAM_WRITABLE) {
404 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
405 _("writable"), RESET_COLOR);
408 if (param->flags & G_PARAM_DEPRECATED) {
409 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
410 _("deprecated"), RESET_COLOR);
413 if (param->flags & GST_PARAM_CONTROLLABLE) {
414 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
418 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
419 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
420 _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
421 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
422 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
423 _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
424 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
425 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
426 _("changeable only in NULL or READY state"), RESET_COLOR);
428 if (param->flags & ~KNOWN_PARAM_FLAGS) {
429 g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
430 param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
434 switch (G_VALUE_TYPE (&value)) {
437 const char *string_val = g_value_get_string (&value);
439 n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
441 if (string_val == NULL)
442 g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
443 PROP_ATTR_VALUE_COLOR, RESET_COLOR);
445 g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
446 PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
451 gboolean bool_val = g_value_get_boolean (&value);
453 n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
454 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
455 PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
460 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
463 ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
464 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
465 PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
466 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
467 PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
469 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
470 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
471 g_param_spec_get_name (param));
476 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
478 n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
479 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
480 PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
481 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
482 g_value_get_long (&value), RESET_COLOR);
484 GST_ERROR ("%s: property '%s' of type long: consider changing to "
485 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
486 g_param_spec_get_name (param));
491 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
494 ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
495 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
496 PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
497 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
498 g_value_get_uint (&value), RESET_COLOR);
503 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
505 n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
506 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
507 PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
508 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
509 g_value_get_int (&value), RESET_COLOR);
514 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
516 n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
517 "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
518 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
519 PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
520 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
521 PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
526 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
528 n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
529 G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
530 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
531 PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
532 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
533 PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
538 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
540 n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
541 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
542 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
543 pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
544 RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
550 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
552 n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
553 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
554 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
555 pdouble->minimum, pdouble->maximum, RESET_COLOR,
556 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
557 g_value_get_double (&value), RESET_COLOR);
562 GST_ERROR ("%s: property '%s' of type char: consider changing to "
563 "int/string", G_OBJECT_CLASS_NAME (obj_class),
564 g_param_spec_get_name (param));
567 if (param->value_type == GST_TYPE_CAPS) {
568 const GstCaps *caps = gst_value_get_caps (&value);
571 n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
573 print_caps (caps, " ");
575 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
579 const gchar *value_nick = "";
581 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
582 enum_value = g_value_get_enum (&value);
584 while (values[j].value_name) {
585 if (values[j].value == enum_value)
586 value_nick = values[j].value_nick;
590 n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
591 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
592 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
593 enum_value, value_nick, RESET_COLOR);
596 while (values[j].value_name) {
598 n_print (" %s(%d)%s: %s%-16s%s - %s%s%s",
599 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
600 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
601 DESC_COLOR, values[j].value_name, RESET_COLOR);
604 /* g_type_class_unref (ec); */
605 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
606 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
610 vals = pflags->flags_class->values;
612 cur = flags_to_string (vals, g_value_get_flags (&value));
614 n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
615 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
616 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
617 g_value_get_flags (&value), cur, RESET_COLOR);
619 while (vals[0].value_name) {
621 n_print (" %s(0x%08x)%s: %s%-16s%s - %s%s%s",
622 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
623 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
624 DESC_COLOR, vals[0].value_name, RESET_COLOR);
629 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
630 n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
631 RESET_COLOR, DATATYPE_COLOR,
632 g_type_name (param->value_type), RESET_COLOR);
633 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
634 n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
635 RESET_COLOR, DATATYPE_COLOR,
636 g_type_name (param->value_type), RESET_COLOR);
637 if (param->value_type == GST_TYPE_STRUCTURE) {
638 const GstStructure *s = gst_value_get_structure (&value);
640 gst_structure_foreach (s, print_field,
643 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
644 if (param->value_type != G_TYPE_POINTER) {
645 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
646 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
649 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
651 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
652 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
654 if (pvarray->element_spec) {
655 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
656 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
657 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
659 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
661 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
662 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
664 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
665 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
666 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
667 pfraction->min_num, pfraction->min_den, pfraction->max_num,
668 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
669 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
670 gst_value_get_fraction_numerator (&value),
671 gst_value_get_fraction_denominator (&value), RESET_COLOR);
672 } else if (param->value_type == GST_TYPE_ARRAY) {
673 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
675 if (parray->element_spec) {
676 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
677 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
678 g_type_name (parray->element_spec->value_type), RESET_COLOR);
680 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
684 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
685 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
686 g_type_name (param->value_type), RESET_COLOR);
691 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
697 g_value_reset (&value);
699 if (num_properties == 0)
700 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
704 g_free (property_specs);
708 print_element_properties_info (GstElement * element)
711 print_object_properties_info (G_OBJECT (element),
712 G_OBJECT_GET_CLASS (element), "Element Properties");
716 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
719 GstStaticPadTemplate *padtemplate;
720 GstPadTemplate *tmpl;
722 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
726 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
727 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
731 pads = gst_element_factory_get_static_pad_templates (factory);
733 padtemplate = (GstStaticPadTemplate *) (pads->data);
734 pads = g_list_next (pads);
736 if (padtemplate->direction == GST_PAD_SRC)
737 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
738 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
739 else if (padtemplate->direction == GST_PAD_SINK)
740 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
741 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
743 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
744 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
748 if (padtemplate->presence == GST_PAD_ALWAYS)
749 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
750 PROP_VALUE_COLOR, RESET_COLOR);
751 else if (padtemplate->presence == GST_PAD_SOMETIMES)
752 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
753 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
754 else if (padtemplate->presence == GST_PAD_REQUEST) {
755 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
756 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
758 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
759 PROP_VALUE_COLOR, RESET_COLOR);
761 if (padtemplate->static_caps.string) {
762 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
764 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
767 print_caps (caps, ""); // FIXME
770 gst_caps_unref (caps);
773 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
774 padtemplate->name_template);
776 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
778 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
781 pad_klass = g_type_class_ref (pad_type);
782 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
783 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
784 print_object_properties_info (NULL, pad_klass, "Pad Properties");
785 g_type_class_unref (pad_klass);
800 print_clocking_info (GstElement * element)
802 gboolean requires_clock, provides_clock;
805 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
807 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
809 if (!requires_clock && !provides_clock) {
811 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
817 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
821 if (requires_clock) {
822 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
825 if (provides_clock) {
828 clock = gst_element_get_clock (element);
830 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
831 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
832 gst_object_unref (clock);
834 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
835 PROP_VALUE_COLOR, RESET_COLOR);
842 print_uri_handler_info (GstElement * element)
844 if (GST_IS_URI_HANDLER (element)) {
845 const gchar *const *uri_protocols;
846 const gchar *uri_type;
848 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
850 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
854 uri_type = "unknown";
856 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
859 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
863 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
865 if (uri_protocols && *uri_protocols) {
866 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
868 for (; *uri_protocols != NULL; uri_protocols++)
869 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
873 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
879 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
885 print_pad_info (GstElement * element)
891 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
895 if (!element->numpads) {
896 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
900 pads = element->pads;
905 pad = GST_PAD (pads->data);
906 pads = g_list_next (pads);
908 name = gst_pad_get_name (pad);
909 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
910 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
911 PROP_VALUE_COLOR, name, RESET_COLOR);
912 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
913 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
914 PROP_VALUE_COLOR, name, RESET_COLOR);
916 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
917 PROP_VALUE_COLOR, name, RESET_COLOR);
921 if (pad->padtemplate) {
923 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
924 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
928 caps = gst_pad_get_current_caps (pad);
930 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
932 print_caps (caps, ""); // FIXME
934 gst_caps_unref (caps);
943 has_sometimes_template (GstElement * element)
945 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
948 for (l = klass->padtemplates; l != NULL; l = l->next) {
949 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
957 gtype_needs_ptr_marker (GType type)
959 if (type == G_TYPE_POINTER)
962 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
963 || G_TYPE_IS_OBJECT (type))
970 print_signal_info (GstElement * element)
972 /* Signals/Actions Block */
976 GSignalQuery *query = NULL;
978 GSList *found_signals, *l;
980 for (k = 0; k < 2; k++) {
981 found_signals = NULL;
983 /* For elements that have sometimes pads, also list a few useful GstElement
984 * signals. Put these first, so element-specific ones come later. */
985 if (k == 0 && has_sometimes_template (element)) {
986 query = g_new0 (GSignalQuery, 1);
987 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
988 found_signals = g_slist_append (found_signals, query);
989 query = g_new0 (GSignalQuery, 1);
990 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
991 found_signals = g_slist_append (found_signals, query);
992 query = g_new0 (GSignalQuery, 1);
993 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
995 found_signals = g_slist_append (found_signals, query);
998 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
999 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1002 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1005 signals = g_signal_list_ids (type, &nsignals);
1006 for (i = 0; i < nsignals; i++) {
1007 query = g_new0 (GSignalQuery, 1);
1008 g_signal_query (signals[i], query);
1010 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1011 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1012 found_signals = g_slist_append (found_signals, query);
1020 if (found_signals) {
1023 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1025 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1030 for (l = found_signals; l; l = l->next) {
1035 query = (GSignalQuery *) l->data;
1036 indent_len = strlen (query->signal_name) +
1037 strlen (g_type_name (query->return_type)) + 24;
1039 if (gtype_needs_ptr_marker (query->return_type)) {
1046 indent = g_new0 (gchar, indent_len + 1);
1047 memset (indent, ' ', indent_len);
1049 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1050 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1051 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1052 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1053 PROP_VALUE_COLOR, RESET_COLOR);
1055 for (j = 0; j < query->n_params; j++) {
1056 const gchar *type_name, *asterisk;
1058 type_name = g_type_name (query->param_types[j]);
1059 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1062 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1063 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1068 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1069 PROP_VALUE_COLOR, RESET_COLOR);
1076 if (found_signals) {
1077 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1078 g_slist_free (found_signals);
1084 print_children_info (GstElement * element)
1088 if (!GST_IS_BIN (element))
1091 children = (GList *) GST_BIN (element)->children;
1094 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1098 n_print (" %s%s%s\n", DATATYPE_COLOR,
1099 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1100 children = g_list_next (children);
1105 print_preset_list (GstElement * element)
1107 gchar **presets, **preset;
1109 if (!GST_IS_PRESET (element))
1112 presets = gst_preset_get_preset_names (GST_PRESET (element));
1113 if (presets && *presets) {
1115 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1116 for (preset = presets; *preset; preset++) {
1117 n_print (" \"%s\"\n", *preset);
1119 g_strfreev (presets);
1124 print_blacklist (void)
1126 GList *plugins, *cur;
1129 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1131 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1132 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1133 GstPlugin *plugin = (GstPlugin *) (cur->data);
1134 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1135 g_print (" %s\n", gst_plugin_get_name (plugin));
1141 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1143 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1145 g_print ("%s\n", RESET_COLOR);
1146 gst_plugin_list_free (plugins);
1150 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1154 while (extensions[i]) {
1155 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1161 print_element_list (gboolean print_all, gchar * ftypes)
1163 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1164 GList *plugins, *orig_plugins;
1165 gchar **types = NULL;
1170 types = g_strsplit (ftypes, "/", -1);
1171 for (i = 0; types[i]; i++)
1172 *types[i] = g_ascii_toupper (*types[i]);
1176 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1178 GList *features, *orig_features;
1181 plugin = (GstPlugin *) (plugins->data);
1182 plugins = g_list_next (plugins);
1185 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1190 orig_features = features =
1191 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1192 gst_plugin_get_name (plugin));
1194 GstPluginFeature *feature;
1196 if (G_UNLIKELY (features->data == NULL))
1198 feature = GST_PLUGIN_FEATURE (features->data);
1201 if (GST_IS_ELEMENT_FACTORY (feature)) {
1203 GstElementFactory *factory;
1205 factory = GST_ELEMENT_FACTORY (feature);
1208 gboolean all_found = TRUE;
1211 gst_element_factory_get_metadata (factory,
1212 GST_ELEMENT_METADATA_KLASS);
1213 for (i = 0; types[i]; i++) {
1214 if (!strstr (klass, types[i])) {
1224 print_element_info (feature, TRUE);
1226 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1227 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1228 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1229 gst_element_factory_get_metadata (factory,
1230 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1231 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1232 GstTypeFindFactory *factory;
1233 const gchar *const *extensions;
1237 factory = GST_TYPE_FIND_FACTORY (feature);
1239 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1240 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1241 gst_plugin_feature_get_name (feature), RESET_COLOR);
1243 extensions = gst_type_find_factory_get_extensions (factory);
1244 if (extensions != NULL) {
1246 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1251 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1257 n_print ("%s%s%s: %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1258 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1259 GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1260 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1264 features = g_list_next (features);
1267 gst_plugin_feature_list_free (orig_features);
1270 gst_plugin_list_free (orig_plugins);
1274 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1276 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1277 if (blacklistcount) {
1279 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1280 blacklistcount), blacklistcount);
1281 g_print (" not shown)");
1283 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1284 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1285 g_print ("%s\n", RESET_COLOR);
1289 print_all_uri_handlers (void)
1291 GList *plugins, *p, *features, *f;
1293 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1295 for (p = plugins; p; p = p->next) {
1296 GstPlugin *plugin = (GstPlugin *) (p->data);
1299 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1300 gst_plugin_get_name (plugin));
1302 for (f = features; f; f = f->next) {
1303 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1305 if (GST_IS_ELEMENT_FACTORY (feature)) {
1306 GstElementFactory *factory;
1307 GstElement *element;
1309 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1311 g_print ("element plugin %s couldn't be loaded\n",
1312 gst_plugin_get_name (plugin));
1316 element = gst_element_factory_create (factory, NULL);
1318 g_print ("couldn't construct element for %s for some reason\n",
1319 GST_OBJECT_NAME (factory));
1320 gst_object_unref (factory);
1324 if (GST_IS_URI_HANDLER (element)) {
1325 const gchar *const *uri_protocols;
1326 const gchar *const *protocol;
1329 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1341 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1343 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1344 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1346 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1350 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1351 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1352 if (protocol != uri_protocols)
1354 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1359 gst_object_unref (element);
1360 gst_object_unref (factory);
1364 gst_plugin_feature_list_free (features);
1367 gst_plugin_list_free (plugins);
1371 print_plugin_info (GstPlugin * plugin)
1373 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1374 const gchar *filename = gst_plugin_get_filename (plugin);
1376 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1380 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1381 PROP_VALUE_COLOR, gst_plugin_get_name (plugin), RESET_COLOR);
1382 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1383 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1384 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1385 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1386 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1387 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1388 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1389 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1390 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1391 PROP_VALUE_COLOR, gst_plugin_get_source (plugin), RESET_COLOR);
1393 if (release_date != NULL) {
1394 const gchar *tz = "(UTC)";
1397 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1398 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1399 str = g_strdup (release_date);
1400 sep = strstr (str, "T");
1403 sep = strstr (sep + 1, "Z");
1409 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1410 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1413 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1414 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1415 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1416 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1424 print_plugin_features (GstPlugin * plugin)
1426 GList *features, *origlist;
1427 gint num_features = 0;
1428 gint num_elements = 0;
1429 gint num_tracers = 0;
1430 gint num_typefinders = 0;
1431 gint num_devproviders = 0;
1434 origlist = features =
1435 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1436 gst_plugin_get_name (plugin));
1439 GstPluginFeature *feature;
1441 feature = GST_PLUGIN_FEATURE (features->data);
1443 if (GST_IS_ELEMENT_FACTORY (feature)) {
1444 GstElementFactory *factory;
1446 factory = GST_ELEMENT_FACTORY (feature);
1447 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1448 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1449 gst_element_factory_get_metadata (factory,
1450 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1452 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1453 GstTypeFindFactory *factory;
1454 const gchar *const *extensions;
1456 factory = GST_TYPE_FIND_FACTORY (feature);
1457 extensions = gst_type_find_factory_get_extensions (factory);
1459 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1460 gst_plugin_feature_get_name (feature), RESET_COLOR);
1461 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1464 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1465 gst_plugin_feature_get_name (feature), RESET_COLOR,
1466 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1469 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1470 GstDeviceProviderFactory *factory;
1472 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1473 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1474 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1475 gst_device_provider_factory_get_metadata (factory,
1476 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1478 } else if (GST_IS_TRACER_FACTORY (feature)) {
1479 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1480 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1481 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1483 } else if (feature) {
1484 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1485 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1486 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1490 features = g_list_next (features);
1493 gst_plugin_feature_list_free (origlist);
1496 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1497 if (num_elements > 0)
1498 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1499 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1500 if (num_typefinders > 0)
1501 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1502 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1503 if (num_devproviders > 0)
1504 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1505 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1506 if (num_tracers > 0)
1507 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1508 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1510 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1511 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1517 print_feature_info (const gchar * feature_name, gboolean print_all)
1519 GstPluginFeature *feature;
1520 GstRegistry *registry = gst_registry_get ();
1523 if ((feature = gst_registry_find_feature (registry, feature_name,
1524 GST_TYPE_ELEMENT_FACTORY))) {
1525 ret = print_element_info (feature, print_all);
1528 if ((feature = gst_registry_find_feature (registry, feature_name,
1529 GST_TYPE_TYPE_FIND_FACTORY))) {
1530 ret = print_typefind_info (feature, print_all);
1533 if ((feature = gst_registry_find_feature (registry, feature_name,
1534 GST_TYPE_TRACER_FACTORY))) {
1535 ret = print_tracer_info (feature, print_all);
1539 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1544 gst_object_unref (feature);
1549 print_element_info (GstPluginFeature * feature, gboolean print_names)
1551 GstElementFactory *factory;
1552 GstElement *element;
1556 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1558 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1563 element = gst_element_factory_create (factory, NULL);
1565 gst_object_unref (factory);
1566 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1573 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1578 print_factory_details_info (factory);
1580 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1582 print_plugin_info (plugin);
1583 gst_object_unref (plugin);
1586 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1587 print_interfaces (G_OBJECT_TYPE (element));
1589 print_pad_templates_info (element, factory);
1590 print_clocking_info (element);
1591 print_uri_handler_info (element);
1592 print_pad_info (element);
1593 print_element_properties_info (element);
1594 print_signal_info (element);
1595 print_children_info (element);
1596 print_preset_list (element);
1598 gst_object_unref (element);
1599 gst_object_unref (factory);
1605 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1607 GstTypeFindFactory *factory;
1612 const gchar *const *extensions;
1614 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1616 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1623 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1628 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1629 rank = gst_plugin_feature_get_rank (feature);
1630 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1631 get_rank_name (s, rank), rank, RESET_COLOR);
1632 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1633 GST_OBJECT_NAME (factory), RESET_COLOR);
1634 caps = gst_type_find_factory_get_caps (factory);
1636 gchar *caps_str = gst_caps_to_string (factory->caps);
1638 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1639 caps_str, RESET_COLOR);
1642 extensions = gst_type_find_factory_get_extensions (factory);
1644 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1645 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1650 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1652 print_plugin_info (plugin);
1653 gst_object_unref (plugin);
1656 gst_object_unref (factory);
1662 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1664 GstTracerFactory *factory;
1669 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1671 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1675 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1677 gst_object_unref (factory);
1678 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1685 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1690 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1691 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1692 GST_OBJECT_NAME (factory), RESET_COLOR);
1695 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1697 print_plugin_info (plugin);
1698 gst_object_unref (plugin);
1701 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1702 print_interfaces (G_OBJECT_TYPE (tracer));
1704 /* TODO: list what hooks it registers
1705 * - the data is available in gsttracerutils, we need to iterate the
1706 * _priv_tracers hashtable for each probe and then check the list of hooks
1707 * for each probe whether hook->tracer == tracer :/
1710 /* TODO: list what records it emits
1711 * - in class_init tracers can create GstTracerRecord instances
1712 * - those only get logged right now and there is no association with the
1713 * tracer that created them
1714 * - we'd need to add them to GstTracerFactory
1715 * gst_tracer_class_add_record (klass, record);
1716 * - needs work in gstregistrychunks to (de)serialize specs
1717 * - gst_tracer_register() would need to iterate the list of records and
1718 * copy the record->spec into the factory
1721 gst_object_unref (tracer);
1722 gst_object_unref (factory);
1727 /* NOTE: Not coloring output from automatic install functions, as their output
1728 * is meant for machines, not humans.
1731 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1733 GstPadDirection direction;
1734 const gchar *type_name;
1736 const GList *static_templates, *l;
1737 GstCaps *caps = NULL;
1741 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1742 g_return_if_fail (klass != NULL);
1744 if (strstr (klass, "Demuxer") ||
1745 strstr (klass, "Decoder") ||
1746 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1747 type_name = "decoder";
1748 direction = GST_PAD_SINK;
1749 } else if (strstr (klass, "Muxer") ||
1750 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1751 type_name = "encoder";
1752 direction = GST_PAD_SRC;
1757 /* decoder/demuxer sink pads should always be static and there should only
1758 * be one, the same applies to encoders/muxers and source pads */
1759 static_templates = gst_element_factory_get_static_pad_templates (factory);
1760 for (l = static_templates; l != NULL; l = l->next) {
1761 GstStaticPadTemplate *tmpl = NULL;
1763 tmpl = (GstStaticPadTemplate *) l->data;
1764 if (tmpl->direction == direction) {
1765 caps = gst_static_pad_template_get_caps (tmpl);
1771 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1772 type_name, GST_OBJECT_NAME (factory));
1776 caps = gst_caps_make_writable (caps);
1777 num = gst_caps_get_size (caps);
1778 for (i = 0; i < num; ++i) {
1782 s = gst_caps_get_structure (caps, i);
1783 /* remove fields that are almost always just MIN-MAX of some sort
1784 * in order to make the caps look less messy */
1785 gst_structure_remove_field (s, "pixel-aspect-ratio");
1786 gst_structure_remove_field (s, "framerate");
1787 gst_structure_remove_field (s, "channels");
1788 gst_structure_remove_field (s, "width");
1789 gst_structure_remove_field (s, "height");
1790 gst_structure_remove_field (s, "rate");
1791 gst_structure_remove_field (s, "depth");
1792 gst_structure_remove_field (s, "clock-rate");
1793 s_str = gst_structure_to_string (s);
1794 g_print ("%s-%s\n", type_name, s_str);
1797 gst_caps_unref (caps);
1801 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1803 const gchar *const *protocols;
1805 protocols = gst_element_factory_get_uri_protocols (factory);
1806 if (protocols != NULL && *protocols != NULL) {
1807 switch (gst_element_factory_get_uri_type (factory)) {
1809 while (*protocols != NULL) {
1810 g_print ("urisink-%s\n", *protocols);
1815 while (*protocols != NULL) {
1816 g_print ("urisource-%s\n", *protocols);
1827 print_plugin_automatic_install_info (GstPlugin * plugin)
1829 GList *features, *l;
1831 /* not interested in typefind factories, only element factories */
1832 features = gst_registry_get_feature_list (gst_registry_get (),
1833 GST_TYPE_ELEMENT_FACTORY);
1835 for (l = features; l != NULL; l = l->next) {
1836 GstPluginFeature *feature;
1837 GstPlugin *feature_plugin;
1839 feature = GST_PLUGIN_FEATURE (l->data);
1841 /* only interested in the ones that are in the plugin we just loaded */
1842 feature_plugin = gst_plugin_feature_get_plugin (feature);
1843 if (feature_plugin == plugin) {
1844 GstElementFactory *factory;
1846 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1848 factory = GST_ELEMENT_FACTORY (feature);
1849 print_plugin_automatic_install_info_protocols (factory);
1850 print_plugin_automatic_install_info_codecs (factory);
1853 gst_object_unref (feature_plugin);
1856 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1857 g_list_free (features);
1861 print_all_plugin_automatic_install_info (void)
1863 GList *plugins, *orig_plugins;
1865 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1869 plugin = (GstPlugin *) (plugins->data);
1870 plugins = g_list_next (plugins);
1872 print_plugin_automatic_install_info (plugin);
1874 gst_plugin_list_free (orig_plugins);
1879 redirect_stdout (void)
1881 GError *error = NULL;
1887 pager = g_getenv ("PAGER");
1889 pager = DEFAULT_PAGER;
1891 argv = g_strsplit (pager, " ", 0);
1893 envp = g_get_environ ();
1894 envp = g_environ_setenv (envp, "LESS", DEFAULT_LESS_OPTS, TRUE);
1896 if (!g_spawn_async_with_pipes (NULL, argv, envp,
1897 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1898 NULL, NULL, &child_pid, &stdin_fd,
1899 /* pass null stdout/stderr to inherit our fds */
1900 NULL, NULL, &error)) {
1901 g_warning ("g_spawn_async_with_pipes() failed: %s\n",
1902 GST_STR_NULL (error->message));
1905 g_clear_error (&error);
1910 /* redirect our stdout to child stdin */
1911 dup2 (stdin_fd, STDOUT_FILENO);
1912 if (isatty (STDERR_FILENO))
1913 dup2 (stdin_fd, STDERR_FILENO);
1923 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
1925 g_spawn_close_pid (child_pid);
1926 g_main_loop_quit (loop);
1931 main (int argc, char *argv[])
1933 gboolean print_all = FALSE;
1934 gboolean do_print_blacklist = FALSE;
1935 gboolean plugin_name = FALSE;
1936 gboolean print_aii = FALSE;
1937 gboolean uri_handlers = FALSE;
1938 gboolean check_exists = FALSE;
1939 gchar *min_version = NULL;
1940 guint minver_maj = GST_VERSION_MAJOR;
1941 guint minver_min = GST_VERSION_MINOR;
1942 guint minver_micro = 0;
1943 gchar *types = NULL;
1944 const gchar *no_colors;
1946 #ifndef GST_DISABLE_OPTION_PARSING
1947 GOptionEntry options[] = {
1948 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1949 N_("Print all elements"), NULL},
1950 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1951 N_("Print list of blacklisted files"), NULL},
1952 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1953 N_("Print a machine-parsable list of features the specified plugin "
1954 "or all plugins provide.\n "
1955 "Useful in connection with external automatic plugin "
1956 "installation mechanisms"), NULL},
1957 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1958 N_("List the plugin contents"), NULL},
1959 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1960 N_("A slashes ('/') separated list of types of elements (also known "
1961 "as klass) to list. (unordered)"), NULL},
1962 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1963 N_("Check if the specified element or plugin exists"), NULL},
1964 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1966 ("When checking if an element or plugin exists, also check that its "
1967 "version is at least the version specified"), NULL},
1968 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1970 ("Print supported URI schemes, with the elements that implement them"),
1972 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1975 ("Disable colors in output. You can also achieve the same by setting"
1976 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
1978 GST_TOOLS_GOPTION_VERSION,
1981 GOptionContext *ctx;
1985 setlocale (LC_ALL, "");
1988 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1989 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1990 textdomain (GETTEXT_PACKAGE);
1993 /* avoid glib warnings when inspecting deprecated properties */
1994 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
1996 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1998 #ifndef GST_DISABLE_OPTION_PARSING
1999 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2000 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2001 g_option_context_add_group (ctx, gst_init_get_option_group ());
2002 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2003 g_printerr ("Error initializing: %s\n", err->message);
2004 g_clear_error (&err);
2005 g_option_context_free (ctx);
2008 g_option_context_free (ctx);
2010 gst_init (&argc, &argv);
2013 gst_tools_print_version ();
2015 if (print_all && argc > 1) {
2016 g_printerr ("-a requires no extra arguments\n");
2020 if (uri_handlers && argc > 1) {
2021 g_printerr ("-u requires no extra arguments\n");
2025 /* --atleast-version implies --exists */
2026 if (min_version != NULL) {
2027 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2028 &minver_micro) < 2) {
2029 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2033 check_exists = TRUE;
2038 g_printerr ("--exists requires an extra command line argument\n");
2042 GstPluginFeature *feature;
2044 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2045 if (feature != NULL && gst_plugin_feature_check_version (feature,
2046 minver_maj, minver_min, minver_micro)) {
2053 gst_object_unref (feature);
2055 /* FIXME: support checking for plugins too */
2056 g_printerr ("Checking for plugins is not supported yet\n");
2063 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2064 /* We only support truecolor */
2065 colored_output &= (no_colors == NULL);
2068 if (isatty (STDOUT_FILENO)) {
2069 if (redirect_stdout ())
2070 loop = g_main_loop_new (NULL, FALSE);
2072 colored_output = FALSE;
2074 #elif defined(G_OS_WIN32)
2076 gint fd = _fileno (stdout);
2077 /* On Windows 10, g_log_writer_supports_color will also setup the console
2078 * so that it correctly interprets ANSI VT sequences if it's supported */
2079 if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2080 colored_output = FALSE;
2084 /* if no arguments, print out list of elements */
2086 print_all_uri_handlers ();
2087 } else if (argc == 1 || print_all) {
2088 if (do_print_blacklist)
2092 print_all_plugin_automatic_install_info ();
2094 print_element_list (print_all, types);
2097 /* else we try to get a factory */
2098 const char *arg = argv[argc - 1];
2102 retval = print_feature_info (arg, print_all);
2105 /* otherwise check if it's a plugin */
2107 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2109 /* if there is such a plugin, print out info */
2112 print_plugin_automatic_install_info (plugin);
2114 print_plugin_info (plugin);
2115 print_plugin_features (plugin);
2118 GError *error = NULL;
2120 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2121 plugin = gst_plugin_load_file (arg, &error);
2125 print_plugin_automatic_install_info (plugin);
2127 print_plugin_info (plugin);
2128 print_plugin_features (plugin);
2131 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2132 g_clear_error (&error);
2137 g_printerr (_("No such element or plugin '%s'\n"), arg);
2151 /* So that the pipe we create in redirect_stdout() is closed */
2152 close (STDOUT_FILENO);
2153 close (STDERR_FILENO);
2154 g_child_watch_add (child_pid, child_exit_cb, NULL);
2155 g_main_loop_run (loop);
2156 g_main_loop_unref (loop);