[FFmpeg-devel] [PATCH 2/5] lavf/demux: treat EAGAIN as REDO unless AVFMT_FLAG_NONBLOCK is set

Anton Khirnov anton at khirnov.net
Tue Nov 8 13:25:47 EET 2022


Lavf only supports a very limited approximation of non-blocking
behavior, so we should not return random EAGAINs to callers unless they
specifically requested it.
---
 libavformat/demux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..5cd9522367 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -574,8 +574,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
             /* Some demuxers return FFERROR_REDO when they consume
                data and discard it (ignored streams, junk, extradata).
-               We must re-call the demuxer to get the real packet. */
-            if (err == FFERROR_REDO)
+               We must re-call the demuxer to get the real packet.
+
+               Treat EAGAIN the same as FFERROR_REDO, unless the user
+               requested non-blocking behavior. */
+            if (err == FFERROR_REDO ||
+                (err == AVERROR(EAGAIN) && !(s->flags & AVFMT_FLAG_NONBLOCK)))
                 continue;
             if (!pktl || err == AVERROR(EAGAIN))
                 return err;
-- 
2.35.1



More information about the ffmpeg-devel mailing list