From 2c8525eabada2863420d92764b750eebc66dfe30 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Fri, 19 Mar 2021 11:18:01 -0400
Subject: [PATCH] preferences: update preferences categories and dependencies

GitLab: #16
Change-Id: Ib02e4201db803ea81abb305e00e494d46e837ad1
---
 .gitignore                         |  3 ++
 AudioFilter/data/preferences.json  |  8 ++----
 AutoAnswer/data/preferences.json   | 18 ++++++------
 GreenScreen/CMakeLists.txt         |  4 ++-
 GreenScreen/build.sh               |  6 ++--
 GreenScreen/pluginMediaHandler.cpp | 16 ++++++++++-
 GreenScreen/preferences-accel.json | 29 +++++++++++++++++++
 GreenScreen/preferences-onnx.json  | 45 ------------------------------
 GreenScreen/preferences-ort.json   | 45 ------------------------------
 GreenScreen/preferences.json       | 21 ++++++++++++++
 GreenScreen/videoSubscriber.h      |  7 +++--
 HelloWorld/data/preferences.json   | 34 +++++++++++-----------
 12 files changed, 107 insertions(+), 129 deletions(-)
 create mode 100644 GreenScreen/preferences-accel.json
 delete mode 100644 GreenScreen/preferences-onnx.json
 delete mode 100644 GreenScreen/preferences-ort.json
 create mode 100644 GreenScreen/preferences.json

diff --git a/.gitignore b/.gitignore
index 1e8bf2c..01d29d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,6 @@ config.mak
 *__pycache__*
 /foo/
 /.vscode/
