FFmpeg
Functions
AVBufferPool

Functions

AVBufferPoolav_buffer_pool_init (size_t size, AVBufferRef *(*alloc)(size_t size))
 Allocate and initialize a buffer pool. More...
 
AVBufferPoolav_buffer_pool_init2 (size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
 Allocate and initialize a buffer pool with a more complex allocator. More...
 
void av_buffer_pool_uninit (AVBufferPool **pool)
 Mark the pool as being available for freeing. More...
 
AVBufferRefav_buffer_pool_get (AVBufferPool *pool)
 Allocate a new AVBuffer, reusing an old buffer from the pool when available. More...
 
void * av_buffer_pool_buffer_get_opaque (const AVBufferRef *ref)
 Query the original opaque parameter of an allocated buffer in the pool. More...
 

Detailed Description

AVBufferPool is an API for a lock-free thread-safe pool of AVBuffers.

Frequently allocating and freeing large buffers may be slow. AVBufferPool is meant to solve this in cases when the caller needs a set of buffers of the same size (the most obvious use case being buffers for raw video or audio frames).

At the beginning, the user must call av_buffer_pool_init() to create the buffer pool. Then whenever a buffer is needed, call av_buffer_pool_get() to get a reference to a new buffer, similar to av_buffer_alloc(). This new reference works in all aspects the same way as the one created by av_buffer_alloc(). However, when the last reference to this buffer is unreferenced, it is returned to the pool instead of being freed and will be reused for subsequent av_buffer_pool_get() calls.

When the caller is done with the pool and no longer needs to allocate any new buffers, av_buffer_pool_uninit() must be called to mark the pool as freeable. Once all the buffers are released, it will automatically be freed.

Allocating and releasing buffers with this API is thread-safe as long as either the default alloc callback is used, or the user-supplied one is thread-safe.

Function Documentation

◆ av_buffer_pool_init()

AVBufferPool* av_buffer_pool_init ( size_t  size,
AVBufferRef *(*)(size_t size alloc 
)

Allocate and initialize a buffer pool.

Parameters
sizesize of each buffer in this pool
alloca function that will be used to allocate new buffers when the pool is empty. May be NULL, then the default allocator will be used (av_buffer_alloc()).
Returns
newly created buffer pool on success, NULL on error.

Definition at line 280 of file buffer.c.

Referenced by buffer_pool_get(), ff_frame_pool_audio_init(), ff_frame_pool_video_init(), get_frame_buffer(), get_output_ref(), libdav1d_picture_allocator(), nvdec_init_hwframes(), qsv_decode_init_context(), and update_frame_pool().

◆ av_buffer_pool_init2()

AVBufferPool* av_buffer_pool_init2 ( size_t  size,
void *  opaque,
AVBufferRef *(*)(void *opaque, size_t size alloc,
void(*)(void *opaque)  pool_free 
)

Allocate and initialize a buffer pool with a more complex allocator.

Parameters
sizesize of each buffer in this pool
opaquearbitrary user data used by the allocator
alloca function that will be used to allocate new buffers when the pool is empty. May be NULL, then the default allocator will be used (av_buffer_alloc()).
pool_freea function that will be called immediately before the pool is freed. I.e. after av_buffer_pool_uninit() is called by the caller and all the frames are returned to the pool and freed. It is intended to uninitialize the user opaque data. May be NULL.
Returns
newly created buffer pool on success, NULL on error.

Definition at line 259 of file buffer.c.

Referenced by create_stream(), cuda_frames_init(), d3d11va_frames_init(), d3d12va_frames_init(), dxva2_init_pool(), ff_vk_get_pooled_buffer(), ff_vk_video_get_buffer(), opencl_frames_init(), qsv_init_pool(), vaapi_frames_init(), vdpau_frames_init(), vt_frames_init(), and vulkan_frames_init().

◆ av_buffer_pool_uninit()

void av_buffer_pool_uninit ( AVBufferPool **  pool)

Mark the pool as being available for freeing.

It will actually be freed only once all the allocated buffers associated with the pool are released. Thus it is safe to call this function while some of the allocated buffers are still in use.

Parameters
poolpointer to the pool to be freed. It will be set to NULL.

Definition at line 322 of file buffer.c.

Referenced by eb_enc_close(), ff_frame_pool_uninit(), ff_vk_video_common_uninit(), frame_pool_free(), get_frame_buffer(), get_output_ref(), hwframe_ctx_free(), libdav1d_close(), libdav1d_picture_allocator(), mpegts_free(), nvdec_free_dummy(), qsv_decode_close_qsvcontext(), vpx_free(), and xcbgrab_read_close().

◆ av_buffer_pool_get()

AVBufferRef* av_buffer_pool_get ( AVBufferPool pool)

◆ av_buffer_pool_buffer_get_opaque()

void* av_buffer_pool_buffer_get_opaque ( const AVBufferRef ref)

Query the original opaque parameter of an allocated buffer in the pool.

Parameters
refa buffer reference to a buffer returned by av_buffer_pool_get.
Returns
the opaque parameter set by the buffer allocator function of the buffer pool.
Note
the opaque parameter of ref is used by the buffer pool implementation, therefore you have to use this function to access the original opaque parameter of an allocated buffer.

Definition at line 411 of file buffer.c.