]> git.sesse.net Git - ffmpeg/commitdiff
fifo: add av_fifo_grow()
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 14 May 2012 17:54:36 +0000 (19:54 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 15 May 2012 16:08:32 +0000 (18:08 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavutil/avutil.h
libavutil/fifo.c
libavutil/fifo.h

index 2491264e35a828713ac3e43da443aa73d291884b..d80393beceb46d765fe1489ce44ec45e09631cde 100644 (file)
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 51
+#define LIBAVUTIL_VERSION_MINOR 52
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
index d1d9ba80033945ac0d7d76e548b2b709305f1039..47328c458542ff049545e9c41efb48426fc7f467 100644 (file)
@@ -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))
 {
index 22a9aa5d189f14f9ab668c4f16f366598b5a10f3..515f0980a7d67e62b56b6bda199305aed9af2465 100644 (file)
@@ -102,6 +102,17 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
  */
 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
 
+/**
+ * Enlarge an AVFifoBuffer.
+ * In case of reallocation failure, the old FIFO is kept unchanged.
+ * The new fifo size may be larger than the requested size.
+ *
+ * @param f AVFifoBuffer to resize
+ * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
+ * @return <0 for failure, >=0 otherwise
+ */
+int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
+
 /**
  * Read and discard the specified amount of data from an AVFifoBuffer.
  * @param f AVFifoBuffer to read from