[C-Api] fix error to run pipeline
authorJaeyun <jy1210.jung@samsung.com>
Wed, 17 Jul 2019 06:56:30 +0000 (15:56 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 17 Jul 2019 12:19:22 +0000 (21:19 +0900)
1. return valid error code when opening single-shot model.
2. When called destroy() in pipeline, remove all callbacks before changing pipeline state.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
api/capi/include/nnstreamer-single.h
api/capi/src/nnstreamer-capi-pipeline.c
api/capi/src/nnstreamer-capi-single.c

index 443264c..d9ee968 100644 (file)
@@ -73,7 +73,7 @@ typedef void *ml_single_h;
  * @retval #ML_ERROR_NONE Successful
  * @retval #ML_ERROR_INVALID_PARAMETER Fail. The parameter is invalid.
  * @retval #ML_ERROR_STREAMS_PIPE Failed to start the pipeline.
- *
+ * @retval #ML_ERROR_NOT_SUPPORTED Fail. The parameter is not available.
  */
 int ml_single_open (ml_single_h *single, const char *model, const ml_tensors_info_h input_info, const ml_tensors_info_h output_info, ml_nnfw_type_e nnfw, ml_nnfw_hw_e hw);
 
index dd8621c..d7ff9d4 100644 (file)
@@ -492,6 +492,13 @@ ml_pipeline_destroy (ml_pipeline_h pipe)
 
   g_mutex_lock (&p->lock);
 
+  /* Before changing the state, remove all callbacks. */
+  p->cb = NULL;
+  g_signal_handler_disconnect (p->bus, p->signal_msg);
+  gst_object_unref (p->bus);
+
+  g_hash_table_remove_all (p->namednodes);
+
   /* if it's PLAYING, PAUSE it. */
   scret = gst_element_get_state (p->element, &state, NULL, 10 * GST_MSECOND);     /* 10ms */
   if (scret != GST_STATE_CHANGE_FAILURE && state == GST_STATE_PLAYING) {
@@ -508,11 +515,9 @@ ml_pipeline_destroy (ml_pipeline_h pipe)
   g_usleep (50000);             /* do 50ms sleep until we have it implemented. Let them complete. And hope they don't call start(). */
   g_mutex_lock (&p->lock);
 
-  g_signal_handler_disconnect (p->bus, p->signal_msg);
-  gst_object_unref (p->bus);
-
   /** Destroy registered callback handles */
   g_hash_table_destroy (p->namednodes);
+  p->namednodes = NULL;
 
   /** Stop (NULL State) the pipeline */
   scret = gst_element_set_state (p->element, GST_STATE_NULL);
index 435a8f9..aeed7a6 100644 (file)
@@ -151,9 +151,12 @@ ml_single_open (ml_single_h * single, const char *model,
   /* 2. Determine hw */
   /** @todo Now the param hw is ignored. (Supposed CPU only) Support others later. */
   status = ml_check_nnfw_availability (nnfw, hw, &available);
-  if (status != ML_ERROR_NONE || !available) {
-    ml_loge ("The given nnfw is not available.");
+  if (status != ML_ERROR_NONE)
     return status;
+
+  if (!available) {
+    ml_loge ("The given nnfw is not available.");
+    return ML_ERROR_NOT_SUPPORTED;
   }
 
   /* 3. Construct a pipeline */