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