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

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