gstreamer_core/tools/gst-inspect.c
changeset 11 1373546e05c6
equal deleted inserted replaced
10:6f340f756486 11:1373546e05c6
       
     1 /* GStreamer
       
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
       
     3  *               2000 Wim Taymans <wtay@chello.be>
       
     4  *               2004 Thomas Vander Stichele <thomas@apestaart.org>
       
     5  *
       
     6  * gst-inspect.c: tool to inspect the GStreamer registry
       
     7  *
       
     8  * This library is free software; you can redistribute it and/or
       
     9  * modify it under the terms of the GNU Library General Public
       
    10  * License as published by the Free Software Foundation; either
       
    11  * version 2 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This library is distributed in the hope that it will be useful,
       
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16  * Library General Public License for more details.
       
    17  *
       
    18  * You should have received a copy of the GNU Library General Public
       
    19  * License along with this library; if not, write to the
       
    20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    21  * Boston, MA 02111-1307, USA.
       
    22  */
       
    23 
       
    24 #ifdef HAVE_CONFIG_H
       
    25 #  include "config.h"
       
    26 #endif
       
    27 
       
    28 
       
    29 #include<gst/gst_global.h>
       
    30 #include "tools.h"
       
    31 
       
    32 #include <string.h>
       
    33 #include <locale.h>
       
    34 #include <glib/gprintf.h>
       
    35 #include <gobject_global.h>
       
    36 #include <gst/controller/gstcontroller.h>
       
    37 
       
    38 static char *_name = NULL;
       
    39 
       
    40 static int print_element_info (GstElementFactory * factory,
       
    41     gboolean print_names);
       
    42 
       
    43 static void
       
    44 n_print (const char *format, ...)
       
    45 {
       
    46   va_list args;
       
    47   gint retval;
       
    48 
       
    49   if (_name)
       
    50     g_print (_name);
       
    51 
       
    52   va_start (args, format);
       
    53   retval = g_vprintf (format, args);
       
    54   va_end (args);
       
    55 }
       
    56 
       
    57 static gboolean
       
    58 print_field (GQuark field, const GValue * value, gpointer pfx)
       
    59 {
       
    60   gchar *str = gst_value_serialize (value);
       
    61 
       
    62   n_print ("%s  %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);
       
    63   g_free (str);
       
    64   return TRUE;
       
    65 }
       
    66 
       
    67 static void
       
    68 print_caps (const GstCaps * caps, const gchar * pfx)
       
    69 {
       
    70   guint i;
       
    71 
       
    72   g_return_if_fail (caps != NULL);
       
    73 
       
    74   if (gst_caps_is_any (caps)) {
       
    75     n_print ("%sANY\n", pfx);
       
    76     return;
       
    77   }
       
    78   if (gst_caps_is_empty (caps)) {
       
    79     n_print ("%sEMPTY\n", pfx);
       
    80     return;
       
    81   }
       
    82 
       
    83   for (i = 0; i < gst_caps_get_size (caps); i++) {
       
    84     GstStructure *structure = gst_caps_get_structure (caps, i);
       
    85 
       
    86     n_print ("%s%s\n", pfx, gst_structure_get_name (structure));
       
    87     gst_structure_foreach (structure, print_field, (gpointer) pfx);
       
    88   }
       
    89 }
       
    90 
       
    91 #if 0
       
    92 static void
       
    93 print_formats (const GstFormat * formats)
       
    94 {
       
    95   while (formats && *formats) {
       
    96     const GstFormatDefinition *definition;
       
    97 
       
    98     definition = gst_format_get_details (*formats);
       
    99     if (definition)
       
   100       n_print ("\t\t(%d):\t%s (%s)\n", *formats,
       
   101           definition->nick, definition->description);
       
   102     else
       
   103       n_print ("\t\t(%d):\tUnknown format\n", *formats);
       
   104 
       
   105     formats++;
       
   106   }
       
   107 }
       
   108 #endif
       
   109 
       
   110 static void
       
   111 print_query_types (const GstQueryType * types)
       
   112 {
       
   113   while (types && *types) {
       
   114     const GstQueryTypeDefinition *definition;
       
   115 
       
   116     definition = gst_query_type_get_details (*types);
       
   117     if (definition)
       
   118       n_print ("\t\t(%d):\t%s (%s)\n", *types,
       
   119           definition->nick, definition->description);
       
   120     else
       
   121       n_print ("\t\t(%d):\tUnknown query format\n", *types);
       
   122 
       
   123     types++;
       
   124   }
       
   125 }
       
   126 
       
   127 #ifndef GST_DISABLE_ENUMTYPES
       
   128 #if 0
       
   129 static void
       
   130 print_event_masks (const GstEventMask * masks)
       
   131 {
       
   132   GType event_type;
       
   133   GEnumClass *klass;
       
   134   GType event_flags;
       
   135   GFlagsClass *flags_class = NULL;
       
   136 
       
   137   event_type = gst_event_type_get_type ();
       
   138   klass = (GEnumClass *) g_type_class_ref (event_type);
       
   139 
       
   140   while (masks && masks->type) {
       
   141     GEnumValue *value;
       
   142     gint flags = 0, index = 0;
       
   143 
       
   144     switch (masks->type) {
       
   145       case GST_EVENT_SEEK:
       
   146         flags = masks->flags;
       
   147         event_flags = gst_seek_type_get_type ();
       
   148         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
       
   149         break;
       
   150       default:
       
   151         break;
       
   152     }
       
   153 
       
   154     value = g_enum_get_value (klass, masks->type);
       
   155     g_print ("\t\t%s ", value->value_nick);
       
   156 
       
   157     while (flags) {
       
   158       GFlagsValue *value;
       
   159 
       
   160       if (flags & 1) {
       
   161         value = g_flags_get_first_value (flags_class, 1 << index);
       
   162 
       
   163         if (value)
       
   164           g_print ("| %s ", value->value_nick);
       
   165         else
       
   166           g_print ("| ? ");
       
   167       }
       
   168       flags >>= 1;
       
   169       index++;
       
   170     }
       
   171     g_print ("\n");
       
   172 
       
   173     masks++;
       
   174   }
       
   175 }
       
   176 #endif
       
   177 #else
       
   178 static void
       
   179 print_event_masks (const GstEventMask * masks)
       
   180 {
       
   181 }
       
   182 #endif
       
   183 
       
   184 static char *
       
   185 get_rank_name (gint rank)
       
   186 {
       
   187   switch (rank) {
       
   188     case GST_RANK_NONE:
       
   189       return "none";
       
   190     case GST_RANK_MARGINAL:
       
   191       return "marginal";
       
   192     case GST_RANK_SECONDARY:
       
   193       return "secondary";
       
   194     case GST_RANK_PRIMARY:
       
   195       return "primary";
       
   196     default:
       
   197       return "unknown";
       
   198   }
       
   199 }
       
   200 
       
   201 static void
       
   202 print_factory_details_info (GstElementFactory * factory)
       
   203 {
       
   204   n_print ("Factory Details:\n");
       
   205   n_print ("  Long name:\t%s\n", factory->details.longname);
       
   206   n_print ("  Class:\t%s\n", factory->details.klass);
       
   207   n_print ("  Description:\t%s\n", factory->details.description);
       
   208   n_print ("  Author(s):\t%s\n", factory->details.author);
       
   209   n_print ("  Rank:\t\t%s (%d)\n",
       
   210       get_rank_name (GST_PLUGIN_FEATURE (factory)->rank),
       
   211       GST_PLUGIN_FEATURE (factory)->rank);
       
   212   n_print ("\n");
       
   213 }
       
   214 
       
   215 static void
       
   216 print_hierarchy (GType type, gint level, gint * maxlevel)
       
   217 {
       
   218   GType parent;
       
   219   gint i;
       
   220 
       
   221   parent = g_type_parent (type);
       
   222 
       
   223   *maxlevel = *maxlevel + 1;
       
   224   level++;
       
   225 
       
   226   if (parent)
       
   227     print_hierarchy (parent, level, maxlevel);
       
   228 
       
   229   if (_name)
       
   230     g_print (_name);
       
   231 
       
   232   for (i = 1; i < *maxlevel - level; i++)
       
   233     g_print ("      ");
       
   234   if (*maxlevel - level)
       
   235     g_print (" +----");
       
   236 
       
   237   g_print ("%s\n", g_type_name (type));
       
   238 
       
   239   if (level == 1)
       
   240     n_print ("\n");
       
   241 }
       
   242 
       
   243 static void
       
   244 print_interfaces (GType type)
       
   245 {
       
   246   guint n_ifaces;
       
   247   GType *iface, *ifaces = g_type_interfaces (type, &n_ifaces);
       
   248 
       
   249   if (ifaces) {
       
   250     if (n_ifaces) {
       
   251       if (_name)
       
   252         g_print (_name);
       
   253       g_print (_("Implemented Interfaces:\n"));
       
   254       iface = ifaces;
       
   255       while (*iface) {
       
   256         if (_name)
       
   257           g_print (_name);
       
   258         g_print ("  %s\n", g_type_name (*iface));
       
   259         iface++;
       
   260       }
       
   261       if (_name)
       
   262         g_print (_name);
       
   263       g_print ("\n");
       
   264     }
       
   265     g_free (ifaces);
       
   266   }
       
   267 }
       
   268 
       
   269 static void
       
   270 print_element_properties_info (GstElement * element)
       
   271 {
       
   272   GParamSpec **property_specs;
       
   273   guint num_properties, i;
       
   274   gboolean readable;
       
   275   gboolean first_flag;
       
   276 
       
   277   property_specs = g_object_class_list_properties
       
   278       (G_OBJECT_GET_CLASS (element), &num_properties);
       
   279   n_print ("\n");
       
   280   n_print ("Element Properties:\n");
       
   281 
       
   282   for (i = 0; i < num_properties; i++) {
       
   283     GValue value = { 0, };
       
   284     GParamSpec *param = property_specs[i];
       
   285 
       
   286     readable = FALSE;
       
   287 
       
   288     g_value_init (&value, param->value_type);
       
   289 
       
   290     n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
       
   291         g_param_spec_get_blurb (param));
       
   292 
       
   293     first_flag = TRUE;
       
   294     n_print ("%-23.23s flags: ", "");
       
   295     if (param->flags & G_PARAM_READABLE) {
       
   296       g_object_get_property (G_OBJECT (element), param->name, &value);
       
   297       readable = TRUE;
       
   298       if (!first_flag)
       
   299         g_print (", ");
       
   300       else
       
   301         first_flag = FALSE;
       
   302       g_print (_("readable"));
       
   303     }
       
   304     if (param->flags & G_PARAM_WRITABLE) {
       
   305       if (!first_flag)
       
   306         g_print (", ");
       
   307       else
       
   308         first_flag = FALSE;
       
   309       g_print (_("writable"));
       
   310     }
       
   311     if (param->flags & GST_PARAM_CONTROLLABLE) {
       
   312       if (!first_flag)
       
   313         g_print (", ");
       
   314       else
       
   315         first_flag = FALSE;
       
   316       g_print (_("controllable"));
       
   317     }
       
   318     n_print ("\n");
       
   319 
       
   320     switch (G_VALUE_TYPE (&value)) {
       
   321       case G_TYPE_STRING:
       
   322       {
       
   323         GParamSpecString *pstring = G_PARAM_SPEC_STRING (param);
       
   324 
       
   325         n_print ("%-23.23s String. ", "");
       
   326 
       
   327         if (pstring->default_value == NULL)
       
   328           g_print ("Default: null ");
       
   329         else
       
   330           g_print ("Default: \"%s\" ", pstring->default_value);
       
   331 
       
   332         if (readable) {
       
   333           const char *string_val = g_value_get_string (&value);
       
   334 
       
   335           if (string_val == NULL)
       
   336             g_print ("Current: null");
       
   337           else
       
   338             g_print ("Current: \"%s\"", string_val);
       
   339         }
       
   340         break;
       
   341       }
       
   342       case G_TYPE_BOOLEAN:
       
   343       {
       
   344         GParamSpecBoolean *pboolean = G_PARAM_SPEC_BOOLEAN (param);
       
   345 
       
   346         n_print ("%-23.23s Boolean. ", "");
       
   347         g_print ("Default: %s ", (pboolean->default_value ? "true" : "false"));
       
   348         if (readable)
       
   349           g_print ("Current: %s",
       
   350               (g_value_get_boolean (&value) ? "true" : "false"));
       
   351         break;
       
   352       }
       
   353       case G_TYPE_ULONG:
       
   354       {
       
   355         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
       
   356 
       
   357         n_print ("%-23.23s Unsigned Long. ", "");
       
   358         g_print ("Range: %lu - %lu Default: %lu ",
       
   359             pulong->minimum, pulong->maximum, pulong->default_value);
       
   360         if (readable)
       
   361           g_print ("Current: %lu", g_value_get_ulong (&value));
       
   362         break;
       
   363       }
       
   364       case G_TYPE_LONG:
       
   365       {
       
   366         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
       
   367 
       
   368         n_print ("%-23.23s Long. ", "");
       
   369         g_print ("Range: %ld - %ld Default: %ld ",
       
   370             plong->minimum, plong->maximum, plong->default_value);
       
   371         if (readable)
       
   372           g_print ("Current: %ld", g_value_get_long (&value));
       
   373         break;
       
   374       }
       
   375       case G_TYPE_UINT:
       
   376       {
       
   377         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
       
   378 
       
   379         n_print ("%-23.23s Unsigned Integer. ", "");
       
   380         g_print ("Range: %u - %u Default: %u ",
       
   381             puint->minimum, puint->maximum, puint->default_value);
       
   382         if (readable)
       
   383           g_print ("Current: %u", g_value_get_uint (&value));
       
   384         break;
       
   385       }
       
   386       case G_TYPE_INT:
       
   387       {
       
   388         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
       
   389 
       
   390         n_print ("%-23.23s Integer. ", "");
       
   391         g_print ("Range: %d - %d Default: %d ",
       
   392             pint->minimum, pint->maximum, pint->default_value);
       
   393         if (readable)
       
   394           g_print ("Current: %d", g_value_get_int (&value));
       
   395         break;
       
   396       }
       
   397       case G_TYPE_UINT64:
       
   398       {
       
   399         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
       
   400 
       
   401         n_print ("%-23.23s Unsigned Integer64. ", "");
       
   402         g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
       
   403             " Default: %" G_GUINT64_FORMAT " ",
       
   404             puint64->minimum, puint64->maximum, puint64->default_value);
       
   405         if (readable)
       
   406           g_print ("Current: %" G_GUINT64_FORMAT, g_value_get_uint64 (&value));
       
   407         break;
       
   408       }
       
   409       case G_TYPE_INT64:
       
   410       {
       
   411         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
       
   412 
       
   413         n_print ("%-23.23s Integer64. ", "");
       
   414         g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
       
   415             " Default: %" G_GINT64_FORMAT " ",
       
   416             pint64->minimum, pint64->maximum, pint64->default_value);
       
   417         if (readable)
       
   418           g_print ("Current: %" G_GINT64_FORMAT, g_value_get_int64 (&value));
       
   419         break;
       
   420       }
       
   421       case G_TYPE_FLOAT:
       
   422       {
       
   423         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
       
   424 
       
   425         n_print ("%-23.23s Float. ", "");
       
   426         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
       
   427             pfloat->minimum, pfloat->maximum, pfloat->default_value);
       
   428         if (readable)
       
   429           g_print ("Current: %15.7g", g_value_get_float (&value));
       
   430         break;
       
   431       }
       
   432       case G_TYPE_DOUBLE:
       
   433       {
       
   434         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
       
   435 
       
   436         n_print ("%-23.23s Double. ", "");
       
   437         g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
       
   438             pdouble->minimum, pdouble->maximum, pdouble->default_value);
       
   439         if (readable)
       
   440           g_print ("Current: %15.7g", g_value_get_double (&value));
       
   441         break;
       
   442       }
       
   443       default:
       
   444         if (param->value_type == GST_TYPE_CAPS) {
       
   445           const GstCaps *caps = gst_value_get_caps (&value);
       
   446 
       
   447           if (!caps)
       
   448             n_print ("%-23.23s Caps (NULL)", "");
       
   449           else {
       
   450             print_caps (caps, "                           ");
       
   451           }
       
   452         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
       
   453           GParamSpecEnum *penum = G_PARAM_SPEC_ENUM (param);
       
   454           GEnumValue *values;
       
   455           guint j = 0;
       
   456           gint enum_value;
       
   457           const gchar *def_val_nick = "", *cur_val_nick = "";
       
   458 
       
   459           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
       
   460           enum_value = g_value_get_enum (&value);
       
   461 
       
   462           while (values[j].value_name) {
       
   463             if (values[j].value == enum_value)
       
   464               cur_val_nick = values[j].value_nick;
       
   465             if (values[j].value == penum->default_value)
       
   466               def_val_nick = values[j].value_nick;
       
   467             j++;
       
   468           }
       
   469 
       
   470           n_print
       
   471               ("%-23.23s Enum \"%s\" Default: %d, \"%s\" Current: %d, \"%s\"",
       
   472               "", g_type_name (G_VALUE_TYPE (&value)), penum->default_value,
       
   473               def_val_nick, enum_value, cur_val_nick);
       
   474 
       
   475           j = 0;
       
   476           while (values[j].value_name) {
       
   477             g_print ("\n");
       
   478             if (_name)
       
   479               g_print (_name);
       
   480             g_print ("%-23.23s    (%d): %-16s - %s", "",
       
   481                 values[j].value, values[j].value_nick, values[j].value_name);
       
   482             j++;
       
   483           }
       
   484           /* g_type_class_unref (ec); */
       
   485         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
       
   486           GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
       
   487           GFlagsValue *values;
       
   488           guint j = 0;
       
   489           gint flags_value;
       
   490           GString *cur_flags = NULL, *def_flags = NULL;
       
   491 
       
   492           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
       
   493           flags_value = g_value_get_flags (&value);
       
   494 
       
   495           while (values[j].value_name) {
       
   496             if (values[j].value & flags_value) {
       
   497               if (cur_flags) {
       
   498                 g_string_append_printf (cur_flags, " | %s",
       
   499                     values[j].value_nick);
       
   500               } else {
       
   501                 cur_flags = g_string_new (values[j].value_nick);
       
   502               }
       
   503             }
       
   504             if (values[j].value & pflags->default_value) {
       
   505               if (def_flags) {
       
   506                 g_string_append_printf (def_flags, " | %s",
       
   507                     values[j].value_nick);
       
   508               } else {
       
   509                 def_flags = g_string_new (values[j].value_nick);
       
   510               }
       
   511             }
       
   512             j++;
       
   513           }
       
   514 
       
   515           n_print
       
   516               ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\" Current: 0x%08x, \"%s\"",
       
   517               "", g_type_name (G_VALUE_TYPE (&value)), pflags->default_value,
       
   518               (def_flags ? def_flags->str : "(none)"), flags_value,
       
   519               (cur_flags ? cur_flags->str : "(none)"));
       
   520 
       
   521           j = 0;
       
   522           while (values[j].value_name) {
       
   523             g_print ("\n");
       
   524             if (_name)
       
   525               g_print (_name);
       
   526             g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
       
   527                 values[j].value, values[j].value_nick, values[j].value_name);
       
   528             j++;
       
   529           }
       
   530 
       
   531           if (cur_flags)
       
   532             g_string_free (cur_flags, TRUE);
       
   533           if (def_flags)
       
   534             g_string_free (def_flags, TRUE);
       
   535         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
       
   536           n_print ("%-23.23s Object of type \"%s\"", "",
       
   537               g_type_name (param->value_type));
       
   538         } else if (G_IS_PARAM_SPEC_BOXED (param)) {
       
   539           n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
       
   540               g_type_name (param->value_type));
       
   541         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
       
   542           if (param->value_type != G_TYPE_POINTER) {
       
   543             n_print ("%-23.23s Pointer of type \"%s\".", "",
       
   544                 g_type_name (param->value_type));
       
   545           } else {
       
   546             n_print ("%-23.23s Pointer.", "");
       
   547           }
       
   548         } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
       
   549           n_print ("%-23.23s Array of GValues", "");
       
   550         } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
       
   551           GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);
       
   552 
       
   553           n_print ("%-23.23s Fraction. ", "");
       
   554 
       
   555           g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
       
   556               pfraction->min_num, pfraction->min_den,
       
   557               pfraction->max_num, pfraction->max_den,
       
   558               pfraction->def_num, pfraction->def_den);
       
   559           if (readable)
       
   560             g_print ("Current: %d/%d",
       
   561                 gst_value_get_fraction_numerator (&value),
       
   562                 gst_value_get_fraction_denominator (&value));
       
   563 
       
   564         } else {
       
   565           n_print ("%-23.23s Unknown type %ld \"%s\"", "", param->value_type,
       
   566               g_type_name (param->value_type));
       
   567         }
       
   568         break;
       
   569     }
       
   570     if (!readable)
       
   571       g_print (" Write only\n");
       
   572     else
       
   573       g_print ("\n");
       
   574 
       
   575     g_value_reset (&value);
       
   576   }
       
   577   if (num_properties == 0)
       
   578     n_print ("  none\n");
       
   579 
       
   580   g_free (property_specs);
       
   581 }
       
   582 
       
   583 static void
       
   584 print_pad_templates_info (GstElement * element, GstElementFactory * factory)
       
   585 {
       
   586   GstElementClass *gstelement_class;
       
   587   const GList *pads;
       
   588   GstStaticPadTemplate *padtemplate;
       
   589 
       
   590   n_print ("Pad Templates:\n");
       
   591   if (!factory->numpadtemplates) {
       
   592     n_print ("  none\n");
       
   593     return;
       
   594   }
       
   595 
       
   596   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
       
   597 
       
   598   pads = factory->staticpadtemplates;
       
   599   while (pads) {
       
   600     padtemplate = (GstStaticPadTemplate *) (pads->data);
       
   601     pads = g_list_next (pads);
       
   602 
       
   603     if (padtemplate->direction == GST_PAD_SRC)
       
   604       n_print ("  SRC template: '%s'\n", padtemplate->name_template);
       
   605     else if (padtemplate->direction == GST_PAD_SINK)
       
   606       n_print ("  SINK template: '%s'\n", padtemplate->name_template);
       
   607     else
       
   608       n_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);
       
   609 
       
   610     if (padtemplate->presence == GST_PAD_ALWAYS)
       
   611       n_print ("    Availability: Always\n");
       
   612     else if (padtemplate->presence == GST_PAD_SOMETIMES)
       
   613       n_print ("    Availability: Sometimes\n");
       
   614     else if (padtemplate->presence == GST_PAD_REQUEST) {
       
   615       n_print ("    Availability: On request\n");
       
   616       n_print ("      Has request_new_pad() function: %s\n",
       
   617           GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
       
   618     } else
       
   619       n_print ("    Availability: UNKNOWN!!!\n");
       
   620 
       
   621     if (padtemplate->static_caps.string) {
       
   622       n_print ("    Capabilities:\n");
       
   623       print_caps (gst_static_caps_get (&padtemplate->static_caps), "      ");
       
   624     }
       
   625 
       
   626     n_print ("\n");
       
   627   }
       
   628 }
       
   629 
       
   630 static void
       
   631 print_element_flag_info (GstElement * element)
       
   632 {
       
   633   gboolean have_flags = FALSE;
       
   634 
       
   635   n_print ("\n");
       
   636   n_print ("Element Flags:\n");
       
   637 
       
   638   if (!have_flags)
       
   639     n_print ("  no flags set\n");
       
   640 
       
   641   if (GST_IS_BIN (element)) {
       
   642     n_print ("\n");
       
   643     n_print ("Bin Flags:\n");
       
   644     if (!have_flags)
       
   645       n_print ("  no flags set\n");
       
   646   }
       
   647 }
       
   648 
       
   649 static void
       
   650 print_implementation_info (GstElement * element)
       
   651 {
       
   652   GstObjectClass *gstobject_class;
       
   653   GstElementClass *gstelement_class;
       
   654 
       
   655   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
       
   656   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
       
   657 
       
   658   n_print ("\n");
       
   659   n_print ("Element Implementation:\n");
       
   660 
       
   661   n_print ("  Has change_state() function: %s\n",
       
   662       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
       
   663 #ifndef GST_DISABLE_LOADSAVE
       
   664   n_print ("  Has custom save_thyself() function: %s\n",
       
   665       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
       
   666   n_print ("  Has custom restore_thyself() function: %s\n",
       
   667       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
       
   668 #endif
       
   669 }
       
   670 
       
   671 static void
       
   672 print_clocking_info (GstElement * element)
       
   673 {
       
   674   if (!gst_element_requires_clock (element) &&
       
   675       !(gst_element_provides_clock (element) &&
       
   676           gst_element_get_clock (element))) {
       
   677     n_print ("\n");
       
   678     n_print ("Element has no clocking capabilities.");
       
   679     return;
       
   680   }
       
   681 
       
   682   n_print ("\n");
       
   683   n_print ("Clocking Interaction:\n");
       
   684   if (gst_element_requires_clock (element)) {
       
   685     n_print ("  element requires a clock\n");
       
   686   }
       
   687 
       
   688   if (gst_element_provides_clock (element)) {
       
   689     GstClock *clock;
       
   690 
       
   691     clock = gst_element_get_clock (element);
       
   692     if (clock)
       
   693       n_print ("  element provides a clock: %s\n", GST_OBJECT_NAME (clock));
       
   694     else
       
   695       n_print ("  element is supposed to provide a clock but returned NULL\n");
       
   696   }
       
   697 }
       
   698 
       
   699 #ifndef GST_DISABLE_INDEX
       
   700 static void
       
   701 print_index_info (GstElement * element)
       
   702 {
       
   703   if (gst_element_is_indexable (element)) {
       
   704     n_print ("\n");
       
   705     n_print ("Indexing capabilities:\n");
       
   706     n_print ("  element can do indexing\n");
       
   707   } else {
       
   708     n_print ("\n");
       
   709     n_print ("Element has no indexing capabilities.\n");
       
   710   }
       
   711 }
       
   712 #else
       
   713 static void
       
   714 print_index_info (GstElement * element)
       
   715 {
       
   716 }
       
   717 #endif
       
   718 
       
   719 static void
       
   720 print_pad_info (GstElement * element)
       
   721 {
       
   722   const GList *pads;
       
   723   GstPad *pad;
       
   724 
       
   725   n_print ("\n");
       
   726   n_print ("Pads:\n");
       
   727 
       
   728   if (!element->numpads) {
       
   729     n_print ("  none\n");
       
   730     return;
       
   731   }
       
   732 
       
   733   pads = element->pads;
       
   734   while (pads) {
       
   735     gchar *name;
       
   736 
       
   737     pad = GST_PAD (pads->data);
       
   738     pads = g_list_next (pads);
       
   739 
       
   740     n_print ("");
       
   741 
       
   742     name = gst_pad_get_name (pad);
       
   743     if (gst_pad_get_direction (pad) == GST_PAD_SRC)
       
   744       g_print ("  SRC: '%s'", name);
       
   745     else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
       
   746       g_print ("  SINK: '%s'", name);
       
   747     else
       
   748       g_print ("  UNKNOWN!!!: '%s'", name);
       
   749 
       
   750     g_free (name);
       
   751 
       
   752     g_print ("\n");
       
   753 
       
   754     n_print ("    Implementation:\n");
       
   755     if (pad->chainfunc)
       
   756       n_print ("      Has chainfunc(): %s\n",
       
   757           GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
       
   758     if (pad->getrangefunc)
       
   759       n_print ("      Has getrangefunc(): %s\n",
       
   760           GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
       
   761     if (pad->eventfunc != gst_pad_event_default)
       
   762       n_print ("      Has custom eventfunc(): %s\n",
       
   763           GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
       
   764     if (pad->queryfunc != gst_pad_query_default)
       
   765       n_print ("      Has custom queryfunc(): %s\n",
       
   766           GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
       
   767     if (pad->querytypefunc != gst_pad_get_query_types_default) {
       
   768       n_print ("        Provides query types:\n");
       
   769       print_query_types (gst_pad_get_query_types (pad));
       
   770     }
       
   771 
       
   772     if (pad->intlinkfunc != gst_pad_get_internal_links_default)
       
   773       n_print ("      Has custom intconnfunc(): %s\n",
       
   774           GST_DEBUG_FUNCPTR_NAME (pad->intlinkfunc));
       
   775 
       
   776     if (pad->bufferallocfunc)
       
   777       n_print ("      Has bufferallocfunc(): %s\n",
       
   778           GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
       
   779 
       
   780     if (pad->padtemplate)
       
   781       n_print ("    Pad Template: '%s'\n", pad->padtemplate->name_template);
       
   782 
       
   783     if (pad->caps) {
       
   784       n_print ("    Capabilities:\n");
       
   785       print_caps (pad->caps, "      ");
       
   786     }
       
   787   }
       
   788 }
       
   789 
       
   790 #if 0
       
   791 static gint
       
   792 compare_signal_names (GSignalQuery * a, GSignalQuery * b)
       
   793 {
       
   794   return strcmp (a->signal_name, b->signal_name);
       
   795 }
       
   796 #endif
       
   797 
       
   798 static void
       
   799 print_signal_info (GstElement * element)
       
   800 {
       
   801   /* Signals/Actions Block */
       
   802   guint *signals;
       
   803   guint nsignals;
       
   804   gint i = 0, j, k;
       
   805   GSignalQuery *query = NULL;
       
   806   GType type;
       
   807   GSList *found_signals, *l;
       
   808 
       
   809   for (k = 0; k < 2; k++) {
       
   810     found_signals = NULL;
       
   811     for (type = G_OBJECT_TYPE (element); type; type = g_type_parent (type)) {
       
   812       if (type == GST_TYPE_ELEMENT || type == GST_TYPE_OBJECT)
       
   813         break;
       
   814 
       
   815       if (type == GST_TYPE_BIN && G_OBJECT_TYPE (element) != GST_TYPE_BIN)
       
   816         continue;
       
   817 
       
   818       signals = g_signal_list_ids (type, &nsignals);
       
   819       for (i = 0; i < nsignals; i++) {
       
   820         query = g_new0 (GSignalQuery, 1);
       
   821         g_signal_query (signals[i], query);
       
   822 
       
   823         if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
       
   824             (k == 1 && (query->signal_flags & G_SIGNAL_ACTION)))
       
   825           found_signals = g_slist_append (found_signals, query);
       
   826         else
       
   827           g_free (query);
       
   828       }
       
   829       g_free (signals);
       
   830       signals = NULL;
       
   831     }
       
   832 
       
   833     if (found_signals) {
       
   834       n_print ("\n");
       
   835       if (k == 0)
       
   836         n_print ("Element Signals:\n");
       
   837       else
       
   838         n_print ("Element Actions:\n");
       
   839     } else {
       
   840       continue;
       
   841     }
       
   842 
       
   843     for (l = found_signals; l; l = l->next) {
       
   844       gchar *indent;
       
   845       int indent_len;
       
   846 
       
   847       query = (GSignalQuery *) l->data;
       
   848       indent_len = strlen (query->signal_name) +
       
   849           strlen (g_type_name (query->return_type)) + 24;
       
   850 
       
   851       indent = g_new0 (gchar, indent_len + 1);
       
   852       memset (indent, ' ', indent_len);
       
   853 
       
   854       n_print ("  \"%s\" :  %s user_function (%s* object",
       
   855           query->signal_name,
       
   856           g_type_name (query->return_type), g_type_name (type));
       
   857 
       
   858       for (j = 0; j < query->n_params; j++) {
       
   859         if (_name)
       
   860           g_print (_name);
       
   861         if (G_TYPE_IS_FUNDAMENTAL (query->param_types[j])) {
       
   862           g_print (",\n%s%s arg%d", indent,
       
   863               g_type_name (query->param_types[j]), j);
       
   864         } else if (G_TYPE_IS_ENUM (query->param_types[j])) {
       
   865           g_print (",\n%s%s arg%d", indent,
       
   866               g_type_name (query->param_types[j]), j);
       
   867         } else {
       
   868           g_print (",\n%s%s* arg%d", indent,
       
   869               g_type_name (query->param_types[j]), j);
       
   870         }
       
   871       }
       
   872 
       
   873       if (k == 0) {
       
   874         if (_name)
       
   875           g_print (_name);
       
   876         g_print (",\n%sgpointer user_data);\n", indent);
       
   877       } else
       
   878         g_print (");\n");
       
   879 
       
   880       g_free (indent);
       
   881     }
       
   882 
       
   883     if (found_signals) {
       
   884       g_slist_foreach (found_signals, (GFunc) g_free, NULL);
       
   885       g_slist_free (found_signals);
       
   886     }
       
   887   }
       
   888 }
       
   889 
       
   890 static void
       
   891 print_children_info (GstElement * element)
       
   892 {
       
   893   GList *children;
       
   894 
       
   895   if (!GST_IS_BIN (element))
       
   896     return;
       
   897 
       
   898   children = (GList *) GST_BIN (element)->children;
       
   899   if (children) {
       
   900     n_print ("\n");
       
   901     g_print ("Children:\n");
       
   902   }
       
   903 
       
   904   while (children) {
       
   905     n_print ("  %s\n", GST_ELEMENT_NAME (GST_ELEMENT (children->data)));
       
   906     children = g_list_next (children);
       
   907   }
       
   908 }
       
   909 
       
   910 static void
       
   911 print_element_list (gboolean print_all)
       
   912 {
       
   913   int plugincount = 0, featurecount = 0;
       
   914   GList *plugins, *orig_plugins;
       
   915 
       
   916   orig_plugins = plugins = gst_default_registry_get_plugin_list ();
       
   917   while (plugins) {
       
   918     GList *features, *orig_features;
       
   919     GstPlugin *plugin;
       
   920 
       
   921     plugin = (GstPlugin *) (plugins->data);
       
   922     plugins = g_list_next (plugins);
       
   923     plugincount++;
       
   924 
       
   925     orig_features = features =
       
   926         gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
       
   927         plugin->desc.name);
       
   928     while (features) {
       
   929       GstPluginFeature *feature;
       
   930 
       
   931       feature = GST_PLUGIN_FEATURE (features->data);
       
   932       featurecount++;
       
   933 
       
   934       if (GST_IS_ELEMENT_FACTORY (feature)) {
       
   935         GstElementFactory *factory;
       
   936 
       
   937         factory = GST_ELEMENT_FACTORY (feature);
       
   938         if (print_all)
       
   939           print_element_info (factory, TRUE);
       
   940         else
       
   941           g_print ("%s:  %s: %s\n", plugin->desc.name,
       
   942               GST_PLUGIN_FEATURE_NAME (factory),
       
   943               gst_element_factory_get_longname (factory));
       
   944       }
       
   945 #ifndef GST_DISABLE_INDEX
       
   946       else if (GST_IS_INDEX_FACTORY (feature)) {
       
   947         GstIndexFactory *factory;
       
   948 
       
   949         factory = GST_INDEX_FACTORY (feature);
       
   950         if (!print_all)
       
   951           g_print ("%s:  %s: %s\n", plugin->desc.name,
       
   952               GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
       
   953       }
       
   954 #endif
       
   955       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
       
   956         GstTypeFindFactory *factory;
       
   957 
       
   958         factory = GST_TYPE_FIND_FACTORY (feature);
       
   959         if (!print_all)
       
   960           g_print ("%s: %s: ", plugin->desc.name,
       
   961               gst_plugin_feature_get_name (feature));
       
   962         if (factory->extensions) {
       
   963           guint i = 0;
       
   964 
       
   965           while (factory->extensions[i]) {
       
   966             if (!print_all)
       
   967               g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
       
   968             i++;
       
   969           }
       
   970           if (!print_all)
       
   971             g_print ("\n");
       
   972         } else {
       
   973           if (!print_all)
       
   974             g_print ("no extensions\n");
       
   975         }
       
   976       } else {
       
   977         if (!print_all)
       
   978           n_print ("%s:  %s (%s)\n", plugin->desc.name,
       
   979               GST_PLUGIN_FEATURE_NAME (feature),
       
   980               g_type_name (G_OBJECT_TYPE (feature)));
       
   981       }
       
   982 
       
   983       features = g_list_next (features);
       
   984     }
       
   985 
       
   986     gst_plugin_feature_list_free (orig_features);
       
   987   }
       
   988 
       
   989   gst_plugin_list_free (orig_plugins);
       
   990 
       
   991   g_print ("\n");
       
   992   g_print (_("Total count: "));
       
   993   g_print (ngettext ("%d plugin", "%d plugins", plugincount), plugincount);
       
   994   g_print (", ");
       
   995   g_print (ngettext ("%d feature", "%d features", featurecount), featurecount);
       
   996   g_print ("\n");
       
   997 }
       
   998 
       
   999 static void
       
  1000 print_plugin_info (GstPlugin * plugin)
       
  1001 {
       
  1002   n_print ("Plugin Details:\n");
       
  1003   n_print ("  Name:\t\t\t%s\n", plugin->desc.name);
       
  1004   n_print ("  Description:\t\t%s\n", plugin->desc.description);
       
  1005   n_print ("  Filename:\t\t%s\n",
       
  1006       plugin->filename ? plugin->filename : "(null)");
       
  1007   n_print ("  Version:\t\t%s\n", plugin->desc.version);
       
  1008   n_print ("  License:\t\t%s\n", plugin->desc.license);
       
  1009   n_print ("  Source module:\t%s\n", plugin->desc.source);
       
  1010   n_print ("  Binary package:\t%s\n", plugin->desc.package);
       
  1011   n_print ("  Origin URL:\t\t%s\n", plugin->desc.origin);
       
  1012   n_print ("\n");
       
  1013 }
       
  1014 
       
  1015 static void
       
  1016 print_plugin_features (GstPlugin * plugin)
       
  1017 {
       
  1018   GList *features;
       
  1019   gint num_features = 0;
       
  1020   gint num_elements = 0;
       
  1021   gint num_types = 0;
       
  1022   gint num_indexes = 0;
       
  1023   gint num_other = 0;
       
  1024 
       
  1025   features =
       
  1026       gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
       
  1027       plugin->desc.name);
       
  1028 
       
  1029   while (features) {
       
  1030     GstPluginFeature *feature;
       
  1031 
       
  1032     feature = GST_PLUGIN_FEATURE (features->data);
       
  1033 
       
  1034     if (GST_IS_ELEMENT_FACTORY (feature)) {
       
  1035       GstElementFactory *factory;
       
  1036 
       
  1037       factory = GST_ELEMENT_FACTORY (feature);
       
  1038       n_print ("  %s: %s\n", GST_PLUGIN_FEATURE_NAME (factory),
       
  1039           gst_element_factory_get_longname (factory));
       
  1040       num_elements++;
       
  1041     }
       
  1042 #ifndef GST_DISABLE_INDEX
       
  1043     else if (GST_IS_INDEX_FACTORY (feature)) {
       
  1044       GstIndexFactory *factory;
       
  1045 
       
  1046       factory = GST_INDEX_FACTORY (feature);
       
  1047       n_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
       
  1048       num_indexes++;
       
  1049     }
       
  1050 #endif
       
  1051     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
       
  1052       GstTypeFindFactory *factory;
       
  1053 
       
  1054       factory = GST_TYPE_FIND_FACTORY (feature);
       
  1055       if (factory->extensions) {
       
  1056         guint i = 0;
       
  1057 
       
  1058         g_print ("%s: %s: ", plugin->desc.name,
       
  1059             gst_plugin_feature_get_name (feature));
       
  1060         while (factory->extensions[i]) {
       
  1061           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
       
  1062           i++;
       
  1063         }
       
  1064         g_print ("\n");
       
  1065       } else
       
  1066         g_print ("%s: %s: no extensions\n", plugin->desc.name,
       
  1067             gst_plugin_feature_get_name (feature));
       
  1068 
       
  1069       num_types++;
       
  1070     } else {
       
  1071       n_print ("  %s (%s)\n", gst_object_get_name (GST_OBJECT (feature)),
       
  1072           g_type_name (G_OBJECT_TYPE (feature)));
       
  1073       num_other++;
       
  1074     }
       
  1075     num_features++;
       
  1076     features = g_list_next (features);
       
  1077   }
       
  1078   n_print ("\n");
       
  1079   n_print ("  %d features:\n", num_features);
       
  1080   if (num_elements > 0)
       
  1081     n_print ("  +-- %d elements\n", num_elements);
       
  1082   if (num_types > 0)
       
  1083     n_print ("  +-- %d types\n", num_types);
       
  1084   if (num_indexes > 0)
       
  1085     n_print ("  +-- %d indexes\n", num_indexes);
       
  1086   if (num_other > 0)
       
  1087     n_print ("  +-- %d other objects\n", num_other);
       
  1088 
       
  1089   n_print ("\n");
       
  1090 }
       
  1091 
       
  1092 static int
       
  1093 print_element_features (const gchar * element_name)
       
  1094 {
       
  1095   GstPluginFeature *feature;
       
  1096 
       
  1097   /* FIXME implement other pretty print function for these */
       
  1098 #ifndef GST_DISABLE_INDEX
       
  1099   feature = gst_default_registry_find_feature (element_name,
       
  1100       GST_TYPE_INDEX_FACTORY);
       
  1101   if (feature) {
       
  1102     n_print ("%s: an index\n", element_name);
       
  1103     return 0;
       
  1104   }
       
  1105 #endif
       
  1106   feature = gst_default_registry_find_feature (element_name,
       
  1107       GST_TYPE_TYPE_FIND_FACTORY);
       
  1108   if (feature) {
       
  1109     n_print ("%s: a typefind function\n", element_name);
       
  1110     return 0;
       
  1111   }
       
  1112 
       
  1113   return -1;
       
  1114 }
       
  1115 
       
  1116 static int
       
  1117 print_element_info (GstElementFactory * factory, gboolean print_names)
       
  1118 {
       
  1119   GstElement *element;
       
  1120   gint maxlevel = 0;
       
  1121 
       
  1122   factory =
       
  1123       GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
       
  1124           (factory)));
       
  1125 
       
  1126   if (!factory) {
       
  1127     g_print ("element plugin couldn't be loaded\n");
       
  1128     return -1;
       
  1129   }
       
  1130 
       
  1131   element = gst_element_factory_create (factory, NULL);
       
  1132   if (!element) {
       
  1133     g_print ("couldn't construct element for some reason\n");
       
  1134     return -1;
       
  1135   }
       
  1136 
       
  1137   if (print_names)
       
  1138     _name = g_strdup_printf ("%s: ", GST_PLUGIN_FEATURE (factory)->name);
       
  1139   else
       
  1140     _name = NULL;
       
  1141 
       
  1142   print_factory_details_info (factory);
       
  1143   if (GST_PLUGIN_FEATURE (factory)->plugin_name) {
       
  1144     GstPlugin *plugin;
       
  1145 
       
  1146     plugin = gst_registry_find_plugin (gst_registry_get_default (),
       
  1147         GST_PLUGIN_FEATURE (factory)->plugin_name);
       
  1148     if (plugin) {
       
  1149       print_plugin_info (plugin);
       
  1150     }
       
  1151   }
       
  1152 
       
  1153   print_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
       
  1154   print_interfaces (G_OBJECT_TYPE (element));
       
  1155 
       
  1156   print_pad_templates_info (element, factory);
       
  1157   print_element_flag_info (element);
       
  1158   print_implementation_info (element);
       
  1159   print_clocking_info (element);
       
  1160   print_index_info (element);
       
  1161   print_pad_info (element);
       
  1162   print_element_properties_info (element);
       
  1163   print_signal_info (element);
       
  1164   print_children_info (element);
       
  1165 
       
  1166   gst_object_unref (element);
       
  1167   gst_object_unref (factory);
       
  1168   g_free (_name);
       
  1169 
       
  1170   return 0;
       
  1171 }
       
  1172 
       
  1173 
       
  1174 static void
       
  1175 print_plugin_automatic_install_info_codecs (GstElementFactory * factory)
       
  1176 {
       
  1177   GstPadDirection direction;
       
  1178   const gchar *type_name;
       
  1179   const gchar *klass;
       
  1180   const GList *static_templates, *l;
       
  1181   GstCaps *caps = NULL;
       
  1182   guint i, num;
       
  1183 
       
  1184   klass = gst_element_factory_get_klass (factory);
       
  1185   g_return_if_fail (klass != NULL);
       
  1186 
       
  1187   if (strstr (klass, "Demuxer") ||
       
  1188       strstr (klass, "Decoder") ||
       
  1189       strstr (klass, "Depay") || strstr (klass, "Parser")) {
       
  1190     type_name = "decoder";
       
  1191     direction = GST_PAD_SINK;
       
  1192   } else if (strstr (klass, "Muxer") ||
       
  1193       strstr (klass, "Encoder") || strstr (klass, "Pay")) {
       
  1194     type_name = "encoder";
       
  1195     direction = GST_PAD_SRC;
       
  1196   } else {
       
  1197     return;
       
  1198   }
       
  1199 
       
  1200   /* decoder/demuxer sink pads should always be static and there should only
       
  1201    * be one, the same applies to encoders/muxers and source pads */
       
  1202   static_templates = gst_element_factory_get_static_pad_templates (factory);
       
  1203   for (l = static_templates; l != NULL; l = l->next) {
       
  1204     GstStaticPadTemplate *tmpl = NULL;
       
  1205 
       
  1206     tmpl = (GstStaticPadTemplate *) l->data;
       
  1207     if (tmpl->direction == direction) {
       
  1208       caps = gst_static_pad_template_get_caps (tmpl);
       
  1209       break;
       
  1210     }
       
  1211   }
       
  1212 
       
  1213   if (caps == NULL) {
       
  1214     g_printerr ("Couldn't find static pad template for %s '%s'\n",
       
  1215         type_name, GST_PLUGIN_FEATURE_NAME (factory));
       
  1216     return;
       
  1217   }
       
  1218 
       
  1219   caps = gst_caps_make_writable (caps);
       
  1220   num = gst_caps_get_size (caps);
       
  1221   for (i = 0; i < num; ++i) {
       
  1222     GstStructure *s;
       
  1223     gchar *s_str;
       
  1224 
       
  1225     s = gst_caps_get_structure (caps, i);
       
  1226     /* remove fields that are almost always just MIN-MAX of some sort
       
  1227      * in order to make the caps look less messy */
       
  1228     gst_structure_remove_field (s, "pixel-aspect-ratio");
       
  1229     gst_structure_remove_field (s, "framerate");
       
  1230     gst_structure_remove_field (s, "channels");
       
  1231     gst_structure_remove_field (s, "width");
       
  1232     gst_structure_remove_field (s, "height");
       
  1233     gst_structure_remove_field (s, "rate");
       
  1234     gst_structure_remove_field (s, "depth");
       
  1235     gst_structure_remove_field (s, "clock-rate");
       
  1236     s_str = gst_structure_to_string (s);
       
  1237     g_print ("%s-%s\n", type_name, s_str);
       
  1238     g_free (s_str);
       
  1239   }
       
  1240   gst_caps_unref (caps);
       
  1241 }
       
  1242 
       
  1243 static void
       
  1244 print_plugin_automatic_install_info_protocols (GstElementFactory * factory)
       
  1245 {
       
  1246   gchar **protocols, **p;
       
  1247 
       
  1248   protocols = gst_element_factory_get_uri_protocols (factory);
       
  1249   if (protocols != NULL && *protocols != NULL) {
       
  1250     switch (gst_element_factory_get_uri_type (factory)) {
       
  1251       case GST_URI_SINK:
       
  1252         for (p = protocols; *p != NULL; ++p)
       
  1253           g_print ("urisink-%s\n", *p);
       
  1254         break;
       
  1255       case GST_URI_SRC:
       
  1256         for (p = protocols; *p != NULL; ++p)
       
  1257           g_print ("urisource-%s\n", *p);
       
  1258         break;
       
  1259       default:
       
  1260         break;
       
  1261     }
       
  1262     g_strfreev (protocols);
       
  1263   }
       
  1264 }
       
  1265 
       
  1266 static void
       
  1267 print_plugin_automatic_install_info (GstPlugin * plugin)
       
  1268 {
       
  1269   const gchar *plugin_name;
       
  1270   GList *features, *l;
       
  1271 
       
  1272   plugin_name = gst_plugin_get_name (plugin);
       
  1273 
       
  1274   /* not interested in typefind factories, only element factories */
       
  1275   features = gst_registry_get_feature_list (gst_registry_get_default (),
       
  1276       GST_TYPE_ELEMENT_FACTORY);
       
  1277 
       
  1278   for (l = features; l != NULL; l = l->next) {
       
  1279     GstPluginFeature *feature;
       
  1280 
       
  1281     feature = GST_PLUGIN_FEATURE (l->data);
       
  1282 
       
  1283     /* only interested in the ones that are in the plugin we just loaded */
       
  1284     if (g_str_equal (plugin_name, feature->plugin_name)) {
       
  1285       GstElementFactory *factory;
       
  1286 
       
  1287       g_print ("element-%s\n", gst_plugin_feature_get_name (feature));
       
  1288 
       
  1289       factory = GST_ELEMENT_FACTORY (feature);
       
  1290       print_plugin_automatic_install_info_protocols (factory);
       
  1291       print_plugin_automatic_install_info_codecs (factory);
       
  1292     }
       
  1293   }
       
  1294 
       
  1295   g_list_foreach (features, (GFunc) gst_object_unref, NULL);
       
  1296   g_list_free (features);
       
  1297 }
       
  1298 
       
  1299 int
       
  1300 main (int argc, char *argv[])
       
  1301 {
       
  1302   static gboolean print_all = FALSE;
       
  1303   static gboolean print_aii = FALSE;
       
  1304   GOptionEntry options[] = {
       
  1305     {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
       
  1306         N_("Print all elements"), NULL},
       
  1307     {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
       
  1308         N_("Print a machine-parsable list of features the specified plugin "
       
  1309               "provides.\n                                       "
       
  1310               "Useful in connection with external automatic plugin "
       
  1311               "installation mechanisms"), NULL},
       
  1312     GST_TOOLS_GOPTION_VERSION,
       
  1313     {NULL}
       
  1314   };
       
  1315   GOptionContext *ctx;
       
  1316   GError *err = NULL;
       
  1317 
       
  1318 #ifdef ENABLE_NLS
       
  1319   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
       
  1320   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
       
  1321   textdomain (GETTEXT_PACKAGE);
       
  1322 #endif
       
  1323 
       
  1324   if (!g_thread_supported ())
       
  1325     g_thread_init (NULL);
       
  1326 
       
  1327   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
       
  1328   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
       
  1329   g_option_context_add_group (ctx, gst_init_get_option_group ());
       
  1330   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
       
  1331     g_print ("Error initializing: %s\n", err->message);
       
  1332     exit (1);
       
  1333   }
       
  1334   g_option_context_free (ctx);
       
  1335 
       
  1336   gst_tools_print_version ("gst-inspect");
       
  1337 
       
  1338   if (print_all && argc > 2) {
       
  1339     g_print ("-a requires no extra arguments\n");
       
  1340     return 1;
       
  1341   }
       
  1342 
       
  1343   /* if no arguments, print out list of elements */
       
  1344   if (argc == 1 || print_all) {
       
  1345     print_element_list (print_all);
       
  1346     /* else we try to get a factory */
       
  1347   } else {
       
  1348     GstElementFactory *factory;
       
  1349     GstPlugin *plugin;
       
  1350     const char *arg = argv[argc - 1];
       
  1351     int retval;
       
  1352 
       
  1353     factory = gst_element_factory_find (arg);
       
  1354     /* if there's a factory, print out the info */
       
  1355     if (factory) {
       
  1356       retval = print_element_info (factory, print_all);
       
  1357       gst_object_unref (factory);
       
  1358     } else {
       
  1359       retval = print_element_features (arg);
       
  1360     }
       
  1361 
       
  1362     /* otherwise check if it's a plugin */
       
  1363     if (retval) {
       
  1364       plugin = gst_default_registry_find_plugin (arg);
       
  1365 
       
  1366       /* if there is such a plugin, print out info */
       
  1367       if (plugin) {
       
  1368         if (print_aii) {
       
  1369           print_plugin_automatic_install_info (plugin);
       
  1370         } else {
       
  1371           print_plugin_info (plugin);
       
  1372           print_plugin_features (plugin);
       
  1373         }
       
  1374       } else {
       
  1375         GError *error = NULL;
       
  1376 
       
  1377         if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
       
  1378           plugin = gst_plugin_load_file (arg, &error);
       
  1379 
       
  1380           if (plugin) {
       
  1381             if (print_aii) {
       
  1382               print_plugin_automatic_install_info (plugin);
       
  1383             } else {
       
  1384               print_plugin_info (plugin);
       
  1385               print_plugin_features (plugin);
       
  1386             }
       
  1387           } else {
       
  1388             g_print (_("Could not load plugin file: %s\n"), error->message);
       
  1389             g_error_free (error);
       
  1390             return -1;
       
  1391           }
       
  1392         } else {
       
  1393           g_print (_("No such element or plugin '%s'\n"), arg);
       
  1394           return -1;
       
  1395         }
       
  1396       }
       
  1397     }
       
  1398   }
       
  1399 
       
  1400   return 0;
       
  1401 }