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