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