Next big merge.
[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 #include <glib/gprintf.h>
36
37 static char *_name;
38
39 static int print_element_info (GstElementFactory * factory,
40     gboolean print_names);
41
42 void
43 n_print (const char *format, ...)
44 {
45   va_list args;
46   gint retval;
47
48   if (_name)
49     g_print (_name);
50
51   va_start (args, format);
52   retval = g_vprintf (format, args);
53   va_end (args);
54 }
55
56 static gboolean
57 print_field (GQuark field, const GValue * value, gpointer pfx)
58 {
59   gchar *str = gst_value_serialize (value);
60
61   n_print ("%s  %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
62   g_free (str);
63   return TRUE;
64 }
65
66 static void
67 print_caps (const GstCaps * caps, const gchar * pfx)
68 {
69   guint i;
70
71   g_return_if_fail (caps != NULL);
72
73   if (gst_caps_is_any (caps)) {
74     n_print ("%sANY\n", pfx);
75     return;
76   }
77   if (gst_caps_is_empty (caps)) {
78     n_print ("%sEMPTY\n", pfx);
79     return;
80   }
81
82   for (i = 0; i < gst_caps_get_size (caps); i++) {
83     GstStructure *structure = gst_caps_get_structure (caps, i);
84
85     n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
86     gst_structure_foreach (structure, print_field, (gpointer) pfx);
87   }
88 }
89
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
107 static void
108 print_query_types (const GstQueryType * types)
109 {
110   while (types && *types) {
111     const GstQueryTypeDefinition *definition;
112
113     definition = gst_query_type_get_details (*types);
114     if (definition)
115       n_print ("\t\t(%d):\t%s (%s)\n", *types,
116           definition->nick, definition->description);
117     else
118       n_print ("\t\t(%d):\tUnknown query format\n", *types);
119
120     types++;
121   }
122 }
123
124 #ifndef GST_DISABLE_ENUMTYPES
125 static void
126 print_event_masks (const GstEventMask * masks)
127 {
128   GType event_type;
129   GEnumClass *klass;
130   GType event_flags;
131   GFlagsClass *flags_class = NULL;
132
133   event_type = gst_event_type_get_type ();
134   klass = (GEnumClass *) g_type_class_ref (event_type);
135
136   while (masks && masks->type) {
137     GEnumValue *value;
138     gint flags = 0, index = 0;
139
140     switch (masks->type) {
141       case GST_EVENT_SEEK:
142         flags = masks->flags;
143         event_flags = gst_seek_type_get_type ();
144         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
145         break;
146       default:
147         break;
148     }
149
150     value = g_enum_get_value (klass, masks->type);
151     g_print ("\t\t%s ", value->value_nick);
152
153     while (flags) {
154       GFlagsValue *value;
155
156       if (flags & 1) {
157         value = g_flags_get_first_value (flags_class, 1 << index);
158
159         if (value)
160           g_print ("| %s ", value->value_nick);
161         else
162           g_print ("| ? ");
163       }
164       flags >>= 1;
165       index++;
166     }
167     g_print ("\n");
168
169     masks++;
170   }
171 }
172 #else
173 static void
174 print_event_masks (const GstEventMask * masks)
175 {
176 }
177 #endif
178
179 static char *
180 get_rank_name (gint rank)
181 {
182   switch (rank) {
183     case GST_RANK_NONE:
184       return "none";
185     case GST_RANK_MARGINAL:
186       return "marginal";
187     case GST_RANK_SECONDARY:
188       return "secondary";
189     case GST_RANK_PRIMARY:
190       return "primary";
191     default:
192       return "unknown";
193   }
194 }
195
196 static void
197 print_factory_details_info (GstElementFactory * factory)
198 {
199   n_print ("Factory Details:\n");
200   n_print ("  Long name:\t%s\n", factory->details.longname);
201   n_print ("  Class:\t%s\n", factory->details.klass);
202   n_print ("  Description:\t%s\n", factory->details.description);
203   n_print ("  Author(s):\t%s\n", factory->details.author);
204   n_print ("  Rank:\t\t%s (%d)\n",
205       get_rank_name (GST_PLUGIN_FEATURE (factory)->rank),
206       GST_PLUGIN_FEATURE (factory)->rank);
207   n_print ("\n");
208 }
209
210 static void
211 print_hierarchy (GType type, gint level, gint * maxlevel)
212 {
213   GType parent;
214   gint i;
215
216   parent = g_type_parent (type);
217
218   *maxlevel = *maxlevel + 1;
219   level++;
220
221   if (parent)
222     print_hierarchy (parent, level, maxlevel);
223
224   if (_name)
225     g_print (_name);
226
227   for (i = 1; i < *maxlevel - level; i++)
228     g_print ("      ");
229   if (*maxlevel - level)
230     g_print (" +----");
231
232   g_print ("%s\n", g_type_name (type));
233
234   if (level == 1)
235     n_print ("\n");
236 }
237
238 static void
239 print_element_properties_info (GstElement * element)
240 {
241   GParamSpec **property_specs;
242   gint num_properties, i;
243   gboolean readable;
244   const char *string_val;
245
246   property_specs = g_object_class_list_properties
247       (G_OBJECT_GET_CLASS (element), &num_properties);
248   n_print ("\n");
249   n_print ("Element Properties:\n");
250
251   for (i = 0; i < num_properties; i++) {
252     GValue value = { 0, };
253     GParamSpec *param = property_specs[i];
254
255     readable = FALSE;
256
257     g_value_init (&value, param->value_type);
258     if (param->flags & G_PARAM_READABLE) {
259       g_object_get_property (G_OBJECT (element), param->name, &value);
260       readable = TRUE;
261     }
262
263     n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
264         g_param_spec_get_blurb (param));
265
266     switch (G_VALUE_TYPE (&value)) {
267       case G_TYPE_STRING:
268         string_val = g_value_get_string (&value);
269         n_print ("%-23.23s String. ", "");
270         if (readable) {
271           if (string_val == NULL)
272             g_print ("(Default \"\")");
273           else
274             g_print ("(Default \"%s\")", g_value_get_string (&value));
275         }
276         break;
277       case G_TYPE_BOOLEAN:
278         n_print ("%-23.23s Boolean. ", "");
279         if (readable)
280           g_print ("(Default %s)",
281               (g_value_get_boolean (&value) ? "true" : "false"));
282         break;
283       case G_TYPE_ULONG:
284       {
285         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
286
287         n_print ("%-23.23s Unsigned Long. ", "");
288         if (readable)
289           g_print ("Range: %lu - %lu (Default %lu)",
290               pulong->minimum, pulong->maximum, g_value_get_ulong (&value));
291         break;
292       }
293       case G_TYPE_LONG:
294       {
295         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
296
297         n_print ("%-23.23s Long. ", "");
298         if (readable)
299           g_print ("Range: %ld - %ld (Default %ld)",
300               plong->minimum, plong->maximum, g_value_get_long (&value));
301         break;
302       }
303       case G_TYPE_UINT:
304       {
305         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
306
307         n_print ("%-23.23s Unsigned Integer. ", "");
308         if (readable)
309           g_print ("Range: %u - %u (Default %u)",
310               puint->minimum, puint->maximum, g_value_get_uint (&value));
311         break;
312       }
313       case G_TYPE_INT:
314       {
315         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
316
317         n_print ("%-23.23s Integer. ", "");
318         if (readable)
319           g_print ("Range: %d - %d (Default %d)",
320               pint->minimum, pint->maximum, g_value_get_int (&value));
321         break;
322       }
323       case G_TYPE_UINT64:
324       {
325         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
326
327         n_print ("%-23.23s Unsigned Integer64. ", "");
328         if (readable)
329           g_print ("Range: %" G_GUINT64_FORMAT " - %"
330               G_GUINT64_FORMAT " (Default %" G_GUINT64_FORMAT ")",
331               puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
332         break;
333       }
334       case G_TYPE_INT64:
335       {
336         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
337
338         n_print ("%-23.23s Integer64. ", "");
339         if (readable)
340           g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
341               " (Default %" G_GINT64_FORMAT ")", pint64->minimum,
342               pint64->maximum, g_value_get_int64 (&value));
343         break;
344       }
345       case G_TYPE_FLOAT:
346       {
347         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
348
349         n_print ("%-23.23s Float. Default: %-8.8s %15.7g\n", "", "",
350             g_value_get_float (&value));
351         n_print ("%-23.23s Range: %15.7g - %15.7g", "",
352             pfloat->minimum, pfloat->maximum);
353         break;
354       }
355       case G_TYPE_DOUBLE:
356       {
357         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
358
359         n_print ("%-23.23s Double. Default: %-8.8s %15.7g\n", "", "",
360             g_value_get_double (&value));
361         n_print ("%-23.23s Range: %15.7g - %15.7g", "",
362             pdouble->minimum, pdouble->maximum);
363         break;
364       }
365       default:
366         if (param->value_type == GST_TYPE_URI) {
367           n_print ("%-23.23s URI", "");
368         }
369         if (param->value_type == GST_TYPE_CAPS) {
370           const GstCaps *caps = gst_value_get_caps (&value);
371
372           if (!caps)
373             n_print ("%-23.23s Caps (NULL)", "");
374           else {
375             print_caps (caps, "                           ");
376           }
377         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
378           GEnumValue *values;
379           guint j = 0;
380           gint enum_value;
381
382           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
383           enum_value = g_value_get_enum (&value);
384
385           while (values[j].value_name) {
386             if (values[j].value == enum_value)
387               break;
388             j++;
389           }
390
391           n_print ("%-23.23s Enum \"%s\" (default %d, \"%s\")", "",
392               g_type_name (G_VALUE_TYPE (&value)),
393               enum_value, values[j].value_nick);
394
395           j = 0;
396           while (values[j].value_name) {
397             g_print ("\n%s%-23.23s    (%d): \t%s", "",
398                 _name, values[j].value, values[j].value_nick);
399             j++;
400           }
401           /* g_type_class_unref (ec); */
402         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
403           GFlagsValue *values;
404           guint j = 0;
405           gint flags_value;
406           GString *flags = NULL;
407
408           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
409           flags_value = g_value_get_flags (&value);
410
411           while (values[j].value_name) {
412             if (values[j].value & flags_value) {
413               if (flags) {
414                 g_string_append_printf (flags, " | %s", values[j].value_nick);
415               } else {
416                 flags = g_string_new (values[j].value_nick);
417               }
418             }
419             j++;
420           }
421
422           n_print ("%-23.23s Flags \"%s\" (default %d, \"%s\")", "",
423               g_type_name (G_VALUE_TYPE (&value)),
424               flags_value, (flags ? flags->str : "(none)"));
425
426           j = 0;
427           while (values[j].value_name) {
428             g_print ("\n%s%-23.23s    (%d): \t%s", "",
429                 _name, values[j].value, values[j].value_nick);
430             j++;
431           }
432
433           if (flags)
434             g_string_free (flags, TRUE);
435         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
436           n_print ("%-23.23s Object of type \"%s\"", "",
437               g_type_name (param->value_type));
438         } else {
439           n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
440               g_type_name (param->value_type));
441         }
442         break;
443     }
444     if (!readable)
445       g_print (" Write only\n");
446     else
447       g_print ("\n");
448   }
449   if (num_properties == 0)
450     n_print ("  none\n");
451 }
452
453 static void
454 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
455 {
456   GstElementClass *gstelement_class;
457   const GList *pads;
458   GstPadTemplate *padtemplate;
459
460   n_print ("Pad Templates:\n");
461   if (!factory->numpadtemplates) {
462     n_print ("  none\n");
463     return;
464   }
465
466   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
467
468   pads = factory->padtemplates;
469   while (pads) {
470     padtemplate = (GstPadTemplate *) (pads->data);
471     pads = g_list_next (pads);
472
473     if (padtemplate->direction == GST_PAD_SRC)
474       n_print ("  SRC template: '%s'\n", padtemplate->name_template);
475     else if (padtemplate->direction == GST_PAD_SINK)
476       n_print ("  SINK template: '%s'\n", padtemplate->name_template);
477     else
478       n_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
479
480     if (padtemplate->presence == GST_PAD_ALWAYS)
481       n_print ("    Availability: Always\n");
482     else if (padtemplate->presence == GST_PAD_SOMETIMES)
483       n_print ("    Availability: Sometimes\n");
484     else if (padtemplate->presence == GST_PAD_REQUEST) {
485       n_print ("    Availability: On request\n");
486       n_print ("      Has request_new_pad() function: %s\n",
487           GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
488     } else
489       n_print ("    Availability: UNKNOWN!!!\n");
490
491     if (padtemplate->caps) {
492       n_print ("    Capabilities:\n");
493       print_caps (padtemplate->caps, "      ");
494     }
495
496     n_print ("\n");
497   }
498 }
499
500 static void
501 print_element_flag_info (GstElement * element)
502 {
503   gboolean have_flags = FALSE;
504
505   n_print ("\n");
506   n_print ("Element Flags:\n");
507
508   if (!have_flags)
509     n_print ("  no flags set\n");
510
511   if (GST_IS_BIN (element)) {
512     n_print ("\n");
513     n_print ("Bin Flags:\n");
514     if (!have_flags)
515       n_print ("  no flags set\n");
516   }
517 }
518
519 static void
520 print_implementation_info (GstElement * element)
521 {
522   GstObjectClass *gstobject_class;
523   GstElementClass *gstelement_class;
524
525   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
526   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
527
528   n_print ("\n");
529   n_print ("Element Implementation:\n");
530
531   n_print ("  No loopfunc(), must be chain-based or not configured yet\n");
532
533   n_print ("  Has change_state() function: %s\n",
534       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
535 #ifndef GST_DISABLE_LOADSAVE
536   n_print ("  Has custom save_thyself() function: %s\n",
537       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
538   n_print ("  Has custom restore_thyself() function: %s\n",
539       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
540 #endif
541 }
542
543 static void
544 print_clocking_info (GstElement * element)
545 {
546   if (!gst_element_requires_clock (element) &&
547       !(gst_element_provides_clock (element) &&
548           gst_element_get_clock (element))) {
549     n_print ("\n");
550     n_print ("Element has no clocking capabilities.");
551     return;
552   }
553
554   n_print ("\n");
555   n_print ("Clocking Interaction:\n");
556   if (gst_element_requires_clock (element)) {
557     n_print ("  element requires a clock\n");
558   }
559
560   if (gst_element_provides_clock (element)) {
561     GstClock *clock;
562
563     clock = gst_element_get_clock (element);
564     if (clock)
565       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
566     else
567       n_print ("  element is supposed to provide a clock but returned NULL\n");
568   }
569 }
570
571 #ifndef GST_DISABLE_INDEX
572 static void
573 print_index_info (GstElement * element)
574 {
575   if (gst_element_is_indexable (element)) {
576     n_print ("\n");
577     n_print ("Indexing capabilities:\n");
578     n_print ("  element can do indexing\n");
579   } else {
580     n_print ("\n");
581     n_print ("Element has no indexing capabilities.\n");
582   }
583 }
584 #else
585 static void
586 print_index_info (GstElement * element)
587 {
588 }
589 #endif
590
591 static void
592 print_pad_info (GstElement * element)
593 {
594   const GList *pads;
595   GstPad *pad;
596   GstRealPad *realpad;
597
598   n_print ("\n");
599   n_print ("Pads:\n");
600
601   if (!element->numpads) {
602     n_print ("  none\n");
603     return;
604   }
605
606   pads = element->pads;
607   while (pads) {
608     pad = GST_PAD (pads->data);
609     pads = g_list_next (pads);
610     realpad = GST_PAD_REALIZE (pad);
611
612     n_print ("");
613
614     if (gst_pad_get_direction (GST_PAD (realpad)) == GST_PAD_SRC)
615       g_print ("  SRC: '%s'", gst_pad_get_name (pad));
616     else if (gst_pad_get_direction (GST_PAD (realpad)) == GST_PAD_SINK)
617       g_print ("  SINK: '%s'", gst_pad_get_name (pad));
618     else
619       g_print ("  UNKNOWN!!!: '%s'", gst_pad_get_name (pad));
620
621     if (GST_IS_GHOST_PAD (pad))
622       g_print (", ghost of real pad %s:%s\n", GST_DEBUG_PAD_NAME (realpad));
623     else
624       g_print ("\n");
625
626     n_print ("    Implementation:\n");
627     if (realpad->chainfunc)
628       n_print ("      Has chainfunc(): %s\n",
629           GST_DEBUG_FUNCPTR_NAME (realpad->chainfunc));
630     if (realpad->getrangefunc)
631       n_print ("      Has getrangefunc(): %s\n",
632           GST_DEBUG_FUNCPTR_NAME (realpad->getrangefunc));
633     if (realpad->formatsfunc != gst_pad_get_formats_default) {
634       n_print ("      Supports seeking/conversion/query formats:\n");
635       print_formats (gst_pad_get_formats (GST_PAD (realpad)));
636     }
637     if (realpad->convertfunc != gst_pad_convert_default)
638       n_print ("      Has custom convertfunc(): %s\n",
639           GST_DEBUG_FUNCPTR_NAME (realpad->convertfunc));
640     if (realpad->eventfunc != gst_pad_event_default)
641       n_print ("      Has custom eventfunc(): %s\n",
642           GST_DEBUG_FUNCPTR_NAME (realpad->eventfunc));
643     if (realpad->eventmaskfunc != gst_pad_get_event_masks_default) {
644       n_print ("        Provides event masks:\n");
645       print_event_masks (gst_pad_get_event_masks (GST_PAD (realpad)));
646     }
647     if (realpad->queryfunc != gst_pad_query_default)
648       n_print ("      Has custom queryfunc(): %s\n",
649           GST_DEBUG_FUNCPTR_NAME (realpad->queryfunc));
650     if (realpad->querytypefunc != gst_pad_get_query_types_default) {
651       n_print ("        Provides query types:\n");
652       print_query_types (gst_pad_get_query_types (GST_PAD (realpad)));
653     }
654
655     if (realpad->intlinkfunc != gst_pad_get_internal_links_default)
656       n_print ("      Has custom intconnfunc(): %s\n",
657           GST_DEBUG_FUNCPTR_NAME (realpad->intlinkfunc));
658
659     if (realpad->bufferallocfunc)
660       n_print ("      Has bufferallocfunc(): %s\n",
661           GST_DEBUG_FUNCPTR_NAME (realpad->bufferallocfunc));
662
663     if (pad->padtemplate)
664       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
665
666     if (realpad->caps) {
667       n_print ("    Capabilities:\n");
668       print_caps (realpad->caps, "      ");
669     }
670   }
671 }
672
673 static void
674 print_dynamic_parameters_info (GstElement * element)
675 {
676   GstDParamManager *dpman;
677   GParamSpec **specs = NULL;
678   gint x;
679
680   if ((dpman = gst_dpman_get_manager (element))) {
681     specs = gst_dpman_list_dparam_specs (dpman);
682   }
683
684   if (specs && specs[0] != NULL) {
685     n_print ("\n");
686     n_print ("Dynamic Parameters:\n");
687
688     for (x = 0; specs[x] != NULL; x++) {
689       g_print ("  %-20.20s: ", g_param_spec_get_name (specs[x]));
690
691       switch (G_PARAM_SPEC_VALUE_TYPE (specs[x])) {
692         case G_TYPE_INT64:
693           g_print ("64 Bit Integer (Default %" G_GINT64_FORMAT ", Range %"
694               G_GINT64_FORMAT " -> %" G_GINT64_FORMAT ")",
695               ((GParamSpecInt64 *) specs[x])->default_value,
696               ((GParamSpecInt64 *) specs[x])->minimum,
697               ((GParamSpecInt64 *) specs[x])->maximum);
698           break;
699         case G_TYPE_INT:
700           g_print ("Integer (Default %d, Range %d -> %d)",
701               ((GParamSpecInt *) specs[x])->default_value,
702               ((GParamSpecInt *) specs[x])->minimum,
703               ((GParamSpecInt *) specs[x])->maximum);
704           break;
705         case G_TYPE_FLOAT:
706           g_print ("Float. Default: %-8.8s %15.7g\n", "",
707               ((GParamSpecFloat *) specs[x])->default_value);
708           g_print ("%-23.23s Range: %15.7g - %15.7g", "",
709               ((GParamSpecFloat *) specs[x])->minimum,
710               ((GParamSpecFloat *) specs[x])->maximum);
711           break;
712         case G_TYPE_DOUBLE:
713           g_print ("Double. Default: %-8.8s %15.7g\n", "",
714               ((GParamSpecDouble *) specs[x])->default_value);
715           g_print ("%-23.23s Range: %15.7g - %15.7g", "",
716               ((GParamSpecDouble *) specs[x])->minimum,
717               ((GParamSpecDouble *) specs[x])->maximum);
718           break;
719         default:
720           g_print ("unknown %ld", G_PARAM_SPEC_VALUE_TYPE (specs[x]));
721       }
722       g_print ("\n");
723     }
724     g_free (specs);
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   GList *plugins;
841
842   plugins = gst_registry_pool_plugin_list ();
843   while (plugins) {
844     GList *features;
845     GstPlugin *plugin;
846
847     plugin = (GstPlugin *) (plugins->data);
848     plugins = g_list_next (plugins);
849
850     features = gst_plugin_get_feature_list (plugin);
851     while (features) {
852       GstPluginFeature *feature;
853
854       feature = GST_PLUGIN_FEATURE (features->data);
855
856       if (GST_IS_ELEMENT_FACTORY (feature)) {
857         GstElementFactory *factory;
858
859         factory = GST_ELEMENT_FACTORY (feature);
860         if (print_all)
861           print_element_info (factory, TRUE);
862         else
863           g_print ("%s:  %s: %s\n", plugin->desc.name,
864               GST_PLUGIN_FEATURE_NAME (factory), factory->details.longname);
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         if (!print_all)
872           g_print ("%s:  %s: %s\n", plugin->desc.name,
873               GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
874       }
875 #endif
876       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
877         GstTypeFindFactory *factory;
878
879         factory = GST_TYPE_FIND_FACTORY (feature);
880         if (!print_all)
881           g_print ("%s: %s: ", plugin->desc.name,
882               gst_plugin_feature_get_name (feature));
883         if (factory->extensions) {
884           guint i = 0;
885
886           while (factory->extensions[i]) {
887             if (!print_all)
888               g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
889             i++;
890           }
891           if (!print_all)
892             g_print ("\n");
893         } else {
894           if (!print_all)
895             g_print ("no extensions\n");
896         }
897       } else if (GST_IS_SCHEDULER_FACTORY (feature)) {
898         GstSchedulerFactory *factory;
899
900         factory = GST_SCHEDULER_FACTORY (feature);
901         if (!print_all)
902           g_print ("%s:  %s: %s\n", plugin->desc.name,
903               GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
904       } else {
905         if (!print_all)
906           n_print ("%s:  %s (%s)\n", plugin->desc.name,
907               GST_PLUGIN_FEATURE_NAME (feature),
908               g_type_name (G_OBJECT_TYPE (feature)));
909       }
910
911       features = g_list_next (features);
912     }
913   }
914 }
915
916 static void
917 print_plugin_info (GstPlugin * plugin)
918 {
919   n_print ("Plugin Details:\n");
920   n_print ("  Name:\t\t%s\n", plugin->desc.name);
921   n_print ("  Description:\t%s\n", plugin->desc.description);
922   n_print ("  Filename:\t%s\n", plugin->filename ? plugin->filename : "(null)");
923   n_print ("  Version:\t%s\n", plugin->desc.version);
924   n_print ("  License:\t%s\n", plugin->desc.license);
925   n_print ("  Package:\t%s\n", plugin->desc.package);
926   n_print ("  Origin URL:\t%s\n", plugin->desc.origin);
927   n_print ("\n");
928 }
929
930 static void
931 print_plugin_features (GstPlugin * plugin)
932 {
933   GList *features;
934   gint num_features = 0;
935   gint num_elements = 0;
936   gint num_types = 0;
937   gint num_schedulers = 0;
938   gint num_indexes = 0;
939   gint num_other = 0;
940
941   features = gst_plugin_get_feature_list (plugin);
942
943   while (features) {
944     GstPluginFeature *feature;
945
946     feature = GST_PLUGIN_FEATURE (features->data);
947
948     if (GST_IS_ELEMENT_FACTORY (feature)) {
949       GstElementFactory *factory;
950
951       factory = GST_ELEMENT_FACTORY (feature);
952       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
953           factory->details.longname);
954       num_elements++;
955     }
956 #ifndef GST_DISABLE_INDEX
957     else if (GST_IS_INDEX_FACTORY (feature)) {
958       GstIndexFactory *factory;
959
960       factory = GST_INDEX_FACTORY (feature);
961       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
962       num_indexes++;
963     }
964 #endif
965     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
966       GstTypeFindFactory *factory;
967
968       factory = GST_TYPE_FIND_FACTORY (feature);
969       if (factory->extensions) {
970         guint i = 0;
971
972         g_print ("%s type: ", plugin->desc.name);
973         while (factory->extensions[i]) {
974           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
975           i++;
976         }
977         g_print ("\n");
978       } else
979         g_print ("%s type: N/A\n", plugin->desc.name);
980
981       num_types++;
982     } else if (GST_IS_SCHEDULER_FACTORY (feature)) {
983       GstSchedulerFactory *factory;
984
985       factory = GST_SCHEDULER_FACTORY (feature);
986       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
987       num_schedulers++;
988     } else {
989       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
990           g_type_name (G_OBJECT_TYPE (feature)));
991       num_other++;
992     }
993     num_features++;
994     features = g_list_next (features);
995   }
996   n_print ("\n");
997   n_print ("  %d features:\n", num_features);
998   if (num_elements > 0)
999     n_print ("  +-- %d elements\n", num_elements);
1000   if (num_types > 0)
1001     n_print ("  +-- %d types\n", num_types);
1002   if (num_schedulers > 0)
1003     n_print ("  +-- %d schedulers\n", num_schedulers);
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   feature = gst_registry_pool_find_feature (element_name,
1019       GST_TYPE_SCHEDULER_FACTORY);
1020   if (feature) {
1021     n_print ("%s: a scheduler\n", element_name);
1022     return 0;
1023   }
1024 #ifndef GST_DISABLE_INDEX
1025   feature = gst_registry_pool_find_feature (element_name,
1026       GST_TYPE_INDEX_FACTORY);
1027   if (feature) {
1028     n_print ("%s: an index\n", element_name);
1029     return 0;
1030   }
1031 #endif
1032   feature = gst_registry_pool_find_feature (element_name,
1033       GST_TYPE_TYPE_FIND_FACTORY);
1034   if (feature) {
1035     n_print ("%s: a typefind function\n", element_name);
1036     return 0;
1037   }
1038 #ifndef GST_DISABLE_URI
1039   feature = gst_registry_pool_find_feature (element_name, GST_TYPE_URI_HANDLER);
1040   if (feature) {
1041     n_print ("%s: an uri handler\n", element_name);
1042     return 0;
1043   }
1044 #endif
1045
1046   return -1;
1047 }
1048
1049 static int
1050 print_element_info (GstElementFactory * factory, gboolean print_names)
1051 {
1052   GstElement *element;
1053   gint maxlevel = 0;
1054
1055   element = gst_element_factory_create (factory, NULL);
1056   if (!element) {
1057     g_print ("couldn't construct element for some reason\n");
1058     return -1;
1059   }
1060
1061   if (print_names)
1062     _name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name);
1063   else
1064     _name = "";
1065
1066   print_factory_details_info (factory);
1067   if (GST_PLUGIN_FEATURE (factory)->manager) {
1068     GstPlugin *plugin = (GstPlugin *) GST_PLUGIN_FEATURE (factory)->manager;
1069
1070     print_plugin_info (plugin);
1071   }
1072
1073   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
1074
1075   print_pad_templates_info (element, factory);
1076   print_element_flag_info (element);
1077   print_implementation_info (element);
1078   print_clocking_info (element);
1079   print_index_info (element);
1080   print_pad_info (element);
1081   print_element_properties_info (element);
1082   print_dynamic_parameters_info (element);
1083   print_signal_info (element);
1084   print_children_info (element);
1085
1086   if (_name != "")
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   struct poptOption options[] = {
1097     {"print-all", 'a', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &print_all, 0,
1098         N_("Print all elements"), NULL},
1099     POPT_TABLEEND
1100   };
1101
1102 #ifdef GETTEXT_PACKAGE
1103   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1104   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1105   textdomain (GETTEXT_PACKAGE);
1106 #endif
1107
1108   gst_init_with_popt_table (&argc, &argv, options);
1109   gst_control_init (&argc, &argv);
1110
1111   if (print_all && argc > 2) {
1112     g_print ("-a requires no extra arguments\n");
1113     return 1;
1114   }
1115
1116   /* if no arguments, print out list of elements */
1117   if (argc == 1 || print_all) {
1118     print_element_list (print_all);
1119     /* else we try to get a factory */
1120   } else {
1121     GstElementFactory *factory;
1122     GstPlugin *plugin;
1123     const char *arg = argv[argc - 1];
1124     int retval;
1125
1126     factory = gst_element_factory_find (arg);
1127     /* if there's a factory, print out the info */
1128     if (factory) {
1129       retval = print_element_info (factory, print_all);
1130     } else {
1131       retval = print_element_features (arg);
1132     }
1133
1134     /* otherwise check if it's a plugin */
1135     if (retval) {
1136       plugin = gst_registry_pool_find_plugin (arg);
1137
1138       /* if there is such a plugin, print out info */
1139       if (plugin) {
1140         print_plugin_info (plugin);
1141         print_plugin_features (plugin);
1142       } else {
1143         g_print ("No such element or plugin '%s'\n", arg);
1144         return -1;
1145       }
1146     }
1147   }
1148
1149   return 0;
1150 }