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;
55 GMainLoop *loop = NULL;
59 /* Escape values for colors */
60 #define BLUE "\033[34m"
61 #define BRBLUE "\033[94m"
62 #define BRCYAN "\033[96m"
63 #define BRMAGENTA "\033[95m"
64 #define BRYELLOW "\033[33m"
65 #define CYAN "\033[36m"
66 #define GREEN "\033[32m"
67 #define MAGENTA "\033[35m"
68 #define YELLOW "\033[33m"
71 #define RESET_COLOR (colored_output? "\033[0m": "")
72 #define HEADING_COLOR (colored_output? BRYELLOW : "")
73 #define PROP_NAME_COLOR (colored_output? BRBLUE : "")
74 #define PROP_VALUE_COLOR (colored_output? RESET_COLOR: "")
75 #define PROP_ATTR_NAME_COLOR (colored_output? BRYELLOW : "")
76 #define PROP_ATTR_VALUE_COLOR (colored_output? CYAN: "")
77 /* FIXME: find a good color that works on both dark & light bg. */
78 #define DESC_COLOR (colored_output? RESET_COLOR: "")
80 /* Datatype-related colors */
81 #define DATATYPE_COLOR (colored_output? GREEN : "")
82 #define CHILD_LINK_COLOR (colored_output? BRMAGENTA : "")
85 #define FIELD_NAME_COLOR (colored_output? CYAN: "")
86 #define FIELD_VALUE_COLOR (colored_output? BRBLUE : "")
87 #define CAPS_TYPE_COLOR (colored_output? YELLOW : "")
88 #define STRUCT_NAME_COLOR (colored_output? YELLOW : "")
89 #define CAPS_FEATURE_COLOR (colored_output? GREEN : "")
91 /* Plugin listing colors */
92 #define PLUGIN_NAME_COLOR (colored_output? BRBLUE : "")
93 #define ELEMENT_NAME_COLOR (colored_output? GREEN : "")
94 /* FIXME: find a good color that works on both dark & light bg. */
95 #define ELEMENT_DETAIL_COLOR (colored_output? RESET_COLOR : "")
96 #define PLUGIN_FEATURE_COLOR (colored_output? BRBLUE: "")
98 /* Feature listing colors */
99 #define FEATURE_NAME_COLOR (colored_output? GREEN : "")
100 #define FEATURE_DIR_COLOR (colored_output? BRMAGENTA : "")
101 #define FEATURE_RANK_COLOR (colored_output? CYAN : "")
102 #define FEATURE_PROTO_COLOR (colored_output? BRYELLOW : "")
104 static char *_name = NULL;
105 static int indent = 0;
107 static int print_element_info (GstPluginFeature * feature,
108 gboolean print_names);
109 static int print_typefind_info (GstPluginFeature * feature,
110 gboolean print_names);
111 static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
113 #define push_indent() push_indent_n(1)
114 #define pop_indent() push_indent_n(-1)
115 #define pop_indent_n(n) push_indent_n(-n)
118 push_indent_n (int n)
120 g_assert (n > 0 || indent > 0);
129 n_print (const char *format, ...)
135 g_print ("%s", _name);
137 for (i = 0; i < indent; ++i)
140 va_start (args, format);
141 g_vprintf (format, args);
146 print_field (GQuark field, const GValue * value, gpointer pfx)
148 gchar *str = gst_value_serialize (value);
150 n_print ("%s %s%15s%s: %s%s%s\n",
151 (gchar *) pfx, FIELD_NAME_COLOR, g_quark_to_string (field), RESET_COLOR,
152 FIELD_VALUE_COLOR, str, RESET_COLOR);
158 print_caps (const GstCaps * caps, const gchar * pfx)
162 g_return_if_fail (caps != NULL);
164 if (gst_caps_is_any (caps)) {
165 n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
168 if (gst_caps_is_empty (caps)) {
169 n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
173 for (i = 0; i < gst_caps_get_size (caps); i++) {
174 GstStructure *structure = gst_caps_get_structure (caps, i);
175 GstCapsFeatures *features = gst_caps_get_features (caps, i);
177 if (features && (gst_caps_features_is_any (features) ||
178 !gst_caps_features_is_equal (features,
179 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
180 gchar *features_string = gst_caps_features_to_string (features);
182 n_print ("%s%s%s%s(%s%s%s)\n", pfx, STRUCT_NAME_COLOR,
183 gst_structure_get_name (structure), RESET_COLOR,
184 CAPS_FEATURE_COLOR, features_string, RESET_COLOR);
185 g_free (features_string);
187 n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
188 gst_structure_get_name (structure), RESET_COLOR);
190 gst_structure_foreach (structure, print_field, (gpointer) pfx);
195 get_rank_name (char *s, gint rank)
197 static const int ranks[4] = {
198 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
200 static const char *rank_names[4] = { "none", "marginal", "secondary",
207 for (i = 0; i < 4; i++) {
208 if (rank == ranks[i])
209 return rank_names[i];
210 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
215 sprintf (s, "%s %c %d", rank_names[best_i],
216 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
222 print_factory_details_info (GstElementFactory * factory)
228 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
229 n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
232 n_print ("%s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
233 get_rank_name (s, rank), rank, RESET_COLOR);
235 keys = gst_element_factory_get_metadata_keys (factory);
237 for (k = keys; *k != NULL; ++k) {
241 val = gst_element_factory_get_metadata (factory, key);
242 key[0] = g_ascii_toupper (key[0]);
243 n_print ("%s%-25s%s%s%s\n", PROP_NAME_COLOR, key, PROP_VALUE_COLOR, val,
253 print_hierarchy (GType type, gint level, gint * maxlevel)
258 parent = g_type_parent (type);
260 *maxlevel = *maxlevel + 1;
264 print_hierarchy (parent, level, maxlevel);
267 g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
269 for (i = 1; i < *maxlevel - level; i++)
271 if (*maxlevel - level)
272 g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
274 g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
281 print_interfaces (GType type)
284 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
288 n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
292 n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
303 flags_to_string (GFlagsValue * vals, guint flags)
308 /* first look for an exact match and count the number of values */
309 for (i = 0; vals[i].value_name != NULL; ++i) {
310 if (vals[i].value == flags)
311 return g_strdup (vals[i].value_nick);
314 s = g_string_new (NULL);
316 /* we assume the values are sorted from lowest to highest value */
320 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
322 g_string_append_c (s, '+');
323 g_string_append (s, vals[i].value_nick);
324 flags_left -= vals[i].value;
331 g_string_assign (s, "(none)");
333 return g_string_free (s, FALSE);
336 #define KNOWN_PARAM_FLAGS \
337 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
338 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
339 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
340 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
341 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
344 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
346 return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
349 /* obj will be NULL if we're printing properties of pad template pads */
351 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
354 GParamSpec **property_specs;
355 guint num_properties, i;
359 property_specs = g_object_class_list_properties (obj_class, &num_properties);
360 g_qsort_with_data (property_specs, num_properties, sizeof (gpointer),
361 (GCompareDataFunc) sort_gparamspecs, NULL);
363 n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
367 for (i = 0; i < num_properties; i++) {
368 GValue value = { 0, };
369 GParamSpec *param = property_specs[i];
370 GType owner_type = param->owner_type;
372 /* We're printing pad properties */
373 if (obj == NULL && (owner_type == G_TYPE_OBJECT
374 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
377 g_value_init (&value, param->value_type);
379 n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
380 g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
381 g_param_spec_get_blurb (param), RESET_COLOR);
386 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
387 readable = ! !(param->flags & G_PARAM_READABLE);
388 if (readable && obj != NULL) {
389 g_object_get_property (obj, param->name, &value);
391 /* if we can't read the property value, assume it's set to the default
392 * (which might not be entirely true for sub-classes, but that's an
393 * unlikely corner-case anyway) */
394 g_param_value_set_default (param, &value);
397 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
398 _("readable"), RESET_COLOR);
401 if (param->flags & G_PARAM_WRITABLE) {
402 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
403 _("writable"), RESET_COLOR);
406 if (param->flags & G_PARAM_DEPRECATED) {
407 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
408 _("deprecated"), RESET_COLOR);
411 if (param->flags & GST_PARAM_CONTROLLABLE) {
412 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
416 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
417 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
418 _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
419 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
420 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
421 _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
422 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
423 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
424 _("changeable only in NULL or READY state"), RESET_COLOR);
426 if (param->flags & ~KNOWN_PARAM_FLAGS) {
427 g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
428 param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
432 switch (G_VALUE_TYPE (&value)) {
435 const char *string_val = g_value_get_string (&value);
437 n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
439 if (string_val == NULL)
440 g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
441 PROP_ATTR_VALUE_COLOR, RESET_COLOR);
443 g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
444 PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
449 gboolean bool_val = g_value_get_boolean (&value);
451 n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
452 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
453 PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
458 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
461 ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
462 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
463 PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
464 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
465 PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
467 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
468 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
469 g_param_spec_get_name (param));
474 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
476 n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
477 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
478 PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
479 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
480 g_value_get_long (&value), RESET_COLOR);
482 GST_ERROR ("%s: property '%s' of type long: consider changing to "
483 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
484 g_param_spec_get_name (param));
489 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
492 ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
493 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
494 PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
495 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
496 g_value_get_uint (&value), RESET_COLOR);
501 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
503 n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
504 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
505 PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
506 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
507 g_value_get_int (&value), RESET_COLOR);
512 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
514 n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
515 "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
516 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
517 PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
518 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
519 PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
524 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
526 n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
527 G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
528 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
529 PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
530 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
531 PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
536 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
538 n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
539 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
540 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
541 pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
542 RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
548 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
550 n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
551 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
552 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
553 pdouble->minimum, pdouble->maximum, RESET_COLOR,
554 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
555 g_value_get_double (&value), RESET_COLOR);
560 GST_ERROR ("%s: property '%s' of type char: consider changing to "
561 "int/string", G_OBJECT_CLASS_NAME (obj_class),
562 g_param_spec_get_name (param));
565 if (param->value_type == GST_TYPE_CAPS) {
566 const GstCaps *caps = gst_value_get_caps (&value);
569 n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
571 print_caps (caps, " ");
573 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
577 const gchar *value_nick = "";
579 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
580 enum_value = g_value_get_enum (&value);
582 while (values[j].value_name) {
583 if (values[j].value == enum_value)
584 value_nick = values[j].value_nick;
588 n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
589 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
590 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
591 enum_value, value_nick, RESET_COLOR);
594 while (values[j].value_name) {
596 n_print (" %s(%d)%s: %s%-16s%s - %s%s%s",
597 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
598 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
599 DESC_COLOR, values[j].value_name, RESET_COLOR);
602 /* g_type_class_unref (ec); */
603 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
604 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
608 vals = pflags->flags_class->values;
610 cur = flags_to_string (vals, g_value_get_flags (&value));
612 n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
613 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
614 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
615 g_value_get_flags (&value), cur, RESET_COLOR);
617 while (vals[0].value_name) {
619 n_print (" %s(0x%08x)%s: %s%-16s%s - %s%s%s",
620 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
621 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
622 DESC_COLOR, vals[0].value_name, RESET_COLOR);
627 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
628 n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
629 RESET_COLOR, DATATYPE_COLOR,
630 g_type_name (param->value_type), RESET_COLOR);
631 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
632 n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
633 RESET_COLOR, DATATYPE_COLOR,
634 g_type_name (param->value_type), RESET_COLOR);
635 if (param->value_type == GST_TYPE_STRUCTURE) {
636 const GstStructure *s = gst_value_get_structure (&value);
638 gst_structure_foreach (s, print_field,
641 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
642 if (param->value_type != G_TYPE_POINTER) {
643 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
644 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
647 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
649 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
650 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
652 if (pvarray->element_spec) {
653 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
654 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
655 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
657 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
659 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
660 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
662 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
663 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
664 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
665 pfraction->min_num, pfraction->min_den, pfraction->max_num,
666 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
667 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
668 gst_value_get_fraction_numerator (&value),
669 gst_value_get_fraction_denominator (&value), RESET_COLOR);
670 } else if (param->value_type == GST_TYPE_ARRAY) {
671 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
673 if (parray->element_spec) {
674 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
675 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
676 g_type_name (parray->element_spec->value_type), RESET_COLOR);
678 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
682 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
683 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
684 g_type_name (param->value_type), RESET_COLOR);
689 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
695 g_value_reset (&value);
697 if (num_properties == 0)
698 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
702 g_free (property_specs);
706 print_element_properties_info (GstElement * element)
709 print_object_properties_info (G_OBJECT (element),
710 G_OBJECT_GET_CLASS (element), "Element Properties");
714 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
717 GstStaticPadTemplate *padtemplate;
718 GstPadTemplate *tmpl;
720 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
724 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
725 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
729 pads = gst_element_factory_get_static_pad_templates (factory);
731 padtemplate = (GstStaticPadTemplate *) (pads->data);
732 pads = g_list_next (pads);
734 if (padtemplate->direction == GST_PAD_SRC)
735 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
736 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
737 else if (padtemplate->direction == GST_PAD_SINK)
738 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
739 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
741 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
742 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
746 if (padtemplate->presence == GST_PAD_ALWAYS)
747 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
748 PROP_VALUE_COLOR, RESET_COLOR);
749 else if (padtemplate->presence == GST_PAD_SOMETIMES)
750 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
751 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
752 else if (padtemplate->presence == GST_PAD_REQUEST) {
753 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
754 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
756 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
757 PROP_VALUE_COLOR, RESET_COLOR);
759 if (padtemplate->static_caps.string) {
760 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
762 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
765 print_caps (caps, ""); // FIXME
768 gst_caps_unref (caps);
771 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
772 padtemplate->name_template);
774 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
776 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
779 pad_klass = g_type_class_ref (pad_type);
780 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
781 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
782 print_object_properties_info (NULL, pad_klass, "Pad Properties");
783 g_type_class_unref (pad_klass);
798 print_clocking_info (GstElement * element)
800 gboolean requires_clock, provides_clock;
803 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
805 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
807 if (!requires_clock && !provides_clock) {
809 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
815 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
819 if (requires_clock) {
820 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
823 if (provides_clock) {
826 clock = gst_element_get_clock (element);
828 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
829 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
830 gst_object_unref (clock);
832 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
833 PROP_VALUE_COLOR, RESET_COLOR);
840 print_uri_handler_info (GstElement * element)
842 if (GST_IS_URI_HANDLER (element)) {
843 const gchar *const *uri_protocols;
844 const gchar *uri_type;
846 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
848 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
852 uri_type = "unknown";
854 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
857 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
861 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
863 if (uri_protocols && *uri_protocols) {
864 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
866 for (; *uri_protocols != NULL; uri_protocols++)
867 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
871 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
877 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
883 print_pad_info (GstElement * element)
889 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
893 if (!element->numpads) {
894 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
898 pads = element->pads;
903 pad = GST_PAD (pads->data);
904 pads = g_list_next (pads);
906 name = gst_pad_get_name (pad);
907 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
908 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
909 PROP_VALUE_COLOR, name, RESET_COLOR);
910 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
911 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
912 PROP_VALUE_COLOR, name, RESET_COLOR);
914 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
915 PROP_VALUE_COLOR, name, RESET_COLOR);
919 if (pad->padtemplate) {
921 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
922 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
926 caps = gst_pad_get_current_caps (pad);
928 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
930 print_caps (caps, ""); // FIXME
932 gst_caps_unref (caps);
941 has_sometimes_template (GstElement * element)
943 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
946 for (l = klass->padtemplates; l != NULL; l = l->next) {
947 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
955 gtype_needs_ptr_marker (GType type)
957 if (type == G_TYPE_POINTER)
960 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
961 || G_TYPE_IS_OBJECT (type))
968 print_signal_info (GstElement * element)
970 /* Signals/Actions Block */
974 GSignalQuery *query = NULL;
976 GSList *found_signals, *l;
978 for (k = 0; k < 2; k++) {
979 found_signals = NULL;
981 /* For elements that have sometimes pads, also list a few useful GstElement
982 * signals. Put these first, so element-specific ones come later. */
983 if (k == 0 && has_sometimes_template (element)) {
984 query = g_new0 (GSignalQuery, 1);
985 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
986 found_signals = g_slist_append (found_signals, query);
987 query = g_new0 (GSignalQuery, 1);
988 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
989 found_signals = g_slist_append (found_signals, query);
990 query = g_new0 (GSignalQuery, 1);
991 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
993 found_signals = g_slist_append (found_signals, query);
996 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
997 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1000 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1003 signals = g_signal_list_ids (type, &nsignals);
1004 for (i = 0; i < nsignals; i++) {
1005 query = g_new0 (GSignalQuery, 1);
1006 g_signal_query (signals[i], query);
1008 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1009 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1010 found_signals = g_slist_append (found_signals, query);
1018 if (found_signals) {
1021 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1023 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1028 for (l = found_signals; l; l = l->next) {
1033 query = (GSignalQuery *) l->data;
1034 indent_len = strlen (query->signal_name) +
1035 strlen (g_type_name (query->return_type)) + 24;
1037 if (gtype_needs_ptr_marker (query->return_type)) {
1044 indent = g_new0 (gchar, indent_len + 1);
1045 memset (indent, ' ', indent_len);
1047 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1048 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1049 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1050 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1051 PROP_VALUE_COLOR, RESET_COLOR);
1053 for (j = 0; j < query->n_params; j++) {
1054 const gchar *type_name, *asterisk;
1056 type_name = g_type_name (query->param_types[j]);
1057 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1060 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1061 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1066 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1067 PROP_VALUE_COLOR, RESET_COLOR);
1074 if (found_signals) {
1075 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1076 g_slist_free (found_signals);
1082 print_children_info (GstElement * element)
1086 if (!GST_IS_BIN (element))
1089 children = (GList *) GST_BIN (element)->children;
1092 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1096 n_print (" %s%s%s\n", DATATYPE_COLOR,
1097 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1098 children = g_list_next (children);
1103 print_preset_list (GstElement * element)
1105 gchar **presets, **preset;
1107 if (!GST_IS_PRESET (element))
1110 presets = gst_preset_get_preset_names (GST_PRESET (element));
1111 if (presets && *presets) {
1113 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1114 for (preset = presets; *preset; preset++) {
1115 n_print (" \"%s\"\n", *preset);
1117 g_strfreev (presets);
1122 print_blacklist (void)
1124 GList *plugins, *cur;
1127 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1129 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1130 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1131 GstPlugin *plugin = (GstPlugin *) (cur->data);
1132 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1133 g_print (" %s\n", gst_plugin_get_name (plugin));
1139 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1141 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1143 g_print ("%s\n", RESET_COLOR);
1144 gst_plugin_list_free (plugins);
1148 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1152 while (extensions[i]) {
1153 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1159 print_element_list (gboolean print_all, gchar * ftypes)
1161 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1162 GList *plugins, *orig_plugins;
1163 gchar **types = NULL;
1168 types = g_strsplit (ftypes, "/", -1);
1169 for (i = 0; types[i]; i++)
1170 *types[i] = g_ascii_toupper (*types[i]);
1174 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1176 GList *features, *orig_features;
1179 plugin = (GstPlugin *) (plugins->data);
1180 plugins = g_list_next (plugins);
1183 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1188 orig_features = features =
1189 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1190 gst_plugin_get_name (plugin));
1192 GstPluginFeature *feature;
1194 if (G_UNLIKELY (features->data == NULL))
1196 feature = GST_PLUGIN_FEATURE (features->data);
1199 if (GST_IS_ELEMENT_FACTORY (feature)) {
1201 GstElementFactory *factory;
1203 factory = GST_ELEMENT_FACTORY (feature);
1206 gboolean all_found = TRUE;
1209 gst_element_factory_get_metadata (factory,
1210 GST_ELEMENT_METADATA_KLASS);
1211 for (i = 0; types[i]; i++) {
1212 if (!strstr (klass, types[i])) {
1222 print_element_info (feature, TRUE);
1224 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1225 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1226 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1227 gst_element_factory_get_metadata (factory,
1228 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1229 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1230 GstTypeFindFactory *factory;
1231 const gchar *const *extensions;
1235 factory = GST_TYPE_FIND_FACTORY (feature);
1237 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1238 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1239 gst_plugin_feature_get_name (feature), RESET_COLOR);
1241 extensions = gst_type_find_factory_get_extensions (factory);
1242 if (extensions != NULL) {
1244 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1249 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1255 n_print ("%s%s%s: %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1256 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1257 GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1258 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1262 features = g_list_next (features);
1265 gst_plugin_feature_list_free (orig_features);
1268 gst_plugin_list_free (orig_plugins);
1272 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1274 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1275 if (blacklistcount) {
1277 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1278 blacklistcount), blacklistcount);
1279 g_print (" not shown)");
1281 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1282 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1283 g_print ("%s\n", RESET_COLOR);
1287 print_all_uri_handlers (void)
1289 GList *plugins, *p, *features, *f;
1291 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1293 for (p = plugins; p; p = p->next) {
1294 GstPlugin *plugin = (GstPlugin *) (p->data);
1297 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1298 gst_plugin_get_name (plugin));
1300 for (f = features; f; f = f->next) {
1301 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1303 if (GST_IS_ELEMENT_FACTORY (feature)) {
1304 GstElementFactory *factory;
1305 GstElement *element;
1307 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1309 g_print ("element plugin %s couldn't be loaded\n",
1310 gst_plugin_get_name (plugin));
1314 element = gst_element_factory_create (factory, NULL);
1316 g_print ("couldn't construct element for %s for some reason\n",
1317 GST_OBJECT_NAME (factory));
1318 gst_object_unref (factory);
1322 if (GST_IS_URI_HANDLER (element)) {
1323 const gchar *const *uri_protocols;
1324 const gchar *const *protocol;
1327 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1339 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1341 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1342 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1344 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1348 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1349 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1350 if (protocol != uri_protocols)
1352 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1357 gst_object_unref (element);
1358 gst_object_unref (factory);
1362 gst_plugin_feature_list_free (features);
1365 gst_plugin_list_free (plugins);
1369 print_plugin_info (GstPlugin * plugin)
1371 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1372 const gchar *filename = gst_plugin_get_filename (plugin);
1374 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1378 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1379 PROP_VALUE_COLOR, gst_plugin_get_name (plugin), RESET_COLOR);
1380 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1381 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1382 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1383 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1384 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1385 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1386 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1387 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1388 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1389 PROP_VALUE_COLOR, gst_plugin_get_source (plugin), RESET_COLOR);
1391 if (release_date != NULL) {
1392 const gchar *tz = "(UTC)";
1395 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1396 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1397 str = g_strdup (release_date);
1398 sep = strstr (str, "T");
1401 sep = strstr (sep + 1, "Z");
1407 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1408 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1411 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1412 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1413 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1414 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1422 print_plugin_features (GstPlugin * plugin)
1424 GList *features, *origlist;
1425 gint num_features = 0;
1426 gint num_elements = 0;
1427 gint num_tracers = 0;
1428 gint num_typefinders = 0;
1429 gint num_devproviders = 0;
1432 origlist = features =
1433 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1434 gst_plugin_get_name (plugin));
1437 GstPluginFeature *feature;
1439 feature = GST_PLUGIN_FEATURE (features->data);
1441 if (GST_IS_ELEMENT_FACTORY (feature)) {
1442 GstElementFactory *factory;
1444 factory = GST_ELEMENT_FACTORY (feature);
1445 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1446 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1447 gst_element_factory_get_metadata (factory,
1448 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1450 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1451 GstTypeFindFactory *factory;
1452 const gchar *const *extensions;
1454 factory = GST_TYPE_FIND_FACTORY (feature);
1455 extensions = gst_type_find_factory_get_extensions (factory);
1457 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1458 gst_plugin_feature_get_name (feature), RESET_COLOR);
1459 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1462 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1463 gst_plugin_feature_get_name (feature), RESET_COLOR,
1464 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1467 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1468 GstDeviceProviderFactory *factory;
1470 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1471 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1472 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1473 gst_device_provider_factory_get_metadata (factory,
1474 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1476 } else if (GST_IS_TRACER_FACTORY (feature)) {
1477 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1478 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1479 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1481 } else if (feature) {
1482 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1483 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1484 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1488 features = g_list_next (features);
1491 gst_plugin_feature_list_free (origlist);
1494 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1495 if (num_elements > 0)
1496 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1497 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1498 if (num_typefinders > 0)
1499 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1500 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1501 if (num_devproviders > 0)
1502 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1503 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1504 if (num_tracers > 0)
1505 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1506 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1508 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1509 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1515 print_feature_info (const gchar * feature_name, gboolean print_all)
1517 GstPluginFeature *feature;
1518 GstRegistry *registry = gst_registry_get ();
1521 if ((feature = gst_registry_find_feature (registry, feature_name,
1522 GST_TYPE_ELEMENT_FACTORY))) {
1523 ret = print_element_info (feature, print_all);
1526 if ((feature = gst_registry_find_feature (registry, feature_name,
1527 GST_TYPE_TYPE_FIND_FACTORY))) {
1528 ret = print_typefind_info (feature, print_all);
1531 if ((feature = gst_registry_find_feature (registry, feature_name,
1532 GST_TYPE_TRACER_FACTORY))) {
1533 ret = print_tracer_info (feature, print_all);
1537 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1542 gst_object_unref (feature);
1547 print_element_info (GstPluginFeature * feature, gboolean print_names)
1549 GstElementFactory *factory;
1550 GstElement *element;
1554 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1556 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1561 element = gst_element_factory_create (factory, NULL);
1563 gst_object_unref (factory);
1564 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1571 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1576 print_factory_details_info (factory);
1578 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1580 print_plugin_info (plugin);
1581 gst_object_unref (plugin);
1584 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1585 print_interfaces (G_OBJECT_TYPE (element));
1587 print_pad_templates_info (element, factory);
1588 print_clocking_info (element);
1589 print_uri_handler_info (element);
1590 print_pad_info (element);
1591 print_element_properties_info (element);
1592 print_signal_info (element);
1593 print_children_info (element);
1594 print_preset_list (element);
1596 gst_object_unref (element);
1597 gst_object_unref (factory);
1603 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1605 GstTypeFindFactory *factory;
1610 const gchar *const *extensions;
1612 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1614 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1621 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1626 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1627 rank = gst_plugin_feature_get_rank (feature);
1628 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1629 get_rank_name (s, rank), rank, RESET_COLOR);
1630 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1631 GST_OBJECT_NAME (factory), RESET_COLOR);
1632 caps = gst_type_find_factory_get_caps (factory);
1634 gchar *caps_str = gst_caps_to_string (factory->caps);
1636 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1637 caps_str, RESET_COLOR);
1640 extensions = gst_type_find_factory_get_extensions (factory);
1642 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1643 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1648 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1650 print_plugin_info (plugin);
1651 gst_object_unref (plugin);
1654 gst_object_unref (factory);
1660 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1662 GstTracerFactory *factory;
1667 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1669 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1673 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1675 gst_object_unref (factory);
1676 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1683 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1688 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1689 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1690 GST_OBJECT_NAME (factory), RESET_COLOR);
1693 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1695 print_plugin_info (plugin);
1696 gst_object_unref (plugin);
1699 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1700 print_interfaces (G_OBJECT_TYPE (tracer));
1702 /* TODO: list what hooks it registers
1703 * - the data is available in gsttracerutils, we need to iterate the
1704 * _priv_tracers hashtable for each probe and then check the list of hooks
1705 * for each probe whether hook->tracer == tracer :/
1708 /* TODO: list what records it emits
1709 * - in class_init tracers can create GstTracerRecord instances
1710 * - those only get logged right now and there is no association with the
1711 * tracer that created them
1712 * - we'd need to add them to GstTracerFactory
1713 * gst_tracer_class_add_record (klass, record);
1714 * - needs work in gstregistrychunks to (de)serialize specs
1715 * - gst_tracer_register() would need to iterate the list of records and
1716 * copy the record->spec into the factory
1719 gst_object_unref (tracer);
1720 gst_object_unref (factory);
1725 /* NOTE: Not coloring output from automatic install functions, as their output
1726 * is meant for machines, not humans.
1729 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1731 GstPadDirection direction;
1732 const gchar *type_name;
1734 const GList *static_templates, *l;
1735 GstCaps *caps = NULL;
1739 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1740 g_return_if_fail (klass != NULL);
1742 if (strstr (klass, "Demuxer") ||
1743 strstr (klass, "Decoder") ||
1744 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1745 type_name = "decoder";
1746 direction = GST_PAD_SINK;
1747 } else if (strstr (klass, "Muxer") ||
1748 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1749 type_name = "encoder";
1750 direction = GST_PAD_SRC;
1755 /* decoder/demuxer sink pads should always be static and there should only
1756 * be one, the same applies to encoders/muxers and source pads */
1757 static_templates = gst_element_factory_get_static_pad_templates (factory);
1758 for (l = static_templates; l != NULL; l = l->next) {
1759 GstStaticPadTemplate *tmpl = NULL;
1761 tmpl = (GstStaticPadTemplate *) l->data;
1762 if (tmpl->direction == direction) {
1763 caps = gst_static_pad_template_get_caps (tmpl);
1769 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1770 type_name, GST_OBJECT_NAME (factory));
1774 caps = gst_caps_make_writable (caps);
1775 num = gst_caps_get_size (caps);
1776 for (i = 0; i < num; ++i) {
1780 s = gst_caps_get_structure (caps, i);
1781 /* remove fields that are almost always just MIN-MAX of some sort
1782 * in order to make the caps look less messy */
1783 gst_structure_remove_field (s, "pixel-aspect-ratio");
1784 gst_structure_remove_field (s, "framerate");
1785 gst_structure_remove_field (s, "channels");
1786 gst_structure_remove_field (s, "width");
1787 gst_structure_remove_field (s, "height");
1788 gst_structure_remove_field (s, "rate");
1789 gst_structure_remove_field (s, "depth");
1790 gst_structure_remove_field (s, "clock-rate");
1791 s_str = gst_structure_to_string (s);
1792 g_print ("%s-%s\n", type_name, s_str);
1795 gst_caps_unref (caps);
1799 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1801 const gchar *const *protocols;
1803 protocols = gst_element_factory_get_uri_protocols (factory);
1804 if (protocols != NULL && *protocols != NULL) {
1805 switch (gst_element_factory_get_uri_type (factory)) {
1807 while (*protocols != NULL) {
1808 g_print ("urisink-%s\n", *protocols);
1813 while (*protocols != NULL) {
1814 g_print ("urisource-%s\n", *protocols);
1825 print_plugin_automatic_install_info (GstPlugin * plugin)
1827 GList *features, *l;
1829 /* not interested in typefind factories, only element factories */
1830 features = gst_registry_get_feature_list (gst_registry_get (),
1831 GST_TYPE_ELEMENT_FACTORY);
1833 for (l = features; l != NULL; l = l->next) {
1834 GstPluginFeature *feature;
1835 GstPlugin *feature_plugin;
1837 feature = GST_PLUGIN_FEATURE (l->data);
1839 /* only interested in the ones that are in the plugin we just loaded */
1840 feature_plugin = gst_plugin_feature_get_plugin (feature);
1841 if (feature_plugin == plugin) {
1842 GstElementFactory *factory;
1844 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1846 factory = GST_ELEMENT_FACTORY (feature);
1847 print_plugin_automatic_install_info_protocols (factory);
1848 print_plugin_automatic_install_info_codecs (factory);
1851 gst_object_unref (feature_plugin);
1854 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1855 g_list_free (features);
1859 print_all_plugin_automatic_install_info (void)
1861 GList *plugins, *orig_plugins;
1863 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1867 plugin = (GstPlugin *) (plugins->data);
1868 plugins = g_list_next (plugins);
1870 print_plugin_automatic_install_info (plugin);
1872 gst_plugin_list_free (orig_plugins);
1877 redirect_stdout (void)
1879 GError *error = NULL;
1885 pager = g_getenv ("PAGER");
1887 pager = DEFAULT_PAGER;
1889 argv = g_strsplit (pager, " ", 0);
1891 envp = g_get_environ ();
1892 envp = g_environ_setenv (envp, "LESS", DEFAULT_LESS_OPTS, TRUE);
1894 if (!g_spawn_async_with_pipes (NULL, argv, envp,
1895 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1896 NULL, NULL, &child_pid, &stdin_fd,
1897 /* pass null stdout/stderr to inherit our fds */
1898 NULL, NULL, &error)) {
1899 g_warning ("g_spawn_async_with_pipes() failed: %s\n",
1900 GST_STR_NULL (error->message));
1903 g_clear_error (&error);
1908 /* redirect our stdout to child stdin */
1909 dup2 (stdin_fd, STDOUT_FILENO);
1910 if (isatty (STDERR_FILENO))
1911 dup2 (stdin_fd, STDERR_FILENO);
1921 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
1923 g_spawn_close_pid (child_pid);
1924 g_main_loop_quit (loop);
1929 main (int argc, char *argv[])
1931 gboolean print_all = FALSE;
1932 gboolean do_print_blacklist = FALSE;
1933 gboolean plugin_name = FALSE;
1934 gboolean print_aii = FALSE;
1935 gboolean uri_handlers = FALSE;
1936 gboolean check_exists = FALSE;
1937 gchar *min_version = NULL;
1938 guint minver_maj = GST_VERSION_MAJOR;
1939 guint minver_min = GST_VERSION_MINOR;
1940 guint minver_micro = 0;
1941 gchar *types = NULL;
1942 const gchar *no_colors;
1944 #ifndef GST_DISABLE_OPTION_PARSING
1945 GOptionEntry options[] = {
1946 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1947 N_("Print all elements"), NULL},
1948 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1949 N_("Print list of blacklisted files"), NULL},
1950 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1951 N_("Print a machine-parsable list of features the specified plugin "
1952 "or all plugins provide.\n "
1953 "Useful in connection with external automatic plugin "
1954 "installation mechanisms"), NULL},
1955 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1956 N_("List the plugin contents"), NULL},
1957 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1958 N_("A slashes ('/') separated list of types of elements (also known "
1959 "as klass) to list. (unordered)"), NULL},
1960 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1961 N_("Check if the specified element or plugin exists"), NULL},
1962 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1964 ("When checking if an element or plugin exists, also check that its "
1965 "version is at least the version specified"), NULL},
1966 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1968 ("Print supported URI schemes, with the elements that implement them"),
1970 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1973 ("Disable colors in output. You can also achieve the same by setting"
1974 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
1976 GST_TOOLS_GOPTION_VERSION,
1979 GOptionContext *ctx;
1983 setlocale (LC_ALL, "");
1986 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1987 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1988 textdomain (GETTEXT_PACKAGE);
1991 /* avoid glib warnings when inspecting deprecated properties */
1992 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
1994 g_set_prgname ("gst-inspect-" GST_API_VERSION);
1996 #ifndef GST_DISABLE_OPTION_PARSING
1997 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1998 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1999 g_option_context_add_group (ctx, gst_init_get_option_group ());
2000 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2001 g_printerr ("Error initializing: %s\n", err->message);
2002 g_clear_error (&err);
2003 g_option_context_free (ctx);
2006 g_option_context_free (ctx);
2008 gst_init (&argc, &argv);
2011 gst_tools_print_version ();
2013 if (print_all && argc > 1) {
2014 g_printerr ("-a requires no extra arguments\n");
2018 if (uri_handlers && argc > 1) {
2019 g_printerr ("-u requires no extra arguments\n");
2023 /* --atleast-version implies --exists */
2024 if (min_version != NULL) {
2025 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2026 &minver_micro) < 2) {
2027 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2031 check_exists = TRUE;
2036 g_printerr ("--exists requires an extra command line argument\n");
2040 GstPluginFeature *feature;
2042 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2043 if (feature != NULL && gst_plugin_feature_check_version (feature,
2044 minver_maj, minver_min, minver_micro)) {
2051 gst_object_unref (feature);
2053 /* FIXME: support checking for plugins too */
2054 g_printerr ("Checking for plugins is not supported yet\n");
2061 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2062 /* We only support truecolor */
2063 colored_output &= (no_colors == NULL);
2066 if (isatty (STDOUT_FILENO)) {
2067 if (redirect_stdout ())
2068 loop = g_main_loop_new (NULL, FALSE);
2070 colored_output = FALSE;
2072 #elif defined(G_OS_WIN32)
2074 gint fd = _fileno (stdout);
2075 /* On Windows 10, g_log_writer_supports_color will also setup the console
2076 * so that it correctly interprets ANSI VT sequences if it's supported */
2077 if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2078 colored_output = FALSE;
2082 /* if no arguments, print out list of elements */
2084 print_all_uri_handlers ();
2085 } else if (argc == 1 || print_all) {
2086 if (do_print_blacklist)
2090 print_all_plugin_automatic_install_info ();
2092 print_element_list (print_all, types);
2095 /* else we try to get a factory */
2096 const char *arg = argv[argc - 1];
2100 retval = print_feature_info (arg, print_all);
2103 /* otherwise check if it's a plugin */
2105 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2107 /* if there is such a plugin, print out info */
2110 print_plugin_automatic_install_info (plugin);
2112 print_plugin_info (plugin);
2113 print_plugin_features (plugin);
2116 GError *error = NULL;
2118 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2119 plugin = gst_plugin_load_file (arg, &error);
2123 print_plugin_automatic_install_info (plugin);
2125 print_plugin_info (plugin);
2126 print_plugin_features (plugin);
2129 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2130 g_clear_error (&error);
2135 g_printerr (_("No such element or plugin '%s'\n"), arg);
2149 /* So that the pipe we create in redirect_stdout() is closed */
2150 close (STDOUT_FILENO);
2151 close (STDERR_FILENO);
2152 g_child_watch_add (child_pid, child_exit_cb, NULL);
2153 g_main_loop_run (loop);
2154 g_main_loop_unref (loop);