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