[FFmpeg-devel] [PATCH] fifo: add av_fifo_enlarge()
Michael Niedermayer
michaelni at gmx.at
Mon May 14 19:58:06 CEST 2012
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavutil/avutil.h | 2 +-
libavutil/fifo.c | 9 +++++++++
libavutil/fifo.h | 11 +++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 2491264..d80393b 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -153,7 +153,7 @@
*/
#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, \
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index d1d9ba8..75bdfb9 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -79,6 +79,15 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
return 0;
}
+int av_fifo_enlarge(AVFifoBuffer *f, unsigned int new_size)
+{
+ unsigned int old_size = f->end - f->buffer;
+
+ if (old_size < new_size)
+ return av_fifo_realloc2(f, FFMAX(new_size, 2*new_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))
{
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index 22a9aa5..8bd924c 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -103,6 +103,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 size new AVFifoBuffer size in bytes
+ * @return <0 for failure, >=0 otherwise
+ */
+int av_fifo_enlarge(AVFifoBuffer *f, unsigned int new_size);
+
+/**
* Read and discard the specified amount of data from an AVFifoBuffer.
* @param f AVFifoBuffer to read from
* @param size amount of data to read in bytes
--
1.7.9.5
More information about the ffmpeg-devel
mailing list