From b31c150213daf194522b6cf59e9e0e182737d495 Mon Sep 17 00:00:00 2001 From: Dongju Chae Date: Wed, 16 Dec 2020 19:05:11 +0900 Subject: [PATCH] [CAPI] Wait until the pipeline state is changed 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 --- api/capi/src/nnstreamer-capi-pipeline.c | 11 +++++++++++ gst/nnstreamer/tensor_demux/gsttensordemux.c | 18 +++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/capi/src/nnstreamer-capi-pipeline.c b/api/capi/src/nnstreamer-capi-pipeline.c index 086982a..f69531f 100644 --- a/api/capi/src/nnstreamer-capi-pipeline.c +++ b/api/capi/src/nnstreamer-capi-pipeline.c @@ -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: diff --git a/gst/nnstreamer/tensor_demux/gsttensordemux.c b/gst/nnstreamer/tensor_demux/gsttensordemux.c index d2ab83b..ff732a5 100644 --- a/gst/nnstreamer/tensor_demux/gsttensordemux.c +++ b/gst/nnstreamer/tensor_demux/gsttensordemux.c @@ -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; -- 2.7.4