From: Jaeyun Jung Date: Tue, 5 Sep 2023 04:40:13 +0000 (+0900) Subject: [Subplugin/Flatbuf] util to get nth info X-Git-Tag: accepted/tizen/unified/20230912.171642~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3da3acca28d56775f14c3f398cbac7c28ff7b46;p=platform%2Fupstream%2Fnnstreamer.git [Subplugin/Flatbuf] util to get nth info Code clean, remove unnecessary copy of tensors-info and use util to get nth info. Signed-off-by: Jaeyun Jung --- diff --git a/ext/nnstreamer/tensor_converter/tensor_converter_flatbuf.cc b/ext/nnstreamer/tensor_converter/tensor_converter_flatbuf.cc index 83f7eed..60a004e 100644 --- a/ext/nnstreamer/tensor_converter/tensor_converter_flatbuf.cc +++ b/ext/nnstreamer/tensor_converter/tensor_converter_flatbuf.cc @@ -74,6 +74,8 @@ fbc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data) GstMemory *in_mem, *out_mem; GstMapInfo in_info; guint mem_size; + GstTensorInfo *_info; + UNUSED (priv_data); if (!in_buf || !config) { @@ -108,12 +110,15 @@ fbc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data) std::string _name = tensor->Get (i)->name ()->str (); const gchar *name = _name.c_str (); - config->info.info[i].name = (name && strlen (name) > 0) ? g_strdup (name) : NULL; - config->info.info[i].type = (tensor_type) tensor->Get (i)->type (); + _info = gst_tensors_info_get_nth_info (&config->info, i); + + g_free (_info->name); + _info->name = (name && strlen (name) > 0) ? g_strdup (name) : NULL; + _info->type = (tensor_type) tensor->Get (i)->type (); tensor_data = tensor->Get (i)->data (); for (guint j = 0; j < NNS_TENSOR_RANK_LIMIT; j++) { - config->info.info[i].dimension[j] = tensor->Get (i)->dimension ()->Get (j); + _info->dimension[j] = tensor->Get (i)->dimension ()->Get (j); } mem_size = VectorLength (tensor_data); diff --git a/ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc b/ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc index 69a2367..f32c068 100644 --- a/ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc +++ b/ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc @@ -91,6 +91,8 @@ flxc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data) GstMemory *in_mem, *out_mem; GstMapInfo in_info; gsize mem_size; + GstTensorInfo *_info; + UNUSED (priv_data); if (!in_buf || !config) { @@ -124,12 +126,15 @@ flxc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data) flexbuffers::String _name = tensor[0].AsString (); const gchar *name = _name.c_str (); - config->info.info[i].name = (name && strlen (name) > 0) ? g_strdup (name) : NULL; - config->info.info[i].type = (tensor_type) tensor[1].AsInt32 (); + _info = gst_tensors_info_get_nth_info (&config->info, i); + + g_free (_info->name); + _info->name = (name && strlen (name) > 0) ? g_strdup (name) : NULL; + _info->type = (tensor_type) tensor[1].AsInt32 (); flexbuffers::TypedVector dim = tensor[2].AsTypedVector (); for (guint j = 0; j < NNS_TENSOR_RANK_LIMIT; j++) { - config->info.info[i].dimension[j] = dim[j].AsInt32 (); + _info->dimension[j] = dim[j].AsInt32 (); } flexbuffers::Blob tensor_data = tensor[3].AsBlob (); mem_size = gst_tensor_info_get_size (&config->info.info[i]); diff --git a/ext/nnstreamer/tensor_decoder/tensordec-flatbuf.cc b/ext/nnstreamer/tensor_decoder/tensordec-flatbuf.cc index 57bea13..22874f3 100644 --- a/ext/nnstreamer/tensor_decoder/tensordec-flatbuf.cc +++ b/ext/nnstreamer/tensor_decoder/tensordec-flatbuf.cc @@ -84,7 +84,6 @@ static GstFlowReturn fbd_decode (void **pdata, const GstTensorsConfig *config, const GstTensorMemory *input, GstBuffer *outbuf) { - char *name; Tensor_type type; Tensor_format format; GstMapInfo out_info; @@ -101,7 +100,7 @@ fbd_decode (void **pdata, const GstTensorsConfig *config, frame_rate fr; gboolean is_flexible; GstTensorMetaInfo meta; - GstTensorsConfig fbd_config; + GstTensorInfo *_info; UNUSED (pdata); @@ -109,30 +108,31 @@ fbd_decode (void **pdata, const GstTensorsConfig *config, ml_loge ("NULL parameter is passed to tensor_decoder::flatbuf"); return GST_FLOW_ERROR; } - gst_tensors_config_copy (&fbd_config, config); - is_flexible = gst_tensors_config_is_flexible (&fbd_config); + is_flexible = gst_tensors_config_is_flexible (config); - num_tensors = fbd_config.info.num_tensors; - fr = frame_rate (fbd_config.rate_n, fbd_config.rate_d); - format = (Tensor_format) fbd_config.info.format; + num_tensors = config->info.num_tensors; + fr = frame_rate (config->rate_n, config->rate_d); + format = (Tensor_format) config->info.format; /* Fill the info in tensor and puth to tensor vector */ for (i = 0; i < num_tensors; i++) { unsigned char *tmp_buf; + _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) &config->info, i); + if (is_flexible) { gst_tensor_meta_info_parse_header (&meta, input[i].data); - gst_tensor_meta_info_convert (&meta, &fbd_config.info.info[i]); + gst_tensor_meta_info_convert (&meta, _info); } - dim = builder.CreateVector (fbd_config.info.info[i].dimension, NNS_TENSOR_RANK_LIMIT); - name = fbd_config.info.info[i].name; - if (name == NULL) + dim = builder.CreateVector (_info->dimension, NNS_TENSOR_RANK_LIMIT); + + if (_info->name == NULL) tensor_name = builder.CreateString (""); else - tensor_name = builder.CreateString (name); + tensor_name = builder.CreateString (_info->name); - type = (Tensor_type) fbd_config.info.info[i].type; + type = (Tensor_type) _info->type; /* Create the vector first, and fill in data later */ /** @todo Consider to remove memcpy */ diff --git a/ext/nnstreamer/tensor_decoder/tensordec-flexbuf.cc b/ext/nnstreamer/tensor_decoder/tensordec-flexbuf.cc index d591ec6..7629329 100644 --- a/ext/nnstreamer/tensor_decoder/tensordec-flexbuf.cc +++ b/ext/nnstreamer/tensor_decoder/tensordec-flexbuf.cc @@ -125,41 +125,45 @@ flxd_decode (void **pdata, const GstTensorsConfig *config, flexbuffers::Builder fbb; gboolean is_flexible; GstTensorMetaInfo meta; - GstTensorsConfig flxd_config; + GstTensorInfo *_info; + UNUSED (pdata); if (!config || !input || !outbuf) { ml_loge ("NULL parameter is passed to tensor_decoder::flexbuf"); return GST_FLOW_ERROR; } - gst_tensors_config_copy (&flxd_config, config); - is_flexible = gst_tensors_config_is_flexible (&flxd_config); - num_tensors = flxd_config.info.num_tensors; + is_flexible = gst_tensors_config_is_flexible (config); + + num_tensors = config->info.num_tensors; fbb.Map ([&] () { fbb.UInt ("num_tensors", num_tensors); - fbb.Int ("rate_n", flxd_config.rate_n); - fbb.Int ("rate_d", flxd_config.rate_d); - fbb.Int ("format", flxd_config.info.format); + fbb.Int ("rate_n", config->rate_n); + fbb.Int ("rate_d", config->rate_d); + fbb.Int ("format", config->info.format); for (i = 0; i < num_tensors; i++) { gchar *tensor_key = g_strdup_printf ("tensor_%d", i); gchar *tensor_name = NULL; + + _info = gst_tensors_info_get_nth_info ((GstTensorsInfo *) &config->info, i); + if (is_flexible) { gst_tensor_meta_info_parse_header (&meta, input[i].data); - gst_tensor_meta_info_convert (&meta, &flxd_config.info.info[i]); + gst_tensor_meta_info_convert (&meta, _info); } - tensor_name = flxd_config.info.info[i].name; - if (flxd_config.info.info[i].name == NULL) { + + if (_info->name == NULL) { tensor_name = g_strdup (""); } else { - tensor_name = g_strdup (flxd_config.info.info[i].name); + tensor_name = g_strdup (_info->name); } - tensor_type type = flxd_config.info.info[i].type; + tensor_type type = _info->type; fbb.Vector (tensor_key, [&] () { fbb += tensor_name; fbb += type; - fbb.Vector (flxd_config.info.info[i].dimension, NNS_TENSOR_RANK_LIMIT); + fbb.Vector (_info->dimension, NNS_TENSOR_RANK_LIMIT); fbb.Blob (input[i].data, input[i].size); }); g_free (tensor_key);