* commit '721a4efc0545548a241080b53ab480e34f366240': buffer: add support for pools using caller data in allocation
Unified · Split
| @@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | API changes, most recent first: | 16 | API changes, most recent first: |
| 17 | 17 | ||
| 18 | 2016-xx-xx - lavu 55.18.0 | ||
| 19 | xxxxxxx buffer.h - Add av_buffer_pool_init2(). | ||
| 20 | |||
| 18 | -------- 8< --------- FFmpeg 3.0 was cut here -------- 8< --------- | 21 | -------- 8< --------- FFmpeg 3.0 was cut here -------- 8< --------- |
| 19 | 22 | ||
| 20 | 2016-02-10 - bc9a596 / 9f61abc - lavf 57.25.100 / 57.3.0 - avformat.h | 23 | 2016-02-10 - bc9a596 / 9f61abc - lavf 57.25.100 / 57.3.0 - avformat.h |
| @@ -214,6 +214,26 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) · 213 unmodified lines | |||
| 214 | return 0; | 214 | return 0; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | AVBufferPool *av_buffer_pool_init2(int size, void *opaque, | ||
| 218 | AVBufferRef* (*alloc)(void *opaque, int size), | ||
| 219 | void (*pool_free)(void *opaque)) | ||
| 220 | { | ||
| 221 | AVBufferPool *pool = av_mallocz(sizeof(*pool)); | ||
| 222 | if (!pool) | ||
| 223 | return NULL; | ||
| 224 | |||
| 225 | ff_mutex_init(&pool->mutex, NULL); | ||
| 226 | |||
| 227 | pool->size = size; | ||
| 228 | pool->opaque = opaque; | ||
| 229 | pool->alloc2 = alloc; | ||
| 230 | pool->pool_free = pool_free; | ||
| 231 | |||
| 232 | avpriv_atomic_int_set(&pool->refcount, 1); | ||
| 233 | |||
| 234 | return pool; | ||
| 235 | } | ||
| 236 | |||
| 217 | AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)) | 237 | AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)) |
| 218 | { | 238 | { |
| 219 | AVBufferPool *pool = av_mallocz(sizeof(*pool)); | 239 | AVBufferPool *pool = av_mallocz(sizeof(*pool)); |
| @@ -244,6 +264,10 @@ static void buffer_pool_free(AVBufferPool *pool) · 24 unmodified lines | |||
| 244 | av_freep(&buf); | 264 | av_freep(&buf); |
| 245 | } | 265 | } |
| 246 | ff_mutex_destroy(&pool->mutex); | 266 | ff_mutex_destroy(&pool->mutex); |
| 267 | |||
| 268 | if (pool->pool_free) | ||
| 269 | pool->pool_free(pool->opaque); | ||
| 270 | |||
| 247 | av_freep(&pool); | 271 | av_freep(&pool); |
| 248 | } | 272 | } |
| 249 | 273 | ||
| @@ -326,7 +350,8 @@ static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool) · 76 unmodified lines | |||
| 326 | BufferPoolEntry *buf; | 350 | BufferPoolEntry *buf; |
| 327 | AVBufferRef *ret; | 351 | AVBufferRef *ret; |
| 328 | 352 | ||
| 329 | ret = pool->alloc(pool->size); | 353 | ret = pool->alloc2 ? pool->alloc2(pool->opaque, pool->size) : |
| 354 | pool->alloc(pool->size); | ||
| 330 | if (!ret) | 355 | if (!ret) |
| 331 | return NULL; | 356 | return NULL; |
| 332 | 357 | ||
| @@ -248,6 +248,23 @@ typedef struct AVBufferPool AVBufferPool; · 247 unmodified lines | |||
| 248 | */ | 248 | */ |
| 249 | AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); | 249 | AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); |
| 250 | 250 | ||
| 251 | /** | ||
| 252 | * Allocate and initialize a buffer pool with a more complex allocator. | ||
| 253 | * | ||
| 254 | * @param size size of each buffer in this pool | ||
| 255 | * @param opaque arbitrary user data used by the allocator | ||
| 256 | * @param alloc a function that will be used to allocate new buffers when the | ||
| 257 | * pool is empty. | ||
| 258 | * @param pool_free a function that will be called immediately before the pool | ||
| 259 | * is freed. I.e. after av_buffer_pool_can_uninit() is called | ||
| 260 | * by the pool and all the frames are returned to the pool and | ||
| 261 | * freed. It is intended to uninitialize the user opaque data. | ||
| 262 | * @return newly created buffer pool on success, NULL on error. | ||
| 263 | */ | ||
| 264 | AVBufferPool *av_buffer_pool_init2(int size, void *opaque, | ||
| 265 | AVBufferRef* (*alloc)(void *opaque, int size), | ||
| 266 | void (*pool_free)(void *opaque)); | ||
| 267 | |||
| 251 | /** | 268 | /** |
| 252 | * Mark the pool as being available for freeing. It will actually be freed only | 269 | * Mark the pool as being available for freeing. It will actually be freed only |
| 253 | * once all the allocated buffers associated with the pool are released. Thus it | 270 | * once all the allocated buffers associated with the pool are released. Thus it |
| @@ -90,7 +90,10 @@ struct AVBufferPool { · 89 unmodified lines | |||
| 90 | volatile int nb_allocated; | 90 | volatile int nb_allocated; |
| 91 | 91 | ||
| 92 | int size; | 92 | int size; |
| 93 | void *opaque; | ||
| 93 | AVBufferRef* (*alloc)(int size); | 94 | AVBufferRef* (*alloc)(int size); |
| 95 | AVBufferRef* (*alloc2)(void *opaque, int size); | ||
| 96 | void (*pool_free)(void *opaque); | ||
| 94 | }; | 97 | }; |
| 95 | 98 | ||
| 96 | #endif /* AVUTIL_BUFFER_INTERNAL_H */ | 99 | #endif /* AVUTIL_BUFFER_INTERNAL_H */ |
| @@ -64,8 +64,8 @@ · 63 unmodified lines | |||
| 64 | */ | 64 | */ |
| 65 | 65 | ||
| 66 | #define LIBAVUTIL_VERSION_MAJOR 55 | 66 | #define LIBAVUTIL_VERSION_MAJOR 55 |
| 67 | #define LIBAVUTIL_VERSION_MINOR 17 | 67 | #define LIBAVUTIL_VERSION_MINOR 18 |
| 68 | #define LIBAVUTIL_VERSION_MICRO 103 | 68 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 69 | 69 | ||
| 70 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 70 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |
| 71 | LIBAVUTIL_VERSION_MINOR, \ | 71 | LIBAVUTIL_VERSION_MINOR, \ |