d62b401eeae422978bf59a5e3cf616615acfd31a
[platform/upstream/gstreamer.git] / subprojects / gstreamer / tools / gst-inspect.c
1 /* GStreamer
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>
5  *               2018 Collabora Ltd.
6  *
7  * gst-inspect.c: tool to inspect the GStreamer registry
8  *
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.
13  *
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.
18  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #  include "config.h"
27 #endif
28
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
32
33 #include "tools.h"
34 #include <gst/gst_private.h>    /* for internal Factories */
35
36 #include <string.h>
37 #include <locale.h>
38 #include <glib/gprintf.h>
39 #ifdef G_OS_UNIX
40 #   include <unistd.h>
41 #   include <sys/wait.h>
42 #endif
43
44 #ifdef G_OS_WIN32
45 /* _isatty() */
46 #include <io.h>
47 #endif
48
49 #ifdef __APPLE__
50 #include <TargetConditionals.h>
51 #endif
52
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
56  *
57  * Don't forget to update the manpage gst-inspect-1.0.1
58  * after changing this default.
59  */
60 #define DEFAULT_LESS_OPTS "RXF"
61
62 gboolean colored_output = TRUE;
63
64 typedef enum
65 {
66   SORT_TYPE_NONE = 0,
67   SORT_TYPE_NAME,               /* default */
68 } SortType;
69
70 SortType sort_output = SORT_TYPE_NAME;
71
72 #ifdef G_OS_UNIX
73 static const gchar DEFAULT_PAGER[] = "less";
74 GPid child_pid = -1;
75 #endif
76 GMainLoop *loop = NULL;
77
78 /* Console colors */
79
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"
90
91 /* General colors */
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: "")
100
101 /* Datatype-related colors */
102 #define DATATYPE_COLOR        (colored_output? GREEN : "")
103 #define CHILD_LINK_COLOR      (colored_output? BRMAGENTA : "")
104
105 /* Caps colors */
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 : "")
111
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: "")
118
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 : "")
124
125 #define GST_DOC_BASE_URL "https://gstreamer.freedesktop.org/documentation"
126
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
131 };
132
133 static char *_name = NULL;
134 static int indent = 0;
135
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);
141
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)
145
146 static void
147 push_indent_n (int n)
148 {
149   g_assert (n > 0 || indent > 0);
150   indent += n;
151 }
152
153 /* *INDENT-OFF* */
154 G_GNUC_PRINTF (1, 2)
155 /* *INDENT-ON* */
156
157 static void
158 n_print (const char *format, ...)
159 {
160   va_list args;
161   int i;
162   gchar *str;
163
164   if (_name)
165     g_print ("%s", _name);
166
167   for (i = 0; i < indent; ++i)
168     g_print ("  ");
169
170   va_start (args, format);
171   str = gst_info_strdup_vprintf (format, args);
172   va_end (args);
173
174   if (!str)
175     return;
176
177   g_print ("%s", str);
178   g_free (str);
179 }
180
181 static gboolean
182 print_field (GQuark field, const GValue * value, gpointer pfx)
183 {
184   gchar *str = gst_value_serialize (value);
185
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);
189   g_free (str);
190   return TRUE;
191 }
192
193 static void
194 print_caps (const GstCaps * caps, const gchar * pfx)
195 {
196   guint i;
197
198   g_return_if_fail (caps != NULL);
199
200   if (gst_caps_is_any (caps)) {
201     n_print ("%s%sANY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
202     return;
203   }
204   if (gst_caps_is_empty (caps)) {
205     n_print ("%s%sEMPTY%s\n", CAPS_TYPE_COLOR, pfx, RESET_COLOR);
206     return;
207   }
208
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);
212
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);
217
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);
222     } else {
223       n_print ("%s%s%s%s\n", pfx, STRUCT_NAME_COLOR,
224           gst_structure_get_name (structure), RESET_COLOR);
225     }
226     gst_structure_foreach (structure, print_field, (gpointer) pfx);
227   }
228 }
229
230 static const char *
231 get_rank_name (char *s, gint rank)
232 {
233   static const int ranks[4] = {
234     GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
235   };
236   static const char *rank_names[4] = { "none", "marginal", "secondary",
237     "primary"
238   };
239   int i;
240   int best_i;
241
242   best_i = 0;
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])) {
247       best_i = i;
248     }
249   }
250
251   sprintf (s, "%s %c %d", rank_names[best_i],
252       (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
253
254   return s;
255 }
256
257 static void
258 print_factory_details_info (GstElementFactory * factory, GstPlugin * plugin)
259 {
260   gchar **keys, **k;
261   gboolean seen_doc_uri = FALSE;
262   GstRank rank;
263   char s[40];
264
265   rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
266   n_print ("%sFactory Details:%s\n", HEADING_COLOR, RESET_COLOR);
267
268   push_indent ();
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);
271
272   keys = gst_element_factory_get_metadata_keys (factory);
273   if (keys != NULL) {
274     for (k = keys; *k != NULL; ++k) {
275       const gchar *val;
276       gchar *key = *k;
277
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,
281           RESET_COLOR);
282       seen_doc_uri =
283           seen_doc_uri || g_str_equal (key, GST_ELEMENT_METADATA_DOC_URI);
284     }
285     g_strfreev (keys);
286   }
287
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);
292
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"))) {
296       GList *features;
297
298       features =
299           gst_registry_get_feature_list_by_plugin (gst_registry_get (),
300           gst_plugin_get_name (plugin));
301
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),
307             RESET_COLOR);
308       } else {
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),
312             RESET_COLOR);
313       }
314       gst_plugin_feature_list_free (features);
315     }
316   }
317
318   pop_indent ();
319   n_print ("\n");
320 }
321
322 static void
323 print_hierarchy (GType type, gint level, gint * maxlevel)
324 {
325   GType parent;
326   gint i;
327
328   parent = g_type_parent (type);
329
330   *maxlevel = *maxlevel + 1;
331   level++;
332
333   if (parent)
334     print_hierarchy (parent, level, maxlevel);
335
336   if (_name)
337     g_print ("%s%s%s", DATATYPE_COLOR, _name, RESET_COLOR);
338
339   for (i = 1; i < *maxlevel - level; i++)
340     g_print ("      ");
341   if (*maxlevel - level)
342     g_print (" %s+----%s", CHILD_LINK_COLOR, RESET_COLOR);
343
344   g_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (type), RESET_COLOR);
345
346   if (level == 1)
347     n_print ("\n");
348 }
349
350 static void
351 print_interfaces (GType type)
352 {
353   guint n_ifaces;
354   GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
355
356   if (ifaces) {
357     if (n_ifaces) {
358       n_print (_("%sImplemented Interfaces%s:\n"), HEADING_COLOR, RESET_COLOR);
359       push_indent ();
360       iface = ifaces;
361       while (*iface) {
362         n_print ("%s%s%s\n", DATATYPE_COLOR, g_type_name (*iface), RESET_COLOR);
363         iface++;
364       }
365       pop_indent ();
366       n_print ("\n");
367     }
368     g_free (ifaces);
369   }
370 }
371
372 static gchar *
373 flags_to_string (GFlagsValue * vals, guint flags)
374 {
375   GString *s = NULL;
376   guint flags_left, i;
377
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);
382   }
383
384   s = g_string_new (NULL);
385
386   /* we assume the values are sorted from lowest to highest value */
387   flags_left = flags;
388   while (i > 0) {
389     --i;
390     if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
391       if (s->len > 0)
392         g_string_append_c (s, '+');
393       g_string_append (s, vals[i].value_nick);
394       flags_left -= vals[i].value;
395       if (flags_left == 0)
396         break;
397     }
398   }
399
400   if (s->len == 0)
401     g_string_assign (s, "(none)");
402
403   return g_string_free (s, FALSE);
404 }
405
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)
413
414 static int
415 sort_gparamspecs (GParamSpec ** a, GParamSpec ** b)
416 {
417   return g_strcmp0 (g_param_spec_get_name (*a), g_param_spec_get_name (*b));
418 }
419
420 /* obj will be NULL if we're printing properties of pad template pads */
421 static void
422 print_object_properties_info (GObject * obj, GObjectClass * obj_class,
423     const gchar * desc)
424 {
425   GParamSpec **property_specs;
426   guint num_properties, i;
427   gboolean readable;
428   gboolean first_flag;
429
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);
433
434   n_print ("%s%s%s:\n", HEADING_COLOR, desc, RESET_COLOR);
435   n_print ("\n");
436
437   push_indent ();
438
439   for (i = 0; i < num_properties; i++) {
440     GValue value = { 0, };
441     GParamSpec *param = property_specs[i];
442     GType owner_type = param->owner_type;
443
444     /* We're printing pad properties */
445     if (obj == NULL && (owner_type == G_TYPE_OBJECT
446             || owner_type == GST_TYPE_OBJECT || owner_type == GST_TYPE_PAD))
447       continue;
448
449     g_value_init (&value, param->value_type);
450
451     n_print ("%s%-20s%s: %s%s%s\n", PROP_NAME_COLOR,
452         g_param_spec_get_name (param), RESET_COLOR, PROP_VALUE_COLOR,
453         g_param_spec_get_blurb (param), RESET_COLOR);
454
455     push_indent_n (11);
456
457     first_flag = TRUE;
458     n_print ("%sflags%s: ", PROP_ATTR_NAME_COLOR, RESET_COLOR);
459     readable = ! !(param->flags & G_PARAM_READABLE);
460     if (readable && obj != NULL) {
461       g_object_get_property (obj, param->name, &value);
462     } else {
463       /* if we can't read the property value, assume it's set to the default
464        * (which might not be entirely true for sub-classes, but that's an
465        * unlikely corner-case anyway) */
466       g_param_value_set_default (param, &value);
467     }
468     if (readable) {
469       g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
470           _("readable"), RESET_COLOR);
471       first_flag = FALSE;
472     }
473     if (param->flags & G_PARAM_WRITABLE) {
474       g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
475           _("writable"), RESET_COLOR);
476       first_flag = FALSE;
477     }
478     if (param->flags & G_PARAM_DEPRECATED) {
479       g_print ("%s%s%s%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
480           _("deprecated"), RESET_COLOR);
481       first_flag = FALSE;
482     }
483     if (param->flags & GST_PARAM_CONTROLLABLE) {
484       g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("controllable"),
485           RESET_COLOR);
486       first_flag = FALSE;
487     }
488     if (param->flags & GST_PARAM_CONDITIONALLY_AVAILABLE) {
489       g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR, _("conditionally available"),
490           RESET_COLOR);
491       first_flag = FALSE;
492     }
493     if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
494       g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
495           _("changeable in NULL, READY, PAUSED or PLAYING state"), RESET_COLOR);
496     } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
497       g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
498           _("changeable only in NULL, READY or PAUSED state"), RESET_COLOR);
499     } else if (param->flags & GST_PARAM_MUTABLE_READY) {
500       g_print (", %s%s%s", PROP_ATTR_VALUE_COLOR,
501           _("changeable only in NULL or READY state"), RESET_COLOR);
502     }
503     if (param->flags & ~KNOWN_PARAM_FLAGS) {
504       g_print ("%s0x%s%0x%s", (first_flag) ? "" : ", ", PROP_ATTR_VALUE_COLOR,
505           param->flags & ~KNOWN_PARAM_FLAGS, RESET_COLOR);
506     }
507     g_print ("\n");
508
509     switch (G_VALUE_TYPE (&value)) {
510       case G_TYPE_STRING:
511       {
512         const char *string_val = g_value_get_string (&value);
513
514         n_print ("%sString%s. ", DATATYPE_COLOR, RESET_COLOR);
515
516         if (string_val == NULL)
517           g_print ("%sDefault%s: %snull%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
518               PROP_ATTR_VALUE_COLOR, RESET_COLOR);
519         else
520           g_print ("%sDefault%s: %s\"%s\"%s", PROP_ATTR_NAME_COLOR, RESET_COLOR,
521               PROP_ATTR_VALUE_COLOR, string_val, RESET_COLOR);
522         break;
523       }
524       case G_TYPE_BOOLEAN:
525       {
526         gboolean bool_val = g_value_get_boolean (&value);
527
528         n_print ("%sBoolean%s. %sDefault%s: %s%s%s", DATATYPE_COLOR,
529             RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
530             PROP_ATTR_VALUE_COLOR, bool_val ? "true" : "false", RESET_COLOR);
531         break;
532       }
533       case G_TYPE_ULONG:
534       {
535         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
536
537         n_print
538             ("%sUnsigned Long%s. %sRange%s: %s%lu - %lu%s %sDefault%s: %s%lu%s ",
539             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
540             PROP_ATTR_VALUE_COLOR, pulong->minimum, pulong->maximum,
541             RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
542             PROP_ATTR_VALUE_COLOR, g_value_get_ulong (&value), RESET_COLOR);
543
544         GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
545             "uint/uint64", G_OBJECT_CLASS_NAME (obj_class),
546             g_param_spec_get_name (param));
547         break;
548       }
549       case G_TYPE_LONG:
550       {
551         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
552
553         n_print ("%sLong%s. %sRange%s: %s%ld - %ld%s %sDefault%s: %s%ld%s ",
554             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
555             PROP_ATTR_VALUE_COLOR, plong->minimum, plong->maximum, RESET_COLOR,
556             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
557             g_value_get_long (&value), RESET_COLOR);
558
559         GST_ERROR ("%s: property '%s' of type long: consider changing to "
560             "int/int64", G_OBJECT_CLASS_NAME (obj_class),
561             g_param_spec_get_name (param));
562         break;
563       }
564       case G_TYPE_UINT:
565       {
566         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
567
568         n_print
569             ("%sUnsigned Integer%s. %sRange%s: %s%u - %u%s %sDefault%s: %s%u%s ",
570             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
571             PROP_ATTR_VALUE_COLOR, puint->minimum, puint->maximum, RESET_COLOR,
572             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
573             g_value_get_uint (&value), RESET_COLOR);
574         break;
575       }
576       case G_TYPE_INT:
577       {
578         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
579
580         n_print ("%sInteger%s. %sRange%s: %s%d - %d%s %sDefault%s: %s%d%s ",
581             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
582             PROP_ATTR_VALUE_COLOR, pint->minimum, pint->maximum, RESET_COLOR,
583             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
584             g_value_get_int (&value), RESET_COLOR);
585         break;
586       }
587       case G_TYPE_UINT64:
588       {
589         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
590
591         n_print ("%sUnsigned Integer64%s. %sRange%s: %s%" G_GUINT64_FORMAT " - "
592             "%" G_GUINT64_FORMAT "%s %sDefault%s: %s%" G_GUINT64_FORMAT "%s ",
593             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
594             PROP_ATTR_VALUE_COLOR, puint64->minimum, puint64->maximum,
595             RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
596             PROP_ATTR_VALUE_COLOR, g_value_get_uint64 (&value), RESET_COLOR);
597         break;
598       }
599       case G_TYPE_INT64:
600       {
601         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
602
603         n_print ("%sInteger64%s. %sRange%s: %s%" G_GINT64_FORMAT " - %"
604             G_GINT64_FORMAT "%s %sDefault%s: %s%" G_GINT64_FORMAT "%s ",
605             DATATYPE_COLOR, RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
606             PROP_ATTR_VALUE_COLOR, pint64->minimum, pint64->maximum,
607             RESET_COLOR, PROP_ATTR_NAME_COLOR, RESET_COLOR,
608             PROP_ATTR_VALUE_COLOR, g_value_get_int64 (&value), RESET_COLOR);
609         break;
610       }
611       case G_TYPE_FLOAT:
612       {
613         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
614
615         n_print ("%sFloat%s. %sRange%s: %s%15.7g - %15.7g%s "
616             "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
617             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
618             pfloat->minimum, pfloat->maximum, RESET_COLOR, PROP_ATTR_NAME_COLOR,
619             RESET_COLOR, PROP_ATTR_VALUE_COLOR, g_value_get_float (&value),
620             RESET_COLOR);
621         break;
622       }
623       case G_TYPE_DOUBLE:
624       {
625         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
626
627         n_print ("%sDouble%s. %sRange%s: %s%15.7g - %15.7g%s "
628             "%sDefault%s: %s%15.7g%s ", DATATYPE_COLOR, RESET_COLOR,
629             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
630             pdouble->minimum, pdouble->maximum, RESET_COLOR,
631             PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
632             g_value_get_double (&value), RESET_COLOR);
633         break;
634       }
635       case G_TYPE_CHAR:
636       case G_TYPE_UCHAR:
637         GST_ERROR ("%s: property '%s' of type char: consider changing to "
638             "int/string", G_OBJECT_CLASS_NAME (obj_class),
639             g_param_spec_get_name (param));
640         /* fall through */
641       default:
642         if (param->value_type == GST_TYPE_CAPS) {
643           const GstCaps *caps = gst_value_get_caps (&value);
644
645           if (!caps)
646             n_print ("%sCaps%s (NULL)", DATATYPE_COLOR, RESET_COLOR);
647           else {
648             print_caps (caps, "                           ");
649           }
650         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
651           GEnumValue *values;
652           guint j = 0;
653           gint enum_value;
654           const gchar *value_nick = "";
655
656           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
657           enum_value = g_value_get_enum (&value);
658
659           while (values[j].value_name) {
660             if (values[j].value == enum_value)
661               value_nick = values[j].value_nick;
662             j++;
663           }
664
665           n_print ("%sEnum \"%s\"%s %sDefault%s: %s%d, \"%s\"%s",
666               DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
667               PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
668               enum_value, value_nick, RESET_COLOR);
669
670           j = 0;
671           while (values[j].value_name) {
672             g_print ("\n");
673             n_print ("   %s(%d)%s: %s%-16s%s - %s%s%s",
674                 PROP_ATTR_NAME_COLOR, values[j].value, RESET_COLOR,
675                 PROP_ATTR_VALUE_COLOR, values[j].value_nick, RESET_COLOR,
676                 DESC_COLOR, values[j].value_name, RESET_COLOR);
677             j++;
678           }
679           /* g_type_class_unref (ec); */
680         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
681           GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
682           GFlagsValue *vals;
683           gchar *cur;
684
685           vals = pflags->flags_class->values;
686
687           cur = flags_to_string (vals, g_value_get_flags (&value));
688
689           n_print ("%sFlags \"%s\"%s %sDefault%s: %s0x%08x, \"%s\"%s",
690               DATATYPE_COLOR, g_type_name (G_VALUE_TYPE (&value)), RESET_COLOR,
691               PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
692               g_value_get_flags (&value), cur, RESET_COLOR);
693
694           while (vals[0].value_name) {
695             g_print ("\n");
696             n_print ("   %s(0x%08x)%s: %s%-16s%s - %s%s%s",
697                 PROP_ATTR_NAME_COLOR, vals[0].value, RESET_COLOR,
698                 PROP_ATTR_VALUE_COLOR, vals[0].value_nick, RESET_COLOR,
699                 DESC_COLOR, vals[0].value_name, RESET_COLOR);
700             ++vals;
701           }
702
703           g_free (cur);
704         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
705           n_print ("%sObject of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
706               RESET_COLOR, DATATYPE_COLOR,
707               g_type_name (param->value_type), RESET_COLOR);
708         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
709           n_print ("%sBoxed pointer of type%s %s\"%s\"%s", PROP_VALUE_COLOR,
710               RESET_COLOR, DATATYPE_COLOR,
711               g_type_name (param->value_type), RESET_COLOR);
712           if (param->value_type == GST_TYPE_STRUCTURE) {
713             const GstStructure *s = gst_value_get_structure (&value);
714             if (s) {
715               g_print ("\n");
716               gst_structure_foreach (s, print_field,
717                   (gpointer) "                           ");
718             }
719           }
720         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
721           if (param->value_type != G_TYPE_POINTER) {
722             n_print ("%sPointer of type%s %s\"%s\"%s.", PROP_VALUE_COLOR,
723                 RESET_COLOR, DATATYPE_COLOR, g_type_name (param->value_type),
724                 RESET_COLOR);
725           } else {
726             n_print ("%sPointer.%s", PROP_VALUE_COLOR, RESET_COLOR);
727           }
728         } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
729           GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
730
731           if (pvarray->element_spec) {
732             n_print ("%sArray of GValues of type%s %s\"%s\"%s",
733                 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
734                 g_type_name (pvarray->element_spec->value_type), RESET_COLOR);
735           } else {
736             n_print ("%sArray of GValues%s", PROP_VALUE_COLOR, RESET_COLOR);
737           }
738         } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
739           GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
740
741           n_print ("%sFraction%s. %sRange%s: %s%d/%d - %d/%d%s "
742               "%sDefault%s: %s%d/%d%s ", DATATYPE_COLOR, RESET_COLOR,
743               PROP_ATTR_NAME_COLOR, RESET_COLOR, PROP_ATTR_VALUE_COLOR,
744               pfraction->min_num, pfraction->min_den, pfraction->max_num,
745               pfraction->max_den, RESET_COLOR, PROP_ATTR_NAME_COLOR,
746               RESET_COLOR, PROP_ATTR_VALUE_COLOR,
747               gst_value_get_fraction_numerator (&value),
748               gst_value_get_fraction_denominator (&value), RESET_COLOR);
749         } else if (param->value_type == GST_TYPE_ARRAY) {
750           GstParamSpecArray *parray = GST_PARAM_SPEC_ARRAY_LIST (param);
751
752           if (GST_VALUE_HOLDS_ARRAY (&value)) {
753             gchar *def = gst_value_serialize (&value);
754
755             n_print ("%sDefault%s: \"%s\"\n", PROP_ATTR_VALUE_COLOR,
756                 RESET_COLOR, def);
757
758             g_free (def);
759           }
760
761           if (parray->element_spec) {
762             n_print ("%sGstValueArray of GValues of type%s %s\"%s\"%s",
763                 PROP_VALUE_COLOR, RESET_COLOR, DATATYPE_COLOR,
764                 g_type_name (parray->element_spec->value_type), RESET_COLOR);
765           } else {
766             n_print ("%sGstValueArray of GValues%s", PROP_VALUE_COLOR,
767                 RESET_COLOR);
768           }
769         } else {
770           n_print ("%sUnknown type %ld%s %s\"%s\"%s", PROP_VALUE_COLOR,
771               (glong) param->value_type, RESET_COLOR, DATATYPE_COLOR,
772               g_type_name (param->value_type), RESET_COLOR);
773         }
774         break;
775     }
776     if (!readable)
777       g_print (" %sWrite only%s\n", PROP_VALUE_COLOR, RESET_COLOR);
778     else
779       g_print ("\n");
780
781     pop_indent_n (11);
782
783     g_value_reset (&value);
784
785     n_print ("\n");
786   }
787   if (num_properties == 0)
788     n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
789
790   pop_indent ();
791
792   g_free (property_specs);
793 }
794
795 static void
796 print_element_properties_info (GstElement * element)
797 {
798   g_print ("\n");
799   print_object_properties_info (G_OBJECT (element),
800       G_OBJECT_GET_CLASS (element), "Element Properties");
801 }
802
803 static gint
804 gst_static_pad_compare_func (gconstpointer p1, gconstpointer p2)
805 {
806   GstStaticPadTemplate *pt1, *pt2;
807
808   pt1 = (GstStaticPadTemplate *) p1;
809   pt2 = (GstStaticPadTemplate *) p2;
810
811   return strcmp (pt1->name_template, pt2->name_template);
812 }
813
814
815 static void
816 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
817 {
818   GList *pads, *tmp;
819   GstStaticPadTemplate *padtemplate;
820   GstPadTemplate *tmpl;
821
822   n_print ("%sPad Templates%s:\n", HEADING_COLOR, RESET_COLOR);
823
824   push_indent ();
825
826   if (gst_element_factory_get_num_pad_templates (factory) == 0) {
827     n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
828     goto done;
829   }
830
831   pads = g_list_copy ((GList *)
832       gst_element_factory_get_static_pad_templates (factory));
833   pads = g_list_sort (pads, gst_static_pad_compare_func);
834
835   for (tmp = pads; tmp; tmp = tmp->next) {
836     padtemplate = (GstStaticPadTemplate *) (tmp->data);
837
838     if (padtemplate->direction == GST_PAD_SRC)
839       n_print ("%sSRC template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
840           PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
841     else if (padtemplate->direction == GST_PAD_SINK)
842       n_print ("%sSINK template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
843           PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
844     else
845       n_print ("%sUNKNOWN template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
846           PROP_VALUE_COLOR, padtemplate->name_template, RESET_COLOR);
847
848     push_indent ();
849
850     if (padtemplate->presence == GST_PAD_ALWAYS)
851       n_print ("%sAvailability%s: %sAlways%s\n", PROP_NAME_COLOR, RESET_COLOR,
852           PROP_VALUE_COLOR, RESET_COLOR);
853     else if (padtemplate->presence == GST_PAD_SOMETIMES)
854       n_print ("%sAvailability%s: %sSometimes%s\n", PROP_NAME_COLOR,
855           RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
856     else if (padtemplate->presence == GST_PAD_REQUEST) {
857       n_print ("%sAvailability%s: %sOn request%s\n", PROP_NAME_COLOR,
858           RESET_COLOR, PROP_VALUE_COLOR, RESET_COLOR);
859     } else
860       n_print ("%sAvailability%s: %sUNKNOWN%s\n", PROP_NAME_COLOR, RESET_COLOR,
861           PROP_VALUE_COLOR, RESET_COLOR);
862
863     if (padtemplate->static_caps.string) {
864       GstCaps *caps = gst_static_caps_get (&padtemplate->static_caps);
865
866       n_print ("%sCapabilities%s:\n", PROP_NAME_COLOR, RESET_COLOR);
867
868       push_indent ();
869       print_caps (caps, "");    // FIXME
870       pop_indent ();
871
872       gst_caps_unref (caps);
873     }
874
875     tmpl = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (element),
876         padtemplate->name_template);
877     if (tmpl != NULL) {
878       GType pad_type = GST_PAD_TEMPLATE_GTYPE (tmpl);
879
880       if (pad_type != G_TYPE_NONE && pad_type != GST_TYPE_PAD) {
881         gpointer pad_klass;
882
883         pad_klass = g_type_class_ref (pad_type);
884         n_print ("%sType%s: %s%s%s\n", PROP_NAME_COLOR, RESET_COLOR,
885             DATATYPE_COLOR, g_type_name (pad_type), RESET_COLOR);
886         print_object_properties_info (NULL, pad_klass, "Pad Properties");
887         g_type_class_unref (pad_klass);
888       }
889     }
890
891     pop_indent ();
892
893     if (tmp->next)
894       n_print ("\n");
895   }
896   g_list_free (pads);
897 done:
898   pop_indent ();
899 }
900
901 static void
902 print_clocking_info (GstElement * element)
903 {
904   gboolean requires_clock, provides_clock;
905
906   requires_clock =
907       GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
908   provides_clock =
909       GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
910
911   if (!requires_clock && !provides_clock) {
912     n_print ("\n");
913     n_print ("%sElement has no clocking capabilities.%s\n", DESC_COLOR,
914         RESET_COLOR);
915     return;
916   }
917
918   n_print ("\n");
919   n_print ("%sClocking Interaction%s:\n", PROP_NAME_COLOR, RESET_COLOR);
920
921   push_indent ();
922
923   if (requires_clock) {
924     n_print ("%selement requires a clock%s\n", PROP_VALUE_COLOR, RESET_COLOR);
925   }
926
927   if (provides_clock) {
928     GstClock *clock;
929
930     clock = gst_element_get_clock (element);
931     if (clock) {
932       n_print ("%selement provides a clock%s: %s%s%s\n", PROP_VALUE_COLOR,
933           RESET_COLOR, DATATYPE_COLOR, GST_OBJECT_NAME (clock), RESET_COLOR);
934       gst_object_unref (clock);
935     } else
936       n_print ("%selement is supposed to provide a clock but returned NULL%s\n",
937           PROP_VALUE_COLOR, RESET_COLOR);
938   }
939
940   pop_indent ();
941 }
942
943 static void
944 print_uri_handler_info (GstElement * element)
945 {
946   if (GST_IS_URI_HANDLER (element)) {
947     const gchar *const *uri_protocols;
948     const gchar *uri_type;
949
950     if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
951       uri_type = "source";
952     else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
953         GST_URI_SINK)
954       uri_type = "sink";
955     else
956       uri_type = "unknown";
957
958     uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
959
960     n_print ("\n");
961     n_print ("%sURI handling capabilities:%s\n", HEADING_COLOR, RESET_COLOR);
962
963     push_indent ();
964
965     n_print ("%sElement can act as %s.%s\n", DESC_COLOR, uri_type, RESET_COLOR);
966
967     if (uri_protocols && *uri_protocols) {
968       n_print ("%sSupported URI protocols%s:\n", DESC_COLOR, RESET_COLOR);
969       push_indent ();
970       for (; *uri_protocols != NULL; uri_protocols++)
971         n_print ("%s%s%s\n", PROP_ATTR_VALUE_COLOR, *uri_protocols,
972             RESET_COLOR);
973       pop_indent ();
974     } else {
975       n_print ("%sNo supported URI protocols%s\n", PROP_VALUE_COLOR,
976           RESET_COLOR);
977     }
978
979     pop_indent ();
980   } else {
981     n_print ("%sElement has no URI handling capabilities.%s\n", DESC_COLOR,
982         RESET_COLOR);
983   }
984 }
985
986 static void
987 print_pad_info (GstElement * element)
988 {
989   const GList *pads;
990   GstPad *pad;
991
992   n_print ("\n");
993   n_print ("%sPads:%s\n", HEADING_COLOR, RESET_COLOR);
994
995   push_indent ();
996
997   if (!element->numpads) {
998     n_print ("%snone%s\n", PROP_VALUE_COLOR, RESET_COLOR);
999     goto done;
1000   }
1001
1002   pads = element->pads;
1003   while (pads) {
1004     gchar *name;
1005     GstCaps *caps;
1006
1007     pad = GST_PAD (pads->data);
1008     pads = g_list_next (pads);
1009
1010     name = gst_pad_get_name (pad);
1011     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
1012       n_print ("%sSRC%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1013           PROP_VALUE_COLOR, name, RESET_COLOR);
1014     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
1015       n_print ("%sSINK%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1016           PROP_VALUE_COLOR, name, RESET_COLOR);
1017     else
1018       n_print ("%sUNKNOWN%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1019           PROP_VALUE_COLOR, name, RESET_COLOR);
1020
1021     g_free (name);
1022
1023     if (pad->padtemplate) {
1024       push_indent ();
1025       n_print ("%sPad Template%s: %s'%s'%s\n", PROP_NAME_COLOR, RESET_COLOR,
1026           PROP_VALUE_COLOR, pad->padtemplate->name_template, RESET_COLOR);
1027       pop_indent ();
1028     }
1029
1030     caps = gst_pad_get_current_caps (pad);
1031     if (caps) {
1032       n_print ("%sCapabilities:%s\n", PROP_NAME_COLOR, RESET_COLOR);
1033       push_indent ();
1034       print_caps (caps, "");    // FIXME
1035       pop_indent ();
1036       gst_caps_unref (caps);
1037     }
1038   }
1039
1040 done:
1041   pop_indent ();
1042 }
1043
1044 static gboolean
1045 has_sometimes_template (GstElement * element)
1046 {
1047   GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
1048   GList *l;
1049
1050   for (l = klass->padtemplates; l != NULL; l = l->next) {
1051     if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
1052       return TRUE;
1053   }
1054
1055   return FALSE;
1056 }
1057
1058 static gboolean
1059 gtype_needs_ptr_marker (GType type)
1060 {
1061   if (type == G_TYPE_POINTER)
1062     return FALSE;
1063
1064   if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_POINTER || G_TYPE_IS_BOXED (type)
1065       || G_TYPE_IS_OBJECT (type))
1066     return TRUE;
1067
1068   return FALSE;
1069 }
1070
1071 static void
1072 print_signal_info (GstElement * element)
1073 {
1074   /* Signals/Actions Block */
1075   guint *signals;
1076   guint nsignals;
1077   gint i = 0, j, k;
1078   GSignalQuery *query = NULL;
1079   GType type;
1080   GSList *found_signals, *l;
1081
1082   for (k = 0; k < 2; k++) {
1083     found_signals = NULL;
1084
1085     /* For elements that have sometimes pads, also list a few useful GstElement
1086      * signals. Put these first, so element-specific ones come later. */
1087     if (k == 0 && has_sometimes_template (element)) {
1088       query = g_new0 (GSignalQuery, 1);
1089       g_signal_query (g_signal_lookup ("pad-added", 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 ("pad-removed", GST_TYPE_ELEMENT), query);
1093       found_signals = g_slist_append (found_signals, query);
1094       query = g_new0 (GSignalQuery, 1);
1095       g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
1096           query);
1097       found_signals = g_slist_append (found_signals, query);
1098     }
1099
1100     for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
1101       if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
1102         break;
1103
1104       if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
1105         continue;
1106
1107       signals = g_signal_list_ids (type, &nsignals);
1108       for (i = 0; i < nsignals; i++) {
1109         query = g_new0 (GSignalQuery, 1);
1110         g_signal_query (signals[i], query);
1111
1112         if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
1113             (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
1114           found_signals = g_slist_append (found_signals, query);
1115         else
1116           g_free (query);
1117       }
1118       g_free (signals);
1119       signals = NULL;
1120     }
1121
1122     if (found_signals) {
1123       n_print ("\n");
1124       if (k == 0)
1125         n_print ("%sElement Signals%s:\n", HEADING_COLOR, RESET_COLOR);
1126       else
1127         n_print ("%sElement Actions%s:\n", HEADING_COLOR, RESET_COLOR);
1128       n_print ("\n");
1129     } else {
1130       continue;
1131     }
1132
1133     for (l = found_signals; l; l = l->next) {
1134       gchar *indent;
1135       const gchar *pmark;
1136       int indent_len;
1137
1138       query = (GSignalQuery *) l->data;
1139       indent_len = strlen (query->signal_name) +
1140           strlen (g_type_name (query->return_type)) + 24;
1141
1142       if (gtype_needs_ptr_marker (query->return_type)) {
1143         pmark = "* ";
1144         indent_len += 2;
1145       } else {
1146         pmark = " ";
1147       }
1148
1149       indent = g_new0 (gchar, indent_len + 1);
1150       memset (indent, ' ', indent_len);
1151
1152       n_print ("  %s\"%s\"%s :  %s%s%s%suser_function%s (%s%s%s* object%s",
1153           PROP_NAME_COLOR, query->signal_name, RESET_COLOR,
1154           DATATYPE_COLOR, g_type_name (query->return_type), PROP_VALUE_COLOR,
1155           pmark, RESET_COLOR, DATATYPE_COLOR, g_type_name (type),
1156           PROP_VALUE_COLOR, RESET_COLOR);
1157
1158       for (j = 0; j < query->n_params; j++) {
1159         const gchar *type_name, *asterisk;
1160
1161         type_name = g_type_name (query->param_types[j]);
1162         asterisk = gtype_needs_ptr_marker (query->param_types[j]) ? "*" : "";
1163
1164         g_print (",\n");
1165         n_print ("%s%s%s%s%s arg%d%s", indent, DATATYPE_COLOR, type_name,
1166             PROP_VALUE_COLOR, asterisk, j, RESET_COLOR);
1167       }
1168
1169       if (k == 0) {
1170         g_print (",\n");
1171         n_print ("%s%sgpointer %suser_data%s);\n", indent, DATATYPE_COLOR,
1172             PROP_VALUE_COLOR, RESET_COLOR);
1173       } else
1174         g_print (");\n");
1175
1176       g_free (indent);
1177       g_print ("\n");
1178     }
1179
1180     if (found_signals) {
1181       g_slist_foreach (found_signals, (GFunc) g_free, NULL);
1182       g_slist_free (found_signals);
1183     }
1184   }
1185 }
1186
1187 static void
1188 print_children_info (GstElement * element)
1189 {
1190   GList *children;
1191
1192   if (!GST_IS_BIN (element))
1193     return;
1194
1195   children = (GList *) GST_BIN (element)->children;
1196   if (children) {
1197     n_print ("\n");
1198     n_print ("%sChildren%s:\n", HEADING_COLOR, RESET_COLOR);
1199   }
1200
1201   while (children) {
1202     n_print ("  %s%s%s\n", DATATYPE_COLOR,
1203         GST_ELEMENT_NAME (GST_ELEMENT (children->data)), RESET_COLOR);
1204     children = g_list_next (children);
1205   }
1206 }
1207
1208 static void
1209 print_preset_list (GstElement * element)
1210 {
1211   gchar **presets, **preset;
1212
1213   if (!GST_IS_PRESET (element))
1214     return;
1215
1216   presets = gst_preset_get_preset_names (GST_PRESET (element));
1217   if (presets && *presets) {
1218     n_print ("\n");
1219     n_print ("%sPresets%s:\n", HEADING_COLOR, RESET_COLOR);
1220     for (preset = presets; *preset; preset++) {
1221       gchar *comment = NULL;
1222       n_print ("  \"%s\"", *preset);
1223
1224       if (gst_preset_get_meta (GST_PRESET (element), *preset, "comment",
1225               &comment) && comment)
1226         g_print (": %s", comment);
1227       g_free (comment);
1228       g_print ("\n");
1229     }
1230     g_strfreev (presets);
1231   }
1232 }
1233
1234 static gint
1235 gst_plugin_name_compare_func (gconstpointer p1, gconstpointer p2)
1236 {
1237   return strcmp (gst_plugin_get_name ((GstPlugin *) p1),
1238       gst_plugin_get_name ((GstPlugin *) p2));
1239 }
1240
1241 static gint
1242 gst_plugin_feature_name_compare_func (gconstpointer p1, gconstpointer p2)
1243 {
1244   return strcmp (GST_OBJECT_NAME (p1), GST_OBJECT_NAME (p2));
1245 }
1246
1247 static void
1248 print_blacklist (void)
1249 {
1250   GList *plugins, *cur;
1251   gint count = 0;
1252
1253   g_print ("%s%s%s\n", HEADING_COLOR, _("Blacklisted files:"), RESET_COLOR);
1254
1255   plugins = gst_registry_get_plugin_list (gst_registry_get ());
1256   if (sort_output == SORT_TYPE_NAME)
1257     plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1258
1259   for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
1260     GstPlugin *plugin = (GstPlugin *) (cur->data);
1261     if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1262       g_print ("  %s\n", gst_plugin_get_name (plugin));
1263       count++;
1264     }
1265   }
1266
1267   g_print ("\n");
1268   g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1269       PROP_VALUE_COLOR);
1270   g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
1271       count);
1272   g_print ("%s\n", RESET_COLOR);
1273   gst_plugin_list_free (plugins);
1274 }
1275
1276 static void
1277 print_typefind_extensions (const gchar * const *extensions, const gchar * color)
1278 {
1279   guint i = 0;
1280
1281   while (extensions[i]) {
1282     g_print ("%s%s%s%s", i > 0 ? ", " : "", color, extensions[i], RESET_COLOR);
1283     i++;
1284   }
1285 }
1286
1287 static void
1288 print_element_list (gboolean print_all, gchar * ftypes)
1289 {
1290   int plugincount = 0, featurecount = 0, blacklistcount = 0;
1291   GList *plugins, *orig_plugins;
1292   gchar **types = NULL;
1293
1294   if (ftypes) {
1295     gint i;
1296
1297     types = g_strsplit (ftypes, "/", -1);
1298     for (i = 0; types[i]; i++)
1299       *types[i] = g_ascii_toupper (*types[i]);
1300
1301   }
1302
1303   orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1304   if (sort_output == SORT_TYPE_NAME)
1305     plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1306   while (plugins) {
1307     GList *features, *orig_features;
1308     GstPlugin *plugin;
1309
1310     plugin = (GstPlugin *) (plugins->data);
1311     plugins = g_list_next (plugins);
1312     plugincount++;
1313
1314     if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1315       blacklistcount++;
1316       continue;
1317     }
1318
1319     orig_features = features =
1320         gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1321         gst_plugin_get_name (plugin));
1322     if (sort_output == SORT_TYPE_NAME)
1323       features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1324     while (features) {
1325       GstPluginFeature *feature;
1326
1327       if (G_UNLIKELY (features->data == NULL))
1328         goto next;
1329       feature = GST_PLUGIN_FEATURE (features->data);
1330       featurecount++;
1331
1332       if (GST_IS_ELEMENT_FACTORY (feature)) {
1333         const gchar *klass;
1334         GstElementFactory *factory;
1335
1336         factory = GST_ELEMENT_FACTORY (feature);
1337         if (types) {
1338           gint i;
1339           gboolean all_found = TRUE;
1340
1341           klass =
1342               gst_element_factory_get_metadata (factory,
1343               GST_ELEMENT_METADATA_KLASS);
1344           for (i = 0; types[i]; i++) {
1345             if (!strstr (klass, types[i])) {
1346               all_found = FALSE;
1347               break;
1348             }
1349           }
1350
1351           if (!all_found)
1352             goto next;
1353         }
1354         if (print_all)
1355           print_element_info (feature, TRUE);
1356         else
1357           g_print ("%s%s%s:  %s%s%s: %s%s%s\n", PLUGIN_NAME_COLOR,
1358               gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1359               GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1360               gst_element_factory_get_metadata (factory,
1361                   GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1362       } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1363         GstTypeFindFactory *factory;
1364         const gchar *const *extensions;
1365
1366         if (types)
1367           goto next;
1368         factory = GST_TYPE_FIND_FACTORY (feature);
1369         if (!print_all)
1370           g_print ("%s%s%s: %s%s%s: ", PLUGIN_NAME_COLOR,
1371               gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1372               gst_plugin_feature_get_name (feature), RESET_COLOR);
1373
1374         extensions = gst_type_find_factory_get_extensions (factory);
1375         if (extensions != NULL) {
1376           if (!print_all) {
1377             print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1378             g_print ("\n");
1379           }
1380         } else {
1381           if (!print_all)
1382             g_print ("%sno extensions%s\n", ELEMENT_DETAIL_COLOR, RESET_COLOR);
1383         }
1384       } else {
1385         if (types)
1386           goto next;
1387         if (!print_all)
1388           n_print ("%s%s%s:  %s%s%s (%s%s%s)\n", PLUGIN_NAME_COLOR,
1389               gst_plugin_get_name (plugin), RESET_COLOR, ELEMENT_NAME_COLOR,
1390               GST_OBJECT_NAME (feature), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1391               g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1392       }
1393
1394     next:
1395       features = g_list_next (features);
1396     }
1397
1398     gst_plugin_feature_list_free (orig_features);
1399   }
1400
1401   gst_plugin_list_free (orig_plugins);
1402   g_strfreev (types);
1403
1404   g_print ("\n");
1405   g_print (_("%sTotal count%s: %s"), PROP_NAME_COLOR, RESET_COLOR,
1406       PROP_VALUE_COLOR);
1407   g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1408   if (blacklistcount) {
1409     g_print (" (");
1410     g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1411             blacklistcount), blacklistcount);
1412     g_print (" not shown)");
1413   }
1414   g_print ("%s, %s", RESET_COLOR, PROP_VALUE_COLOR);
1415   g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1416   g_print ("%s\n", RESET_COLOR);
1417 }
1418
1419 static void
1420 print_all_uri_handlers (void)
1421 {
1422   GList *plugins, *p, *features, *f;
1423
1424   plugins = gst_registry_get_plugin_list (gst_registry_get ());
1425   if (sort_output == SORT_TYPE_NAME)
1426     plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
1427   for (p = plugins; p; p = p->next) {
1428     GstPlugin *plugin = (GstPlugin *) (p->data);
1429
1430     features =
1431         gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1432         gst_plugin_get_name (plugin));
1433     if (sort_output == SORT_TYPE_NAME)
1434       features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1435     for (f = features; f; f = f->next) {
1436       GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1437
1438       if (GST_IS_ELEMENT_FACTORY (feature)) {
1439         GstElementFactory *factory;
1440         GstElement *element;
1441
1442         factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1443         if (!factory) {
1444           g_print ("element plugin %s couldn't be loaded\n",
1445               gst_plugin_get_name (plugin));
1446           continue;
1447         }
1448
1449         element = gst_element_factory_create (factory, NULL);
1450         if (!element) {
1451           g_print ("couldn't construct element for %s for some reason\n",
1452               GST_OBJECT_NAME (factory));
1453           gst_object_unref (factory);
1454           continue;
1455         }
1456
1457         if (GST_IS_URI_HANDLER (element)) {
1458           const gchar *const *uri_protocols;
1459           const gchar *const *protocol;
1460           const gchar *dir;
1461
1462           switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1463             case GST_URI_SRC:
1464               dir = "read";
1465               break;
1466             case GST_URI_SINK:
1467               dir = "write";
1468               break;
1469             default:
1470               dir = "unknown";
1471               break;
1472           }
1473
1474           g_print ("%s%s%s (%s%s%s, %srank %u%s): ",
1475               FEATURE_NAME_COLOR,
1476               gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)),
1477               RESET_COLOR, FEATURE_DIR_COLOR, dir, RESET_COLOR,
1478               FEATURE_RANK_COLOR,
1479               gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1480               RESET_COLOR);
1481
1482           uri_protocols =
1483               gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1484           for (protocol = uri_protocols; *protocol != NULL; protocol++) {
1485             if (protocol != uri_protocols)
1486               g_print (", ");
1487             g_print ("%s%s%s", FEATURE_PROTO_COLOR, *protocol, RESET_COLOR);
1488           }
1489           g_print ("\n");
1490         }
1491
1492         gst_object_unref (element);
1493         gst_object_unref (factory);
1494       }
1495     }
1496
1497     gst_plugin_feature_list_free (features);
1498   }
1499
1500   gst_plugin_list_free (plugins);
1501 }
1502
1503 static void
1504 print_plugin_info (GstPlugin * plugin)
1505 {
1506   const gchar *plugin_name = gst_plugin_get_name (plugin);
1507   const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1508   const gchar *filename = gst_plugin_get_filename (plugin);
1509   const gchar *module = gst_plugin_get_source (plugin);
1510   const gchar *origin = gst_plugin_get_origin (plugin);
1511
1512   n_print ("%sPlugin Details%s:\n", HEADING_COLOR, RESET_COLOR);
1513
1514   push_indent ();
1515
1516   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Name", RESET_COLOR,
1517       PROP_VALUE_COLOR, plugin_name, RESET_COLOR);
1518   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Description", RESET_COLOR,
1519       PROP_VALUE_COLOR, gst_plugin_get_description (plugin), RESET_COLOR);
1520   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Filename", RESET_COLOR,
1521       PROP_VALUE_COLOR, (filename != NULL) ? filename : "(null)", RESET_COLOR);
1522   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Version", RESET_COLOR,
1523       PROP_VALUE_COLOR, gst_plugin_get_version (plugin), RESET_COLOR);
1524   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "License", RESET_COLOR,
1525       PROP_VALUE_COLOR, gst_plugin_get_license (plugin), RESET_COLOR);
1526   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Source module", RESET_COLOR,
1527       PROP_VALUE_COLOR, module, RESET_COLOR);
1528
1529   /* gst-plugins-rs has per-plugin module names so need to check origin there */
1530   if (g_strv_contains (gstreamer_modules, module)
1531       || (origin != NULL && g_str_has_suffix (origin, "/gst-plugins-rs"))) {
1532     n_print ("%s%-25s%s%s%s/%s/%s\n", PROP_NAME_COLOR, "Documentation",
1533         RESET_COLOR, PROP_VALUE_COLOR, GST_DOC_BASE_URL, plugin_name,
1534         RESET_COLOR);
1535   }
1536
1537   if (release_date != NULL) {
1538     const gchar *tz = "(UTC)";
1539     gchar *str, *sep;
1540
1541 /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1542 /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1543     str = g_strdup (release_date);
1544     sep = strstr (str, "T");
1545     if (sep != NULL) {
1546       *sep = ' ';
1547       sep = strstr (sep + 1, "Z");
1548       if (sep != NULL)
1549         *sep = ' ';
1550     } else {
1551       tz = "";
1552     }
1553     n_print ("%s%-25s%s%s%s%s%s\n", PROP_NAME_COLOR, "Source release date",
1554         RESET_COLOR, PROP_VALUE_COLOR, str, tz, RESET_COLOR);
1555     g_free (str);
1556   }
1557   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Binary package", RESET_COLOR,
1558       PROP_VALUE_COLOR, gst_plugin_get_package (plugin), RESET_COLOR);
1559   n_print ("%s%-25s%s%s%s%s\n", PROP_NAME_COLOR, "Origin URL", RESET_COLOR,
1560       PROP_VALUE_COLOR, gst_plugin_get_origin (plugin), RESET_COLOR);
1561
1562   pop_indent ();
1563
1564   n_print ("\n");
1565 }
1566
1567 static void
1568 print_plugin_features (GstPlugin * plugin)
1569 {
1570   GList *features, *origlist;
1571   gint num_features = 0;
1572   gint num_elements = 0;
1573   gint num_tracers = 0;
1574   gint num_typefinders = 0;
1575   gint num_devproviders = 0;
1576   gint num_other = 0;
1577
1578   origlist = features =
1579       gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1580       gst_plugin_get_name (plugin));
1581   if (sort_output == SORT_TYPE_NAME)
1582     features = g_list_sort (features, gst_plugin_feature_name_compare_func);
1583   while (features) {
1584     GstPluginFeature *feature;
1585
1586     feature = GST_PLUGIN_FEATURE (features->data);
1587
1588     if (GST_IS_ELEMENT_FACTORY (feature)) {
1589       GstElementFactory *factory;
1590
1591       factory = GST_ELEMENT_FACTORY (feature);
1592       n_print ("  %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1593           GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1594           gst_element_factory_get_metadata (factory,
1595               GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1596       num_elements++;
1597     } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1598       GstTypeFindFactory *factory;
1599       const gchar *const *extensions;
1600
1601       factory = GST_TYPE_FIND_FACTORY (feature);
1602       extensions = gst_type_find_factory_get_extensions (factory);
1603       if (extensions) {
1604         g_print ("  %s%s%s: ", ELEMENT_NAME_COLOR,
1605             gst_plugin_feature_get_name (feature), RESET_COLOR);
1606         print_typefind_extensions (extensions, ELEMENT_DETAIL_COLOR);
1607         g_print ("\n");
1608       } else
1609         g_print ("  %s%s%s: %sno extensions%s\n", ELEMENT_NAME_COLOR,
1610             gst_plugin_feature_get_name (feature), RESET_COLOR,
1611             ELEMENT_DETAIL_COLOR, RESET_COLOR);
1612
1613       num_typefinders++;
1614     } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
1615       GstDeviceProviderFactory *factory;
1616
1617       factory = GST_DEVICE_PROVIDER_FACTORY (feature);
1618       n_print ("  %s%s%s: %s%s%s\n", ELEMENT_NAME_COLOR,
1619           GST_OBJECT_NAME (factory), RESET_COLOR, ELEMENT_DETAIL_COLOR,
1620           gst_device_provider_factory_get_metadata (factory,
1621               GST_ELEMENT_METADATA_LONGNAME), RESET_COLOR);
1622       num_devproviders++;
1623     } else if (GST_IS_TRACER_FACTORY (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);
1627       num_tracers++;
1628     } else if (feature) {
1629       n_print ("  %s%s%s (%s%s%s)\n", ELEMENT_NAME_COLOR,
1630           gst_object_get_name (GST_OBJECT (feature)), RESET_COLOR,
1631           DATATYPE_COLOR, g_type_name (G_OBJECT_TYPE (feature)), RESET_COLOR);
1632       num_other++;
1633     }
1634     num_features++;
1635     features = g_list_next (features);
1636   }
1637
1638   gst_plugin_feature_list_free (origlist);
1639
1640   n_print ("\n");
1641   n_print ("  %s%d features%s:\n", HEADING_COLOR, num_features, RESET_COLOR);
1642   if (num_elements > 0)
1643     n_print ("  %s+--%s %s%d elements%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1644         PLUGIN_FEATURE_COLOR, num_elements, RESET_COLOR);
1645   if (num_typefinders > 0)
1646     n_print ("  %s+--%s %s%d typefinders%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1647         PLUGIN_FEATURE_COLOR, num_typefinders, RESET_COLOR);
1648   if (num_devproviders > 0)
1649     n_print ("  %s+--%s %s%d device providers%s\n", CHILD_LINK_COLOR,
1650         RESET_COLOR, PLUGIN_FEATURE_COLOR, num_devproviders, RESET_COLOR);
1651   if (num_tracers > 0)
1652     n_print ("  %s+--%s %s%d tracers%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1653         PLUGIN_FEATURE_COLOR, num_tracers, RESET_COLOR);
1654   if (num_other > 0)
1655     n_print ("  %s+--%s %s%d other objects%s\n", CHILD_LINK_COLOR, RESET_COLOR,
1656         PLUGIN_FEATURE_COLOR, num_other, RESET_COLOR);
1657
1658   n_print ("\n");
1659 }
1660
1661 static int
1662 print_feature_info (const gchar * feature_name, gboolean print_all)
1663 {
1664   GstPluginFeature *feature;
1665   GstRegistry *registry = gst_registry_get ();
1666   int ret;
1667
1668   if ((feature = gst_registry_find_feature (registry, feature_name,
1669               GST_TYPE_ELEMENT_FACTORY))) {
1670     ret = print_element_info (feature, print_all);
1671     goto handled;
1672   }
1673   if ((feature = gst_registry_find_feature (registry, feature_name,
1674               GST_TYPE_TYPE_FIND_FACTORY))) {
1675     ret = print_typefind_info (feature, print_all);
1676     goto handled;
1677   }
1678   if ((feature = gst_registry_find_feature (registry, feature_name,
1679               GST_TYPE_TRACER_FACTORY))) {
1680     ret = print_tracer_info (feature, print_all);
1681     goto handled;
1682   }
1683
1684   /* TODO: handle DEVICE_PROVIDER_FACTORY */
1685
1686   return -1;
1687
1688 handled:
1689   gst_object_unref (feature);
1690   return ret;
1691 }
1692
1693 static int
1694 print_element_info (GstPluginFeature * feature, gboolean print_names)
1695 {
1696   GstElementFactory *factory;
1697   GstElement *element;
1698   GstPlugin *plugin;
1699   gint maxlevel = 0;
1700
1701   factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1702   if (!factory) {
1703     g_print ("%selement plugin couldn't be loaded%s\n", DESC_COLOR,
1704         RESET_COLOR);
1705     return -1;
1706   }
1707
1708   element = gst_element_factory_create (factory, NULL);
1709   if (!element) {
1710     gst_object_unref (factory);
1711     g_print ("%scouldn't construct element for some reason%s\n", DESC_COLOR,
1712         RESET_COLOR);
1713     return -1;
1714   }
1715
1716   if (print_names)
1717     _name =
1718         g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1719         RESET_COLOR);
1720   else
1721     _name = NULL;
1722
1723   plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1724
1725   print_factory_details_info (factory, plugin);
1726
1727   if (plugin) {
1728     print_plugin_info (plugin);
1729     gst_object_unref (plugin);
1730   }
1731
1732   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1733   print_interfaces (G_OBJECT_TYPE (element));
1734
1735   print_pad_templates_info (element, factory);
1736   print_clocking_info (element);
1737   print_uri_handler_info (element);
1738   print_pad_info (element);
1739   print_element_properties_info (element);
1740   print_signal_info (element);
1741   print_children_info (element);
1742   print_preset_list (element);
1743
1744   gst_object_unref (element);
1745   gst_object_unref (factory);
1746   g_free (_name);
1747   return 0;
1748 }
1749
1750 static int
1751 print_typefind_info (GstPluginFeature * feature, gboolean print_names)
1752 {
1753   GstTypeFindFactory *factory;
1754   GstPlugin *plugin;
1755   GstCaps *caps;
1756   GstRank rank;
1757   char s[40];
1758   const gchar *const *extensions;
1759
1760   factory = GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (feature));
1761   if (!factory) {
1762     g_print ("%stypefind plugin couldn't be loaded%s\n", DESC_COLOR,
1763         RESET_COLOR);
1764     return -1;
1765   }
1766
1767   if (print_names)
1768     _name =
1769         g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1770         RESET_COLOR);
1771   else
1772     _name = NULL;
1773
1774   n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1775   rank = gst_plugin_feature_get_rank (feature);
1776   n_print ("  %s%-25s%s%s (%d)%s\n", PROP_NAME_COLOR, "Rank", PROP_VALUE_COLOR,
1777       get_rank_name (s, rank), rank, RESET_COLOR);
1778   n_print ("  %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1779       GST_OBJECT_NAME (factory), RESET_COLOR);
1780   caps = gst_type_find_factory_get_caps (factory);
1781   if (caps) {
1782     gchar *caps_str = gst_caps_to_string (factory->caps);
1783
1784     n_print ("  %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Caps", PROP_VALUE_COLOR,
1785         caps_str, RESET_COLOR);
1786     g_free (caps_str);
1787   }
1788   extensions = gst_type_find_factory_get_extensions (factory);
1789   if (extensions) {
1790     n_print ("  %s%-25s%s", PROP_NAME_COLOR, "Extensions", RESET_COLOR);
1791     print_typefind_extensions (extensions, PROP_VALUE_COLOR);
1792     n_print ("\n");
1793   }
1794   n_print ("\n");
1795
1796   plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1797   if (plugin) {
1798     print_plugin_info (plugin);
1799     gst_object_unref (plugin);
1800   }
1801
1802   gst_object_unref (factory);
1803   g_free (_name);
1804   return 0;
1805 }
1806
1807 static int
1808 print_tracer_info (GstPluginFeature * feature, gboolean print_names)
1809 {
1810   GstTracerFactory *factory;
1811   GstTracer *tracer;
1812   GstPlugin *plugin;
1813   gint maxlevel = 0;
1814
1815   factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
1816   if (!factory) {
1817     g_print ("%stracer plugin couldn't be loaded%s\n", DESC_COLOR, RESET_COLOR);
1818     return -1;
1819   }
1820
1821   tracer = (GstTracer *) g_object_new (factory->type, NULL);
1822   if (!tracer) {
1823     gst_object_unref (factory);
1824     g_print ("%scouldn't construct tracer for some reason%s\n", DESC_COLOR,
1825         RESET_COLOR);
1826     return -1;
1827   }
1828
1829   if (print_names)
1830     _name =
1831         g_strdup_printf ("%s%s%s: ", DATATYPE_COLOR, GST_OBJECT_NAME (factory),
1832         RESET_COLOR);
1833   else
1834     _name = NULL;
1835
1836   n_print ("%sFactory Details%s:\n", HEADING_COLOR, RESET_COLOR);
1837   n_print ("  %s%-25s%s%s%s\n", PROP_NAME_COLOR, "Name", PROP_VALUE_COLOR,
1838       GST_OBJECT_NAME (factory), RESET_COLOR);
1839   n_print ("\n");
1840
1841   plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1842   if (plugin) {
1843     print_plugin_info (plugin);
1844     gst_object_unref (plugin);
1845   }
1846
1847   print_hierarchy (G_OBJECT_TYPE (tracer), 0, &maxlevel);
1848   print_interfaces (G_OBJECT_TYPE (tracer));
1849
1850   /* TODO: list what hooks it registers
1851    * - the data is available in gsttracerutils, we need to iterate the
1852    *   _priv_tracers hashtable for each probe and then check the list of hooks
1853    *  for each probe whether hook->tracer == tracer :/
1854    */
1855
1856   /* TODO: list what records it emits
1857    * - in class_init tracers can create GstTracerRecord instances
1858    * - those only get logged right now and there is no association with the
1859    *   tracer that created them
1860    * - we'd need to add them to GstTracerFactory
1861    *   gst_tracer_class_add_record (klass, record);
1862    *   - needs work in gstregistrychunks to (de)serialize specs
1863    *   - gst_tracer_register() would need to iterate the list of records and
1864    *     copy the record->spec into the factory
1865    */
1866
1867   gst_object_unref (tracer);
1868   gst_object_unref (factory);
1869   g_free (_name);
1870   return 0;
1871 }
1872
1873 /* NOTE: Not coloring output from automatic install functions, as their output
1874  * is meant for machines, not humans.
1875  */
1876 static void
1877 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1878 {
1879   GstPadDirection direction;
1880   const gchar *type_name;
1881   const gchar *klass;
1882   const GList *static_templates, *l;
1883   GstCaps *caps = NULL;
1884   guint i, num;
1885
1886   klass =
1887       gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1888   g_return_if_fail (klass != NULL);
1889
1890   if (strstr (klass, "Demuxer") ||
1891       strstr (klass, "Decoder") ||
1892       strstr (klass, "Depay") || strstr (klass, "Parser")) {
1893     type_name = "decoder";
1894     direction = GST_PAD_SINK;
1895   } else if (strstr (klass, "Muxer") ||
1896       strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1897     type_name = "encoder";
1898     direction = GST_PAD_SRC;
1899   } else {
1900     return;
1901   }
1902
1903   /* decoder/demuxer sink pads should always be static and there should only
1904    * be one, the same applies to encoders/muxers and source pads */
1905   static_templates = gst_element_factory_get_static_pad_templates (factory);
1906   for (l = static_templates; l != NULL; l = l->next) {
1907     GstStaticPadTemplate *tmpl = NULL;
1908
1909     tmpl = (GstStaticPadTemplate *) l->data;
1910     if (tmpl->direction == direction) {
1911       caps = gst_static_pad_template_get_caps (tmpl);
1912       break;
1913     }
1914   }
1915
1916   if (caps == NULL) {
1917     g_printerr ("Couldn't find static pad template for %s '%s'\n",
1918         type_name, GST_OBJECT_NAME (factory));
1919     return;
1920   }
1921
1922   caps = gst_caps_make_writable (caps);
1923   num = gst_caps_get_size (caps);
1924   for (i = 0; i < num; ++i) {
1925     GstStructure *s;
1926     gchar *s_str;
1927
1928     s = gst_caps_get_structure (caps, i);
1929     /* remove fields that are almost always just MIN-MAX of some sort
1930      * in order to make the caps look less messy */
1931     gst_structure_remove_field (s, "pixel-aspect-ratio");
1932     gst_structure_remove_field (s, "framerate");
1933     gst_structure_remove_field (s, "channels");
1934     gst_structure_remove_field (s, "width");
1935     gst_structure_remove_field (s, "height");
1936     gst_structure_remove_field (s, "rate");
1937     gst_structure_remove_field (s, "depth");
1938     gst_structure_remove_field (s, "clock-rate");
1939     s_str = gst_structure_to_string (s);
1940     g_print ("%s-%s\n", type_name, s_str);
1941     g_free (s_str);
1942   }
1943   gst_caps_unref (caps);
1944 }
1945
1946 static void
1947 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1948 {
1949   const gchar *const *protocols;
1950
1951   protocols = gst_element_factory_get_uri_protocols (factory);
1952   if (protocols != NULL && *protocols != NULL) {
1953     switch (gst_element_factory_get_uri_type (factory)) {
1954       case GST_URI_SINK:
1955         while (*protocols != NULL) {
1956           g_print ("urisink-%s\n", *protocols);
1957           ++protocols;
1958         }
1959         break;
1960       case GST_URI_SRC:
1961         while (*protocols != NULL) {
1962           g_print ("urisource-%s\n", *protocols);
1963           ++protocols;
1964         }
1965         break;
1966       default:
1967         break;
1968     }
1969   }
1970 }
1971
1972 static void
1973 print_plugin_automatic_install_info (GstPlugin * plugin)
1974 {
1975   GList *features, *l;
1976
1977   /* not interested in typefind factories, only element factories */
1978   features = gst_registry_get_feature_list (gst_registry_get (),
1979       GST_TYPE_ELEMENT_FACTORY);
1980
1981   for (l = features; l != NULL; l = l->next) {
1982     GstPluginFeature *feature;
1983     GstPlugin *feature_plugin;
1984
1985     feature = GST_PLUGIN_FEATURE (l->data);
1986
1987     /* only interested in the ones that are in the plugin we just loaded */
1988     feature_plugin = gst_plugin_feature_get_plugin (feature);
1989     if (feature_plugin == plugin) {
1990       GstElementFactory *factory;
1991
1992       g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1993
1994       factory = GST_ELEMENT_FACTORY (feature);
1995       print_plugin_automatic_install_info_protocols (factory);
1996       print_plugin_automatic_install_info_codecs (factory);
1997     }
1998     if (feature_plugin)
1999       gst_object_unref (feature_plugin);
2000   }
2001
2002   g_list_foreach (features, (GFunc) gst_object_unref, NULL);
2003   g_list_free (features);
2004 }
2005
2006 static void
2007 print_all_plugin_automatic_install_info (void)
2008 {
2009   GList *plugins, *orig_plugins;
2010
2011   orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
2012   if (sort_output == SORT_TYPE_NAME)
2013     plugins = g_list_sort (plugins, gst_plugin_name_compare_func);
2014   while (plugins) {
2015     GstPlugin *plugin;
2016
2017     plugin = (GstPlugin *) (plugins->data);
2018     plugins = g_list_next (plugins);
2019
2020     print_plugin_automatic_install_info (plugin);
2021   }
2022   gst_plugin_list_free (orig_plugins);
2023 }
2024
2025 #ifdef G_OS_UNIX
2026 static gboolean
2027 redirect_stdout (void)
2028 {
2029   GError *error = NULL;
2030   gchar **argv;
2031   const gchar *pager, *less;
2032   gint stdin_fd;
2033   gchar **envp;
2034
2035   pager = g_getenv ("PAGER");
2036   if (pager == NULL)
2037     pager = DEFAULT_PAGER;
2038
2039   argv = g_strsplit (pager, " ", 0);
2040
2041   less = g_getenv ("GST_LESS");
2042   if (less == NULL)
2043     less = DEFAULT_LESS_OPTS;
2044
2045   envp = g_get_environ ();
2046   envp = g_environ_setenv (envp, "LESS", less, TRUE);
2047
2048   if (!g_spawn_async_with_pipes (NULL, argv, envp,
2049           G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
2050           NULL, NULL, &child_pid, &stdin_fd,
2051           /* pass null stdout/stderr to inherit our fds */
2052           NULL, NULL, &error)) {
2053     if (pager != DEFAULT_PAGER) {
2054       g_warning ("g_spawn_async_with_pipes() failed: %s\n",
2055           GST_STR_NULL (error->message));
2056     }
2057     g_strfreev (argv);
2058     g_strfreev (envp);
2059     g_clear_error (&error);
2060
2061     return FALSE;
2062   }
2063
2064   /* redirect our stdout to child stdin */
2065   dup2 (stdin_fd, STDOUT_FILENO);
2066   if (isatty (STDERR_FILENO))
2067     dup2 (stdin_fd, STDERR_FILENO);
2068   close (stdin_fd);
2069
2070   g_strfreev (argv);
2071   g_strfreev (envp);
2072
2073   return TRUE;
2074 }
2075
2076 static void
2077 child_exit_cb (GPid child_pid, gint status, gpointer user_data)
2078 {
2079   g_spawn_close_pid (child_pid);
2080   g_main_loop_quit (loop);
2081 }
2082 #endif
2083
2084 static gboolean
2085 _parse_sort_type (const gchar * option_name, const gchar * optarg,
2086     gpointer data, GError ** error)
2087 {
2088   if (!g_strcmp0 (optarg, "name")) {
2089     sort_output = SORT_TYPE_NAME;
2090     return TRUE;
2091   } else if (!g_strcmp0 (optarg, "none")) {
2092     sort_output = SORT_TYPE_NONE;
2093     return TRUE;
2094   }
2095
2096   return FALSE;
2097 }
2098
2099 static int
2100 real_main (int argc, char *argv[])
2101 {
2102   gboolean print_all = FALSE;
2103   gboolean do_print_blacklist = FALSE;
2104   gboolean plugin_name = FALSE;
2105   gboolean print_aii = FALSE;
2106   gboolean uri_handlers = FALSE;
2107   gboolean check_exists = FALSE;
2108   gboolean color_always = FALSE;
2109   gchar *min_version = NULL;
2110   guint minver_maj = GST_VERSION_MAJOR;
2111   guint minver_min = GST_VERSION_MINOR;
2112   guint minver_micro = 0;
2113   gchar *types = NULL;
2114   const gchar *no_colors;
2115   int exit_code = 0;
2116 #ifndef GST_DISABLE_OPTION_PARSING
2117   GOptionEntry options[] = {
2118     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
2119         N_("Print all elements"), NULL},
2120     {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
2121         N_("Print list of blacklisted files"), NULL},
2122     {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
2123         N_("Print a machine-parsable list of features the specified plugin "
2124               "or all plugins provide.\n                                       "
2125               "Useful in connection with external automatic plugin "
2126               "installation mechanisms"), NULL},
2127     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
2128         N_("List the plugin contents"), NULL},
2129     {"types", 't', 0, G_OPTION_ARG_STRING, &types,
2130         N_("A slashes ('/') separated list of types of elements (also known "
2131               "as klass) to list. (unordered)"), NULL},
2132     {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
2133         N_("Check if the specified element or plugin exists"), NULL},
2134     {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
2135         N_
2136           ("When checking if an element or plugin exists, also check that its "
2137               "version is at least the version specified"), NULL},
2138     {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
2139           N_
2140           ("Print supported URI schemes, with the elements that implement them"),
2141         NULL},
2142     {"no-colors", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
2143           &colored_output,
2144           N_
2145           ("Disable colors in output. You can also achieve the same by setting "
2146               "'GST_INSPECT_NO_COLORS' environment variable to any value."),
2147         NULL},
2148     {"sort", '\0', G_OPTION_ARG_NONE, G_OPTION_ARG_CALLBACK, &_parse_sort_type,
2149           "Sort plugins and features. Sorting keys: name (default), none.",
2150         "<sort-key>"}
2151     ,
2152     {"color", 'C', 0, G_OPTION_ARG_NONE, &color_always,
2153           N_("Color output, even when not sending to a tty."),
2154         NULL},
2155     GST_TOOLS_GOPTION_VERSION,
2156     {NULL}
2157   };
2158   GOptionContext *ctx;
2159   GError *err = NULL;
2160 #endif
2161
2162   setlocale (LC_ALL, "");
2163
2164 #ifdef ENABLE_NLS
2165   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
2166   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2167   textdomain (GETTEXT_PACKAGE);
2168 #endif
2169
2170   /* avoid glib warnings when inspecting deprecated properties */
2171   g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE);
2172
2173   g_set_prgname ("gst-inspect-" GST_API_VERSION);
2174
2175 #ifndef GST_DISABLE_OPTION_PARSING
2176   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
2177   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
2178   g_option_context_add_group (ctx, gst_init_get_option_group ());
2179 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2180   if (!g_option_context_parse_strv (ctx, &argv, &err))
2181 #else
2182   if (!g_option_context_parse (ctx, &argc, &argv, &err))
2183 #endif
2184   {
2185     g_printerr ("Error initializing: %s\n", err->message);
2186     g_clear_error (&err);
2187     g_option_context_free (ctx);
2188     return -1;
2189   }
2190   g_option_context_free (ctx);
2191 #else
2192   gst_init (&argc, &argv);
2193 #endif
2194
2195 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2196   argc = g_strv_length (argv);
2197 #endif
2198
2199   gst_tools_print_version ();
2200
2201   if (print_all && argc > 1) {
2202     g_printerr ("-a requires no extra arguments\n");
2203     return -1;
2204   }
2205
2206   if (uri_handlers && argc > 1) {
2207     g_printerr ("-u requires no extra arguments\n");
2208     return -1;
2209   }
2210
2211   /* --atleast-version implies --exists */
2212   if (min_version != NULL) {
2213     if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
2214             &minver_micro) < 2) {
2215       g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
2216           min_version);
2217       g_free (min_version);
2218       return -1;
2219     }
2220     g_free (min_version);
2221     check_exists = TRUE;
2222   }
2223
2224   if (check_exists) {
2225     if (argc == 1) {
2226       g_printerr ("--exists requires an extra command line argument\n");
2227       exit_code = -1;
2228     } else {
2229       if (!plugin_name) {
2230         GstPluginFeature *feature;
2231
2232         feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
2233         if (feature != NULL && gst_plugin_feature_check_version (feature,
2234                 minver_maj, minver_min, minver_micro)) {
2235           exit_code = 0;
2236         } else {
2237           exit_code = 1;
2238         }
2239
2240         if (feature)
2241           gst_object_unref (feature);
2242       } else {
2243         /* FIXME: support checking for plugins too */
2244         g_printerr ("Checking for plugins is not supported yet\n");
2245         exit_code = -1;
2246       }
2247     }
2248     return exit_code;
2249   }
2250
2251   no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
2252   /* We only support truecolor */
2253   colored_output &= (no_colors == NULL);
2254
2255 #ifdef G_OS_UNIX
2256   if (isatty (STDOUT_FILENO)) {
2257     if (redirect_stdout ())
2258       loop = g_main_loop_new (NULL, FALSE);
2259   } else {
2260     colored_output = (color_always) ? TRUE : FALSE;
2261   }
2262 #elif defined(G_OS_WIN32)
2263   {
2264     /* g_log_writer_supports_color is available since 2.50.0 */
2265     gint fd = _fileno (stdout);
2266     /* On Windows 10, g_log_writer_supports_color will also setup the console
2267      * so that it correctly interprets ANSI VT sequences if it's supported */
2268     if (!_isatty (fd) || !g_log_writer_supports_color (fd))
2269       colored_output = FALSE;
2270   }
2271 #endif
2272
2273   /* if no arguments, print out list of elements */
2274   if (uri_handlers) {
2275     print_all_uri_handlers ();
2276   } else if (argc == 1 || print_all) {
2277     if (do_print_blacklist)
2278       print_blacklist ();
2279     else {
2280       if (print_aii)
2281         print_all_plugin_automatic_install_info ();
2282       else
2283         print_element_list (print_all, types);
2284     }
2285   } else {
2286     /* else we try to get a factory */
2287     const char *arg = argv[argc - 1];
2288     int retval = -1;
2289
2290     if (!plugin_name) {
2291       retval = print_feature_info (arg, print_all);
2292     }
2293
2294     /* otherwise check if it's a plugin */
2295     if (retval) {
2296       GstPlugin *plugin = gst_registry_find_plugin (gst_registry_get (), arg);
2297
2298       /* if there is such a plugin, print out info */
2299       if (plugin) {
2300         if (print_aii) {
2301           print_plugin_automatic_install_info (plugin);
2302         } else {
2303           print_plugin_info (plugin);
2304           print_plugin_features (plugin);
2305         }
2306       } else {
2307         GError *error = NULL;
2308
2309         if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
2310           plugin = gst_plugin_load_file (arg, &error);
2311
2312           if (plugin) {
2313             if (print_aii) {
2314               print_plugin_automatic_install_info (plugin);
2315             } else {
2316               print_plugin_info (plugin);
2317               print_plugin_features (plugin);
2318             }
2319           } else {
2320             g_printerr (_("Could not load plugin file: %s\n"), error->message);
2321             g_clear_error (&error);
2322             exit_code = -1;
2323             goto done;
2324           }
2325         } else {
2326           g_printerr (_("No such element or plugin '%s'\n"), arg);
2327           exit_code = -1;
2328           goto done;
2329         }
2330       }
2331     }
2332   }
2333
2334 done:
2335
2336 #ifdef G_OS_UNIX
2337   if (loop) {
2338     fflush (stdout);
2339     fflush (stderr);
2340     /* So that the pipe we create in redirect_stdout() is closed */
2341     close (STDOUT_FILENO);
2342     close (STDERR_FILENO);
2343     g_child_watch_add (child_pid, child_exit_cb, NULL);
2344     g_main_loop_run (loop);
2345     g_main_loop_unref (loop);
2346   }
2347 #endif
2348
2349   return exit_code;
2350 }
2351
2352 int
2353 main (int argc, char *argv[])
2354 {
2355   int ret;
2356
2357   /* gstinspect.c calls this function */
2358 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2359   argv = g_win32_get_command_line ();
2360 #endif
2361
2362 #if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
2363   ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
2364 #else
2365   ret = real_main (argc, argv);
2366 #endif
2367
2368 #if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
2369   g_strfreev (argv);
2370 #endif
2371
2372   return ret;
2373 }