[21004] | 1 | #ifdef HAVE_CONFIG_H |
---|
| 2 | # include "config.h" |
---|
| 3 | #endif |
---|
| 4 | |
---|
| 5 | #include <locale.h> |
---|
| 6 | |
---|
[18713] | 7 | #include <gst/gst.h> |
---|
| 8 | |
---|
[21004] | 9 | GST_DEBUG_CATEGORY_STATIC (debug_compprep); |
---|
| 10 | #define GST_CAT_DEFAULT debug_compprep |
---|
| 11 | #define GST_COMPREG_FILE (GST_CACHE_DIR "/compreg.xml") |
---|
| 12 | |
---|
| 13 | #ifdef HAVE_LIBXML2 |
---|
| 14 | #if LIBXML_VERSION >= 20600 |
---|
| 15 | void |
---|
| 16 | handle_xmlerror (void *userData, xmlErrorPtr error) |
---|
| 17 | { |
---|
| 18 | g_print ("Error writing the completion registry: %s, %s\n", GST_COMPREG_FILE, |
---|
| 19 | error->message); |
---|
| 20 | } |
---|
| 21 | #endif |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | int |
---|
| 25 | main (int argc, char *argv[]) |
---|
| 26 | { |
---|
[18713] | 27 | xmlDocPtr doc; |
---|
| 28 | xmlNodePtr factorynode, padnode, argnode, optionnode; |
---|
| 29 | GList *plugins, *features, *padtemplates; |
---|
| 30 | const GList *pads; |
---|
| 31 | GstElement *element; |
---|
| 32 | GstPad *pad; |
---|
| 33 | GstPadTemplate *padtemplate; |
---|
| 34 | GParamSpec **property_specs; |
---|
[21004] | 35 | guint num_properties, i; |
---|
[18713] | 36 | |
---|
[21004] | 37 | setlocale (LC_ALL, ""); |
---|
[18713] | 38 | |
---|
[21004] | 39 | gst_init (&argc, &argv); |
---|
| 40 | GST_DEBUG_CATEGORY_INIT (debug_compprep, "compprep", GST_DEBUG_BOLD, |
---|
| 41 | "gst-compprep application"); |
---|
[18713] | 42 | |
---|
[21004] | 43 | doc = xmlNewDoc ("1.0"); |
---|
| 44 | doc->xmlRootNode = xmlNewDocNode (doc, NULL, "GST-CompletionRegistry", NULL); |
---|
| 45 | |
---|
| 46 | plugins = g_list_copy (gst_registry_pool_plugin_list ()); |
---|
[18713] | 47 | while (plugins) { |
---|
| 48 | GstPlugin *plugin; |
---|
| 49 | |
---|
[21004] | 50 | plugin = (GstPlugin *) (plugins->data); |
---|
[18713] | 51 | plugins = g_list_next (plugins); |
---|
| 52 | |
---|
[21004] | 53 | features = g_list_copy (gst_plugin_get_feature_list (plugin)); |
---|
[18713] | 54 | while (features) { |
---|
| 55 | GstPluginFeature *feature; |
---|
| 56 | GstElementFactory *factory; |
---|
| 57 | |
---|
| 58 | feature = GST_PLUGIN_FEATURE (features->data); |
---|
| 59 | features = g_list_next (features); |
---|
| 60 | |
---|
| 61 | if (!GST_IS_ELEMENT_FACTORY (feature)) |
---|
[21004] | 62 | continue; |
---|
[18713] | 63 | |
---|
| 64 | factory = GST_ELEMENT_FACTORY (feature); |
---|
| 65 | |
---|
| 66 | factorynode = xmlNewChild (doc->xmlRootNode, NULL, "element", NULL); |
---|
[21004] | 67 | xmlNewChild (factorynode, NULL, "name", |
---|
| 68 | GST_PLUGIN_FEATURE_NAME (factory)); |
---|
[18713] | 69 | |
---|
[21004] | 70 | element = gst_element_factory_create (factory, NULL); |
---|
| 71 | GST_DEBUG ("adding factory %s", GST_PLUGIN_FEATURE_NAME (factory)); |
---|
[18713] | 72 | if (element == NULL) { |
---|
[21004] | 73 | GST_ERROR ("couldn't construct element from factory %s\n", |
---|
| 74 | gst_object_get_name (GST_OBJECT (factory))); |
---|
[18713] | 75 | return 1; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /* write out the padtemplates */ |
---|
| 79 | padtemplates = factory->padtemplates; |
---|
| 80 | while (padtemplates) { |
---|
[21004] | 81 | padtemplate = (GstPadTemplate *) (padtemplates->data); |
---|
[18713] | 82 | padtemplates = g_list_next (padtemplates); |
---|
| 83 | |
---|
| 84 | if (padtemplate->direction == GST_PAD_SRC) |
---|
[21004] | 85 | padnode = |
---|
| 86 | xmlNewChild (factorynode, NULL, "srcpadtemplate", |
---|
| 87 | padtemplate->name_template); |
---|
[18713] | 88 | else if (padtemplate->direction == GST_PAD_SINK) |
---|
[21004] | 89 | padnode = |
---|
| 90 | xmlNewChild (factorynode, NULL, "sinkpadtemplate", |
---|
| 91 | padtemplate->name_template); |
---|
[18713] | 92 | } |
---|
| 93 | |
---|
| 94 | pads = gst_element_get_pad_list (element); |
---|
| 95 | while (pads) { |
---|
[21004] | 96 | pad = (GstPad *) (pads->data); |
---|
[18713] | 97 | pads = g_list_next (pads); |
---|
| 98 | |
---|
[21004] | 99 | if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) |
---|
| 100 | padnode = |
---|
| 101 | xmlNewChild (factorynode, NULL, "srcpad", GST_PAD_NAME (pad)); |
---|
| 102 | else if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) |
---|
| 103 | padnode = |
---|
| 104 | xmlNewChild (factorynode, NULL, "sinkpad", GST_PAD_NAME (pad)); |
---|
[18713] | 105 | } |
---|
| 106 | |
---|
| 107 | /* write out the args */ |
---|
[21004] | 108 | property_specs = |
---|
| 109 | g_object_class_list_properties (G_OBJECT_GET_CLASS (element), |
---|
| 110 | &num_properties); |
---|
| 111 | for (i = 0; i < num_properties; i++) { |
---|
[18713] | 112 | GParamSpec *param = property_specs[i]; |
---|
[21004] | 113 | |
---|
[18713] | 114 | argnode = xmlNewChild (factorynode, NULL, "argument", param->name); |
---|
[21004] | 115 | if (param->value_type == GST_TYPE_URI) { |
---|
[18713] | 116 | xmlNewChild (argnode, NULL, "filename", NULL); |
---|
| 117 | } else if (G_IS_PARAM_SPEC_ENUM (param) == G_TYPE_ENUM) { |
---|
| 118 | GEnumValue *values; |
---|
| 119 | gint j; |
---|
| 120 | |
---|
| 121 | values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values; |
---|
[21004] | 122 | for (j = 0; values[j].value_name; j++) { |
---|
| 123 | gchar *value = g_strdup_printf ("%d", values[j].value); |
---|
| 124 | |
---|
[18713] | 125 | optionnode = xmlNewChild (argnode, NULL, "option", value); |
---|
| 126 | xmlNewChild (optionnode, NULL, "value_nick", values[j].value_nick); |
---|
[21004] | 127 | g_free (value); |
---|
[18713] | 128 | } |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | #ifdef HAVE_LIBXML2 |
---|
[21004] | 135 | #if LIBXML_VERSION >= 20600 |
---|
| 136 | xmlSetStructuredErrorFunc (NULL, handle_xmlerror); |
---|
| 137 | #endif |
---|
| 138 | xmlSaveFormatFile (GST_COMPREG_FILE, doc, 1); |
---|
[18713] | 139 | #else |
---|
[21004] | 140 | xmlSaveFile (GST_COMPREG_FILE, doc); |
---|
[18713] | 141 | #endif |
---|
| 142 | |
---|
| 143 | return 0; |
---|
| 144 | } |
---|