Address feedback from PR#4115
authorHarshJ20 <hjain24in@gmail.com>
Fri, 16 Jun 2023 11:32:31 +0000 (17:02 +0530)
committergichan-jang <56856496+gichan-jang@users.noreply.github.com>
Tue, 20 Jun 2023 04:14:31 +0000 (13:14 +0900)
    - 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 <hjain24in@gmail.com>
ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c

index f37bcd0..8850966 100644 (file)
@@ -396,15 +396,14 @@ typedef struct {
  * @param[in] results The final results to be transfered.\r
  */\r
 static void\r
-finalize (GstMapInfo *out_info, tensor_region *data, GArray *results)\r
+gst_tensor_top_detectedObjects_cropInfo (GstMapInfo *out_info, tensor_region *data, GArray *results)\r
 {\r
 \r
   guint i;\r
   guint size = sizeof (crop_region); /**Assuming crop_region is a structure with four integer fields */\r
-  guint8 *out_data = out_info->data;\r
+  int *out_data = (int *)out_info->data;\r
   crop_region region;\r
   guint maxx = MIN (results->len, data->num);\r
-\r
   for (i = 0; i < maxx; i++) {\r
     detected_object *temp = &g_array_index (results, detected_object, i);\r
     region.x = temp->x;\r
@@ -578,18 +577,31 @@ nms (GArray *results, gfloat threshold)
   } while (i < results->len);\r
 }\r
 \r
+/**\r
+ * @brief Private function to initialize the meta info\r
+ */\r
+static void \r
+init_meta(GstTensorMetaInfo * meta, tensor_region * trData){\r
+  gst_tensor_meta_info_init (meta);\r
+  meta->type = _NNS_UINT32;\r
+  meta->dimension[0] = BOX_SIZE;\r
+  meta->dimension[1] = trData->num;\r
+  meta->media_type = _NNS_TENSOR;\r
+}\r
+\r
 /** @brief tensordec-plugin's GstTensorDecoderDef callback */\r
 static GstFlowReturn\r
 tr_decode (void **pdata, const GstTensorsConfig *config,\r
     const GstTensorMemory *input, GstBuffer *outbuf)\r
 {\r
   tensor_region *trData = *pdata;\r
+  GstTensorMetaInfo meta;\r
   GstMapInfo out_info;\r
   GstMemory *out_mem;\r
   GArray *results = NULL;\r
   const guint num_tensors = config->info.num_tensors;\r
   gboolean need_output_alloc = gst_buffer_get_size (outbuf) == 0;\r
-  const size_t size = (size_t) 4 * trData->num; /**4 field per block */\r
+  const size_t size = (size_t) 4 * trData->num * sizeof(uint32_t); /**4 field per block */\r
 \r
   g_assert (outbuf);\r
   /**Ensure we have outbuf properly allocated */\r
@@ -639,12 +651,18 @@ tr_decode (void **pdata, const GstTensorsConfig *config,
     GST_ERROR ("Failed to get output buffer, unknown mode %d.", trData->mode);\r
     goto error_unmap;\r
   }\r
-  finalize (&out_info, trData, results);\r
+  gst_tensor_top_detectedObjects_cropInfo (&out_info, trData, results);\r
 \r
   g_array_free (results, TRUE);\r
 \r
   gst_memory_unmap (out_mem, &out_info);\r
 \r
+  /** converting to Flexible tensor since  \r
+   * info pad of tensor_crop has capability for flexible tensor stream \r
+  */\r
+  init_meta(&meta, trData);\r
+  out_mem = gst_tensor_meta_info_append_header(&meta, out_mem);\r
+\r
   if (need_output_alloc)\r
     gst_buffer_append_memory (outbuf, out_mem);\r
   else\r
@@ -723,7 +741,7 @@ tr_getOutCaps (void **pdata, const GstTensorsConfig *config)
   if (!_set_max_detection (data, max_detection, MOBILENET_SSD_DETECTION_MAX)) {\r
     return NULL;\r
   }\r
-  str = g_strdup_printf ("testing");\r
+  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);\r
   caps = gst_caps_from_string (str);\r
   setFramerateFromConfig (caps, config);\r
   g_free (str);\r