gstreamer_core/tools/gst-xmlinspect.c
changeset 11 1373546e05c6
parent 2 5505e8908944
equal deleted inserted replaced
10:6f340f756486 11:1373546e05c6
       
     1 #ifdef HAVE_CONFIG_H
       
     2 #  include "config.h"
       
     3 #endif
       
     4 
       
     5 #include <string.h>
       
     6 #include <locale.h>
       
     7 #include <glib/gprintf.h>
       
     8 
       
     9 #include "tools.h"
       
    10 
       
    11 #define PUT_START_TAG(pfx,tag)                                  \
       
    12 G_STMT_START{                                                   \
       
    13   g_print ("%*.*s<%s>\n", pfx, pfx, "", tag);                   \
       
    14 }G_STMT_END
       
    15 
       
    16 #define PUT_END_TAG(pfx,tag)                                    \
       
    17 G_STMT_START{                                                   \
       
    18   g_print ("%*.*s</%s>\n", pfx, pfx, "", tag);                  \
       
    19 }G_STMT_END
       
    20 
       
    21 #define PUT_ESCAPED(pfx,tag,value)                              \
       
    22 G_STMT_START{                                                   \
       
    23   const gchar *toconv = value;                                  \
       
    24   if (value) {                                                  \
       
    25     gchar *v = g_markup_escape_text (toconv, strlen (toconv));  \
       
    26     g_print ("%*.*s<%s>%s</%s>\n", pfx, pfx, "", tag, v, tag);  \
       
    27     g_free (v);                                                 \
       
    28   }                                                             \
       
    29 }G_STMT_END
       
    30 
       
    31 #ifdef G_HAVE_ISO_VARARGS
       
    32 
       
    33 #define PUT_STRING(pfx, ...)                                    \
       
    34 G_STMT_START{                                                   \
       
    35   gchar *ps_val = g_strdup_printf(__VA_ARGS__);                 \
       
    36   g_print ("%*.*s%s\n", pfx, pfx, "", ps_val);                  \
       
    37   g_free(ps_val);                                               \
       
    38 }G_STMT_END
       
    39 
       
    40 #elif defined(G_HAVE_GNUC_VARARGS)
       
    41 
       
    42 #define PUT_STRING(pfx, str, a...)                              \
       
    43 G_STMT_START{                                                   \
       
    44   g_print ("%*.*s"str"\n", pfx, pfx, "" , ##a);                 \
       
    45 }G_STMT_END
       
    46 
       
    47 #else
       
    48 
       
    49 static inline void
       
    50 PUT_STRING (int pfx, const char *format, ...)
       
    51 {
       
    52   va_list varargs;
       
    53 
       
    54   g_print ("%*.*s", pfx, pfx, "");
       
    55   va_start (varargs, format);
       
    56   g_vprintf (format, varargs);
       
    57   va_end (varargs);
       
    58   g_print ("\n");
       
    59 }
       
    60 
       
    61 #endif
       
    62 
       
    63 static void
       
    64 print_caps (const GstCaps * caps, gint pfx)
       
    65 {
       
    66   char *s;
       
    67 
       
    68   if (!caps)
       
    69     return;
       
    70 
       
    71   s = gst_caps_to_string (caps);
       
    72   PUT_ESCAPED (pfx, "caps", s);
       
    73   g_free (s);
       
    74 }
       
    75 
       
    76 #if 0
       
    77 static void
       
    78 print_formats (const GstFormat * formats, gint pfx)
       
    79 {
       
    80   while (formats && *formats) {
       
    81     const GstFormatDefinition *definition;
       
    82 
       
    83     definition = gst_format_get_details (*formats);
       
    84     if (definition)
       
    85       PUT_STRING (pfx, "<format id=\"%d\" nick=\"%s\">%s</format>",
       
    86           *formats, definition->nick, definition->description);
       
    87     else
       
    88       PUT_STRING (pfx, "<format id=\"%d\">unknown</format>", *formats);
       
    89 
       
    90     formats++;
       
    91   }
       
    92 }
       
    93 #endif
       
    94 
       
    95 static void
       
    96 print_query_types (const GstQueryType * types, gint pfx)
       
    97 {
       
    98   while (types && *types) {
       
    99     const GstQueryTypeDefinition *definition;
       
   100 
       
   101     definition = gst_query_type_get_details (*types);
       
   102     if (definition)
       
   103       PUT_STRING (pfx, "<query-type id=\"%d\" nick=\"%s\">%s</query-type>",
       
   104           *types, definition->nick, definition->description);
       
   105     else
       
   106       PUT_STRING (pfx, "<query-type id=\"%d\">unknown</query-type>", *types);
       
   107 
       
   108     types++;
       
   109   }
       
   110 }
       
   111 
       
   112 #if 0
       
   113 static void
       
   114 print_event_masks (const GstEventMask * masks, gint pfx)
       
   115 {
       
   116 #ifndef GST_DISABLE_ENUMTYPES
       
   117   GType event_type;
       
   118   GEnumClass *klass;
       
   119   GType event_flags;
       
   120   GFlagsClass *flags_class = NULL;
       
   121 
       
   122   event_type = gst_event_type_get_type ();
       
   123   klass = (GEnumClass *) g_type_class_ref (event_type);
       
   124 
       
   125   while (masks && masks->type) {
       
   126     GEnumValue *value;
       
   127     gint flags = 0, index = 0;
       
   128 
       
   129     switch (masks->type) {
       
   130       case GST_EVENT_SEEK:
       
   131         flags = masks->flags;
       
   132         event_flags = gst_seek_type_get_type ();
       
   133         flags_class = (GFlagsClass *) g_type_class_ref (event_flags);
       
   134         break;
       
   135       default:
       
   136         break;
       
   137     }
       
   138 
       
   139     value = g_enum_get_value (klass, masks->type);
       
   140     PUT_STRING (pfx, "<event type=\"%s\">", value->value_nick);
       
   141 
       
   142     while (flags) {
       
   143       GFlagsValue *value;
       
   144 
       
   145       if (flags & 1) {
       
   146         value = g_flags_get_first_value (flags_class, 1 << index);
       
   147 
       
   148         if (value)
       
   149           PUT_ESCAPED (pfx + 1, "flag", value->value_nick);
       
   150         else
       
   151           PUT_ESCAPED (pfx + 1, "flag", "?");
       
   152       }
       
   153       flags >>= 1;
       
   154       index++;
       
   155     }
       
   156     PUT_END_TAG (pfx, "event");
       
   157 
       
   158     masks++;
       
   159   }
       
   160 #endif
       
   161 }
       
   162 #endif
       
   163 
       
   164 static void
       
   165 output_hierarchy (GType type, gint level, gint * maxlevel)
       
   166 {
       
   167   GType parent;
       
   168 
       
   169   parent = g_type_parent (type);
       
   170 
       
   171   *maxlevel = *maxlevel + 1;
       
   172   level++;
       
   173 
       
   174   PUT_STRING (level, "<object name=\"%s\">", g_type_name (type));
       
   175 
       
   176   if (parent)
       
   177     output_hierarchy (parent, level, maxlevel);
       
   178 
       
   179   PUT_END_TAG (level, "object");
       
   180 }
       
   181 
       
   182 static void
       
   183 print_element_properties (GstElement * element, gint pfx)
       
   184 {
       
   185   GParamSpec **property_specs;
       
   186   guint num_properties;
       
   187   gint i;
       
   188   gboolean readable;
       
   189 
       
   190   property_specs = g_object_class_list_properties
       
   191       (G_OBJECT_GET_CLASS (element), &num_properties);
       
   192 
       
   193   PUT_START_TAG (pfx, "element-properties");
       
   194 
       
   195   for (i = 0; i < num_properties; i++) {
       
   196     GValue value = { 0, };
       
   197     GParamSpec *param = property_specs[i];
       
   198 
       
   199     readable = FALSE;
       
   200 
       
   201     g_value_init (&value, param->value_type);
       
   202     if (param->flags & G_PARAM_READABLE) {
       
   203       g_object_get_property (G_OBJECT (element), param->name, &value);
       
   204       readable = TRUE;
       
   205     }
       
   206     PUT_START_TAG (pfx + 1, "element-property");
       
   207     PUT_ESCAPED (pfx + 2, "name", g_param_spec_get_name (param));
       
   208     PUT_ESCAPED (pfx + 2, "type", g_type_name (param->value_type));
       
   209     PUT_ESCAPED (pfx + 2, "nick", g_param_spec_get_nick (param));
       
   210     PUT_ESCAPED (pfx + 2, "blurb", g_param_spec_get_blurb (param));
       
   211     if (readable) {
       
   212       PUT_ESCAPED (pfx + 2, "flags", "RW");
       
   213     } else {
       
   214       PUT_ESCAPED (pfx + 2, "flags", "W");
       
   215     }
       
   216 
       
   217     switch (G_VALUE_TYPE (&value)) {
       
   218       case G_TYPE_STRING:
       
   219         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   220         break;
       
   221       case G_TYPE_BOOLEAN:
       
   222         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   223         break;
       
   224       case G_TYPE_ULONG:
       
   225       {
       
   226         GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);
       
   227 
       
   228         PUT_STRING (pfx + 2, "<range min=\"%lu\" max=\"%lu\"/>",
       
   229             pulong->minimum, pulong->maximum);
       
   230         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   231         break;
       
   232       }
       
   233       case G_TYPE_LONG:
       
   234       {
       
   235         GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);
       
   236 
       
   237         PUT_STRING (pfx + 2, "<range min=\"%ld\" max=\"%ld\"/>",
       
   238             plong->minimum, plong->maximum);
       
   239         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   240         break;
       
   241       }
       
   242       case G_TYPE_UINT:
       
   243       {
       
   244         GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);
       
   245 
       
   246         PUT_STRING (pfx + 2, "<range min=\"%u\" max=\"%u\"/>",
       
   247             puint->minimum, puint->maximum);
       
   248         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   249         break;
       
   250       }
       
   251       case G_TYPE_INT:
       
   252       {
       
   253         GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
       
   254 
       
   255         PUT_STRING (pfx + 2, "<range min=\"%d\" max=\"%d\"/>",
       
   256             pint->minimum, pint->maximum);
       
   257         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   258         break;
       
   259       }
       
   260       case G_TYPE_UINT64:
       
   261       {
       
   262         GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);
       
   263 
       
   264         PUT_STRING (pfx + 2,
       
   265             "<range min=\"%" G_GUINT64_FORMAT "\" max=\"%" G_GUINT64_FORMAT
       
   266             "\"/>", puint64->minimum, puint64->maximum);
       
   267         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   268         break;
       
   269       }
       
   270       case G_TYPE_INT64:
       
   271       {
       
   272         GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);
       
   273 
       
   274         PUT_STRING (pfx + 2,
       
   275             "<range min=\"%" G_GINT64_FORMAT "\" max=\"%" G_GINT64_FORMAT
       
   276             "\"/>", pint64->minimum, pint64->maximum);
       
   277         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   278         break;
       
   279       }
       
   280       case G_TYPE_FLOAT:
       
   281       {
       
   282         GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);
       
   283 
       
   284         PUT_STRING (pfx + 2, "<range min=\"%f\" max=\"%f\"/>",
       
   285             pfloat->minimum, pfloat->maximum);
       
   286         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   287         break;
       
   288       }
       
   289       case G_TYPE_DOUBLE:
       
   290       {
       
   291         GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);
       
   292 
       
   293         PUT_STRING (pfx + 2, "<range min=\"%g\" max=\"%g\"/>",
       
   294             pdouble->minimum, pdouble->maximum);
       
   295         PUT_ESCAPED (pfx + 2, "default", g_strdup_value_contents (&value));
       
   296         break;
       
   297       }
       
   298       default:
       
   299         if (param->value_type == GST_TYPE_CAPS) {
       
   300           GstCaps *caps = g_value_peek_pointer (&value);
       
   301 
       
   302           if (!caps)
       
   303             PUT_ESCAPED (pfx + 2, "default", "NULL");
       
   304           else {
       
   305             print_caps (caps, 2);
       
   306           }
       
   307         } else if (G_IS_PARAM_SPEC_ENUM (param)) {
       
   308           GEnumValue *values;
       
   309           guint j = 0;
       
   310           gint enum_value;
       
   311 
       
   312           values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
       
   313           enum_value = g_value_get_enum (&value);
       
   314 
       
   315           while (values[j].value_name) {
       
   316             if (values[j].value == enum_value)
       
   317               break;
       
   318             j++;
       
   319           }
       
   320           PUT_STRING (pfx + 2, "<default>%d</default>", values[j].value);
       
   321 
       
   322           PUT_START_TAG (pfx + 2, "enum-values");
       
   323           j = 0;
       
   324           while (values[j].value_name) {
       
   325             PUT_STRING (pfx + 3, "<value value=\"%d\" nick=\"%s\"/>",
       
   326                 values[j].value, values[j].value_nick);
       
   327             j++;
       
   328           }
       
   329           PUT_END_TAG (pfx + 2, "enum-values");
       
   330         } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
       
   331           GFlagsValue *values;
       
   332           guint j = 0;
       
   333           gint flags_value;
       
   334 
       
   335           values = G_FLAGS_CLASS (g_type_class_ref (param->value_type))->values;
       
   336           flags_value = g_value_get_flags (&value);
       
   337 
       
   338           PUT_STRING (pfx + 2, "<default>%d</default>", flags_value);
       
   339 
       
   340           PUT_START_TAG (pfx + 2, "flags");
       
   341           j = 0;
       
   342           while (values[j].value_name) {
       
   343             PUT_STRING (pfx + 3, "<flag value=\"%d\" nick=\"%s\"/>",
       
   344                 values[j].value, values[j].value_nick);
       
   345             j++;
       
   346           }
       
   347           PUT_END_TAG (pfx + 2, "flags");
       
   348         } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
       
   349           PUT_ESCAPED (pfx + 2, "object-type", g_type_name (param->value_type));
       
   350         }
       
   351         break;
       
   352     }
       
   353 
       
   354     PUT_END_TAG (pfx + 1, "element-property");
       
   355   }
       
   356   PUT_END_TAG (pfx, "element-properties");
       
   357   g_free (property_specs);
       
   358 }
       
   359 
       
   360 static void
       
   361 print_element_signals (GstElement * element, gint pfx)
       
   362 {
       
   363   guint *signals;
       
   364   guint nsignals;
       
   365   gint i, k;
       
   366   GSignalQuery *query;
       
   367 
       
   368   signals = g_signal_list_ids (G_OBJECT_TYPE (element), &nsignals);
       
   369   for (k = 0; k < 2; k++) {
       
   370     gint counted = 0;
       
   371 
       
   372     if (k == 0)
       
   373       PUT_START_TAG (pfx, "element-signals");
       
   374     else
       
   375       PUT_START_TAG (pfx, "element-actions");
       
   376 
       
   377     for (i = 0; i < nsignals; i++) {
       
   378       gint n_params;
       
   379       GType return_type;
       
   380       const GType *param_types;
       
   381       gint j;
       
   382 
       
   383       query = g_new0 (GSignalQuery, 1);
       
   384       g_signal_query (signals[i], query);
       
   385 
       
   386       if ((k == 0 && !(query->signal_flags & G_SIGNAL_ACTION)) ||
       
   387           (k == 1 && (query->signal_flags & G_SIGNAL_ACTION))) {
       
   388         n_params = query->n_params;
       
   389         return_type = query->return_type;
       
   390         param_types = query->param_types;
       
   391 
       
   392         PUT_START_TAG (pfx + 1, "signal");
       
   393         PUT_ESCAPED (pfx + 2, "name", query->signal_name);
       
   394         PUT_ESCAPED (pfx + 2, "return-type", g_type_name (return_type));
       
   395         PUT_ESCAPED (pfx + 2, "object-type",
       
   396             g_type_name (G_OBJECT_TYPE (element)));
       
   397 
       
   398         PUT_START_TAG (pfx + 2, "params");
       
   399         for (j = 0; j < n_params; j++) {
       
   400           PUT_ESCAPED (pfx + 3, "type", g_type_name (param_types[j]));
       
   401         }
       
   402 
       
   403         PUT_END_TAG (pfx + 2, "params");
       
   404 
       
   405         PUT_END_TAG (pfx + 1, "signal");
       
   406 
       
   407         counted++;
       
   408       }
       
   409 
       
   410       g_free (query);
       
   411     }
       
   412     if (k == 0)
       
   413       PUT_END_TAG (pfx, "element-signals");
       
   414     else
       
   415       PUT_END_TAG (pfx, "element-actions");
       
   416   }
       
   417 }
       
   418 
       
   419 static gint
       
   420 print_element_info (GstElementFactory * factory)
       
   421 {
       
   422   GstElement *element;
       
   423   GstObjectClass *gstobject_class;
       
   424   GstElementClass *gstelement_class;
       
   425   GList *pads;
       
   426   GstPad *pad;
       
   427   GstStaticPadTemplate *padtemplate;
       
   428   gint maxlevel = 0;
       
   429 
       
   430   element = gst_element_factory_create (factory, "element");
       
   431   if (!element) {
       
   432     g_print ("couldn't construct element for some reason\n");
       
   433     return -1;
       
   434   }
       
   435   PUT_START_TAG (0, "element");
       
   436   PUT_ESCAPED (1, "name", GST_PLUGIN_FEATURE_NAME (factory));
       
   437 
       
   438   gstobject_class = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS (element));
       
   439   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
       
   440 
       
   441   PUT_START_TAG (1, "details");
       
   442   PUT_ESCAPED (2, "long-name", factory->details.longname);
       
   443   PUT_ESCAPED (2, "class", factory->details.klass);
       
   444   PUT_ESCAPED (2, "description", factory->details.description);
       
   445   PUT_ESCAPED (2, "authors", factory->details.author);
       
   446   PUT_END_TAG (1, "details");
       
   447 
       
   448   output_hierarchy (G_OBJECT_TYPE (element), 0, &maxlevel);
       
   449 
       
   450   PUT_START_TAG (1, "pad-templates");
       
   451   if (factory->numpadtemplates) {
       
   452     pads = factory->staticpadtemplates;
       
   453     while (pads) {
       
   454       padtemplate = (GstStaticPadTemplate *) (pads->data);
       
   455       pads = g_list_next (pads);
       
   456 
       
   457       PUT_START_TAG (2, "pad-template");
       
   458       PUT_ESCAPED (3, "name", padtemplate->name_template);
       
   459 
       
   460       if (padtemplate->direction == GST_PAD_SRC)
       
   461         PUT_ESCAPED (3, "direction", "src");
       
   462       else if (padtemplate->direction == GST_PAD_SINK)
       
   463         PUT_ESCAPED (3, "direction", "sink");
       
   464       else
       
   465         PUT_ESCAPED (3, "direction", "unknown");
       
   466 
       
   467       if (padtemplate->presence == GST_PAD_ALWAYS)
       
   468         PUT_ESCAPED (3, "presence", "always");
       
   469       else if (padtemplate->presence == GST_PAD_SOMETIMES)
       
   470         PUT_ESCAPED (3, "presence", "sometimes");
       
   471       else if (padtemplate->presence == GST_PAD_REQUEST) {
       
   472         PUT_ESCAPED (3, "presence", "request");
       
   473         PUT_ESCAPED (3, "request-function",
       
   474             GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad));
       
   475       } else
       
   476         PUT_ESCAPED (3, "presence", "unknown");
       
   477 
       
   478       if (padtemplate->static_caps.string) {
       
   479         print_caps (gst_static_caps_get (&padtemplate->static_caps), 3);
       
   480       }
       
   481       PUT_END_TAG (2, "pad-template");
       
   482     }
       
   483   }
       
   484   PUT_END_TAG (1, "pad-templates");
       
   485 
       
   486   PUT_START_TAG (1, "element-flags");
       
   487   PUT_END_TAG (1, "element-flags");
       
   488 
       
   489   if (GST_IS_BIN (element)) {
       
   490     PUT_START_TAG (1, "bin-flags");
       
   491 
       
   492     PUT_END_TAG (1, "bin-flags");
       
   493   }
       
   494 
       
   495 
       
   496   PUT_START_TAG (1, "element-implementation");
       
   497 
       
   498   PUT_STRING (2, "<state-change function=\"%s\"/>",
       
   499       GST_DEBUG_FUNCPTR_NAME (gstelement_class->change_state));
       
   500 
       
   501 #ifndef GST_DISABLE_LOADSAVE
       
   502   PUT_STRING (2, "<save function=\"%s\"/>",
       
   503       GST_DEBUG_FUNCPTR_NAME (gstobject_class->save_thyself));
       
   504   PUT_STRING (2, "<load function=\"%s\"/>",
       
   505       GST_DEBUG_FUNCPTR_NAME (gstobject_class->restore_thyself));
       
   506 #endif
       
   507   PUT_END_TAG (1, "element-implementation");
       
   508 
       
   509   PUT_START_TAG (1, "clocking-interaction");
       
   510   if (gst_element_requires_clock (element)) {
       
   511     PUT_STRING (2, "<requires-clock/>");
       
   512   }
       
   513   if (gst_element_provides_clock (element)) {
       
   514     GstClock *clock;
       
   515 
       
   516     clock = gst_element_get_clock (element);
       
   517     if (clock)
       
   518       PUT_STRING (2, "<provides-clock name=\"%s\"/>", GST_OBJECT_NAME (clock));
       
   519   }
       
   520   PUT_END_TAG (1, "clocking-interaction");
       
   521 
       
   522 #ifndef GST_DISABLE_INDEX
       
   523   if (gst_element_is_indexable (element)) {
       
   524     PUT_STRING (1, "<indexing-capabilities/>");
       
   525   }
       
   526 #endif
       
   527 
       
   528   PUT_START_TAG (1, "pads");
       
   529   if (element->numpads) {
       
   530     const GList *pads;
       
   531 
       
   532     pads = element->pads;
       
   533     while (pads) {
       
   534       pad = GST_PAD (pads->data);
       
   535       pads = g_list_next (pads);
       
   536 
       
   537       PUT_START_TAG (2, "pad");
       
   538       PUT_ESCAPED (3, "name", gst_pad_get_name (pad));
       
   539 
       
   540       if (gst_pad_get_direction (pad) == GST_PAD_SRC)
       
   541         PUT_ESCAPED (3, "direction", "src");
       
   542       else if (gst_pad_get_direction (pad) == GST_PAD_SINK)
       
   543         PUT_ESCAPED (3, "direction", "sink");
       
   544       else
       
   545         PUT_ESCAPED (3, "direction", "unknown");
       
   546 
       
   547       if (pad->padtemplate)
       
   548         PUT_ESCAPED (3, "template", pad->padtemplate->name_template);
       
   549 
       
   550       PUT_START_TAG (3, "implementation");
       
   551       if (pad->chainfunc)
       
   552         PUT_STRING (4, "<chain-based function=\"%s\"/>",
       
   553             GST_DEBUG_FUNCPTR_NAME (pad->chainfunc));
       
   554       if (pad->getrangefunc)
       
   555         PUT_STRING (4, "<get-range-based function=\"%s\"/>",
       
   556             GST_DEBUG_FUNCPTR_NAME (pad->getrangefunc));
       
   557       if (pad->eventfunc != gst_pad_event_default)
       
   558         PUT_STRING (4, "<event-function function=\"%s\"/>",
       
   559             GST_DEBUG_FUNCPTR_NAME (pad->eventfunc));
       
   560       if (pad->queryfunc != gst_pad_query_default)
       
   561         PUT_STRING (4, "<query-function function=\"%s\"/>",
       
   562             GST_DEBUG_FUNCPTR_NAME (pad->queryfunc));
       
   563       if (pad->querytypefunc != gst_pad_get_query_types_default) {
       
   564         PUT_STRING (4, "<query-type-func function=\"%s\">",
       
   565             GST_DEBUG_FUNCPTR_NAME (pad->querytypefunc));
       
   566         print_query_types (gst_pad_get_query_types (pad), 5);
       
   567         PUT_END_TAG (4, "query-type-func");
       
   568       }
       
   569 
       
   570       if (pad->intlinkfunc != gst_pad_get_internal_links_default)
       
   571         PUT_STRING (4, "<intlink-function function=\"%s\"/>",
       
   572             GST_DEBUG_FUNCPTR_NAME (pad->intlinkfunc));
       
   573 
       
   574       if (pad->bufferallocfunc)
       
   575         PUT_STRING (4, "<bufferalloc-function function=\"%s\"/>",
       
   576             GST_DEBUG_FUNCPTR_NAME (pad->bufferallocfunc));
       
   577       PUT_END_TAG (3, "implementation");
       
   578 
       
   579       if (pad->caps) {
       
   580         print_caps (pad->caps, 3);
       
   581       }
       
   582       PUT_END_TAG (2, "pad");
       
   583     }
       
   584   }
       
   585   PUT_END_TAG (1, "pads");
       
   586 
       
   587   print_element_properties (element, 1);
       
   588   print_element_signals (element, 1);
       
   589 
       
   590   /* for compound elements */
       
   591   /* FIXME: gst_bin_get_list does not exist anymore
       
   592      if (GST_IS_BIN (element)) {
       
   593      GList *children;
       
   594      GstElement *child;
       
   595      PUT_START_TAG (1, "children");
       
   596      children = (GList *) gst_bin_get_list (GST_BIN (element));
       
   597      while (children) {
       
   598      child = GST_ELEMENT (children->data);
       
   599      children = g_list_next (children);
       
   600 
       
   601      PUT_ESCAPED (2, "child", GST_ELEMENT_NAME (child));
       
   602      }
       
   603      PUT_END_TAG (1, "children");
       
   604      }
       
   605    */
       
   606   PUT_END_TAG (0, "element");
       
   607 
       
   608   return 0;
       
   609 }
       
   610 
       
   611 static void
       
   612 print_element_list (void)
       
   613 {
       
   614   GList *plugins;
       
   615 
       
   616   plugins = gst_default_registry_get_plugin_list ();
       
   617   while (plugins) {
       
   618     GList *features;
       
   619     GstPlugin *plugin;
       
   620 
       
   621     plugin = (GstPlugin *) (plugins->data);
       
   622     plugins = g_list_next (plugins);
       
   623 
       
   624     features =
       
   625         gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
       
   626         plugin->desc.name);
       
   627     while (features) {
       
   628       GstPluginFeature *feature;
       
   629 
       
   630       feature = GST_PLUGIN_FEATURE (features->data);
       
   631 
       
   632       if (GST_IS_ELEMENT_FACTORY (feature)) {
       
   633         GstElementFactory *factory;
       
   634 
       
   635         factory = GST_ELEMENT_FACTORY (feature);
       
   636         g_print ("%s:  %s: %s\n", plugin->desc.name,
       
   637             GST_PLUGIN_FEATURE_NAME (factory),
       
   638             gst_element_factory_get_longname (factory));
       
   639       }
       
   640 #ifndef GST_DISABLE_INDEX
       
   641       else if (GST_IS_INDEX_FACTORY (feature)) {
       
   642         GstIndexFactory *factory;
       
   643 
       
   644         factory = GST_INDEX_FACTORY (feature);
       
   645         g_print ("%s:  %s: %s\n", plugin->desc.name,
       
   646             GST_PLUGIN_FEATURE_NAME (factory), factory->longdesc);
       
   647       }
       
   648 #endif
       
   649       else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
       
   650         GstTypeFindFactory *factory;
       
   651 
       
   652         factory = GST_TYPE_FIND_FACTORY (feature);
       
   653         if (factory->extensions) {
       
   654           guint i = 0;
       
   655 
       
   656           g_print ("%s type: ", plugin->desc.name);
       
   657           while (factory->extensions[i]) {
       
   658             g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
       
   659             i++;
       
   660           }
       
   661         } else
       
   662           g_print ("%s type: N/A\n", plugin->desc.name);
       
   663       } else {
       
   664         g_print ("%s:  %s (%s)\n", plugin->desc.name,
       
   665             GST_PLUGIN_FEATURE_NAME (feature),
       
   666             g_type_name (G_OBJECT_TYPE (feature)));
       
   667       }
       
   668 
       
   669       features = g_list_next (features);
       
   670     }
       
   671   }
       
   672 }
       
   673 
       
   674 static void
       
   675 print_plugin_info (GstPlugin * plugin)
       
   676 {
       
   677   GList *features;
       
   678   gint num_features = 0;
       
   679   gint num_elements = 0;
       
   680   gint num_autoplug = 0;
       
   681   gint num_types = 0;
       
   682   gint num_indexes = 0;
       
   683   gint num_other = 0;
       
   684 
       
   685   g_print ("Plugin Details:\n");
       
   686   g_print ("  Name:\t\t%s\n", plugin->desc.name);
       
   687   g_print ("  Description:\t%s\n", plugin->desc.description);
       
   688   g_print ("  Filename:\t%s\n", plugin->filename);
       
   689   g_print ("  Version:\t%s\n", plugin->desc.version);
       
   690   g_print ("  License:\t%s\n", plugin->desc.license);
       
   691   g_print ("  Package:\t%s\n", plugin->desc.package);
       
   692   g_print ("  Origin URL:\t%s\n", plugin->desc.origin);
       
   693   g_print ("\n");
       
   694 
       
   695   features =
       
   696       gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
       
   697       plugin->desc.name);
       
   698 
       
   699   while (features) {
       
   700     GstPluginFeature *feature;
       
   701 
       
   702     feature = GST_PLUGIN_FEATURE (features->data);
       
   703 
       
   704     if (GST_IS_ELEMENT_FACTORY (feature)) {
       
   705       GstElementFactory *factory;
       
   706 
       
   707       factory = GST_ELEMENT_FACTORY (feature);
       
   708       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory),
       
   709           gst_element_factory_get_longname (factory));
       
   710       num_elements++;
       
   711     }
       
   712 #ifndef GST_DISABLE_INDEX
       
   713     else if (GST_IS_INDEX_FACTORY (feature)) {
       
   714       GstIndexFactory *factory;
       
   715 
       
   716       factory = GST_INDEX_FACTORY (feature);
       
   717       g_print ("  %s: %s\n", GST_OBJECT_NAME (factory), factory->longdesc);
       
   718       num_indexes++;
       
   719     }
       
   720 #endif
       
   721     else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
       
   722       GstTypeFindFactory *factory;
       
   723 
       
   724       factory = GST_TYPE_FIND_FACTORY (feature);
       
   725       if (factory->extensions) {
       
   726         guint i = 0;
       
   727 
       
   728         g_print ("%s type: ", plugin->desc.name);
       
   729         while (factory->extensions[i]) {
       
   730           g_print ("%s%s", i > 0 ? ", " : "", factory->extensions[i]);
       
   731           i++;
       
   732         }
       
   733       } else
       
   734         g_print ("%s type: N/A\n", plugin->desc.name);
       
   735       num_types++;
       
   736     } else {
       
   737       g_print ("  %s (%s)\n", GST_OBJECT_NAME (feature),
       
   738           g_type_name (G_OBJECT_TYPE (feature)));
       
   739       num_other++;
       
   740     }
       
   741     num_features++;
       
   742     features = g_list_next (features);
       
   743   }
       
   744   g_print ("\n  %d features:\n", num_features);
       
   745   if (num_elements > 0)
       
   746     g_print ("  +-- %d elements\n", num_elements);
       
   747   if (num_autoplug > 0)
       
   748     g_print ("  +-- %d autopluggers\n", num_autoplug);
       
   749   if (num_types > 0)
       
   750     g_print ("  +-- %d types\n", num_types);
       
   751   if (num_indexes > 0)
       
   752     g_print ("  +-- %d indexes\n", num_indexes);
       
   753   if (num_other > 0)
       
   754     g_print ("  +-- %d other objects\n", num_other);
       
   755 
       
   756   g_print ("\n");
       
   757 }
       
   758 
       
   759 
       
   760 int
       
   761 main (int argc, char *argv[])
       
   762 {
       
   763   GstElementFactory *factory;
       
   764   GstPlugin *plugin;
       
   765   gchar *so;
       
   766   GOptionEntry options[] = {
       
   767     {"gst-inspect-plugin", 'p', 0, G_OPTION_ARG_STRING,
       
   768         "Show plugin details", NULL},
       
   769     {"gst-inspect-scheduler", 's', 0, G_OPTION_ARG_STRING,
       
   770         "Show scheduler details", NULL},
       
   771     GST_TOOLS_GOPTION_VERSION,
       
   772     {NULL}
       
   773   };
       
   774   GOptionContext *ctx;
       
   775   GError *err = NULL;
       
   776 
       
   777   setlocale (LC_ALL, "");
       
   778 
       
   779   if (!g_thread_supported ())
       
   780     g_thread_init (NULL);
       
   781 
       
   782   ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
       
   783   g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
       
   784   g_option_context_add_group (ctx, gst_init_get_option_group ());
       
   785   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
       
   786     g_print ("Error initializing: %s\n", err->message);
       
   787     exit (1);
       
   788   }
       
   789   g_option_context_free (ctx);
       
   790 
       
   791   gst_tools_print_version ("gst-xmlinspect");
       
   792 
       
   793   PUT_STRING (0, "<?xml version=\"1.0\"?>");
       
   794 
       
   795   /* if no arguments, print out list of elements */
       
   796   if (argc == 1) {
       
   797     print_element_list ();
       
   798 
       
   799     /* else we try to get a factory */
       
   800   } else {
       
   801     /* first check for help */
       
   802     if (strstr (argv[1], "-help")) {
       
   803       g_print ("Usage: %s\t\t\tList all registered elements\n", argv[0]);
       
   804       g_print ("       %s element-name\tShow element details\n", argv[0]);
       
   805       g_print ("       %s plugin-name[.so]\tShow information about plugin\n",
       
   806           argv[0]);
       
   807       return 0;
       
   808     }
       
   809 
       
   810     /* only search for a factory if there's not a '.so' */
       
   811     if (!strstr (argv[1], ".so")) {
       
   812       factory = gst_element_factory_find (argv[1]);
       
   813 
       
   814       /* if there's a factory, print out the info */
       
   815       if (factory)
       
   816         return print_element_info (factory);
       
   817       else {
       
   818         GstPluginFeature *feature;
       
   819 
       
   820         /* FIXME implement other pretty print function for these */
       
   821 #ifndef GST_DISABLE_INDEX
       
   822         feature = gst_default_registry_find_feature (argv[1],
       
   823             GST_TYPE_INDEX_FACTORY);
       
   824         if (feature) {
       
   825           g_print ("%s: an index\n", argv[1]);
       
   826           return 0;
       
   827         }
       
   828 #endif
       
   829         feature = gst_default_registry_find_feature (argv[1],
       
   830             GST_TYPE_TYPE_FIND_FACTORY);
       
   831         if (feature) {
       
   832           g_print ("%s: a type find function\n", argv[1]);
       
   833           return 0;
       
   834         }
       
   835       }
       
   836     } else {
       
   837       /* strip the .so */
       
   838       so = strstr (argv[1], ".so");
       
   839       so[0] = '\0';
       
   840     }
       
   841 
       
   842     /* otherwise assume it's a plugin */
       
   843     plugin = gst_default_registry_find_plugin (argv[1]);
       
   844 
       
   845     /* if there is such a plugin, print out info */
       
   846 
       
   847     if (plugin) {
       
   848       print_plugin_info (plugin);
       
   849     } else {
       
   850       g_print ("no such element or plugin '%s'\n", argv[1]);
       
   851       return -1;
       
   852     }
       
   853   }
       
   854 
       
   855   return 0;
       
   856 }