From ee3d5a03fee9b4234e707bbb15dc3cd824704bbb Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Tue, 12 Jan 2021 16:38:43 +0100
Subject: [PATCH] [ML][pipeline] Implement Pipeline::getSwitch()
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
ACR: TWDAPI-274
[Verification] Code tested in Chrome DevTools with below snippets works
fine
var pipeline_def = "videotestsrc is-live=true"
+ " ! videoconvert"
+ " ! tensor_converter"
+ " ! output-selector name=outs outs.src_0"
+ " ! tensor_sink name=sink0 async=false outs.src_1"
+ " ! tensor_sink name=sink1 async=false"
var pipeline = tizen.ml.pipeline.createPipeline(pipeline_def, function(state) {console.log(state);})
pipeline.getSwitch('outs')
// Switch {name: "outs", type: "OUTPUT_SELECTOR", _pipeline_id: 3}
pipeline.getSwitch('non existent switch')
// VM31:1 Uncaught WebAPIException {code: 0, name: "InvalidValuesError"
Change-Id: Ia7d6838b5e49072c35f0b796151c436d4a3b60e1
Signed-off-by: Pawel Wasowski
---
src/ml/js/ml_pipeline.js | 45 +++++++++++++++++
src/ml/ml.gyp | 2 +
src/ml/ml_instance.cc | 28 +++++++++++
src/ml/ml_instance.h | 2 +-
src/ml/ml_pipeline.cc | 19 ++++++++
src/ml/ml_pipeline.h | 23 ++++++---
src/ml/ml_pipeline_manager.cc | 12 +++++
src/ml/ml_pipeline_manager.h | 2 +-
src/ml/ml_pipeline_switch.cc | 91 +++++++++++++++++++++++++++++++++++
src/ml/ml_pipeline_switch.h | 56 +++++++++++++++++++++
10 files changed, 271 insertions(+), 9 deletions(-)
create mode 100644 src/ml/ml_pipeline_switch.cc
create mode 100644 src/ml/ml_pipeline_switch.h
diff --git a/src/ml/js/ml_pipeline.js b/src/ml/js/ml_pipeline.js
index df2913af..2cfb8bee 100755
--- a/src/ml/js/ml_pipeline.js
+++ b/src/ml/js/ml_pipeline.js
@@ -212,7 +212,52 @@ Pipeline.prototype.getNodeInfo = function() {
//Pipeline::getSource() end
//Pipeline::getSwitch() begin
+function Switch(name, type, pipeline_id) {
+ Object.defineProperties(this, {
+ name: {
+ enumerable: true,
+ value: name
+ },
+ type: {
+ enumerable: true,
+ value: type
+ },
+ _pipeline_id: {
+ value: pipeline_id
+ }
+ });
+}
+var ValidPipelineGetSwitchExceptions = [
+ 'InvalidStateError',
+ 'InvalidValuesError',
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
+Pipeline.prototype.getSwitch = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'name',
+ type: validator_.Types.STRING
+ }
+ ]);
+
+ var nativeArgs = {
+ name: args.name,
+ id: this._id
+ };
+ var result = native_.callSync('MLPipelineGetSwitch', nativeArgs);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidPipelineGetSwitchExceptions,
+ AbortError
+ );
+ }
+
+ return new Switch(nativeArgs.name, result.type, this._id);
+};
//Pipeline::getSwitch() end
//Pipeline::getValve() begin
diff --git a/src/ml/ml.gyp b/src/ml/ml.gyp
index c0ab8262..1c60e04d 100644
--- a/src/ml/ml.gyp
+++ b/src/ml/ml.gyp
@@ -21,6 +21,8 @@
'ml_pipeline_manager.h',
'ml_pipeline_nodeinfo.cc',
'ml_pipeline_nodeinfo.h',
+ 'ml_pipeline_switch.cc',
+ 'ml_pipeline_switch.h',
'ml_utils.cc',
'ml_utils.h',
],
diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc
index e9445adb..853dab4c 100644
--- a/src/ml/ml_instance.cc
+++ b/src/ml/ml_instance.cc
@@ -59,6 +59,7 @@ MlInstance::MlInstance() : pipeline_manager_{this} {
REGISTER_METHOD(MLPipelineStart);
REGISTER_METHOD(MLPipelineStop);
REGISTER_METHOD(MLPipelineGetNodeInfo);
+ REGISTER_METHOD(MLPipelineGetSwitch);
// Pipeline API end
#undef REGISTER_METHOD
@@ -266,7 +267,34 @@ void MlInstance::MLPipelineGetNodeInfo(const picojson::value& args, picojson::ob
// Pipeline::getSource() end
// Pipeline::getSwitch() begin
+void MlInstance::MLPipelineGetSwitch(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: %s", args.serialize().c_str());
+ if (!args.get(kId).is()) {
+ LoggerD("id is not a number");
+ ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out);
+ return;
+ }
+
+ if (!args.get(kName).is()) {
+ LoggerD("name is not a string");
+ ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid name"}, &out);
+ return;
+ }
+
+ auto name = args.get(kName).get();
+ auto pipeline_id = args.get(kId).get();
+ std::string type;
+
+ auto ret = pipeline_manager_.GetSwitch(name, pipeline_id, &type);
+ if (!ret) {
+ LogAndReportError(ret, &out);
+ return;
+ }
+
+ out["type"] = picojson::value{type};
+ ReportSuccess(out);
+}
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h
index 47d95671..acb013c1 100644
--- a/src/ml/ml_instance.h
+++ b/src/ml/ml_instance.h
@@ -73,7 +73,7 @@ class MlInstance : public common::ParsedInstance {
// Pipeline::getSource() end
// Pipeline::getSwitch() begin
-
+ void MLPipelineGetSwitch(const picojson::value& args, picojson::object& out);
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc
index c843df35..de5edb1d 100644
--- a/src/ml/ml_pipeline.cc
+++ b/src/ml/ml_pipeline.cc
@@ -190,6 +190,7 @@ PlatformResult Pipeline::Dispose() {
* They have to be released HERE (i.e. BEFORE releasing pipeline_).
* If they're released after pipeline_, the app may crash.
*/
+ switches_.clear();
node_info_.clear();
@@ -234,7 +235,25 @@ PlatformResult Pipeline::GetNodeInfo(std::string& name) {
// Pipeline::getSource() end
// Pipeline::getSwitch() begin
+PlatformResult Pipeline::GetSwitch(const std::string& name, std::string* type) {
+ ScopeLogger("id: [%d], name: [%s]", id_, name.c_str());
+ auto switch_it = switches_.find(name);
+ if (switches_.end() != switch_it) {
+ LoggerD("Switch [%s] found", name.c_str());
+ *type = switch_it->second->GetType();
+ return PlatformResult{};
+ }
+ LoggerD("Switch [%s] not found", name.c_str());
+
+ std::unique_ptr switch_ptr;
+ auto ret = Switch::CreateSwitch(name, pipeline_, &switch_ptr);
+ if (ret) {
+ *type = switch_ptr->GetType();
+ switches_.insert({name, std::move(switch_ptr)});
+ }
+ return ret;
+}
// Pipeline::getSwitch() end
// Pipeline::getValve() begin
diff --git a/src/ml/ml_pipeline.h b/src/ml/ml_pipeline.h
index 80c859ba..9d3df8ca 100644
--- a/src/ml/ml_pipeline.h
+++ b/src/ml/ml_pipeline.h
@@ -19,6 +19,7 @@
#include