2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2004 Thomas Vander Stichele <thomas@apestaart.org>
7 * gst-inspect.c: tool to inspect the GStreamer registry
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
29 /* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
30 * with newer GLib versions (>= 2.31.0) */
31 #define GLIB_DISABLE_DEPRECATION_WARNINGS
34 #include <gst/gst_private.h> /* for internal Factories */
38 #include <glib/gprintf.h>
41 # include <sys/wait.h>
44 #define DEFAULT_PAGER "less -F -X -R"
46 gboolean colored_output = TRUE;
50 /* Escape values for colors */
51 #define BLUE "\033[34m"
52 #define BRBLUE "\033[94m"
53 #define BRCYAN "\033[96m"
54 #define BRMAGENTA "\033[95m"
55 #define BRYELLOW "\033[33m"
56 #define CYAN "\033[36m"
57 #define GREEN "\033[32m"
58 #define MAGENTA "\033[35m"
59 #define YELLOW "\033[33m"
62 #define RESET_COLOR (colored_output? "\033[0m": "")
63 #define HEADING_COLOR (colored_output? BRYELLOW : "")
64 #define PROP_NAME_COLOR (colored_output? BRBLUE : "")
65 #define PROP_VALUE_COLOR (colored_output? RESET_COLOR: "")
66 #define PROP_ATTR_NAME_COLOR (colored_output? BRYELLOW : "")
67 #define PROP_ATTR_VALUE_COLOR (colored_output? CYAN: "")
68 /* FIXME: find a good color that works on both dark & light bg. */
69 #define DESC_COLOR (colored_output? RESET_COLOR: "")
71 /* Datatype-related colors */
72 #define DATATYPE_COLOR (colored_output? GREEN : "")
73 #define CHILD_LINK_COLOR (colored_output? BRMAGENTA : "")
76 #define FIELD_NAME_COLOR (colored_output? CYAN: "")
77 #define FIELD_VALUE_COLOR (colored_output? BRBLUE : "")
78 #define CAPS_TYPE_COLOR (colored_output? YELLOW : "")
79 #define STRUCT_NAME_COLOR (colored_output? YELLOW : "")
80 #define CAPS_FEATURE_COLOR (colored_output? GREEN : "")
82 /* Plugin listing colors */
83 #define PLUGIN_NAME_COLOR (colored_output? BRBLUE : "")
84 #define ELEMENT_NAME_COLOR (colored_output? GREEN : "")
85 /* FIXME: find a good color that works on both dark & light bg. */
86 #define ELEMENT_DETAIL_COLOR (colored_output? RESET_COLOR : "")
87 #define PLUGIN_FEATURE_COLOR (colored_output? BRBLUE: "")
89 /* Feature listing colors */
90 #define FEATURE_NAME_COLOR (colored_output? GREEN : "")
91 #define FEATURE_DIR_COLOR (colored_output? BRMAGENTA : "")
92 #define FEATURE_RANK_COLOR (colored_output? CYAN : "")
93 #define FEATURE_PROTO_COLOR (colored_output? BRYELLOW : "")
95 static char *_name = NULL;
96 static int indent = 0;
98 static int print_element_info (GstPluginFeature * feature,
99 gboolean print_names);
100 static int print_typefind_info (GstPluginFeature * feature,
101 gboolean print_names);
102 static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
104 #define push_indent() push_indent_n(1)
105 #define pop_indent() push_indent_n(-1)
106 #define pop_indent_n(n) push_indent_n(-n)
109 push_indent_n (int n)
111 g_assert (n > 0 || indent > 0);
120 n_print (const char *format, ...)
126 g_print ("%s", _name);
128 for (i = 0; i < indent; ++i)
131 va_start (args, format);
132 g_vprintf (format, args);
137 print_field (GQuark field, const GValue * value, gpointer pfx)
139 gchar *str = gst_value_serialize (value);
141 n_print ("%s %s%15s%s: %s%s%s\n",
142 (gchar *) pfx, FIELD_NAME_COLOR, g_quark_to_string (field), RESET_COLOR,
143 FIELD_VALUE_COLOR, str, RESET_COLOR);
149 print_caps (const GstCaps * caps, const gchar * pfx)
153 g_return_if_fail (caps != NULL);
155 if (gst_caps_is_any (caps)) {
156 n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
159 if (gst_caps_is_empty (caps)) {
160 n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
164 for (i = 0; i < gst_caps_get_size (caps); i++) {
165 GstStructure *structure = gst_caps_get_structure (caps, i);
166 GstCapsFeatures *features = gst_caps_get_features (caps, i);
168 if (features && (gst_caps_features_is_any (features) ||
169 !gst_caps_features_is_equal (features,
170 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
171 gchar *features_string = gst_caps_features_to_string (features);
173 n_print ("%s%s%s%s(%s%s%s)\n", pfx, STRUCT_NAME_COLOR,
174 gst_structure_get_name (structure), RESET_COLOR,
175 CAPS_FEATURE_COLOR, features_string, RESET_COLOR);
176 g_free (features_string);
178 n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
179 gst_structure_get_name (structure), RESET_COLOR);
181 gst_structure_foreach (structure, print_field, (gpointer) pfx);
186 get_rank_name (char *s, gint rank)
188 static const int ranks[4] = {
189 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
191 static const char *rank_names[4] = { "none", "marginal", "secondary",
198 for (i = 0; i < 4; i++) {
199 if (rank == ranks[i])
200 return rank_names[i];
201 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
206 sprintf (s, "%s %c %d", rank_names[best_i],
207 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
213 print_factory_details_info (GstElementFactory * factory)
219 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
220 n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
223 n_print ("%s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
224 get_rank_name (s, rank), rank, RESET_COLOR);
226 keys = gst_element_factory_get_metadata_keys (factory);
228 for (k = keys; *k != NULL; ++k) {
232 val = gst_element_factory_get_metadata (factory, key);
233 key[0] = g_ascii_toupper (key[0]);
234 n_print ("%s%-25s%s%s%s\n", PROP_NAME_COLOR, key, PROP_VALUE_COLOR, val,
244 print_hierarchy (GType type, gint level, gint * maxlevel)
249 parent = g_type_parent (type);
251 *maxlevel = *maxlevel + 1;
255 print_hierarchy (parent, level, maxlevel);
258 g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
260 for (i = 1; i < *maxlevel - level; i++)
262 if (*maxlevel - level)
263 g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
265 g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
272 print_interfaces (GType type)
275 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
279 n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
283 n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
294 flags_to_string (GFlagsValue * vals, guint flags)
299 /* first look for an exact match and count the number of values */
300 for (i = 0; vals[i].value_name != NULL; ++i) {
301 if (vals[i].value == flags)
302 return g_strdup (vals[i].value_nick);
305 s = g_string_new (NULL);
307 /* we assume the values are sorted from lowest to highest value */
311 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
313 g_string_append_c (s, '+');
314 g_string_append (s, vals[i].value_nick);
315 flags_left -= vals[i].value;
322 g_string_assign (s, "(none)");
324 return g_string_free (s, FALSE);
327 #define KNOWN_PARAM_FLAGS \
328 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
329 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
330 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
331 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
332 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY)
335 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
337 return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
340 /* obj will be NULL if we're printing properties of pad template pads */
342 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
345 GParamSpec **property_specs;
346 guint num_properties, i;
350 property_specs = g_object_class_list_properties (obj_class, &num_properties);
351 g_qsort_with_data (property_specs, num_properties, sizeof (gpointer),
352 (GCompareDataFunc) sort_gparamspecs, NULL);
354 n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
358 for (i = 0; i < num_properties; i++) {
359 GValue value = { 0, };
360 GParamSpec *param = property_specs[i];
361 GType owner_type = param->owner_type;
363 /* We're printing pad properties */
364 if (obj == NULL && (owner_type == G_TYPE_OBJECT
365 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
370 g_value_init (&value, param->value_type);
372 n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
373 g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
374 g_param_spec_get_blurb (param), RESET_COLOR);
379 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
380 readable = ! !(param->flags & G_PARAM_READABLE);
381 if (readable && obj != NULL) {
382 g_object_get_property (obj, param->name, &value);
384 /* if we can't read the property value, assume it's set to the default
385 * (which might not be entirely true for sub-classes, but that's an
386 * unlikely corner-case anyway) */
387 g_param_value_set_default (param, &value);
390 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
391 _("readable"), RESET_COLOR);
394 if (param->flags & G_PARAM_WRITABLE) {
395 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
396 _("writable"), RESET_COLOR);
399 if (param->flags & G_PARAM_DEPRECATED) {
400 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
401 _("deprecated"), RESET_COLOR);
404 if (param->flags & GST_PARAM_CONTROLLABLE) {
405 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
409 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
410 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
411 _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
412 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
413 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
414 _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
415 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
416 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
417 _("changeable only in NULL or READY state"), RESET_COLOR);
419 if (param->flags & ~KNOWN_PARAM_FLAGS) {
420 g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
421 param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
425 switch (G_VALUE_TYPE (&value)) {
428 const char *string_val = g_value_get_string (&value);
430 n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
432 if (string_val == NULL)
433 g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
434 PROP_ATTR_VALUE_COLOR, RESET_COLOR);
436 g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
437 PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
442 gboolean bool_val = g_value_get_boolean (&value);
444 n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
445 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
446 PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
451 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
454 ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
455 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
456 PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
457 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
458 PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
460 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
461 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
462 g_param_spec_get_name (param));
467 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
469 n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
470 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
471 PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
472 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
473 g_value_get_long (&value), RESET_COLOR);
475 GST_ERROR ("%s: property '%s' of type long: consider changing to "
476 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
477 g_param_spec_get_name (param));
482 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
485 ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
486 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
487 PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
488 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
489 g_value_get_uint (&value), RESET_COLOR);
494 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
496 n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
497 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
498 PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
499 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
500 g_value_get_int (&value), RESET_COLOR);
505 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
507 n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
508 "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
509 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
510 PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
511 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
512 PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
517 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
519 n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
520 G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
521 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
522 PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
523 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
524 PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
529 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
531 n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
532 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
533 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
534 pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
535 RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
541 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
543 n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
544 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
545 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
546 pdouble->minimum, pdouble->maximum, RESET_COLOR,
547 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
548 g_value_get_double (&value), RESET_COLOR);
553 GST_ERROR ("%s: property '%s' of type char: consider changing to "
554 "int/string", G_OBJECT_CLASS_NAME (obj_class),
555 g_param_spec_get_name (param));
558 if (param->value_type == GST_TYPE_CAPS) {
559 const GstCaps *caps = gst_value_get_caps (&value);
562 n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
564 print_caps (caps, " ");
566 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
570 const gchar *value_nick = "";
572 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
573 enum_value = g_value_get_enum (&value);
575 while (values[j].value_name) {
576 if (values[j].value == enum_value)
577 value_nick = values[j].value_nick;
581 n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
582 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
583 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
584 enum_value, value_nick, RESET_COLOR);
587 while (values[j].value_name) {
589 n_print (" %s(%d)%s: %s%-16s%s - %s%s%s",
590 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
591 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
592 DESC_COLOR, values[j].value_name, RESET_COLOR);
595 /* g_type_class_unref (ec); */
596 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
597 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
601 vals = pflags->flags_class->values;
603 cur = flags_to_string (vals, g_value_get_flags (&value));
605 n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
606 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
607 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
608 g_value_get_flags (&value), cur, RESET_COLOR);
610 while (vals[0].value_name) {
612 n_print (" %s(0x%08x)%s: %s%-16s%s - %s%s%s",
613 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
614 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
615 DESC_COLOR, vals[0].value_name, RESET_COLOR);
620 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
621 n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
622 RESET_COLOR, DATATYPE_COLOR,
623 g_type_name (param->value_type), RESET_COLOR);
624 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
625 n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
626 RESET_COLOR, DATATYPE_COLOR,
627 g_type_name (param->value_type), RESET_COLOR);
628 if (param->value_type == GST_TYPE_STRUCTURE) {
629 const GstStructure *s = gst_value_get_structure (&value);
631 gst_structure_foreach (s, print_field,
634 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
635 if (param->value_type != G_TYPE_POINTER) {
636 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
637 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
640 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
642 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
643 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
645 if (pvarray->element_spec) {
646 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
647 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
648 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
650 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
652 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
653 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
655 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
656 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
657 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
658 pfraction->min_num, pfraction->min_den, pfraction->max_num,
659 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
660 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
661 gst_value_get_fraction_numerator (&value),
662 gst_value_get_fraction_denominator (&value), RESET_COLOR);
663 } else if (param->value_type == GST_TYPE_ARRAY) {
664 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
666 if (parray->element_spec) {
667 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
668 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
669 g_type_name (parray->element_spec->value_type), RESET_COLOR);
671 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
675 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
676 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
677 g_type_name (param->value_type), RESET_COLOR);
682 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
688 g_value_reset (&value);
690 if (num_properties == 0)
691 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
695 g_free (property_specs);
699 print_element_properties_info (GstElement * element)
702 print_object_properties_info (G_OBJECT (element),
703 G_OBJECT_GET_CLASS (element), "Element Properties");
707 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
710 GstStaticPadTemplate *padtemplate;
711 GstPadTemplate *tmpl;
713 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
717 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
718 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
722 pads = gst_element_factory_get_static_pad_templates (factory);
724 padtemplate = (GstStaticPadTemplate *) (pads->data);
725 pads = g_list_next (pads);
727 if (padtemplate->direction == GST_PAD_SRC)
728 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
729 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
730 else if (padtemplate->direction == GST_PAD_SINK)
731 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
732 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
734 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
735 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
739 if (padtemplate->presence == GST_PAD_ALWAYS)
740 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
741 PROP_VALUE_COLOR, RESET_COLOR);
742 else if (padtemplate->presence == GST_PAD_SOMETIMES)
743 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
744 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
745 else if (padtemplate->presence == GST_PAD_REQUEST) {
746 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
747 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
749 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
750 PROP_VALUE_COLOR, RESET_COLOR);
752 if (padtemplate->static_caps.string) {
753 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
755 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
758 print_caps (caps, ""); // FIXME
761 gst_caps_unref (caps);
764 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
765 padtemplate->name_template);
767 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
769 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
772 pad_klass = g_type_class_ref (pad_type);
773 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
774 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
775 print_object_properties_info (NULL, pad_klass, "Pad Properties");
776 g_type_class_unref (pad_klass);
791 print_clocking_info (GstElement * element)
793 gboolean requires_clock, provides_clock;
796 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
798 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
800 if (!requires_clock && !provides_clock) {
802 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
808 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
812 if (requires_clock) {
813 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
816 if (provides_clock) {
819 clock = gst_element_get_clock (element);
821 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
822 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
823 gst_object_unref (clock);
825 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
826 PROP_VALUE_COLOR, RESET_COLOR);
833 print_uri_handler_info (GstElement * element)
835 if (GST_IS_URI_HANDLER (element)) {
836 const gchar *const *uri_protocols;
837 const gchar *uri_type;
839 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
841 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
845 uri_type = "unknown";
847 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
850 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
854 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
856 if (uri_protocols && *uri_protocols) {
857 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
859 for (; *uri_protocols != NULL; uri_protocols++)
860 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
864 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
870 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
876 print_pad_info (GstElement * element)
882 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
886 if (!element->numpads) {
887 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
891 pads = element->pads;
896 pad = GST_PAD (pads->data);
897 pads = g_list_next (pads);
899 name = gst_pad_get_name (pad);
900 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
901 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
902 PROP_VALUE_COLOR, name, RESET_COLOR);
903 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
904 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
905 PROP_VALUE_COLOR, name, RESET_COLOR);
907 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
908 PROP_VALUE_COLOR, name, RESET_COLOR);
912 if (pad->padtemplate) {
914 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
915 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
919 caps = gst_pad_get_current_caps (pad);
921 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
923 print_caps (caps, ""); // FIXME
925 gst_caps_unref (caps);
934 has_sometimes_template (GstElement * element)
936 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
939 for (l = klass->padtemplates; l != NULL; l = l->next) {
940 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
948 gtype_needs_ptr_marker (GType type)
950 if (type == G_TYPE_POINTER)
953 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
954 || G_TYPE_IS_OBJECT (type))
961 print_signal_info (GstElement * element)
963 /* Signals/Actions Block */
967 GSignalQuery *query = NULL;
969 GSList *found_signals, *l;
971 for (k = 0; k < 2; k++) {
972 found_signals = NULL;
974 /* For elements that have sometimes pads, also list a few useful GstElement
975 * signals. Put these first, so element-specific ones come later. */
976 if (k == 0 && has_sometimes_template (element)) {
977 query = g_new0 (GSignalQuery, 1);
978 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
979 found_signals = g_slist_append (found_signals, query);
980 query = g_new0 (GSignalQuery, 1);
981 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
982 found_signals = g_slist_append (found_signals, query);
983 query = g_new0 (GSignalQuery, 1);
984 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
986 found_signals = g_slist_append (found_signals, query);
989 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
990 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
993 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
996 signals = g_signal_list_ids (type, &nsignals);
997 for (i = 0; i < nsignals; i++) {
998 query = g_new0 (GSignalQuery, 1);
999 g_signal_query (signals[i], query);
1001 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1002 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1003 found_signals = g_slist_append (found_signals, query);
1011 if (found_signals) {
1014 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1016 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1021 for (l = found_signals; l; l = l->next) {
1026 query = (GSignalQuery *) l->data;
1027 indent_len = strlen (query->signal_name) +
1028 strlen (g_type_name (query->return_type)) + 24;
1030 if (gtype_needs_ptr_marker (query->return_type)) {
1037 indent = g_new0 (gchar, indent_len + 1);
1038 memset (indent, ' ', indent_len);
1040 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1041 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1042 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1043 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1044 PROP_VALUE_COLOR, RESET_COLOR);
1046 for (j = 0; j < query->n_params; j++) {
1047 const gchar *type_name, *asterisk;
1049 type_name = g_type_name (query->param_types[j]);
1050 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1053 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1054 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1059 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1060 PROP_VALUE_COLOR, RESET_COLOR);
1067 if (found_signals) {
1068 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1069 g_slist_free (found_signals);
1075 print_children_info (GstElement * element)
1079 if (!GST_IS_BIN (element))
1082 children = (GList *) GST_BIN (element)->children;
1085 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1089 n_print (" %s%s%s\n", DATATYPE_COLOR,
1090 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1091 children = g_list_next (children);
1096 print_preset_list (GstElement * element)
1098 gchar **presets, **preset;
1100 if (!GST_IS_PRESET (element))
1103 presets = gst_preset_get_preset_names (GST_PRESET (element));
1104 if (presets && *presets) {
1106 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1107 for (preset = presets; *preset; preset++) {
1108 n_print (" \"%s\"\n", *preset);
1110 g_strfreev (presets);
1115 print_blacklist (void)
1117 GList *plugins, *cur;
1120 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1122 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1123 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1124 GstPlugin *plugin = (GstPlugin *) (cur->data);
1125 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1126 g_print (" %s\n", gst_plugin_get_name (plugin));
1132 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1134 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1136 g_print ("%s\n", RESET_COLOR);
1137 gst_plugin_list_free (plugins);
1141 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1145 while (extensions[i]) {
1146 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1152 print_element_list (gboolean print_all, gchar * ftypes)
1154 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1155 GList *plugins, *orig_plugins;
1156 gchar **types = NULL;
1161 types = g_strsplit (ftypes, "/", -1);
1162 for (i = 0; types[i]; i++)
1163 *types[i] = g_ascii_toupper (*types[i]);
1167 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1169 GList *features, *orig_features;
1172 plugin = (GstPlugin *) (plugins->data);
1173 plugins = g_list_next (plugins);
1176 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1181 orig_features = features =
1182 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1183 gst_plugin_get_name (plugin));
1185 GstPluginFeature *feature;
1187 if (G_UNLIKELY (features->data == NULL))
1189 feature = GST_PLUGIN_FEATURE (features->data);
1192 if (GST_IS_ELEMENT_FACTORY (feature)) {
1194 GstElementFactory *factory;
1196 factory = GST_ELEMENT_FACTORY (feature);
1199 gboolean all_found = TRUE;
1202 gst_element_factory_get_metadata (factory,
1203 GST_ELEMENT_METADATA_KLASS);
1204 for (i = 0; types[i]; i++) {
1205 if (!strstr (klass, types[i])) {
1215 print_element_info (feature, TRUE);
1217 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1218 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1219 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1220 gst_element_factory_get_metadata (factory,
1221 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1222 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1223 GstTypeFindFactory *factory;
1224 const gchar *const *extensions;
1228 factory = GST_TYPE_FIND_FACTORY (feature);
1230 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1231 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1232 gst_plugin_feature_get_name (feature), RESET_COLOR);
1234 extensions = gst_type_find_factory_get_extensions (factory);
1235 if (extensions != NULL) {
1237 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1242 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1248 n_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 (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1251 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1255 features = g_list_next (features);
1258 gst_plugin_feature_list_free (orig_features);
1261 gst_plugin_list_free (orig_plugins);
1265 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1267 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1268 if (blacklistcount) {
1270 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1271 blacklistcount), blacklistcount);
1272 g_print (" not shown)");
1274 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1275 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1276 g_print ("%s\n", RESET_COLOR);
1280 print_all_uri_handlers (void)
1282 GList *plugins, *p, *features, *f;
1284 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1286 for (p = plugins; p; p = p->next) {
1287 GstPlugin *plugin = (GstPlugin *) (p->data);
1290 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1291 gst_plugin_get_name (plugin));
1293 for (f = features; f; f = f->next) {
1294 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1296 if (GST_IS_ELEMENT_FACTORY (feature)) {
1297 GstElementFactory *factory;
1298 GstElement *element;
1300 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1302 g_print ("element plugin %s couldn't be loaded\n",
1303 gst_plugin_get_name (plugin));
1307 element = gst_element_factory_create (factory, NULL);
1309 g_print ("couldn't construct element for %s for some reason\n",
1310 GST_OBJECT_NAME (factory));
1311 gst_object_unref (factory);
1315 if (GST_IS_URI_HANDLER (element)) {
1316 const gchar *const *uri_protocols;
1317 const gchar *const *protocol;
1320 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1332 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1334 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1335 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1337 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1341 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1342 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1343 if (protocol != uri_protocols)
1345 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1350 gst_object_unref (element);
1351 gst_object_unref (factory);
1355 gst_plugin_feature_list_free (features);
1358 gst_plugin_list_free (plugins);
1362 print_plugin_info (GstPlugin * plugin)
1364 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1365 const gchar *filename = gst_plugin_get_filename (plugin);
1367 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1371 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1372 PROP_VALUE_COLOR, gst_plugin_get_name (plugin), RESET_COLOR);
1373 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1374 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1375 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1376 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1377 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1378 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1379 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1380 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1381 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1382 PROP_VALUE_COLOR, gst_plugin_get_source (plugin), RESET_COLOR);
1384 if (release_date != NULL) {
1385 const gchar *tz = "(UTC)";
1388 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1389 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1390 str = g_strdup (release_date);
1391 sep = strstr (str, "T");
1394 sep = strstr (sep + 1, "Z");
1400 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1401 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1404 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1405 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1406 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1407 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1415 print_plugin_features (GstPlugin * plugin)
1417 GList *features, *origlist;
1418 gint num_features = 0;
1419 gint num_elements = 0;
1420 gint num_tracers = 0;
1421 gint num_typefinders = 0;
1422 gint num_devproviders = 0;
1425 origlist = features =
1426 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1427 gst_plugin_get_name (plugin));
1430 GstPluginFeature *feature;
1432 feature = GST_PLUGIN_FEATURE (features->data);
1434 if (GST_IS_ELEMENT_FACTORY (feature)) {
1435 GstElementFactory *factory;
1437 factory = GST_ELEMENT_FACTORY (feature);
1438 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1439 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1440 gst_element_factory_get_metadata (factory,
1441 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1443 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1444 GstTypeFindFactory *factory;
1445 const gchar *const *extensions;
1447 factory = GST_TYPE_FIND_FACTORY (feature);
1448 extensions = gst_type_find_factory_get_extensions (factory);
1450 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1451 gst_plugin_feature_get_name (feature), RESET_COLOR);
1452 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1455 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1456 gst_plugin_feature_get_name (feature), RESET_COLOR,
1457 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1460 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1461 GstDeviceProviderFactory *factory;
1463 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1464 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1465 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1466 gst_device_provider_factory_get_metadata (factory,
1467 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1469 } else if (GST_IS_TRACER_FACTORY (feature)) {
1470 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1471 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1472 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1474 } else if (feature) {
1475 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1476 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1477 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1481 features = g_list_next (features);
1484 gst_plugin_feature_list_free (origlist);
1487 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1488 if (num_elements > 0)
1489 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1490 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1491 if (num_typefinders > 0)
1492 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1493 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1494 if (num_devproviders > 0)
1495 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1496 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1497 if (num_tracers > 0)
1498 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1499 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1501 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1502 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1508 print_feature_info (const gchar * feature_name, gboolean print_all)
1510 GstPluginFeature *feature;
1511 GstRegistry *registry = gst_registry_get ();
1514 if ((feature = gst_registry_find_feature (registry, feature_name,
1515 GST_TYPE_ELEMENT_FACTORY))) {
1516 ret = print_element_info (feature, print_all);
1519 if ((feature = gst_registry_find_feature (registry, feature_name,
1520 GST_TYPE_TYPE_FIND_FACTORY))) {
1521 ret = print_typefind_info (feature, print_all);
1524 if ((feature = gst_registry_find_feature (registry, feature_name,
1525 GST_TYPE_TRACER_FACTORY))) {
1526 ret = print_tracer_info (feature, print_all);
1530 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1535 gst_object_unref (feature);
1540 print_element_info (GstPluginFeature * feature, gboolean print_names)
1542 GstElementFactory *factory;
1543 GstElement *element;
1547 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1549 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1554 element = gst_element_factory_create (factory, NULL);
1556 gst_object_unref (factory);
1557 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1564 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1569 print_factory_details_info (factory);
1571 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1573 print_plugin_info (plugin);
1574 gst_object_unref (plugin);
1577 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1578 print_interfaces (G_OBJECT_TYPE (element));
1580 print_pad_templates_info (element, factory);
1581 print_clocking_info (element);
1582 print_uri_handler_info (element);
1583 print_pad_info (element);
1584 print_element_properties_info (element);
1585 print_signal_info (element);
1586 print_children_info (element);
1587 print_preset_list (element);
1589 gst_object_unref (element);
1590 gst_object_unref (factory);
1596 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1598 GstTypeFindFactory *factory;
1603 const gchar *const *extensions;
1605 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1607 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1614 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1619 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1620 rank = gst_plugin_feature_get_rank (feature);
1621 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1622 get_rank_name (s, rank), rank, RESET_COLOR);
1623 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1624 GST_OBJECT_NAME (factory), RESET_COLOR);
1625 caps = gst_type_find_factory_get_caps (factory);
1627 gchar *caps_str = gst_caps_to_string (factory->caps);
1629 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1630 caps_str, RESET_COLOR);
1633 extensions = gst_type_find_factory_get_extensions (factory);
1635 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1636 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1641 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1643 print_plugin_info (plugin);
1644 gst_object_unref (plugin);
1647 gst_object_unref (factory);
1653 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1655 GstTracerFactory *factory;
1660 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1662 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1666 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1668 gst_object_unref (factory);
1669 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1676 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1681 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1682 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1683 GST_OBJECT_NAME (factory), RESET_COLOR);
1686 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1688 print_plugin_info (plugin);
1689 gst_object_unref (plugin);
1692 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1693 print_interfaces (G_OBJECT_TYPE (tracer));
1695 /* TODO: list what hooks it registers
1696 * - the data is available in gsttracerutils, we need to iterate the
1697 * _priv_tracers hashtable for each probe and then check the list of hooks
1698 * for each probe whether hook->tracer == tracer :/
1701 /* TODO: list what records it emits
1702 * - in class_init tracers can create GstTracerRecord instances
1703 * - those only get logged right now and there is no association with the
1704 * tracer that created them
1705 * - we'd need to add them to GstTracerFactory
1706 * gst_tracer_class_add_record (klass, record);
1707 * - needs work in gstregistrychunks to (de)serialize specs
1708 * - gst_tracer_register() would need to iterate the list of records and
1709 * copy the record->spec into the factory
1712 gst_object_unref (tracer);
1713 gst_object_unref (factory);
1718 /* NOTE: Not coloring output from automatic install functions, as their output
1719 * is meant for machines, not humans.
1722 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1724 GstPadDirection direction;
1725 const gchar *type_name;
1727 const GList *static_templates, *l;
1728 GstCaps *caps = NULL;
1732 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1733 g_return_if_fail (klass != NULL);
1735 if (strstr (klass, "Demuxer") ||
1736 strstr (klass, "Decoder") ||
1737 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1738 type_name = "decoder";
1739 direction = GST_PAD_SINK;
1740 } else if (strstr (klass, "Muxer") ||
1741 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1742 type_name = "encoder";
1743 direction = GST_PAD_SRC;
1748 /* decoder/demuxer sink pads should always be static and there should only
1749 * be one, the same applies to encoders/muxers and source pads */
1750 static_templates = gst_element_factory_get_static_pad_templates (factory);
1751 for (l = static_templates; l != NULL; l = l->next) {
1752 GstStaticPadTemplate *tmpl = NULL;
1754 tmpl = (GstStaticPadTemplate *) l->data;
1755 if (tmpl->direction == direction) {
1756 caps = gst_static_pad_template_get_caps (tmpl);
1762 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1763 type_name, GST_OBJECT_NAME (factory));
1767 caps = gst_caps_make_writable (caps);
1768 num = gst_caps_get_size (caps);
1769 for (i = 0; i < num; ++i) {
1773 s = gst_caps_get_structure (caps, i);
1774 /* remove fields that are almost always just MIN-MAX of some sort
1775 * in order to make the caps look less messy */
1776 gst_structure_remove_field (s, "pixel-aspect-ratio");
1777 gst_structure_remove_field (s, "framerate");
1778 gst_structure_remove_field (s, "channels");
1779 gst_structure_remove_field (s, "width");
1780 gst_structure_remove_field (s, "height");
1781 gst_structure_remove_field (s, "rate");
1782 gst_structure_remove_field (s, "depth");
1783 gst_structure_remove_field (s, "clock-rate");
1784 s_str = gst_structure_to_string (s);
1785 g_print ("%s-%s\n", type_name, s_str);
1788 gst_caps_unref (caps);
1792 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1794 const gchar *const *protocols;
1796 protocols = gst_element_factory_get_uri_protocols (factory);
1797 if (protocols != NULL && *protocols != NULL) {
1798 switch (gst_element_factory_get_uri_type (factory)) {
1800 while (*protocols != NULL) {
1801 g_print ("urisink-%s\n", *protocols);
1806 while (*protocols != NULL) {
1807 g_print ("urisource-%s\n", *protocols);
1818 print_plugin_automatic_install_info (GstPlugin * plugin)
1820 GList *features, *l;
1822 /* not interested in typefind factories, only element factories */
1823 features = gst_registry_get_feature_list (gst_registry_get (),
1824 GST_TYPE_ELEMENT_FACTORY);
1826 for (l = features; l != NULL; l = l->next) {
1827 GstPluginFeature *feature;
1828 GstPlugin *feature_plugin;
1830 feature = GST_PLUGIN_FEATURE (l->data);
1832 /* only interested in the ones that are in the plugin we just loaded */
1833 feature_plugin = gst_plugin_feature_get_plugin (feature);
1834 if (feature_plugin == plugin) {
1835 GstElementFactory *factory;
1837 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1839 factory = GST_ELEMENT_FACTORY (feature);
1840 print_plugin_automatic_install_info_protocols (factory);
1841 print_plugin_automatic_install_info_codecs (factory);
1844 gst_object_unref (feature_plugin);
1847 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1848 g_list_free (features);
1852 print_all_plugin_automatic_install_info (void)
1854 GList *plugins, *orig_plugins;
1856 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1860 plugin = (GstPlugin *) (plugins->data);
1861 plugins = g_list_next (plugins);
1863 print_plugin_automatic_install_info (plugin);
1865 gst_plugin_list_free (orig_plugins);
1870 redirect_stdout (void)
1875 if (pipe (pipefd) == -1) {
1876 g_printerr (_("Error creating pipe: %s\n"), g_strerror (errno));
1881 if (child_id == -1) {
1882 g_printerr (_("Error forking: %s\n"), g_strerror (errno));
1886 if (child_id == 0) {
1891 pager = g_getenv ("PAGER");
1893 pager = DEFAULT_PAGER;
1894 argv = g_strsplit (pager, " ", 0);
1898 dup2 (pipefd[0], STDIN_FILENO);
1901 ret = execvp (argv[0], argv);
1904 /* No less? Let's just dump everything to stdout then */
1910 if ((ret = read (STDIN_FILENO, buffer, sizeof (buffer))) == -1) {
1911 if (errno == EINTR || errno == EAGAIN) {
1915 g_printerr (_("Error reading from console: %s\n"),
1916 g_strerror (errno));
1921 bytes_written = write (STDOUT_FILENO, buffer, ret);
1922 } while (bytes_written == -1 && (errno == EINTR || errno == EAGAIN));
1924 if (bytes_written < 0) {
1925 g_printerr (_("Error writing to console: %s\n"), g_strerror (errno));
1934 dup2 (pipefd[1], STDOUT_FILENO);
1935 if (isatty (STDERR_FILENO))
1936 dup2 (pipefd[1], STDERR_FILENO);
1938 close (STDIN_FILENO);
1944 main (int argc, char *argv[])
1946 gboolean print_all = FALSE;
1947 gboolean do_print_blacklist = FALSE;
1948 gboolean plugin_name = FALSE;
1949 gboolean print_aii = FALSE;
1950 gboolean uri_handlers = FALSE;
1951 gboolean check_exists = FALSE;
1952 gchar *min_version = NULL;
1953 guint minver_maj = GST_VERSION_MAJOR;
1954 guint minver_min = GST_VERSION_MINOR;
1955 guint minver_micro = 0;
1956 gchar *types = NULL;
1957 const gchar *no_colors;
1958 #ifndef GST_DISABLE_OPTION_PARSING
1959 GOptionEntry options[] = {
1960 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1961 N_("Print all elements"), NULL},
1962 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1963 N_("Print list of blacklisted files"), NULL},
1964 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1965 N_("Print a machine-parsable list of features the specified plugin "
1966 "or all plugins provide.\n "
1967 "Useful in connection with external automatic plugin "
1968 "installation mechanisms"), NULL},
1969 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1970 N_("List the plugin contents"), NULL},
1971 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
1972 N_("A slashes ('/') separated list of types of elements (also known "
1973 "as klass) to list. (unordered)"), NULL},
1974 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1975 N_("Check if the specified element or plugin exists"), NULL},
1976 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1978 ("When checking if an element or plugin exists, also check that its "
1979 "version is at least the version specified"), NULL},
1980 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1982 ("Print supported URI schemes, with the elements that implement them"),
1984 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1987 ("Disable colors in output. You can also achieve the same by setting"
1988 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
1990 GST_TOOLS_GOPTION_VERSION,
1993 GOptionContext *ctx;
1997 setlocale (LC_ALL, "");
2000 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
2001 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2002 textdomain (GETTEXT_PACKAGE);
2005 /* avoid glib warnings when inspecting deprecated properties */
2006 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
2008 g_set_prgname ("gst-inspect-" GST_API_VERSION);
2010 #ifndef GST_DISABLE_OPTION_PARSING
2011 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2012 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2013 g_option_context_add_group (ctx, gst_init_get_option_group ());
2014 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2015 g_printerr ("Error initializing: %s\n", err->message);
2016 g_clear_error (&err);
2017 g_option_context_free (ctx);
2020 g_option_context_free (ctx);
2022 gst_init (&argc, &argv);
2025 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2026 /* We only support truecolor */
2027 colored_output &= (no_colors == NULL);
2030 if (isatty (STDOUT_FILENO)) {
2035 gst_tools_print_version ();
2037 if (print_all && argc > 1) {
2038 g_printerr ("-a requires no extra arguments\n");
2042 if (uri_handlers && argc > 1) {
2043 g_printerr ("-u requires no extra arguments\n");
2047 /* --atleast-version implies --exists */
2048 if (min_version != NULL) {
2049 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2050 &minver_micro) < 2) {
2051 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2055 check_exists = TRUE;
2062 g_printerr ("--exists requires an extra command line argument\n");
2066 GstPluginFeature *feature;
2068 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2069 if (feature != NULL && gst_plugin_feature_check_version (feature,
2070 minver_maj, minver_min, minver_micro)) {
2077 gst_object_unref (feature);
2079 /* FIXME: support checking for plugins too */
2080 g_printerr ("Checking for plugins is not supported yet\n");
2087 /* if no arguments, print out list of elements */
2089 print_all_uri_handlers ();
2090 } else if (argc == 1 || print_all) {
2091 if (do_print_blacklist)
2095 print_all_plugin_automatic_install_info ();
2097 print_element_list (print_all, types);
2100 /* else we try to get a factory */
2101 const char *arg = argv[argc - 1];
2105 retval = print_feature_info (arg, print_all);
2108 /* otherwise check if it's a plugin */
2110 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2112 /* if there is such a plugin, print out info */
2115 print_plugin_automatic_install_info (plugin);
2117 print_plugin_info (plugin);
2118 print_plugin_features (plugin);
2121 GError *error = NULL;
2123 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2124 plugin = gst_plugin_load_file (arg, &error);
2128 print_plugin_automatic_install_info (plugin);
2130 print_plugin_info (plugin);
2131 print_plugin_features (plugin);
2134 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2135 g_clear_error (&error);
2139 g_printerr (_("No such element or plugin '%s'\n"), arg);
2149 /* So that the pipe we create in redirect_stdout() is closed */
2150 close (STDOUT_FILENO);
2151 close (STDERR_FILENO);