[FFmpeg-devel] [PATCH] avformat/aviobuf: fix broken logic in ffio_ensure_seekback()

Paul B Mahol onemda at gmail.com
Wed Sep 16 23:54:14 EEST 2020


This removes big CPU overhead for demuxing chained ogg streams.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/aviobuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index a77517d712..9dfef2377e 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -999,10 +999,10 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
     int filled = s->buf_end - s->buffer;
     ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
 
-    buf_size += s->buf_ptr - s->buffer + max_buffer_size;
-
     if (buf_size < filled || s->seekable || !s->read_packet)
         return 0;
+    buf_size += s->buf_end - s->buf_ptr + max_buffer_size;
+
     av_assert0(!s->write_flag);
 
     buffer = av_malloc(buf_size);
-- 
2.17.1



More information about the ffmpeg-devel mailing list