[TTVD] Fix order of decoder releasing and removing dependents 16/315616/3
authorJakub Gajownik <j.gajownik2@samsung.com>
Fri, 2 Aug 2024 13:50:11 +0000 (15:50 +0200)
committerj.gajownik2 <j.gajownik2@samsung.com>
Mon, 5 Aug 2024 08:47:48 +0000 (10:47 +0200)
[Problem]
It was possible that decoder is released during switching to
partial view while still trying to render decoded frames.
All the dependents video frame should not try accesing data
given by platform decoder since it's already released. But
there was a race between decoder (notify data should not be
longer used) and GPU thread (notification about switching to
texture mode).

The result was segmentation fault when GPU thread tried to
access already unmapped data.

[Solution]
Fix ordering of operations to wait with decoder release
after GPU thread objects are notified they should not use
data from decoder.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-546
Change-Id: I40aecdceed169ec091a886c9b4f17c2b874428c5
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
media/filters/tizen/ttvd_video_decoder_impl.cc

index a5a5d0f19b808423583985f9a2e6e3b2d69e092e..3a294cf2d0f046ca4ce232af60185bb9342cfc8b 100644 (file)
@@ -796,6 +796,11 @@ void TTvdVideoDecoderImpl::ResourceConflict(
   }
 
   TIZEN_MEDIA_LOG(ERROR) << "Resource conflict, release decoder";
+
+  // As we'll release decoder, we need to take care of pictures
+  // that has reference to decoder allocated memory.
+  RemoveDecoderDependentResults();
+
   decoder_state_ = DecoderState::kResourceTaken;
   decoder_facade_.reset();
 
@@ -808,9 +813,6 @@ void TTvdVideoDecoderImpl::ResourceConflict(
 
   std::move(token_provider).Run(std::move(allocated_decoder_));
 
-  // Decoder is release, ensure that won't access decoder mapped data
-  // after releasing.
-  RemoveDecoderDependentResults();
 
   // Mark failure of any pending decodes. `kKeyFrameRequired` is used
   // to mark such situation in other places (see `Decode()`).
@@ -920,12 +922,13 @@ void TTvdVideoDecoderImpl::ReleaseResources() {
     // reinitialization is seamless decoder switch is not possible.
     decoder_state_ = DecoderState::kResourceTaken;
   }
-  decoder_facade_.reset();
-  allocated_decoder_.reset();
 
-  // Decoder is released, ensure that won't access decoder mapped data
-  // after releasing.
+  // As we'll release decoder, we need to take care of pictures
+  // that has reference to decoder allocated memory.
   RemoveDecoderDependentResults();
+
+  decoder_facade_.reset();
+  allocated_decoder_.reset();
 }
 
 bool TTvdVideoDecoderImpl::AllocateDecoder() {