From a07d403354a9340e5392550a969c87233b4afffe Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Mon, 11 Feb 2019 18:07:37 +0900 Subject: [PATCH] [Common] add common function 1. add new function _info_free() to free allocated data in tensor-info structure 2. move functions to plugin api header TODO: I will add new PR to use common functions to set/get tensor info in tensor_filter tf sub-plugins. Signed-off-by: Jaeyun Jung --- gst/nnstreamer/nnstreamer_plugin_api.h | 42 ++++++++++++++++++++++++++++++++++ gst/nnstreamer/tensor_common.c | 35 ++++++++++++++++++++++++++-- gst/nnstreamer/tensor_common.h | 28 ----------------------- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/gst/nnstreamer/nnstreamer_plugin_api.h b/gst/nnstreamer/nnstreamer_plugin_api.h index 03a85f7..4b04099 100644 --- a/gst/nnstreamer/nnstreamer_plugin_api.h +++ b/gst/nnstreamer/nnstreamer_plugin_api.h @@ -47,6 +47,13 @@ extern void gst_tensor_info_init (GstTensorInfo * info); /** + * @brief Free allocated data in tensor info structure + * @param info tensor info structure + */ +extern void +gst_tensor_info_free (GstTensorInfo * info); + +/** * @brief Get data size of single tensor * @param info tensor info structure * @return data size @@ -63,6 +70,20 @@ extern gboolean gst_tensor_info_validate (const GstTensorInfo *info); /** + * @brief Compare tensor info + * @param TRUE if equal + */ +extern gboolean +gst_tensor_info_is_equal (const GstTensorInfo * i1, const GstTensorInfo * i2); + +/** + * @brief Copy tensor info + * @note Copied info should be freed with gst_tensor_info_free() + */ +extern void +gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src); + +/** * @brief Initialize the tensors info structure * @param info tensors info structure to be initialized */ @@ -70,6 +91,13 @@ extern void gst_tensors_info_init (GstTensorsInfo *info); /** + * @brief Free allocated data in tensors info structure + * @param info tensors info structure + */ +extern void +gst_tensors_info_free (GstTensorsInfo * info); + +/** * @brief Parse the string of dimensions * @param info tensors info structure * @param dim_string string of dimensions @@ -98,6 +126,20 @@ extern gboolean gst_tensors_info_validate (const GstTensorsInfo *info); /** + * @brief Compare tensors info + * @param TRUE if equal + */ +extern gboolean +gst_tensors_info_is_equal (const GstTensorsInfo * i1, const GstTensorsInfo * i2); + +/** + * @brief Copy tensor info + * @note Copied info should be freed with gst_tensors_info_free() + */ +extern void +gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src); + +/** * @brief Initialize the tensor config info structure * @param config tensor config structure to be initialized */ diff --git a/gst/nnstreamer/tensor_common.c b/gst/nnstreamer/tensor_common.c index 754a437..821eec2 100644 --- a/gst/nnstreamer/tensor_common.c +++ b/gst/nnstreamer/tensor_common.c @@ -27,6 +27,21 @@ #include /** + * @brief Free allocated data in tensor info structure + * @param info tensor info structure + */ +void +gst_tensor_info_free (GstTensorInfo * info) +{ + g_return_if_fail (info != NULL); + + if (info->name) { + g_free (info->name); + info->name = NULL; + } +} + +/** * @brief Compare tensor info * @param TRUE if equal */ @@ -54,7 +69,7 @@ gst_tensor_info_is_equal (const GstTensorInfo * i1, const GstTensorInfo * i2) /** * @brief Copy tensor info - * @note GstTensorInfo::name should be freed with g_free() + * @note Copied info should be freed with gst_tensor_info_free() */ void gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src) @@ -73,6 +88,22 @@ gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src) } /** + * @brief Free allocated data in tensors info structure + * @param info tensors info structure + */ +void +gst_tensors_info_free (GstTensorsInfo * info) +{ + guint i; + + g_return_if_fail (info != NULL); + + for (i = 0; i < info->num_tensors; i++) { + gst_tensor_info_free (&info->info[i]); + } +} + +/** * @brief Compare tensors info * @param TRUE if equal */ @@ -100,7 +131,7 @@ gst_tensors_info_is_equal (const GstTensorsInfo * i1, const GstTensorsInfo * i2) /** * @brief Copy tensor info - * @note GstTensorInfo::name should be freed with g_free() + * @note Copied info should be freed with gst_tensors_info_free() */ void gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src) diff --git a/gst/nnstreamer/tensor_common.h b/gst/nnstreamer/tensor_common.h index 7af7063..ef72583 100644 --- a/gst/nnstreamer/tensor_common.h +++ b/gst/nnstreamer/tensor_common.h @@ -125,34 +125,6 @@ typedef struct } GstTensorCollectPadData; /** - * @brief Compare tensor info - * @param TRUE if equal - */ -extern gboolean -gst_tensor_info_is_equal (const GstTensorInfo * i1, const GstTensorInfo * i2); - -/** - * @brief Copy tensor info - * @note GstTensorInfo::name should be freed with g_free() - */ -extern void -gst_tensor_info_copy (GstTensorInfo * dest, const GstTensorInfo * src); - -/** - * @brief Compare tensors info - * @param TRUE if equal - */ -extern gboolean -gst_tensors_info_is_equal (const GstTensorsInfo * i1, const GstTensorsInfo * i2); - -/** - * @brief Copy tensor info - * @note GstTensorInfo::name should be freed with g_free() - */ -extern void -gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src); - -/** * @brief Parse the string of names * @param info tensors info structure * @param name_string string of names -- 2.7.4