History

Merge commit '721a4efc0545548a241080b53ab480e34f366240'

* commit '721a4efc0545548a241080b53ab480e34f366240': buffer: add support for pools using caller data in allocation

Derek Buitenhuis committed 10 years ago

Commit 26abd512 parents ae3c0a9 721a4ef5 files · +51 −3Browse files

Unified · Split

5 files
  1. doc/APIchanges +3 −0
  2. libavutil/buffer.c +26 −1
  3. libavutil/buffer.h +17 −0
  4. libavutil/buffer_internal.h +3 −0
  5. libavutil/version.h +2 −2
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2016-xx-xx - lavu 55.18.0
19+ xxxxxxx buffer.h - Add av_buffer_pool_init2().
20+
1821 -------- 8< --------- FFmpeg 3.0 was cut here -------- 8< ---------
1922
2023 2016-02-10 - bc9a596 / 9f61abc - lavf 57.25.100 / 57.3.0 - avformat.h
libavutil/buffer.c+26−1
@@ -214,6 +214,26 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) · 213 unmodified lines
214214 return 0;
215215 }
216216
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+
217237 AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
218238 {
219239 AVBufferPool *pool = av_mallocz(sizeof(*pool));
@@ -244,6 +264,10 @@ static void buffer_pool_free(AVBufferPool *pool) · 24 unmodified lines
244264 av_freep(&buf);
245265 }
246266 ff_mutex_destroy(&pool->mutex);
267+
268+ if (pool->pool_free)
269+ pool->pool_free(pool->opaque);
270+
247271 av_freep(&pool);
248272 }
249273
@@ -326,7 +350,8 @@ static AVBufferRef *pool_alloc_buffer(AVBufferPool *pool) · 76 unmodified lines
326350 BufferPoolEntry *buf;
327351 AVBufferRef *ret;
328352
329− ret = pool->alloc(pool->size);
353+ ret = pool->alloc2 ? pool->alloc2(pool->opaque, pool->size) :
354+ pool->alloc(pool->size);
330355 if (!ret)
331356 return NULL;
332357
libavutil/buffer.h+17−0
@@ -248,6 +248,23 @@ typedef struct AVBufferPool AVBufferPool; · 247 unmodified lines
248248 */
249249 AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
250250
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+
251268 /**
252269 * Mark the pool as being available for freeing. It will actually be freed only
253270 * once all the allocated buffers associated with the pool are released. Thus it
libavutil/buffer_internal.h+3−0
@@ -90,7 +90,10 @@ struct AVBufferPool { · 89 unmodified lines
9090 volatile int nb_allocated;
9191
9292 int size;
93+ void *opaque;
9394 AVBufferRef* (*alloc)(int size);
95+ AVBufferRef* (*alloc2)(void *opaque, int size);
96+ void (*pool_free)(void *opaque);
9497 };
9598
9699 #endif /* AVUTIL_BUFFER_INTERNAL_H */
libavutil/version.h+2−2
@@ -64,8 +64,8 @@ · 63 unmodified lines
6464 */
6565
6666 #define LIBAVUTIL_VERSION_MAJOR 55
67−#define LIBAVUTIL_VERSION_MINOR 17
68−#define LIBAVUTIL_VERSION_MICRO 103
67+#define LIBAVUTIL_VERSION_MINOR 18
68+#define LIBAVUTIL_VERSION_MICRO 100
6969
7070 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
7171 LIBAVUTIL_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t