[ML][pipeline] Prepare room for a bugfix 97/251697/2
authorPawel Wasowski <p.wasowski2@samsung.com>
Mon, 18 Jan 2021 13:01:19 +0000 (14:01 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Mon, 18 Jan 2021 13:20:05 +0000 (14:20 +0100)
Native handles to all pipeline elements (switches, node infos, etc.)
have to be released BEFORE Pipeline::pipeline_ handle.
Pipeline::Dispose() will release them in proper order and from now on
will be called from ~Pipeline() to not repeat the error prone release
logic.

[Verification] Code tested with below snippets in Chrome DevTools works
fine.

var pipeline = tizen.ml.pipeline.createPipeline('videotestsrc ! tizenwlsink',
                                                function(state) {console.log(state);})
// test screen appears

pipeline.dispose() // no errors, test screen disappear;
// DLOG message about successful disposal

<press F5> // no crash; DLOG message tells that pipeline_ has been destroyed

Change-Id: Ibe8b1260bc7bf057fed375ac579b87fce59d8caf
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/ml_pipeline.cc
src/ml/ml_pipeline.h

index 440d77348bf7022738fb2168c7d6e98237bc78a1..63b6fbf707b58e3ba0f21878b715e3a63b5b4c43 100644 (file)
@@ -117,11 +117,7 @@ Pipeline::~Pipeline() {
     return;
   }
 
-  auto ret = ml_pipeline_destroy(pipeline_);
-  if (ML_ERROR_NONE != ret) {
-    LoggerE("ml_pipeline_destroy() failed: [%d] (%s)", ret, get_error_message(ret));
-  }
-  LoggerD("ml_pipeline_destroy() succeeded");
+  Dispose();
 }
 
 void Pipeline::PipelineStateChangeListener(ml_pipeline_state_e state, void* user_data) {
@@ -166,6 +162,17 @@ PlatformResult Pipeline::GetState(std::string* out) {
 PlatformResult Pipeline::Dispose() {
   ScopeLogger("id_: [%d]", id_);
 
+  /*
+   * TODO in future commits:
+   *
+   * Release all nodes belonging to this pipeline and
+   * cached in this object in containers like
+   * switches_, node_infos_, etc.
+   *
+   * They have to be released HERE (i.e. BEFORE releasing pipeline_).
+   * If they're released after pipeline_, the app may crash.
+   */
+
   auto ret = ml_pipeline_destroy(pipeline_);
   if (ML_ERROR_NONE != ret) {
     LoggerE("ml_pipeline_destroy() failed: [%d] (%s)", ret, get_error_message(ret));
index 92e2fa936113453cd077ae2bb058f13c0139b384..5fd19aab5eeff5e5e14d83679c3e36feb3a23ad1 100644 (file)
@@ -125,6 +125,11 @@ class Pipeline {
  private:
   Pipeline(int id, const std::string& state_change_listener_name, common::Instance* instance_ptr);
 
+  /* ######### VERY IMPORTANT #########
+   * All nnstreamer handles to nodes belonging to this Pipeline
+   * object have to be released in Dispose(), before calling
+   * ml_pipeline_destroy(pipeline_) (otherwise, the app may crash).
+   */
   const int id_;
   ml_pipeline_h pipeline_;
   const std::string state_change_listener_name_;