diff options
author | Marton Balint <cus@passwd.hu> | 2020-09-29 00:15:27 +0200 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2020-10-09 21:07:18 +0200 |
commit | 84d88154995e26ff2dea6b17893a70d309983918 (patch) | |
tree | 5372316a77f6f021c8392da6f5723995caa2ced1 /libavformat/aviobuf.c | |
parent | da74a740617be53bc83b6b952cfb9b8866ccc222 (diff) | |
download | ffmpeg-84d88154995e26ff2dea6b17893a70d309983918.tar.gz |
avformat/aviobuf: do not allocate a new buffer in ffio_ensure_seekback if not needed
Let's move unread data to the start of the old buffer instead.
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 75ddf52efc..2f1abe7d81 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1015,7 +1015,10 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size) return 0; av_assert0(!s->write_flag); - buf_size = FFMAX(buf_size, s->buffer_size); + if (buf_size <= s->buffer_size) { + update_checksum(s); + memmove(s->buffer, s->buf_ptr, filled); + } else { buffer = av_malloc(buf_size); if (!buffer) return AVERROR(ENOMEM); @@ -1024,6 +1027,7 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size) av_free(s->buffer); s->buffer = buffer; s->buffer_size = buf_size; + } s->buf_ptr = s->buffer; s->buf_end = s->buffer + filled; s->checksum_ptr = s->buffer; |