History

avcodec/bsf/dts2pts: use a RefStruct pool to allocate nodes

James Almer committed 2 years ago

Commit fec6a8d1 parent 99ec7a81 file · +12 −4Browse files

Unified · Split

libavcodec/bsf/dts2pts.c+12−4
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 #include "cbs_h264.h"
3535 #include "h264_parse.h"
3636 #include "h264_ps.h"
37+#include "refstruct.h"
3738
3839 typedef struct DTS2PTSNode {
3940 int64_t dts;
@@ -61,6 +62,7 @@ typedef struct DTS2PTSH264Context { · 21 unmodified lines
6162 typedef struct DTS2PTSContext {
6263 struct AVTreeNode *root;
6364 AVFifo *fifo;
65+ FFRefStructPool *node_pool;
6466
6567 // Codec specific function pointers and constants
6668 int (*init)(AVBSFContext *ctx);
@@ -110,7 +112,7 @@ static int dec_poc(void *opaque, void *elem) · 43 unmodified lines
110112 static int free_node(void *opaque, void *elem)
111113 {
112114 DTS2PTSNode *node = elem;
113− av_free(node);
115+ ff_refstruct_unref(&node);
114116 return 0;
115117 }
116118
@@ -124,7 +126,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration · 7 unmodified lines
124126 DTS2PTSNode *poc_node, *ret;
125127 if (!node)
126128 return AVERROR(ENOMEM);
127− poc_node = av_malloc(sizeof(*poc_node));
129+ poc_node = ff_refstruct_pool_get(s->node_pool);
128130 if (!poc_node) {
129131 av_free(node);
130132 return AVERROR(ENOMEM);
@@ -135,7 +137,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration · 4 unmodified lines
135137 ret = av_tree_insert(&s->root, poc_node, cmp_insert, &node);
136138 if (ret && ret != poc_node) {
137139 *ret = *poc_node;
138− av_free(poc_node);
140+ ff_refstruct_unref(&poc_node);
139141 av_free(node);
140142 }
141143 }
@@ -394,6 +396,11 @@ static int dts2pts_init(AVBSFContext *ctx) · 252 unmodified lines
394396 if (!s->fifo)
395397 return AVERROR(ENOMEM);
396398
399+ s->node_pool = ff_refstruct_pool_alloc(sizeof(DTS2PTSNode), 0);
400+
401+ if (!s->node_pool)
402+ return AVERROR(ENOMEM);
403+
397404 ret = ff_cbs_init(&s->cbc, ctx->par_in->codec_id, ctx);
398405 if (ret < 0)
399406 return ret;
@@ -459,7 +466,7 @@ static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out) · 59 unmodified lines
459466 if (!poc_node || poc_node->dts != out->pts)
460467 continue;
461468 av_tree_insert(&s->root, poc_node, cmp_insert, &node);
462− av_free(poc_node);
469+ ff_refstruct_unref(&poc_node);
463470 av_free(node);
464471 poc_node = av_tree_find(s->root, &dup, cmp_find, NULL);
465472 }
@@ -521,6 +528,7 @@ static void dts2pts_close(AVBSFContext *ctx) · 55 unmodified lines
521528 dts2pts_flush(ctx);
522529
523530 av_fifo_freep2(&s->fifo);
531+ ff_refstruct_pool_uninit(&s->node_pool);
524532 ff_cbs_fragment_free(&s->au);
525533 ff_cbs_close(&s->cbc);
526534 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t