diff options
author | James Almer <jamrial@gmail.com> | 2024-09-13 21:45:33 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-09-16 16:45:00 -0300 |
commit | fec6a8df3127795f0796f73494df7f27fe354550 (patch) | |
tree | 76cb7e3790ccbd5d663db4a42cf18a0af3b3273b /libavcodec | |
parent | 99ec7a8ceddc92740b69202bbc39bfaa51754256 (diff) | |
download | ffmpeg-fec6a8df3127795f0796f73494df7f27fe354550.tar.gz |
avcodec/bsf/dts2pts: use a RefStruct pool to allocate nodes
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/bsf/dts2pts.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/libavcodec/bsf/dts2pts.c b/libavcodec/bsf/dts2pts.c index ba4dc43f84..2be79c624b 100644 --- a/libavcodec/bsf/dts2pts.c +++ b/libavcodec/bsf/dts2pts.c @@ -34,6 +34,7 @@ #include "cbs_h264.h" #include "h264_parse.h" #include "h264_ps.h" +#include "refstruct.h" typedef struct DTS2PTSNode { int64_t dts; @@ -61,6 +62,7 @@ typedef struct DTS2PTSH264Context { typedef struct DTS2PTSContext { struct AVTreeNode *root; AVFifo *fifo; + FFRefStructPool *node_pool; // Codec specific function pointers and constants int (*init)(AVBSFContext *ctx); @@ -110,7 +112,7 @@ static int dec_poc(void *opaque, void *elem) static int free_node(void *opaque, void *elem) { DTS2PTSNode *node = elem; - av_free(node); + ff_refstruct_unref(&node); return 0; } @@ -124,7 +126,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration DTS2PTSNode *poc_node, *ret; if (!node) return AVERROR(ENOMEM); - poc_node = av_malloc(sizeof(*poc_node)); + poc_node = ff_refstruct_pool_get(s->node_pool); if (!poc_node) { av_free(node); return AVERROR(ENOMEM); @@ -135,7 +137,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration ret = av_tree_insert(&s->root, poc_node, cmp_insert, &node); if (ret && ret != poc_node) { *ret = *poc_node; - av_free(poc_node); + ff_refstruct_unref(&poc_node); av_free(node); } } @@ -394,6 +396,11 @@ static int dts2pts_init(AVBSFContext *ctx) if (!s->fifo) return AVERROR(ENOMEM); + s->node_pool = ff_refstruct_pool_alloc(sizeof(DTS2PTSNode), 0); + + if (!s->node_pool) + return AVERROR(ENOMEM); + ret = ff_cbs_init(&s->cbc, ctx->par_in->codec_id, ctx); if (ret < 0) return ret; @@ -459,7 +466,7 @@ static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out) if (!poc_node || poc_node->dts != out->pts) continue; av_tree_insert(&s->root, poc_node, cmp_insert, &node); - av_free(poc_node); + ff_refstruct_unref(&poc_node); av_free(node); poc_node = av_tree_find(s->root, &dup, cmp_find, NULL); } @@ -521,6 +528,7 @@ static void dts2pts_close(AVBSFContext *ctx) dts2pts_flush(ctx); av_fifo_freep2(&s->fifo); + ff_refstruct_pool_uninit(&s->node_pool); ff_cbs_fragment_free(&s->au); ff_cbs_close(&s->cbc); } |