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.
This commit is contained in:
Alexander Kernozhitsky 2022-09-01 03:40:14 +03:00 committed by John Preston
parent 9ac739c423
commit ca4b5edf21

View file

@ -482,7 +482,13 @@ FFMpegReaderImplementation::PacketResult FFMpegReaderImplementation::readAndProc
int FFMpegReaderImplementation::_read(void *opaque, uint8_t *buf, int buf_size) {
FFMpegReaderImplementation *l = reinterpret_cast<FFMpegReaderImplementation*>(opaque);
return int(l->_device->read((char*)(buf), buf_size));
FFMpegReaderImplementation *l = reinterpret_cast<FFMpegReaderImplementation*>(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) {