[ML][Pipeline] Implement Start and Stop method. 02/250902/10
authorLukasz Bardeli <l.bardeli@AMDN2706VM01.digital.local>
Mon, 11 Jan 2021 07:29:29 +0000 (08:29 +0100)
committerLukasz Bardeli <l.bardeli@samsung.com>
Mon, 18 Jan 2021 19:38:44 +0000 (20:38 +0100)
ACR: TWDAPI-274

[Verification] Code compiles without error.

var pipeline = tizen.ml.pipeline.createPipeline("videotestsrc! tizenwlsink");

pipeline.start()

// pipeline.state = "PLAYING"

pipeline.stop()

// pipeline.state = "PAUSED"

Change-Id: I529c47fd349741d3e11b0b57e265d3a9a930f652
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/ml/js/ml_pipeline.js
src/ml/ml_instance.cc
src/ml/ml_instance.h
src/ml/ml_pipeline.cc
src/ml/ml_pipeline.h
src/ml/ml_pipeline_manager.cc
src/ml/ml_pipeline_manager.h

index e9debd3e9b87fa25bc65d12603bb530a3dcf23a9..17dba5ef5d2de947939885843dcb2fd4449bb3d4 100755 (executable)
@@ -114,11 +114,38 @@ var Pipeline = function(id) {
 //Pipeline::state end
 
 //Pipeline::start() begin
+var ValidPipelineStartStopExceptions = ['NotFoundError', 'NotSupportedError', 'AbortError'];
+Pipeline.prototype.start = function() {
+    var nativeArgs = {
+        id: this._id
+    };
 
+    var result = native_.callSync('MLPipelineStart', nativeArgs);
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObjectAndValidate(
+            result,
+            ValidPipelineStartStopExceptions,
+            AbortError
+        );
+    }
+};
 //Pipeline::start() end
 
 //Pipeline::stop() begin
+Pipeline.prototype.stop = function() {
+    var nativeArgs = {
+        id: this._id
+    };
 
+    var result = native_.callSync('MLPipelineStop', nativeArgs);
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObjectAndValidate(
+            result,
+            ValidPipelineStartStopExceptions,
+            AbortError
+        );
+    }
+};
 //Pipeline::stop() end
 
 //Pipeline::dispose() begin
index 17415507a503172f350ceba32f8f50ed108dfbf6..3a0cd4d4c91301d7a3e78c21abda3927bfcde147 100644 (file)
@@ -42,6 +42,8 @@ MlInstance::MlInstance() : pipeline_manager_{this} {
   REGISTER_METHOD(MLPipelineManagerCreatePipeline);
   REGISTER_METHOD(MLPipelineGetState);
   REGISTER_METHOD(MLPipelineDispose);
+  REGISTER_METHOD(MLPipelineStart);
+  REGISTER_METHOD(MLPipelineStop);
 // Pipeline API end
 
 #undef REGISTER_METHOD
@@ -137,11 +139,47 @@ void MlInstance::MLPipelineGetState(const picojson::value& args, picojson::objec
 // Pipeline::state end
 
 // Pipeline::start() begin
+void MlInstance::MLPipelineStart(const picojson::value& args, picojson::object& out) {
+  ScopeLogger("args: %s", args.serialize().c_str());
+
+  if (!args.get(kId).is<double>()) {
+    LoggerD("id is not a number");
+    ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out);
+    return;
+  }
+  auto id = static_cast<int>(args.get(kId).get<double>());
 
+  PlatformResult result = pipeline_manager_.Start(id);
+
+  if (!result) {
+    ReportError(result, &out);
+    return;
+  }
+
+  ReportSuccess(out);
+}
 // Pipeline::start() end
 
 // Pipeline::stop() begin
+void MlInstance::MLPipelineStop(const picojson::value& args, picojson::object& out) {
+  ScopeLogger("args: %s", args.serialize().c_str());
 
+  if (!args.get(kId).is<double>()) {
+    LoggerD("id is not a number");
+    ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out);
+    return;
+  }
+  auto id = static_cast<int>(args.get(kId).get<double>());
+
+  PlatformResult result = pipeline_manager_.Stop(id);
+
+  if (!result) {
+    LogAndReportError(result, &out);
+    return;
+  }
+
+  ReportSuccess(out);
+}
 // Pipeline::stop() end
 
 // Pipeline::dispose() begin
@@ -221,6 +259,7 @@ void MlInstance::MLPipelineDispose(const picojson::value& args, picojson::object
 // Valve::setOpen() begin
 
 // Valve::setOpen() end
+
 // Pipeline API end
 
 }  // namespace ml
