diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-17 16:07:16 +0000 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-17 16:07:16 +0000 |
commit | 26abd5149ebf9602d8036be4c6e72e08c98ea998 (patch) | |
tree | ffc931a2c7a53ff57272601f2a43dca7b799c301 /libavutil/buffer.c | |
parent | ae3c0a9c1f66367586c82e9b48d31bedac3e14aa (diff) | |
parent | 721a4efc0545548a241080b53ab480e34f366240 (diff) |
Merge commit '721a4efc0545548a241080b53ab480e34f366240'
* commit '721a4efc0545548a241080b53ab480e34f366240':
buffer: add support for pools using caller data in allocation
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavutil/buffer.c')
-rw-r--r-- | libavutil/buffer.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libavutil/buffer.c b/libavutil/buffer.c index bb112c238e..694e116a3c 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -214,6 +214,26 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) return 0; } +AVBufferPool *av_buffer_pool_init2(int size, void *opaque, + AVBufferRef* (*alloc)(void *opaque, int size), + void (*pool_free)(void *opaque)) +{ + AVBufferPool *pool = av_mallocz(sizeof(*pool)); + if (!pool) + return NULL; + + ff_mutex_init(&pool->mutex, NULL); + + pool->size = size; + pool->opaque = opaque; + pool->alloc2 = alloc; + pool->pool_free = pool_free; + + avpriv_atomic_int_set(&pool->refcount, 1); + + return pool; +} + AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)) { AVBufferPool *pool = av_mallocz(sizeof(*pool)); @@ -244,6 +264,10 @@ static void buffer_pool_free(AVBufferPool *pool) av_freep(&buf); } ff_mutex_destroy(&pool->mutex); + + if (pool->pool_free) + pool->pool_free(pool->opaque); + av_freep(&pool); } @@ -326,7 +350,8 @@ static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool) BufferPoolEntry *buf; AVBufferRef *ret; - ret = pool->alloc(pool->size); + ret = pool->alloc2 ? pool->alloc2(pool->opaque, pool->size) : + pool->alloc(pool->size); if (!ret) return NULL; |