From 2139948711102d816fd51c07df9aa8d61f9deca2 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Fri, 30 Nov 2018 20:10:06 +0900 Subject: [PATCH] [Filter] update macros to avoid assertion 1. check fw and fw-function before calling in macro 2. return true in _start() and _stop() vmethods Signed-off-by: Jaeyun Jung --- gst/tensor_filter/tensor_filter.c | 129 ++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 74 deletions(-) diff --git a/gst/tensor_filter/tensor_filter.c b/gst/tensor_filter/tensor_filter.c index 7564d07..2bc8b93 100644 --- a/gst/tensor_filter/tensor_filter.c +++ b/gst/tensor_filter/tensor_filter.c @@ -206,12 +206,10 @@ static gboolean gst_tensor_filter_stop (GstBaseTransform * trans); * @brief Open nn framework. */ #define gst_tensor_filter_open_fw(filter) do { \ - if (filter->prop.fw_opened == FALSE) { \ + if (filter->prop.fw_opened == FALSE && filter->fw) { \ if (filter->fw->open != NULL) {\ if (filter->fw->open (filter, &filter->privateData) == 0) \ filter->prop.fw_opened = TRUE; \ - else \ - filter->prop.fw_opened = FALSE; \ } else {\ filter->prop.fw_opened = TRUE; \ } \ @@ -222,10 +220,11 @@ static gboolean gst_tensor_filter_stop (GstBaseTransform * trans); * @brief Close nn framework. */ #define gst_tensor_filter_close_fw(filter) do { \ - g_assert (filter->prop.fw_opened); \ - if (filter->fw->close) \ - filter->fw->close (filter, &filter->privateData); \ - filter->prop.fw_opened = FALSE; \ + if (filter->prop.fw_opened) { \ + if (filter->fw && filter->fw->close) \ + filter->fw->close (filter, &filter->privateData); \ + filter->prop.fw_opened = FALSE; \ + } \ } while (0) /** @@ -233,11 +232,10 @@ static gboolean gst_tensor_filter_stop (GstBaseTransform * trans); */ #define gst_tensor_filter_call(filter,ret,funcname,...) do { \ gst_tensor_filter_open_fw (filter); \ - if (filter->prop.fw_opened == FALSE) { \ - ret = -1; \ - break; \ + ret = -1; \ + if (filter->prop.fw_opened && filter->fw && filter->fw->funcname) { \ + ret = filter->fw->funcname (filter, &filter->privateData, __VA_ARGS__); \ } \ - ret = filter->fw->funcname (filter, &filter->privateData, __VA_ARGS__); \ } while (0) /** @@ -409,9 +407,7 @@ gst_tensor_filter_set_property (GObject * object, guint prop_id, break; case PROP_FRAMEWORK: if (prop->nnfw != _T_F_UNDEFINED) { - /** @todo CRITICAL: CLOSE IT before proceeding */ - if (prop->fw_opened == TRUE) - gst_tensor_filter_close_fw (self); + gst_tensor_filter_close_fw (self); } prop->nnfw = find_key_strv (nnfw_names, g_value_get_string (value)); silent_debug ("Framework = %s\n", g_value_get_string (value)); @@ -438,9 +434,7 @@ gst_tensor_filter_set_property (GObject * object, guint prop_id, break; case PROP_MODEL: if (prop->model_file) { - /** @todo CRITICAL: CLOSE IT before proceeding */ - if (prop->fw_opened == TRUE) - gst_tensor_filter_close_fw (self); + gst_tensor_filter_close_fw (self); g_free ((char *) prop->model_file); /* g_free cannot handle const * */ } if (!value) { @@ -807,25 +801,23 @@ gst_tensor_filter_load_tensor_info (GstTensorFilter * self) * supposed fixed in-tensor info if getInputDimension is defined. */ if (!prop->input_configured) { - if (self->fw && self->fw->getInputDimension) { - GstTensorsInfo in_info; + GstTensorsInfo in_info; - gst_tensors_info_init (&in_info); - gst_tensor_filter_call (self, res, getInputDimension, &in_info); + gst_tensors_info_init (&in_info); + gst_tensor_filter_call (self, res, getInputDimension, &in_info); - if (res == 0) { - g_assert (in_info.num_tensors > 0); + if (res == 0) { + g_assert (in_info.num_tensors > 0); - /** if set-property called and already has info, verify it! */ - if (prop->input_meta.num_tensors > 0) { - g_assert (gst_tensors_info_is_equal (&prop->input_meta, &in_info)); - } + /** if set-property called and already has info, verify it! */ + if (prop->input_meta.num_tensors > 0) { + g_assert (gst_tensors_info_is_equal (&prop->input_meta, &in_info)); + } - prop->input_configured = TRUE; - prop->input_meta = in_info; + prop->input_configured = TRUE; + prop->input_meta = in_info; - silent_debug_info (&in_info, "input tensor"); - } + silent_debug_info (&in_info, "input tensor"); } } @@ -833,25 +825,23 @@ gst_tensor_filter_load_tensor_info (GstTensorFilter * self) * supposed fixed out-tensor info if getOutputDimension is defined. */ if (!prop->output_configured) { - if (self->fw && self->fw->getOutputDimension) { - GstTensorsInfo out_info; + GstTensorsInfo out_info; - gst_tensors_info_init (&out_info); - gst_tensor_filter_call (self, res, getOutputDimension, &out_info); + gst_tensors_info_init (&out_info); + gst_tensor_filter_call (self, res, getOutputDimension, &out_info); - if (res == 0) { - g_assert (out_info.num_tensors > 0); + if (res == 0) { + g_assert (out_info.num_tensors > 0); - /** if set-property called and already has info, verify it! */ - if (prop->output_meta.num_tensors > 0) { - g_assert (gst_tensors_info_is_equal (&prop->output_meta, &out_info)); - } + /** if set-property called and already has info, verify it! */ + if (prop->output_meta.num_tensors > 0) { + g_assert (gst_tensors_info_is_equal (&prop->output_meta, &out_info)); + } - prop->output_configured = TRUE; - prop->output_meta = out_info; + prop->output_configured = TRUE; + prop->output_meta = out_info; - silent_debug_info (&out_info, "output tensor"); - } + silent_debug_info (&out_info, "output tensor"); } } } @@ -964,32 +954,29 @@ gst_tensor_filter_configure_tensor (GstTensorFilter * self, /** call setInputDimension if output tensor is not configured */ if (!prop->output_configured) { - if (self->fw->setInputDimension) { - GstTensorsInfo out_info; - int res; + GstTensorsInfo out_info; + int res; - gst_tensors_info_init (&out_info); - gst_tensor_filter_call (self, res, setInputDimension, &in_config.info, - &out_info); + gst_tensors_info_init (&out_info); + gst_tensor_filter_call (self, res, setInputDimension, &in_config.info, + &out_info); - if (res == 0) { - /** if set-property called and already has info, verify it! */ - if (prop->output_meta.num_tensors > 0) { - if (!gst_tensors_info_is_equal (&prop->output_meta, &out_info)) { - gchar *str = - _compare_tensors (&in_config.info, &prop->input_meta); - GST_ERROR_OBJECT (self, - "The output tensor is not compatible.\n%s", str); - g_free (str); - return FALSE; - } + if (res == 0) { + /** if set-property called and already has info, verify it! */ + if (prop->output_meta.num_tensors > 0) { + if (!gst_tensors_info_is_equal (&prop->output_meta, &out_info)) { + gchar *str = _compare_tensors (&in_config.info, &prop->input_meta); + GST_ERROR_OBJECT (self, + "The output tensor is not compatible.\n%s", str); + g_free (str); + return FALSE; } + } - prop->output_configured = TRUE; - prop->output_meta = out_info; + prop->output_configured = TRUE; + prop->output_meta = out_info; - silent_debug_info (&out_info, "output tensor"); - } + silent_debug_info (&out_info, "output tensor"); } if (!prop->output_configured) { @@ -1108,10 +1095,8 @@ gst_tensor_filter_transform_caps (GstBaseTransform * trans, int res = -1; /* call setInputDimension with given input tensor */ - if (self->fw->setInputDimension) { - gst_tensor_filter_call (self, res, setInputDimension, &in_info, - &config.info); - } + gst_tensor_filter_call (self, res, setInputDimension, &in_info, + &config.info); if (res == 0) { result = gst_tensor_filter_caps_from_config (self, &config); @@ -1265,8 +1250,6 @@ gst_tensor_filter_start (GstBaseTransform * trans) GstTensorFilter *self; self = GST_TENSOR_FILTER_CAST (trans); - if (self->fw == NULL) - return FALSE; gst_tensor_filter_open_fw (self); return TRUE; @@ -1283,8 +1266,6 @@ gst_tensor_filter_stop (GstBaseTransform * trans) GstTensorFilter *self; self = GST_TENSOR_FILTER_CAST (trans); - if (self->fw == NULL) - return FALSE; gst_tensor_filter_close_fw (self); return TRUE; -- 2.7.4