[CONF] add the new variables and method
authorHyoung Joo Ahn <hello.ahn@samsung.com>
Thu, 14 Mar 2019 12:47:09 +0000 (21:47 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 19 Mar 2019 00:49:52 +0000 (09:49 +0900)
to process with int/boolean value, the new variables and method is added.

Signed-off-by: Hyoung Joo Ahn <hello.ahn@samsung.com>
gst/nnstreamer/nnstreamer_conf.c
gst/nnstreamer/nnstreamer_conf.h
gst/nnstreamer/nnstreamer_subplugin.c
gst/nnstreamer/nnstreamer_subplugin.h
meson.build
meson_options.txt
nnstreamer.ini.in

index b3bc0a3..ac65c59 100644 (file)
@@ -44,6 +44,7 @@ typedef struct
   gchar *pathFILTERS[CONF_SOURCES];        /**< directory paths for FILTERS */
   gchar *pathDECODERS[CONF_SOURCES];       /**< directory paths for DECODERS */
   gchar *pathCUSTOM_FILTERS[CONF_SOURCES]; /**< directory paths for CUSTOM FILTERS */
+  gchar *valueTF_MEM_OPTMZ[CONF_SOURCES];  /**< value of TF_MEM_OPTMZ */
 
   gchar **filesFILTERS;        /**< Null terminated list of full filepaths for FILTERS */
   gchar **filesDECODERS;;      /**< Null terminated list of full filepaths for DECODERS */
@@ -52,6 +53,8 @@ typedef struct
   gchar **basenameFILTERS;        /**< Null terminated list of basenames for FILTERS */
   gchar **basenameDECODERS;;      /**< Null terminated list of basenames for DECODERS */
   gchar **basenameCUSTOM_FILTERS; /**< Null terminated list of basenames for CUSTOM FILTERS */
+
+  gboolean boolTF_MEM_OPTMZ; /**< The flag to decide using memcpy or not at Tensorflow in boolean type */
 } confdata;
 
 static confdata conf = { 0 };
@@ -229,6 +232,7 @@ nnsconf_loadconf (gboolean force_reload)
       g_free (conf.pathFILTERS[i]);
       g_free (conf.pathDECODERS[i]);
       g_free (conf.pathCUSTOM_FILTERS[i]);
+      g_free (conf.valueTF_MEM_OPTMZ[i]);
     }
 
     g_strfreev (conf.filesFILTERS);
@@ -257,6 +261,7 @@ nnsconf_loadconf (gboolean force_reload)
   conf.pathFILTERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_FILTERS);
   conf.pathDECODERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_DECODERS);
   conf.pathCUSTOM_FILTERS[0] = _strdup_getenv (NNSTREAMER_ENVVAR_CUSTOMFILTERS);
+  conf.valueTF_MEM_OPTMZ[0] = _strdup_getenv (NNSTREAMER_ENVVAR_TF_MEM_OPTMZ);
 
   /* Read the conf file. It's ok even if we cannot load it. */
   if (conf.conffile &&
@@ -269,12 +274,15 @@ nnsconf_loadconf (gboolean force_reload)
         g_key_file_get_string (key_file, "decoder", "decoders", &error);
     conf.pathCUSTOM_FILTERS[1] =
         g_key_file_get_string (key_file, "filter", "customfilters", &error);
+    conf.valueTF_MEM_OPTMZ[1] =
+        g_key_file_get_string (key_file, "tensorflow", "mem_optmz", &error);
   }
 
   /* Strdup the hardcoded */
   conf.pathFILTERS[2] = g_strdup (NNSTREAMER_FILTERS);
   conf.pathDECODERS[2] = g_strdup (NNSTREAMER_DECODERS);
   conf.pathCUSTOM_FILTERS[2] = g_strdup (NNSTREAMER_CUSTOM_FILTERS);
+  conf.valueTF_MEM_OPTMZ[2] = g_strdup (NNSTREAMER_TF_MEM_OPTMZ);
 
   /* Fill in conf.files* */
   _fill_in_vstr (&conf.filesFILTERS, &conf.basenameFILTERS, conf.pathFILTERS);
@@ -291,21 +299,21 @@ nnsconf_loadconf (gboolean force_reload)
 
 /** @brief Public function defined in the header */
 const gchar *
