diff mbox series

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

Message ID 20200916192118.22135-1-onemda@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avformat/aviobuf: fix broken logic in ffio_ensure_seekback() | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Paul B Mahol Sept. 16, 2020, 7:21 p.m. UTC
This removes big CPU overhead for demuxing chained ogg streams.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/aviobuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt Sept. 16, 2020, 7:30 p.m. UTC | #1
Paul B Mahol:
> This removes big CPU overhead for demuxing chained ogg streams.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavformat/aviobuf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index a77517d712..c27d564602 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -999,7 +999,7 @@ 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;
> +    buf_size += (s->buf_end - s->buf_ptr) + max_buffer_size;
>  
>      if (buf_size < filled || s->seekable || !s->read_packet)
>          return 0;
> 
Wouldn't it actually be enough to check whether buf_size < filled (which
should probably be renamed to available) without adding anything to
buf_size at all (at least not before doing the check)?
(Btw: avio_seek() does not always perform seeks within the buffer, even
when it could: It doesn't do so if the direct flag is set and if there
is a seek function; but does the existence of the latter really imply
that the stream is actually seekable?)

- Andreas
diff mbox series

Patch

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index a77517d712..c27d564602 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -999,7 +999,7 @@  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;
+    buf_size += (s->buf_end - s->buf_ptr) + max_buffer_size;
 
     if (buf_size < filled || s->seekable || !s->read_packet)
         return 0;