[FFmpeg-devel] [PATCH] avutil/buffer: add a dynamic size buffer pool API

James Almer jamrial at gmail.com
Fri Apr 6 18:05:10 EEST 2018


On 3/28/2018 10:42 AM, James Almer wrote:
> On 3/28/2018 6:59 AM, wm4 wrote:
>> On Tue, 27 Mar 2018 23:11:27 -0300
>> James Almer <jamrial at gmail.com> wrote:
>>
>>> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
>>> index 73b6bd0b14..d06b301fe5 100644
>>> --- a/libavutil/buffer.h
>>> +++ b/libavutil/buffer.h
>>> @@ -284,6 +284,59 @@ void av_buffer_pool_uninit(AVBufferPool **pool);
>>>   */
>>>  AVBufferRef *av_buffer_pool_get(AVBufferPool *pool);
>>>  
>>> +/**
>>> + * @}
>>> + */
>>> +
>>> +/**
>>> + * @defgroup lavu_bufferdynpool AVBufferDynPool
>>> + * @ingroup lavu_data
>>> + *
>>> + * @{
>>> + * AVBufferDynPool is an API for a lock-free thread-safe pool of AVBuffers.
>>> + *
>>> + * Unlike AVBufferPool, AVBufferDynPool allows the user to request buffers
>>> + * of any arbitrary size. It is functionally the same otherwise.
>>> + */
>>> +
>>> +/**
>>> + * The buffer pool. This structure is opaque and not meant to be accessed
>>> + * directly. It is allocated with av_buffer_dyn_pool_init() and freed with
>>> + * av_buffer_dyn_pool_uninit().
>>> + */
>>> +typedef struct AVBufferDynPool AVBufferDynPool;
>>> +
>>> +/**
>>> + * Allocate and initialize a buffer pool.
>>> + *
>>> + * @param alloc a 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()).
>>> + * @return newly created buffer pool on success, NULL on error.
>>> + */
>>> +AVBufferDynPool *av_buffer_dyn_pool_init(AVBufferRef* (*alloc)(int size));
>>
>> No custom free pool free function like the fixed buffer API? (Not sure if neded.)
> 
> That's only in the second, more "complex" kind of pool alloc, when you
> need to pass an opaque pointer to both the alloc and free buffer
> functions. It was added afaik for some hwaccel stuff, like vaapi encoder.
> 
> It can be added later if needed, as another init2() for this new API,
> but I'd rather not make it the default and only init function here as it
> wouldn't allow the caller to use the standard signature functions like
> av_buffer_alloc() as callback, forcing them to come up with custom
> wrappers even if they need a simple pool.

If there are no other comments, I'd like to push this soon.


More information about the ffmpeg-devel mailing list