[Aggregator] update code to concatenate data with axis
authorJaeyun <jy1210.jung@samsung.com>
Wed, 10 Oct 2018 11:54:45 +0000 (20:54 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Wed, 10 Oct 2018 14:53:20 +0000 (23:53 +0900)
update data concatenation for the axis (frames-dim)

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/tensor_aggregator/tensor_aggregator.c

index d70a761..96b19c5 100644 (file)
@@ -549,10 +549,10 @@ gst_tensor_aggregator_concat (GstTensorAggregator * self, GstBuffer * outbuf,
 {
   GstBuffer *srcbuf;
   GstMapInfo src_info, dest_info;
-  guint f, d0, d1;
+  guint f;
   gsize block_size;
   gsize src_idx, dest_idx;
-  gsize frame_size;
+  gsize frame_size, copied;
 
   frame_size = gst_tensor_info_get_size (info);
   g_assert (frame_size > 0);
@@ -736,28 +736,26 @@ gst_tensor_aggregator_concat (GstTensorAggregator * self, GstBuffer * outbuf,
    ********************************************************************
    */
 
-  /* get block size */
+  /** get block size */
   block_size = tensor_element_size[info->type];
-  for (d0 = 0; d0 <= self->frames_dim; d0++) {
-    block_size *= info->dimension[d0];
+  for (f = 0; f <= self->frames_dim; f++) {
+    block_size *= info->dimension[f];
   }
 
-  /**
-   * @todo add code to concatenate data with given axis (self->frames_dim)
-   * now added one case (frames_dim 1)
-   */
-  dest_idx = 0;
-  for (d0 = 0; d0 < info->dimension[3]; d0++) {
-    for (d1 = 0; d1 < info->dimension[2]; d1++) {
-      for (f = 0; f < self->frames_out; f++) {
-        src_idx = frame_size * f;
-        src_idx += ((d0 * info->dimension[2]) + d1) * block_size;
-
-        memcpy (dest_info.data + dest_idx, src_info.data + src_idx, block_size);
-        dest_idx += block_size;
-      }
+  copied = src_idx = dest_idx = 0;
+
+  do {
+    for (f = 0; f < self->frames_out; f++) {
+      memcpy (dest_info.data + dest_idx,
+          src_info.data + src_idx + (frame_size * f), block_size);
+      dest_idx += block_size;
     }
-  }
+
+    src_idx = block_size * ++copied;
+
+    g_assert (src_idx <= frame_size);
+    g_assert (dest_idx <= dest_info.size);
+  } while (src_idx < frame_size);
 
   gst_buffer_unmap (srcbuf, &src_info);
   gst_buffer_unmap (outbuf, &dest_info);