diff --git a/src/ui/Logic/VideoPlayers/Ffmpeg/FfmpegPlayer.cs b/src/ui/Logic/VideoPlayers/Ffmpeg/FfmpegPlayer.cs index 743191d8bc..988378b17d 100644 --- a/src/ui/Logic/VideoPlayers/Ffmpeg/FfmpegPlayer.cs +++ b/src/ui/Logic/VideoPlayers/Ffmpeg/FfmpegPlayer.cs @@ -391,13 +391,22 @@ public void Dispose() CloseFile(); } - private void Present(VideoFrame frame, VideoFrameQueue pool) + private void Present(VideoFrame frame, VideoFrameQueue pool, LoadCancellation cancellation) { VideoFrame? previous; - lock (_currentFrameLock) + lock (_loadLock) { - previous = _currentFrame; - _currentFrame = frame; + if (_disposed || cancellation.IsCancelled || !ReferenceEquals(_loadCancellation, cancellation)) + { + pool.Return(frame); + return; + } + + lock (_currentFrameLock) + { + previous = _currentFrame; + _currentFrame = frame; + } } pool.Return(previous); @@ -1779,7 +1788,7 @@ private void ShowFrame(VideoFrame frame) // Timestamp after the serial so HasPlaybackRestartedSince never sees a new // timestamp with an old serial. Interlocked.Exchange(ref _lastRestartTimestamp, Stopwatch.GetTimestamp()); - _owner.Present(frame, _videoFrames); + _owner.Present(frame, _videoFrames, _loadCancellation); } // ---------------------------------------------------------------- teardown