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