Send copied memory when GetDecodedPacket 33/297633/3 accepted/tizen/unified/20230823.021344
authorEunhye Choi <eunhae1.choi@samsung.com>
Tue, 22 Aug 2023 06:23:17 +0000 (15:23 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Tue, 22 Aug 2023 07:05:50 +0000 (16:05 +0900)
- send copied memory instead of sending reference of
  decoding buffer directly
- if app does not return decoding buffer,
  it can cause video decoding error

[Version] 0.0.31

Change-Id: I08db60d842841f74a259c2c2ab925e4065357de4

packaging/libtrackrenderer.spec
src/trackrenderer.cpp

index 4ff7d47fea68dd5a28c92a53307c67c6100b2b3f..b63de23bc9c6c3664735f5c539e8854f4364a926 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libtrackrenderer
 Summary:    new multimedia streaming player trackrenderer
-Version:    0.0.30
+Version:    0.0.31
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index f0823a111c03968948fe8aae7565fbdd350fa367..611887655dfeb109fe94eb23fb13acc281630bc1 100644 (file)
@@ -352,6 +352,43 @@ tbm_surface_h CreateTbmSurfaceWithBuffer(GstMemory* mem, GstCaps* caps) {
   return tbm_surf;
 }
 
+tbm_surface_h CopyTbmSurface(tbm_surface_h tsurf_origin) {
+
+  TRACKRENDERER_ENTER;
+
+  if (!tsurf_origin) {
+    TRACKRENDERER_ERROR("tsurf_origin is null");
+    return nullptr;
+  }
+
+  tbm_surface_info_s info;
+  int ret = tbm_surface_get_info(tsurf_origin, &info);
+  if (ret != TBM_SURFACE_ERROR_NONE) {
+    TRACKRENDERER_ERROR("failed to get tbm surface info");
+    return nullptr;
+  }
+
+  tbm_surface_h tsurf_copy =
+      tbm_surface_create(info.width, info.height, info.format);
+  if (!tsurf_copy) {
+    TRACKRENDERER_ERROR("failed to create tbm surface");
+    return nullptr;
+  }
+
+  tbm_surface_info_s info_copy;
+  ret = tbm_surface_get_info(tsurf_copy, &info_copy);
+  if (ret != TBM_SURFACE_ERROR_NONE) {
+    TRACKRENDERER_ERROR("failed to get tbm surface info");
+    tbm_surface_destroy(tsurf_copy);
+    return nullptr;
+  }
+
+  for (int i = 0; i < (int)info.num_planes; i++)
+    memcpy(info_copy.planes[i].ptr, info.planes[i].ptr, info.planes[i].size);
+
+  return tsurf_copy;
+}
+
 #ifdef __DEBUG__
 void DumpVideoFrame(tbm_surface_h tbm_surf) {
   static int cnt = 0;
@@ -515,7 +552,7 @@ void TrackRenderer::SetVideoQualityInfo_() {
   gst_caps_set_simple(new_caps_guard.get(), "maxwidth", G_TYPE_INT, max_w,
                       "maxheight", G_TYPE_INT, max_h, NULL);
 
-  TRACKRENDERER_INFO("max widh [%d], max height [%d]", max_w, max_h);
+  TRACKRENDERER_INFO("max width [%d], max height [%d]", max_w, max_h);
   display_->SetDisplayQualityInfo(new_caps_guard.get());
 }
 
@@ -550,7 +587,7 @@ bool TrackRenderer::Prepare() {
 
   if (internal::IsUhd8kResolution(max_width, max_height)) {
     constexpr uint32_t kAdaptiveStreaming8kMode =
-        0x80;  // refer to waylandsink properity value.
+        0x80;  // refer to waylandsink property value.
     TRACKRENDERER_INFO("Set 8K Video quality mode : 0x80");
     display_->SetVideoQualityMode(kAdaptiveStreaming8kMode);
   }
@@ -2521,7 +2558,7 @@ void TrackRenderer::SetVolume_() {
   if (strstr(sink_name, "pulsesink")) {
     pipeline_->SetProperty(Elements::kSinkAudio, "volume", (volume_/100.0));
   } else {
-    TRACKRENDERER_WARN("unknow audio sink name: %s", sink_name);
+    TRACKRENDERER_WARN("unknown audio sink name: %s", sink_name);
   }
 }
 
@@ -2928,19 +2965,16 @@ GetDecodedVideoFrameState TrackRenderer::GetDecodedPacket(
   tbm_surface_h tbm_surf;
 
   if (gst_is_tizen_memory(mem)) {
-    tbm_surf = static_cast<tbm_surface_h>(gst_tizen_memory_get_surface(mem));
-    packet.buffer_addr = gst_buffer_ref(buffer);
+    tbm_surf = internal::CopyTbmSurface(static_cast<tbm_surface_h>(gst_tizen_memory_get_surface(mem)));
   } else {
     auto caps = gstguard::make_guard(pipeline_->GetSinkPadCaps(Elements::kSinkVideo));
     tbm_surf = internal::CreateTbmSurfaceWithBuffer(mem, caps.get());
-    packet.buffer_addr = nullptr;
   }
+  packet.buffer_addr = nullptr;
 
   if (!tbm_surf) {
     gst_sample_unref(sample);
-    TRACKRENDERER_ERROR("failed to get tbm surface");
-    if (packet.buffer_addr)
-      gst_buffer_unref(buffer);
+    TRACKRENDERER_ERROR("failed to create tbm surface");
     return GetDecodedVideoFrameState::kUnknownError;
   }
 
@@ -2952,17 +2986,16 @@ GetDecodedVideoFrameState TrackRenderer::GetDecodedPacket(
   packet.surface_data = tbm_surf;
   gst_sample_unref(sample);
 
+  TRACKRENDERER_DEBUG("packet.surface_data [%p] is created", packet.surface_data);
+
   return GetDecodedVideoFrameState::kErrorNone;
 }
 
 bool TrackRenderer::ReturnDecodedPacket(const DecodedVideoPacket& packet) {
   if (packet.surface_data == nullptr) return false;
-  TRACKRENDERER_DEBUG("packet.surface_data [%p] will be deleted", packet.surface_data);
 
-  if (packet.buffer_addr) // hw dec
-    gst_buffer_unref(GST_BUFFER_CAST(packet.buffer_addr));
-  else
-    tbm_surface_destroy(static_cast<tbm_surface_h>(packet.surface_data));
+  TRACKRENDERER_DEBUG("packet.surface_data [%p] will be deleted", packet.surface_data);
+  tbm_surface_destroy(static_cast<tbm_surface_h>(packet.surface_data));
 
   return true;
 }