2019-09-17 15:52:10 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
from string import Template
|
|
|
|
|
|
|
|
TEMPLATE = Template('''
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2020-07-16 11:18:38 +00:00
|
|
|
$elements_declaration
|
|
|
|
$typefind_funcs_declaration
|
|
|
|
$device_providers_declaration
|
|
|
|
$dynamic_types_declaration
|
2019-09-17 15:52:10 +00:00
|
|
|
$plugins_declaration
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_init_static_plugins (void)
|
|
|
|
{
|
2020-10-01 14:43:36 +00:00
|
|
|
static gsize initialization_value = 0;
|
|
|
|
if (g_once_init_enter (&initialization_value)) {
|
2020-07-16 11:18:38 +00:00
|
|
|
$elements_registration
|
|
|
|
$typefind_funcs_registration
|
|
|
|
$device_providers_registration
|
|
|
|
$dynamic_types_registration
|
2020-10-01 14:43:36 +00:00
|
|
|
$plugins_registration
|
2020-07-16 11:18:38 +00:00
|
|
|
|
2020-10-01 14:43:36 +00:00
|
|
|
g_once_init_leave (&initialization_value, 1);
|
|
|
|
}
|
2019-09-17 15:52:10 +00:00
|
|
|
}
|
|
|
|
''')
|
2022-02-04 13:47:32 +00:00
|
|
|
|
|
|
|
|
2020-07-16 11:18:38 +00:00
|
|
|
# Retrieve the plugin name as it can be a plugin filename
|
|
|
|
def get_plugin_name(name):
|
|
|
|
for p in plugins:
|
|
|
|
if name in p:
|
|
|
|
return p
|
|
|
|
return ''
|
|
|
|
|
2022-02-04 13:47:32 +00:00
|
|
|
|
2020-07-16 11:18:38 +00:00
|
|
|
def process_features(features_list, plugins, feature_prefix):
|
|
|
|
plugins_list = plugins
|
|
|
|
feature_declaration = []
|
|
|
|
feature_registration = []
|
|
|
|
if features_list is not None:
|
2022-02-04 13:47:32 +00:00
|
|
|
feature_plugins = features_list.split(';')
|
2020-07-16 11:18:38 +00:00
|
|
|
for plugin in feature_plugins:
|
|
|
|
split = plugin.split(':')
|
|
|
|
plugin_name = split[0].strip()
|
|
|
|
if len(split) == 2:
|
|
|
|
if (get_plugin_name(plugin_name)) != '':
|
|
|
|
plugins_list.remove(get_plugin_name(plugin_name))
|
|
|
|
features = split[1].split(',')
|
|
|
|
for feature in features:
|
|
|
|
feature = feature.replace("-", "_")
|
|
|
|
feature_declaration += ['%s_REGISTER_DECLARE(%s);' % (feature_prefix, feature)]
|
|
|
|
feature_registration += ['%s_REGISTER(%s, NULL);' % (feature_prefix, feature)]
|
|
|
|
return (plugins_list, feature_declaration, feature_registration)
|
2019-09-17 15:52:10 +00:00
|
|
|
|
2022-02-04 13:47:32 +00:00
|
|
|
|
2019-09-17 15:52:10 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
2020-07-16 11:18:38 +00:00
|
|
|
parser.add_argument('-o', dest="output", help="Output file")
|
2022-02-04 13:47:32 +00:00
|
|
|
parser.add_argument('-p', '--plugins', nargs='?', default='', dest="plugins", help="The list of plugins")
|
2020-07-16 11:18:38 +00:00
|
|
|
parser.add_argument('-e', '--elements', nargs='?', default='', dest="elements", help="The list of plugin:elements")
|
2022-02-04 13:47:32 +00:00
|
|
|
parser.add_argument('-t', '--type-finds', nargs='?', default='',
|
|
|
|
dest="typefindfuncs", help="The list of plugin:typefinds")
|
|
|
|
parser.add_argument('-d', '--devide-providers', nargs='?', default='',
|
|
|
|
dest="deviceproviders", help="The list of plugin:deviceproviders")
|
|
|
|
parser.add_argument('-T', '--dynamic-types', nargs='?', default='',
|
|
|
|
dest="dynamictypes", help="The list of plugin:dynamictypes")
|
2019-09-17 15:52:10 +00:00
|
|
|
options = parser.parse_args()
|
2020-07-16 11:18:38 +00:00
|
|
|
if options.output is None:
|
|
|
|
output_file = 'gstinitstaticplugins.c'
|
|
|
|
else:
|
|
|
|
output_file = options.output
|
2022-02-04 13:47:32 +00:00
|
|
|
enable_staticelements_plugin = 0
|
2020-07-16 11:18:38 +00:00
|
|
|
elements_declaration = []
|
|
|
|
elements_registration = []
|
|
|
|
typefind_funcs_declaration = []
|
|
|
|
typefind_funcs_registration = []
|
|
|
|
device_providers_declaration = []
|
|
|
|
device_providers_registration = []
|
|
|
|
dynamic_types_declaration = []
|
|
|
|
dynamic_types_registration = []
|
|
|
|
plugins_declaration = []
|
|
|
|
plugins_registration = []
|
2019-09-17 15:52:10 +00:00
|
|
|
|
2022-02-04 13:46:24 +00:00
|
|
|
if ',' in options.plugins or ':' in options.plugins:
|
|
|
|
print("Only ';' is allowed in the list of plugins.")
|
|
|
|
exit(1)
|
|
|
|
|
2021-05-18 12:30:33 +00:00
|
|
|
if options.plugins is None or options.plugins.isspace():
|
2020-07-16 11:18:38 +00:00
|
|
|
plugins = []
|
|
|
|
else:
|
|
|
|
plugins = options.plugins.split(';')
|
|
|
|
|
|
|
|
# process the features
|
|
|
|
(plugins, elements_declaration, elements_registration) = process_features(options.elements, plugins, 'GST_ELEMENT')
|
2022-02-04 13:47:32 +00:00
|
|
|
(plugins, typefind_funcs_declaration, typefind_funcs_registration) = process_features(
|
|
|
|
options.typefindfuncs, plugins, 'GST_TYPE_FIND')
|
|
|
|
(plugins, device_providers_declaration, device_providers_registration) = process_features(
|
|
|
|
options.deviceproviders, plugins, 'GST_DEVICE_PROVIDER')
|
|
|
|
(plugins, dynamic_types_declaration, dynamic_types_registration) = process_features(
|
|
|
|
options.dynamictypes, plugins, 'GST_DYNAMIC_TYPE')
|
2020-07-16 11:18:38 +00:00
|
|
|
|
|
|
|
# Enable plugin or elements according to the ';' separated list.
|
|
|
|
for plugin in plugins:
|
|
|
|
split = plugin.split(':')
|
|
|
|
plugin_name = split[0]
|
|
|
|
if plugin_name == '':
|
2022-02-04 13:47:32 +00:00
|
|
|
continue
|
2019-09-17 15:52:10 +00:00
|
|
|
filename = os.path.basename(plugin)
|
|
|
|
if filename.startswith('libgst') and filename.endswith('.a'):
|
2020-07-16 11:18:38 +00:00
|
|
|
plugin_name = filename[len('libgst'):-len('.a')]
|
|
|
|
plugins_registration += ['GST_PLUGIN_STATIC_REGISTER(%s);' % (plugin_name)]
|
|
|
|
plugins_declaration += ['GST_PLUGIN_STATIC_DECLARE(%s);' % (plugin_name)]
|
2019-09-17 15:52:10 +00:00
|
|
|
|
2020-07-16 11:18:38 +00:00
|
|
|
with open(output_file.strip(), "w") as f:
|
|
|
|
static_elements_plugin = ''
|
2019-09-17 15:52:10 +00:00
|
|
|
f.write(TEMPLATE.substitute({
|
2020-07-16 11:18:38 +00:00
|
|
|
'elements_declaration': '\n'.join(elements_declaration),
|
|
|
|
'elements_registration': '\n '.join(elements_registration),
|
|
|
|
'typefind_funcs_declaration': '\n'.join(typefind_funcs_declaration),
|
|
|
|
'typefind_funcs_registration': '\n '.join(typefind_funcs_registration),
|
|
|
|
'device_providers_declaration': '\n'.join(device_providers_declaration),
|
|
|
|
'device_providers_registration': '\n '.join(device_providers_registration),
|
|
|
|
'dynamic_types_declaration': '\n'.join(dynamic_types_declaration),
|
|
|
|
'dynamic_types_registration': '\n '.join(dynamic_types_registration),
|
|
|
|
'plugins_declaration': '\n'.join(plugins_declaration),
|
|
|
|
'plugins_registration': '\n '.join(plugins_registration),
|
2022-02-04 13:47:32 +00:00
|
|
|
}))
|