[FFmpeg-cvslog] avformat/aviobuf: do not allocate a new buffer in ffio_ensure_seekback if not needed

Marton Balint git at videolan.org
Fri Oct 9 22:25:27 EEST 2020


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Tue Sep 29 00:15:27 2020 +0200| [84d88154995e26ff2dea6b17893a70d309983918] | committer: Marton Balint

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 at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=84d88154995e26ff2dea6b17893a70d309983918
---

 libavformat/aviobuf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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;



More information about the ffmpeg-cvslog mailing list