-nnsconf_get_fullpath_fromfile (const gchar * file2find, nnsconf_type type)
+nnsconf_get_fullpath_fromfile (const gchar * file2find, nnsconf_type_path type)
 {
   gchar **vstr, **vstrFull;
   int i;
 
   switch (type) {
-    case NNSCONF_FILTERS:
+    case NNSCONF_PATH_FILTERS:
       vstr = conf.basenameFILTERS;
       vstrFull = conf.filesFILTERS;
       break;
-    case NNSCONF_DECODERS:
+    case NNSCONF_PATH_DECODERS:
       vstr = conf.basenameDECODERS;
       vstrFull = conf.filesDECODERS;
       break;
-    case NNSCONF_CUSTOM_FILTERS:
+    case NNSCONF_PATH_CUSTOM_FILTERS:
       vstr = conf.basenameCUSTOM_FILTERS;
       vstrFull = conf.filesCUSTOM_FILTERS;
       break;
@@ -327,17 +335,20 @@ nnsconf_get_fullpath_fromfile (const gchar * file2find, nnsconf_type type)
   return NULL;
 }
 
-const gchar *subplugin_prefixes[NNSCONF_END] = {
-  [NNSCONF_FILTERS] = NNSTREAMER_PREFIX_FILTER,
-  [NNSCONF_DECODERS] = NNSTREAMER_PREFIX_DECODER,
-  [NNSCONF_CUSTOM_FILTERS] = NNSTREAMER_PREFIX_CUSTOMFILTERS,
+const gchar *subplugin_prefixes[NNSCONF_PATH_END] = {
+  [NNSCONF_PATH_FILTERS] = NNSTREAMER_PREFIX_FILTER,
+  [NNSCONF_PATH_DECODERS] = NNSTREAMER_PREFIX_DECODER,
+  [NNSCONF_PATH_CUSTOM_FILTERS] = NNSTREAMER_PREFIX_CUSTOMFILTERS,
   NULL,
 };
 
 /** @brief Public function defined in the header */
 const gchar *
-nnsconf_get_fullpath (const gchar * subpluginname, nnsconf_type type)
+nnsconf_get_fullpath (const gchar * subpluginname, nnsconf_type_path type)
 {
+  if (!conf.loaded)
+    nnsconf_loadconf (FALSE);
+
   gchar *filename =
       g_strconcat (subplugin_prefixes[type], subpluginname, ".so", NULL);
   const gchar *ret = nnsconf_get_fullpath_fromfile (filename, type);
@@ -345,3 +356,36 @@ nnsconf_get_fullpath (const gchar * subpluginname, nnsconf_type type)
   g_free (filename);
   return ret;
 }
+
+/** @brief Public function defined in the header */
+const gboolean
+nnsconf_get_value_bool (nnsconf_type_value type)
+{
+  int i;
+  gboolean ret;
+
+  if (!conf.loaded)
+    nnsconf_loadconf (FALSE);
+
+  switch (type) {
+    case NNSCONF_VAL_TF_MEM_OPTMZ:
+      for (i = 0; i < CONF_SOURCES; i++) {
+        if (conf.valueTF_MEM_OPTMZ[i]) {
+          if (!g_ascii_strncasecmp ("1", conf.valueTF_MEM_OPTMZ[i], 1) ||
+              !g_ascii_strncasecmp ("t", conf.valueTF_MEM_OPTMZ[i], 1))
+            conf.boolTF_MEM_OPTMZ = TRUE;
+          else
+            conf.boolTF_MEM_OPTMZ = FALSE;
+
+          break;
+        }
+      }
+      ret = conf.boolTF_MEM_OPTMZ;
+      break;
+
+    default:
+      ret = FALSE;
+  }
+
+  return ret;
+}
index df85fe0..1f27c36 100644 (file)
 #define NNSTREAMER_ENVVAR_FILTERS       "NNSTREAMER_FILTERS"
 #define NNSTREAMER_ENVVAR_DECODERS      "NNSTREAMER_DECODERS"
 #define NNSTREAMER_ENVVAR_CUSTOMFILTERS "NNSTREAMER_CUSTOMFILTERS"
+#define NNSTREAMER_ENVVAR_TF_MEM_OPTMZ  "NNSTREAMER_TF_MEM_OPTMZ"
 
 /* Internal Hardcoded Values */
 #define NNSTREAMER_DEFAULT_CONF_FILE    "/etc/nnstreamer.ini"
 #define NNSTREAMER_FILTERS              "/usr/lib/nnstreamer/filters/"
 #define NNSTREAMER_DECODERS             "/usr/lib/nnstreamer/decoders/"
 #define NNSTREAMER_CUSTOM_FILTERS       "/usr/lib/nnstreamer/customfilters/"
+#define NNSTREAMER_TF_MEM_OPTMZ         "false"
 /**
  *  Note that users still can place their custom filters anywhere if they
  * designate them with the full path.
 /* Custom filter does not have prefix */
 
 typedef enum {
-  NNSCONF_FILTERS = 0,
-  NNSCONF_DECODERS,
-  NNSCONF_CUSTOM_FILTERS,
-  NNSCONF_CONFFILE,
+  NNSCONF_PATH_FILTERS = 0,
+  NNSCONF_PATH_DECODERS,
+  NNSCONF_PATH_CUSTOM_FILTERS,
+  NNSCONF_PATH_CONFFILE,
 
-  NNSCONF_END,
-} nnsconf_type;
+  NNSCONF_PATH_END,
+} nnsconf_type_path;
 
-extern const gchar *subplugin_prefixes[NNSCONF_END];
+typedef enum {
+  NNSCONF_VAL_TF_MEM_OPTMZ = 0,
+
+  NNSCONF_VAL_END,
+} nnsconf_type_value;
+
+extern const gchar *subplugin_prefixes[NNSCONF_PATH_END];
 
 /**
  * @brief Load the .ini file
@@ -84,7 +92,7 @@ nnsconf_loadconf (gboolean force_reload);
  *         Returns NULL if we cannot find the file.
  */
 extern const gchar *
-nnsconf_get_fullpath_fromfile (const gchar *file2find, nnsconf_type type);
+nnsconf_get_fullpath_fromfile (const gchar *file2find, nnsconf_type_path type);
 
 /**
  * @brief Get the configured paths for the type with sub-plugin name.
@@ -96,6 +104,15 @@ nnsconf_get_fullpath_fromfile (const gchar *file2find, nnsconf_type type);
  * This is mainly supposed to be used by CUSTOM_FILTERS
  */
 extern const gchar *
-nnsconf_get_fullpath (const gchar *subpluginname, nnsconf_type type);
+nnsconf_get_fullpath (const gchar *subpluginname, nnsconf_type_path type);
+
+/**
+ * @brief Get the configured boolean values for the type
+ * @param[in] type The type (TF_MEM_OPTMZ)
+ * @return The boolean value to the file. Caller MUST NOT modify this.
+ *         Returns FALSE if we cannot find the file or the value as a DEFAULT.
+ */
+extern const gboolean
+nnsconf_get_value_bool (nnsconf_type_value type);
 
 #endif /* __GST_NNSTREAMER_CONF_H__ */
index 9476b41..bcf322a 100644 (file)
@@ -60,8 +60,6 @@ get_subplugin (subpluginType type, const char *name)
   subpluginData *data;
   void *handle;
 
-  nnsconf_loadconf (FALSE);
-
   G_LOCK (splock);
 
   if (subplugins[type] == NULL)
index 26e0377..059ecf8 100644 (file)
@@ -38,8 +38,8 @@
 #include "nnstreamer_conf.h"
 
 typedef enum {
-  NNS_SUBPLUGIN_FILTER = NNSCONF_FILTERS,
-  NNS_SUBPLUGIN_DECODER = NNSCONF_DECODERS,
+  NNS_SUBPLUGIN_FILTER = NNSCONF_PATH_FILTERS,
+  NNS_SUBPLUGIN_DECODER = NNSCONF_PATH_DECODERS,
 
   NNS_SUBPLUGIN_END,
 } subpluginType;
index b3831b1..f9f7c88 100644 (file)
@@ -97,6 +97,11 @@ if get_option('enable-tensorflow')
   else
     message('Cannot find tensorflow')
   endif
+
+  nnstreamer_conf.set('TF_MEM_OPTMZ', get_option('enable-tensorflow-mem-optmz'))
+else
+  message('Tensorflow is disabled')
+  nnstreamer_conf.set('TF_MEM_OPTMZ', false)
 endif
 
 # Tensorflow-lite
index 6025e90..7f2efc0 100644 (file)
@@ -2,5 +2,6 @@ option('enable-test', type: 'boolean', value: true)
 option('enable-opencv-test', type: 'boolean', value: true)
 option('enable-tensorflow-lite', type: 'boolean', value: true)
 option('enable-tensorflow', type: 'boolean', value: true)
+option('enable-tensorflow-mem-optmz', type: 'boolean', value: true)
 option('install-example', type: 'boolean', value: false)
 option('disable-audio-support', type: 'boolean', value: false)
index e43c62c..71caaa5 100644 (file)
@@ -4,3 +4,8 @@ customfilters=@SUBPLUGIN_INSTALL_PREFIX@/customfilters/
 
 [decoder]
 decoders=@SUBPLUGIN_INSTALL_PREFIX@/decoders/
+
+# Set 1 or TRUE if you want to eliminate memcpy of tensorflow input frames for faster executions.
+# It may break in some special cases (running tensorflow & nnstreamer in a chroot of a AWS VM); in such a case, keep it 0 or FALSE.
+[tensorflow]
+mem_optmz=@TF_MEM_OPTMZ@