#include "nnstreamer-capi-private.h"
#include "nnstreamer_plugin_api.h"
#include "nnstreamer_plugin_api_filter.h"
+#include "nnstreamer_conf.h"
#if defined(__TIZEN__)
#include <system_info.h>
int
ml_check_plugin_availability (const char *plugin_name, const char *element_name)
{
-#ifdef __TIZEN__
+ static gboolean list_loaded = FALSE;
+ static gchar **restricted_elements = NULL;
+
if (!plugin_name || !element_name) {
ml_loge ("The name is invalid, failed to check the availability.");
return ML_ERROR_INVALID_PARAMETER;
}
- /**
- * @todo check white-list of available plugins
- * e.g, plugin name 'nnstreamer', element name 'tensor_converter'
- */
-#endif /* __TIZEN__ */
+ if (!list_loaded) {
+ gboolean restricted;
+
+ restricted = nnsconf_get_custom_value_bool ("element-restriction", "enable_element_restriction", FALSE);
+ if (restricted) {
+ gchar *elements;
+
+ /* check white-list of available plugins */
+ elements = nnsconf_get_custom_value_string ("element-restriction", "restricted_elements");
+ if (elements) {
+ restricted_elements = g_strsplit_set (elements, " ,;", -1);
+ g_free (elements);
+ }
+ }
+
+ list_loaded = TRUE;
+ }
+
+ /* nnstreamer elements */
+ if (g_str_equal (plugin_name, "nnstreamer") &&
+ g_str_has_prefix (element_name, "tensor_")) {
+ return ML_ERROR_NONE;
+ }
+
+ if (restricted_elements &&
+ find_key_strv ((const gchar **) restricted_elements, element_name) < 0) {
+ ml_logw ("The element %s is restricted.", element_name);
+ return ML_ERROR_NOT_SUPPORTED;
+ }
+
return ML_ERROR_NONE;
}
nnstreamer_test_conf.set('ENABLE_ENV_VAR', true)
nnstreamer_test_conf.set('ENABLE_SYMBOLIC_LINK', false)
nnstreamer_test_conf.set('TORCH_USE_GPU', false)
+ nnstreamer_test_conf.set('ELEMENT_RESTRICTION_CONFIG', '')
# meson 0.50 supports install argument in configure_file()
if get_option('install-test')
nnstreamer_install_conf.set('ENABLE_SYMBOLIC_LINK', get_option('enable-symbolic-link'))
nnstreamer_install_conf.set('TORCH_USE_GPU', get_option('enable-pytorch-use-gpu'))
+# Element restriction
+restriction_config = ''
+
+if get_option('enable-element-restriction')
+ restriction_config = '''[element-restriction]
+enable_element_restriction=True
+restricted_elements=''' + get_option('restricted-elements')
+endif
+
+nnstreamer_install_conf.set('ELEMENT_RESTRICTION_CONFIG', restriction_config)
+
# Install .ini
configure_file(input: 'nnstreamer.ini.in', output: 'nnstreamer.ini',
install_dir: nnstreamer_inidir,
option('enable-capi', type: 'boolean', value: false)
option('enable-python', type: 'boolean', value: true)
option('enable-tizen', type: 'boolean', value: false)
+option('enable-element-restriction', type: 'boolean', value: false) # true to restrict gst-elements in api
+option('restricted-elements', type: 'string', value: '')
# Set 1 or True if you want to use GPU with pytorch for computation.
[pytorch]
enable_use_gpu=@TORCH_USE_GPU@
+
+@ELEMENT_RESTRICTION_CONFIG@