From baf065b789af08685b6e7571132342f459f50652 Mon Sep 17 00:00:00 2001
From: Nils Hasenbanck <nils@hasenbanck.de>
Date: Tue, 4 Feb 2020 21:29:35 +0100
Subject: [PATCH] Fix crash on seeking when using HW decoding in some cases.

This fix makes sure that we don't de-allocate the video buffer before
while the decoding thread is still working. We also don't throw
an misleading error when the decoding threads flushed the buffers
on seeking.
---
 cores/libretro-ffmpeg/ffmpeg_core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/cores/libretro-ffmpeg/ffmpeg_core.c b/cores/libretro-ffmpeg/ffmpeg_core.c
index d2483be851..ec9dd35306 100644
--- a/cores/libretro-ffmpeg/ffmpeg_core.c
+++ b/cores/libretro-ffmpeg/ffmpeg_core.c
@@ -497,9 +497,6 @@ static void seek_frame(int seek_frames)
    }
    audio_frames = frame_cnt * media.sample_rate / media.interpolate_fps;
 
-   tpool_wait(tpool);
-   video_buffer_clear(video_buffer);
-
    if (audio_decode_fifo)
       fifo_clear(audio_decode_fifo);
    scond_signal(fifo_decode_cond);
@@ -512,7 +509,6 @@ static void seek_frame(int seek_frames)
    }
 
    slock_unlock(fifo_lock);
-
 }
 
 void CORE_PREFIX(retro_run)(void)
@@ -1363,7 +1359,8 @@ static void decode_video(AVCodecContext *ctx, AVPacket *pkt, size_t frame_size)
    {
       if (main_sleeping)
       {
-         log_cb(RETRO_LOG_ERROR, "[FFMPEG] Thread: Video deadlock detected.\n");
+         if (!do_seek)
+            log_cb(RETRO_LOG_ERROR, "[FFMPEG] Thread: Video deadlock detected.\n");
          tpool_wait(tpool);
          video_buffer_clear(video_buffer);
          return;