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>
50 #include <TargetConditionals.h>
53 /* "R" : support color
54 * "X" : do not clear the screen when leaving the pager
55 * "F" : skip the pager if content fit into the screen
57 * Don't forget to update the manpage gst-inspect-1.0.1
58 * after changing this default.
60 #define DEFAULT_LESS_OPTS "RXF"
62 gboolean colored_output = TRUE;
67 SORT_TYPE_NAME, /* default */
70 SortType sort_output = SORT_TYPE_NAME;
73 static const gchar DEFAULT_PAGER[] = "less";
76 GMainLoop *loop = NULL;
80 /* Escape values for colors */
81 #define BLUE "\033[34m"
82 #define BRBLUE "\033[94m"
83 #define BRCYAN "\033[96m"
84 #define BRMAGENTA "\033[95m"
85 #define BRYELLOW "\033[33m"
86 #define CYAN "\033[36m"
87 #define GREEN "\033[32m"
88 #define MAGENTA "\033[35m"
89 #define YELLOW "\033[33m"
92 #define RESET_COLOR (colored_output? "\033[0m": "")
93 #define HEADING_COLOR (colored_output? BRYELLOW : "")
94 #define PROP_NAME_COLOR (colored_output? BRBLUE : "")
95 #define PROP_VALUE_COLOR (colored_output? RESET_COLOR: "")
96 #define PROP_ATTR_NAME_COLOR (colored_output? BRYELLOW : "")
97 #define PROP_ATTR_VALUE_COLOR (colored_output? CYAN: "")
98 /* FIXME: find a good color that works on both dark & light bg. */
99 #define DESC_COLOR (colored_output? RESET_COLOR: "")
101 /* Datatype-related colors */
102 #define DATATYPE_COLOR (colored_output? GREEN : "")
103 #define CHILD_LINK_COLOR (colored_output? BRMAGENTA : "")
106 #define FIELD_NAME_COLOR (colored_output? CYAN: "")
107 #define FIELD_VALUE_COLOR (colored_output? BRBLUE : "")
108 #define CAPS_TYPE_COLOR (colored_output? YELLOW : "")
109 #define STRUCT_NAME_COLOR (colored_output? YELLOW : "")
110 #define CAPS_FEATURE_COLOR (colored_output? GREEN : "")
112 /* Plugin listing colors */
113 #define PLUGIN_NAME_COLOR (colored_output? BRBLUE : "")
114 #define ELEMENT_NAME_COLOR (colored_output? GREEN : "")
115 /* FIXME: find a good color that works on both dark & light bg. */
116 #define ELEMENT_DETAIL_COLOR (colored_output? RESET_COLOR : "")
117 #define PLUGIN_FEATURE_COLOR (colored_output? BRBLUE: "")
119 /* Feature listing colors */
120 #define FEATURE_NAME_COLOR (colored_output? GREEN : "")
121 #define FEATURE_DIR_COLOR (colored_output? BRMAGENTA : "")
122 #define FEATURE_RANK_COLOR (colored_output? CYAN : "")
123 #define FEATURE_PROTO_COLOR (colored_output? BRYELLOW : "")
125 #define GST_DOC_BASE_URL "https://gstreamer.freedesktop.org/documentation"
127 static const gchar *gstreamer_modules[] = {
128 "gstreamer", "gst-plugins-base", "gst-plugins-good", "gst-plugins-ugly",
129 "gst-plugins-bad", "gst-editing-services", "gst-libav", "gst-rtsp-server",
130 "gstreamer-vaapi", NULL
133 static char *_name = NULL;
134 static int indent = 0;
136 static int print_element_info (GstPluginFeature * feature,
137 gboolean print_names);
138 static int print_typefind_info (GstPluginFeature * feature,
139 gboolean print_names);
140 static int print_tracer_info (GstPluginFeature * feature, gboolean print_names);
142 #define push_indent() push_indent_n(1)
143 #define pop_indent() push_indent_n(-1)
144 #define pop_indent_n(n) push_indent_n(-n)
147 push_indent_n (int n)
149 g_assert (n > 0 || indent > 0);
158 n_print (const char *format, ...)
165 g_print ("%s", _name);
167 for (i = 0; i < indent; ++i)
170 va_start (args, format);
171 str = gst_info_strdup_vprintf (format, args);
182 print_field (GQuark field, const GValue * value, gpointer pfx)
184 gchar *str = gst_value_serialize (value);
186 n_print ("%s %s%15s%s: %s%s%s\n",
187 (gchar *) pfx, FIELD_NAME_COLOR, g_quark_to_string (field), RESET_COLOR,
188 FIELD_VALUE_COLOR, str, RESET_COLOR);
194 print_caps (const GstCaps * caps, const gchar * pfx)
198 g_return_if_fail (caps != NULL);
200 if (gst_caps_is_any (caps)) {
201 n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
204 if (gst_caps_is_empty (caps)) {
205 n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
209 for (i = 0; i < gst_caps_get_size (caps); i++) {
210 GstStructure *structure = gst_caps_get_structure (caps, i);
211 GstCapsFeatures *features = gst_caps_get_features (caps, i);
213 if (features && (gst_caps_features_is_any (features) ||
214 !gst_caps_features_is_equal (features,
215 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
216 gchar *features_string = gst_caps_features_to_string (features);
218 n_print ("%s%s%s%s(%s%s%s)\n", pfx, STRUCT_NAME_COLOR,
219 gst_structure_get_name (structure), RESET_COLOR,
220 CAPS_FEATURE_COLOR, features_string, RESET_COLOR);
221 g_free (features_string);
223 n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
224 gst_structure_get_name (structure), RESET_COLOR);
226 gst_structure_foreach (structure, print_field, (gpointer) pfx);
231 get_rank_name (char *s, gint rank)
233 static const int ranks[4] = {
234 GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
236 static const char *rank_names[4] = { "none", "marginal", "secondary",
243 for (i = 0; i < 4; i++) {
244 if (rank == ranks[i])
245 return rank_names[i];
246 if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
251 sprintf (s, "%s %c %d", rank_names[best_i],
252 (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
258 print_factory_details_info (GstElementFactory * factory, GstPlugin * plugin)
261 gboolean seen_doc_uri = FALSE;
265 rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
266 n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
269 n_print ("%s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
270 get_rank_name (s, rank), rank, RESET_COLOR);
272 keys = gst_element_factory_get_metadata_keys (factory);
274 for (k = keys; *k != NULL; ++k) {
278 val = gst_element_factory_get_metadata (factory, key);
279 key[0] = g_ascii_toupper (key[0]);
280 n_print ("%s%-25s%s%s%s\n", PROP_NAME_COLOR, key, PROP_VALUE_COLOR, val,
283 seen_doc_uri || g_str_equal (key, GST_ELEMENT_METADATA_DOC_URI);
288 if (!seen_doc_uri && plugin != NULL &&
289 !gst_element_factory_get_skip_documentation (factory)) {
290 const gchar *module = gst_plugin_get_source (plugin);
291 const gchar *origin = gst_plugin_get_origin (plugin);
293 /* gst-plugins-rs has per-plugin module names so need to check origin there */
294 if (g_strv_contains (gstreamer_modules, module)
295 || (origin != NULL && g_str_has_suffix (origin, "/gst-plugins-rs"))) {
299 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
300 gst_plugin_get_name (plugin));
302 /* if the plugin only has a single feature, plugin page == feature page */
303 if (features != NULL && features->next == NULL) {
304 n_print ("%s%-25s%s%s%s/%s/#%s-page%s\n", PROP_NAME_COLOR,
305 "Documentation", RESET_COLOR, PROP_VALUE_COLOR, GST_DOC_BASE_URL,
306 gst_plugin_get_name (plugin), GST_OBJECT_NAME (factory),
309 n_print ("%s%-25s%s%s%s/%s/%s.html%s\n", PROP_NAME_COLOR,
310 "Documentation", RESET_COLOR, PROP_VALUE_COLOR, GST_DOC_BASE_URL,
311 gst_plugin_get_name (plugin), GST_OBJECT_NAME (factory),
314 gst_plugin_feature_list_free (features);
323 print_hierarchy (GType type, gint level, gint * maxlevel)
328 parent = g_type_parent (type);
330 *maxlevel = *maxlevel + 1;
334 print_hierarchy (parent, level, maxlevel);
337 g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
339 for (i = 1; i < *maxlevel - level; i++)
341 if (*maxlevel - level)
342 g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
344 g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
351 print_interfaces (GType type)
354 GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
358 n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
362 n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
373 flags_to_string (GFlagsValue * vals, guint flags)
378 /* first look for an exact match and count the number of values */
379 for (i = 0; vals[i].value_name != NULL; ++i) {
380 if (vals[i].value == flags)
381 return g_strdup (vals[i].value_nick);
384 s = g_string_new (NULL);
386 /* we assume the values are sorted from lowest to highest value */
390 if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
392 g_string_append_c (s, '+');
393 g_string_append (s, vals[i].value_nick);
394 flags_left -= vals[i].value;
401 g_string_assign (s, "(none)");
403 return g_string_free (s, FALSE);
406 #define KNOWN_PARAM_FLAGS \
407 (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
408 G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS | \
409 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_DEPRECATED | \
410 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | \
411 GST_PARAM_MUTABLE_PAUSED | GST_PARAM_MUTABLE_READY | \
412 GST_PARAM_CONDITIONALLY_AVAILABLE | GST_PARAM_DOC_SHOW_DEFAULT)
415 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
417 return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
420 /* obj will be NULL if we're printing properties of pad template pads */
422 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
425 GParamSpec **property_specs;
426 guint num_properties, i;
430 property_specs = g_object_class_list_properties (obj_class, &num_properties);
431 g_qsort_with_data (property_specs, num_properties, sizeof (gpointer),
432 (GCompareDataFunc) sort_gparamspecs, NULL);
434 n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
438 for (i = 0; i < num_properties; i++) {
439 GValue value = { 0, };
440 GParamSpec *param = property_specs[i];
441 GType owner_type = param->owner_type;
443 /* We're printing pad properties */
444 if (obj == NULL && (owner_type == G_TYPE_OBJECT
445 || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
448 g_value_init (&value, param->value_type);
450 n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
451 g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
452 g_param_spec_get_blurb (param), RESET_COLOR);
457 n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
458 readable = ! !(param->flags & G_PARAM_READABLE);
459 if (readable && obj != NULL) {
460 g_object_get_property (obj, param->name, &value);
462 /* if we can't read the property value, assume it's set to the default
463 * (which might not be entirely true for sub-classes, but that's an
464 * unlikely corner-case anyway) */
465 g_param_value_set_default (param, &value);
468 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
469 _("readable"), RESET_COLOR);
472 if (param->flags & G_PARAM_WRITABLE) {
473 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
474 _("writable"), RESET_COLOR);
477 if (param->flags & G_PARAM_DEPRECATED) {
478 g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
479 _("deprecated"), RESET_COLOR);
482 if (param->flags & GST_PARAM_CONTROLLABLE) {
483 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
487 if (param->flags & GST_PARAM_CONDITIONALLY_AVAILABLE) {
488 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("conditionally available"),
492 if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
493 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
494 _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
495 } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
496 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
497 _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
498 } else if (param->flags & GST_PARAM_MUTABLE_READY) {
499 g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
500 _("changeable only in NULL or READY state"), RESET_COLOR);
502 if (param->flags & ~KNOWN_PARAM_FLAGS) {
503 g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
504 param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
508 switch (G_VALUE_TYPE (&value)) {
511 const char *string_val = g_value_get_string (&value);
513 n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
515 if (string_val == NULL)
516 g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
517 PROP_ATTR_VALUE_COLOR, RESET_COLOR);
519 g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
520 PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
525 gboolean bool_val = g_value_get_boolean (&value);
527 n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
528 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
529 PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
534 GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
537 ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
538 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
539 PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
540 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
541 PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
543 GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
544 "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
545 g_param_spec_get_name (param));
550 GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
552 n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
553 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
554 PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
555 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
556 g_value_get_long (&value), RESET_COLOR);
558 GST_ERROR ("%s: property '%s' of type long: consider changing to "
559 "int/int64", G_OBJECT_CLASS_NAME (obj_class),
560 g_param_spec_get_name (param));
565 GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
568 ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
569 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
570 PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
571 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
572 g_value_get_uint (&value), RESET_COLOR);
577 GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
579 n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
580 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
581 PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
582 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
583 g_value_get_int (&value), RESET_COLOR);
588 GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
590 n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
591 "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
592 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
593 PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
594 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
595 PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
600 GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
602 n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
603 G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
604 DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
605 PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
606 RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
607 PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
612 GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
614 n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
615 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
616 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
617 pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
618 RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
624 GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
626 n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
627 "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
628 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
629 pdouble->minimum, pdouble->maximum, RESET_COLOR,
630 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
631 g_value_get_double (&value), RESET_COLOR);
636 GST_ERROR ("%s: property '%s' of type char: consider changing to "
637 "int/string", G_OBJECT_CLASS_NAME (obj_class),
638 g_param_spec_get_name (param));
641 if (param->value_type == GST_TYPE_CAPS) {
642 const GstCaps *caps = gst_value_get_caps (&value);
645 n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
647 print_caps (caps, " ");
649 } else if (G_IS_PARAM_SPEC_ENUM (param)) {
653 const gchar *value_nick = "";
655 values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
656 enum_value = g_value_get_enum (&value);
658 while (values[j].value_name) {
659 if (values[j].value == enum_value)
660 value_nick = values[j].value_nick;
664 n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
665 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
666 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
667 enum_value, value_nick, RESET_COLOR);
670 while (values[j].value_name) {
672 n_print (" %s(%d)%s: %s%-16s%s - %s%s%s",
673 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
674 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
675 DESC_COLOR, values[j].value_name, RESET_COLOR);
678 /* g_type_class_unref (ec); */
679 } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
680 GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
684 vals = pflags->flags_class->values;
686 cur = flags_to_string (vals, g_value_get_flags (&value));
688 n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
689 DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
690 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
691 g_value_get_flags (&value), cur, RESET_COLOR);
693 while (vals[0].value_name) {
695 n_print (" %s(0x%08x)%s: %s%-16s%s - %s%s%s",
696 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
697 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
698 DESC_COLOR, vals[0].value_name, RESET_COLOR);
703 } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
704 n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
705 RESET_COLOR, DATATYPE_COLOR,
706 g_type_name (param->value_type), RESET_COLOR);
707 } else if (G_IS_PARAM_SPEC_BOXED (param)) {
708 n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
709 RESET_COLOR, DATATYPE_COLOR,
710 g_type_name (param->value_type), RESET_COLOR);
711 if (param->value_type == GST_TYPE_STRUCTURE) {
712 const GstStructure *s = gst_value_get_structure (&value);
715 gst_structure_foreach (s, print_field,
719 } else if (G_IS_PARAM_SPEC_POINTER (param)) {
720 if (param->value_type != G_TYPE_POINTER) {
721 n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
722 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
725 n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
727 } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
728 GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
730 if (pvarray->element_spec) {
731 n_print ("%sArray of GValues of type%s %s\"%s\"%s",
732 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
733 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
735 n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
737 } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
738 GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
740 n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
741 "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
742 PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
743 pfraction->min_num, pfraction->min_den, pfraction->max_num,
744 pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
745 RESET_COLOR, PROP_ATTR_VALUE_COLOR,
746 gst_value_get_fraction_numerator (&value),
747 gst_value_get_fraction_denominator (&value), RESET_COLOR);
748 } else if (param->value_type == GST_TYPE_ARRAY) {
749 GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
751 if (GST_VALUE_HOLDS_ARRAY (&value)) {
752 gchar *def = gst_value_serialize (&value);
754 n_print ("%sDefault%s: \"%s\"\n", PROP_ATTR_VALUE_COLOR,
760 if (parray->element_spec) {
761 n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
762 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
763 g_type_name (parray->element_spec->value_type), RESET_COLOR);
765 n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
769 n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
770 (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
771 g_type_name (param->value_type), RESET_COLOR);
776 g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
782 g_value_reset (&value);
784 if (num_properties == 0)
785 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
789 g_free (property_specs);
793 print_element_properties_info (GstElement * element)
796 print_object_properties_info (G_OBJECT (element),
797 G_OBJECT_GET_CLASS (element), "Element Properties");
801 gst_static_pad_compare_func (gconstpointer p1, gconstpointer p2)
803 GstStaticPadTemplate *pt1, *pt2;
805 pt1 = (GstStaticPadTemplate *) p1;
806 pt2 = (GstStaticPadTemplate *) p2;
808 return strcmp (pt1->name_template, pt2->name_template);
813 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
816 GstStaticPadTemplate *padtemplate;
817 GstPadTemplate *tmpl;
819 n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
823 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
824 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
828 pads = g_list_copy ((GList *)
829 gst_element_factory_get_static_pad_templates (factory));
830 pads = g_list_sort (pads, gst_static_pad_compare_func);
832 for (tmp = pads; tmp; tmp = tmp->next) {
833 padtemplate = (GstStaticPadTemplate *) (tmp->data);
835 if (padtemplate->direction == GST_PAD_SRC)
836 n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
837 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
838 else if (padtemplate->direction == GST_PAD_SINK)
839 n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
840 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
842 n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
843 PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
847 if (padtemplate->presence == GST_PAD_ALWAYS)
848 n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
849 PROP_VALUE_COLOR, RESET_COLOR);
850 else if (padtemplate->presence == GST_PAD_SOMETIMES)
851 n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
852 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
853 else if (padtemplate->presence == GST_PAD_REQUEST) {
854 n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
855 RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
857 n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
858 PROP_VALUE_COLOR, RESET_COLOR);
860 if (padtemplate->static_caps.string) {
861 GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
863 n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
866 print_caps (caps, ""); // FIXME
869 gst_caps_unref (caps);
872 tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
873 padtemplate->name_template);
875 GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
877 if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
880 pad_klass = g_type_class_ref (pad_type);
881 n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
882 DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
883 print_object_properties_info (NULL, pad_klass, "Pad Properties");
884 g_type_class_unref (pad_klass);
899 print_clocking_info (GstElement * element)
901 gboolean requires_clock, provides_clock;
904 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
906 GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
908 if (!requires_clock && !provides_clock) {
910 n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
916 n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
920 if (requires_clock) {
921 n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
924 if (provides_clock) {
927 clock = gst_element_get_clock (element);
929 n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
930 RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
931 gst_object_unref (clock);
933 n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
934 PROP_VALUE_COLOR, RESET_COLOR);
941 print_uri_handler_info (GstElement * element)
943 if (GST_IS_URI_HANDLER (element)) {
944 const gchar *const *uri_protocols;
945 const gchar *uri_type;
947 if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
949 else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
953 uri_type = "unknown";
955 uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
958 n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
962 n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
964 if (uri_protocols && *uri_protocols) {
965 n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
967 for (; *uri_protocols != NULL; uri_protocols++)
968 n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
972 n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
978 n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
984 print_pad_info (GstElement * element)
990 n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
994 if (!element->numpads) {
995 n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
999 pads = element->pads;
1004 pad = GST_PAD (pads->data);
1005 pads = g_list_next (pads);
1007 name = gst_pad_get_name (pad);
1008 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
1009 n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1010 PROP_VALUE_COLOR, name, RESET_COLOR);
1011 else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
1012 n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1013 PROP_VALUE_COLOR, name, RESET_COLOR);
1015 n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1016 PROP_VALUE_COLOR, name, RESET_COLOR);
1020 if (pad->padtemplate) {
1022 n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1023 PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
1027 caps = gst_pad_get_current_caps (pad);
1029 n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
1031 print_caps (caps, ""); // FIXME
1033 gst_caps_unref (caps);
1042 has_sometimes_template (GstElement * element)
1044 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
1047 for (l = klass->padtemplates; l != NULL; l = l->next) {
1048 if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
1056 gtype_needs_ptr_marker (GType type)
1058 if (type == G_TYPE_POINTER)
1061 if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
1062 || G_TYPE_IS_OBJECT (type))
1069 print_signal_info (GstElement * element)
1071 /* Signals/Actions Block */
1075 GSignalQuery *query = NULL;
1077 GSList *found_signals, *l;
1079 for (k = 0; k < 2; k++) {
1080 found_signals = NULL;
1082 /* For elements that have sometimes pads, also list a few useful GstElement
1083 * signals. Put these first, so element-specific ones come later. */
1084 if (k == 0 && has_sometimes_template (element)) {
1085 query = g_new0 (GSignalQuery, 1);
1086 g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
1087 found_signals = g_slist_append (found_signals, query);
1088 query = g_new0 (GSignalQuery, 1);
1089 g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
1090 found_signals = g_slist_append (found_signals, query);
1091 query = g_new0 (GSignalQuery, 1);
1092 g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
1094 found_signals = g_slist_append (found_signals, query);
1097 for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
1098 if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1101 if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1104 signals = g_signal_list_ids (type, &nsignals);
1105 for (i = 0; i < nsignals; i++) {
1106 query = g_new0 (GSignalQuery, 1);
1107 g_signal_query (signals[i], query);
1109 if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1110 (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1111 found_signals = g_slist_append (found_signals, query);
1119 if (found_signals) {
1122 n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1124 n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1129 for (l = found_signals; l; l = l->next) {
1134 query = (GSignalQuery *) l->data;
1135 indent_len = strlen (query->signal_name) +
1136 strlen (g_type_name (query->return_type)) + 24;
1138 if (gtype_needs_ptr_marker (query->return_type)) {
1145 indent = g_new0 (gchar, indent_len + 1);
1146 memset (indent, ' ', indent_len);
1148 n_print (" %s\"%s\"%s : %s%s%s%suser_function%s (%s%s%s* object%s",
1149 PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1150 DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1151 pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1152 PROP_VALUE_COLOR, RESET_COLOR);
1154 for (j = 0; j < query->n_params; j++) {
1155 const gchar *type_name, *asterisk;
1157 type_name = g_type_name (query->param_types[j]);
1158 asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1161 n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1162 PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1167 n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1168 PROP_VALUE_COLOR, RESET_COLOR);
1175 if (found_signals) {
1176 g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1177 g_slist_free (found_signals);
1183 print_children_info (GstElement * element)
1187 if (!GST_IS_BIN (element))
1190 children = (GList *) GST_BIN (element)->children;
1193 n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1197 n_print (" %s%s%s\n", DATATYPE_COLOR,
1198 GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1199 children = g_list_next (children);
1204 print_preset_list (GstElement * element)
1206 gchar **presets, **preset;
1208 if (!GST_IS_PRESET (element))
1211 presets = gst_preset_get_preset_names (GST_PRESET (element));
1212 if (presets && *presets) {
1214 n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1215 for (preset = presets; *preset; preset++) {
1216 gchar *comment = NULL;
1217 n_print (" \"%s\"", *preset);
1219 if (gst_preset_get_meta (GST_PRESET (element), *preset, "comment",
1220 &comment) && comment)
1221 g_print (": %s", comment);
1225 g_strfreev (presets);
1230 gst_plugin_name_compare_func (gconstpointer p1, gconstpointer p2)
1232 return strcmp (gst_plugin_get_name ((GstPlugin *) p1),
1233 gst_plugin_get_name ((GstPlugin *) p2));
1237 gst_plugin_feature_name_compare_func (gconstpointer p1, gconstpointer p2)
1239 return strcmp (GST_OBJECT_NAME (p1), GST_OBJECT_NAME (p2));
1243 print_blacklist (void)
1245 GList *plugins, *cur;
1248 g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1250 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1251 if (sort_output == SORT_TYPE_NAME)
1252 plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1254 for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1255 GstPlugin *plugin = (GstPlugin *) (cur->data);
1256 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1257 g_print (" %s\n", gst_plugin_get_name (plugin));
1263 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1265 g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1267 g_print ("%s\n", RESET_COLOR);
1268 gst_plugin_list_free (plugins);
1272 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1276 while (extensions[i]) {
1277 g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1283 print_element_list (gboolean print_all, gchar * ftypes)
1285 int plugincount = 0, featurecount = 0, blacklistcount = 0;
1286 GList *plugins, *orig_plugins;
1287 gchar **types = NULL;
1292 types = g_strsplit (ftypes, "/", -1);
1293 for (i = 0; types[i]; i++)
1294 *types[i] = g_ascii_toupper (*types[i]);
1298 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1299 if (sort_output == SORT_TYPE_NAME)
1300 plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1302 GList *features, *orig_features;
1305 plugin = (GstPlugin *) (plugins->data);
1306 plugins = g_list_next (plugins);
1309 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1314 orig_features = features =
1315 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1316 gst_plugin_get_name (plugin));
1317 if (sort_output == SORT_TYPE_NAME)
1318 features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1320 GstPluginFeature *feature;
1322 if (G_UNLIKELY (features->data == NULL))
1324 feature = GST_PLUGIN_FEATURE (features->data);
1327 if (GST_IS_ELEMENT_FACTORY (feature)) {
1329 GstElementFactory *factory;
1331 factory = GST_ELEMENT_FACTORY (feature);
1334 gboolean all_found = TRUE;
1337 gst_element_factory_get_metadata (factory,
1338 GST_ELEMENT_METADATA_KLASS);
1339 for (i = 0; types[i]; i++) {
1340 if (!strstr (klass, types[i])) {
1350 print_element_info (feature, TRUE);
1352 g_print ("%s%s%s: %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1353 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1354 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1355 gst_element_factory_get_metadata (factory,
1356 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1357 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1358 GstTypeFindFactory *factory;
1359 const gchar *const *extensions;
1363 factory = GST_TYPE_FIND_FACTORY (feature);
1365 g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1366 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1367 gst_plugin_feature_get_name (feature), RESET_COLOR);
1369 extensions = gst_type_find_factory_get_extensions (factory);
1370 if (extensions != NULL) {
1372 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1377 g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1383 n_print ("%s%s%s: %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1384 gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1385 GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1386 g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1390 features = g_list_next (features);
1393 gst_plugin_feature_list_free (orig_features);
1396 gst_plugin_list_free (orig_plugins);
1400 g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1402 g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1403 if (blacklistcount) {
1405 g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1406 blacklistcount), blacklistcount);
1407 g_print (" not shown)");
1409 g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1410 g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1411 g_print ("%s\n", RESET_COLOR);
1415 print_all_uri_handlers (void)
1417 GList *plugins, *p, *features, *f;
1419 plugins = gst_registry_get_plugin_list (gst_registry_get ());
1420 if (sort_output == SORT_TYPE_NAME)
1421 plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1422 for (p = plugins; p; p = p->next) {
1423 GstPlugin *plugin = (GstPlugin *) (p->data);
1426 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1427 gst_plugin_get_name (plugin));
1428 if (sort_output == SORT_TYPE_NAME)
1429 features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1430 for (f = features; f; f = f->next) {
1431 GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1433 if (GST_IS_ELEMENT_FACTORY (feature)) {
1434 GstElementFactory *factory;
1435 GstElement *element;
1437 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1439 g_print ("element plugin %s couldn't be loaded\n",
1440 gst_plugin_get_name (plugin));
1444 element = gst_element_factory_create (factory, NULL);
1446 g_print ("couldn't construct element for %s for some reason\n",
1447 GST_OBJECT_NAME (factory));
1448 gst_object_unref (factory);
1452 if (GST_IS_URI_HANDLER (element)) {
1453 const gchar *const *uri_protocols;
1454 const gchar *const *protocol;
1457 switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1469 g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1471 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1472 RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1474 gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1478 gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1479 for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1480 if (protocol != uri_protocols)
1482 g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1487 gst_object_unref (element);
1488 gst_object_unref (factory);
1492 gst_plugin_feature_list_free (features);
1495 gst_plugin_list_free (plugins);
1499 print_plugin_info (GstPlugin * plugin)
1501 const gchar *plugin_name = gst_plugin_get_name (plugin);
1502 const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1503 const gchar *filename = gst_plugin_get_filename (plugin);
1504 const gchar *module = gst_plugin_get_source (plugin);
1505 const gchar *origin = gst_plugin_get_origin (plugin);
1507 n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1511 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1512 PROP_VALUE_COLOR, plugin_name, RESET_COLOR);
1513 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1514 PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1515 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1516 PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1517 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1518 PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1519 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1520 PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1521 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1522 PROP_VALUE_COLOR, module, RESET_COLOR);
1524 /* gst-plugins-rs has per-plugin module names so need to check origin there */
1525 if (g_strv_contains (gstreamer_modules, module)
1526 || (origin != NULL && g_str_has_suffix (origin, "/gst-plugins-rs"))) {
1527 n_print ("%s%-25s%s%s%s/%s/%s\n", PROP_NAME_COLOR, "Documentation",
1528 RESET_COLOR, PROP_VALUE_COLOR, GST_DOC_BASE_URL, plugin_name,
1532 if (release_date != NULL) {
1533 const gchar *tz = "(UTC)";
1536 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1537 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1538 str = g_strdup (release_date);
1539 sep = strstr (str, "T");
1542 sep = strstr (sep + 1, "Z");
1548 n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1549 RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1552 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1553 PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1554 n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1555 PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1563 print_plugin_features (GstPlugin * plugin)
1565 GList *features, *origlist;
1566 gint num_features = 0;
1567 gint num_elements = 0;
1568 gint num_tracers = 0;
1569 gint num_typefinders = 0;
1570 gint num_devproviders = 0;
1573 origlist = features =
1574 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1575 gst_plugin_get_name (plugin));
1576 if (sort_output == SORT_TYPE_NAME)
1577 features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1579 GstPluginFeature *feature;
1581 feature = GST_PLUGIN_FEATURE (features->data);
1583 if (GST_IS_ELEMENT_FACTORY (feature)) {
1584 GstElementFactory *factory;
1586 factory = GST_ELEMENT_FACTORY (feature);
1587 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1588 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1589 gst_element_factory_get_metadata (factory,
1590 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1592 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1593 GstTypeFindFactory *factory;
1594 const gchar *const *extensions;
1596 factory = GST_TYPE_FIND_FACTORY (feature);
1597 extensions = gst_type_find_factory_get_extensions (factory);
1599 g_print (" %s%s%s: ", ELEMENT_NAME_COLOR,
1600 gst_plugin_feature_get_name (feature), RESET_COLOR);
1601 print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1604 g_print (" %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1605 gst_plugin_feature_get_name (feature), RESET_COLOR,
1606 ELEMENT_DETAIL_COLOR, RESET_COLOR);
1609 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1610 GstDeviceProviderFactory *factory;
1612 factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1613 n_print (" %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1614 GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1615 gst_device_provider_factory_get_metadata (factory,
1616 GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1618 } else if (GST_IS_TRACER_FACTORY (feature)) {
1619 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1620 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1621 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1623 } else if (feature) {
1624 n_print (" %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1625 gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1626 DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1630 features = g_list_next (features);
1633 gst_plugin_feature_list_free (origlist);
1636 n_print (" %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1637 if (num_elements > 0)
1638 n_print (" %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1639 PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1640 if (num_typefinders > 0)
1641 n_print (" %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1642 PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1643 if (num_devproviders > 0)
1644 n_print (" %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1645 RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1646 if (num_tracers > 0)
1647 n_print (" %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1648 PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1650 n_print (" %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1651 PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1657 print_feature_info (const gchar * feature_name, gboolean print_all)
1659 GstPluginFeature *feature;
1660 GstRegistry *registry = gst_registry_get ();
1663 if ((feature = gst_registry_find_feature (registry, feature_name,
1664 GST_TYPE_ELEMENT_FACTORY))) {
1665 ret = print_element_info (feature, print_all);
1668 if ((feature = gst_registry_find_feature (registry, feature_name,
1669 GST_TYPE_TYPE_FIND_FACTORY))) {
1670 ret = print_typefind_info (feature, print_all);
1673 if ((feature = gst_registry_find_feature (registry, feature_name,
1674 GST_TYPE_TRACER_FACTORY))) {
1675 ret = print_tracer_info (feature, print_all);
1679 /* TODO: handle DEVICE_PROVIDER_FACTORY */
1684 gst_object_unref (feature);
1689 print_element_info (GstPluginFeature * feature, gboolean print_names)
1691 GstElementFactory *factory;
1692 GstElement *element;
1696 factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1698 g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1703 element = gst_element_factory_create (factory, NULL);
1705 gst_object_unref (factory);
1706 g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1713 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1718 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1720 print_factory_details_info (factory, plugin);
1723 print_plugin_info (plugin);
1724 gst_object_unref (plugin);
1727 print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1728 print_interfaces (G_OBJECT_TYPE (element));
1730 print_pad_templates_info (element, factory);
1731 print_clocking_info (element);
1732 print_uri_handler_info (element);
1733 print_pad_info (element);
1734 print_element_properties_info (element);
1735 print_signal_info (element);
1736 print_children_info (element);
1737 print_preset_list (element);
1739 gst_object_unref (element);
1740 gst_object_unref (factory);
1746 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1748 GstTypeFindFactory *factory;
1753 const gchar *const *extensions;
1755 factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1757 g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1764 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1769 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1770 rank = gst_plugin_feature_get_rank (feature);
1771 n_print (" %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1772 get_rank_name (s, rank), rank, RESET_COLOR);
1773 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1774 GST_OBJECT_NAME (factory), RESET_COLOR);
1775 caps = gst_type_find_factory_get_caps (factory);
1777 gchar *caps_str = gst_caps_to_string (factory->caps);
1779 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1780 caps_str, RESET_COLOR);
1783 extensions = gst_type_find_factory_get_extensions (factory);
1785 n_print (" %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1786 print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1791 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1793 print_plugin_info (plugin);
1794 gst_object_unref (plugin);
1797 gst_object_unref (factory);
1803 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1805 GstTracerFactory *factory;
1810 factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1812 g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1816 tracer = (GstTracer *) g_object_new (factory->type, NULL);
1818 gst_object_unref (factory);
1819 g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1826 g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1831 n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1832 n_print (" %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1833 GST_OBJECT_NAME (factory), RESET_COLOR);
1836 plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1838 print_plugin_info (plugin);
1839 gst_object_unref (plugin);
1842 print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1843 print_interfaces (G_OBJECT_TYPE (tracer));
1845 /* TODO: list what hooks it registers
1846 * - the data is available in gsttracerutils, we need to iterate the
1847 * _priv_tracers hashtable for each probe and then check the list of hooks
1848 * for each probe whether hook->tracer == tracer :/
1851 /* TODO: list what records it emits
1852 * - in class_init tracers can create GstTracerRecord instances
1853 * - those only get logged right now and there is no association with the
1854 * tracer that created them
1855 * - we'd need to add them to GstTracerFactory
1856 * gst_tracer_class_add_record (klass, record);
1857 * - needs work in gstregistrychunks to (de)serialize specs
1858 * - gst_tracer_register() would need to iterate the list of records and
1859 * copy the record->spec into the factory
1862 gst_object_unref (tracer);
1863 gst_object_unref (factory);
1868 /* NOTE: Not coloring output from automatic install functions, as their output
1869 * is meant for machines, not humans.
1872 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1874 GstPadDirection direction;
1875 const gchar *type_name;
1877 const GList *static_templates, *l;
1878 GstCaps *caps = NULL;
1882 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1883 g_return_if_fail (klass != NULL);
1885 if (strstr (klass, "Demuxer") ||
1886 strstr (klass, "Decoder") ||
1887 strstr (klass, "Depay") || strstr (klass, "Parser")) {
1888 type_name = "decoder";
1889 direction = GST_PAD_SINK;
1890 } else if (strstr (klass, "Muxer") ||
1891 strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1892 type_name = "encoder";
1893 direction = GST_PAD_SRC;
1898 /* decoder/demuxer sink pads should always be static and there should only
1899 * be one, the same applies to encoders/muxers and source pads */
1900 static_templates = gst_element_factory_get_static_pad_templates (factory);
1901 for (l = static_templates; l != NULL; l = l->next) {
1902 GstStaticPadTemplate *tmpl = NULL;
1904 tmpl = (GstStaticPadTemplate *) l->data;
1905 if (tmpl->direction == direction) {
1906 caps = gst_static_pad_template_get_caps (tmpl);
1912 g_printerr ("Couldn't find static pad template for %s '%s'\n",
1913 type_name, GST_OBJECT_NAME (factory));
1917 caps = gst_caps_make_writable (caps);
1918 num = gst_caps_get_size (caps);
1919 for (i = 0; i < num; ++i) {
1923 s = gst_caps_get_structure (caps, i);
1924 /* remove fields that are almost always just MIN-MAX of some sort
1925 * in order to make the caps look less messy */
1926 gst_structure_remove_field (s, "pixel-aspect-ratio");
1927 gst_structure_remove_field (s, "framerate");
1928 gst_structure_remove_field (s, "channels");
1929 gst_structure_remove_field (s, "width");
1930 gst_structure_remove_field (s, "height");
1931 gst_structure_remove_field (s, "rate");
1932 gst_structure_remove_field (s, "depth");
1933 gst_structure_remove_field (s, "clock-rate");
1934 s_str = gst_structure_to_string (s);
1935 g_print ("%s-%s\n", type_name, s_str);
1938 gst_caps_unref (caps);
1942 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1944 const gchar *const *protocols;
1946 protocols = gst_element_factory_get_uri_protocols (factory);
1947 if (protocols != NULL && *protocols != NULL) {
1948 switch (gst_element_factory_get_uri_type (factory)) {
1950 while (*protocols != NULL) {
1951 g_print ("urisink-%s\n", *protocols);
1956 while (*protocols != NULL) {
1957 g_print ("urisource-%s\n", *protocols);
1968 print_plugin_automatic_install_info (GstPlugin * plugin)
1970 GList *features, *l;
1972 /* not interested in typefind factories, only element factories */
1973 features = gst_registry_get_feature_list (gst_registry_get (),
1974 GST_TYPE_ELEMENT_FACTORY);
1976 for (l = features; l != NULL; l = l->next) {
1977 GstPluginFeature *feature;
1978 GstPlugin *feature_plugin;
1980 feature = GST_PLUGIN_FEATURE (l->data);
1982 /* only interested in the ones that are in the plugin we just loaded */
1983 feature_plugin = gst_plugin_feature_get_plugin (feature);
1984 if (feature_plugin == plugin) {
1985 GstElementFactory *factory;
1987 g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1989 factory = GST_ELEMENT_FACTORY (feature);
1990 print_plugin_automatic_install_info_protocols (factory);
1991 print_plugin_automatic_install_info_codecs (factory);
1994 gst_object_unref (feature_plugin);
1997 g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1998 g_list_free (features);
2002 print_all_plugin_automatic_install_info (void)
2004 GList *plugins, *orig_plugins;
2006 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
2007 if (sort_output == SORT_TYPE_NAME)
2008 plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
2012 plugin = (GstPlugin *) (plugins->data);
2013 plugins = g_list_next (plugins);
2015 print_plugin_automatic_install_info (plugin);
2017 gst_plugin_list_free (orig_plugins);
2022 redirect_stdout (void)
2024 GError *error = NULL;
2026 const gchar *pager, *less;
2030 pager = g_getenv ("PAGER");
2032 pager = DEFAULT_PAGER;
2034 argv = g_strsplit (pager, " ", 0);
2036 less = g_getenv ("GST_LESS");
2038 less = DEFAULT_LESS_OPTS;
2040 envp = g_get_environ ();
2041 envp = g_environ_setenv (envp, "LESS", less, TRUE);
2043 if (!g_spawn_async_with_pipes (NULL, argv, envp,
2044 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
2045 NULL, NULL, &child_pid, &stdin_fd,
2046 /* pass null stdout/stderr to inherit our fds */
2047 NULL, NULL, &error)) {
2048 if (pager != DEFAULT_PAGER) {
2049 g_warning ("g_spawn_async_with_pipes() failed: %s\n",
2050 GST_STR_NULL (error->message));
2054 g_clear_error (&error);
2059 /* redirect our stdout to child stdin */
2060 dup2 (stdin_fd, STDOUT_FILENO);
2061 if (isatty (STDERR_FILENO))
2062 dup2 (stdin_fd, STDERR_FILENO);
2072 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
2074 g_spawn_close_pid (child_pid);
2075 g_main_loop_quit (loop);
2080 _parse_sort_type (const gchar * option_name, const gchar * optarg,
2081 gpointer data, GError ** error)
2083 if (!g_strcmp0 (optarg, "name")) {
2084 sort_output = SORT_TYPE_NAME;
2086 } else if (!g_strcmp0 (optarg, "none")) {
2087 sort_output = SORT_TYPE_NONE;
2095 real_main (int argc, char *argv[])
2097 gboolean print_all = FALSE;
2098 gboolean do_print_blacklist = FALSE;
2099 gboolean plugin_name = FALSE;
2100 gboolean print_aii = FALSE;
2101 gboolean uri_handlers = FALSE;
2102 gboolean check_exists = FALSE;
2103 gboolean color_always = FALSE;
2104 gchar *min_version = NULL;
2105 guint minver_maj = GST_VERSION_MAJOR;
2106 guint minver_min = GST_VERSION_MINOR;
2107 guint minver_micro = 0;
2108 gchar *types = NULL;
2109 const gchar *no_colors;
2111 #ifndef GST_DISABLE_OPTION_PARSING
2112 GOptionEntry options[] = {
2113 {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
2114 N_("Print all elements"), NULL},
2115 {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
2116 N_("Print list of blacklisted files"), NULL},
2117 {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
2118 N_("Print a machine-parsable list of features the specified plugin "
2119 "or all plugins provide.\n "
2120 "Useful in connection with external automatic plugin "
2121 "installation mechanisms"), NULL},
2122 {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
2123 N_("List the plugin contents"), NULL},
2124 {"types", 't', 0, G_OPTION_ARG_STRING, &types,
2125 N_("A slashes ('/') separated list of types of elements (also known "
2126 "as klass) to list. (unordered)"), NULL},
2127 {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
2128 N_("Check if the specified element or plugin exists"), NULL},
2129 {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
2131 ("When checking if an element or plugin exists, also check that its "
2132 "version is at least the version specified"), NULL},
2133 {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
2135 ("Print supported URI schemes, with the elements that implement them"),
2137 {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
2140 ("Disable colors in output. You can also achieve the same by setting "
2141 "'GST_INSPECT_NO_COLORS' environment variable to any value."),
2143 {"sort", '\0', G_OPTION_ARG_NONE, G_OPTION_ARG_CALLBACK, &_parse_sort_type,
2144 "Sort plugins and features. Sorting keys: name (default), none.",
2147 {"color", 'C', 0, G_OPTION_ARG_NONE, &color_always,
2148 N_("Color output, even when not sending to a tty."),
2150 GST_TOOLS_GOPTION_VERSION,
2153 GOptionContext *ctx;
2157 setlocale (LC_ALL, "");
2160 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
2161 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2162 textdomain (GETTEXT_PACKAGE);
2165 /* avoid glib warnings when inspecting deprecated properties */
2166 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
2168 g_set_prgname ("gst-inspect-" GST_API_VERSION);
2170 #ifndef GST_DISABLE_OPTION_PARSING
2171 ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2172 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2173 g_option_context_add_group (ctx, gst_init_get_option_group ());
2174 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2175 if (!g_option_context_parse_strv (ctx, &argv, &err))
2177 if (!g_option_context_parse (ctx, &argc, &argv, &err))
2180 g_printerr ("Error initializing: %s\n", err->message);
2181 g_clear_error (&err);
2182 g_option_context_free (ctx);
2185 g_option_context_free (ctx);
2187 gst_init (&argc, &argv);
2190 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2191 argc = g_strv_length (argv);
2194 gst_tools_print_version ();
2196 if (print_all && argc > 1) {
2197 g_printerr ("-a requires no extra arguments\n");
2201 if (uri_handlers && argc > 1) {
2202 g_printerr ("-u requires no extra arguments\n");
2206 /* --atleast-version implies --exists */
2207 if (min_version != NULL) {
2208 if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2209 &minver_micro) < 2) {
2210 g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2212 g_free (min_version);
2215 g_free (min_version);
2216 check_exists = TRUE;
2221 g_printerr ("--exists requires an extra command line argument\n");
2225 GstPluginFeature *feature;
2227 feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2228 if (feature != NULL && gst_plugin_feature_check_version (feature,
2229 minver_maj, minver_min, minver_micro)) {
2236 gst_object_unref (feature);
2238 /* FIXME: support checking for plugins too */
2239 g_printerr ("Checking for plugins is not supported yet\n");
2246 no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2247 /* We only support truecolor */
2248 colored_output &= (no_colors == NULL);
2251 if (isatty (STDOUT_FILENO)) {
2252 if (redirect_stdout ())
2253 loop = g_main_loop_new (NULL, FALSE);
2255 colored_output = (color_always) ? TRUE : FALSE;
2257 #elif defined(G_OS_WIN32)
2259 /* g_log_writer_supports_color is available since 2.50.0 */
2260 gint fd = _fileno (stdout);
2261 /* On Windows 10, g_log_writer_supports_color will also setup the console
2262 * so that it correctly interprets ANSI VT sequences if it's supported */
2263 if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2264 colored_output = FALSE;
2268 /* if no arguments, print out list of elements */
2270 print_all_uri_handlers ();
2271 } else if (argc == 1 || print_all) {
2272 if (do_print_blacklist)
2276 print_all_plugin_automatic_install_info ();
2278 print_element_list (print_all, types);
2281 /* else we try to get a factory */
2282 const char *arg = argv[argc - 1];
2286 retval = print_feature_info (arg, print_all);
2289 /* otherwise check if it's a plugin */
2291 GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2293 /* if there is such a plugin, print out info */
2296 print_plugin_automatic_install_info (plugin);
2298 print_plugin_info (plugin);
2299 print_plugin_features (plugin);
2302 GError *error = NULL;
2304 if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2305 plugin = gst_plugin_load_file (arg, &error);
2309 print_plugin_automatic_install_info (plugin);
2311 print_plugin_info (plugin);
2312 print_plugin_features (plugin);
2315 g_printerr (_("Could not load plugin file: %s\n"), error->message);
2316 g_clear_error (&error);
2321 g_printerr (_("No such element or plugin '%s'\n"), arg);
2335 /* So that the pipe we create in redirect_stdout() is closed */
2336 close (STDOUT_FILENO);
2337 close (STDERR_FILENO);
2338 g_child_watch_add (child_pid, child_exit_cb, NULL);
2339 g_main_loop_run (loop);
2340 g_main_loop_unref (loop);
2348 main (int argc, char *argv[])
2352 /* gstinspect.c calls this function */
2353 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2354 argv = g_win32_get_command_line ();
2357 #if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
2358 ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
2360 ret = real_main (argc, argv);
2363 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)