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