Merge branch 'work'
[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 <gst/controller/gstcontroller.h>
29
30 #include "tools.h"
31
32 #include <string.h>
33 #include <locale.h>
34 #include <glib/gprintf.h>
35
36 static char *_name = NULL;
37
38 static int print_element_info (GstElementFactory * factory,
39     gboolean print_names);
40
41 static void
42 n_print (const char *format, ...)
43 {
44   va_list args;
45
46   if (_name)
47     g_print ("%s", _name);
48
49   va_start (args, format);
50   g_vprintf (format, args);
51   va_end (args);
52 }
53
54 static gboolean
55 print_field (GQuark field, const GValue * value, gpointer pfx)
56 {
57   gchar *str = gst_value_serialize (value);
58
59   n_print ("%s  %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
60   g_free (str);
61   return TRUE;
62 }
63
64 static void
65 print_caps (const GstCaps * caps, const gchar * pfx)
66 {
67   guint i;
68
69   g_return_if_fail (caps != NULL);
70
71   if (gst_caps_is_any (caps)) {
72     n_print ("%sANY\n", pfx);
73     return;
74   }
75   if (gst_caps_is_empty (caps)) {
76     n_print ("%sEMPTY\n", pfx);
77     return;
78   }
79
80   for (i = 0; i < gst_caps_get_size (caps); i++) {
81     GstStructure *structure = gst_caps_get_structure (caps, i);
82
83     n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
84     gst_structure_foreach (structure, print_field, (gpointer) pfx);
85   }
86 }
87
88 #if 0
89 static void
90 print_formats (const GstFormat * formats)
91 {
92   while (formats && *formats) {
93     const GstFormatDefinition *definition;
94
95     definition = gst_format_get_details (*formats);
96     if (definition)
97       n_print ("\t\t(%d):\t%s (%s)\n", *formats,
98           definition->nick, definition->description);
99     else
100       n_print ("\t\t(%d):\tUnknown format\n", *formats);
101
102     formats++;
103   }
104 }
105 #endif
106
107 static void
108 print_query_types (const GstQueryType * types)
109 {
110   while (types && *types) {
111     const GstQueryTypeDefinition *definition;
112
113     definition = gst_query_type_get_details (*types);
114     if (definition)
115       n_print ("\t\t(%d):\t%s (%s)\n", *types,
116           definition->nick, definition->description);
117     else
118       n_print ("\t\t(%d):\tUnknown query format\n", *types);
119
120     types++;
121   }
122 }
123
124 #if 0
125 static void
126 print_event_masks (const GstEventMask * masks)
127 {
128   GType event_type;
129   GEnumClass *klass;
130   GType event_flags;
131   GFlagsClass *flags_class = NULL;
132
133   event_type = gst_event_type_get_type ();
134   klass = (GEnumClass *) g_type_class_ref (event_type);
135
136   while (masks && masks->type) {
137     GEnumValue *value;
138     gint flags = 0, index = 0;
139
140     switch (masks->type) {
141       case GST_EVENT_SEEK:
142         flags = masks->flags;
143         event_flags = gst_seek_type_get_type ();
144         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
145         break;
146       default:
147         break;
148     }
149
150     value = g_enum_get_value (klass, masks->type);
151     g_print ("\t\t%s ", value->value_nick);
152
153     while (flags) {
154       GFlagsValue *value;
155
156       if (flags & 1) {
157         value = g_flags_get_first_value (flags_class, 1 << index);
158
159         if (value)
160           g_print ("| %s ", value->value_nick);
161         else
162           g_print ("| ? ");
163       }
164       flags >>= 1;
165       index++;
166     }
167     g_print ("\n");
168
169     masks++;
170   }
171 }
172 #endif
173
174 static const char *
175 get_rank_name (gint rank)
176 {
177   switch (rank) {
178     case GST_RANK_NONE:
179       return "none";
180     case GST_RANK_MARGINAL:
181       return "marginal";
182     case GST_RANK_SECONDARY:
183       return "secondary";
184     case GST_RANK_PRIMARY:
185       return "primary";
186     default:
187       return "unknown";
188   }
189 }
190
191 static void
192 print_factory_details_info (GstElementFactory * factory)
193 {
194   n_print ("Factory Details:\n");
195   n_print ("  Long name:\t%s\n", factory->details.longname);
196   n_print ("  Class:\t%s\n", factory->details.klass);
197   n_print ("  Description:\t%s\n", factory->details.description);
198   n_print ("  Author(s):\t%s\n", factory->details.author);
199   n_print ("  Rank:\t\t%s (%d)\n",
200       get_rank_name (GST_PLUGIN_FEATURE (factory)->rank),
201       GST_PLUGIN_FEATURE (factory)->rank);
202   n_print ("\n");
203 }
204
205 static void
206 print_hierarchy (GType type, gint level, gint * maxlevel)
207 {
208   GType parent;
209   gint i;
210
211   parent = g_type_parent (type);
212
213   *maxlevel = *maxlevel + 1;
214   level++;
215
216   if (parent)
217     print_hierarchy (parent, level, maxlevel);
218
219   if (_name)
220     g_print ("%s", _name);
221
222   for (i = 1; i < *maxlevel - level; i++)
223     g_print ("      ");
224   if (*maxlevel - level)
225     g_print (" +----");
226
227   g_print ("%s\n", g_type_name (type));
228
229   if (level == 1)
230     n_print ("\n");
231 }
232
233 static void
234 print_interfaces (GType type)
235 {
236   guint n_ifaces;
237   GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
238
239   if (ifaces) {
240     if (n_ifaces) {
241       if (_name)
242         g_print ("%s", _name);
243       g_print (_("Implemented Interfaces:\n"));
244       iface = ifaces;
245       while (*iface) {
246         if (_name)
247           g_print ("%s", _name);
248         g_print ("  %s\n", g_type_name (*iface));
249         iface++;
250       }
251       if (_name)
252         g_print ("%s", _name);
253       g_print ("\n");
254     }
255     g_free (ifaces);
256   }
257 }
258
259 static gchar *
260 flags_to_string (GFlagsValue * vals, guint flags)
261 {
262   GString *s = NULL;
263   guint flags_left, i;
264
265   /* first look for an exact match and count the number of values */
266   for (i = 0; vals[i].value_name != NULL; ++i) {
267     if (vals[i].value == flags)
268       return g_strdup (vals[i].value_nick);
269   }
270
271   s = g_string_new (NULL);
272
273   /* we assume the values are sorted from lowest to highest value */
274   flags_left = flags;
275   while (i > 0) {
276     --i;
277     if (vals[i].value != 0 && (flags_left & vals[i].value) == vals[i].value) {
278       if (s->len > 0)
279         g_string_append (s, " | ");
280       g_string_append (s, vals[i].value_nick);
281       flags_left -= vals[i].value;
282       if (flags_left == 0)
283         break;
284     }
285   }
286
287   if (s->len == 0)
288     g_string_assign (s, "(none)");
289
290   return g_string_free (s, FALSE);
291 }
292
293 static void
294 print_element_properties_info (GstElement * element)
295 {
296   GParamSpec **property_specs;
297   guint num_properties, i;
298   gboolean readable;
299   gboolean first_flag;
300
301   property_specs = g_object_class_list_properties
302       (G_OBJECT_GET_CLASS (element), &num_properties);
303   n_print ("\n");
304   n_print ("Element Properties:\n");
305
306   for (i = 0; i < num_properties; i++) {
307     GValue value = { 0, };
308     GParamSpec *param = property_specs[i];
309
310     readable = FALSE;
311
312     g_value_init (&value, param->value_type);
313
314     n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
315         g_param_spec_get_blurb (param));
316
317     first_flag = TRUE;
318     n_print ("%-23.23s flags: ", "");
319     if (param->flags & G_PARAM_READABLE) {
320       g_object_get_property (G_OBJECT (element), param->name, &value);
321       readable = TRUE;
322       if (!first_flag)
323         g_print (", ");
324       else
325         first_flag = FALSE;
326       g_print (_("readable"));
327     }
328     if (param->flags & G_PARAM_WRITABLE) {
329       if (!first_flag)
330         g_print (", ");
331       else
332         first_flag = FALSE;
333       g_print (_("writable"));
334     }
335     if (param->flags & GST_PARAM_CONTROLLABLE) {
336       if (!first_flag)
337         g_print (", ");
338       g_print (_("controllable"));
339     }
340     n_print ("\n");
341
342     switch (G_VALUE_TYPE (&value)) {
343       case G_TYPE_STRING:
344       {
345         GParamSpecString *pstring = G_PARAM_SPEC_STRING (param);
346
347         n_print ("%-23.23s String. ", "");
348
349         if (pstring->default_value == NULL)
350           g_print ("Default: null ");
351         else
352           g_print ("Default: \"%s\" ", pstring->default_value);
353
354         if (readable) {
355           const char *string_val = g_value_get_string (&value);
356
357           if (string_val == NULL)
358             g_print ("Current: null");
359           else
360             g_print ("Current: \"%s\"", string_val);
361         }
362         break;
363       }
364       case G_TYPE_BOOLEAN:
365       {
366         GParamSpecBoolean *pboolean = G_PARAM_SPEC_BOOLEAN (param);
367
368         n_print ("%-23.23s Boolean. ", "");
369         g_print ("Default: %s ", (pboolean->default_value ? "true" : "false"));
370         if (readable)
371           g_print ("Current: %s",
372               (g_value_get_boolean (&value) ? "true" : "false"));
373         break;
374       }
375       case G_TYPE_ULONG:
376       {
377         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
378
379         n_print ("%-23.23s Unsigned Long. ", "");
380         g_print ("Range: %lu - %lu Default: %lu ",
381             pulong->minimum, pulong->maximum, pulong->default_value);
382         if (readable)
383           g_print ("Current: %lu", g_value_get_ulong (&value));
384         break;
385       }
386       case G_TYPE_LONG:
387       {
388         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
389
390         n_print ("%-23.23s Long. ", "");
391         g_print ("Range: %ld - %ld Default: %ld ",
392             plong->minimum, plong->maximum, plong->default_value);
393         if (readable)
394           g_print ("Current: %ld", g_value_get_long (&value));
395         break;
396       }
397       case G_TYPE_UINT:
398       {
399         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
400
401         n_print ("%-23.23s Unsigned Integer. ", "");
402         g_print ("Range: %u - %u Default: %u ",
403             puint->minimum, puint->maximum, puint->default_value);
404         if (readable)
405           g_print ("Current: %u", g_value_get_uint (&value));
406         break;
407       }
408       case G_TYPE_INT:
409       {
410         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
411
412         n_print ("%-23.23s Integer. ", "");
413         g_print ("Range: %d - %d Default: %d ",
414             pint->minimum, pint->maximum, pint->default_value);
415         if (readable)
416           g_print ("Current: %d", g_value_get_int (&value));
417         break;
418       }
419       case G_TYPE_UINT64:
420       {
421         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
422
423         n_print ("%-23.23s Unsigned Integer64. ", "");
424         g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
425             " Default: %" G_GUINT64_FORMAT " ",
426             puint64->minimum, puint64->maximum, puint64->default_value);
427         if (readable)
428           g_print ("Current: %" G_GUINT64_FORMAT, g_value_get_uint64 (&value));
429         break;
430       }
431       case G_TYPE_INT64:
432       {
433         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
434
435         n_print ("%-23.23s Integer64. ", "");
436         g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
437             " Default: %" G_GINT64_FORMAT " ",
438             pint64->minimum, pint64->maximum, pint64->default_value);
439         if (readable)
440           g_print ("Current: %" G_GINT64_FORMAT, g_value_get_int64 (&value));
441         break;
442       }
443       case G_TYPE_FLOAT:
444       {
445         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
446
447         n_print ("%-23.23s Float. ", "");
448         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
449             pfloat->minimum, pfloat->maximum, pfloat->default_value);
450         if (readable)
451           g_print ("Current: %15.7g", 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, pdouble->default_value);
461         if (readable)
462           g_print ("Current: %15.7g", g_value_get_double (&value));
463         break;
464       }
465       default:
466         if (param->value_type == GST_TYPE_CAPS) {
467           const GstCaps *caps = gst_value_get_caps (&value);
468
469           if (!caps)
470             n_print ("%-23.23s Caps (NULL)", "");
471           else {
472             print_caps (caps, "                           ");
473           }
474         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
475           GParamSpecEnum *penum = G_PARAM_SPEC_ENUM (param);
476           GEnumValue *values;
477           guint j = 0;
478           gint enum_value;
479           const gchar *def_val_nick = "", *cur_val_nick = "";
480
481           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
482           enum_value = g_value_get_enum (&value);
483
484           while (values[j].value_name) {
485             if (values[j].value == enum_value)
486               cur_val_nick = values[j].value_nick;
487             if (values[j].value == penum->default_value)
488               def_val_nick = values[j].value_nick;
489             j++;
490           }
491
492           n_print
493               ("%-23.23s Enum \"%s\" Default: %d, \"%s\" Current: %d, \"%s\"",
494               "", g_type_name (G_VALUE_TYPE (&value)), penum->default_value,
495               def_val_nick, enum_value, cur_val_nick);
496
497           j = 0;
498           while (values[j].value_name) {
499             g_print ("\n");
500             if (_name)
501               g_print ("%s", _name);
502             g_print ("%-23.23s    (%d): %-16s - %s", "",
503                 values[j].value, values[j].value_nick, values[j].value_name);
504             j++;
505           }
506           /* g_type_class_unref (ec); */
507         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
508           GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
509           GFlagsValue *vals;
510           gchar *cur, *def;
511
512           vals = pflags->flags_class->values;
513
514           cur = flags_to_string (vals, g_value_get_flags (&value));
515           def = flags_to_string (vals, pflags->default_value);
516
517           n_print
518               ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\" Current: 0x%08x, \"%s\"",
519               "", g_type_name (G_VALUE_TYPE (&value)), pflags->default_value,
520               def, g_value_get_flags (&value), cur);
521
522           while (vals[0].value_name) {
523             g_print ("\n");
524             if (_name)
525               g_print ("%s", _name);
526             g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
527                 vals[0].value, vals[0].value_nick, vals[0].value_name);
528             ++vals;
529           }
530
531           g_free (cur);
532           g_free (def);
533         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
534           n_print ("%-23.23s Object of type \"%s\"", "",
535               g_type_name (param->value_type));
536         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
537           n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
538               g_type_name (param->value_type));
539         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
540           if (param->value_type != G_TYPE_POINTER) {
541             n_print ("%-23.23s Pointer of type \"%s\".", "",
542                 g_type_name (param->value_type));
543           } else {
544             n_print ("%-23.23s Pointer.", "");
545           }
546         } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
547           GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);
548
549           if (pvarray->element_spec) {
550             n_print ("%-23.23s Array of GValues of type \"%s\"", "",
551                 g_type_name (pvarray->element_spec->value_type));
552           } else {
553             n_print ("%-23.23s Array of GValues", "");
554           }
555         } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
556           GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
557
558           n_print ("%-23.23s Fraction. ", "");
559
560           g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
561               pfraction->min_num, pfraction->min_den,
562               pfraction->max_num, pfraction->max_den,
563               pfraction->def_num, pfraction->def_den);
564           if (readable)
565             g_print ("Current: %d/%d",
566                 gst_value_get_fraction_numerator (&value),
567                 gst_value_get_fraction_denominator (&value));
568
569         } else if (GST_IS_PARAM_SPEC_MINI_OBJECT (param)) {
570           n_print ("%-23.23s MiniObject of type \"%s\"", "",
571               g_type_name (param->value_type));
572         } else {
573           n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
574               g_type_name (param->value_type));
575         }
576         break;
577     }
578     if (!readable)
579       g_print (" Write only\n");
580     else
581       g_print ("\n");
582
583     g_value_reset (&value);
584   }
585   if (num_properties == 0)
586     n_print ("  none\n");
587
588   g_free (property_specs);
589 }
590
591 static void
592 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
593 {
594   GstElementClass *gstelement_class;
595   const GList *pads;
596   GstStaticPadTemplate *padtemplate;
597
598   n_print ("Pad Templates:\n");
599   if (!factory->numpadtemplates) {
600     n_print ("  none\n");
601     return;
602   }
603
604   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
605
606   pads = factory->staticpadtemplates;
607   while (pads) {
608     padtemplate = (GstStaticPadTemplate *) (pads->data);
609     pads = g_list_next (pads);
610
611     if (padtemplate->direction == GST_PAD_SRC)
612       n_print ("  SRC template: '%s'\n", padtemplate->name_template);
613     else if (padtemplate->direction == GST_PAD_SINK)
614       n_print ("  SINK template: '%s'\n", padtemplate->name_template);
615     else
616       n_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
617
618     if (padtemplate->presence == GST_PAD_ALWAYS)
619       n_print ("    Availability: Always\n");
620     else if (padtemplate->presence == GST_PAD_SOMETIMES)
621       n_print ("    Availability: Sometimes\n");
622     else if (padtemplate->presence == GST_PAD_REQUEST) {
623       n_print ("    Availability: On request\n");
624       n_print ("      Has request_new_pad() function: %s\n",
625           GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
626     } else
627       n_print ("    Availability: UNKNOWN!!!\n");
628
629     if (padtemplate->static_caps.string) {
630       n_print ("    Capabilities:\n");
631       print_caps (gst_static_caps_get (&padtemplate->static_caps), "      ");
632     }
633
634     n_print ("\n");
635   }
636 }
637
638 static void
639 print_element_flag_info (GstElement * element)
640 {
641   gboolean have_flags = FALSE;
642
643   n_print ("\n");
644   n_print ("Element Flags:\n");
645
646   if (!have_flags)
647     n_print ("  no flags set\n");
648
649   if (GST_IS_BIN (element)) {
650     n_print ("\n");
651     n_print ("Bin Flags:\n");
652     if (!have_flags)
653       n_print ("  no flags set\n");
654   }
655 }
656
657 static void
658 print_implementation_info (GstElement * element)
659 {
660   GstObjectClass *gstobject_class;
661   GstElementClass *gstelement_class;
662
663   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
664   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
665
666   n_print ("\n");
667   n_print ("Element Implementation:\n");
668
669   n_print ("  Has change_state() function: %s\n",
670       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
671 #ifndef GST_DISABLE_LOADSAVE
672   n_print ("  Has custom save_thyself() function: %s\n",
673       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
674   n_print ("  Has custom restore_thyself() function: %s\n",
675       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
676 #endif
677 }
678
679 static void
680 print_clocking_info (GstElement * element)
681 {
682   if (!gst_element_requires_clock (element) &&
683       !(gst_element_provides_clock (element) &&
684           gst_element_get_clock (element))) {
685     n_print ("\n");
686     n_print ("Element has no clocking capabilities.");
687     return;
688   }
689
690   n_print ("\n");
691   n_print ("Clocking Interaction:\n");
692   if (gst_element_requires_clock (element)) {
693     n_print ("  element requires a clock\n");
694   }
695
696   if (gst_element_provides_clock (element)) {
697     GstClock *clock;
698
699     clock = gst_element_get_clock (element);
700     if (clock)
701       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
702     else
703       n_print ("  element is supposed to provide a clock but returned NULL\n");
704   }
705 }
706
707 static void
708 print_index_info (GstElement * element)
709 {
710   if (gst_element_is_indexable (element)) {
711     n_print ("\n");
712     n_print ("Indexing capabilities:\n");
713     n_print ("  element can do indexing\n");
714   } else {
715     n_print ("\n");
716     n_print ("Element has no indexing capabilities.\n");
717   }
718 }
719
720 static void
721 print_uri_handler_info (GstElement * element)
722 {
723   if (GST_IS_URI_HANDLER (element)) {
724     const gchar *uri_type;
725     gchar **uri_protocols;
726
727     if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) == GST_URI_SRC)
728       uri_type = "source";
729     else if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (element)) ==
730         GST_URI_SINK)
731       uri_type = "sink";
732     else
733       uri_type = "unknown";
734
735     uri_protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (element));
736
737     n_print ("\n");
738     n_print ("URI handling capabilities:\n");
739     n_print ("  Element can act as %s.\n", uri_type);
740
741     if (uri_protocols && *uri_protocols) {
742       n_print ("  Supported URI protocols:\n");
743       for (; *uri_protocols != NULL; uri_protocols++)
744         n_print ("    %s\n", *uri_protocols);
745     } else {
746       n_print ("  No supported URI protocols\n");
747     }
748   } else {
749     n_print ("Element has no URI handling capabilities.\n");
750   }
751 }
752
753 static void
754 print_pad_info (GstElement * element)
755 {
756   const GList *pads;
757   GstPad *pad;
758
759   n_print ("\n");
760   n_print ("Pads:\n");
761
762   if (!element->numpads) {
763     n_print ("  none\n");
764     return;
765   }
766
767   pads = element->pads;
768   while (pads) {
769     gchar *name;
770
771     pad = GST_PAD (pads->data);
772     pads = g_list_next (pads);
773
774     n_print ("");
775
776     name = gst_pad_get_name (pad);
777     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
778       g_print ("  SRC: '%s'", name);
779     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
780       g_print ("  SINK: '%s'", name);
781     else
782       g_print ("  UNKNOWN!!!: '%s'", name);
783
784     g_free (name);
785
786     g_print ("\n");
787
788     n_print ("    Implementation:\n");
789     if (pad->chainfunc)
790       n_print ("      Has chainfunc(): %s\n",
791           GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
792     if (pad->getrangefunc)
793       n_print ("      Has getrangefunc(): %s\n",
794           GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
795     if (pad->eventfunc != gst_pad_event_default)
796       n_print ("      Has custom eventfunc(): %s\n",
797           GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
798     if (pad->queryfunc != gst_pad_query_default)
799       n_print ("      Has custom queryfunc(): %s\n",
800           GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
801     if (pad->querytypefunc != gst_pad_get_query_types_default) {
802       n_print ("        Provides query types:\n");
803       print_query_types (gst_pad_get_query_types (pad));
804     }
805
806     if (pad->iterintlinkfunc != gst_pad_iterate_internal_links_default)
807       n_print ("      Has custom iterintlinkfunc(): %s\n",
808           GST_DEBUG_FUNCPTR_NAME (pad->iterintlinkfunc));
809
810     if (pad->bufferallocfunc)
811       n_print ("      Has bufferallocfunc(): %s\n",
812           GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
813
814     if (pad->padtemplate)
815       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
816
817     if (pad->caps) {
818       n_print ("    Capabilities:\n");
819       print_caps (pad->caps, "      ");
820     }
821   }
822 }
823
824 #if 0
825 static gint
826 compare_signal_names (GSignalQuery * a, GSignalQuery * b)
827 {
828   return strcmp (a->signal_name, b->signal_name);
829 }
830 #endif
831
832 static void
833 print_signal_info (GstElement * element)
834 {
835   /* Signals/Actions Block */
836   guint *signals;
837   guint nsignals;
838   gint i = 0, j, k;
839   GSignalQuery *query = NULL;
840   GType type;
841   GSList *found_signals, *l;
842
843   for (k = 0; k < 2; k++) {
844     found_signals = NULL;
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_PLUGIN_FEATURE_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_PLUGIN_FEATURE_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_PLUGIN_FEATURE_NAME (feature),
1042               g_type_name (G_OBJECT_TYPE (feature)));
1043       }
1044
1045     next:
1046       features = g_list_next (features);
1047     }
1048
1049     gst_plugin_feature_list_free (orig_features);
1050   }
1051
1052   gst_plugin_list_free (orig_plugins);
1053
1054   g_print ("\n");
1055   g_print (_("Total count: "));
1056   g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
1057   if (blacklistcount) {
1058     g_print (" (");
1059     g_print (ngettext ("%d blacklist entry", "%d blacklist entries",
1060             blacklistcount), blacklistcount);
1061     g_print (" not shown)");
1062   }
1063   g_print (", ");
1064   g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
1065   g_print ("\n");
1066 }
1067
1068 static void
1069 print_all_uri_handlers (void)
1070 {
1071   GList *plugins, *p, *features, *f;
1072
1073   plugins = gst_default_registry_get_plugin_list ();
1074
1075   for (p = plugins; p; p = p->next) {
1076     GstPlugin *plugin = (GstPlugin *) (p->data);
1077
1078     features =
1079         gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
1080         plugin->desc.name);
1081
1082     for (f = features; f; f = f->next) {
1083       GstPluginFeature *feature = GST_PLUGIN_FEATURE (f->data);
1084
1085       if (GST_IS_ELEMENT_FACTORY (feature)) {
1086         GstElementFactory *factory;
1087         GstElement *element;
1088
1089         factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (feature));
1090         if (!factory) {
1091           g_print ("element plugin %s couldn't be loaded\n", plugin->desc.name);
1092           continue;
1093         }
1094
1095         element = gst_element_factory_create (factory, NULL);
1096         if (!element) {
1097           g_print ("couldn't construct element for %s for some reason\n",
1098               GST_OBJECT_NAME (factory));
1099           gst_object_unref (factory);
1100           continue;
1101         }
1102
1103         if (GST_IS_URI_HANDLER (element)) {
1104           const gchar *dir;
1105           gchar **uri_protocols, *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 (", ", uri_protocols);
1122
1123           g_print ("%s (%s, rank %u): %s\n", GST_OBJECT_NAME (factory), dir,
1124               gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)),
1125               joined);
1126
1127           g_free (joined);
1128           //g_strfreev (uri_protocols);
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   n_print ("  Binary package:\t%s\n", plugin->desc.package);
1154   n_print ("  Origin URL:\t\t%s\n", plugin->desc.origin);
1155   n_print ("\n");
1156 }
1157
1158 static void
1159 print_plugin_features (GstPlugin * plugin)
1160 {
1161   GList *features;
1162   gint num_features = 0;
1163   gint num_elements = 0;
1164   gint num_typefinders = 0;
1165   gint num_indexes = 0;
1166   gint num_other = 0;
1167
1168   features =
1169       gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
1170       plugin->desc.name);
1171
1172   while (features) {
1173     GstPluginFeature *feature;
1174
1175     feature = GST_PLUGIN_FEATURE (features->data);
1176
1177     if (GST_IS_ELEMENT_FACTORY (feature)) {
1178       GstElementFactory *factory;
1179
1180       factory = GST_ELEMENT_FACTORY (feature);
1181       n_print ("  %s: %s\n", GST_PLUGIN_FEATURE_NAME (factory),
1182           gst_element_factory_get_longname (factory));
1183       num_elements++;
1184     } else if (GST_IS_INDEX_FACTORY (feature)) {
1185       GstIndexFactory *factory;
1186
1187       factory = GST_INDEX_FACTORY (feature);
1188       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
1189       num_indexes++;
1190     } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
1191       GstTypeFindFactory *factory;
1192
1193       factory = GST_TYPE_FIND_FACTORY (feature);
1194       if (factory->extensions) {
1195         guint i = 0;
1196
1197         g_print ("%s: %s: ", plugin->desc.name,
1198             gst_plugin_feature_get_name (feature));
1199         while (factory->extensions[i]) {
1200           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
1201           i++;
1202         }
1203         g_print ("\n");
1204       } else
1205         g_print ("%s: %s: no extensions\n", plugin->desc.name,
1206             gst_plugin_feature_get_name (feature));
1207
1208       num_typefinders++;
1209     } else if (feature) {
1210       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
1211           g_type_name (G_OBJECT_TYPE (feature)));
1212       num_other++;
1213     }
1214     num_features++;
1215     features = g_list_next (features);
1216   }
1217   n_print ("\n");
1218   n_print ("  %d features:\n", num_features);
1219   if (num_elements > 0)
1220     n_print ("  +-- %d elements\n", num_elements);
1221   if (num_typefinders > 0)
1222     n_print ("  +-- %d typefinders\n", num_typefinders);
1223   if (num_indexes > 0)
1224     n_print ("  +-- %d indexes\n", num_indexes);
1225   if (num_other > 0)
1226     n_print ("  +-- %d other objects\n", num_other);
1227
1228   n_print ("\n");
1229 }
1230
1231 static int
1232 print_element_features (const gchar * element_name)
1233 {
1234   GstPluginFeature *feature;
1235
1236   /* FIXME implement other pretty print function for these */
1237   feature = gst_default_registry_find_feature (element_name,
1238       GST_TYPE_INDEX_FACTORY);
1239   if (feature) {
1240     n_print ("%s: an index\n", element_name);
1241     return 0;
1242   }
1243   feature = gst_default_registry_find_feature (element_name,
1244       GST_TYPE_TYPE_FIND_FACTORY);
1245   if (feature) {
1246     n_print ("%s: a typefind function\n", element_name);
1247     return 0;
1248   }
1249
1250   return -1;
1251 }
1252
1253 static int
1254 print_element_info (GstElementFactory * factory, gboolean print_names)
1255 {
1256   GstElement *element;
1257   gint maxlevel = 0;
1258
1259   factory =
1260       GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1261           (factory)));
1262
1263   if (!factory) {
1264     g_print ("element plugin couldn't be loaded\n");
1265     return -1;
1266   }
1267
1268   element = gst_element_factory_create (factory, NULL);
1269   if (!element) {
1270     g_print ("couldn't construct element for some reason\n");
1271     return -1;
1272   }
1273
1274   if (print_names)
1275     _name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name);
1276   else
1277     _name = NULL;
1278
1279   print_factory_details_info (factory);
1280   if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
1281     GstPlugin *plugin;
1282
1283     plugin = gst_registry_find_plugin (gst_registry_get_default (),
1284         GST_PLUGIN_FEATURE (factory)->plugin_name);
1285     if (plugin) {
1286       print_plugin_info (plugin);
1287     }
1288   }
1289
1290   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1291   print_interfaces (G_OBJECT_TYPE (element));
1292
1293   print_pad_templates_info (element, factory);
1294   print_element_flag_info (element);
1295   print_implementation_info (element);
1296   print_clocking_info (element);
1297   print_index_info (element);
1298   print_uri_handler_info (element);
1299   print_pad_info (element);
1300   print_element_properties_info (element);
1301   print_signal_info (element);
1302   print_children_info (element);
1303
1304   gst_object_unref (element);
1305   gst_object_unref (factory);
1306   g_free (_name);
1307
1308   return 0;
1309 }
1310
1311
1312 static void
1313 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
1314 {
1315   GstPadDirection direction;
1316   const gchar *type_name;
1317   const gchar *klass;
1318   const GList *static_templates, *l;
1319   GstCaps *caps = NULL;
1320   guint i, num;
1321
1322   klass = gst_element_factory_get_klass (factory);
1323   g_return_if_fail (klass != NULL);
1324
1325   if (strstr (klass, "Demuxer") ||
1326       strstr (klass, "Decoder") ||
1327       strstr (klass, "Depay") || strstr (klass, "Parser")) {
1328     type_name = "decoder";
1329     direction = GST_PAD_SINK;
1330   } else if (strstr (klass, "Muxer") ||
1331       strstr (klass, "Encoder") || strstr (klass, "Pay")) {
1332     type_name = "encoder";
1333     direction = GST_PAD_SRC;
1334   } else {
1335     return;
1336   }
1337
1338   /* decoder/demuxer sink pads should always be static and there should only
1339    * be one, the same applies to encoders/muxers and source pads */
1340   static_templates = gst_element_factory_get_static_pad_templates (factory);
1341   for (l = static_templates; l != NULL; l = l->next) {
1342     GstStaticPadTemplate *tmpl = NULL;
1343
1344     tmpl = (GstStaticPadTemplate *) l->data;
1345     if (tmpl->direction == direction) {
1346       caps = gst_static_pad_template_get_caps (tmpl);
1347       break;
1348     }
1349   }
1350
1351   if (caps == NULL) {
1352     g_printerr ("Couldn't find static pad template for %s '%s'\n",
1353         type_name, GST_PLUGIN_FEATURE_NAME (factory));
1354     return;
1355   }
1356
1357   caps = gst_caps_make_writable (caps);
1358   num = gst_caps_get_size (caps);
1359   for (i = 0; i < num; ++i) {
1360     GstStructure *s;
1361     gchar *s_str;
1362
1363     s = gst_caps_get_structure (caps, i);
1364     /* remove fields that are almost always just MIN-MAX of some sort
1365      * in order to make the caps look less messy */
1366     gst_structure_remove_field (s, "pixel-aspect-ratio");
1367     gst_structure_remove_field (s, "framerate");
1368     gst_structure_remove_field (s, "channels");
1369     gst_structure_remove_field (s, "width");
1370     gst_structure_remove_field (s, "height");
1371     gst_structure_remove_field (s, "rate");
1372     gst_structure_remove_field (s, "depth");
1373     gst_structure_remove_field (s, "clock-rate");
1374     s_str = gst_structure_to_string (s);
1375     g_print ("%s-%s\n", type_name, s_str);
1376     g_free (s_str);
1377   }
1378   gst_caps_unref (caps);
1379 }
1380
1381 static void
1382 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
1383 {
1384   gchar **protocols, **p;
1385
1386   protocols = gst_element_factory_get_uri_protocols (factory);
1387   if (protocols != NULL && *protocols != NULL) {
1388     switch (gst_element_factory_get_uri_type (factory)) {
1389       case GST_URI_SINK:
1390         for (p = protocols; *p != NULL; ++p)
1391           g_print ("urisink-%s\n", *p);
1392         break;
1393       case GST_URI_SRC:
1394         for (p = protocols; *p != NULL; ++p)
1395           g_print ("urisource-%s\n", *p);
1396         break;
1397       default:
1398         break;
1399     }
1400     g_strfreev (protocols);
1401   }
1402 }
1403
1404 static void
1405 print_plugin_automatic_install_info (GstPlugin * plugin)
1406 {
1407   const gchar *plugin_name;
1408   GList *features, *l;
1409
1410   plugin_name = gst_plugin_get_name (plugin);
1411
1412   /* not interested in typefind factories, only element factories */
1413   features = gst_registry_get_feature_list (gst_registry_get_default (),
1414       GST_TYPE_ELEMENT_FACTORY);
1415
1416   for (l = features; l != NULL; l = l->next) {
1417     GstPluginFeature *feature;
1418
1419     feature = GST_PLUGIN_FEATURE (l->data);
1420
1421     /* only interested in the ones that are in the plugin we just loaded */
1422     if (g_str_equal (plugin_name, feature->plugin_name)) {
1423       GstElementFactory *factory;
1424
1425       g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
1426
1427       factory = GST_ELEMENT_FACTORY (feature);
1428       print_plugin_automatic_install_info_protocols (factory);
1429       print_plugin_automatic_install_info_codecs (factory);
1430     }
1431   }
1432
1433   g_list_foreach (features, (GFunc) gst_object_unref, NULL);
1434   g_list_free (features);
1435 }
1436
1437 static void
1438 print_all_plugin_automatic_install_info (void)
1439 {
1440   GList *plugins, *orig_plugins;
1441
1442   orig_plugins = plugins = gst_default_registry_get_plugin_list ();
1443   while (plugins) {
1444     GstPlugin *plugin;
1445
1446     plugin = (GstPlugin *) (plugins->data);
1447     plugins = g_list_next (plugins);
1448
1449     print_plugin_automatic_install_info (plugin);
1450   }
1451   gst_plugin_list_free (orig_plugins);
1452 }
1453
1454 int
1455 main (int argc, char *argv[])
1456 {
1457   gboolean print_all = FALSE;
1458   gboolean do_print_blacklist = FALSE;
1459   gboolean plugin_name = FALSE;
1460   gboolean print_aii = FALSE;
1461   gboolean uri_handlers = FALSE;
1462 #ifndef GST_DISABLE_OPTION_PARSING
1463   GOptionEntry options[] = {
1464     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1465         N_("Print all elements"), NULL},
1466     {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist,
1467         N_("Print list of blacklisted files"), NULL},
1468     {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
1469         N_("Print a machine-parsable list of features the specified plugin "
1470               "or all plugins provide.\n                                       "
1471               "Useful in connection with external automatic plugin "
1472               "installation mechanisms"), NULL},
1473     {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name,
1474         N_("List the plugin contents"), NULL},
1475     {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers,
1476           N_
1477           ("Print supported URI schemes, with the elements that implement them"),
1478         NULL},
1479     GST_TOOLS_GOPTION_VERSION,
1480     {NULL}
1481   };
1482   GOptionContext *ctx;
1483   GError *err = NULL;
1484 #endif
1485
1486 #ifdef ENABLE_NLS
1487   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1488   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1489   textdomain (GETTEXT_PACKAGE);
1490 #endif
1491
1492   g_thread_init (NULL);
1493
1494   gst_tools_set_prgname ("gst-inspect");
1495
1496 #ifndef GST_DISABLE_OPTION_PARSING
1497   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1498   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1499   g_option_context_add_group (ctx, gst_init_get_option_group ());
1500   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1501     g_print ("Error initializing: %s\n", err->message);
1502     exit (1);
1503   }
1504   g_option_context_free (ctx);
1505 #else
1506   gst_init (&argc, &argv);
1507 #endif
1508
1509   gst_tools_print_version ("gst-inspect");
1510
1511   if (print_all && argc > 1) {
1512     g_print ("-a requires no extra arguments\n");
1513     return 1;
1514   }
1515
1516   if (uri_handlers && argc > 1) {
1517     g_print ("-u requires no extra arguments\n");
1518     exit (1);
1519   }
1520
1521   /* if no arguments, print out list of elements */
1522   if (uri_handlers) {
1523     print_all_uri_handlers ();
1524   } else if (argc == 1 || print_all) {
1525     if (do_print_blacklist)
1526       print_blacklist ();
1527     else {
1528       if (print_aii)
1529         print_all_plugin_automatic_install_info ();
1530       else
1531         print_element_list (print_all);
1532     }
1533   } else {
1534     /* else we try to get a factory */
1535     GstElementFactory *factory;
1536     GstPlugin *plugin;
1537     const char *arg = argv[argc - 1];
1538     int retval;
1539
1540     if (!plugin_name) {
1541       factory = gst_element_factory_find (arg);
1542
1543       /* if there's a factory, print out the info */
1544       if (factory) {
1545         retval = print_element_info (factory, print_all);
1546         gst_object_unref (factory);
1547       } else {
1548         retval = print_element_features (arg);
1549       }
1550     } else {
1551       retval = -1;
1552     }
1553
1554     /* otherwise check if it's a plugin */
1555     if (retval) {
1556       plugin = gst_default_registry_find_plugin (arg);
1557
1558       /* if there is such a plugin, print out info */
1559       if (plugin) {
1560         if (print_aii) {
1561           print_plugin_automatic_install_info (plugin);
1562         } else {
1563           print_plugin_info (plugin);
1564           print_plugin_features (plugin);
1565         }
1566       } else {
1567         GError *error = NULL;
1568
1569         if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1570           plugin = gst_plugin_load_file (arg, &error);
1571
1572           if (plugin) {
1573             if (print_aii) {
1574               print_plugin_automatic_install_info (plugin);
1575             } else {
1576               print_plugin_info (plugin);
1577               print_plugin_features (plugin);
1578             }
1579           } else {
1580             g_print (_("Could not load plugin file: %s\n"), error->message);
1581             g_error_free (error);
1582             return -1;
1583           }
1584         } else {
1585           g_print (_("No such element or plugin '%s'\n"), arg);
1586           return -1;
1587         }
1588       }
1589     }
1590   }
1591
1592   return 0;
1593 }