gst-inspect: Print caps features too
[platform/upstream/gstreamer.git] / 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  *
6  * gst-inspect.c: tool to inspect the GStreamer registry
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
29  * with newer GLib versions (>= 2.31.0) */
30 #define GLIB_DISABLE_DEPRECATION_WARNINGS
31
32 #include "tools.h"
33
34 #include <string.h>
35 #include <locale.h>
36 #include <glib/gprintf.h>
37
38 static char *_name = NULL;
39
40 static int print_element_info (GstElementFactory * factory,
41     gboolean print_names);
42
43 static void
44 n_print (const char *format, ...)
45 {
46   va_list args;
47
48   if (_name)
49     g_print ("%s", _name);
50
51   va_start (args, format);
52   g_vprintf (format, args);
53   va_end (args);
54 }
55
56 static gboolean
57 print_field (GQuark field, const GValue * value, gpointer pfx)
58 {
59   gchar *str = gst_value_serialize (value);
60
61   n_print ("%s  %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
62   g_free (str);
63   return TRUE;
64 }
65
66 static void
67 print_caps (const GstCaps * caps, const gchar * pfx)
68 {
69   guint i;
70
71   g_return_if_fail (caps != NULL);
72
73   if (gst_caps_is_any (caps)) {
74     n_print ("%sANY\n", pfx);
75     return;
76   }
77   if (gst_caps_is_empty (caps)) {
78     n_print ("%sEMPTY\n", pfx);
79     return;
80   }
81
82   for (i = 0; i < gst_caps_get_size (caps); i++) {
83     GstStructure *structure = gst_caps_get_structure (caps, i);
84     GstCapsFeatures *features = gst_caps_get_features (caps, i);
85
86     if (features
87         && !gst_caps_features_is_equal (features,
88             GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) {
89       gchar *features_string = gst_caps_features_to_string (features);
90
91       n_print ("%s%s(%s)\n", pfx, gst_structure_get_name (structure),
92           features_string);
93       g_free (features_string);
94     } else {
95       n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
96     }
97     gst_structure_foreach (structure, print_field, (gpointer) pfx);
98   }
99 }
100
101 #if 0
102 static void
103 print_formats (const GstFormat * formats)
104 {
105   while (formats && *formats) {
106     const GstFormatDefinition *definition;
107
108     definition = gst_format_get_details (*formats);
109     if (definition)
110       n_print ("\t\t(%d):\t%s (%s)\n", *formats,
111           definition->nick, definition->description);
112     else
113       n_print ("\t\t(%d):\tUnknown format\n", *formats);
114
115     formats++;
116   }
117 }
118
119 static void
120 print_event_masks (const GstEventMask * masks)
121 {
122   GType event_type;
123   GEnumClass *klass;
124   GType event_flags;
125   GFlagsClass *flags_class = NULL;
126
127   event_type = gst_event_type_get_type ();
128   klass = (GEnumClass *) g_type_class_ref (event_type);
129
130   while (masks && masks->type) {
131     GEnumValue *value;
132     gint flags = 0, index = 0;
133
134     switch (masks->type) {
135       case GST_EVENT_SEEK:
136         flags = masks->flags;
137         event_flags = gst_seek_type_get_type ();
138         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
139         break;
140       default:
141         break;
142     }
143
144     value = g_enum_get_value (klass, masks->type);
145     g_print ("\t\t%s ", value->value_nick);
146
147     while (flags) {
148       GFlagsValue *value;
149
150       if (flags & 1) {
151         value = g_flags_get_first_value (flags_class, 1 << index);
152
153         if (value)
154           g_print ("| %s ", value->value_nick);
155         else
156           g_print ("| ? ");
157       }
158       flags >>= 1;
159       index++;
160     }
161     g_print ("\n");
162
163     masks++;
164   }
165 }
166 #endif
167
168 static const char *
169 get_rank_name (char *s, gint rank)
170 {
171   static const int ranks[4] = {
172     GST_RANK_NONE, GST_RANK_MARGINAL, GST_RANK_SECONDARY, GST_RANK_PRIMARY
173   };
174   static const char *rank_names[4] = { "none", "marginal", "secondary",
175     "primary"
176   };
177   int i;
178   int best_i;
179
180   best_i = 0;
181   for (i = 0; i < 4; i++) {
182     if (rank == ranks[i])
183       return rank_names[i];
184     if (abs (rank - ranks[i]) < abs (rank - ranks[best_i])) {
185       best_i = i;
186     }
187   }
188
189   sprintf (s, "%s %c %d", rank_names[best_i],
190       (rank - ranks[best_i] > 0) ? '+' : '-', abs (ranks[best_i] - rank));
191
192   return s;
193 }
194
195 static void
196 print_factory_details_info (GstElementFactory * factory)
197 {
198   gchar **keys, **k;
199   GstRank rank;
200   char s[20];
201
202   rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
203   n_print ("Factory Details:\n");
204   n_print ("  %-25s%s (%d)\n", "Rank", get_rank_name (s, rank), rank);
205
206   keys = gst_element_factory_get_metadata_keys (factory);
207   if (keys != NULL) {
208     for (k = keys; *k != NULL; ++k) {
209       const gchar *val;
210       gchar *key = *k;
211
212       val = gst_element_factory_get_metadata (factory, key);
213       key[0] = g_ascii_toupper (key[0]);
214       n_print ("  %-25s%s\n", key, val);
215     }
216     g_strfreev (keys);
217   }
218   n_print ("\n");
219 }
220
221 static void
222 print_hierarchy (GType type, gint level, gint * maxlevel)
223 {
224   GType parent;
225   gint i;
226
227   parent = g_type_parent (type);
228
229   *maxlevel = *maxlevel + 1;
230   level++;
231
232   if (parent)
233     print_hierarchy (parent, level, maxlevel);
234
235   if (_name)
236     g_print ("%s", _name);
237
238   for (i = 1; i < *maxlevel - level; i++)
239     g_print ("      ");
240   if (*maxlevel - level)
241     g_print (" +----");
242
243   g_print ("%s\n", g_type_name (type));
244
245   if (level == 1)
246     n_print ("\n");
247 }
248
249 static void
250 print_interfaces (GType type)
251 {
252   guint n_ifaces;
253   GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
254
255   if (ifaces) {
256     if (n_ifaces) {
257       if (_name)
258         g_print ("%s", _name);
259       g_print (_("Implemented Interfaces:\n"));
260       iface = ifaces;
261       while (*iface) {
262         if (_name)
263           g_print ("%s", _name);
264         g_print ("  %s\n", g_type_name (*iface));
265         iface++;
266       }
267       if (_name)
268         g_print ("%s", _name);
269       g_print ("\n");
270     }
271     g_free (ifaces);
272   }
273 }
274
275 static gchar *
276 flags_to_string (GFlagsValue * vals, guint flags)
277 {
278   GString *s = NULL;
279   guint flags_left, i;
280
281   /* first look for an exact match and count the number of values */
282   for (i = 0; vals[i].value_name != NULL; ++i) {
283     if (vals[i].value == flags)
284       return g_strdup (vals[i].value_nick);
285   }
286
287   s = g_string_new (NULL);
288
289   /* we assume the values are sorted from lowest to highest value */
290   flags_left = flags;
291   while (i > 0) {
292     --i;
293     if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
294       if (s->len > 0)
295         g_string_append_c (s, '+');
296       g_string_append (s, vals[i].value_nick);
297       flags_left -= vals[i].value;
298       if (flags_left == 0)
299         break;
300     }
301   }
302
303   if (s->len == 0)
304     g_string_assign (s, "(none)");
305
306   return g_string_free (s, FALSE);
307 }
308
309 #define KNOWN_PARAM_FLAGS \
310   (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | \
311   G_PARAM_LAX_VALIDATION |  G_PARAM_STATIC_STRINGS | \
312   G_PARAM_READABLE | G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | \
313   GST_PARAM_MUTABLE_PLAYING | GST_PARAM_MUTABLE_PAUSED | \
314   GST_PARAM_MUTABLE_READY)
315
316 static void
317 print_element_properties_info (GstElement * element)
318 {
319   GParamSpec **property_specs;
320   guint num_properties, i;
321   gboolean readable;
322   gboolean first_flag;
323
324   property_specs = g_object_class_list_properties
325       (G_OBJECT_GET_CLASS (element), &num_properties);
326   n_print ("\n");
327   n_print ("Element Properties:\n");
328
329   for (i = 0; i < num_properties; i++) {
330     GValue value = { 0, };
331     GParamSpec *param = property_specs[i];
332
333     readable = FALSE;
334
335     g_value_init (&value, param->value_type);
336
337     n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
338         g_param_spec_get_blurb (param));
339
340     first_flag = TRUE;
341     n_print ("%-23.23s flags: ", "");
342     if (param->flags & G_PARAM_READABLE) {
343       g_object_get_property (G_OBJECT (element), param->name, &value);
344       readable = TRUE;
345       g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
346       first_flag = FALSE;
347     } else {
348       /* if we can't read the property value, assume it's set to the default
349        * (which might not be entirely true for sub-classes, but that's an
350        * unlikely corner-case anyway) */
351       g_param_value_set_default (param, &value);
352     }
353     if (param->flags & G_PARAM_WRITABLE) {
354       g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
355       first_flag = FALSE;
356     }
357     if (param->flags & GST_PARAM_CONTROLLABLE) {
358       g_print (", %s", _("controllable"));
359       first_flag = FALSE;
360     }
361     if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
362       g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
363     } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
364       g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
365     } else if (param->flags & GST_PARAM_MUTABLE_READY) {
366       g_print (", %s", _("changeable only in NULL or READY state"));
367     }
368     if (param->flags & ~KNOWN_PARAM_FLAGS) {
369       g_print ("%s0x%0x", (first_flag) ? "" : ", ",
370           param->flags & ~KNOWN_PARAM_FLAGS);
371     }
372     n_print ("\n");
373
374     switch (G_VALUE_TYPE (&value)) {
375       case G_TYPE_STRING:
376       {
377         const char *string_val = g_value_get_string (&value);
378
379         n_print ("%-23.23s String. ", "");
380
381         if (string_val == NULL)
382           g_print ("Default: null");
383         else
384           g_print ("Default: \"%s\"", string_val);
385         break;
386       }
387       case G_TYPE_BOOLEAN:
388       {
389         gboolean bool_val = g_value_get_boolean (&value);
390
391         n_print ("%-23.23s Boolean. ", "");
392
393         g_print ("Default: %s", bool_val ? "true" : "false");
394         break;
395       }
396       case G_TYPE_ULONG:
397       {
398         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
399
400         n_print ("%-23.23s Unsigned Long. ", "");
401         g_print ("Range: %lu - %lu Default: %lu ",
402             pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
403
404         GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
405             "uint/uint64", GST_OBJECT_NAME (element),
406             g_param_spec_get_name (param));
407         break;
408       }
409       case G_TYPE_LONG:
410       {
411         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
412
413         n_print ("%-23.23s Long. ", "");
414         g_print ("Range: %ld - %ld Default: %ld ",
415             plong->minimum, plong->maximum, g_value_get_long (&value));
416
417         GST_ERROR ("%s: property '%s' of type long: consider changing to "
418             "int/int64", GST_OBJECT_NAME (element),
419             g_param_spec_get_name (param));
420         break;
421       }
422       case G_TYPE_UINT:
423       {
424         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
425
426         n_print ("%-23.23s Unsigned Integer. ", "");
427         g_print ("Range: %u - %u Default: %u ",
428             puint->minimum, puint->maximum, g_value_get_uint (&value));
429         break;
430       }
431       case G_TYPE_INT:
432       {
433         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
434
435         n_print ("%-23.23s Integer. ", "");
436         g_print ("Range: %d - %d Default: %d ",
437             pint->minimum, pint->maximum, g_value_get_int (&value));
438         break;
439       }
440       case G_TYPE_UINT64:
441       {
442         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
443
444         n_print ("%-23.23s Unsigned Integer64. ", "");
445         g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
446             " Default: %" G_GUINT64_FORMAT " ",
447             puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
448         break;
449       }
450       case G_TYPE_INT64:
451       {
452         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
453
454         n_print ("%-23.23s Integer64. ", "");
455         g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
456             " Default: %" G_GINT64_FORMAT " ",
457             pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
458         break;
459       }
460       case G_TYPE_FLOAT:
461       {
462         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
463
464         n_print ("%-23.23s Float. ", "");
465         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
466             pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
467         break;
468       }
469       case G_TYPE_DOUBLE:
470       {
471         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
472
473         n_print ("%-23.23s Double. ", "");
474         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
475             pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
476         break;
477       }
478       case G_TYPE_CHAR:
479       case G_TYPE_UCHAR:
480         GST_ERROR ("%s: property '%s' of type char: consider changing to "
481             "int/string", GST_OBJECT_NAME (element),
482             g_param_spec_get_name (param));
483         /* fall through */
484       default:
485         if (param->value_type == GST_TYPE_CAPS) {
486           const GstCaps *caps = gst_value_get_caps (&value);
487
488           if (!caps)
489             n_print ("%-23.23s Caps (NULL)", "");
490           else {
491             print_caps (caps, "                           ");
492           }
493         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
494           GEnumValue *values;
495           guint j = 0;
496           gint enum_value;
497           const gchar *value_nick = "";
498
499           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
500           enum_value = g_value_get_enum (&value);
501
502           while (values[j].value_name) {
503             if (values[j].value == enum_value)
504               value_nick = values[j].value_nick;
505             j++;
506           }
507
508           n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
509               g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);
510
511           j = 0;
512           while (values[j].value_name) {
513             g_print ("\n");
514             if (_name)
515               g_print ("%s", _name);
516             g_print ("%-23.23s    (%d): %-16s - %s", "",
517                 values[j].value, values[j].value_nick, values[j].value_name);
518             j++;
519           }
520           /* g_type_class_unref (ec); */
521         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
522           GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
523           GFlagsValue *vals;
524           gchar *cur;
525
526           vals = pflags->flags_class->values;
527
528           cur = flags_to_string (vals, g_value_get_flags (&value));
529
530           n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
531               g_type_name (G_VALUE_TYPE (&value)),
532               g_value_get_flags (&value), cur);
533
534           while (vals[0].value_name) {
535             g_print ("\n");
536             if (_name)
537               g_print ("%s", _name);
538             g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
539                 vals[0].value, vals[0].value_nick, vals[0].value_name);
540             ++vals;
541           }
542
543           g_free (cur);
544         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
545           n_print ("%-23.23s Object of type \"%s\"", "",
546               g_type_name (param->value_type));
547         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
548           n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
549               g_type_name (param->value_type));
550         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
551           if (param->value_type != G_TYPE_POINTER) {
552             n_print ("%-23.23s Pointer of type \"%s\".", "",
553                 g_type_name (param->value_type));
554           } else {
555             n_print ("%-23.23s Pointer.", "");
556           }
557         } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
558           GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
559
560           if (pvarray->element_spec) {
561             n_print ("%-23.23s Array of GValues of type \"%s\"", "",
562                 g_type_name (pvarray->element_spec->value_type));
563           } else {
564             n_print ("%-23.23s Array of GValues", "");
565           }
566         } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
567           GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
568
569           n_print ("%-23.23s Fraction. ", "");
570
571           g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
572               pfraction->min_num, pfraction->min_den,
573               pfraction->max_num, pfraction->max_den,
574               gst_value_get_fraction_numerator (&value),
575               gst_value_get_fraction_denominator (&value));
576         } else {
577           n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
578               g_type_name (param->value_type));
579         }
580         break;
581     }
582     if (!readable)
583       g_print (" Write only\n");
584     else
585       g_print ("\n");
586
587     g_value_reset (&value);
588   }
589   if (num_properties == 0)
590     n_print ("  none\n");
591
592   g_free (property_specs);
593 }
594
595 static void
596 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
597 {
598   GstElementClass *gstelement_class;
599   const GList *pads;
600   GstStaticPadTemplate *padtemplate;
601
602   n_print ("Pad Templates:\n");
603   if (gst_element_factory_get_num_pad_templates (factory) == 0) {
604     n_print ("  none\n");
605     return;
606   }
607
608   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
609
610   pads = gst_element_factory_get_static_pad_templates (factory);
611   while (pads) {
612     padtemplate = (GstStaticPadTemplate *) (pads->data);
613     pads = g_list_next (pads);
614
615     if (padtemplate->direction == GST_PAD_SRC)
616       n_print ("  SRC template: '%s'\n", padtemplate->name_template);
617     else if (padtemplate->direction == GST_PAD_SINK)
618       n_print ("  SINK template: '%s'\n", padtemplate->name_template);
619     else
620       n_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
621
622     if (padtemplate->presence == GST_PAD_ALWAYS)
623       n_print ("    Availability: Always\n");
624     else if (padtemplate->presence == GST_PAD_SOMETIMES)
625       n_print ("    Availability: Sometimes\n");
626     else if (padtemplate->presence == GST_PAD_REQUEST) {
627       n_print ("    Availability: On request\n");
628       n_print ("      Has request_new_pad() function: %s\n",
629           GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
630     } else
631       n_print ("    Availability: UNKNOWN!!!\n");
632
633     if (padtemplate->static_caps.string) {
634       n_print ("    Capabilities:\n");
635       print_caps (gst_static_caps_get (&padtemplate->static_caps), "      ");
636     }
637
638     n_print ("\n");
639   }
640 }
641
642 static void
643 print_element_flag_info (GstElement * element)
644 {
645   gboolean have_flags = FALSE;
646
647   n_print ("\n");
648   n_print ("Element Flags:\n");
649
650   if (!have_flags)
651     n_print ("  no flags set\n");
652
653   if (GST_IS_BIN (element)) {
654     n_print ("\n");
655     n_print ("Bin Flags:\n");
656     if (!have_flags)
657       n_print ("  no flags set\n");
658   }
659 }
660
661 static void
662 print_implementation_info (GstElement * element)
663 {
664   GstElementClass *gstelement_class;
665
666   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
667
668   n_print ("\n");
669   n_print ("Element Implementation:\n");
670
671   n_print ("  Has change_state() function: %s\n",
672       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
673 }
674
675 static void
676 print_clocking_info (GstElement * element)
677 {
678   gboolean requires_clock, provides_clock;
679
680   requires_clock =
681       GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
682   provides_clock =
683       GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
684
685   if (!requires_clock && !provides_clock) {
686     n_print ("\n");
687     n_print ("Element has no clocking capabilities.");
688     return;
689   }
690
691   n_print ("\n");
692   n_print ("Clocking Interaction:\n");
693   if (requires_clock) {
694     n_print ("  element requires a clock\n");
695   }
696
697   if (provides_clock) {
698     GstClock *clock;
699
700     clock = gst_element_get_clock (element);
701     if (clock) {
702       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
703       gst_object_unref (clock);
704     } else
705       n_print ("  element is supposed to provide a clock but returned NULL\n");
706   }
707 }
708
709 static void
710 print_index_info (GstElement * element)
711 {
712   if (GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_INDEXABLE)) {
713     n_print ("\n");
714     n_print ("Indexing capabilities:\n");
715     n_print ("  element can do indexing\n");
716   } else {
717     n_print ("\n");
718     n_print ("Element has no indexing capabilities.\n");
719   }
720 }
721
722 static void
723 print_uri_handler_info (GstElement * element)
724 {
725   if (GST_IS_URI_HANDLER (element)) {
726     const gchar *const *uri_protocols;
727     const gchar *uri_type;
728
729     if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
730       uri_type = "source";
731     else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
732         GST_URI_SINK)
733       uri_type = "sink";
734     else
735       uri_type = "unknown";
736
737     uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
738
739     n_print ("\n");
740     n_print ("URI handling capabilities:\n");
741     n_print ("  Element can act as %s.\n", uri_type);
742
743     if (uri_protocols && *uri_protocols) {
744       n_print ("  Supported URI protocols:\n");
745       for (; *uri_protocols != NULL; uri_protocols++)
746         n_print ("    %s\n", *uri_protocols);
747     } else {
748       n_print ("  No supported URI protocols\n");
749     }
750   } else {
751     n_print ("Element has no URI handling capabilities.\n");
752   }
753 }
754
755 static void
756 print_pad_info (GstElement * element)
757 {
758   const GList *pads;
759   GstPad *pad;
760
761   n_print ("\n");
762   n_print ("Pads:\n");
763
764   if (!element->numpads) {
765     n_print ("  none\n");
766     return;
767   }
768
769   pads = element->pads;
770   while (pads) {
771     gchar *name;
772     GstCaps *caps;
773
774     pad = GST_PAD (pads->data);
775     pads = g_list_next (pads);
776
777     n_print ("");
778
779     name = gst_pad_get_name (pad);
780     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
781       g_print ("  SRC: '%s'", name);
782     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
783       g_print ("  SINK: '%s'", name);
784     else
785       g_print ("  UNKNOWN!!!: '%s'", name);
786
787     g_free (name);
788
789     g_print ("\n");
790
791     n_print ("    Implementation:\n");
792     if (pad->chainfunc)
793       n_print ("      Has chainfunc(): %s\n",
794           GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
795     if (pad->getrangefunc)
796       n_print ("      Has getrangefunc(): %s\n",
797           GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
798     if (pad->eventfunc != gst_pad_event_default)
799       n_print ("      Has custom eventfunc(): %s\n",
800           GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
801     if (pad->queryfunc != gst_pad_query_default)
802       n_print ("      Has custom queryfunc(): %s\n",
803           GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
804
805     if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
806       n_print ("      Has custom iterintlinkfunc(): %s\n",
807           GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
808
809     if (pad->padtemplate)
810       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
811
812     caps = gst_pad_get_current_caps (pad);
813     if (caps) {
814       n_print ("    Capabilities:\n");
815       print_caps (caps, "      ");
816       gst_caps_unref (caps);
817     }
818   }
819 }
820
821 static gboolean
822 has_sometimes_template (GstElement * element)
823 {
824   GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
825   GList *l;
826
827   for (l = klass->padtemplates; l != NULL; l = l->next) {
828     if (GST_PAD_TEMPLATE (l->data)->presence == GST_PAD_SOMETIMES)
829       return TRUE;
830   }
831
832   return FALSE;
833 }
834
835 static void
836 print_signal_info (GstElement * element)
837 {
838   /* Signals/Actions Block */
839   guint *signals;
840   guint nsignals;
841   gint i = 0, j, k;
842   GSignalQuery *query = NULL;
843   GType type;
844   GSList *found_signals, *l;
845
846   for (k = 0; k < 2; k++) {
847     found_signals = NULL;
848
849     /* For elements that have sometimes pads, also list a few useful GstElement
850      * signals. Put these first, so element-specific ones come later. */
851     if (k == 0 && has_sometimes_template (element)) {
852       query = g_new0 (GSignalQuery, 1);
853       g_signal_query (g_signal_lookup ("pad-added", GST_TYPE_ELEMENT), query);
854       found_signals = g_slist_append (found_signals, query);
855       query = g_new0 (GSignalQuery, 1);
856       g_signal_query (g_signal_lookup ("pad-removed", GST_TYPE_ELEMENT), query);
857       found_signals = g_slist_append (found_signals, query);
858       query = g_new0 (GSignalQuery, 1);
859       g_signal_query (g_signal_lookup ("no-more-pads", GST_TYPE_ELEMENT),
860           query);
861       found_signals = g_slist_append (found_signals, query);
862     }
863
864     for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
865       if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
866         break;
867
868       if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
869         continue;
870
871       signals = g_signal_list_ids (type, &nsignals);
872       for (i = 0; i < nsignals; i++) {
873         query = g_new0 (GSignalQuery, 1);
874         g_signal_query (signals[i], query);
875
876         if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
877             (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
878           found_signals = g_slist_append (found_signals, query);
879         else
880           g_free (query);
881       }
882       g_free (signals);
883       signals = NULL;
884     }
885
886     if (found_signals) {
887       n_print ("\n");
888       if (k == 0)
889         n_print ("Element Signals:\n");
890       else
891         n_print ("Element Actions:\n");
892     } else {
893       continue;
894     }
895
896     for (l = found_signals; l; l = l->next) {
897       gchar *indent;
898       int indent_len;
899
900       query = (GSignalQuery *) l->data;
901       indent_len = strlen (query->signal_name) +
902           strlen (g_type_name (query->return_type)) + 24;
903
904       indent = g_new0 (gchar, indent_len + 1);
905       memset (indent, ' ', indent_len);
906
907       n_print ("  \"%s\" :  %s user_function (%s* object",
908           query->signal_name,
909           g_type_name (query->return_type), g_type_name (type));
910
911       for (j = 0; j < query->n_params; j++) {
912         g_print (",\n");
913         if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
914           n_print ("%s%s arg%d", indent,
915               g_type_name (query->param_types[j]), j);
916         } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
917           n_print ("%s%s arg%d", indent,
918               g_type_name (query->param_types[j]), j);
919         } else {
920           n_print ("%s%s* arg%d", indent,
921               g_type_name (query->param_types[j]), j);
922         }
923       }
924
925       if (k == 0) {
926         g_print (",\n");
927         n_print ("%sgpointer user_data);\n", indent);
928       } else
929         g_print (");\n");
930
931       g_free (indent);
932     }
933
934     if (found_signals) {
935       g_slist_foreach (found_signals, (GFunc) g_free, NULL);
936       g_slist_free (found_signals);
937     }
938   }
939 }
940
941 static void
942 print_children_info (GstElement * element)
943 {
944   GList *children;
945
946   if (!GST_IS_BIN (element))
947     return;
948
949   children = (GList *) GST_BIN (element)->children;
950   if (children) {
951     n_print ("\n");
952     n_print ("Children:\n");
953   }
954
955   while (children) {
956     n_print ("  %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
957     children = g_list_next (children);
958   }
959 }
960
961 static void
962 print_blacklist (void)
963 {
964   GList *plugins, *cur;
965   gint count = 0;
966
967   g_print ("%s\n", _("Blacklisted files:"));
968
969   plugins = gst_registry_get_plugin_list (gst_registry_get ());
970   for (cur = plugins; cur != NULL; cur = g_list_next (cur)) {
971     GstPlugin *plugin = (GstPlugin *) (cur->data);
972     if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
973       g_print ("  %s\n", gst_plugin_get_name (plugin));
974       count++;
975     }
976   }
977
978   g_print ("\n");
979   g_print (_("Total count: "));
980   g_print (ngettext ("%d blacklisted file", "%d blacklisted files", count),
981       count);
982   g_print ("\n");
983   gst_plugin_list_free (plugins);
984 }
985
986 static void
987 print_element_list (gboolean print_all)
988 {
989   int plugincount = 0, featurecount = 0, blacklistcount = 0;
990   GList *plugins, *orig_plugins;
991
992   orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
993   while (plugins) {
994     GList *features, *orig_features;
995     GstPlugin *plugin;
996
997     plugin = (GstPlugin *) (plugins->data);
998     plugins = g_list_next (plugins);
999     plugincount++;
1000
1001     if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
1002       blacklistcount++;
1003       continue;
1004     }
1005
1006     orig_features = features =
1007         gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1008         gst_plugin_get_name (plugin));
1009     while (features) {
1010       GstPluginFeature *feature;
1011
1012       if (G_UNLIKELY (features->data == NULL))
1013         goto next;
1014       feature = GST_PLUGIN_FEATURE (features->data);
1015       featurecount++;
1016
1017       if (GST_IS_ELEMENT_FACTORY (feature)) {
1018         GstElementFactory *factory;
1019
1020         factory = GST_ELEMENT_FACTORY (feature);
1021         if (print_all)
1022           print_element_info (factory, TRUE);
1023         else
1024           g_print ("%s:  %s: %s\n", gst_plugin_get_name (plugin),
1025               GST_OBJECT_NAME (factory),
1026               gst_element_factory_get_metadata (factory,
1027                   GST_ELEMENT_METADATA_LONGNAME));
1028 #if 0
1029       } else if (GST_IS_INDEX_FACTORY (feature)) {
1030         GstIndexFactory *factory;
1031
1032         factory = GST_INDEX_FACTORY (feature);
1033         if (!print_all)
1034           g_print ("%s:  %s: %s\n", plugin->desc.name,
1035               GST_OBJECT_NAME (factory), factory->longdesc);
1036 #endif
1037       } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1038         GstTypeFindFactory *factory;
1039         const gchar *const *extensions;
1040
1041         factory = GST_TYPE_FIND_FACTORY (feature);
1042         if (!print_all)
1043           g_print ("%s: %s: ", gst_plugin_get_name (plugin),
1044               gst_plugin_feature_get_name (feature));
1045
1046         extensions = gst_type_find_factory_get_extensions (factory);
1047         if (extensions != NULL) {
1048           guint i = 0;
1049
1050           while (extensions[i]) {
1051             if (!print_all)
1052               g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1053             i++;
1054           }
1055           if (!print_all)
1056             g_print ("\n");
1057         } else {
1058           if (!print_all)
1059             g_print ("no extensions\n");
1060         }
1061       } else {
1062         if (!print_all)
1063           n_print ("%s:  %s (%s)\n", gst_plugin_get_name (plugin),
1064               GST_OBJECT_NAME (feature), g_type_name (G_OBJECT_TYPE (feature)));
1065       }
1066
1067     next:
1068       features = g_list_next (features);
1069     }
1070
1071     gst_plugin_feature_list_free (orig_features);
1072   }
1073
1074   gst_plugin_list_free (orig_plugins);
1075
1076   g_print ("\n");
1077   g_print (_("Total count: "));
1078   g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1079   if (blacklistcount) {
1080     g_print (" (");
1081     g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1082             blacklistcount), blacklistcount);
1083     g_print (" not shown)");
1084   }
1085   g_print (", ");
1086   g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1087   g_print ("\n");
1088 }
1089
1090 static void
1091 print_all_uri_handlers (void)
1092 {
1093   GList *plugins, *p, *features, *f;
1094
1095   plugins = gst_registry_get_plugin_list (gst_registry_get ());
1096
1097   for (p = plugins; p; p = p->next) {
1098     GstPlugin *plugin = (GstPlugin *) (p->data);
1099
1100     features =
1101         gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1102         gst_plugin_get_name (plugin));
1103
1104     for (f = features; f; f = f->next) {
1105       GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1106
1107       if (GST_IS_ELEMENT_FACTORY (feature)) {
1108         GstElementFactory *factory;
1109         GstElement *element;
1110
1111         factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1112         if (!factory) {
1113           g_print ("element plugin %s couldn't be loaded\n",
1114               gst_plugin_get_name (plugin));
1115           continue;
1116         }
1117
1118         element = gst_element_factory_create (factory, NULL);
1119         if (!element) {
1120           g_print ("couldn't construct element for %s for some reason\n",
1121               GST_OBJECT_NAME (factory));
1122           gst_object_unref (factory);
1123           continue;
1124         }
1125
1126         if (GST_IS_URI_HANDLER (element)) {
1127           const gchar *const *uri_protocols;
1128           const gchar *dir;
1129           gchar *joined;
1130
1131           switch (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element))) {
1132             case GST_URI_SRC:
1133               dir = "read";
1134               break;
1135             case GST_URI_SINK:
1136               dir = "write";
1137               break;
1138             default:
1139               dir = "unknown";
1140               break;
1141           }
1142
1143           uri_protocols =
1144               gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
1145           joined = g_strjoinv (", ", (gchar **) uri_protocols);
1146
1147           g_print ("%s (%s, rank %u): %s\n",
1148               gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)), dir,
1149               gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1150               joined);
1151
1152           g_free (joined);
1153         }
1154
1155         gst_object_unref (element);
1156         gst_object_unref (factory);
1157       }
1158     }
1159
1160     gst_plugin_feature_list_free (features);
1161   }
1162
1163   gst_plugin_list_free (plugins);
1164 }
1165
1166 static void
1167 print_plugin_info (GstPlugin * plugin)
1168 {
1169   const gchar *release_date = gst_plugin_get_release_date_string (plugin);
1170   const gchar *filename = gst_plugin_get_filename (plugin);
1171
1172   n_print ("Plugin Details:\n");
1173   n_print ("  %-25s%s\n", "Name", gst_plugin_get_name (plugin));
1174   n_print ("  %-25s%s\n", "Description", gst_plugin_get_description (plugin));
1175   n_print ("  %-25s%s\n", "Filename", (filename != NULL) ? filename : "(null)");
1176   n_print ("  %-25s%s\n", "Version", gst_plugin_get_version (plugin));
1177   n_print ("  %-25s%s\n", "License", gst_plugin_get_license (plugin));
1178   n_print ("  %-25s%s\n", "Source module", gst_plugin_get_source (plugin));
1179
1180   if (release_date != NULL) {
1181     const gchar *tz = "(UTC)";
1182     gchar *str, *sep;
1183
1184     /* may be: YYYY-MM-DD or YYYY-MM-DDTHH:MMZ */
1185     /* YYYY-MM-DDTHH:MMZ => YYYY-MM-DD HH:MM (UTC) */
1186     str = g_strdup (release_date);
1187     sep = strstr (str, "T");
1188     if (sep != NULL) {
1189       *sep = ' ';
1190       sep = strstr (sep + 1, "Z");
1191       if (sep != NULL)
1192         *sep = ' ';
1193     } else {
1194       tz = "";
1195     }
1196     n_print ("  %-25s%s%s\n", "Source release date", str, tz);
1197     g_free (str);
1198   }
1199   n_print ("  %-25s%s\n", "Binary package", gst_plugin_get_package (plugin));
1200   n_print ("  %-25s%s\n", "Origin URL", gst_plugin_get_origin (plugin));
1201   n_print ("\n");
1202 }
1203
1204 static void
1205 print_plugin_features (GstPlugin * plugin)
1206 {
1207   GList *features, *origlist;
1208   gint num_features = 0;
1209   gint num_elements = 0;
1210   gint num_typefinders = 0;
1211   gint num_indexes = 0;
1212   gint num_other = 0;
1213
1214   origlist = features =
1215       gst_registry_get_feature_list_by_plugin (gst_registry_get (),
1216       gst_plugin_get_name (plugin));
1217
1218   while (features) {
1219     GstPluginFeature *feature;
1220
1221     feature = GST_PLUGIN_FEATURE (features->data);
1222
1223     if (GST_IS_ELEMENT_FACTORY (feature)) {
1224       GstElementFactory *factory;
1225
1226       factory = GST_ELEMENT_FACTORY (feature);
1227       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
1228           gst_element_factory_get_metadata (factory,
1229               GST_ELEMENT_METADATA_LONGNAME));
1230       num_elements++;
1231 #if 0
1232     } else if (GST_IS_INDEX_FACTORY (feature)) {
1233       GstIndexFactory *factory;
1234
1235       factory = GST_INDEX_FACTORY (feature);
1236       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1237       num_indexes++;
1238 #endif
1239     } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1240       GstTypeFindFactory *factory;
1241       const gchar *const *extensions;
1242
1243       factory = GST_TYPE_FIND_FACTORY (feature);
1244       extensions = gst_type_find_factory_get_extensions (factory);
1245       if (extensions) {
1246         guint i = 0;
1247
1248         g_print ("  %s: %s: ", gst_plugin_get_name (plugin),
1249             gst_plugin_feature_get_name (feature));
1250         while (extensions[i]) {
1251           g_print ("%s%s", i > 0 ? ", " : "", extensions[i]);
1252           i++;
1253         }
1254         g_print ("\n");
1255       } else
1256         g_print ("  %s: %s: no extensions\n", gst_plugin_get_name (plugin),
1257             gst_plugin_feature_get_name (feature));
1258
1259       num_typefinders++;
1260     } else if (feature) {
1261       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1262           g_type_name (G_OBJECT_TYPE (feature)));
1263       num_other++;
1264     }
1265     num_features++;
1266     features = g_list_next (features);
1267   }
1268
1269   gst_plugin_feature_list_free (origlist);
1270
1271   n_print ("\n");
1272   n_print ("  %d features:\n", num_features);
1273   if (num_elements > 0)
1274     n_print ("  +-- %d elements\n", num_elements);
1275   if (num_typefinders > 0)
1276     n_print ("  +-- %d typefinders\n", num_typefinders);
1277   if (num_indexes > 0)
1278     n_print ("  +-- %d indexes\n", num_indexes);
1279   if (num_other > 0)
1280     n_print ("  +-- %d other objects\n", num_other);
1281
1282   n_print ("\n");
1283 }
1284
1285 static int
1286 print_element_features (const gchar * element_name)
1287 {
1288   GstPluginFeature *feature;
1289
1290   /* FIXME implement other pretty print function for these */
1291 #if 0
1292   feature = gst_default_registry_find_feature (element_name,
1293       GST_TYPE_INDEX_FACTORY);
1294   if (feature) {
1295     n_print ("%s: an index\n", element_name);
1296     return 0;
1297   }
1298 #endif
1299   feature = gst_registry_find_feature (gst_registry_get (), element_name,
1300       GST_TYPE_TYPE_FIND_FACTORY);
1301   if (feature) {
1302     n_print ("%s: a typefind function\n", element_name);
1303     return 0;
1304   }
1305
1306   return -1;
1307 }
1308
1309 static int
1310 print_element_info (GstElementFactory * factory, gboolean print_names)
1311 {
1312   GstElement *element;
1313   GstPlugin *plugin;
1314   gint maxlevel = 0;
1315
1316   factory =
1317       GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1318           (factory)));
1319
1320   if (!factory) {
1321     g_print ("element plugin couldn't be loaded\n");
1322     return -1;
1323   }
1324
1325   element = gst_element_factory_create (factory, NULL);
1326   if (!element) {
1327     gst_object_unref (factory);
1328     g_print ("couldn't construct element for some reason\n");
1329     return -1;
1330   }
1331
1332   if (print_names)
1333     _name = g_strdup_printf ("%s: ", GST_OBJECT_NAME (factory));
1334   else
1335     _name = NULL;
1336
1337   print_factory_details_info (factory);
1338
1339   plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory));
1340   if (plugin) {
1341     print_plugin_info (plugin);
1342     gst_object_unref (plugin);
1343   }
1344
1345   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1346   print_interfaces (G_OBJECT_TYPE (element));
1347
1348   print_pad_templates_info (element, factory);
1349   print_element_flag_info (element);
1350   print_implementation_info (element);
1351   print_clocking_info (element);
1352   print_index_info (element);
1353   print_uri_handler_info (element);
1354   print_pad_info (element);
1355   print_element_properties_info (element);
1356   print_signal_info (element);
1357   print_children_info (element);
1358
1359   gst_object_unref (element);
1360   gst_object_unref (factory);
1361   g_free (_name);
1362
1363   return 0;
1364 }
1365
1366
1367 static void
1368 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1369 {
1370   GstPadDirection direction;
1371   const gchar *type_name;
1372   const gchar *klass;
1373   const GList *static_templates, *l;
1374   GstCaps *caps = NULL;
1375   guint i, num;
1376
1377   klass =
1378       gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
1379   g_return_if_fail (klass != NULL);
1380
1381   if (strstr (klass, "Demuxer") ||
1382       strstr (klass, "Decoder") ||
1383       strstr (klass, "Depay") || strstr (klass, "Parser")) {
1384     type_name = "decoder";
1385     direction = GST_PAD_SINK;
1386   } else if (strstr (klass, "Muxer") ||
1387       strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1388     type_name = "encoder";
1389     direction = GST_PAD_SRC;
1390   } else {
1391     return;
1392   }
1393
1394   /* decoder/demuxer sink pads should always be static and there should only
1395    * be one, the same applies to encoders/muxers and source pads */
1396   static_templates = gst_element_factory_get_static_pad_templates (factory);
1397   for (l = static_templates; l != NULL; l = l->next) {
1398     GstStaticPadTemplate *tmpl = NULL;
1399
1400     tmpl = (GstStaticPadTemplate *) l->data;
1401     if (tmpl->direction == direction) {
1402       caps = gst_static_pad_template_get_caps (tmpl);
1403       break;
1404     }
1405   }
1406
1407   if (caps == NULL) {
1408     g_printerr ("Couldn't find static pad template for %s '%s'\n",
1409         type_name, GST_OBJECT_NAME (factory));
1410     return;
1411   }
1412
1413   caps = gst_caps_make_writable (caps);
1414   num = gst_caps_get_size (caps);
1415   for (i = 0; i < num; ++i) {
1416     GstStructure *s;
1417     gchar *s_str;
1418
1419     s = gst_caps_get_structure (caps, i);
1420     /* remove fields that are almost always just MIN-MAX of some sort
1421      * in order to make the caps look less messy */
1422     gst_structure_remove_field (s, "pixel-aspect-ratio");
1423     gst_structure_remove_field (s, "framerate");
1424     gst_structure_remove_field (s, "channels");
1425     gst_structure_remove_field (s, "width");
1426     gst_structure_remove_field (s, "height");
1427     gst_structure_remove_field (s, "rate");
1428     gst_structure_remove_field (s, "depth");
1429     gst_structure_remove_field (s, "clock-rate");
1430     s_str = gst_structure_to_string (s);
1431     g_print ("%s-%s\n", type_name, s_str);
1432     g_free (s_str);
1433   }
1434   gst_caps_unref (caps);
1435 }
1436
1437 static void
1438 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1439 {
1440   const gchar *const *protocols;
1441
1442   protocols = gst_element_factory_get_uri_protocols (factory);
1443   if (protocols != NULL && *protocols != NULL) {
1444     switch (gst_element_factory_get_uri_type (factory)) {
1445       case GST_URI_SINK:
1446         while (*protocols != NULL) {
1447           g_print ("urisink-%s\n", *protocols);
1448           ++protocols;
1449         }
1450         break;
1451       case GST_URI_SRC:
1452         while (*protocols != NULL) {
1453           g_print ("urisource-%s\n", *protocols);
1454           ++protocols;
1455         }
1456         break;
1457       default:
1458         break;
1459     }
1460   }
1461 }
1462
1463 static void
1464 print_plugin_automatic_install_info (GstPlugin * plugin)
1465 {
1466   GList *features, *l;
1467
1468   /* not interested in typefind factories, only element factories */
1469   features = gst_registry_get_feature_list (gst_registry_get (),
1470       GST_TYPE_ELEMENT_FACTORY);
1471
1472   for (l = features; l != NULL; l = l->next) {
1473     GstPluginFeature *feature;
1474     GstPlugin *feature_plugin;
1475
1476     feature = GST_PLUGIN_FEATURE (l->data);
1477
1478     /* only interested in the ones that are in the plugin we just loaded */
1479     feature_plugin = gst_plugin_feature_get_plugin (feature);
1480     if (feature_plugin == plugin) {
1481       GstElementFactory *factory;
1482
1483       g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1484
1485       factory = GST_ELEMENT_FACTORY (feature);
1486       print_plugin_automatic_install_info_protocols (factory);
1487       print_plugin_automatic_install_info_codecs (factory);
1488     }
1489     if (feature_plugin)
1490       gst_object_unref (feature_plugin);
1491   }
1492
1493   g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1494   g_list_free (features);
1495 }
1496
1497 static void
1498 print_all_plugin_automatic_install_info (void)
1499 {
1500   GList *plugins, *orig_plugins;
1501
1502   orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
1503   while (plugins) {
1504     GstPlugin *plugin;
1505
1506     plugin = (GstPlugin *) (plugins->data);
1507     plugins = g_list_next (plugins);
1508
1509     print_plugin_automatic_install_info (plugin);
1510   }
1511   gst_plugin_list_free (orig_plugins);
1512 }
1513
1514 int
1515 main (int argc, char *argv[])
1516 {
1517   gboolean print_all = FALSE;
1518   gboolean do_print_blacklist = FALSE;
1519   gboolean plugin_name = FALSE;
1520   gboolean print_aii = FALSE;
1521   gboolean uri_handlers = FALSE;
1522   gboolean check_exists = FALSE;
1523   gchar *min_version = NULL;
1524   guint minver_maj = GST_VERSION_MAJOR;
1525   guint minver_min = GST_VERSION_MINOR;
1526   guint minver_micro = 0;
1527 #ifndef GST_DISABLE_OPTION_PARSING
1528   GOptionEntry options[] = {
1529     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1530         N_("Print all elements"), NULL},
1531     {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1532         N_("Print list of blacklisted files"), NULL},
1533     {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1534         N_("Print a machine-parsable list of features the specified plugin "
1535               "or all plugins provide.\n                                       "
1536               "Useful in connection with external automatic plugin "
1537               "installation mechanisms"), NULL},
1538     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1539         N_("List the plugin contents"), NULL},
1540     {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists,
1541         N_("Check if the specified element or plugin exists"), NULL},
1542     {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version,
1543         N_
1544           ("When checking if an element or plugin exists, also check that its "
1545               "version is at least the version specified"), NULL},
1546     {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1547           N_
1548           ("Print supported URI schemes, with the elements that implement them"),
1549         NULL},
1550     GST_TOOLS_GOPTION_VERSION,
1551     {NULL}
1552   };
1553   GOptionContext *ctx;
1554   GError *err = NULL;
1555 #endif
1556
1557 #ifdef ENABLE_NLS
1558   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1559   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1560   textdomain (GETTEXT_PACKAGE);
1561 #endif
1562
1563   g_set_prgname ("gst-inspect-" GST_API_VERSION);
1564
1565 #ifndef GST_DISABLE_OPTION_PARSING
1566   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1567   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1568   g_option_context_add_group (ctx, gst_init_get_option_group ());
1569   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1570     g_printerr ("Error initializing: %s\n", err->message);
1571     return -1;
1572   }
1573   g_option_context_free (ctx);
1574 #else
1575   gst_init (&argc, &argv);
1576 #endif
1577
1578   gst_tools_print_version ();
1579
1580   if (print_all && argc > 1) {
1581     g_printerr ("-a requires no extra arguments\n");
1582     return -1;
1583   }
1584
1585   if (uri_handlers && argc > 1) {
1586     g_printerr ("-u requires no extra arguments\n");
1587     return -1;
1588   }
1589
1590   /* --atleast-version implies --exists */
1591   if (min_version != NULL) {
1592     if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min,
1593             &minver_micro) < 2) {
1594       g_printerr ("Can't parse version '%s' passed to --atleast-version\n",
1595           min_version);
1596       return -1;
1597     }
1598     check_exists = TRUE;
1599   }
1600
1601   if (check_exists) {
1602     int exit_code;
1603
1604     if (argc == 1) {
1605       g_printerr ("--exists requires an extra command line argument\n");
1606       exit_code = -1;
1607     } else {
1608       if (!plugin_name) {
1609         GstPluginFeature *feature;
1610
1611         feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]);
1612         if (feature != NULL && gst_plugin_feature_check_version (feature,
1613                 minver_maj, minver_min, minver_micro)) {
1614           exit_code = 0;
1615         } else {
1616           exit_code = 1;
1617         }
1618       } else {
1619         /* FIXME: support checking for plugins too */
1620         g_printerr ("Checking for plugins is not supported yet\n");
1621         exit_code = -1;
1622       }
1623     }
1624     return exit_code;
1625   }
1626
1627   /* if no arguments, print out list of elements */
1628   if (uri_handlers) {
1629     print_all_uri_handlers ();
1630   } else if (argc == 1 || print_all) {
1631     if (do_print_blacklist)
1632       print_blacklist ();
1633     else {
1634       if (print_aii)
1635         print_all_plugin_automatic_install_info ();
1636       else
1637         print_element_list (print_all);
1638     }
1639   } else {
1640     /* else we try to get a factory */
1641     GstElementFactory *factory;
1642     GstPlugin *plugin;
1643     const char *arg = argv[argc - 1];
1644     int retval;
1645
1646     if (!plugin_name) {
1647       factory = gst_element_factory_find (arg);
1648
1649       /* if there's a factory, print out the info */
1650       if (factory) {
1651         retval = print_element_info (factory, print_all);
1652         gst_object_unref (factory);
1653       } else {
1654         retval = print_element_features (arg);
1655       }
1656     } else {
1657       retval = -1;
1658     }
1659
1660     /* otherwise check if it's a plugin */
1661     if (retval) {
1662       plugin = gst_registry_find_plugin (gst_registry_get (), arg);
1663
1664       /* if there is such a plugin, print out info */
1665       if (plugin) {
1666         if (print_aii) {
1667           print_plugin_automatic_install_info (plugin);
1668         } else {
1669           print_plugin_info (plugin);
1670           print_plugin_features (plugin);
1671         }
1672       } else {
1673         GError *error = NULL;
1674
1675         if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1676           plugin = gst_plugin_load_file (arg, &error);
1677
1678           if (plugin) {
1679             if (print_aii) {
1680               print_plugin_automatic_install_info (plugin);
1681             } else {
1682               print_plugin_info (plugin);
1683               print_plugin_features (plugin);
1684             }
1685           } else {
1686             g_printerr (_("Could not load plugin file: %s\n"), error->message);
1687             g_error_free (error);
1688             return -1;
1689           }
1690         } else {
1691           g_printerr (_("No such element or plugin '%s'\n"), arg);
1692           return -1;
1693         }
1694       }
1695     }
1696   }
1697
1698   return 0;
1699 }