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 static const gchar 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);
641 gst_structure_foreach (s, print_field,
645 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
646 if (param->value_type != G_TYPE_POINTER) {
647 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
648 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
651 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
653 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
654 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
656 if (pvarray->element_spec) {
657 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
658 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
659 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
661 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
663 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
664 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
666 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
667 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
668 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
669 pfraction->min_num, pfraction->min_den, pfraction->max_num,
670 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
671 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
672 gst_value_get_fraction_numerator (&value),
673 gst_value_get_fraction_denominator (&value), RESET_COLOR);
674 } else if (param->value_type == GST_TYPE_ARRAY) {
675 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
677 if (parray->element_spec) {
678 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
679 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
680 g_type_name (parray->element_spec->value_type), RESET_COLOR);
682 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
686 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
687 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
688 g_type_name (param->value_type), RESET_COLOR);
693 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
699 g_value_reset (&value);
701 if (num_properties == 0)
702 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
706 g_free (property_specs);
710 print_element_properties_info (GstElement * element)
713 print_object_properties_info (G_OBJECT (element),
714 G_OBJECT_GET_CLASS (element), "Element Properties");
718 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
721 GstStaticPadTemplate *padtemplate;
722 GstPadTemplate *tmpl;
724 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
728 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
729 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
733 pads = gst_element_factory_get_static_pad_templates (factory);
735 padtemplate = (GstStaticPadTemplate *) (pads->data);
736 pads = g_list_next (pads);
738 if (padtemplate->direction == GST_PAD_SRC)
739 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
740 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
741 else if (padtemplate->direction == GST_PAD_SINK)
742 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
743 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
745 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
746 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
750 if (padtemplate->presence == GST_PAD_ALWAYS)
751 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
752 PROP_VALUE_COLOR, RESET_COLOR);
753 else if (padtemplate->presence == GST_PAD_SOMETIMES)
754 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
755 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
756 else if (padtemplate->presence == GST_PAD_REQUEST) {
757 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
758 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
760 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
761 PROP_VALUE_COLOR, RESET_COLOR);
763 if (padtemplate->static_caps.string) {
764 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
766 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
769 print_caps (caps, ""); // FIXME
772 gst_caps_unref (caps);
775 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
776 padtemplate->name_template);
778 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
780 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
783 pad_klass = g_type_class_ref (pad_type);
784 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
785 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
786 print_object_properties_info (NULL, pad_klass, "Pad Properties");
787 g_type_class_unref (pad_klass);
802 print_clocking_info (GstElement * element)
804 gboolean requires_clock, provides_clock;
807 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
809 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
811 if (!requires_clock && !provides_clock) {
813 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
819 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
823 if (requires_clock) {
824 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
827 if (provides_clock) {
830 clock = gst_element_get_clock (element);
832 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
833 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
834 gst_object_unref (clock);
836 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
837 PROP_VALUE_COLOR, RESET_COLOR);
844 print_uri_handler_info (GstElement * element)
846 if (GST_IS_URI_HANDLER (element)) {
847 const gchar *const *uri_protocols;
848 const gchar *uri_type;
850 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
852 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
856 uri_type = "unknown";
858 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
861 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
865 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
867 if (uri_protocols && *uri_protocols) {
868 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
870 for (; *uri_protocols != NULL; uri_protocols++)
871 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
875 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
881 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
887 print_pad_info (GstElement * element)
893 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
897 if (!element->numpads) {
898 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
902 pads = element->pads;
907 pad = GST_PAD (pads->data);
908 pads = g_list_next (pads);
910 name = gst_pad_get_name (pad);
911 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
912 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
913 PROP_VALUE_COLOR, name, RESET_COLOR);
914 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
915 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
916 PROP_VALUE_COLOR, name, RESET_COLOR);
918 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
919 PROP_VALUE_COLOR, name, RESET_COLOR);
923 if (pad->padtemplate) {
925 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
926 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
930 caps = gst_pad_get_current_caps (pad);
932 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
934 print_caps (caps, ""); // FIXME
936 gst_caps_unref (caps);
945 has_sometimes_template (GstElement * element)
947 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
950 for (l = klass->padtemplates; l != NULL; l = l->next) {
951 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
959 gtype_needs_ptr_marker (GType type)
961 if (type == G_TYPE_POINTER)
964 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
965 || G_TYPE_IS_OBJECT (type))
972 print_signal_info (GstElement * element)
974 /* Signals/Actions Block */
978 GSignalQuery *query = NULL;
980 GSList *found_signals, *l;
982 for (k = 0; k < 2; k++) {
983 found_signals = NULL;
985 /* For elements that have sometimes pads, also list a few useful GstElement
986 * signals. Put these first, so element-specific ones come later. */
987 if (k == 0 && has_sometimes_template (element)) {
988 query = g_new0 (GSignalQuery, 1);
989 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
990 found_signals = g_slist_append (found_signals, query);
991 query = g_new0 (GSignalQuery, 1);
992 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
993 found_signals = g_slist_append (found_signals, query);
994 query = g_new0 (GSignalQuery, 1);
995 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
997 found_signals = g_slist_append (found_signals, query);
1000 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
1001 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1004 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1007 signals = g_signal_list_ids (type, &nsignals);
1008 for (i = 0; i < nsignals; i++) {
1009 query = g_new0 (GSignalQuery, 1);
1010 g_signal_query (signals[i], query);
1012 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1013 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1014 found_signals = g_slist_append (found_signals, query);
1022 if (found_signals) {
1025 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1027 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1032 for (l = found_signals; l; l = l->next) {
1037 query = (GSignalQuery *) l->data;
1038 indent_len = strlen (query->signal_name) +
1039 strlen (g_type_name (query->return_type)) + 24;
1041 if (gtype_needs_ptr_marker (query->return_type)) {
1048 indent = g_new0 (gchar, indent_len + 1);
1049 memset (indent, ' ', indent_len);
1051 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1052 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1053 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1054 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1055 PROP_VALUE_COLOR, RESET_COLOR);
1057 for (j = 0; j < query->n_params; j++) {
1058 const gchar *type_name, *asterisk;
1060 type_name = g_type_name (query->param_types[j]);
1061 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1064 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1065 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1070 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1071 PROP_VALUE_COLOR, RESET_COLOR);
1078 if (found_signals) {
1079 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1080 g_slist_free (found_signals);
1086 print_children_info (GstElement * element)
1090 if (!GST_IS_BIN (element))
1093 children = (GList *) GST_BIN (element)->children;
1096 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1100 n_print (" %s%s%s\n", DATATYPE_COLOR,
1101 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1102 children = g_list_next (children);
1107 print_preset_list (GstElement * element)
1109 gchar **presets, **preset;
1111 if (!GST_IS_PRESET (element))
1114 presets = gst_preset_get_preset_names (GST_PRESET (element));
1115 if (presets && *presets) {
1117 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1118 for (preset = presets; *preset; preset++) {
1119 n_print (" \"%s\"\n", *preset);
1121 g_strfreev (presets);
1126 print_blacklist (void)
1128 GList *plugins, *cur;
1131 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1133 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1134 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1135 GstPlugin *plugin = (GstPlugin *) (cur->data);
1136 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1137 g_print (" %s\n", gst_plugin_get_name (plugin));
1143 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1145 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1147 g_print ("%s\n", RESET_COLOR);
1148 gst_plugin_list_free (plugins);
1152 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1156 while (extensions[i]) {
1157 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1163 print_element_list (gboolean print_all, gchar * ftypes)
1165 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1166 GList *plugins, *orig_plugins;
1167 gchar **types = NULL;
1172 types = g_strsplit (ftypes, "/", -1);
1173 for (i = 0; types[i]; i++)
1174 *types[i] = g_ascii_toupper (*types[i]);
1178 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1180 GList *features, *orig_features;
1183 plugin = (GstPlugin *) (plugins->data);
1184 plugins = g_list_next (plugins);
1187 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1192 orig_features = features =
1193 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1194 gst_plugin_get_name (plugin));
1196 GstPluginFeature *feature;
1198 if (G_UNLIKELY (features->data == NULL))
1200 feature = GST_PLUGIN_FEATURE (features->data);
1203 if (GST_IS_ELEMENT_FACTORY (feature)) {
1205 GstElementFactory *factory;
1207 factory = GST_ELEMENT_FACTORY (feature);
1210 gboolean all_found = TRUE;
1213 gst_element_factory_get_metadata (factory,
1214 GST_ELEMENT_METADATA_KLASS);
1215 for (i = 0; types[i]; i++) {
1216 if (!strstr (klass, types[i])) {
1226 print_element_info (feature, TRUE);
1228 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1229 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1230 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1231 gst_element_factory_get_metadata (factory,
1232 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1233 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1234 GstTypeFindFactory *factory;
1235 const gchar *const *extensions;
1239 factory = GST_TYPE_FIND_FACTORY (feature);
1241 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1242 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1243 gst_plugin_feature_get_name (feature), RESET_COLOR);
1245 extensions = gst_type_find_factory_get_extensions (factory);
1246 if (extensions != NULL) {
1248 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1253 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1259 n_print ("%s%s%s: %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1260 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1261 GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1262 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1266 features = g_list_next (features);
1269 gst_plugin_feature_list_free (orig_features);
1272 gst_plugin_list_free (orig_plugins);
1276 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1278 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1279 if (blacklistcount) {
1281 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1282 blacklistcount), blacklistcount);
1283 g_print (" not shown)");
1285 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1286 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1287 g_print ("%s\n", RESET_COLOR);
1291 print_all_uri_handlers (void)
1293 GList *plugins, *p, *features, *f;
1295 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1297 for (p = plugins; p; p = p->next) {
1298 GstPlugin *plugin = (GstPlugin *) (p->data);
1301 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1302 gst_plugin_get_name (plugin));
1304 for (f = features; f; f = f->next) {
1305 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1307 if (GST_IS_ELEMENT_FACTORY (feature)) {
1308 GstElementFactory *factory;
1309 GstElement *element;
1311 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1313 g_print ("element plugin %s couldn't be loaded\n",
1314 gst_plugin_get_name (plugin));
1318 element = gst_element_factory_create (factory, NULL);
1320 g_print ("couldn't construct element for %s for some reason\n",
1321 GST_OBJECT_NAME (factory));
1322 gst_object_unref (factory);
1326 if (GST_IS_URI_HANDLER (element)) {
1327 const gchar *const *uri_protocols;
1328 const gchar *const *protocol;
1331 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1343 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1345 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1346 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1348 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1352 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1353 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1354 if (protocol != uri_protocols)
1356 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1361 gst_object_unref (element);
1362 gst_object_unref (factory);
1366 gst_plugin_feature_list_free (features);
1369 gst_plugin_list_free (plugins);
1373 print_plugin_info (GstPlugin * plugin)
1375 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1376 const gchar *filename = gst_plugin_get_filename (plugin);
1378 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1382 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1383 PROP_VALUE_COLOR, gst_plugin_get_name (plugin), RESET_COLOR);
1384 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1385 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1386 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1387 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1388 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1389 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1390 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1391 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1392 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1393 PROP_VALUE_COLOR, gst_plugin_get_source (plugin), RESET_COLOR);
1395 if (release_date != NULL) {
1396 const gchar *tz = "(UTC)";
1399 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1400 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1401 str = g_strdup (release_date);
1402 sep = strstr (str, "T");
1405 sep = strstr (sep + 1, "Z");
1411 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1412 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1415 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1416 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1417 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1418 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1426 print_plugin_features (GstPlugin * plugin)
1428 GList *features, *origlist;
1429 gint num_features = 0;
1430 gint num_elements = 0;
1431 gint num_tracers = 0;
1432 gint num_typefinders = 0;
1433 gint num_devproviders = 0;
1436 origlist = features =
1437 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1438 gst_plugin_get_name (plugin));
1441 GstPluginFeature *feature;
1443 feature = GST_PLUGIN_FEATURE (features->data);
1445 if (GST_IS_ELEMENT_FACTORY (feature)) {
1446 GstElementFactory *factory;
1448 factory = GST_ELEMENT_FACTORY (feature);
1449 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1450 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1451 gst_element_factory_get_metadata (factory,
1452 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1454 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1455 GstTypeFindFactory *factory;
1456 const gchar *const *extensions;
1458 factory = GST_TYPE_FIND_FACTORY (feature);
1459 extensions = gst_type_find_factory_get_extensions (factory);
1461 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1462 gst_plugin_feature_get_name (feature), RESET_COLOR);
1463 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1466 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1467 gst_plugin_feature_get_name (feature), RESET_COLOR,
1468 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1471 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1472 GstDeviceProviderFactory *factory;
1474 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1475 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1476 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1477 gst_device_provider_factory_get_metadata (factory,
1478 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1480 } else if (GST_IS_TRACER_FACTORY (feature)) {
1481 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1482 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1483 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1485 } else if (feature) {
1486 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1487 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1488 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1492 features = g_list_next (features);
1495 gst_plugin_feature_list_free (origlist);
1498 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1499 if (num_elements > 0)
1500 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1501 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1502 if (num_typefinders > 0)
1503 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1504 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1505 if (num_devproviders > 0)
1506 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1507 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1508 if (num_tracers > 0)
1509 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1510 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1512 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1513 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1519 print_feature_info (const gchar * feature_name, gboolean print_all)
1521 GstPluginFeature *feature;
1522 GstRegistry *registry = gst_registry_get ();
1525 if ((feature = gst_registry_find_feature (registry, feature_name,
1526 GST_TYPE_ELEMENT_FACTORY))) {
1527 ret = print_element_info (feature, print_all);
1530 if ((feature = gst_registry_find_feature (registry, feature_name,
1531 GST_TYPE_TYPE_FIND_FACTORY))) {
1532 ret = print_typefind_info (feature, print_all);
1535 if ((feature = gst_registry_find_feature (registry, feature_name,
1536 GST_TYPE_TRACER_FACTORY))) {
1537 ret = print_tracer_info (feature, print_all);
1541 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1546 gst_object_unref (feature);
1551 print_element_info (GstPluginFeature * feature, gboolean print_names)
1553 GstElementFactory *factory;
1554 GstElement *element;
1558 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1560 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1565 element = gst_element_factory_create (factory, NULL);
1567 gst_object_unref (factory);
1568 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1575 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1580 print_factory_details_info (factory);
1582 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1584 print_plugin_info (plugin);
1585 gst_object_unref (plugin);
1588 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1589 print_interfaces (G_OBJECT_TYPE (element));
1591 print_pad_templates_info (element, factory);
1592 print_clocking_info (element);
1593 print_uri_handler_info (element);
1594 print_pad_info (element);
1595 print_element_properties_info (element);
1596 print_signal_info (element);
1597 print_children_info (element);
1598 print_preset_list (element);
1600 gst_object_unref (element);
1601 gst_object_unref (factory);
1607 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1609 GstTypeFindFactory *factory;
1614 const gchar *const *extensions;
1616 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1618 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1625 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1630 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1631 rank = gst_plugin_feature_get_rank (feature);
1632 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1633 get_rank_name (s, rank), rank, RESET_COLOR);
1634 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1635 GST_OBJECT_NAME (factory), RESET_COLOR);
1636 caps = gst_type_find_factory_get_caps (factory);
1638 gchar *caps_str = gst_caps_to_string (factory->caps);
1640 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1641 caps_str, RESET_COLOR);
1644 extensions = gst_type_find_factory_get_extensions (factory);
1646 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1647 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1652 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1654 print_plugin_info (plugin);
1655 gst_object_unref (plugin);
1658 gst_object_unref (factory);
1664 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1666 GstTracerFactory *factory;
1671 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1673 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1677 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1679 gst_object_unref (factory);
1680 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1687 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1692 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1693 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1694 GST_OBJECT_NAME (factory), RESET_COLOR);
1697 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1699 print_plugin_info (plugin);
1700 gst_object_unref (plugin);
1703 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1704 print_interfaces (G_OBJECT_TYPE (tracer));
1706 /* TODO: list what hooks it registers
1707 * - the data is available in gsttracerutils, we need to iterate the
1708 * _priv_tracers hashtable for each probe and then check the list of hooks
1709 * for each probe whether hook->tracer == tracer :/
1712 /* TODO: list what records it emits
1713 * - in class_init tracers can create GstTracerRecord instances
1714 * - those only get logged right now and there is no association with the
1715 * tracer that created them
1716 * - we'd need to add them to GstTracerFactory
1717 * gst_tracer_class_add_record (klass, record);
1718 * - needs work in gstregistrychunks to (de)serialize specs
1719 * - gst_tracer_register() would need to iterate the list of records and
1720 * copy the record->spec into the factory
1723 gst_object_unref (tracer);
1724 gst_object_unref (factory);
1729 /* NOTE: Not coloring output from automatic install functions, as their output
1730 * is meant for machines, not humans.
1733 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1735 GstPadDirection direction;
1736 const gchar *type_name;
1738 const GList *static_templates, *l;
1739 GstCaps *caps = NULL;
1743 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1744 g_return_if_fail (klass != NULL);
1746 if (strstr (klass, "Demuxer") ||
1747 strstr (klass, "Decoder") ||
1748 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1749 type_name = "decoder";
1750 direction = GST_PAD_SINK;
1751 } else if (strstr (klass, "Muxer") ||
1752 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1753 type_name = "encoder";
1754 direction = GST_PAD_SRC;
1759 /* decoder/demuxer sink pads should always be static and there should only
1760 * be one, the same applies to encoders/muxers and source pads */
1761 static_templates = gst_element_factory_get_static_pad_templates (factory);
1762 for (l = static_templates; l != NULL; l = l->next) {
1763 GstStaticPadTemplate *tmpl = NULL;
1765 tmpl = (GstStaticPadTemplate *) l->data;
1766 if (tmpl->direction == direction) {
1767 caps = gst_static_pad_template_get_caps (tmpl);
1773 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1774 type_name, GST_OBJECT_NAME (factory));
1778 caps = gst_caps_make_writable (caps);
1779 num = gst_caps_get_size (caps);
1780 for (i = 0; i < num; ++i) {
1784 s = gst_caps_get_structure (caps, i);
1785 /* remove fields that are almost always just MIN-MAX of some sort
1786 * in order to make the caps look less messy */
1787 gst_structure_remove_field (s, "pixel-aspect-ratio");
1788 gst_structure_remove_field (s, "framerate");
1789 gst_structure_remove_field (s, "channels");
1790 gst_structure_remove_field (s, "width");
1791 gst_structure_remove_field (s, "height");
1792 gst_structure_remove_field (s, "rate");
1793 gst_structure_remove_field (s, "depth");
1794 gst_structure_remove_field (s, "clock-rate");
1795 s_str = gst_structure_to_string (s);
1796 g_print ("%s-%s\n", type_name, s_str);
1799 gst_caps_unref (caps);
1803 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1805 const gchar *const *protocols;
1807 protocols = gst_element_factory_get_uri_protocols (factory);
1808 if (protocols != NULL && *protocols != NULL) {
1809 switch (gst_element_factory_get_uri_type (factory)) {
1811 while (*protocols != NULL) {
1812 g_print ("urisink-%s\n", *protocols);
1817 while (*protocols != NULL) {
1818 g_print ("urisource-%s\n", *protocols);
1829 print_plugin_automatic_install_info (GstPlugin * plugin)
1831 GList *features, *l;
1833 /* not interested in typefind factories, only element factories */
1834 features = gst_registry_get_feature_list (gst_registry_get (),
1835 GST_TYPE_ELEMENT_FACTORY);
1837 for (l = features; l != NULL; l = l->next) {
1838 GstPluginFeature *feature;
1839 GstPlugin *feature_plugin;
1841 feature = GST_PLUGIN_FEATURE (l->data);
1843 /* only interested in the ones that are in the plugin we just loaded */
1844 feature_plugin = gst_plugin_feature_get_plugin (feature);
1845 if (feature_plugin == plugin) {
1846 GstElementFactory *factory;
1848 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1850 factory = GST_ELEMENT_FACTORY (feature);
1851 print_plugin_automatic_install_info_protocols (factory);
1852 print_plugin_automatic_install_info_codecs (factory);
1855 gst_object_unref (feature_plugin);
1858 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1859 g_list_free (features);
1863 print_all_plugin_automatic_install_info (void)
1865 GList *plugins, *orig_plugins;
1867 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1871 plugin = (GstPlugin *) (plugins->data);
1872 plugins = g_list_next (plugins);
1874 print_plugin_automatic_install_info (plugin);
1876 gst_plugin_list_free (orig_plugins);
1881 redirect_stdout (void)
1883 GError *error = NULL;
1889 pager = g_getenv ("PAGER");
1891 pager = DEFAULT_PAGER;
1893 argv = g_strsplit (pager, " ", 0);
1895 envp = g_get_environ ();
1896 envp = g_environ_setenv (envp, "LESS", DEFAULT_LESS_OPTS, TRUE);
1898 if (!g_spawn_async_with_pipes (NULL, argv, envp,
1899 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1900 NULL, NULL, &child_pid, &stdin_fd,
1901 /* pass null stdout/stderr to inherit our fds */
1902 NULL, NULL, &error)) {
1903 if (pager != DEFAULT_PAGER) {
1904 g_warning ("g_spawn_async_with_pipes() failed: %s\n",
1905 GST_STR_NULL (error->message));
1909 g_clear_error (&error);
1914 /* redirect our stdout to child stdin */
1915 dup2 (stdin_fd, STDOUT_FILENO);
1916 if (isatty (STDERR_FILENO))
1917 dup2 (stdin_fd, STDERR_FILENO);
1927 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
1929 g_spawn_close_pid (child_pid);
1930 g_main_loop_quit (loop);
1935 main (int argc, char *argv[])
1937 gboolean print_all = FALSE;
1938 gboolean do_print_blacklist = FALSE;
1939 gboolean plugin_name = FALSE;
1940 gboolean print_aii = FALSE;
1941 gboolean uri_handlers = FALSE;
1942 gboolean check_exists = FALSE;
1943 gchar *min_version = NULL;
1944 guint minver_maj = GST_VERSION_MAJOR;
1945 guint minver_min = GST_VERSION_MINOR;
1946 guint minver_micro = 0;
1947 gchar *types = NULL;
1948 const gchar *no_colors;
1950 #ifndef GST_DISABLE_OPTION_PARSING
1951 GOptionEntry options[] = {
1952 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1953 N_("Print all elements"), NULL},
1954 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1955 N_("Print list of blacklisted files"), NULL},
1956 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1957 N_("Print a machine-parsable list of features the specified plugin "
1958 "or all plugins provide.\n "
1959 "Useful in connection with external automatic plugin "
1960 "installation mechanisms"), NULL},
1961 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1962 N_("List the plugin contents"), NULL},
1963 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1964 N_("A slashes ('/') separated list of types of elements (also known "
1965 "as klass) to list. (unordered)"), NULL},
1966 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1967 N_("Check if the specified element or plugin exists"), NULL},
1968 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1970 ("When checking if an element or plugin exists, also check that its "
1971 "version is at least the version specified"), NULL},
1972 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1974 ("Print supported URI schemes, with the elements that implement them"),
1976 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1979 ("Disable colors in output. You can also achieve the same by setting"
1980 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
1982 GST_TOOLS_GOPTION_VERSION,
1985 GOptionContext *ctx;
1989 setlocale (LC_ALL, "");
1992 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1993 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1994 textdomain (GETTEXT_PACKAGE);
1997 /* avoid glib warnings when inspecting deprecated properties */
1998 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
2000 g_set_prgname ("gst-inspect-" GST_API_VERSION);
2002 #ifndef GST_DISABLE_OPTION_PARSING
2003 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2004 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2005 g_option_context_add_group (ctx, gst_init_get_option_group ());
2006 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2007 g_printerr ("Error initializing: %s\n", err->message);
2008 g_clear_error (&err);
2009 g_option_context_free (ctx);
2012 g_option_context_free (ctx);
2014 gst_init (&argc, &argv);
2017 gst_tools_print_version ();
2019 if (print_all && argc > 1) {
2020 g_printerr ("-a requires no extra arguments\n");
2024 if (uri_handlers && argc > 1) {
2025 g_printerr ("-u requires no extra arguments\n");
2029 /* --atleast-version implies --exists */
2030 if (min_version != NULL) {
2031 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2032 &minver_micro) < 2) {
2033 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2037 check_exists = TRUE;
2042 g_printerr ("--exists requires an extra command line argument\n");
2046 GstPluginFeature *feature;
2048 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2049 if (feature != NULL && gst_plugin_feature_check_version (feature,
2050 minver_maj, minver_min, minver_micro)) {
2057 gst_object_unref (feature);
2059 /* FIXME: support checking for plugins too */
2060 g_printerr ("Checking for plugins is not supported yet\n");
2067 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2068 /* We only support truecolor */
2069 colored_output &= (no_colors == NULL);
2072 if (isatty (STDOUT_FILENO)) {
2073 if (redirect_stdout ())
2074 loop = g_main_loop_new (NULL, FALSE);
2076 colored_output = FALSE;
2078 #elif defined(G_OS_WIN32)
2080 gint fd = _fileno (stdout);
2081 /* On Windows 10, g_log_writer_supports_color will also setup the console
2082 * so that it correctly interprets ANSI VT sequences if it's supported */
2083 if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2084 colored_output = FALSE;
2088 /* if no arguments, print out list of elements */
2090 print_all_uri_handlers ();
2091 } else if (argc == 1 || print_all) {
2092 if (do_print_blacklist)
2096 print_all_plugin_automatic_install_info ();
2098 print_element_list (print_all, types);
2101 /* else we try to get a factory */
2102 const char *arg = argv[argc - 1];
2106 retval = print_feature_info (arg, print_all);
2109 /* otherwise check if it's a plugin */
2111 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2113 /* if there is such a plugin, print out info */
2116 print_plugin_automatic_install_info (plugin);
2118 print_plugin_info (plugin);
2119 print_plugin_features (plugin);
2122 GError *error = NULL;
2124 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2125 plugin = gst_plugin_load_file (arg, &error);
2129 print_plugin_automatic_install_info (plugin);
2131 print_plugin_info (plugin);
2132 print_plugin_features (plugin);
2135 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2136 g_clear_error (&error);
2141 g_printerr (_("No such element or plugin '%s'\n"), arg);
2155 /* So that the pipe we create in redirect_stdout() is closed */
2156 close (STDOUT_FILENO);
2157 close (STDERR_FILENO);
2158 g_child_watch_add (child_pid, child_exit_cb, NULL);
2159 g_main_loop_run (loop);
2160 g_main_loop_unref (loop);