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