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 | #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 | { |
---|
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; |
---|
35 | guint num_properties, i; |
---|
36 | |
---|
37 | setlocale (LC_ALL, ""); |
---|
38 | |
---|
39 | gst_init (&argc, &argv); |
---|
40 | GST_DEBUG_CATEGORY_INIT (debug_compprep, "compprep", GST_DEBUG_BOLD, |
---|
41 | "gst-compprep application"); |
---|
42 | |
---|
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 ()); |
---|
47 | while (plugins) { |
---|
48 | GstPlugin *plugin; |
---|
49 | |
---|
50 | plugin = (GstPlugin *) (plugins->data); |
---|
51 | plugins = g_list_next (plugins); |
---|
52 | |
---|
53 | features = g_list_copy (gst_plugin_get_feature_list (plugin)); |
---|
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)) |
---|
62 | continue; |
---|
63 | |
---|
64 | factory = GST_ELEMENT_FACTORY (feature); |
---|
65 | |
---|
66 | factorynode = xmlNewChild (doc->xmlRootNode, NULL, "element", NULL); |
---|
67 | xmlNewChild (factorynode, NULL, "name", |
---|
68 | GST_PLUGIN_FEATURE_NAME (factory)); |
---|
69 | |
---|
70 | element = gst_element_factory_create (factory, NULL); |
---|
71 | GST_DEBUG ("adding factory %s", GST_PLUGIN_FEATURE_NAME (factory)); |
---|
72 | if (element == NULL) { |
---|
73 | GST_ERROR ("couldn't construct element from factory %s\n", |
---|
74 | gst_object_get_name (GST_OBJECT (factory))); |
---|
75 | return 1; |
---|
76 | } |
---|
77 | |
---|
78 | /* write out the padtemplates */ |
---|
79 | padtemplates = factory->padtemplates; |
---|
80 | while (padtemplates) { |
---|
81 | padtemplate = (GstPadTemplate *) (padtemplates->data); |
---|
82 | padtemplates = g_list_next (padtemplates); |
---|
83 | |
---|
84 | if (padtemplate->direction == GST_PAD_SRC) |
---|
85 | padnode = |
---|
86 | xmlNewChild (factorynode, NULL, "srcpadtemplate", |
---|
87 | padtemplate->name_template); |
---|
88 | else if (padtemplate->direction == GST_PAD_SINK) |
---|
89 | padnode = |
---|
90 | xmlNewChild (factorynode, NULL, "sinkpadtemplate", |
---|
91 | padtemplate->name_template); |
---|
92 | } |
---|
93 | |
---|
94 | pads = gst_element_get_pad_list (element); |
---|
95 | while (pads) { |
---|
96 | pad = (GstPad *) (pads->data); |
---|
97 | pads = g_list_next (pads); |
---|
98 | |
---|
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)); |
---|
105 | } |
---|
106 | |
---|
107 | /* write out the args */ |
---|
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++) { |
---|
112 | GParamSpec *param = property_specs[i]; |
---|
113 | |
---|
114 | argnode = xmlNewChild (factorynode, NULL, "argument", param->name); |
---|
115 | if (param->value_type == GST_TYPE_URI) { |
---|
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; |
---|
122 | for (j = 0; values[j].value_name; j++) { |
---|
123 | gchar *value = g_strdup_printf ("%d", values[j].value); |
---|
124 | |
---|
125 | optionnode = xmlNewChild (argnode, NULL, "option", value); |
---|
126 | xmlNewChild (optionnode, NULL, "value_nick", values[j].value_nick); |
---|
127 | g_free (value); |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | #ifdef HAVE_LIBXML2 |
---|
135 | #if LIBXML_VERSION >= 20600 |
---|
136 | xmlSetStructuredErrorFunc (NULL, handle_xmlerror); |
---|
137 | #endif |
---|
138 | xmlSaveFormatFile (GST_COMPREG_FILE, doc, 1); |
---|
139 | #else |
---|
140 | xmlSaveFile (GST_COMPREG_FILE, doc); |
---|
141 | #endif |
---|
142 | |
---|
143 | return 0; |
---|
144 | } |
---|