[util] Fix the signature of gst_tensor_buffer_get_nth_meory
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Tue, 13 Jun 2023 05:43:36 +0000 (14:43 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 13 Jun 2023 08:12:14 +0000 (17:12 +0900)
- Remove unused argument of GstTensorsInfo.
- Fix used lines.

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
gst/nnstreamer/include/nnstreamer_plugin_api.h
gst/nnstreamer/nnstreamer_plugin_api_impl.c
gst/nnstreamer/tensor_filter/tensor_filter.c
tests/nnstreamer_filter_tensorflow2_lite/unittest_filter_tensorflow2_lite.cc
tests/nnstreamer_sink/unittest_sink.cc

index f797106..d2cafdc 100644 (file)
@@ -126,7 +126,7 @@ gst_tensor_caps_can_intersect (GstCaps *caps1, GstCaps *caps2);
  * @return GstMemory if found, otherwise NULL (Caller should free returned memory using gst_memory_unref()).
  */
 extern GstMemory *
-gst_tensor_buffer_get_nth_memory (GstBuffer * buffer, const GstTensorsInfo * info, const guint index);
+gst_tensor_buffer_get_nth_memory (GstBuffer * buffer, const guint index);
 
 /**
  * @brief Append @a memory to given @a buffer.
index 58618ba..cea978a 100644 (file)
@@ -1523,10 +1523,9 @@ gst_tensor_extra_info_init (GstTensorExtraInfo * extra, gsize reserved_size)
  * @return GstMemory if found, otherwise NULL (Caller should free returned memory using gst_memory_unref()).
  */
 GstMemory *
-gst_tensor_buffer_get_nth_memory (GstBuffer * buffer,
-    const GstTensorsInfo * info, const guint index)
+gst_tensor_buffer_get_nth_memory (GstBuffer * buffer, const guint index)
 {
-  guint i, offset = 0;
+  guint i, num_tensors, offset = 0;
   GstMemory *extra_tensors_memory, *res_mem;
   GstMapInfo extra_tensors_map;
   GstTensorExtraInfo *extra_info;
@@ -1536,19 +1535,14 @@ gst_tensor_buffer_get_nth_memory (GstBuffer * buffer,
     return NULL;
   }
 
-  if (!info) {
-    nns_loge ("Failed to get tensors info (invalid input info).");
-    return NULL;
-  }
-
-  if (info->num_tensors <= 0) {
-    nns_loge ("num_tensors is 0. Please check the tensors info.");
+  num_tensors = gst_buffer_n_tensor (buffer);
+  if (num_tensors == 0U) {
+    nns_loge ("num_tensors is 0. Please check the buffer.");
     return NULL;
   }
 
   /* If num_tensors is less than or equal to NNS_TENSOR_SIZE_LIMIT, it's trivial. */
-  if (info->num_tensors <= NNS_TENSOR_SIZE_LIMIT
-      || index < NNS_TENSOR_SIZE_LIMIT - 1) {
+  if (num_tensors <= NNS_TENSOR_SIZE_LIMIT || index < NNS_TENSOR_SIZE_LIMIT - 1) {
     return gst_buffer_get_memory (buffer, index);
   }
 
index a32ee4f..ea02f8b 100644 (file)
@@ -688,7 +688,7 @@ gst_tensor_filter_transform (GstBaseTransform * trans,
   num_tensors = gst_buffer_n_tensor (inbuf);
 
   for (i = 0; i < num_tensors; i++) {
-    in_mem[i] = gst_tensor_buffer_get_nth_memory (inbuf, &prop->input_meta, i);
+    in_mem[i] = gst_tensor_buffer_get_nth_memory (inbuf, i);
     if (!gst_memory_map (in_mem[i], &in_info[i], GST_MAP_READ)) {
       ml_logf_stacktrace
           ("gst_tensor_filter_transform: For the given input buffer, tensor-filter (%s : %s) cannot map input memory from the buffer for reading. The %u-th memory chunk (%u-th tensor) has failed for memory map.\n",
index f5d285a..e0ca04a 100644 (file)
@@ -293,15 +293,11 @@ check_output_many (GstElement *element, GstBuffer *buffer, gpointer user_data)
   gboolean mapped;
   UNUSED (element);
 
-  GstTensorsInfo ts_info;
-  gst_tensors_info_init (&ts_info);
-  ts_info.num_tensors = 32;
-
   guint *data_received = (guint *) user_data;
   (*data_received)++;
 
   for (guint i = 0; i < 32; i++) {
-    mem_res = gst_tensor_buffer_get_nth_memory (buffer, &ts_info, i);
+    mem_res = gst_tensor_buffer_get_nth_memory (buffer, i);
     mapped = gst_memory_map (mem_res, &info_res, GST_MAP_READ);
     ASSERT_TRUE (mapped);
     gfloat *output = (gfloat *) info_res.data;
index 5636e3d..3f6651c 100644 (file)
@@ -6451,14 +6451,10 @@ _manual_extra_tensors_new_data_cb (GstElement *element, GstBuffer *buffer, gpoin
   GstMapInfo info_res;
   gint *output, i;
   gboolean ret;
-  GstTensorsInfo ts_info;
-
-  gst_tensors_info_init (&ts_info);
-  ts_info.num_tensors = 20;
 
   data_received++;
   for (i = 0; i < 20; ++i) {
-    mem_res = gst_tensor_buffer_get_nth_memory (buffer, &ts_info, i);
+    mem_res = gst_tensor_buffer_get_nth_memory (buffer, i);
     ret = gst_memory_map (mem_res, &info_res, GST_MAP_READ);
     ASSERT_TRUE (ret);
     output = (gint *) info_res.data;
@@ -6466,8 +6462,6 @@ _manual_extra_tensors_new_data_cb (GstElement *element, GstBuffer *buffer, gpoin
     gst_memory_unmap (mem_res, &info_res);
     gst_memory_unref (mem_res);
   }
-
-  gst_tensors_info_free (&ts_info);
 }
 
 /**
@@ -6556,14 +6550,11 @@ _tensor_mux_extra_tensors_new_data_cb (GstElement *element, GstBuffer *buffer, g
   guint8 *output;
   gint i;
   gboolean ret;
-  GstTensorsInfo ts_info;
 
-  gst_tensors_info_init (&ts_info);
   data_received++;
-  ts_info.num_tensors = 20;
 
   for (i = 0; i < 20; ++i) {
-    mem_res = gst_tensor_buffer_get_nth_memory (buffer, &ts_info, (guint) i);
+    mem_res = gst_tensor_buffer_get_nth_memory (buffer, (guint) i);
     ret = gst_memory_map (mem_res, &info_res, GST_MAP_READ);
     ASSERT_TRUE (ret);
     output = (guint8 *) info_res.data;