From 7e9cca74ce50954f991e9f4925f5258be2263a6d Mon Sep 17 00:00:00 2001 From: Hendi48 <32822533+Hendi48@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:27:17 +0200 Subject: [PATCH] ffmpegdec: Fix system freeze at end of playback with ffmpeg --- src/driver/audiodec/ffmpegdec.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/driver/audiodec/ffmpegdec.cpp b/src/driver/audiodec/ffmpegdec.cpp index 094b169fd..0c3c59f36 100644 --- a/src/driver/audiodec/ffmpegdec.cpp +++ b/src/driver/audiodec/ffmpegdec.cpp @@ -108,7 +108,15 @@ int CFfmpegDec::Read(void *buf, size_t buf_size) static int read_packet(void *opaque, uint8_t *buf, int buf_size) { +#if LIBAVFORMAT_VERSION_MAJOR < 58 return ((CFfmpegDec *) opaque)->Read(buf, (size_t) buf_size); +#else + // ffmpeg 4.0+: read_packet MUST return a valid AVERROR code instead of 0. + int len = ((CFfmpegDec *) opaque)->Read(buf, (size_t) buf_size); + if (len == 0) + return AVERROR_EOF; + return len; +#endif } int64_t CFfmpegDec::Seek(int64_t offset, int whence)