[Api/Pipeline] element restriction
authorJaeyun <jy1210.jung@samsung.com>
Thu, 8 Aug 2019 11:57:45 +0000 (20:57 +0900)
committerwooksong <wook16.song@samsung.com>
Mon, 19 Aug 2019 14:07:07 +0000 (23:07 +0900)
Handles element restriction (whitelist for API release)

If needs restriction in pipeline elements, simply set the list in meson option.

e.g. meson -Denable-capi=true -Denable-element-restriction=true -Drestricted-elements='videotestsrc videoconvert' build
this allows videotestsrc and videoconvert with nnstreamer elements.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
api/capi/src/nnstreamer-capi-util.c
meson.build
meson_options.txt
nnstreamer.ini.in

index 3907eba..7dd6d77 100644 (file)
@@ -26,6 +26,7 @@
 #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>
@@ -932,16 +933,43 @@ ml_set_feature_status (int status)
 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;
 }
index d7b3dc3..a3defb9 100644 (file)
@@ -236,6 +236,7 @@ if get_option('enable-test')
   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')
@@ -258,6 +259,17 @@ nnstreamer_install_conf.set('ENABLE_ENV_VAR', get_option('enable-env-var'))
 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,
index ebf8129..d842d3f 100644 (file)
@@ -15,3 +15,5 @@ option('enable-symbolic-link', type: 'boolean', value: true)
 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: '')
index f613156..c52cea8 100644 (file)
@@ -21,3 +21,5 @@ enable_nnapi=False
 # Set 1 or True if you want to use GPU with pytorch for computation.
 [pytorch]
 enable_use_gpu=@TORCH_USE_GPU@
+
+@ELEMENT_RESTRICTION_CONFIG@