From 2dcf1f7ed2601672e4081b6318334968fd7a9b68 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 17 Sep 2024 20:56:04 +0200 Subject: [PATCH] Don't break the read_packet contract --- extern/osg-ffmpeg-videoplayer/videostate.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index 61e4f09cf3..158336784e 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -236,11 +236,17 @@ int VideoState::istream_read(void *user_data, uint8_t *buf, int buf_size) std::istream& stream = *static_cast(user_data)->stream; stream.clear(); stream.read((char*)buf, buf_size); - return stream.gcount(); + if (stream.bad()) + return AVERROR_UNKNOWN; + auto count = stream.gcount(); + // avio_alloc_context says we mustn't return 0 for stream protocols + if (!count) + return AVERROR_EOF; + return count; } catch (std::exception& ) { - return 0; + return AVERROR_UNKNOWN; } }