From f8196759b45d658fd67064c83e18da1cc871e205 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 14 May 2012 19:54:36 +0200 Subject: fifo: add av_fifo_grow() Signed-off-by: Michael Niedermayer --- libavutil/fifo.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libavutil/fifo.c') diff --git a/libavutil/fifo.c b/libavutil/fifo.c index d1d9ba8003..47328c4585 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -79,6 +79,19 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) return 0; } +int av_fifo_grow(AVFifoBuffer *f, unsigned int size) +{ + unsigned int old_size = f->end - f->buffer; + if(size + (unsigned)av_fifo_size(f) < size) + return AVERROR(EINVAL); + + size += av_fifo_size(f); + + if (old_size < size) + return av_fifo_realloc2(f, FFMAX(size, 2*size)); + return 0; +} + // src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter) int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)) { -- cgit v1.2.3