[FFmpeg-devel] [RFC 1/6] avutil: add av_buffer_pool_reclaim()

James Almer jamrial at gmail.com
Tue Apr 9 00:04:09 EEST 2019


On 4/8/2019 5:12 PM, Jonas Karlman wrote:
> Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
> ---
>  libavutil/buffer.c | 13 +++++++++++++
>  libavutil/buffer.h |  5 +++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/libavutil/buffer.c b/libavutil/buffer.c
> index 8d1aa5fa84..9c5d530c7a 100644
> --- a/libavutil/buffer.c
> +++ b/libavutil/buffer.c
> @@ -272,6 +272,19 @@ static void buffer_pool_free(AVBufferPool *pool)
>      av_freep(&pool);
>  }
>  
> +void av_buffer_pool_reclaim(AVBufferPool *pool)
> +{
> +    ff_mutex_lock(&pool->mutex);
> +    while (pool->pool) {
> +        BufferPoolEntry *buf = pool->pool;
> +        pool->pool = buf->next;
> +
> +        buf->free(buf->opaque, buf->data);
> +        av_freep(&buf);
> +    }
> +    ff_mutex_unlock(&pool->mutex);
> +}
> +
>  void av_buffer_pool_uninit(AVBufferPool **ppool)
>  {
>      AVBufferPool *pool;
> diff --git a/libavutil/buffer.h b/libavutil/buffer.h
> index 73b6bd0b14..fab745f853 100644
> --- a/libavutil/buffer.h
> +++ b/libavutil/buffer.h
> @@ -266,6 +266,11 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
>                                     AVBufferRef* (*alloc)(void *opaque, int size),
>                                     void (*pool_free)(void *opaque));
>  
> +/**
> + * Free all available buffers in a buffer pool.
> + */
> + void av_buffer_pool_reclaim(AVBufferPool *pool);

Maybe flush instead of reclaim? It'd be more in line with other API.

Also, you need to add an entry for the new function in doc/APIChanges,
and increase LIBAVUTIL_VERSION_MINOR by 1 in libavutil/version.h

> +
>  /**
>   * 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
> 



More information about the ffmpeg-devel mailing list