From ca4b5edf217f63048d435a9b783b56201c6ff5bb Mon Sep 17 00:00:00 2001 From: Alexander Kernozhitsky Date: Thu, 1 Sep 2022 03:40:14 +0300 Subject: [PATCH] Correct FFmpeg API usage FFmpeg docs say that you must return AVERROR_EOF from the read callback, not zero. Still, Telegram just propagates the return value from IODevice::read() call, which returns zero in case of EOF. I don't know whether this commit has any effect on the upstream build, but it fixes a bug in Debian build of Telegram, which is using FFmpeg 5.1 instead of 4.4. Still, it's also useful in the upstream, as it makes work with FFmpeg more correct. --- Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp b/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp index cee45b923..619ff9b28 100644 --- a/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp +++ b/Telegram/SourceFiles/media/clip/media_clip_ffmpeg.cpp @@ -482,7 +482,13 @@ FFMpegReaderImplementation::PacketResult FFMpegReaderImplementation::readAndProc int FFMpegReaderImplementation::_read(void *opaque, uint8_t *buf, int buf_size) { FFMpegReaderImplementation *l = reinterpret_cast(opaque); - return int(l->_device->read((char*)(buf), buf_size)); + FFMpegReaderImplementation *l = reinterpret_cast(opaque); + int ret = l->_device->read((char*)(buf), buf_size); + switch (ret) { + case -1: return AVERROR_EXTERNAL; + case 0: return AVERROR_EOF; + default: return ret; + } } int64_t FFMpegReaderImplementation::_seek(void *opaque, int64_t offset, int whence) {