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