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