Unified · Split
| @@ -34,6 +34,7 @@ · 33 unmodified lines | ||
| 34 | 34 | #include "cbs_h264.h" |
| 35 | 35 | #include "h264_parse.h" |
| 36 | 36 | #include "h264_ps.h" |
| 37 | +#include "refstruct.h" | |
| 37 | 38 | |
| 38 | 39 | typedef struct DTS2PTSNode { |
| 39 | 40 | int64_t dts; |
| @@ -61,6 +62,7 @@ typedef struct DTS2PTSH264Context { · 21 unmodified lines | ||
| 61 | 62 | typedef struct DTS2PTSContext { |
| 62 | 63 | struct AVTreeNode *root; |
| 63 | 64 | AVFifo *fifo; |
| 65 | + FFRefStructPool *node_pool; | |
| 64 | 66 | |
| 65 | 67 | // Codec specific function pointers and constants |
| 66 | 68 | int (*init)(AVBSFContext *ctx); |
| @@ -110,7 +112,7 @@ static int dec_poc(void *opaque, void *elem) · 43 unmodified lines | ||
| 110 | 112 | static int free_node(void *opaque, void *elem) |
| 111 | 113 | { |
| 112 | 114 | DTS2PTSNode *node = elem; |
| 113 | − av_free(node); | |
| 115 | + ff_refstruct_unref(&node); | |
| 114 | 116 | return 0; |
| 115 | 117 | } |
| 116 | 118 | |
| @@ -124,7 +126,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration · 7 unmodified lines | ||
| 124 | 126 | DTS2PTSNode *poc_node, *ret; |
| 125 | 127 | if (!node) |
| 126 | 128 | return AVERROR(ENOMEM); |
| 127 | − poc_node = av_malloc(sizeof(*poc_node)); | |
| 129 | + poc_node = ff_refstruct_pool_get(s->node_pool); | |
| 128 | 130 | if (!poc_node) { |
| 129 | 131 | av_free(node); |
| 130 | 132 | return AVERROR(ENOMEM); |
| @@ -135,7 +137,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration · 4 unmodified lines | ||
| 135 | 137 | ret = av_tree_insert(&s->root, poc_node, cmp_insert, &node); |
| 136 | 138 | if (ret && ret != poc_node) { |
| 137 | 139 | *ret = *poc_node; |
| 138 | − av_free(poc_node); | |
| 140 | + ff_refstruct_unref(&poc_node); | |
| 139 | 141 | av_free(node); |
| 140 | 142 | } |
| 141 | 143 | } |
| @@ -394,6 +396,11 @@ static int dts2pts_init(AVBSFContext *ctx) · 252 unmodified lines | ||
| 394 | 396 | if (!s->fifo) |
| 395 | 397 | return AVERROR(ENOMEM); |
| 396 | 398 | |
| 399 | + s->node_pool = ff_refstruct_pool_alloc(sizeof(DTS2PTSNode), 0); | |
| 400 | + | |
| 401 | + if (!s->node_pool) | |
| 402 | + return AVERROR(ENOMEM); | |
| 403 | + | |
| 397 | 404 | ret = ff_cbs_init(&s->cbc, ctx->par_in->codec_id, ctx); |
| 398 | 405 | if (ret < 0) |
| 399 | 406 | return ret; |
| @@ -459,7 +466,7 @@ static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out) · 59 unmodified lines | ||
| 459 | 466 | if (!poc_node || poc_node->dts != out->pts) |
| 460 | 467 | continue; |
| 461 | 468 | av_tree_insert(&s->root, poc_node, cmp_insert, &node); |
| 462 | − av_free(poc_node); | |
| 469 | + ff_refstruct_unref(&poc_node); | |
| 463 | 470 | av_free(node); |
| 464 | 471 | poc_node = av_tree_find(s->root, &dup, cmp_find, NULL); |
| 465 | 472 | } |
| @@ -521,6 +528,7 @@ static void dts2pts_close(AVBSFContext *ctx) · 55 unmodified lines | ||
| 521 | 528 | dts2pts_flush(ctx); |
| 522 | 529 | |
| 523 | 530 | av_fifo_freep2(&s->fifo); |
| 531 | + ff_refstruct_pool_uninit(&s->node_pool); | |
| 524 | 532 | ff_cbs_fragment_free(&s->au); |
| 525 | 533 | ff_cbs_close(&s->cbc); |
| 526 | 534 | } |