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