5 from string import Template
7 TEMPLATE = Template('''
11 $typefind_funcs_declaration
12 $device_providers_declaration
13 $dynamic_types_declaration
17 gst_init_static_plugins (void)
19 static gsize initialization_value = 0;
20 if (g_once_init_enter (&initialization_value)) {
21 $elements_registration
22 $typefind_funcs_registration
23 $device_providers_registration
24 $dynamic_types_registration
27 g_once_init_leave (&initialization_value, 1);
31 # Retrieve the plugin name as it can be a plugin filename
32 def get_plugin_name(name):
38 def process_features(features_list, plugins, feature_prefix):
39 plugins_list = plugins
40 feature_declaration = []
41 feature_registration = []
42 if features_list is not None:
43 feature_plugins = features_list.split(';')
44 for plugin in feature_plugins:
45 split = plugin.split(':')
46 plugin_name = split[0].strip()
48 if (get_plugin_name(plugin_name)) != '':
49 plugins_list.remove(get_plugin_name(plugin_name))
50 features = split[1].split(',')
51 for feature in features:
52 feature = feature.replace("-", "_")
53 feature_declaration += ['%s_REGISTER_DECLARE(%s);' % (feature_prefix, feature)]
54 feature_registration += ['%s_REGISTER(%s, NULL);' % (feature_prefix, feature)]
55 return (plugins_list, feature_declaration, feature_registration)
57 if __name__ == "__main__":
58 parser = argparse.ArgumentParser()
59 parser.add_argument('-o', dest="output", help="Output file")
60 parser.add_argument('-p','--plugins', nargs='?', default='', dest="plugins", help="The list of plugins")
61 parser.add_argument('-e', '--elements', nargs='?', default='', dest="elements", help="The list of plugin:elements")
62 parser.add_argument('-t', '--type-finds', nargs='?', default='', dest="typefindfuncs", help="The list of plugin:typefinds")
63 parser.add_argument('-d', '--devide-providers', nargs='?', default='', dest="deviceproviders", help="The list of plugin:deviceproviders")
64 parser.add_argument('-T', '--dynamic-types', nargs='?', default='', dest="dynamictypes", help="The list of plugin:dynamictypes")
65 options = parser.parse_args()
66 if options.output is None:
67 output_file = 'gstinitstaticplugins.c'
69 output_file = options.output
70 enable_staticelements_plugin = 0;
71 elements_declaration = []
72 elements_registration = []
73 typefind_funcs_declaration = []
74 typefind_funcs_registration = []
75 device_providers_declaration = []
76 device_providers_registration = []
77 dynamic_types_declaration = []
78 dynamic_types_registration = []
79 plugins_declaration = []
80 plugins_registration = []
82 if options.plugins is None:
85 plugins = options.plugins.split(';')
87 # process the features
88 (plugins, elements_declaration, elements_registration) = process_features(options.elements, plugins, 'GST_ELEMENT')
89 (plugins, typefind_funcs_declaration, typefind_funcs_registration) = process_features(options.typefindfuncs, plugins, 'GST_TYPE_FIND')
90 (plugins, device_providers_declaration, device_providers_registration) = process_features(options.deviceproviders, plugins, 'GST_DEVICE_PROVIDER')
91 (plugins, dynamic_types_declaration, dynamic_types_registration) = process_features(options.dynamictypes, plugins, 'GST_DYNAMIC_TYPE')
93 # Enable plugin or elements according to the ';' separated list.
94 for plugin in plugins:
95 split = plugin.split(':')
96 plugin_name = split[0]
99 filename = os.path.basename(plugin)
100 if filename.startswith('libgst') and filename.endswith('.a'):
101 plugin_name = filename[len('libgst'):-len('.a')]
102 plugins_registration += ['GST_PLUGIN_STATIC_REGISTER(%s);' % (plugin_name)]
103 plugins_declaration += ['GST_PLUGIN_STATIC_DECLARE(%s);' % (plugin_name)]
105 with open(output_file.strip(), "w") as f:
106 static_elements_plugin = ''
107 f.write(TEMPLATE.substitute({
108 'elements_declaration': '\n'.join(elements_declaration),
109 'elements_registration': '\n '.join(elements_registration),
110 'typefind_funcs_declaration': '\n'.join(typefind_funcs_declaration),
111 'typefind_funcs_registration': '\n '.join(typefind_funcs_registration),
112 'device_providers_declaration': '\n'.join(device_providers_declaration),
113 'device_providers_registration': '\n '.join(device_providers_registration),
114 'dynamic_types_declaration': '\n'.join(dynamic_types_declaration),
115 'dynamic_types_registration': '\n '.join(dynamic_types_registration),
116 'plugins_declaration': '\n'.join(plugins_declaration),
117 'plugins_registration': '\n '.join(plugins_registration),