+*.crt
+*.key
+*.sign
diff --git a/AudioFilter/data/preferences.json b/AudioFilter/data/preferences.json
index 8da6414..4f4657d 100644
--- a/AudioFilter/data/preferences.json
+++ b/AudioFilter/data/preferences.json
@@ -1,9 +1,8 @@
 [
     {
-        "category": "ir",
         "type": "List",
         "key": "irFile",
-        "title": "Impulse Response",
+        "title": "Impulse response",
         "summary": "Choose a impulse response",
         "defaultValue": "average_space_ir_0.mp3",
         "scope": "plugin,Filter",
@@ -19,11 +18,10 @@
         ]
     },
     {
-        "category": "stream",
         "type": "List",
         "key": "streamlist",
-        "title": "Stream to transform",
-        "summary": "Select audio to transform",
+        "title": "Audio stream",
+        "summary": "Select stream",
         "defaultValue": "out",
         "scope": "plugin",
         "entryValues": [
diff --git a/AutoAnswer/data/preferences.json b/AutoAnswer/data/preferences.json
index 5552907..db5a259 100644
--- a/AutoAnswer/data/preferences.json
+++ b/AutoAnswer/data/preferences.json
@@ -1,20 +1,18 @@
 [
     {
-        "category": "text",
         "type": "EditText",
-        "key": "answer",
-        "title": "Bot Answer",
-        "summary": "Set bot text",
-        "defaultValue": "Hello World from bot preference",
+        "key": "inText",
+        "title": "Bot trigger",
+        "summary": "Text that bot will answer to",
+        "defaultValue": "Hi",
         "scope": "plugin,Bot"
     },
     {
-        "category": "text",
         "type": "EditText",
-        "key": "inText",
-        "title": "Bot Trigger",
-        "summary": "Text that bot will answer to",
-        "defaultValue": "Hi",
+        "key": "answer",
+        "title": "Bot answer",
+        "summary": "Set bot text",
+        "defaultValue": "Hello World from bot preference",
         "scope": "plugin,Bot"
     }
 ]
\ No newline at end of file
diff --git a/GreenScreen/CMakeLists.txt b/GreenScreen/CMakeLists.txt
index 552a6b1..fc399b7 100644
--- a/GreenScreen/CMakeLists.txt
+++ b/GreenScreen/CMakeLists.txt
@@ -14,6 +14,7 @@ set (PLUGINS_LIB ${PROJECT_SOURCE_DIR}/../lib)
 set (JPL_DIRECTORY ${PROJECT_BINARY_DIR}/jpl)
 set (LIBS_DIR ${PROJECT_SOURCE_DIR}/../contrib/Libs)
 set (ONNX_DIR $ENV{PLUGIN_ENV}/onnxruntime)
+set (PREFERENCESFILENAME preferences)
 
 if(WIN32)
     message(OS:\  WINDOWS\ ${CMAKE_SYSTEM_PROCESSOR})
@@ -36,6 +37,7 @@ add_definitions(-DNVIDIA)
 set(ONNX_DIR ${ONNX_DIR}/nvidia-gpu)
 message(Provider:\ NVIDIA)
 set(EXTRA_PATH nvidia-gpu)
+set (PREFERENCESFILENAME ${PREFERENCESFILENAME}-accel)
 else()
 set(ONNX_DIR ${ONNX_DIR}/cpu)
 message(Provider:\ NONE)
@@ -100,7 +102,7 @@ add_custom_command(
     COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.dll ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM}
     COMMAND ${CMAKE_COMMAND} -E make_directory ${JPL_DIRECTORY}/data/model
     COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/modelSRC/mModel.onnx ${JPL_DIRECTORY}/data/model
-    COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/preferences-onnx.json ${JPL_DIRECTORY}/data/preferences.json
+    COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/${PREFERENCESFILENAME}.json ${JPL_DIRECTORY}/data/preferences.json
     COMMENT "Assembling Plugin files"
 )
 
diff --git a/GreenScreen/build.sh b/GreenScreen/build.sh
index c5e4ea7..2f0b65f 100755
--- a/GreenScreen/build.sh
+++ b/GreenScreen/build.sh
@@ -26,12 +26,14 @@ DAEMON_SRC="${DAEMON}/src"
 CONTRIB_PATH="${DAEMON}/contrib"
 PLUGINS_LIB="../lib"
 LIBS_DIR="./../contrib/Libs"
+PREFERENCESFILENAME="preferences"
 
 if [ "${PROCESSOR}" = "CPU" ]; then
     ONNX_LIBS="cpu"
 elif [ "${PROCESSOR}" = "NVIDIA" ]; then
     ONNX_LIBS="nvidia-gpu"
     CUBLASLT="-lcublasLt"
+    PREFERENCESFILENAME="${PREFERENCESFILENAME}-accel"
 fi
 
 PLATFORM="linux-gnu"
@@ -117,7 +119,7 @@ then
 
     mkdir "./build-local/jpl/data/model"
     cp "./modelSRC/mModel.onnx" "./build-local/jpl/data/model/mModel.onnx"
-    cp "./preferences-onnx.json" "./build-local/jpl/data/preferences.json"
+    cp "./${PREFERENCESFILENAME}.json" "./build-local/jpl/data/preferences.json"
 
 elif [ "${PLATFORM}" = "android" ]
 then
@@ -283,7 +285,7 @@ then
 
     mkdir "./build-local/jpl/data/model"
     cp "./modelSRC/mModel.ort" "./build-local/jpl/data/model/mModel.ort"
-    cp "./preferences-ort.json" "./build-local/jpl/data/preferences.json"
+    cp "./${PREFERENCESFILENAME}-accel.json" "./build-local/jpl/data/preferences.json"
 fi
 
 python3 ./../SDK/jplManipulation.py --assemble --plugin=${PLUGIN_NAME} --distribution=${PLATFORM} --extraPath=${ONNX_LIBS}
diff --git a/GreenScreen/pluginMediaHandler.cpp b/GreenScreen/pluginMediaHandler.cpp
index 9afc24b..2643d6d 100644
--- a/GreenScreen/pluginMediaHandler.cpp
+++ b/GreenScreen/pluginMediaHandler.cpp
@@ -36,7 +36,21 @@ PluginMediaHandler::PluginMediaHandler(std::map<std::string, std::string>&& pref
     , preferences_ {preferences}
 {
     setId(datapath_);
-    mVS = std::make_shared<VideoSubscriber>(datapath_, preferences_.at("modellist"), preferences_.at("background"), preferences_.at("acceleration") == "1");
+#ifdef __ANDROID__
+    mVS = std::make_shared<VideoSubscriber>(datapath_,
+                                            "mModel.ort",
+                                            preferences_.at("background"),
+                                            preferences_.at("acceleration") == "1");
+#else
+#ifdef NVIDIA
+    mVS = std::make_shared<VideoSubscriber>(datapath_,
+                                            "mModel.onnx",
+                                            preferences_.at("background"),
+                                            preferences_.at("acceleration") == "1");
+#else
+    mVS = std::make_shared<VideoSubscriber>(datapath_, "mModel.onnx", preferences_.at("background"));
+#endif // NVIDIA
+#endif // ANDROID
 }
 
 void
diff --git a/GreenScreen/preferences-accel.json b/GreenScreen/preferences-accel.json
new file mode 100644
index 0000000..8f87311
--- /dev/null
+++ b/GreenScreen/preferences-accel.json
@@ -0,0 +1,29 @@
+[
+    {
+        "type": "Path",
+        "mimeType": "image/png,image/jpeg,image/jpg",
+        "key": "background",
+        "title": "Background image",
+        "summary": "Select background image file",
+        "defaultValue": "data/backgrounds/background2.jpeg",
+        "scope": "plugin,Foreground Segmentation"
+    },
+    {
+        "type": "Switch",
+        "key": "acceleration",
+        "title": "Use HW Acceleration",
+        "summary": "Use CUDA/NNAPI",
+        "defaultValue": "1",
+        "scope": "plugin"
+    },
+    {
+        "type": "List",
+        "key": "streamslist",
+        "title": "Video stream",
+        "summary": "Select stream",
+        "defaultValue": "out",
+        "entries": ["sent", "received"],
+        "entryValues": ["out", "in"],
+        "scope": "plugin"
+    }
+]
diff --git a/GreenScreen/preferences-onnx.json b/GreenScreen/preferences-onnx.json
deleted file mode 100644
index 8d31f95..0000000
--- a/GreenScreen/preferences-onnx.json
+++ /dev/null
@@ -1,45 +0,0 @@
-[
-    {
-        "category" : "StreamsListPreference",
-        "type": "List",
-        "key": "streamslist",
-        "title": "Streams to transform",
-        "summary": "Select video to transform",
-        "defaultValue": "out",
-        "entries": ["sent", "received"],
-        "entryValues": ["out", "in"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "acceleration",
-        "type": "List",
-        "key": "acceleration",
-        "title": "Use HW Acceleration",
-        "summary": "Define Yes or No",
-        "defaultValue": "1",
-        "entries": ["Yes", "No"],
-        "entryValues": ["1", "0"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "models",
-        "type": "List",
-        "key": "modellist",
-        "title": "Model to load",
-        "summary": "Select the model to use",
-        "defaultValue": "mModel.onnx",
-        "entries": ["mModel"],
-        "entryValues": ["mModel.onnx"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "backgrounds",
-        "type": "Path",
-        "mimeType": "image/png,image/jpeg,image/jpg",
-        "key": "background",
-        "title": "Background image",
-        "summary": "Select the image background to use",
-        "defaultValue": "data/backgrounds/background2.jpeg",
-        "scope": "plugin,Foreground Segmentation"
-    }
-]
diff --git a/GreenScreen/preferences-ort.json b/GreenScreen/preferences-ort.json
deleted file mode 100644
index f40f75b..0000000
--- a/GreenScreen/preferences-ort.json
+++ /dev/null
@@ -1,45 +0,0 @@
-[
-    {
-        "category" : "StreamsListPreference",
-        "type": "List",
-        "key": "streamslist",
-        "title": "Streams to transform",
-        "summary": "Select video to transform",
-        "defaultValue": "out",
-        "entries": ["sent", "received"],
-        "entryValues": ["out", "in"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "acceleration",
-        "type": "List",
-        "key": "acceleration",
-        "title": "Use HW Acceleration",
-        "summary": "Define Yes or No",
-        "defaultValue": "1",
-        "entries": ["Yes", "No"],
-        "entryValues": ["1", "0"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "models",
-        "type": "List",
-        "key": "modellist",
-        "title": "Model to load",
-        "summary": "Select the model to use",
-        "defaultValue": "mModel.ort",
-        "entries": ["mModel"],
-        "entryValues": ["mModel.ort"],
-        "scope": "plugin"
-    },
-    {
-        "category" : "backgrounds",
-        "type": "Path",
-        "mimeType": "image/png,image/jpeg,image/jpg",
-        "key": "background",
-        "title": "Background image",
-        "summary": "Select the image background to use",
-        "defaultValue": "data/backgrounds/background2.jpeg",
-        "scope": "plugin,Foreground Segmentation"
-    }
-]
diff --git a/GreenScreen/preferences.json b/GreenScreen/preferences.json
new file mode 100644
index 0000000..94b6b8f
--- /dev/null
+++ b/GreenScreen/preferences.json
@@ -0,0 +1,21 @@
+[
+    {
+        "type": "Path",
+        "mimeType": "image/png,image/jpeg,image/jpg",
+        "key": "background",
+        "title": "Background image",
+        "summary": "Select background image file",
+        "defaultValue": "data/backgrounds/background2.jpeg",
+        "scope": "plugin,Foreground Segmentation"
+    },
+    {
+        "type": "List",
+        "key": "streamslist",
+        "title": "Video stream",
+        "summary": "Select stream",
+        "defaultValue": "out",
+        "entries": ["sent", "received"],
+        "entryValues": ["out", "in"],
+        "scope": "plugin"
+    }
+]
diff --git a/GreenScreen/videoSubscriber.h b/GreenScreen/videoSubscriber.h
index b306fea..f23f02d 100644
--- a/GreenScreen/videoSubscriber.h
+++ b/GreenScreen/videoSubscriber.h
@@ -54,7 +54,10 @@ public:
 class VideoSubscriber : public jami::Observer<AVFrame*>
 {
 public:
-    VideoSubscriber(const std::string& dataPath, const std::string& model, const std::string& backgroundImage, bool acc);
+    VideoSubscriber(const std::string& dataPath,
+                    const std::string& model,
+                    const std::string& backgroundImage,
+                    bool acc = false);
     ~VideoSubscriber();
 
     virtual void update(jami::Observable<AVFrame*>*, AVFrame* const&) override;
@@ -67,7 +70,7 @@ public:
 
 private:
     // Observer pattern
-    Observable<AVFrame*>* observable_{};
+    Observable<AVFrame*>* observable_ {};
 
     // Data
     std::string path_;
diff --git a/HelloWorld/data/preferences.json b/HelloWorld/data/preferences.json
index a8ba793..968cd21 100644
--- a/HelloWorld/data/preferences.json
+++ b/HelloWorld/data/preferences.json
@@ -1,23 +1,5 @@
 [
     {
-        "category": "stream",
-        "type": "List",
-        "key": "videostream",
-        "title": "Video stream",
-        "summary": "select a video direction",
-        "defaultValue": "0",
-        "scope": "plugin",
-        "entryValues": [
-            "0",
-            "1"
-        ],
-        "entries": [
-            "sent",
-            "received"
-        ]
-    },
-    {
-        "category": "color",
         "type": "List",
         "key": "color",
         "title": "Circle color",
@@ -34,5 +16,21 @@
             "green",
             "red"
         ]
+    },
+    {
+        "type": "List",
+        "key": "videostream",
+        "title": "Video stream",
+        "summary": "Select stream",
+        "defaultValue": "0",
+        "scope": "plugin",
+        "entryValues": [
+            "0",
+            "1"
+        ],
+        "entries": [
+            "sent",
+            "received"
+        ]
     }
 ]
\ No newline at end of file
-- 
GitLab