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