Browse code

fifo: add av_fifo_grow()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/05/15 02:54:36
Showing 3 changed files
... ...
@@ -153,7 +153,7 @@
153 153
  */
154 154
 
155 155
 #define LIBAVUTIL_VERSION_MAJOR 51
156
-#define LIBAVUTIL_VERSION_MINOR 51
156
+#define LIBAVUTIL_VERSION_MINOR 52
157 157
 #define LIBAVUTIL_VERSION_MICRO 100
158 158
 
159 159
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
... ...
@@ -79,6 +79,19 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
79 79
     return 0;
80 80
 }
81 81
 
82
+int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
83
+{
84
+    unsigned int old_size = f->end - f->buffer;
85
+    if(size + (unsigned)av_fifo_size(f) < size)
86
+        return AVERROR(EINVAL);
87
+
88
+    size += av_fifo_size(f);
89
+
90
+    if (old_size < size)
91
+        return av_fifo_realloc2(f, FFMAX(size, 2*size));
92
+    return 0;
93
+}
94
+
82 95
 // src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)
83 96
 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
84 97
 {
... ...
@@ -103,6 +103,17 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
103 103
 int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
104 104
 
105 105
 /**
106
+ * Enlarge an AVFifoBuffer.
107
+ * In case of reallocation failure, the old FIFO is kept unchanged.
108
+ * The new fifo size may be larger than the requested size.
109
+ *
110
+ * @param f AVFifoBuffer to resize
111
+ * @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
112
+ * @return <0 for failure, >=0 otherwise
113
+ */
114
+int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
115
+
116
+/**
106 117
  * Read and discard the specified amount of data from an AVFifoBuffer.
107 118
  * @param f AVFifoBuffer to read from
108 119
  * @param size amount of data to read in bytes