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