From: Lukasz Bardeli Date: Mon, 11 Jan 2021 07:29:29 +0000 (+0100) Subject: [ML][Pipeline] Implement Start and Stop method. X-Git-Tag: submit/tizen/20210128.113801~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19ac4ad30701963f6e51fff59c8554b19307726d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [ML][Pipeline] Implement Start and Stop method. 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 --- diff --git a/src/ml/js/ml_pipeline.js b/src/ml/js/ml_pipeline.js index e9debd3e..17dba5ef 100755 --- a/src/ml/js/ml_pipeline.js +++ b/src/ml/js/ml_pipeline.js @@ -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 diff --git a/src/ml/ml_instance.cc b/src/ml/ml_instance.cc index 17415507..3a0cd4d4 100644 --- a/src/ml/ml_instance.cc +++ b/src/ml/ml_instance.cc @@ -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()) { + LoggerD("id is not a number"); + ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out); + return; + } + auto id = static_cast(args.get(kId).get()); + 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()) { + LoggerD("id is not a number"); + ReportError(PlatformResult{ErrorCode::ABORT_ERR, "Invalid pipeline"}, &out); + return; + } + auto id = static_cast(args.get(kId).get()); + + 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 diff --git a/src/ml/ml_instance.h b/src/ml/ml_instance.h index 975fd7a5..df6e214c 100644 --- a/src/ml/ml_instance.h +++ b/src/ml/ml_instance.h @@ -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 diff --git a/src/ml/ml_pipeline.cc b/src/ml/ml_pipeline.cc index 63b6fbf7..10930cf2 100644 --- a/src/ml/ml_pipeline.cc +++ b/src/ml/ml_pipeline.cc @@ -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 diff --git a/src/ml/ml_pipeline.h b/src/ml/ml_pipeline.h index 5fd19aab..42287f8b 100644 --- a/src/ml/ml_pipeline.h +++ b/src/ml/ml_pipeline.h @@ -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_ diff --git a/src/ml/ml_pipeline_manager.cc b/src/ml/ml_pipeline_manager.cc index 553770a9..3d578618 100644 --- a/src/ml/ml_pipeline_manager.cc +++ b/src/ml/ml_pipeline_manager.cc @@ -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 diff --git a/src/ml/ml_pipeline_manager.h b/src/ml/ml_pipeline_manager.h index f5d0af3e..300aa311 100644 --- a/src/ml/ml_pipeline_manager.h +++ b/src/ml/ml_pipeline_manager.h @@ -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_