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