diff mbox series

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

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

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, 8:54 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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Marton Balint Sept. 17, 2020, 7:30 a.m. UTC | #1
On Wed, 16 Sep 2020, Paul B Mahol wrote:

> This removes big CPU overhead for demuxing chained ogg streams.
>
> Signed-off-by: Paul B Mahol <onemda@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)

This does not seem right, the amount of to-be-read data in 
the buffer is (buf_end - buf_ptr), so that is the amount that is seekable 
backwards, not (buf_end - buffer = filled).

Regards,
Marton

>         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
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

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);