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