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