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