index 975fd7a54caf205fd5c2ae052ddcfa7296e8dc01..df6e214cd2dd9a2c54f09ad15e6a5b1f72cc455c 100644 (file)
@@ -52,11 +52,11 @@ class MlInstance : public common::ParsedInstance {
   // Pipeline::state end
 
   // Pipeline::start() begin
-
+  void MLPipelineStart(const picojson::value& args, picojson::object& out);
   // Pipeline::start() end
 
   // Pipeline::stop() begin
-
+  void MLPipelineStop(const picojson::value& args, picojson::object& out);
   // Pipeline::stop() end
 
   // Pipeline::dispose() begin
index 63b6fbf707b58e3ba0f21878b715e3a63b5b4c43..10930cf24725802330d62f458ba55eb99aff8b1d 100644 (file)
@@ -151,11 +151,29 @@ PlatformResult Pipeline::GetState(std::string* out) {
 // Pipeline::state end
 
 // Pipeline::start() begin
+PlatformResult Pipeline::Start() {
+  ScopeLogger("id_: [%d]", id_);
 
+  auto ret = ml_pipeline_start(pipeline_);
+  if (ML_ERROR_NONE != ret) {
+    LoggerE("ml_pipeline_start() failed: [%d] (%s)", ret, get_error_message(ret));
+    return util::ToPlatformResult(ret, "Could not start pipeline");
+  }
+  return PlatformResult{};
+}
 // Pipeline::start() end
 
 // Pipeline::stop() begin
+PlatformResult Pipeline::Stop() {
+  ScopeLogger("id_: [%d]", id_);
 
+  auto ret = ml_pipeline_stop(pipeline_);
+  if (ML_ERROR_NONE != ret) {
+    LoggerE("ml_pipeline_stop() failed: [%d] (%s)", ret, get_error_message(ret));
+    return util::ToPlatformResult(ret, "Could not stop pipeline");
+  }
+  return PlatformResult{};
+}
 // Pipeline::stop() end
 
 // Pipeline::dispose() begin
index 5fd19aab5eeff5e5e14d83679c3e36feb3a23ad1..42287f8bfb09c2e240707d320936dcf19a38a895 100644 (file)
@@ -56,11 +56,11 @@ class Pipeline {
   // Pipeline::state end
 
   // Pipeline::start() begin
-
+  PlatformResult Start();
   // Pipeline::start() end
 
   // Pipeline::stop() begin
-
+  PlatformResult Stop();
   // Pipeline::stop() end
 
   // Pipeline::dispose() begin
@@ -141,4 +141,4 @@ class Pipeline {
 }  // namespace ml
 }  // namespace extension
 
-#endif  // ML_ML_PIPELINE_H_
\ No newline at end of file
+#endif  // ML_ML_PIPELINE_H_
index 553770a940be65aa626f4952f34d9bb2cf5636f2..3d578618d9d72bf500f3021d215dbc62dfc96cf1 100644 (file)
@@ -74,11 +74,33 @@ PlatformResult PipelineManager::GetPipelineState(int id, std::string* out) {
 // Pipeline::state end
 
 // Pipeline::start() begin
+PlatformResult PipelineManager::Start(int id) {
+  ScopeLogger("id: [%d]", id);
 
+  auto pipeline_it = pipelines_.find(id);
+  if (pipelines_.end() == pipeline_it) {
+    LoggerD("Pipeline not found: [%d]", id);
+    return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"};
+  }
+
+  auto ret = pipeline_it->second->Start();
+  return ret;
+}
 // Pipeline::start() end
 
 // Pipeline::stop() begin
+PlatformResult PipelineManager::Stop(int id) {
+  ScopeLogger("id: [%d]", id);
 
+  auto pipeline_it = pipelines_.find(id);
+  if (pipelines_.end() == pipeline_it) {
+    LoggerD("Pipeline not found: [%d]", id);
+    return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"};
+  }
+
+  auto ret = pipeline_it->second->Stop();
+  return ret;
+}
 // Pipeline::stop() end
 
 // Pipeline::dispose() begin
index f5d0af3e9e04c839ced8d6c589bf596efcc319e2..300aa311e679e63f987d233e03744c8ccf98d66e 100644 (file)
@@ -48,11 +48,11 @@ class PipelineManager {
   // Pipeline::state end
 
   // Pipeline::start() begin
-
+  PlatformResult Start(int id);
   // Pipeline::start() end
 
   // Pipeline::stop() begin
-
+  PlatformResult Stop(int id);
   // Pipeline::stop() end
 
   // Pipeline::dispose() begin
@@ -122,4 +122,4 @@ class PipelineManager {
 }  // namespace ml
 }  // namespace extension
 
-#endif  // ML_ML_PIPELINE_MANAGER_H_
\ No newline at end of file
+#endif  // ML_ML_PIPELINE_MANAGER_H_