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