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>
45 /* "R" : support color
46 * "X" : do not clear the screen when leaving the pager
47 * "F" : skip the pager if content fit into the screen
49 #define DEFAULT_LESS_OPTS "RXF"
51 gboolean colored_output = TRUE;
54 static const gchar DEFAULT_PAGER[] = "less";
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, ...)
138 g_print ("%s", _name);
140 for (i = 0; i < indent; ++i)
143 va_start (args, format);
144 str = gst_info_strdup_vprintf (format, args);
155 print_field (GQuark field, const GValue * value, gpointer pfx)
157 gchar *str = gst_value_serialize (value);
159 n_print ("%s %s%15s%s: %s%s%s\n",
160 (gchar *) pfx, FIELD_NAME_COLOR, g_quark_to_string (field), RESET_COLOR,
161 FIELD_VALUE_COLOR, str, RESET_COLOR);
167 print_caps (const GstCaps * caps, const gchar * pfx)
171 g_return_if_fail (caps != NULL);
173 if (gst_caps_is_any (caps)) {
174 n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
177 if (gst_caps_is_empty (caps)) {
178 n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
182 for (i = 0; i < gst_caps_get_size (caps); i++) {
183 GstStructure *structure = gst_caps_get_structure (caps, i);
184 GstCapsFeatures *features = gst_caps_get_features (caps, i);
186 if (features && (gst_caps_features_is_any (features) ||
187 !gst_caps_features_is_equal (features,
188 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
189 gchar *features_string = gst_caps_features_to_string (features);
191 n_print ("%s%s%s%s(%s%s%s)\n", pfx, STRUCT_NAME_COLOR,
192 gst_structure_get_name (structure), RESET_COLOR,
193 CAPS_FEATURE_COLOR, features_string, RESET_COLOR);
194 g_free (features_string);
196 n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
197 gst_structure_get_name (structure), RESET_COLOR);
199 gst_structure_foreach (structure, print_field, (gpointer) pfx);
204 get_rank_name (char *s, gint rank)
206 static const int ranks[4] = {
207 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
209 static const char *rank_names[4] = { "none", "marginal", "secondary",
216 for (i = 0; i < 4; i++) {
217 if (rank == ranks[i])
218 return rank_names[i];
219 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
224 sprintf (s, "%s %c %d", rank_names[best_i],
225 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
231 print_factory_details_info (GstElementFactory * factory)
237 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
238 n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
241 n_print ("%s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
242 get_rank_name (s, rank), rank, RESET_COLOR);
244 keys = gst_element_factory_get_metadata_keys (factory);
246 for (k = keys; *k != NULL; ++k) {
250 val = gst_element_factory_get_metadata (factory, key);
251 key[0] = g_ascii_toupper (key[0]);
252 n_print ("%s%-25s%s%s%s\n", PROP_NAME_COLOR, key, PROP_VALUE_COLOR, val,
262 print_hierarchy (GType type, gint level, gint * maxlevel)
267 parent = g_type_parent (type);
269 *maxlevel = *maxlevel + 1;
273 print_hierarchy (parent, level, maxlevel);
276 g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
278 for (i = 1; i < *maxlevel - level; i++)
280 if (*maxlevel - level)
281 g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
283 g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
290 print_interfaces (GType type)
293 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
297 n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
301 n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
312 flags_to_string (GFlagsValue * vals, guint flags)
317 /* first look for an exact match and count the number of values */
318 for (i = 0; vals[i].value_name != NULL; ++i) {
319 if (vals[i].value == flags)
320 return g_strdup (vals[i].value_nick);
323 s = g_string_new (NULL);
325 /* we assume the values are sorted from lowest to highest value */
329 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
331 g_string_append_c (s, '+');
332 g_string_append (s, vals[i].value_nick);
333 flags_left -= vals[i].value;
340 g_string_assign (s, "(none)");
342 return g_string_free (s, FALSE);
345 #define KNOWN_PARAM_FLAGS \
346 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
347 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
348 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
349 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
350 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY | \
351 GST_PARAM_CONDITIONALLY_AVAILABLE)
354 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
356 return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
359 /* obj will be NULL if we're printing properties of pad template pads */
361 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
364 GParamSpec **property_specs;
365 guint num_properties, i;
369 property_specs = g_object_class_list_properties (obj_class, &num_properties);
370 g_qsort_with_data (property_specs, num_properties, sizeof (gpointer),
371 (GCompareDataFunc) sort_gparamspecs, NULL);
373 n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
377 for (i = 0; i < num_properties; i++) {
378 GValue value = { 0, };
379 GParamSpec *param = property_specs[i];
380 GType owner_type = param->owner_type;
382 /* We're printing pad properties */
383 if (obj == NULL && (owner_type == G_TYPE_OBJECT
384 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
387 g_value_init (&value, param->value_type);
389 n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
390 g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
391 g_param_spec_get_blurb (param), RESET_COLOR);
396 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
397 readable = ! !(param->flags & G_PARAM_READABLE);
398 if (readable && obj != NULL) {
399 g_object_get_property (obj, param->name, &value);
401 /* if we can't read the property value, assume it's set to the default
402 * (which might not be entirely true for sub-classes, but that's an
403 * unlikely corner-case anyway) */
404 g_param_value_set_default (param, &value);
407 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
408 _("readable"), RESET_COLOR);
411 if (param->flags & G_PARAM_WRITABLE) {
412 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
413 _("writable"), RESET_COLOR);
416 if (param->flags & G_PARAM_DEPRECATED) {
417 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
418 _("deprecated"), RESET_COLOR);
421 if (param->flags & GST_PARAM_CONTROLLABLE) {
422 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
426 if (param->flags & GST_PARAM_CONDITIONALLY_AVAILABLE) {
427 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("conditionally available"),
431 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
432 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
433 _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
434 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
435 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
436 _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
437 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
438 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
439 _("changeable only in NULL or READY state"), RESET_COLOR);
441 if (param->flags & ~KNOWN_PARAM_FLAGS) {
442 g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
443 param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
447 switch (G_VALUE_TYPE (&value)) {
450 const char *string_val = g_value_get_string (&value);
452 n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
454 if (string_val == NULL)
455 g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
456 PROP_ATTR_VALUE_COLOR, RESET_COLOR);
458 g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
459 PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
464 gboolean bool_val = g_value_get_boolean (&value);
466 n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
467 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
468 PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
473 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
476 ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
477 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
478 PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
479 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
480 PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
482 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
483 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
484 g_param_spec_get_name (param));
489 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
491 n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
492 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
493 PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
494 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
495 g_value_get_long (&value), RESET_COLOR);
497 GST_ERROR ("%s: property '%s' of type long: consider changing to "
498 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
499 g_param_spec_get_name (param));
504 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
507 ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
508 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
509 PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
510 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
511 g_value_get_uint (&value), RESET_COLOR);
516 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
518 n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
519 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
520 PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
521 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
522 g_value_get_int (&value), RESET_COLOR);
527 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
529 n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
530 "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
531 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
532 PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
533 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
534 PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
539 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
541 n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
542 G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
543 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
544 PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
545 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
546 PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
551 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
553 n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
554 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
555 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
556 pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
557 RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
563 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
565 n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
566 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
567 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
568 pdouble->minimum, pdouble->maximum, RESET_COLOR,
569 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
570 g_value_get_double (&value), RESET_COLOR);
575 GST_ERROR ("%s: property '%s' of type char: consider changing to "
576 "int/string", G_OBJECT_CLASS_NAME (obj_class),
577 g_param_spec_get_name (param));
580 if (param->value_type == GST_TYPE_CAPS) {
581 const GstCaps *caps = gst_value_get_caps (&value);
584 n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
586 print_caps (caps, " ");
588 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
592 const gchar *value_nick = "";
594 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
595 enum_value = g_value_get_enum (&value);
597 while (values[j].value_name) {
598 if (values[j].value == enum_value)
599 value_nick = values[j].value_nick;
603 n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
604 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
605 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
606 enum_value, value_nick, RESET_COLOR);
609 while (values[j].value_name) {
611 n_print (" %s(%d)%s: %s%-16s%s - %s%s%s",
612 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
613 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
614 DESC_COLOR, values[j].value_name, RESET_COLOR);
617 /* g_type_class_unref (ec); */
618 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
619 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
623 vals = pflags->flags_class->values;
625 cur = flags_to_string (vals, g_value_get_flags (&value));
627 n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
628 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
629 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
630 g_value_get_flags (&value), cur, RESET_COLOR);
632 while (vals[0].value_name) {
634 n_print (" %s(0x%08x)%s: %s%-16s%s - %s%s%s",
635 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
636 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
637 DESC_COLOR, vals[0].value_name, RESET_COLOR);
642 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
643 n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
644 RESET_COLOR, DATATYPE_COLOR,
645 g_type_name (param->value_type), RESET_COLOR);
646 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
647 n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
648 RESET_COLOR, DATATYPE_COLOR,
649 g_type_name (param->value_type), RESET_COLOR);
650 if (param->value_type == GST_TYPE_STRUCTURE) {
651 const GstStructure *s = gst_value_get_structure (&value);
654 gst_structure_foreach (s, print_field,
658 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
659 if (param->value_type != G_TYPE_POINTER) {
660 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
661 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
664 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
666 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
667 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
669 if (pvarray->element_spec) {
670 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
671 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
672 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
674 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
676 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
677 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
679 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
680 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
681 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
682 pfraction->min_num, pfraction->min_den, pfraction->max_num,
683 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
684 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
685 gst_value_get_fraction_numerator (&value),
686 gst_value_get_fraction_denominator (&value), RESET_COLOR);
687 } else if (param->value_type == GST_TYPE_ARRAY) {
688 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
690 if (parray->element_spec) {
691 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
692 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
693 g_type_name (parray->element_spec->value_type), RESET_COLOR);
695 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
699 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
700 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
701 g_type_name (param->value_type), RESET_COLOR);
706 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
712 g_value_reset (&value);
714 if (num_properties == 0)
715 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
719 g_free (property_specs);
723 print_element_properties_info (GstElement * element)
726 print_object_properties_info (G_OBJECT (element),
727 G_OBJECT_GET_CLASS (element), "Element Properties");
731 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
734 GstStaticPadTemplate *padtemplate;
735 GstPadTemplate *tmpl;
737 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
741 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
742 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
746 pads = gst_element_factory_get_static_pad_templates (factory);
748 padtemplate = (GstStaticPadTemplate *) (pads->data);
749 pads = g_list_next (pads);
751 if (padtemplate->direction == GST_PAD_SRC)
752 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
753 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
754 else if (padtemplate->direction == GST_PAD_SINK)
755 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
756 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
758 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
759 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
763 if (padtemplate->presence == GST_PAD_ALWAYS)
764 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
765 PROP_VALUE_COLOR, RESET_COLOR);
766 else if (padtemplate->presence == GST_PAD_SOMETIMES)
767 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
768 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
769 else if (padtemplate->presence == GST_PAD_REQUEST) {
770 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
771 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
773 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
774 PROP_VALUE_COLOR, RESET_COLOR);
776 if (padtemplate->static_caps.string) {
777 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
779 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
782 print_caps (caps, ""); // FIXME
785 gst_caps_unref (caps);
788 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
789 padtemplate->name_template);
791 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
793 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
796 pad_klass = g_type_class_ref (pad_type);
797 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
798 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
799 print_object_properties_info (NULL, pad_klass, "Pad Properties");
800 g_type_class_unref (pad_klass);
815 print_clocking_info (GstElement * element)
817 gboolean requires_clock, provides_clock;
820 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
822 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
824 if (!requires_clock && !provides_clock) {
826 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
832 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
836 if (requires_clock) {
837 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
840 if (provides_clock) {
843 clock = gst_element_get_clock (element);
845 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
846 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
847 gst_object_unref (clock);
849 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
850 PROP_VALUE_COLOR, RESET_COLOR);
857 print_uri_handler_info (GstElement * element)
859 if (GST_IS_URI_HANDLER (element)) {
860 const gchar *const *uri_protocols;
861 const gchar *uri_type;
863 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
865 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
869 uri_type = "unknown";
871 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
874 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
878 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
880 if (uri_protocols && *uri_protocols) {
881 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
883 for (; *uri_protocols != NULL; uri_protocols++)
884 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
888 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
894 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
900 print_pad_info (GstElement * element)
906 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
910 if (!element->numpads) {
911 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
915 pads = element->pads;
920 pad = GST_PAD (pads->data);
921 pads = g_list_next (pads);
923 name = gst_pad_get_name (pad);
924 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
925 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
926 PROP_VALUE_COLOR, name, RESET_COLOR);
927 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
928 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
929 PROP_VALUE_COLOR, name, RESET_COLOR);
931 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
932 PROP_VALUE_COLOR, name, RESET_COLOR);
936 if (pad->padtemplate) {
938 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
939 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
943 caps = gst_pad_get_current_caps (pad);
945 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
947 print_caps (caps, ""); // FIXME
949 gst_caps_unref (caps);
958 has_sometimes_template (GstElement * element)
960 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
963 for (l = klass->padtemplates; l != NULL; l = l->next) {
964 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
972 gtype_needs_ptr_marker (GType type)
974 if (type == G_TYPE_POINTER)
977 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
978 || G_TYPE_IS_OBJECT (type))
985 print_signal_info (GstElement * element)
987 /* Signals/Actions Block */
991 GSignalQuery *query = NULL;
993 GSList *found_signals, *l;
995 for (k = 0; k < 2; k++) {
996 found_signals = NULL;
998 /* For elements that have sometimes pads, also list a few useful GstElement
999 * signals. Put these first, so element-specific ones come later. */
1000 if (k == 0 && has_sometimes_template (element)) {
1001 query = g_new0 (GSignalQuery, 1);
1002 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
1003 found_signals = g_slist_append (found_signals, query);
1004 query = g_new0 (GSignalQuery, 1);
1005 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
1006 found_signals = g_slist_append (found_signals, query);
1007 query = g_new0 (GSignalQuery, 1);
1008 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
1010 found_signals = g_slist_append (found_signals, query);
1013 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
1014 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1017 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1020 signals = g_signal_list_ids (type, &nsignals);
1021 for (i = 0; i < nsignals; i++) {
1022 query = g_new0 (GSignalQuery, 1);
1023 g_signal_query (signals[i], query);
1025 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1026 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1027 found_signals = g_slist_append (found_signals, query);
1035 if (found_signals) {
1038 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1040 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1045 for (l = found_signals; l; l = l->next) {
1050 query = (GSignalQuery *) l->data;
1051 indent_len = strlen (query->signal_name) +
1052 strlen (g_type_name (query->return_type)) + 24;
1054 if (gtype_needs_ptr_marker (query->return_type)) {
1061 indent = g_new0 (gchar, indent_len + 1);
1062 memset (indent, ' ', indent_len);
1064 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1065 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1066 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1067 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1068 PROP_VALUE_COLOR, RESET_COLOR);
1070 for (j = 0; j < query->n_params; j++) {
1071 const gchar *type_name, *asterisk;
1073 type_name = g_type_name (query->param_types[j]);
1074 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1077 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1078 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1083 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1084 PROP_VALUE_COLOR, RESET_COLOR);
1091 if (found_signals) {
1092 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1093 g_slist_free (found_signals);
1099 print_children_info (GstElement * element)
1103 if (!GST_IS_BIN (element))
1106 children = (GList *) GST_BIN (element)->children;
1109 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1113 n_print (" %s%s%s\n", DATATYPE_COLOR,
1114 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1115 children = g_list_next (children);
1120 print_preset_list (GstElement * element)
1122 gchar **presets, **preset;
1124 if (!GST_IS_PRESET (element))
1127 presets = gst_preset_get_preset_names (GST_PRESET (element));
1128 if (presets && *presets) {
1130 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1131 for (preset = presets; *preset; preset++) {
1132 gchar *comment = NULL;
1133 n_print (" \"%s\"", *preset);
1135 if (gst_preset_get_meta (GST_PRESET (element), *preset, "comment",
1136 &comment) && comment)
1137 g_print (": %s", comment);
1141 g_strfreev (presets);
1146 print_blacklist (void)
1148 GList *plugins, *cur;
1151 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1153 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1154 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1155 GstPlugin *plugin = (GstPlugin *) (cur->data);
1156 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1157 g_print (" %s\n", gst_plugin_get_name (plugin));
1163 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1165 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1167 g_print ("%s\n", RESET_COLOR);
1168 gst_plugin_list_free (plugins);
1172 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1176 while (extensions[i]) {
1177 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1183 print_element_list (gboolean print_all, gchar * ftypes)
1185 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1186 GList *plugins, *orig_plugins;
1187 gchar **types = NULL;
1192 types = g_strsplit (ftypes, "/", -1);
1193 for (i = 0; types[i]; i++)
1194 *types[i] = g_ascii_toupper (*types[i]);
1198 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1200 GList *features, *orig_features;
1203 plugin = (GstPlugin *) (plugins->data);
1204 plugins = g_list_next (plugins);
1207 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1212 orig_features = features =
1213 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1214 gst_plugin_get_name (plugin));
1216 GstPluginFeature *feature;
1218 if (G_UNLIKELY (features->data == NULL))
1220 feature = GST_PLUGIN_FEATURE (features->data);
1223 if (GST_IS_ELEMENT_FACTORY (feature)) {
1225 GstElementFactory *factory;
1227 factory = GST_ELEMENT_FACTORY (feature);
1230 gboolean all_found = TRUE;
1233 gst_element_factory_get_metadata (factory,
1234 GST_ELEMENT_METADATA_KLASS);
1235 for (i = 0; types[i]; i++) {
1236 if (!strstr (klass, types[i])) {
1246 print_element_info (feature, TRUE);
1248 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1249 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1250 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1251 gst_element_factory_get_metadata (factory,
1252 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1253 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1254 GstTypeFindFactory *factory;
1255 const gchar *const *extensions;
1259 factory = GST_TYPE_FIND_FACTORY (feature);
1261 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1262 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1263 gst_plugin_feature_get_name (feature), RESET_COLOR);
1265 extensions = gst_type_find_factory_get_extensions (factory);
1266 if (extensions != NULL) {
1268 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1273 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1279 n_print ("%s%s%s: %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1280 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1281 GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1282 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1286 features = g_list_next (features);
1289 gst_plugin_feature_list_free (orig_features);
1292 gst_plugin_list_free (orig_plugins);
1296 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1298 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1299 if (blacklistcount) {
1301 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1302 blacklistcount), blacklistcount);
1303 g_print (" not shown)");
1305 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1306 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1307 g_print ("%s\n", RESET_COLOR);
1311 print_all_uri_handlers (void)
1313 GList *plugins, *p, *features, *f;
1315 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1317 for (p = plugins; p; p = p->next) {
1318 GstPlugin *plugin = (GstPlugin *) (p->data);
1321 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1322 gst_plugin_get_name (plugin));
1324 for (f = features; f; f = f->next) {
1325 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1327 if (GST_IS_ELEMENT_FACTORY (feature)) {
1328 GstElementFactory *factory;
1329 GstElement *element;
1331 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1333 g_print ("element plugin %s couldn't be loaded\n",
1334 gst_plugin_get_name (plugin));
1338 element = gst_element_factory_create (factory, NULL);
1340 g_print ("couldn't construct element for %s for some reason\n",
1341 GST_OBJECT_NAME (factory));
1342 gst_object_unref (factory);
1346 if (GST_IS_URI_HANDLER (element)) {
1347 const gchar *const *uri_protocols;
1348 const gchar *const *protocol;
1351 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1363 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1365 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1366 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1368 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1372 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1373 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1374 if (protocol != uri_protocols)
1376 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1381 gst_object_unref (element);
1382 gst_object_unref (factory);
1386 gst_plugin_feature_list_free (features);
1389 gst_plugin_list_free (plugins);
1393 print_plugin_info (GstPlugin * plugin)
1395 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1396 const gchar *filename = gst_plugin_get_filename (plugin);
1398 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1402 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1403 PROP_VALUE_COLOR, gst_plugin_get_name (plugin), RESET_COLOR);
1404 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1405 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1406 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1407 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1408 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1409 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1410 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1411 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1412 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1413 PROP_VALUE_COLOR, gst_plugin_get_source (plugin), RESET_COLOR);
1415 if (release_date != NULL) {
1416 const gchar *tz = "(UTC)";
1419 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1420 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1421 str = g_strdup (release_date);
1422 sep = strstr (str, "T");
1425 sep = strstr (sep + 1, "Z");
1431 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1432 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1435 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1436 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1437 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1438 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1446 print_plugin_features (GstPlugin * plugin)
1448 GList *features, *origlist;
1449 gint num_features = 0;
1450 gint num_elements = 0;
1451 gint num_tracers = 0;
1452 gint num_typefinders = 0;
1453 gint num_devproviders = 0;
1456 origlist = features =
1457 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1458 gst_plugin_get_name (plugin));
1461 GstPluginFeature *feature;
1463 feature = GST_PLUGIN_FEATURE (features->data);
1465 if (GST_IS_ELEMENT_FACTORY (feature)) {
1466 GstElementFactory *factory;
1468 factory = GST_ELEMENT_FACTORY (feature);
1469 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1470 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1471 gst_element_factory_get_metadata (factory,
1472 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1474 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1475 GstTypeFindFactory *factory;
1476 const gchar *const *extensions;
1478 factory = GST_TYPE_FIND_FACTORY (feature);
1479 extensions = gst_type_find_factory_get_extensions (factory);
1481 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1482 gst_plugin_feature_get_name (feature), RESET_COLOR);
1483 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1486 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1487 gst_plugin_feature_get_name (feature), RESET_COLOR,
1488 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1491 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1492 GstDeviceProviderFactory *factory;
1494 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1495 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1496 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1497 gst_device_provider_factory_get_metadata (factory,
1498 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1500 } else if (GST_IS_TRACER_FACTORY (feature)) {
1501 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1502 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1503 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1505 } else if (feature) {
1506 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1507 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1508 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1512 features = g_list_next (features);
1515 gst_plugin_feature_list_free (origlist);
1518 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1519 if (num_elements > 0)
1520 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1521 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1522 if (num_typefinders > 0)
1523 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1524 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1525 if (num_devproviders > 0)
1526 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1527 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1528 if (num_tracers > 0)
1529 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1530 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1532 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1533 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1539 print_feature_info (const gchar * feature_name, gboolean print_all)
1541 GstPluginFeature *feature;
1542 GstRegistry *registry = gst_registry_get ();
1545 if ((feature = gst_registry_find_feature (registry, feature_name,
1546 GST_TYPE_ELEMENT_FACTORY))) {
1547 ret = print_element_info (feature, print_all);
1550 if ((feature = gst_registry_find_feature (registry, feature_name,
1551 GST_TYPE_TYPE_FIND_FACTORY))) {
1552 ret = print_typefind_info (feature, print_all);
1555 if ((feature = gst_registry_find_feature (registry, feature_name,
1556 GST_TYPE_TRACER_FACTORY))) {
1557 ret = print_tracer_info (feature, print_all);
1561 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1566 gst_object_unref (feature);
1571 print_element_info (GstPluginFeature * feature, gboolean print_names)
1573 GstElementFactory *factory;
1574 GstElement *element;
1578 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1580 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1585 element = gst_element_factory_create (factory, NULL);
1587 gst_object_unref (factory);
1588 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1595 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1600 print_factory_details_info (factory);
1602 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1604 print_plugin_info (plugin);
1605 gst_object_unref (plugin);
1608 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1609 print_interfaces (G_OBJECT_TYPE (element));
1611 print_pad_templates_info (element, factory);
1612 print_clocking_info (element);
1613 print_uri_handler_info (element);
1614 print_pad_info (element);
1615 print_element_properties_info (element);
1616 print_signal_info (element);
1617 print_children_info (element);
1618 print_preset_list (element);
1620 gst_object_unref (element);
1621 gst_object_unref (factory);
1627 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1629 GstTypeFindFactory *factory;
1634 const gchar *const *extensions;
1636 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1638 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1645 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1650 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1651 rank = gst_plugin_feature_get_rank (feature);
1652 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1653 get_rank_name (s, rank), rank, RESET_COLOR);
1654 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1655 GST_OBJECT_NAME (factory), RESET_COLOR);
1656 caps = gst_type_find_factory_get_caps (factory);
1658 gchar *caps_str = gst_caps_to_string (factory->caps);
1660 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1661 caps_str, RESET_COLOR);
1664 extensions = gst_type_find_factory_get_extensions (factory);
1666 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1667 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1672 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1674 print_plugin_info (plugin);
1675 gst_object_unref (plugin);
1678 gst_object_unref (factory);
1684 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1686 GstTracerFactory *factory;
1691 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1693 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1697 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1699 gst_object_unref (factory);
1700 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1707 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1712 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1713 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1714 GST_OBJECT_NAME (factory), RESET_COLOR);
1717 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1719 print_plugin_info (plugin);
1720 gst_object_unref (plugin);
1723 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1724 print_interfaces (G_OBJECT_TYPE (tracer));
1726 /* TODO: list what hooks it registers
1727 * - the data is available in gsttracerutils, we need to iterate the
1728 * _priv_tracers hashtable for each probe and then check the list of hooks
1729 * for each probe whether hook->tracer == tracer :/
1732 /* TODO: list what records it emits
1733 * - in class_init tracers can create GstTracerRecord instances
1734 * - those only get logged right now and there is no association with the
1735 * tracer that created them
1736 * - we'd need to add them to GstTracerFactory
1737 * gst_tracer_class_add_record (klass, record);
1738 * - needs work in gstregistrychunks to (de)serialize specs
1739 * - gst_tracer_register() would need to iterate the list of records and
1740 * copy the record->spec into the factory
1743 gst_object_unref (tracer);
1744 gst_object_unref (factory);
1749 /* NOTE: Not coloring output from automatic install functions, as their output
1750 * is meant for machines, not humans.
1753 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1755 GstPadDirection direction;
1756 const gchar *type_name;
1758 const GList *static_templates, *l;
1759 GstCaps *caps = NULL;
1763 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1764 g_return_if_fail (klass != NULL);
1766 if (strstr (klass, "Demuxer") ||
1767 strstr (klass, "Decoder") ||
1768 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1769 type_name = "decoder";
1770 direction = GST_PAD_SINK;
1771 } else if (strstr (klass, "Muxer") ||
1772 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1773 type_name = "encoder";
1774 direction = GST_PAD_SRC;
1779 /* decoder/demuxer sink pads should always be static and there should only
1780 * be one, the same applies to encoders/muxers and source pads */
1781 static_templates = gst_element_factory_get_static_pad_templates (factory);
1782 for (l = static_templates; l != NULL; l = l->next) {
1783 GstStaticPadTemplate *tmpl = NULL;
1785 tmpl = (GstStaticPadTemplate *) l->data;
1786 if (tmpl->direction == direction) {
1787 caps = gst_static_pad_template_get_caps (tmpl);
1793 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1794 type_name, GST_OBJECT_NAME (factory));
1798 caps = gst_caps_make_writable (caps);
1799 num = gst_caps_get_size (caps);
1800 for (i = 0; i < num; ++i) {
1804 s = gst_caps_get_structure (caps, i);
1805 /* remove fields that are almost always just MIN-MAX of some sort
1806 * in order to make the caps look less messy */
1807 gst_structure_remove_field (s, "pixel-aspect-ratio");
1808 gst_structure_remove_field (s, "framerate");
1809 gst_structure_remove_field (s, "channels");
1810 gst_structure_remove_field (s, "width");
1811 gst_structure_remove_field (s, "height");
1812 gst_structure_remove_field (s, "rate");
1813 gst_structure_remove_field (s, "depth");
1814 gst_structure_remove_field (s, "clock-rate");
1815 s_str = gst_structure_to_string (s);
1816 g_print ("%s-%s\n", type_name, s_str);
1819 gst_caps_unref (caps);
1823 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1825 const gchar *const *protocols;
1827 protocols = gst_element_factory_get_uri_protocols (factory);
1828 if (protocols != NULL && *protocols != NULL) {
1829 switch (gst_element_factory_get_uri_type (factory)) {
1831 while (*protocols != NULL) {
1832 g_print ("urisink-%s\n", *protocols);
1837 while (*protocols != NULL) {
1838 g_print ("urisource-%s\n", *protocols);
1849 print_plugin_automatic_install_info (GstPlugin * plugin)
1851 GList *features, *l;
1853 /* not interested in typefind factories, only element factories */
1854 features = gst_registry_get_feature_list (gst_registry_get (),
1855 GST_TYPE_ELEMENT_FACTORY);
1857 for (l = features; l != NULL; l = l->next) {
1858 GstPluginFeature *feature;
1859 GstPlugin *feature_plugin;
1861 feature = GST_PLUGIN_FEATURE (l->data);
1863 /* only interested in the ones that are in the plugin we just loaded */
1864 feature_plugin = gst_plugin_feature_get_plugin (feature);
1865 if (feature_plugin == plugin) {
1866 GstElementFactory *factory;
1868 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1870 factory = GST_ELEMENT_FACTORY (feature);
1871 print_plugin_automatic_install_info_protocols (factory);
1872 print_plugin_automatic_install_info_codecs (factory);
1875 gst_object_unref (feature_plugin);
1878 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1879 g_list_free (features);
1883 print_all_plugin_automatic_install_info (void)
1885 GList *plugins, *orig_plugins;
1887 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1891 plugin = (GstPlugin *) (plugins->data);
1892 plugins = g_list_next (plugins);
1894 print_plugin_automatic_install_info (plugin);
1896 gst_plugin_list_free (orig_plugins);
1901 redirect_stdout (void)
1903 GError *error = NULL;
1909 pager = g_getenv ("PAGER");
1911 pager = DEFAULT_PAGER;
1913 argv = g_strsplit (pager, " ", 0);
1915 envp = g_get_environ ();
1916 envp = g_environ_setenv (envp, "LESS", DEFAULT_LESS_OPTS, TRUE);
1918 if (!g_spawn_async_with_pipes (NULL, argv, envp,
1919 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1920 NULL, NULL, &child_pid, &stdin_fd,
1921 /* pass null stdout/stderr to inherit our fds */
1922 NULL, NULL, &error)) {
1923 if (pager != DEFAULT_PAGER) {
1924 g_warning ("g_spawn_async_with_pipes() failed: %s\n",
1925 GST_STR_NULL (error->message));
1929 g_clear_error (&error);
1934 /* redirect our stdout to child stdin */
1935 dup2 (stdin_fd, STDOUT_FILENO);
1936 if (isatty (STDERR_FILENO))
1937 dup2 (stdin_fd, STDERR_FILENO);
1947 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
1949 g_spawn_close_pid (child_pid);
1950 g_main_loop_quit (loop);
1955 main (int argc, char *argv[])
1957 gboolean print_all = FALSE;
1958 gboolean do_print_blacklist = FALSE;
1959 gboolean plugin_name = FALSE;
1960 gboolean print_aii = FALSE;
1961 gboolean uri_handlers = FALSE;
1962 gboolean check_exists = FALSE;
1963 gboolean color_always = FALSE;
1964 gchar *min_version = NULL;
1965 guint minver_maj = GST_VERSION_MAJOR;
1966 guint minver_min = GST_VERSION_MINOR;
1967 guint minver_micro = 0;
1968 gchar *types = NULL;
1969 const gchar *no_colors;
1971 #ifndef GST_DISABLE_OPTION_PARSING
1972 GOptionEntry options[] = {
1973 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1974 N_("Print all elements"), NULL},
1975 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1976 N_("Print list of blacklisted files"), NULL},
1977 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1978 N_("Print a machine-parsable list of features the specified plugin "
1979 "or all plugins provide.\n "
1980 "Useful in connection with external automatic plugin "
1981 "installation mechanisms"), NULL},
1982 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1983 N_("List the plugin contents"), NULL},
1984 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1985 N_("A slashes ('/') separated list of types of elements (also known "
1986 "as klass) to list. (unordered)"), NULL},
1987 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1988 N_("Check if the specified element or plugin exists"), NULL},
1989 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1991 ("When checking if an element or plugin exists, also check that its "
1992 "version is at least the version specified"), NULL},
1993 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1995 ("Print supported URI schemes, with the elements that implement them"),
1997 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
2000 ("Disable colors in output. You can also achieve the same by setting"
2001 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
2003 {"color", 'C', 0, G_OPTION_ARG_NONE, &color_always,
2004 N_("Color output, even when not sending to a tty."),
2006 GST_TOOLS_GOPTION_VERSION,
2009 GOptionContext *ctx;
2013 setlocale (LC_ALL, "");
2016 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
2017 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2018 textdomain (GETTEXT_PACKAGE);
2021 /* avoid glib warnings when inspecting deprecated properties */
2022 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
2024 g_set_prgname ("gst-inspect-" GST_API_VERSION);
2026 #ifndef GST_DISABLE_OPTION_PARSING
2027 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2028 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2029 g_option_context_add_group (ctx, gst_init_get_option_group ());
2030 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2031 g_printerr ("Error initializing: %s\n", err->message);
2032 g_clear_error (&err);
2033 g_option_context_free (ctx);
2036 g_option_context_free (ctx);
2038 gst_init (&argc, &argv);
2041 gst_tools_print_version ();
2043 if (print_all && argc > 1) {
2044 g_printerr ("-a requires no extra arguments\n");
2048 if (uri_handlers && argc > 1) {
2049 g_printerr ("-u requires no extra arguments\n");
2053 /* --atleast-version implies --exists */
2054 if (min_version != NULL) {
2055 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2056 &minver_micro) < 2) {
2057 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2059 g_free (min_version);
2062 g_free (min_version);
2063 check_exists = TRUE;
2068 g_printerr ("--exists requires an extra command line argument\n");
2072 GstPluginFeature *feature;
2074 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2075 if (feature != NULL && gst_plugin_feature_check_version (feature,
2076 minver_maj, minver_min, minver_micro)) {
2083 gst_object_unref (feature);
2085 /* FIXME: support checking for plugins too */
2086 g_printerr ("Checking for plugins is not supported yet\n");
2093 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2094 /* We only support truecolor */
2095 colored_output &= (no_colors == NULL);
2098 if (isatty (STDOUT_FILENO)) {
2099 if (redirect_stdout ())
2100 loop = g_main_loop_new (NULL, FALSE);
2102 colored_output = (color_always) ? TRUE : FALSE;
2104 #elif defined(G_OS_WIN32)
2106 /* g_log_writer_supports_color is available since 2.50.0 */
2107 #if GLIB_CHECK_VERSION(2,50,0)
2108 gint fd = _fileno (stdout);
2109 /* On Windows 10, g_log_writer_supports_color will also setup the console
2110 * so that it correctly interprets ANSI VT sequences if it's supported */
2111 if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2112 colored_output = FALSE;
2114 colored_output = FALSE;
2119 /* if no arguments, print out list of elements */
2121 print_all_uri_handlers ();
2122 } else if (argc == 1 || print_all) {
2123 if (do_print_blacklist)
2127 print_all_plugin_automatic_install_info ();
2129 print_element_list (print_all, types);
2132 /* else we try to get a factory */
2133 const char *arg = argv[argc - 1];
2137 retval = print_feature_info (arg, print_all);
2140 /* otherwise check if it's a plugin */
2142 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2144 /* if there is such a plugin, print out info */
2147 print_plugin_automatic_install_info (plugin);
2149 print_plugin_info (plugin);
2150 print_plugin_features (plugin);
2153 GError *error = NULL;
2155 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2156 plugin = gst_plugin_load_file (arg, &error);
2160 print_plugin_automatic_install_info (plugin);
2162 print_plugin_info (plugin);
2163 print_plugin_features (plugin);
2166 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2167 g_clear_error (&error);
2172 g_printerr (_("No such element or plugin '%s'\n"), arg);
2186 /* So that the pipe we create in redirect_stdout() is closed */
2187 close (STDOUT_FILENO);
2188 close (STDERR_FILENO);
2189 g_child_watch_add (child_pid, child_exit_cb, NULL);
2190 g_main_loop_run (loop);
2191 g_main_loop_unref (loop);