summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorLukasz Marek <lukasz.m.luki2@gmail.com>2014-05-10 08:06:53 +0200
committerLukasz Marek <lukasz.m.luki2@gmail.com>2014-05-20 00:00:44 +0200
commit7336e39f3cd2833786b0ebcca5604e13d2f86500 (patch)
treeea7365b22575f5a411f6ec1f1351adcfade2f1cd /libavutil
parentd43c303038e9bd9c7d1856234d81e6fc5b410c3f (diff)
lavu/fifo: add av_fifo_alloc_array function
Allows to alloc fifo buffer by passing number of elements and size of element. Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/fifo.c27
-rw-r--r--libavutil/fifo.h8
-rw-r--r--libavutil/version.h2
3 files changed, 30 insertions, 7 deletions
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 09ffa4fd26..77391ee7f2 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -24,19 +24,34 @@
#include "common.h"
#include "fifo.h"
-AVFifoBuffer *av_fifo_alloc(unsigned int size)
+static AVFifoBuffer *fifo_alloc_common(void *buffer, size_t size)
{
- AVFifoBuffer *f = av_mallocz(sizeof(AVFifoBuffer));
- if (!f)
+ AVFifoBuffer *f;
+ if (!buffer)
+ return NULL;
+ f = av_mallocz(sizeof(AVFifoBuffer));
+ if (!f) {
+ av_free(buffer);
return NULL;
- f->buffer = av_malloc(size);
+ }
+ f->buffer = buffer;
f->end = f->buffer + size;
av_fifo_reset(f);
- if (!f->buffer)
- av_freep(&f);
return f;
}
+AVFifoBuffer *av_fifo_alloc(unsigned int size)
+{
+ void *buffer = av_malloc(size);
+ return fifo_alloc_common(buffer, size);
+}
+
+AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size)
+{
+ void *buffer = av_malloc_array(nmemb, size);
+ return fifo_alloc_common(buffer, nmemb * size);
+}
+
void av_fifo_free(AVFifoBuffer *f)
{
if (f) {
diff --git a/libavutil/fifo.h b/libavutil/fifo.h
index f0b11094d0..dda7dd2e96 100644
--- a/libavutil/fifo.h
+++ b/libavutil/fifo.h
@@ -42,6 +42,14 @@ typedef struct AVFifoBuffer {
AVFifoBuffer *av_fifo_alloc(unsigned int size);
/**
+ * Initialize an AVFifoBuffer.
+ * @param nmemb number of elements
+ * @param size size of the single element
+ * @return AVFifoBuffer or NULL in case of memory allocation failure
+ */
+AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size);
+
+/**
* Free an AVFifoBuffer.
* @param f AVFifoBuffer to free
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index 9eeba9abd9..b134615a5b 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 85
+#define LIBAVUTIL_VERSION_MINOR 86
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \