Skip to content

Commit

Permalink
DEBUG: log buffer pool get and release
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwiboo committed Dec 3, 2018
1 parent 3fc8243 commit 42e3ab0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libavcodec/v4l2_request.c
Expand Up @@ -545,6 +545,16 @@ static void v4l2_request_pool_free(void *opaque)
av_log(NULL, AV_LOG_DEBUG, "%s: opaque=%p\n", __func__, opaque);
}

static void v4l2_request_frame_get(void *opaque, void *data)
{
av_log(NULL, AV_LOG_DEBUG, "%s: opaque=%p data=%p\n", __func__, opaque, data);
}

static void v4l2_request_frame_release(void *opaque, void *data)
{
av_log(NULL, AV_LOG_DEBUG, "%s: opaque=%p data=%p\n", __func__, opaque, data);
}

static void v4l2_request_hwframe_ctx_free(AVHWFramesContext *hwfc)
{
av_log(NULL, AV_LOG_DEBUG, "%s: hwfc=%p pool=%p\n", __func__, hwfc, hwfc->pool);
Expand All @@ -563,7 +573,7 @@ int ff_v4l2_request_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_c
hwfc->width = ctx->format.fmt.pix.width;
hwfc->height = ctx->format.fmt.pix.height;

hwfc->pool = av_buffer_pool_init2(sizeof(V4L2RequestDescriptor), avctx, v4l2_request_frame_alloc, v4l2_request_pool_free);
hwfc->pool = av_buffer_pool_init3(sizeof(V4L2RequestDescriptor), avctx, v4l2_request_frame_alloc, v4l2_request_frame_get, v4l2_request_frame_release, v4l2_request_pool_free);
if (!hwfc->pool)
return AVERROR(ENOMEM);

Expand Down
31 changes: 31 additions & 0 deletions libavutil/buffer.c
Expand Up @@ -235,6 +235,31 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
return pool;
}

AVBufferPool *av_buffer_pool_init3(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size),
void (*get)(void *opaque, void *data),
void (*release)(void *opaque, void *data),
void (*pool_free)(void *opaque))
{
AVBufferPool *pool = av_mallocz(sizeof(*pool));
if (!pool)
return NULL;

ff_mutex_init(&pool->mutex, NULL);

pool->size = size;
pool->opaque = opaque;
pool->alloc2 = alloc;
pool->pool_free = pool_free;

pool->get = get;
pool->release = release;

atomic_init(&pool->refcount, 1);

return pool;
}

AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size))
{
AVBufferPool *pool = av_mallocz(sizeof(*pool));
Expand Down Expand Up @@ -303,6 +328,9 @@ static void pool_release_buffer(void *opaque, uint8_t *data)
BufferPoolEntry *buf = opaque;
AVBufferPool *pool = buf->pool;

if (pool->release)
pool->release(pool->opaque, buf->data);

if(CONFIG_MEMORY_POISONING)
memset(buf->data, FF_MEMORY_POISON, pool->size);

Expand Down Expand Up @@ -366,5 +394,8 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool)
if (ret)
atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed);

if (pool->get)
pool->get(pool->opaque, ret->data);

return ret;
}
6 changes: 6 additions & 0 deletions libavutil/buffer.h
Expand Up @@ -266,6 +266,12 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size),
void (*pool_free)(void *opaque));

AVBufferPool *av_buffer_pool_init3(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size),
void (*get)(void *opaque, void *data),
void (*release)(void *opaque, void *data),
void (*pool_free)(void *opaque));

/**
* Free all available buffers in a buffer pool.
*/
Expand Down
3 changes: 3 additions & 0 deletions libavutil/buffer_internal.h
Expand Up @@ -93,6 +93,9 @@ struct AVBufferPool {
AVBufferRef* (*alloc)(int size);
AVBufferRef* (*alloc2)(void *opaque, int size);
void (*pool_free)(void *opaque);

void (*get)(void *opaque, void *data);
void (*release)(void *opaque, void *data);
};

#endif /* AVUTIL_BUFFER_INTERNAL_H */

0 comments on commit 42e3ab0

Please sign in to comment.