Message ID | AM3PR03MB0966ADECB40145162EF00509AC2C0@AM3PR03MB0966.eurprd03.prod.outlook.com |
---|---|
State | New |
Headers | show |
On 4/8/2019 5:12 PM, Jonas Karlman wrote: > Signed-off-by: Jonas Karlman <jonas@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 >
On 2019-04-08 23:04, James Almer wrote: > On 4/8/2019 5:12 PM, Jonas Karlman wrote: >> Signed-off-by: Jonas Karlman <jonas@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 Thanks, I will rename to av_buffer_pool_flush() and add to doc/APIChanges and fix LIBAVUTIL_VERSION_MINOR in v2. Regards, Jonas
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); + /** * 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
Signed-off-by: Jonas Karlman <jonas@kwiboo.se> --- libavutil/buffer.c | 13 +++++++++++++ libavutil/buffer.h | 5 +++++ 2 files changed, 18 insertions(+)