[FFmpeg-devel] [PATCH] avformat/aviobuf: fix broken logic in ffio_ensure_seekback()
Paul B Mahol
onemda at gmail.com
Fri Sep 18 00:32:36 EEST 2020
On Thu, Sep 17, 2020 at 09:44:52PM +0200, Marton Balint wrote:
>
>
> On Thu, 17 Sep 2020, Paul B Mahol wrote:
>
> > This removes big CPU overhead for demuxing chained ogg streams.
> >
> > Signed-off-by: Paul B Mahol <onemda at gmail.com>
> > ---
> > libavformat/aviobuf.c | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index a77517d712..ce9b7d59c9 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -996,20 +996,20 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
> > uint8_t *buffer;
> > int max_buffer_size = s->max_packet_size ?
> > s->max_packet_size : IO_BUFFER_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)
> > + if (buf_size <= s->buffer_size || s->seekable || !s->read_packet)
> > return 0;
>
> This is still not correct. You can only return if
> buf_size <= s->buf_end - s->buf_ptr
That one gives you original issue.
> OR
> buf_size <= s->buffer + s->buffer_size - s->buf_ptr - max_buffer_size + 1
>
That one gives you also original issue but at slower peace.
> And the new minimum buffer size is what is calculated now, so that should
> not be changed.
>
> I am not sure if this fixes you original issue. It might make sense to
> allocate max_buffer_size*2 length buffers by default, but the buffer size
> revert logic must be fixed to support that...
>
> Regards,
> Marton
>
>
>
> > + buf_size += s->buffer_size;
> > + buf_size = FFMAX(buf_size, max_buffer_size);
> > +
> > av_assert0(!s->write_flag);
> >
> > buffer = av_malloc(buf_size);
> > if (!buffer)
> > return AVERROR(ENOMEM);
> >
> > - memcpy(buffer, s->buffer, filled);
> > + memcpy(buffer, s->buffer, s->buffer_size);
> > av_free(s->buffer);
> > s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
> > s->buf_end = buffer + (s->buf_end - s->buffer);
> > --
> > 2.17.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list