FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
AVBufferPool

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

Functions

AVBufferPoolav_buffer_pool_init (int size, AVBufferRef *(*alloc)(int size))
 Allocate and initialize a buffer pool. More...
 
AVBufferPoolav_buffer_pool_init2 (int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int 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...
 

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

AVBufferPool* av_buffer_pool_init ( int  size,
AVBufferRef *(*)(int 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 238 of file buffer.c.

Referenced by ff_frame_pool_audio_init(), ff_frame_pool_video_init(), init_table_pools(), pic_arrays_init(), and update_frame_pool().

AVBufferPool* av_buffer_pool_init2 ( int  size,
void opaque,
AVBufferRef *(*)(void *opaque, int 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.
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.
Returns
newly created buffer pool on success, NULL on error.

Definition at line 218 of file buffer.c.

Referenced by cuda_frames_init(), d3d11va_frames_init(), dxva2_init_pool(), ff_nvdec_decode_init(), ff_vaapi_encode_init(), opencl_frames_init(), qsv_init_pool(), vaapi_frames_init(), and vdpau_frames_init().

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 275 of file buffer.c.

Referenced by avcodec_close(), ff_frame_pool_uninit(), ff_h264_free_tables(), ff_nvdec_decode_uninit(), ff_vaapi_encode_close(), hwframe_ctx_free(), init_table_pools(), pic_arrays_free(), and update_frame_pool().

AVBufferRef* av_buffer_pool_get ( AVBufferPool pool)

Allocate a new AVBuffer, reusing an old buffer from the pool when available.

This function may be called simultaneously from multiple threads.

Returns
a reference to the new buffer on success, NULL on error.

Definition at line 334 of file buffer.c.

Referenced by alloc_frame(), alloc_picture(), audio_get_buffer(), cuda_get_buffer(), d3d11va_get_buffer(), drm_get_buffer(), dxva2_get_buffer(), ff_frame_pool_get(), ff_nvdec_start_frame(), opencl_get_buffer(), qsv_get_buffer(), vaapi_encode_issue(), vaapi_frames_init(), vaapi_get_buffer(), vdpau_get_buffer(), video_get_buffer(), and vt_get_buffer().