8a5076c9cff1187e41a32b30eef706fae0bb6567
[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/gst.h>
29 #include <gst/control/control.h>
30
31 #include "gst/gst-i18n-app.h"
32
33 #include <string.h>
34 #include <locale.h>
35
36 static void
37 print_caps (const GstCaps *caps, const gchar *pfx)
38 {
39   char *s, *tmp;
40   char **v;
41
42   s = gst_caps_to_string (caps);
43   
44   tmp = g_strdup_printf ("\n  %s", pfx);
45   v = g_strsplit (s, ", ", -1);
46   g_free (s);
47   s = g_strjoinv (tmp, v);
48   g_strfreev (v);
49   g_free (tmp);
50   
51   tmp = g_strdup_printf ("\n%s", pfx);
52   v = g_strsplit (s, "; ", -1);
53   g_free (s);
54   s = g_strjoinv (tmp, v);
55   g_free (tmp);
56   g_strfreev (v);
57   
58   g_print ("%s%s\n", pfx, s);
59   g_free(s);
60 }
61
62 static void
63 print_formats (const GstFormat *formats)
64 {
65   while (formats && *formats) {
66     const GstFormatDefinition *definition;
67
68     definition = gst_format_get_details (*formats);
69     if (definition)
70       g_print ("\t\t(%d):\t%s (%s)\n", *formats,
71                definition->nick, definition->description);
72     else
73       g_print ("\t\t(%d):\tUnknown format\n", *formats);
74
75     formats++;
76   }
77 }
78
79 static void
80 print_query_types (const GstQueryType *types)
81 {
82   while (types && *types) {
83     const GstQueryTypeDefinition *definition;
84
85     definition = gst_query_type_get_details (*types);
86     if (definition)
87       g_print ("\t\t(%d):\t%s (%s)\n", *types,
88                definition->nick, definition->description);
89     else
90       g_print ("\t\t(%d):\tUnknown query format\n", *types);
91
92     types++;
93   }
94 }
95
96 static void
97 print_event_masks (const GstEventMask *masks)
98 {
99 #ifndef GST_DISABLE_ENUMTYPES
100   GType event_type;
101   GEnumClass *klass;
102   GType event_flags;
103   GFlagsClass *flags_class = NULL;
104
105   event_type = gst_event_type_get_type();
106   klass = (GEnumClass *) g_type_class_ref (event_type);
107
108   while (masks && masks->type) {
109     GEnumValue *value;
110     gint flags = 0, index = 0;
111
112     switch (masks->type) {
113       case GST_EVENT_SEEK:
114         flags = masks->flags;
115         event_flags = gst_seek_type_get_type ();
116         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
117         break;
118       default:
119         break;
120     }
121
122     value = g_enum_get_value (klass, masks->type);
123     g_print ("\t\t%s ", value->value_nick);
124
125     while (flags) {
126       GFlagsValue *value;
127
128       if (flags & 1) {
129         value = g_flags_get_first_value (flags_class, 1 << index);
130
131         if (value)
132           g_print ("| %s ", value->value_nick);
133         else
134           g_print ("| ? ");
135       }
136       flags >>= 1;
137       index++;
138     }
139     g_print ("\n");
140
141     masks++;
142   }
143 #endif
144 }
145
146 static void
147 output_hierarchy (GType type, gint level, gint *maxlevel)
148 {
149   GType parent;
150   gint i;
151
152   parent = g_type_parent (type);
153
154   *maxlevel = *maxlevel + 1;
155   level++;
156
157   if (parent)
158     output_hierarchy (parent, level, maxlevel);
159
160   for (i=1; i<*maxlevel-level; i++)
161    g_print ("      ");
162   if (*maxlevel-level)
163     g_print (" +----");
164
165   g_print ("%s\n", g_type_name (type));
166
167   if (level == 1)
168     g_print ("\n");
169 }
170
171 static void
172 print_element_properties (GstElement *element)
173 {
174   GParamSpec **property_specs;
175   gint num_properties,i;
176   gboolean readable;
177   const char *string_val;
178
179   property_specs = g_object_class_list_properties
180                      (G_OBJECT_GET_CLASS (element), &num_properties);
181   g_print("\nElement Properties:\n");
182
183   for (i = 0; i < num_properties; i++) {
184     GValue value = { 0, };
185     GParamSpec *param = property_specs[i];
186     readable = FALSE;
187
188     g_value_init (&value, param->value_type);
189     if (param->flags & G_PARAM_READABLE) {
190       g_object_get_property (G_OBJECT (element), param->name, &value);
191       readable = TRUE;
192     }
193
194     g_print("  %-20s: %s\n", g_param_spec_get_name (param),
195                                g_param_spec_get_blurb (param));
196
197     switch (G_VALUE_TYPE (&value)) {
198       case G_TYPE_STRING:
199         string_val = g_value_get_string (&value);
200         g_print ("%-23.23s String. ", "");
201         if (readable) {
202           if (string_val == NULL)
203             g_print ("(Default \"\")");
204           else
205             g_print ("(Default \"%s\")", g_value_get_string (&value));
206         }
207         break;
208       case G_TYPE_BOOLEAN:
209         g_print ("%-23.23s Boolean. ", "");
210         if (readable) g_print ("(Default %s)", (g_value_get_boolean (&value) ? "true" : "false"));
211         break;
212       case G_TYPE_ULONG:
213       {
214         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
215         g_print("%-23.23s Unsigned Long. ", "");
216         if (readable) g_print("Range: %lu - %lu (Default %lu)",
217                         pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
218         break;
219       }
220       case G_TYPE_LONG:
221       {
222         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
223         g_print("%-23.23s Long. ", "");
224         if (readable) g_print("Range: %ld - %ld (Default %ld)",
225                         plong->minimum, plong->maximum, g_value_get_long (&value));
226         break;
227       }
228       case G_TYPE_UINT:
229       {
230         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
231         g_print("%-23.23s Unsigned Integer. ", "");
232         if (readable) g_print("Range: %u - %u (Default %u)",
233                         puint->minimum, puint->maximum, g_value_get_uint (&value));
234         break;
235       }
236       case G_TYPE_INT:
237       {
238         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
239         g_print("%-23.23s Integer. ", "");
240         if (readable) g_print("Range: %d - %d (Default %d)",
241                         pint->minimum, pint->maximum, g_value_get_int (&value));
242         break;
243       }
244       case G_TYPE_UINT64:
245       {
246         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
247         g_print("%-23.23s Unsigned Integer64. ", "");
248         if (readable) g_print("Range: %" G_GUINT64_FORMAT " - %"
249                         G_GUINT64_FORMAT " (Default %" G_GUINT64_FORMAT ")",
250                         puint64->minimum, puint64->maximum,
251                         g_value_get_uint64 (&value));
252         break;
253       }
254       case G_TYPE_INT64:
255       {
256         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
257         g_print("%-23.23s Integer64. ", "");
258         if (readable) g_print("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT                         " (Default %" G_GINT64_FORMAT ")", pint64->minimum,
259                         pint64->maximum, g_value_get_int64 (&value));
260         break;
261       }
262       case G_TYPE_FLOAT:
263       {
264         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
265         g_print("%-23.23s Float. Default: %-8.8s %15.7g\n", "", "",
266                 g_value_get_float (&value));
267         g_print("%-23.23s Range: %15.7g - %15.7g", "",
268                pfloat->minimum, pfloat->maximum);
269         break;
270       }
271       case G_TYPE_DOUBLE:
272       {
273         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
274         g_print("%-23.23s Double. Default: %-8.8s %15.7g\n", "", "",
275                 g_value_get_double (&value));
276         g_print("%-23.23s Range: %15.7g - %15.7g", "",
277                pdouble->minimum, pdouble->maximum);
278         break;
279       }
280       default:
281         if (param->value_type == GST_TYPE_URI) {
282           g_print("%-23.23s URI", "");
283         }
284         if (param->value_type == GST_TYPE_CAPS) {
285           const GstCaps *caps = gst_value_get_caps (&value);
286
287           if (!caps)
288             g_print("%-23.23s Caps (NULL)", "");
289           else {
290             print_caps (caps, "                           ");
291           }
292         }
293         else if (G_IS_PARAM_SPEC_ENUM (param)) {
294           GEnumValue *values;
295           guint j = 0;
296           gint enum_value;
297
298           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
299           enum_value = g_value_get_enum (&value);
300
301           while (values[j].value_name) {
302             if (values[j].value == enum_value)
303               break;
304             j++; 
305           }
306
307           g_print ("%-23.23s Enum \"%s\" (default %d, \"%s\")", "",
308                         g_type_name (G_VALUE_TYPE (&value)),
309                         enum_value, values[j].value_nick);
310
311           j = 0;
312           while (values[j].value_name) {
313             g_print("\n%-23.23s    (%d): \t%s", "",
314                         values[j].value, values[j].value_nick);
315             j++;
316           }
317           /* g_type_class_unref (ec); */
318         }
319         else if (G_IS_PARAM_SPEC_FLAGS (param)) {
320           GFlagsValue *values;
321           guint j = 0;
322           gint flags_value;
323           GString *flags = NULL;
324
325           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
326           flags_value = g_value_get_flags (&value);
327
328           while (values[j].value_name) {
329             if (values[j].value & flags_value) {
330               if (flags) {
331                 g_string_append_printf (flags, " | %s", values[j].value_nick);
332               }
333               else {
334                 flags = g_string_new (values[j].value_nick);
335               }
336             }
337             j++;
338           }
339
340           g_print("%-23.23s Flags \"%s\" (default %d, \"%s\")", "",
341                       g_type_name (G_VALUE_TYPE (&value)),
342                       flags_value, (flags ? flags->str : "(none)"));
343
344           j = 0;
345           while (values[j].value_name) {
346             g_print("\n%-23.23s    (%d): \t%s", "",
347                       values[j].value, values[j].value_nick);
348             j++;
349           }
350
351           if (flags)
352             g_string_free (flags, TRUE);
353         }
354         else if (G_IS_PARAM_SPEC_OBJECT (param)) {
355           g_print("%-23.23s Object of type \"%s\"", "",
356                       g_type_name(param->value_type));
357         }
358         else {
359           g_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
360                       g_type_name(param->value_type));
361         }
362         break;
363     }
364     if (!readable)
365       g_print (" Write only\n");
366     else
367       g_print ("\n");
368   }
369   if (num_properties == 0)
370     g_print ("  none\n");
371 }
372
373 static char *
374 get_rank_name (gint rank)
375 {
376   switch(rank){
377     case GST_RANK_NONE:
378       return "none";
379     case GST_RANK_MARGINAL:
380       return "marginal";
381     case GST_RANK_SECONDARY:
382       return "secondary";
383     case GST_RANK_PRIMARY:
384       return "primary";
385     default:
386       return "unknown";
387   }
388 }
389
390 static gint
391 print_element_info (GstElementFactory *factory)
392 {
393   GstElement *element;
394   GstObjectClass *gstobject_class;
395   GstElementClass *gstelement_class;
396   GstPad *pad;
397   GstRealPad *realpad;
398   GstPadTemplate *padtemplate;
399   GList *children;
400   GstElement *child;
401   gboolean have_flags;
402   gint maxlevel = 0;
403
404   element = gst_element_factory_create (factory, "element");
405   if (!element) {
406     g_print ("couldn't construct element for some reason\n");
407     return -1;
408   }
409
410   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
411   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
412
413   g_print ("Factory Details:\n");
414   g_print ("  Long name:\t%s\n",   factory->details.longname);
415   g_print ("  Class:\t%s\n",       factory->details.klass);
416   g_print ("  Description:\t%s\n", factory->details.description);
417   g_print ("  Author(s):\t%s\n",   factory->details.author);
418   g_print ("  Rank:\t\t%s\n",      get_rank_name(GST_PLUGIN_FEATURE(factory)->rank));
419   g_print ("\n");
420
421   output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
422
423   g_print ("Pad Templates:\n");
424   if (factory->numpadtemplates) {
425     const GList *pads;
426
427     pads = factory->padtemplates;
428     while (pads) {
429       padtemplate = (GstPadTemplate*)(pads->data);
430       pads = g_list_next(pads);
431
432       if (padtemplate->direction == GST_PAD_SRC)
433         g_print ("  SRC template: '%s'\n", padtemplate->name_template);
434       else if (padtemplate->direction == GST_PAD_SINK)
435         g_print ("  SINK template: '%s'\n", padtemplate->name_template);
436       else
437         g_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
438
439       if (padtemplate->presence == GST_PAD_ALWAYS)
440         g_print ("    Availability: Always\n");
441       else if (padtemplate->presence == GST_PAD_SOMETIMES)
442         g_print ("    Availability: Sometimes\n");
443       else if (padtemplate->presence == GST_PAD_REQUEST) {
444         g_print ("    Availability: On request\n");
445         g_print ("      Has request_new_pad() function: %s\n",
446                 GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
447       }
448       else
449         g_print ("    Availability: UNKNOWN!!!\n");
450
451       if (padtemplate->caps) {
452         g_print ("    Capabilities:\n");
453         print_caps (padtemplate->caps, "      ");
454       }
455
456       g_print ("\n");
457     }
458   } else
459     g_print ("  none\n");
460
461   have_flags = FALSE;
462
463   g_print ("\nElement Flags:\n");
464   if (GST_FLAG_IS_SET (element, GST_ELEMENT_COMPLEX)) {
465     g_print ("  GST_ELEMENT_COMPLEX\n");
466     have_flags = TRUE;
467   }
468   if (GST_FLAG_IS_SET (element, GST_ELEMENT_DECOUPLED)) {
469     g_print ("  GST_ELEMENT_DECOUPLED\n");
470     have_flags = TRUE;
471   }
472   if (GST_FLAG_IS_SET (element, GST_ELEMENT_THREAD_SUGGESTED)) {
473     g_print ("  GST_ELEMENT_THREADSUGGESTED\n");
474     have_flags = TRUE;
475   }
476   if (GST_FLAG_IS_SET (element, GST_ELEMENT_EVENT_AWARE)) {
477     g_print("  GST_ELEMENT_EVENT_AWARE\n");
478     have_flags = TRUE;
479   }
480   if (!have_flags)
481     g_print("  no flags set\n");
482
483   if (GST_IS_BIN (element)) {
484     g_print ("\nBin Flags:\n");
485     if (GST_FLAG_IS_SET (element, GST_BIN_FLAG_MANAGER)) {
486       g_print ("  GST_BIN_FLAG_MANAGER\n");
487       have_flags = TRUE;
488     }
489     if (GST_FLAG_IS_SET (element, GST_BIN_SELF_SCHEDULABLE)) {
490       g_print ("  GST_BIN_SELF_SCHEDULABLE\n");
491       have_flags = TRUE;
492     }
493     if (GST_FLAG_IS_SET (element, GST_BIN_FLAG_PREFER_COTHREADS)) {
494       g_print ("  GST_BIN_FLAG_PREFER_COTHREADS\n");
495       have_flags = TRUE;
496     }
497     if (!have_flags)
498       g_print ("  no flags set\n");
499   }
500
501
502
503   g_print ("\nElement Implementation:\n");
504
505   if (element->loopfunc)
506     g_print ("  loopfunc()-based element: %s\n",
507             GST_DEBUG_FUNCPTR_NAME (element->loopfunc));
508   else
509     g_print ("  No loopfunc(), must be chain-based or not configured yet\n");
510
511   g_print ("  Has change_state() function: %s\n",
512           GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
513 #ifndef GST_DISABLE_LOADSAVE
514   g_print ("  Has custom save_thyself() function: %s\n",
515           GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
516   g_print ("  Has custom restore_thyself() function: %s\n",
517           GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
518 #endif
519
520   have_flags = FALSE;
521
522   g_print ("\nClocking Interaction:\n");
523   if (gst_element_requires_clock (element)) {
524     g_print ("  element requires a clock\n");
525     have_flags = TRUE;
526   }
527   if (gst_element_provides_clock (element)) {
528     GstClock *clock;
529
530     clock = gst_element_get_clock (element);
531     if (clock)
532       g_print ("  element provides a clock: %s\n", GST_OBJECT_NAME(clock));
533     else
534       g_print ("  element is supposed to provide a clock but returned NULL\n");
535     have_flags = TRUE;
536   }
537   if (!have_flags) {
538     g_print ("  none\n");
539   }
540
541 #ifndef GST_DISABLE_INDEX
542   g_print ("\nIndexing capabilities:\n");
543   if (gst_element_is_indexable (element)) {
544     g_print ("  element can do indexing\n");
545   }
546   else {
547     g_print ("  none\n");
548   }
549 #endif
550
551   g_print ("\nPads:\n");
552   if (element->numpads) {
553     const GList *pads;
554     pads = gst_element_get_pad_list (element);
555     while (pads) {
556       pad = GST_PAD (pads->data);
557       pads = g_list_next (pads);
558       realpad = GST_PAD_REALIZE (pad);
559
560       if (gst_pad_get_direction (pad) == GST_PAD_SRC)
561         g_print ("  SRC: '%s'", gst_pad_get_name (pad));
562       else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
563         g_print ("  SINK: '%s'", gst_pad_get_name (pad));
564       else
565         g_print ("  UNKNOWN!!!: '%s'\n", gst_pad_get_name (pad));
566
567       if (GST_IS_GHOST_PAD (pad))
568         g_print (", ghost of real pad %s:%s\n", GST_DEBUG_PAD_NAME (realpad));
569       else
570         g_print ("\n");
571
572       g_print ("    Implementation:\n");
573       if (realpad->chainfunc)
574         g_print ("      Has chainfunc(): %s\n",
575                 GST_DEBUG_FUNCPTR_NAME (realpad->chainfunc));
576       if (realpad->getfunc)
577         g_print ("      Has getfunc(): %s\n",
578                 GST_DEBUG_FUNCPTR_NAME (realpad->getfunc));
579       if (realpad->formatsfunc != gst_pad_get_formats_default) {
580         g_print ("      Supports seeking/conversion/query formats:\n");
581         print_formats (gst_pad_get_formats (GST_PAD (realpad)));
582       }
583       if (realpad->convertfunc != gst_pad_convert_default)
584         g_print ("      Has custom convertfunc(): %s\n",
585                 GST_DEBUG_FUNCPTR_NAME (realpad->convertfunc));
586       if (realpad->eventfunc != gst_pad_event_default)
587         g_print ("      Has custom eventfunc(): %s\n",
588                 GST_DEBUG_FUNCPTR_NAME (realpad->eventfunc));
589       if (realpad->eventmaskfunc != gst_pad_get_event_masks_default) {
590         g_print ("        Provides event masks:\n");
591         print_event_masks (gst_pad_get_event_masks (GST_PAD (realpad)));
592       }
593       if (realpad->queryfunc != gst_pad_query_default)
594         g_print ("      Has custom queryfunc(): %s\n",
595                 GST_DEBUG_FUNCPTR_NAME (realpad->queryfunc));
596       if (realpad->querytypefunc != gst_pad_get_query_types_default) {
597         g_print ("        Provides query types:\n");
598         print_query_types (gst_pad_get_query_types (GST_PAD (realpad)));
599       }
600
601       if (realpad->intlinkfunc != gst_pad_get_internal_links_default)
602         g_print ("      Has custom intconnfunc(): %s\n",
603                 GST_DEBUG_FUNCPTR_NAME(realpad->intlinkfunc));
604
605       if (realpad->bufferallocfunc)
606         g_print ("      Has bufferallocfunc(): %s\n",
607                 GST_DEBUG_FUNCPTR_NAME(realpad->bufferallocfunc));
608
609       if (pad->padtemplate)
610         g_print ("    Pad Template: '%s'\n",
611                 pad->padtemplate->name_template);
612
613       if (realpad->caps) {
614         g_print ("    Capabilities:\n");
615         print_caps (realpad->caps, "      ");
616       }
617     }
618   } else
619     g_print ("  none\n");
620
621   print_element_properties (element);
622
623   /* Dynamic Parameters block */
624   {
625     GstDParamManager* dpman;
626     GParamSpec** specs;
627     gint x;
628
629     g_print ("\nDynamic Parameters:\n");
630     if((dpman = gst_dpman_get_manager (element))) {
631       specs = gst_dpman_list_dparam_specs (dpman);
632       for (x = 0; specs[x] != NULL; x++) {
633         g_print ("  %-20.20s: ", g_param_spec_get_name (specs[x]));
634
635         switch (G_PARAM_SPEC_VALUE_TYPE (specs[x])) {
636           case G_TYPE_INT64:
637             g_print ("64 Bit Integer (Default %" G_GINT64_FORMAT ", Range %"
638                          G_GINT64_FORMAT " -> %" G_GINT64_FORMAT ")",
639             ((GParamSpecInt64 *) specs[x])->default_value,
640             ((GParamSpecInt64 *) specs[x])->minimum,
641             ((GParamSpecInt64 *) specs[x])->maximum);
642             break;
643           case G_TYPE_INT:
644             g_print ("Integer (Default %d, Range %d -> %d)",
645             ((GParamSpecInt *) specs[x])->default_value,
646             ((GParamSpecInt *) specs[x])->minimum,
647             ((GParamSpecInt *) specs[x])->maximum);
648             break;
649           case G_TYPE_FLOAT:
650             g_print ("Float. Default: %-8.8s %15.7g\n", "",
651               ((GParamSpecFloat *) specs[x])->default_value);
652             g_print ("%-23.23s Range: %15.7g - %15.7g", "",
653               ((GParamSpecFloat *) specs[x])->minimum,
654               ((GParamSpecFloat *) specs[x])->maximum);
655             break;
656           case G_TYPE_DOUBLE:
657             g_print ("Double. Default: %-8.8s %15.7g\n", "",
658               ((GParamSpecDouble *) specs[x])->default_value);
659             g_print ("%-23.23s Range: %15.7g - %15.7g", "",
660               ((GParamSpecDouble *) specs[x])->minimum,
661               ((GParamSpecDouble *) specs[x])->maximum);
662             break;
663         default: g_print ("unknown %ld", G_PARAM_SPEC_VALUE_TYPE (specs[x]));
664         }
665         g_print ("\n");
666       }
667       g_free (specs);
668     }
669     else {
670       g_print ("  none\n");
671     }
672   }
673
674   /* Signals/Actions Block */
675   {
676     guint *signals;
677     guint nsignals;
678     gint i, k;
679     GSignalQuery *query;
680     GType type;
681
682     for (k = 0; k < 2; k++) {
683       gint counted = 0;
684
685       if (k == 0)
686         g_print ("\nElement Signals:\n");
687       else
688         g_print ("\nElement Actions:\n");
689
690       for(type = G_OBJECT_TYPE(element); type; type = g_type_parent(type)){
691         signals = g_signal_list_ids (type, &nsignals);
692
693         for (i = 0; i < nsignals; i++) {
694           gint n_params;
695           GType return_type;
696           const GType *param_types;
697           gint j;
698
699           query = g_new0 (GSignalQuery,1);
700           g_signal_query (signals[i], query);
701
702           if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
703               (k == 1 &&  (query->signal_flags & G_SIGNAL_ACTION))) {
704             n_params = query->n_params;
705             return_type = query->return_type;
706             param_types = query->param_types;
707
708             g_print ("  \"%s\" :\t %s user_function (%s* object",
709                     query->signal_name, g_type_name (return_type),
710                     g_type_name (type));
711
712             for (j = 0; j < n_params; j++) {
713               g_print (",\n    \t\t\t\t%s arg%d", g_type_name(param_types[j]), j);
714             }
715             if (k == 0)
716               g_print (",\n    \t\t\t\tgpointer user_data);\n");
717             else
718               g_print (");\n");
719
720             counted++;
721           }
722
723           g_free (query);
724         }
725       }
726       if (counted == 0) g_print ("  none\n");
727     }
728   }
729
730   /* for compound elements */
731   if (GST_IS_BIN (element)) {
732     g_print ("\nChildren:\n");
733     children = (GList *) gst_bin_get_list (GST_BIN (element));
734     if (!children)
735       g_print ("  none\n");
736     else {
737       while (children) {
738         child = GST_ELEMENT (children->data);
739         children = g_list_next (children);
740
741         g_print ("  %s\n", GST_ELEMENT_NAME (child));
742       }
743     }
744   }
745
746   return 0;
747 }
748
749 static void
750 print_element_list (void)
751 {
752   GList *plugins;
753
754   plugins = gst_registry_pool_plugin_list();
755   while (plugins) {
756     GList *features;
757     GstPlugin *plugin;
758
759     plugin = (GstPlugin*)(plugins->data);
760     plugins = g_list_next (plugins);
761
762     features = gst_plugin_get_feature_list (plugin);
763     while (features) {
764       GstPluginFeature *feature;
765
766       feature = GST_PLUGIN_FEATURE (features->data);
767
768       if (GST_IS_ELEMENT_FACTORY (feature)) {
769         GstElementFactory *factory;
770
771         factory = GST_ELEMENT_FACTORY (feature);
772         g_print ("%s:  %s: %s\n", plugin->desc.name,
773                 GST_PLUGIN_FEATURE_NAME (factory) ,factory->details.longname);
774       }
775 #ifndef GST_DISABLE_INDEX
776       else if (GST_IS_INDEX_FACTORY (feature)) {
777         GstIndexFactory *factory;
778
779         factory = GST_INDEX_FACTORY (feature);
780         g_print ("%s:  %s: %s\n", plugin->desc.name,
781                 GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
782       }
783 #endif
784       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
785         GstTypeFindFactory *factory;
786
787         factory = GST_TYPE_FIND_FACTORY (feature);
788         g_print ("%s: %s: ", plugin->desc.name, gst_plugin_feature_get_name (feature));
789         if (factory->extensions) {
790           guint i = 0;
791           while (factory->extensions[i]) {
792             g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
793             i++;
794           }
795           g_print ("\n");
796         } else {
797           g_print ("no extensions\n");
798         }
799       }
800       else if (GST_IS_SCHEDULER_FACTORY (feature)) {
801         GstSchedulerFactory *factory;
802
803         factory = GST_SCHEDULER_FACTORY (feature);
804         g_print ("%s:  %s: %s\n", plugin->desc.name,
805                 GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
806       }
807       else {
808         g_print ("%s:  %s (%s)\n", plugin->desc.name,
809                 GST_PLUGIN_FEATURE_NAME (feature),
810                 g_type_name (G_OBJECT_TYPE (feature)));
811       }
812
813       features = g_list_next (features);
814     }
815   }
816 }
817
818 static void
819 print_plugin_info (GstPlugin *plugin)
820 {
821   GList *features;
822   gint num_features = 0;
823   gint num_elements = 0;
824   gint num_types = 0;
825   gint num_schedulers = 0;
826   gint num_indexes = 0;
827   gint num_other = 0;
828
829   g_print ("Plugin Details:\n");
830   g_print ("  Name:\t\t%s\n",       plugin->desc.name);
831   g_print ("  Description:\t%s\n",  plugin->desc.description);
832   g_print ("  Filename:\t%s\n",     plugin->filename);
833   g_print ("  Version:\t%s\n",      plugin->desc.version);
834   g_print ("  License:\t%s\n",      plugin->desc.license);
835   g_print ("  Package:\t%s\n",      plugin->desc.package);
836   g_print ("  Origin URL:\t%s\n",   plugin->desc.origin);
837   g_print ("\n");
838
839   features = gst_plugin_get_feature_list (plugin);
840
841   while (features) {
842     GstPluginFeature *feature;
843
844     feature = GST_PLUGIN_FEATURE (features->data);
845
846     if (GST_IS_ELEMENT_FACTORY (feature)) {
847       GstElementFactory *factory;
848
849       factory = GST_ELEMENT_FACTORY (feature);
850       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
851               factory->details.longname);
852       num_elements++;
853     }
854 #ifndef GST_DISABLE_INDEX
855     else if (GST_IS_INDEX_FACTORY (feature)) {
856       GstIndexFactory *factory;
857
858       factory = GST_INDEX_FACTORY (feature);
859       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
860       num_indexes++;
861     }
862 #endif
863     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
864       GstTypeFindFactory *factory;
865
866       factory = GST_TYPE_FIND_FACTORY (feature);
867       if (factory->extensions) {
868         guint i = 0;
869         g_print ("%s type: ", plugin->desc.name);
870         while (factory->extensions[i]) {
871           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
872           i++;
873         }
874       } else
875         g_print ("%s type: N/A\n", plugin->desc.name);
876
877       num_types++;
878     }
879     else if (GST_IS_SCHEDULER_FACTORY (feature)) {
880       GstSchedulerFactory *factory;
881
882       factory = GST_SCHEDULER_FACTORY (feature);
883       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
884       num_schedulers++;
885     }
886     else {
887       g_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
888                              g_type_name (G_OBJECT_TYPE (feature)));
889       num_other++;
890     }
891     num_features++;
892     features = g_list_next (features);
893   }
894   g_print ("\n  %d features:\n", num_features);
895   if (num_elements > 0)
896     g_print ("  +-- %d elements\n", num_elements);
897   if (num_types > 0)
898     g_print ("  +-- %d types\n", num_types);
899   if (num_schedulers > 0)
900     g_print ("  +-- %d schedulers\n", num_schedulers);
901   if (num_indexes > 0)
902     g_print ("  +-- %d indexes\n", num_indexes);
903   if (num_other > 0)
904     g_print ("  +-- %d other objects\n", num_other);
905
906   g_print ("\n");
907 }
908
909 int
910 main (int argc, char *argv[])
911 {
912   GstElementFactory *factory;
913   GstPlugin *plugin;
914   gchar *so;
915   struct poptOption options[] = {
916     {"gst-inspect-plugin", 'p', POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, 0,
917                    N_("Show plugin details"), NULL},
918     {"gst-inspect-scheduler", 's', POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, 0,
919                    N_("Show scheduler details"), NULL},
920     POPT_TABLEEND
921   };
922
923   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
924   bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
925   textdomain (GETTEXT_PACKAGE);
926
927   gst_init_with_popt_table (&argc, &argv, options);
928   gst_control_init (&argc, &argv);
929
930   /* if no arguments, print out list of elements */
931   if (argc == 1) {
932     print_element_list();
933
934   /* else we try to get a factory */
935   } else {
936     /* first check for help */
937     if (strstr (argv[1], "-help")) {
938       g_print ("Usage: %s\t\t\tList all registered elements\n",argv[0]);
939       g_print ("       %s element-name\tShow element details\n",argv[0]);
940       g_print ("       %s plugin-name[.so]\tShow information about plugin\n",
941               argv[0]);
942       return 0;
943     }
944
945     /* only search for a factory if there's not a '.so' */
946     if (! strstr (argv[1], ".so")) {
947       factory = gst_element_factory_find (argv[1]);
948
949       /* if there's a factory, print out the info */
950       if (factory)
951         return print_element_info (factory);
952       else {
953          GstPluginFeature* feature;
954
955          /* FIXME implement other pretty print function for these */
956          feature = gst_registry_pool_find_feature (argv[1],
957                                                    GST_TYPE_SCHEDULER_FACTORY);
958          if (feature) {
959            g_print ("%s: a scheduler\n", argv[1]);
960            return 0;
961          }
962 #ifndef GST_DISABLE_INDEX
963          feature = gst_registry_pool_find_feature (argv[1],
964                                                    GST_TYPE_INDEX_FACTORY);
965          if (feature) {
966            g_print ("%s: an index\n", argv[1]);
967            return 0;
968          }
969 #endif
970          feature = gst_registry_pool_find_feature (argv[1],
971                                                    GST_TYPE_TYPE_FIND_FACTORY);
972          if (feature) {
973            g_print ("%s: a typefind function\n", argv[1]);
974            return 0;
975          }
976 #ifndef GST_DISABLE_URI
977          feature = gst_registry_pool_find_feature (argv[1],
978                                                    GST_TYPE_URI_HANDLER);
979          if (feature) {
980            g_print ("%s: an uri handler\n", argv[1]);
981            return 0;
982          }
983 #endif
984       }
985     } else {
986       /* strip the .so */
987       so = strstr(argv[1],".so");
988       so[0] = '\0';
989     }
990
991     /* otherwise assume it's a plugin */
992     plugin = gst_registry_pool_find_plugin (argv[1]);
993
994     /* if there is such a plugin, print out info */
995
996     if (plugin) {
997       print_plugin_info (plugin);
998
999     } else {
1000       g_print("no such element or plugin '%s'\n", argv[1]);
1001       return -1;
1002     }
1003   }
1004
1005   return 0;
1006 }