diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-06-30 20:18:13 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-07-04 21:13:38 +0400 |
commit | 186ec1784336df11df48e646595e2ec646f82329 (patch) | |
tree | 517c54149f39834c172b7d00369002755a5fedc8 /libavformat/aviobuf.c | |
parent | 2ca48e466675a8a3630061cd2c15325eab8eda97 (diff) |
avformat/aviobuf: Add ffio_ensure_seekback()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 790c26155f..93a187b4aa 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -725,6 +725,31 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) return 0; } +int ffio_ensure_seekback(AVIOContext *s, int buf_size) +{ + uint8_t *buffer; + int max_buffer_size = s->max_packet_size ? + s->max_packet_size : IO_BUFFER_SIZE; + + buf_size += s->buf_ptr - s->buffer + max_buffer_size; + + if (buf_size < s->buffer_size || s->seekable) + return 0; + av_assert0(!s->write_flag); + + buffer = av_malloc(buf_size); + if (!buffer) + return AVERROR(ENOMEM); + + 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); + s->buffer = buffer; + s->buffer_size = buf_size; + return 0; +} + int ffio_set_buf_size(AVIOContext *s, int buf_size) { uint8_t *buffer; |