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