[TTVD] Prevent TBM surface from being used for encoding when sub-rect is used 46/314646/4
authorJakub Gajownik <j.gajownik2@samsung.com>
Fri, 5 Jul 2024 15:18:43 +0000 (17:18 +0200)
committerBot Blink <blinkbot@samsung.com>
Wed, 17 Jul 2024 14:30:16 +0000 (14:30 +0000)
HW encoder does not support cropping data when it's feeded
into encoder using TBM surface. That's why we need to
disable this path when visible rect of video frame is not
equal to coded size.
Without this change, encoded frame still has proper
resolution, but video proportions are invalid.
It can happen when video is cropped to match required
contraints of camera device or application might apply
their own cropping.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-532
Change-Id: I17e26b69a9627ee1b1ae413e4fc100a64cf683ad
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
media/gpu/tizen/tizen_video_encode_accelerator_utils.cc

index 6e1ff7ecfa81003e02f85f307d6a755986fff791..6632431c9eb4b8827996ddd34edfbca22622ce47 100644 (file)
@@ -177,9 +177,29 @@ MediaPacketTuple CreateMediaPacketFromTBMSurface(
   if (!video_frame->HasGpuMemoryBuffer())
     return {};
 
+  auto gpu_memory_buffer = video_frame->GetGpuMemoryBuffer()->CloneHandle();
+
+  // Hardware encoder platform library does not apply offset given in TBM
+  // surface. We cannot encode region indicated by visible rect, so we need
+  // to fallback to other methods.
+  if (video_frame->visible_rect().size() != video_frame->coded_size()) {
+    TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE)
+        << "Visible rect size ("
+        << video_frame->visible_rect().size().ToString()
+        << ") is different than coded size "
+        << video_frame->coded_size().ToString() << ")";
+    return {};
+  }
+
+  for (const auto& plane : gpu_memory_buffer.native_pixmap_handle.planes) {
+    if (plane.offset != 0) {
+      TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE) << "Offset is non-zero";
+      return {};
+    }
+  }
+
   auto tbm_surface = gfx::TbmSurface::ImportTbmSurface(
-      video_frame->GetGpuMemoryBuffer()->CloneHandle().native_pixmap_handle,
-      video_frame->coded_size());
+      gpu_memory_buffer.native_pixmap_handle, video_frame->coded_size());
 
   if (!tbm_surface)
     return {};