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