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