[CAPI] Wait until the pipeline state is changed accepted/tizen/unified/20201222.122524 submit/tizen/20201222.073053
authorDongju Chae <dongju.chae@samsung.com>
Wed, 16 Dec 2020 10:05:11 +0000 (19:05 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 22 Dec 2020 00:50:55 +0000 (09:50 +0900)
This patch fixes a potential danger after ml_pipeline_construct()
is called. As ml_pipeline_construct() does not wait the pipeline
state change, the following APIs such as set_property may affect
the initial pipeline processing with dummy data (even if the pipe
line is not started).

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
api/capi/src/nnstreamer-capi-pipeline.c
gst/nnstreamer/tensor_demux/gsttensordemux.c

index 086982a..f69531f 100644 (file)
@@ -631,6 +631,17 @@ construct_pipeline_internal (const char *pipeline_description,
   /* finally set pipeline state to PAUSED */
   if (status == ML_ERROR_NONE) {
     status = ml_pipeline_stop ((ml_pipeline_h) pipe_h);
+
+    if (status == ML_ERROR_NONE) {
+      /**
+       * Let's wait until the pipeline state is changed to paused.
+       * Otherwise, the following APIs like 'set_property' may incur
+       * unintended behaviors. But, don't need to return any error
+       * even if this state change is not finished within the timeout,
+       * just replying on the caller.
+       */
+      gst_element_get_state (pipeline, NULL, NULL, 10 * GST_MSECOND);
+    }
   }
 
 failed:
index d2ab83b..ff732a5 100644 (file)
@@ -312,7 +312,7 @@ gst_tensor_demux_get_tensor_pad (GstTensorDemux * tensor_demux,
   gchar *name;
   GstEvent *event;
   gchar *stream_id;
-  GstCaps *caps;
+  GstCaps *caps = NULL;
 
   walk = tensor_demux->srcpads;
   while (walk) {
@@ -387,8 +387,8 @@ gst_tensor_demux_get_tensor_pad (GstTensorDemux * tensor_demux,
     if (num == 1 && gst_pad_has_tensor_caps (pad)) {
       GstTensorConfig config;
       gint64 idx = g_ascii_strtoll (strv[0], NULL, 10);
-      gst_tensor_demux_get_tensor_config (tensor_demux, &config, idx);
-      caps = gst_tensor_caps_from_config (&config);
+      if (gst_tensor_demux_get_tensor_config (tensor_demux, &config, idx))
+        caps = gst_tensor_caps_from_config (&config);
     } else {
       GstTensorsConfig config;
       guint i;
@@ -405,12 +405,16 @@ gst_tensor_demux_get_tensor_pad (GstTensorDemux * tensor_demux,
     g_strfreev (strv);
   } else {
     GstTensorConfig config;
-    gst_tensor_demux_get_tensor_config (tensor_demux, &config, nth);
-    caps = gst_tensor_caps_from_config (&config);
+    if (gst_tensor_demux_get_tensor_config (tensor_demux, &config, nth))
+      caps = gst_tensor_caps_from_config (&config);
   }
 
-  gst_pad_set_caps (pad, caps);
-  gst_caps_unref (caps);
+  if (caps) {
+    gst_pad_set_caps (pad, caps);
+    gst_caps_unref (caps);
+  } else {
+    GST_WARNING_OBJECT (tensor_demux, "Unable to set pad caps");
+  }
 
   if (created) {
     *created = TRUE;