From d65e0f2725cff47a9808bd84e1ba292468353557 Mon Sep 17 00:00:00 2001 From: HarshJ20 Date: Fri, 16 Jun 2023 17:02:31 +0530 Subject: [PATCH] Address feedback from PR#4115 - changed "finalize" function to "gst_tensor_top_detectedObjects_cropInfo" - introduced new function "init_meta" to intialize flexible tensor header info for tensor_crop - changed the string value in GstOutCaps for updating Caps info - checked the resulting buffer's data with the intended result Signed-off-by: HarshJ20 --- .../tensor_decoder/tensordec-tensor_region.c | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c b/ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c index f37bcd0..8850966 100644 --- a/ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c +++ b/ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c @@ -396,15 +396,14 @@ typedef struct { * @param[in] results The final results to be transfered. */ static void -finalize (GstMapInfo *out_info, tensor_region *data, GArray *results) +gst_tensor_top_detectedObjects_cropInfo (GstMapInfo *out_info, tensor_region *data, GArray *results) { guint i; guint size = sizeof (crop_region); /**Assuming crop_region is a structure with four integer fields */ - guint8 *out_data = out_info->data; + int *out_data = (int *)out_info->data; crop_region region; guint maxx = MIN (results->len, data->num); - for (i = 0; i < maxx; i++) { detected_object *temp = &g_array_index (results, detected_object, i); region.x = temp->x; @@ -578,18 +577,31 @@ nms (GArray *results, gfloat threshold) } while (i < results->len); } +/** + * @brief Private function to initialize the meta info + */ +static void +init_meta(GstTensorMetaInfo * meta, tensor_region * trData){ + gst_tensor_meta_info_init (meta); + meta->type = _NNS_UINT32; + meta->dimension[0] = BOX_SIZE; + meta->dimension[1] = trData->num; + meta->media_type = _NNS_TENSOR; +} + /** @brief tensordec-plugin's GstTensorDecoderDef callback */ static GstFlowReturn tr_decode (void **pdata, const GstTensorsConfig *config, const GstTensorMemory *input, GstBuffer *outbuf) { tensor_region *trData = *pdata; + GstTensorMetaInfo meta; GstMapInfo out_info; GstMemory *out_mem; GArray *results = NULL; const guint num_tensors = config->info.num_tensors; gboolean need_output_alloc = gst_buffer_get_size (outbuf) == 0; - const size_t size = (size_t) 4 * trData->num; /**4 field per block */ + const size_t size = (size_t) 4 * trData->num * sizeof(uint32_t); /**4 field per block */ g_assert (outbuf); /**Ensure we have outbuf properly allocated */ @@ -639,12 +651,18 @@ tr_decode (void **pdata, const GstTensorsConfig *config, GST_ERROR ("Failed to get output buffer, unknown mode %d.", trData->mode); goto error_unmap; } - finalize (&out_info, trData, results); + gst_tensor_top_detectedObjects_cropInfo (&out_info, trData, results); g_array_free (results, TRUE); gst_memory_unmap (out_mem, &out_info); + /** converting to Flexible tensor since + * info pad of tensor_crop has capability for flexible tensor stream + */ + init_meta(&meta, trData); + out_mem = gst_tensor_meta_info_append_header(&meta, out_mem); + if (need_output_alloc) gst_buffer_append_memory (outbuf, out_mem); else @@ -723,7 +741,7 @@ tr_getOutCaps (void **pdata, const GstTensorsConfig *config) if (!_set_max_detection (data, max_detection, MOBILENET_SSD_DETECTION_MAX)) { return NULL; } - str = g_strdup_printf ("testing"); + str = g_strdup_printf("other/tensor-flexible, width=%u, height=%u, type=(int)32, dimension=%d:%d", data->i_width, data->i_height, BOX_SIZE, data->num); caps = gst_caps_from_string (str); setFramerateFromConfig (caps, config); g_free (str); -- 2.7.4