32fbe7d2db23a46f582a01c5519a8bf764a117e3
[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;
37
38 static int print_element_info (GstElementFactory * factory,
39     gboolean print_names);
40
41 void
42 n_print (const char *format, ...)
43 {
44   va_list args;
45   gint retval;
46
47   if (_name)
48     g_print (_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 #ifndef GST_DISABLE_ENUMTYPES
126 #if 0
127 static void
128 print_event_masks (const GstEventMask * masks)
129 {
130   GType event_type;
131   GEnumClass *klass;
132   GType event_flags;
133   GFlagsClass *flags_class = NULL;
134
135   event_type = gst_event_type_get_type ();
136   klass = (GEnumClass *) g_type_class_ref (event_type);
137
138   while (masks && masks->type) {
139     GEnumValue *value;
140     gint flags = 0, index = 0;
141
142     switch (masks->type) {
143       case GST_EVENT_SEEK:
144         flags = masks->flags;
145         event_flags = gst_seek_type_get_type ();
146         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
147         break;
148       default:
149         break;
150     }
151
152     value = g_enum_get_value (klass, masks->type);
153     g_print ("\t\t%s ", value->value_nick);
154
155     while (flags) {
156       GFlagsValue *value;
157
158       if (flags & 1) {
159         value = g_flags_get_first_value (flags_class, 1 << index);
160
161         if (value)
162           g_print ("| %s ", value->value_nick);
163         else
164           g_print ("| ? ");
165       }
166       flags >>= 1;
167       index++;
168     }
169     g_print ("\n");
170
171     masks++;
172   }
173 }
174 #endif
175 #else
176 static void
177 print_event_masks (const GstEventMask * masks)
178 {
179 }
180 #endif
181
182 static char *
183 get_rank_name (gint rank)
184 {
185   switch (rank) {
186     case GST_RANK_NONE:
187       return "none";
188     case GST_RANK_MARGINAL:
189       return "marginal";
190     case GST_RANK_SECONDARY:
191       return "secondary";
192     case GST_RANK_PRIMARY:
193       return "primary";
194     default:
195       return "unknown";
196   }
197 }
198
199 static void
200 print_factory_details_info (GstElementFactory * factory)
201 {
202   n_print ("Factory Details:\n");
203   n_print ("  Long name:\t%s\n", factory->details.longname);
204   n_print ("  Class:\t%s\n", factory->details.klass);
205   n_print ("  Description:\t%s\n", factory->details.description);
206   n_print ("  Author(s):\t%s\n", factory->details.author);
207   n_print ("  Rank:\t\t%s (%d)\n",
208       get_rank_name (GST_PLUGIN_FEATURE (factory)->rank),
209       GST_PLUGIN_FEATURE (factory)->rank);
210   n_print ("\n");
211 }
212
213 static void
214 print_hierarchy (GType type, gint level, gint * maxlevel)
215 {
216   GType parent;
217   gint i;
218
219   parent = g_type_parent (type);
220
221   *maxlevel = *maxlevel + 1;
222   level++;
223
224   if (parent)
225     print_hierarchy (parent, level, maxlevel);
226
227   if (_name)
228     g_print (_name);
229
230   for (i = 1; i < *maxlevel - level; i++)
231     g_print ("      ");
232   if (*maxlevel - level)
233     g_print (" +----");
234
235   g_print ("%s\n", g_type_name (type));
236
237   if (level == 1)
238     n_print ("\n");
239 }
240
241 static void
242 print_interfaces (GType type)
243 {
244   guint n_ifaces;
245   GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
246
247   if (ifaces) {
248     if (n_ifaces) {
249       g_print ("%sImplemented Interfaces:\n", _name);
250       iface = ifaces;
251       while (*iface) {
252         g_print ("%s  %s\n", _name, g_type_name (*iface));
253         iface++;
254       }
255       g_print ("%s\n", _name);
256       g_free (ifaces);
257     }
258   }
259 }
260
261 static void
262 print_element_properties_info (GstElement * element)
263 {
264   GParamSpec **property_specs;
265   guint num_properties, i;
266   gboolean readable;
267   gboolean first_flag;
268
269   property_specs = g_object_class_list_properties
270       (G_OBJECT_GET_CLASS (element), &num_properties);
271   n_print ("\n");
272   n_print ("Element Properties:\n");
273
274   for (i = 0; i < num_properties; i++) {
275     GValue value = { 0, };
276     GParamSpec *param = property_specs[i];
277
278     readable = FALSE;
279
280     g_value_init (&value, param->value_type);
281
282     n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
283         g_param_spec_get_blurb (param));
284
285     first_flag = TRUE;
286     n_print ("%-23.23s flags: ", "");
287     if (param->flags & G_PARAM_READABLE) {
288       g_object_get_property (G_OBJECT (element), param->name, &value);
289       readable = TRUE;
290       g_print ((first_flag ? "readable" : ", readable"));
291       first_flag = FALSE;
292     }
293     if (param->flags & G_PARAM_WRITABLE) {
294       g_print ((first_flag ? "writable" : ", writable"));
295       first_flag = FALSE;
296     }
297     if (param->flags & GST_PARAM_CONTROLLABLE) {
298       g_print ((first_flag ? "controllable" : ", controllable"));
299       first_flag = FALSE;
300     }
301     n_print ("\n");
302
303     switch (G_VALUE_TYPE (&value)) {
304       case G_TYPE_STRING:
305       {
306         GParamSpecString *pstring = G_PARAM_SPEC_STRING (param);
307
308         n_print ("%-23.23s String. ", "");
309
310         if (pstring->default_value == NULL)
311           g_print ("Default: null ");
312         else
313           g_print ("Default: \"%s\" ", pstring->default_value);
314
315         if (readable) {
316           const char *string_val = g_value_get_string (&value);
317
318           if (string_val == NULL)
319             g_print ("Current: null");
320           else
321             g_print ("Current: \"%s\"", string_val);
322         }
323         break;
324       }
325       case G_TYPE_BOOLEAN:
326       {
327         GParamSpecBoolean *pboolean = G_PARAM_SPEC_BOOLEAN (param);
328
329         n_print ("%-23.23s Boolean. ", "");
330         g_print ("Default: %s ", (pboolean->default_value ? "true" : "false"));
331         if (readable)
332           g_print ("Current: %s",
333               (g_value_get_boolean (&value) ? "true" : "false"));
334         break;
335       }
336       case G_TYPE_ULONG:
337       {
338         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
339
340         n_print ("%-23.23s Unsigned Long. ", "");
341         g_print ("Range: %lu - %lu Default: %lu ",
342             pulong->minimum, pulong->maximum, pulong->default_value);
343         if (readable)
344           g_print ("Current: %lu", g_value_get_ulong (&value));
345         break;
346       }
347       case G_TYPE_LONG:
348       {
349         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
350
351         n_print ("%-23.23s Long. ", "");
352         g_print ("Range: %ld - %ld Default: %ld ",
353             plong->minimum, plong->maximum, plong->default_value);
354         if (readable)
355           g_print ("Current: %ld", g_value_get_long (&value));
356         break;
357       }
358       case G_TYPE_UINT:
359       {
360         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
361
362         n_print ("%-23.23s Unsigned Integer. ", "");
363         g_print ("Range: %u - %u Default: %u ",
364             puint->minimum, puint->maximum, puint->default_value);
365         if (readable)
366           g_print ("Current: %u", g_value_get_uint (&value));
367         break;
368       }
369       case G_TYPE_INT:
370       {
371         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
372
373         n_print ("%-23.23s Integer. ", "");
374         g_print ("Range: %d - %d Default: %d ",
375             pint->minimum, pint->maximum, pint->default_value);
376         if (readable)
377           g_print ("Current: %d", g_value_get_int (&value));
378         break;
379       }
380       case G_TYPE_UINT64:
381       {
382         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
383
384         n_print ("%-23.23s Unsigned Integer64. ", "");
385         g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
386             " Default: %" G_GUINT64_FORMAT " ",
387             puint64->minimum, puint64->maximum, puint64->default_value);
388         if (readable)
389           g_print ("Current: %" G_GUINT64_FORMAT, g_value_get_uint64 (&value));
390         break;
391       }
392       case G_TYPE_INT64:
393       {
394         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
395
396         n_print ("%-23.23s Integer64. ", "");
397         g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
398             " Default: %" G_GINT64_FORMAT " ",
399             pint64->minimum, pint64->maximum, pint64->default_value);
400         if (readable)
401           g_print ("Current: %" G_GINT64_FORMAT, g_value_get_int64 (&value));
402         break;
403       }
404       case G_TYPE_FLOAT:
405       {
406         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
407
408         n_print ("%-23.23s Float. ", "");
409         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
410             pfloat->minimum, pfloat->maximum, pfloat->default_value);
411         if (readable)
412           g_print ("Current: %15.7g", g_value_get_float (&value));
413         break;
414       }
415       case G_TYPE_DOUBLE:
416       {
417         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
418
419         n_print ("%-23.23s Double. ", "");
420         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
421             pdouble->minimum, pdouble->maximum, pdouble->default_value);
422         if (readable)
423           g_print ("Current: %15.7g", g_value_get_double (&value));
424         break;
425       }
426       default:
427         if (param->value_type == GST_TYPE_CAPS) {
428           const GstCaps *caps = gst_value_get_caps (&value);
429
430           if (!caps)
431             n_print ("%-23.23s Caps (NULL)", "");
432           else {
433             print_caps (caps, "                           ");
434           }
435         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
436           GEnumValue *values;
437           guint j = 0;
438           gint enum_value;
439
440           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
441           enum_value = g_value_get_enum (&value);
442
443           while (values[j].value_name) {
444             if (values[j].value == enum_value)
445               break;
446             j++;
447           }
448
449           n_print ("%-23.23s Enum \"%s\" Current: %d, \"%s\"", "",
450               g_type_name (G_VALUE_TYPE (&value)),
451               enum_value, values[j].value_nick);
452
453           j = 0;
454           while (values[j].value_name) {
455             g_print ("\n%s%-23.23s    %d) %-16s - %s", "",
456                 _name, values[j].value, values[j].value_nick,
457                 values[j].value_name);
458             j++;
459           }
460           /* g_type_class_unref (ec); */
461         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
462           GFlagsValue *values;
463           guint j = 0;
464           gint flags_value;
465           GString *flags = NULL;
466
467           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
468           flags_value = g_value_get_flags (&value);
469
470           while (values[j].value_name) {
471             if (values[j].value & flags_value) {
472               if (flags) {
473                 g_string_append_printf (flags, " | %s", values[j].value_nick);
474               } else {
475                 flags = g_string_new (values[j].value_nick);
476               }
477             }
478             j++;
479           }
480
481           n_print ("%-23.23s Flags \"%s\" Current: %d, \"%s\"", "",
482               g_type_name (G_VALUE_TYPE (&value)),
483               flags_value, (flags ? flags->str : "(none)"));
484
485           j = 0;
486           while (values[j].value_name) {
487             g_print ("\n%s%-23.23s    (%d): \t%s", "",
488                 _name, values[j].value, values[j].value_nick);
489             j++;
490           }
491
492           if (flags)
493             g_string_free (flags, TRUE);
494         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
495           n_print ("%-23.23s Object of type \"%s\"", "",
496               g_type_name (param->value_type));
497         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
498           n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
499               g_type_name (param->value_type));
500         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
501           if (param->value_type != G_TYPE_POINTER) {
502             n_print ("%-23.23s Pointer of type \"%s\".", "",
503                 g_type_name (param->value_type));
504           } else {
505             n_print ("%-23.23s Pointer.", "");
506           }
507         } else {
508           n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
509               g_type_name (param->value_type));
510         }
511         break;
512     }
513     if (!readable)
514       g_print (" Write only\n");
515     else
516       g_print ("\n");
517   }
518   if (num_properties == 0)
519     n_print ("  none\n");
520
521   g_free (property_specs);
522 }
523
524 static void
525 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
526 {
527   GstElementClass *gstelement_class;
528   const GList *pads;
529   GstStaticPadTemplate *padtemplate;
530
531   n_print ("Pad Templates:\n");
532   if (!factory->numpadtemplates) {
533     n_print ("  none\n");
534     return;
535   }
536
537   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
538
539   pads = factory->staticpadtemplates;
540   while (pads) {
541     padtemplate = (GstStaticPadTemplate *) (pads->data);
542     pads = g_list_next (pads);
543
544     if (padtemplate->direction == GST_PAD_SRC)
545       n_print ("  SRC template: '%s'\n", padtemplate->name_template);
546     else if (padtemplate->direction == GST_PAD_SINK)
547       n_print ("  SINK template: '%s'\n", padtemplate->name_template);
548     else
549       n_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
550
551     if (padtemplate->presence == GST_PAD_ALWAYS)
552       n_print ("    Availability: Always\n");
553     else if (padtemplate->presence == GST_PAD_SOMETIMES)
554       n_print ("    Availability: Sometimes\n");
555     else if (padtemplate->presence == GST_PAD_REQUEST) {
556       n_print ("    Availability: On request\n");
557       n_print ("      Has request_new_pad() function: %s\n",
558           GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
559     } else
560       n_print ("    Availability: UNKNOWN!!!\n");
561
562     if (padtemplate->static_caps.string) {
563       n_print ("    Capabilities:\n");
564       print_caps (gst_static_caps_get (&padtemplate->static_caps), "      ");
565     }
566
567     n_print ("\n");
568   }
569 }
570
571 static void
572 print_element_flag_info (GstElement * element)
573 {
574   gboolean have_flags = FALSE;
575
576   n_print ("\n");
577   n_print ("Element Flags:\n");
578
579   if (!have_flags)
580     n_print ("  no flags set\n");
581
582   if (GST_IS_BIN (element)) {
583     n_print ("\n");
584     n_print ("Bin Flags:\n");
585     if (!have_flags)
586       n_print ("  no flags set\n");
587   }
588 }
589
590 static void
591 print_implementation_info (GstElement * element)
592 {
593   GstObjectClass *gstobject_class;
594   GstElementClass *gstelement_class;
595
596   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
597   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
598
599   n_print ("\n");
600   n_print ("Element Implementation:\n");
601
602   n_print ("  No loopfunc(), must be chain-based or not configured yet\n");
603
604   n_print ("  Has change_state() function: %s\n",
605       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
606 #ifndef GST_DISABLE_LOADSAVE
607   n_print ("  Has custom save_thyself() function: %s\n",
608       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
609   n_print ("  Has custom restore_thyself() function: %s\n",
610       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
611 #endif
612 }
613
614 static void
615 print_clocking_info (GstElement * element)
616 {
617   if (!gst_element_requires_clock (element) &&
618       !(gst_element_provides_clock (element) &&
619           gst_element_get_clock (element))) {
620     n_print ("\n");
621     n_print ("Element has no clocking capabilities.");
622     return;
623   }
624
625   n_print ("\n");
626   n_print ("Clocking Interaction:\n");
627   if (gst_element_requires_clock (element)) {
628     n_print ("  element requires a clock\n");
629   }
630
631   if (gst_element_provides_clock (element)) {
632     GstClock *clock;
633
634     clock = gst_element_get_clock (element);
635     if (clock)
636       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
637     else
638       n_print ("  element is supposed to provide a clock but returned NULL\n");
639   }
640 }
641
642 #ifndef GST_DISABLE_INDEX
643 static void
644 print_index_info (GstElement * element)
645 {
646   if (gst_element_is_indexable (element)) {
647     n_print ("\n");
648     n_print ("Indexing capabilities:\n");
649     n_print ("  element can do indexing\n");
650   } else {
651     n_print ("\n");
652     n_print ("Element has no indexing capabilities.\n");
653   }
654 }
655 #else
656 static void
657 print_index_info (GstElement * element)
658 {
659 }
660 #endif
661
662 static void
663 print_pad_info (GstElement * element)
664 {
665   const GList *pads;
666   GstPad *pad;
667
668   n_print ("\n");
669   n_print ("Pads:\n");
670
671   if (!element->numpads) {
672     n_print ("  none\n");
673     return;
674   }
675
676   pads = element->pads;
677   while (pads) {
678     pad = GST_PAD (pads->data);
679     pads = g_list_next (pads);
680
681     n_print ("");
682
683     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
684       g_print ("  SRC: '%s'", gst_pad_get_name (pad));
685     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
686       g_print ("  SINK: '%s'", gst_pad_get_name (pad));
687     else
688       g_print ("  UNKNOWN!!!: '%s'", gst_pad_get_name (pad));
689
690     g_print ("\n");
691
692     n_print ("    Implementation:\n");
693     if (pad->chainfunc)
694       n_print ("      Has chainfunc(): %s\n",
695           GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
696     if (pad->getrangefunc)
697       n_print ("      Has getrangefunc(): %s\n",
698           GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
699     if (pad->eventfunc != gst_pad_event_default)
700       n_print ("      Has custom eventfunc(): %s\n",
701           GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
702     if (pad->queryfunc != gst_pad_query_default)
703       n_print ("      Has custom queryfunc(): %s\n",
704           GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
705     if (pad->querytypefunc != gst_pad_get_query_types_default) {
706       n_print ("        Provides query types:\n");
707       print_query_types (gst_pad_get_query_types (pad));
708     }
709
710     if (pad->intlinkfunc != gst_pad_get_internal_links_default)
711       n_print ("      Has custom intconnfunc(): %s\n",
712           GST_DEBUG_FUNCPTR_NAME (pad->intlinkfunc));
713
714     if (pad->bufferallocfunc)
715       n_print ("      Has bufferallocfunc(): %s\n",
716           GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
717
718     if (pad->padtemplate)
719       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
720
721     if (pad->caps) {
722       n_print ("    Capabilities:\n");
723       print_caps (pad->caps, "      ");
724     }
725   }
726 }
727
728 #if 0
729 static gint
730 compare_signal_names (GSignalQuery * a, GSignalQuery * b)
731 {
732   return strcmp (a->signal_name, b->signal_name);
733 }
734 #endif
735
736 static void
737 print_signal_info (GstElement * element)
738 {
739   /* Signals/Actions Block */
740   guint *signals;
741   guint nsignals;
742   gint i = 0, j, k;
743   GSignalQuery *query = NULL;
744   GType type;
745   GSList *found_signals, *l;
746
747   for (k = 0; k < 2; k++) {
748     found_signals = NULL;
749     for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
750       if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
751         break;
752
753       if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
754         continue;
755
756       signals = g_signal_list_ids (type, &nsignals);
757       for (i = 0; i < nsignals; i++) {
758         query = g_new0 (GSignalQuery, 1);
759         g_signal_query (signals[i], query);
760
761         if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
762             (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
763           found_signals = g_slist_append (found_signals, query);
764       }
765     }
766
767     if (found_signals) {
768       n_print ("\n");
769       if (k == 0)
770         n_print ("Element Signals:\n");
771       else
772         n_print ("Element Actions:\n");
773     } else {
774       continue;
775     }
776
777     for (l = found_signals; l; l = l->next) {
778       gchar *indent;
779       int indent_len;
780
781       query = (GSignalQuery *) l->data;
782       indent_len = strlen (query->signal_name) +
783           strlen (g_type_name (query->return_type)) + 24;
784
785       indent = g_new0 (gchar, indent_len + 1);
786       memset (indent, ' ', indent_len);
787
788       n_print ("  \"%s\" :  %s user_function (%s* object",
789           query->signal_name,
790           g_type_name (query->return_type), g_type_name (type));
791
792       for (j = 0; j < query->n_params; j++) {
793         if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
794           g_print (",\n%s%s%s arg%d", _name, indent,
795               g_type_name (query->param_types[j]), j);
796         } else {
797           g_print (",\n%s%s%s* arg%d", _name, indent,
798               g_type_name (query->param_types[j]), j);
799         }
800       }
801
802       if (k == 0)
803         g_print (",\n%s%sgpointer user_data);\n", _name, indent);
804       else
805         g_print (");\n");
806
807       g_free (indent);
808     }
809
810     if (found_signals) {
811       g_slist_foreach (found_signals, (GFunc) g_free, NULL);
812       g_slist_free (found_signals);
813     }
814   }
815 }
816
817 static void
818 print_children_info (GstElement * element)
819 {
820   GList *children;
821
822   if (!GST_IS_BIN (element))
823     return;
824
825   children = (GList *) GST_BIN (element)->children;
826   if (children) {
827     n_print ("\n");
828     g_print ("Children:\n");
829   }
830
831   while (children) {
832     n_print ("  %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
833     children = g_list_next (children);
834   }
835 }
836
837 static void
838 print_element_list (gboolean print_all)
839 {
840   int plugincount = 0, featurecount = 0;
841   GList *plugins, *orig_plugins;
842
843   orig_plugins = plugins = gst_default_registry_get_plugin_list ();
844   while (plugins) {
845     GList *features, *orig_features;
846     GstPlugin *plugin;
847
848     plugin = (GstPlugin *) (plugins->data);
849     plugins = g_list_next (plugins);
850     plugincount++;
851
852     orig_features = features =
853         gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
854         plugin->desc.name);
855     while (features) {
856       GstPluginFeature *feature;
857
858       feature = GST_PLUGIN_FEATURE (features->data);
859       featurecount++;
860
861       if (GST_IS_ELEMENT_FACTORY (feature)) {
862         GstElementFactory *factory;
863
864         factory = GST_ELEMENT_FACTORY (feature);
865         if (print_all)
866           print_element_info (factory, TRUE);
867         else
868           g_print ("%s:  %s: %s\n", plugin->desc.name,
869               GST_PLUGIN_FEATURE_NAME (factory), factory->details.longname);
870       }
871 #ifndef GST_DISABLE_INDEX
872       else if (GST_IS_INDEX_FACTORY (feature)) {
873         GstIndexFactory *factory;
874
875         factory = GST_INDEX_FACTORY (feature);
876         if (!print_all)
877           g_print ("%s:  %s: %s\n", plugin->desc.name,
878               GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
879       }
880 #endif
881       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
882         GstTypeFindFactory *factory;
883
884         factory = GST_TYPE_FIND_FACTORY (feature);
885         if (!print_all)
886           g_print ("%s: %s: ", plugin->desc.name,
887               gst_plugin_feature_get_name (feature));
888         if (factory->extensions) {
889           guint i = 0;
890
891           while (factory->extensions[i]) {
892             if (!print_all)
893               g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
894             i++;
895           }
896           if (!print_all)
897             g_print ("\n");
898         } else {
899           if (!print_all)
900             g_print ("no extensions\n");
901         }
902       } else {
903         if (!print_all)
904           n_print ("%s:  %s (%s)\n", plugin->desc.name,
905               GST_PLUGIN_FEATURE_NAME (feature),
906               g_type_name (G_OBJECT_TYPE (feature)));
907       }
908
909       features = g_list_next (features);
910     }
911
912     gst_plugin_feature_list_free (orig_features);
913   }
914
915   gst_plugin_list_free (orig_plugins);
916
917   g_print ("\nTotal plugins: %d\nTotal features: %d\n",
918       plugincount, featurecount);
919 }
920
921 static void
922 print_plugin_info (GstPlugin * plugin)
923 {
924   n_print ("Plugin Details:\n");
925   n_print ("  Name:\t\t\t%s\n", plugin->desc.name);
926   n_print ("  Description:\t\t%s\n", plugin->desc.description);
927   n_print ("  Filename:\t\t%s\n",
928       plugin->filename ? plugin->filename : "(null)");
929   n_print ("  Version:\t\t%s\n", plugin->desc.version);
930   n_print ("  License:\t\t%s\n", plugin->desc.license);
931   n_print ("  Source module:\t%s\n", plugin->desc.source);
932   n_print ("  Binary package:\t%s\n", plugin->desc.package);
933   n_print ("  Origin URL:\t\t%s\n", plugin->desc.origin);
934   n_print ("\n");
935 }
936
937 static void
938 print_plugin_features (GstPlugin * plugin)
939 {
940   GList *features;
941   gint num_features = 0;
942   gint num_elements = 0;
943   gint num_types = 0;
944   gint num_indexes = 0;
945   gint num_other = 0;
946
947   features =
948       gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
949       plugin->desc.name);
950
951   while (features) {
952     GstPluginFeature *feature;
953
954     feature = GST_PLUGIN_FEATURE (features->data);
955
956     if (GST_IS_ELEMENT_FACTORY (feature)) {
957       GstElementFactory *factory;
958
959       factory = GST_ELEMENT_FACTORY (feature);
960       n_print ("  %s: %s\n", GST_PLUGIN_FEATURE_NAME (factory),
961           factory->details.longname);
962       num_elements++;
963     }
964 #ifndef GST_DISABLE_INDEX
965     else if (GST_IS_INDEX_FACTORY (feature)) {
966       GstIndexFactory *factory;
967
968       factory = GST_INDEX_FACTORY (feature);
969       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
970       num_indexes++;
971     }
972 #endif
973     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
974       GstTypeFindFactory *factory;
975
976       factory = GST_TYPE_FIND_FACTORY (feature);
977       if (factory->extensions) {
978         guint i = 0;
979
980         g_print ("%s type: ", plugin->desc.name);
981         while (factory->extensions[i]) {
982           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
983           i++;
984         }
985         g_print ("\n");
986       } else
987         g_print ("%s type: N/A\n", plugin->desc.name);
988
989       num_types++;
990     } else {
991       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
992           g_type_name (G_OBJECT_TYPE (feature)));
993       num_other++;
994     }
995     num_features++;
996     features = g_list_next (features);
997   }
998   n_print ("\n");
999   n_print ("  %d features:\n", num_features);
1000   if (num_elements > 0)
1001     n_print ("  +-- %d elements\n", num_elements);
1002   if (num_types > 0)
1003     n_print ("  +-- %d types\n", num_types);
1004   if (num_indexes > 0)
1005     n_print ("  +-- %d indexes\n", num_indexes);
1006   if (num_other > 0)
1007     n_print ("  +-- %d other objects\n", num_other);
1008
1009   n_print ("\n");
1010 }
1011
1012 static int
1013 print_element_features (const gchar * element_name)
1014 {
1015   GstPluginFeature *feature;
1016
1017   /* FIXME implement other pretty print function for these */
1018 #ifndef GST_DISABLE_INDEX
1019   feature = gst_default_registry_find_feature (element_name,
1020       GST_TYPE_INDEX_FACTORY);
1021   if (feature) {
1022     n_print ("%s: an index\n", element_name);
1023     return 0;
1024   }
1025 #endif
1026   feature = gst_default_registry_find_feature (element_name,
1027       GST_TYPE_TYPE_FIND_FACTORY);
1028   if (feature) {
1029     n_print ("%s: a typefind function\n", element_name);
1030     return 0;
1031   }
1032
1033   return -1;
1034 }
1035
1036 static int
1037 print_element_info (GstElementFactory * factory, gboolean print_names)
1038 {
1039   GstElement *element;
1040   gint maxlevel = 0;
1041
1042   factory =
1043       GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
1044           (factory)));
1045
1046   if (!factory) {
1047     g_print ("element plugin couldn't be loaded\n");
1048     return -1;
1049   }
1050
1051   element = gst_element_factory_create (factory, NULL);
1052   if (!element) {
1053     g_print ("couldn't construct element for some reason\n");
1054     return -1;
1055   }
1056
1057   if (print_names)
1058     _name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name);
1059   else
1060     _name = "";
1061
1062   print_factory_details_info (factory);
1063   if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
1064     GstPlugin *plugin;
1065
1066     plugin = gst_registry_find_plugin (gst_registry_get_default (),
1067         GST_PLUGIN_FEATURE (factory)->plugin_name);
1068     if (plugin) {
1069       print_plugin_info (plugin);
1070     }
1071   }
1072
1073   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1074   print_interfaces (G_OBJECT_TYPE (element));
1075
1076   print_pad_templates_info (element, factory);
1077   print_element_flag_info (element);
1078   print_implementation_info (element);
1079   print_clocking_info (element);
1080   print_index_info (element);
1081   print_pad_info (element);
1082   print_element_properties_info (element);
1083   print_signal_info (element);
1084   print_children_info (element);
1085
1086   if (_name[0] != '\0')
1087     g_free (_name);
1088
1089   return 0;
1090 }
1091
1092 int
1093 main (int argc, char *argv[])
1094 {
1095   gboolean print_all = FALSE;
1096   GOptionEntry options[] = {
1097     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
1098         N_("Print all elements"), NULL},
1099     GST_TOOLS_GOPTION_VERSION,
1100     {NULL}
1101   };
1102   GOptionContext *ctx;
1103   GError *err = NULL;
1104
1105 #ifdef ENABLE_NLS
1106   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1107   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1108   textdomain (GETTEXT_PACKAGE);
1109 #endif
1110
1111   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
1112   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1113   g_option_context_add_group (ctx, gst_init_get_option_group ());
1114   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1115     g_print ("Error initializing: %s\n", err->message);
1116     exit (1);
1117   }
1118   g_option_context_free (ctx);
1119
1120   gst_tools_print_version ("gst-inspect");
1121
1122   if (print_all && argc > 2) {
1123     g_print ("-a requires no extra arguments\n");
1124     return 1;
1125   }
1126
1127   /* if no arguments, print out list of elements */
1128   if (argc == 1 || print_all) {
1129     print_element_list (print_all);
1130     /* else we try to get a factory */
1131   } else {
1132     GstElementFactory *factory;
1133     GstPlugin *plugin;
1134     const char *arg = argv[argc - 1];
1135     int retval;
1136
1137     factory = gst_element_factory_find (arg);
1138     /* if there's a factory, print out the info */
1139     if (factory) {
1140       retval = print_element_info (factory, print_all);
1141       gst_object_unref (factory);
1142     } else {
1143       retval = print_element_features (arg);
1144     }
1145
1146     /* otherwise check if it's a plugin */
1147     if (retval) {
1148       plugin = gst_default_registry_find_plugin (arg);
1149
1150       /* if there is such a plugin, print out info */
1151       if (plugin) {
1152         print_plugin_info (plugin);
1153         print_plugin_features (plugin);
1154       } else {
1155         GError *error = NULL;
1156
1157         if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
1158           plugin = gst_plugin_load_file (arg, &error);
1159
1160           if (plugin) {
1161             print_plugin_info (plugin);
1162             print_plugin_features (plugin);
1163           } else {
1164             g_print ("Error loading plugin file: %s\n", error->message);
1165             g_error_free (error);
1166             return -1;
1167           }
1168         } else {
1169           g_print ("No such element or plugin '%s'\n", arg);
1170           return -1;
1171         }
1172       }
1173     }
1174   }
1175
1176   return 0;
1177 }