lavc/refstruct: move to lavu and make public

It is highly versatile and generally useful.
This commit is contained in:
Anton Khirnov 2024-10-15 22:37:56 +02:00
parent 183c59b473
commit 56ba57b672
70 changed files with 657 additions and 651 deletions

View file

@ -2,6 +2,10 @@ The last version increases of all libraries were on 2024-03-07
API changes, most recent first: API changes, most recent first:
2024-12-15 - xxxxxxxxxx - lavu 59.51.100 - refstruct.h
Add a new public header refstruct.h with new API for
reference-counted objects.
2024-12-13 - xxxxxxxxxx - lavu 59.50.100 - channel_layout.h 2024-12-13 - xxxxxxxxxx - lavu 59.50.100 - channel_layout.h
Add AV_CH_LAYOUT_9POINT1POINT6 and AV_CHANNEL_LAYOUT_9POINT1POINT6. Add AV_CH_LAYOUT_9POINT1POINT6 and AV_CHANNEL_LAYOUT_9POINT1POINT6.

View file

@ -57,7 +57,6 @@ OBJS = ac3_parser.o \
profiles.o \ profiles.o \
qsv_api.o \ qsv_api.o \
raw.o \ raw.o \
refstruct.o \
threadprogress.o \ threadprogress.o \
utils.o \ utils.o \
version.o \ version.o \

View file

@ -39,7 +39,7 @@
#include "hwconfig.h" #include "hwconfig.h"
#include "profiles.h" #include "profiles.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
/**< same with Div_Lut defined in spec 7.11.3.7 */ /**< same with Div_Lut defined in spec 7.11.3.7 */
static const uint16_t div_lut[AV1_DIV_LUT_NUM] = { static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
@ -687,8 +687,8 @@ static int get_pixel_format(AVCodecContext *avctx)
static void av1_frame_unref(AV1Frame *f) static void av1_frame_unref(AV1Frame *f)
{ {
ff_progress_frame_unref(&f->pf); ff_progress_frame_unref(&f->pf);
ff_refstruct_unref(&f->hwaccel_picture_private); av_refstruct_unref(&f->hwaccel_picture_private);
ff_refstruct_unref(&f->header_ref); av_refstruct_unref(&f->header_ref);
f->raw_frame_header = NULL; f->raw_frame_header = NULL;
f->spatial_id = f->temporal_id = 0; f->spatial_id = f->temporal_id = 0;
memset(f->skip_mode_frame_idx, 0, memset(f->skip_mode_frame_idx, 0,
@ -701,13 +701,13 @@ static void av1_frame_replace(AV1Frame *dst, const AV1Frame *src)
{ {
av_assert1(dst != src); av_assert1(dst != src);
ff_refstruct_replace(&dst->header_ref, src->header_ref); av_refstruct_replace(&dst->header_ref, src->header_ref);
dst->raw_frame_header = src->raw_frame_header; dst->raw_frame_header = src->raw_frame_header;
ff_progress_frame_replace(&dst->pf, &src->pf); ff_progress_frame_replace(&dst->pf, &src->pf);
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
dst->spatial_id = src->spatial_id; dst->spatial_id = src->spatial_id;
@ -747,10 +747,10 @@ static av_cold int av1_decode_free(AVCodecContext *avctx)
av1_frame_unref(&s->ref[i]); av1_frame_unref(&s->ref[i]);
av1_frame_unref(&s->cur_frame); av1_frame_unref(&s->cur_frame);
av_buffer_unref(&s->seq_data_ref); av_buffer_unref(&s->seq_data_ref);
ff_refstruct_unref(&s->seq_ref); av_refstruct_unref(&s->seq_ref);
ff_refstruct_unref(&s->header_ref); av_refstruct_unref(&s->header_ref);
ff_refstruct_unref(&s->cll_ref); av_refstruct_unref(&s->cll_ref);
ff_refstruct_unref(&s->mdcv_ref); av_refstruct_unref(&s->mdcv_ref);
av_freep(&s->tile_group_info); av_freep(&s->tile_group_info);
while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
@ -1218,7 +1218,7 @@ static int get_current_frame(AVCodecContext *avctx)
av1_frame_unref(&s->cur_frame); av1_frame_unref(&s->cur_frame);
s->cur_frame.header_ref = ff_refstruct_ref(s->header_ref); s->cur_frame.header_ref = av_refstruct_ref(s->header_ref);
s->cur_frame.raw_frame_header = s->raw_frame_header; s->cur_frame.raw_frame_header = s->raw_frame_header;
@ -1306,7 +1306,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
s->seq_data_ref->data = unit->data; s->seq_data_ref->data = unit->data;
s->seq_data_ref->size = unit->data_size; s->seq_data_ref->size = unit->data_size;
ff_refstruct_replace(&s->seq_ref, unit->content_ref); av_refstruct_replace(&s->seq_ref, unit->content_ref);
s->raw_seq = &obu->obu.sequence_header; s->raw_seq = &obu->obu.sequence_header;
@ -1334,7 +1334,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
goto end; goto end;
} }
ff_refstruct_replace(&s->header_ref, unit->content_ref); av_refstruct_replace(&s->header_ref, unit->content_ref);
if (unit->type == AV1_OBU_FRAME) if (unit->type == AV1_OBU_FRAME)
s->raw_frame_header = &obu->obu.frame.header; s->raw_frame_header = &obu->obu.frame.header;
@ -1414,11 +1414,11 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
case AV1_OBU_METADATA: case AV1_OBU_METADATA:
switch (obu->obu.metadata.metadata_type) { switch (obu->obu.metadata.metadata_type) {
case AV1_METADATA_TYPE_HDR_CLL: case AV1_METADATA_TYPE_HDR_CLL:
ff_refstruct_replace(&s->cll_ref, unit->content_ref); av_refstruct_replace(&s->cll_ref, unit->content_ref);
s->cll = &obu->obu.metadata.metadata.hdr_cll; s->cll = &obu->obu.metadata.metadata.hdr_cll;
break; break;
case AV1_METADATA_TYPE_HDR_MDCV: case AV1_METADATA_TYPE_HDR_MDCV:
ff_refstruct_replace(&s->mdcv_ref, unit->content_ref); av_refstruct_replace(&s->mdcv_ref, unit->content_ref);
s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv; s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv;
break; break;
case AV1_METADATA_TYPE_ITUT_T35: { case AV1_METADATA_TYPE_ITUT_T35: {

View file

@ -45,7 +45,7 @@
#include "frame_thread_encoder.h" #include "frame_thread_encoder.h"
#include "hwconfig.h" #include "hwconfig.h"
#include "internal.h" #include "internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
/** /**
@ -453,8 +453,8 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
av_frame_free(&avci->in_frame); av_frame_free(&avci->in_frame);
av_frame_free(&avci->recon_frame); av_frame_free(&avci->recon_frame);
ff_refstruct_unref(&avci->pool); av_refstruct_unref(&avci->pool);
ff_refstruct_pool_uninit(&avci->progress_frame_pool); av_refstruct_pool_uninit(&avci->progress_frame_pool);
if (av_codec_is_decoder(avctx->codec)) if (av_codec_is_decoder(avctx->codec))
ff_decode_internal_uninit(avctx); ff_decode_internal_uninit(avctx);

View file

@ -34,7 +34,7 @@
#include "cbs_h264.h" #include "cbs_h264.h"
#include "h264_parse.h" #include "h264_parse.h"
#include "h264_ps.h" #include "h264_ps.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
typedef struct DTS2PTSNode { typedef struct DTS2PTSNode {
int64_t dts; int64_t dts;
@ -62,7 +62,7 @@ typedef struct DTS2PTSH264Context {
typedef struct DTS2PTSContext { typedef struct DTS2PTSContext {
struct AVTreeNode *root; struct AVTreeNode *root;
AVFifo *fifo; AVFifo *fifo;
FFRefStructPool *node_pool; AVRefStructPool *node_pool;
// Codec specific function pointers and constants // Codec specific function pointers and constants
int (*init)(AVBSFContext *ctx); int (*init)(AVBSFContext *ctx);
@ -112,7 +112,7 @@ static int dec_poc(void *opaque, void *elem)
static int free_node(void *opaque, void *elem) static int free_node(void *opaque, void *elem)
{ {
DTS2PTSNode *node = elem; DTS2PTSNode *node = elem;
ff_refstruct_unref(&node); av_refstruct_unref(&node);
return 0; return 0;
} }
@ -126,7 +126,7 @@ static int alloc_and_insert_node(AVBSFContext *ctx, int64_t ts, int64_t duration
DTS2PTSNode *poc_node, *ret; DTS2PTSNode *poc_node, *ret;
if (!node) if (!node)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
poc_node = ff_refstruct_pool_get(s->node_pool); poc_node = av_refstruct_pool_get(s->node_pool);
if (!poc_node) { if (!poc_node) {
av_free(node); av_free(node);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -137,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); ret = av_tree_insert(&s->root, poc_node, cmp_insert, &node);
if (ret && ret != poc_node) { if (ret && ret != poc_node) {
*ret = *poc_node; *ret = *poc_node;
ff_refstruct_unref(&poc_node); av_refstruct_unref(&poc_node);
av_free(node); av_free(node);
} }
} }
@ -396,8 +396,8 @@ static int dts2pts_init(AVBSFContext *ctx)
if (!s->fifo) if (!s->fifo)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
s->node_pool = ff_refstruct_pool_alloc(sizeof(DTS2PTSNode), s->node_pool = av_refstruct_pool_alloc(sizeof(DTS2PTSNode),
FF_REFSTRUCT_POOL_FLAG_NO_ZEROING); AV_REFSTRUCT_POOL_FLAG_NO_ZEROING);
if (!s->node_pool) if (!s->node_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -467,7 +467,7 @@ static int dts2pts_filter(AVBSFContext *ctx, AVPacket *out)
if (!poc_node || poc_node->dts != out->pts) if (!poc_node || poc_node->dts != out->pts)
continue; continue;
av_tree_insert(&s->root, poc_node, cmp_insert, &node); av_tree_insert(&s->root, poc_node, cmp_insert, &node);
ff_refstruct_unref(&poc_node); av_refstruct_unref(&poc_node);
av_free(node); av_free(node);
poc_node = av_tree_find(s->root, &dup, cmp_find, NULL); poc_node = av_tree_find(s->root, &dup, cmp_find, NULL);
} }
@ -529,7 +529,7 @@ static void dts2pts_close(AVBSFContext *ctx)
dts2pts_flush(ctx); dts2pts_flush(ctx);
av_fifo_freep2(&s->fifo); av_fifo_freep2(&s->fifo);
ff_refstruct_pool_uninit(&s->node_pool); av_refstruct_pool_uninit(&s->node_pool);
ff_cbs_fragment_free(&s->au); ff_cbs_fragment_free(&s->au);
ff_cbs_close(&s->cbc); ff_cbs_close(&s->cbc);
} }

View file

@ -29,7 +29,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "cbs.h" #include "cbs.h"
#include "cbs_internal.h" #include "cbs_internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static const CodedBitstreamType *const cbs_type_table[] = { static const CodedBitstreamType *const cbs_type_table[] = {
@ -160,7 +160,7 @@ av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
static void cbs_unit_uninit(CodedBitstreamUnit *unit) static void cbs_unit_uninit(CodedBitstreamUnit *unit)
{ {
ff_refstruct_unref(&unit->content_ref); av_refstruct_unref(&unit->content_ref);
unit->content = NULL; unit->content = NULL;
av_buffer_unref(&unit->data_ref); av_buffer_unref(&unit->data_ref);
@ -208,7 +208,7 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
continue; continue;
} }
ff_refstruct_unref(&unit->content_ref); av_refstruct_unref(&unit->content_ref);
unit->content = NULL; unit->content = NULL;
av_assert0(unit->data && unit->data_ref); av_assert0(unit->data && unit->data_ref);
@ -222,7 +222,7 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
av_log(ctx->log_ctx, AV_LOG_VERBOSE, av_log(ctx->log_ctx, AV_LOG_VERBOSE,
"Skipping decomposition of unit %d " "Skipping decomposition of unit %d "
"(type %"PRIu32").\n", i, unit->type); "(type %"PRIu32").\n", i, unit->type);
ff_refstruct_unref(&unit->content_ref); av_refstruct_unref(&unit->content_ref);
unit->content = NULL; unit->content = NULL;
} else if (err < 0) { } else if (err < 0) {
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d " av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
@ -799,7 +799,7 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
if (content_ref) { if (content_ref) {
// Create our own reference out of the user-supplied one. // Create our own reference out of the user-supplied one.
content_ref = ff_refstruct_ref(content_ref); content_ref = av_refstruct_ref(content_ref);
} }
unit = &frag->units[position]; unit = &frag->units[position];
@ -873,7 +873,7 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
(frag->nb_units - position) * sizeof(*frag->units)); (frag->nb_units - position) * sizeof(*frag->units));
} }
static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content) static void cbs_default_free_unit_content(AVRefStructOpaque opaque, void *content)
{ {
const CodedBitstreamUnitTypeDescriptor *desc = opaque.c; const CodedBitstreamUnitTypeDescriptor *desc = opaque.c;
@ -913,8 +913,8 @@ static const CodedBitstreamUnitTypeDescriptor
static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc) static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
{ {
return ff_refstruct_alloc_ext_c(desc->content_size, 0, return av_refstruct_alloc_ext_c(desc->content_size, 0,
(FFRefStructOpaque){ .c = desc }, (AVRefStructOpaque){ .c = desc },
desc->content_type == CBS_CONTENT_TYPE_COMPLEX desc->content_type == CBS_CONTENT_TYPE_COMPLEX
? desc->type.complex.content_free ? desc->type.complex.content_free
: cbs_default_free_unit_content); : cbs_default_free_unit_content);
@ -989,7 +989,7 @@ static int cbs_clone_noncomplex_unit_content(void **clonep,
return 0; return 0;
fail: fail:
ff_refstruct_unref(&copy); av_refstruct_unref(&copy);
return err; return err;
} }
@ -1048,13 +1048,13 @@ int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
int err; int err;
av_assert0(unit->content); av_assert0(unit->content);
if (ref && ff_refstruct_exclusive(ref)) if (ref && av_refstruct_exclusive(ref))
return 0; return 0;
err = cbs_clone_unit_content(ctx, unit); err = cbs_clone_unit_content(ctx, unit);
if (err < 0) if (err < 0)
return err; return err;
ff_refstruct_unref(&ref); av_refstruct_unref(&ref);
return 0; return 0;
} }

View file

@ -24,7 +24,7 @@
#include "cbs_internal.h" #include "cbs_internal.h"
#include "cbs_av1.h" #include "cbs_av1.h"
#include "defs.h" #include "defs.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
@ -878,7 +878,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point]; priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point];
} }
ff_refstruct_replace(&priv->sequence_header_ref, unit->content_ref); av_refstruct_replace(&priv->sequence_header_ref, unit->content_ref);
priv->sequence_header = &obu->obu.sequence_header; priv->sequence_header = &obu->obu.sequence_header;
} }
break; break;
@ -997,7 +997,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
av1ctx = *priv; av1ctx = *priv;
if (priv->sequence_header_ref) { if (priv->sequence_header_ref) {
av1ctx.sequence_header_ref = ff_refstruct_ref(priv->sequence_header_ref); av1ctx.sequence_header_ref = av_refstruct_ref(priv->sequence_header_ref);
} }
if (priv->frame_header_ref) { if (priv->frame_header_ref) {
@ -1035,14 +1035,14 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
if (err < 0) if (err < 0)
goto error; goto error;
ff_refstruct_unref(&priv->sequence_header_ref); av_refstruct_unref(&priv->sequence_header_ref);
priv->sequence_header = NULL; priv->sequence_header = NULL;
err = ff_cbs_make_unit_refcounted(ctx, unit); err = ff_cbs_make_unit_refcounted(ctx, unit);
if (err < 0) if (err < 0)
goto error; goto error;
priv->sequence_header_ref = ff_refstruct_ref(unit->content_ref); priv->sequence_header_ref = av_refstruct_ref(unit->content_ref);
priv->sequence_header = &obu->obu.sequence_header; priv->sequence_header = &obu->obu.sequence_header;
} }
break; break;
@ -1146,7 +1146,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
av_assert0(data_pos <= start_pos); av_assert0(data_pos <= start_pos);
if (8 * obu->obu_size > put_bits_left(pbc)) { if (8 * obu->obu_size > put_bits_left(pbc)) {
ff_refstruct_unref(&priv->sequence_header_ref); av_refstruct_unref(&priv->sequence_header_ref);
av_buffer_unref(&priv->frame_header_ref); av_buffer_unref(&priv->frame_header_ref);
*priv = av1ctx; *priv = av1ctx;
@ -1175,7 +1175,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
err = 0; err = 0;
error: error:
ff_refstruct_unref(&av1ctx.sequence_header_ref); av_refstruct_unref(&av1ctx.sequence_header_ref);
av_buffer_unref(&av1ctx.frame_header_ref); av_buffer_unref(&av1ctx.frame_header_ref);
return err; return err;
@ -1227,11 +1227,11 @@ static void cbs_av1_close(CodedBitstreamContext *ctx)
{ {
CodedBitstreamAV1Context *priv = ctx->priv_data; CodedBitstreamAV1Context *priv = ctx->priv_data;
ff_refstruct_unref(&priv->sequence_header_ref); av_refstruct_unref(&priv->sequence_header_ref);
av_buffer_unref(&priv->frame_header_ref); av_buffer_unref(&priv->frame_header_ref);
} }
static void cbs_av1_free_metadata(FFRefStructOpaque unused, void *content) static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
{ {
AV1RawOBU *obu = content; AV1RawOBU *obu = content;
AV1RawMetadata *md; AV1RawMetadata *md;

View file

@ -28,7 +28,7 @@
#include "cbs_h266.h" #include "cbs_h266.h"
#include "h264.h" #include "h264.h"
#include "h2645_parse.h" #include "h2645_parse.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "vvc.h" #include "vvc.h"
#include "hevc/hevc.h" #include "hevc/hevc.h"
@ -345,7 +345,7 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
/* The CBS SEI code uses the refstruct API for the allocation /* The CBS SEI code uses the refstruct API for the allocation
* of its child buffers. */ * of its child buffers. */
#define allocate(name, size) do { \ #define allocate(name, size) do { \
name = ff_refstruct_allocz(size + \ name = av_refstruct_allocz(size + \
AV_INPUT_BUFFER_PADDING_SIZE); \ AV_INPUT_BUFFER_PADDING_SIZE); \
if (!name) \ if (!name) \
return AVERROR(ENOMEM); \ return AVERROR(ENOMEM); \
@ -769,7 +769,7 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
if (priv->ps_var[id] == priv->active_ ## ps_var) \ if (priv->ps_var[id] == priv->active_ ## ps_var) \
priv->active_ ## ps_var = NULL ; \ priv->active_ ## ps_var = NULL ; \
av_assert0(unit->content_ref); \ av_assert0(unit->content_ref); \
ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
return 0; \ return 0; \
} }
@ -790,7 +790,7 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
if (err < 0) \ if (err < 0) \
return err; \ return err; \
av_assert0(unit->content_ref); \ av_assert0(unit->content_ref); \
ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
return 0; \ return 0; \
} }
@ -810,10 +810,10 @@ static int cbs_h266_replace_sps(CodedBitstreamContext *ctx,
if (priv->sps[id] && memcmp(priv->sps[id], unit->content_ref, sizeof(*priv->sps[id]))) { if (priv->sps[id] && memcmp(priv->sps[id], unit->content_ref, sizeof(*priv->sps[id]))) {
for (unsigned int i = 0; i < VVC_MAX_PPS_COUNT; i++) { for (unsigned int i = 0; i < VVC_MAX_PPS_COUNT; i++) {
if (priv->pps[i] && priv->pps[i]->pps_seq_parameter_set_id == id) if (priv->pps[i] && priv->pps[i]->pps_seq_parameter_set_id == id)
ff_refstruct_unref(&priv->pps[i]); av_refstruct_unref(&priv->pps[i]);
} }
} }
ff_refstruct_replace(&priv->sps[id], unit->content_ref); av_refstruct_replace(&priv->sps[id], unit->content_ref);
return 0; return 0;
} }
@ -828,7 +828,7 @@ static int cbs_h266_replace_ph(CodedBitstreamContext *ctx,
if (err < 0) if (err < 0)
return err; return err;
av_assert0(unit->content_ref); av_assert0(unit->content_ref);
ff_refstruct_replace(&h266->ph_ref, unit->content_ref); av_refstruct_replace(&h266->ph_ref, unit->content_ref);
h266->ph = ph; h266->ph = ph;
return 0; return 0;
} }
@ -1910,9 +1910,9 @@ static void cbs_h264_flush(CodedBitstreamContext *ctx)
CodedBitstreamH264Context *h264 = ctx->priv_data; CodedBitstreamH264Context *h264 = ctx->priv_data;
for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
ff_refstruct_unref(&h264->sps[i]); av_refstruct_unref(&h264->sps[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
ff_refstruct_unref(&h264->pps[i]); av_refstruct_unref(&h264->pps[i]);
h264->active_sps = NULL; h264->active_sps = NULL;
h264->active_pps = NULL; h264->active_pps = NULL;
@ -1927,9 +1927,9 @@ static void cbs_h264_close(CodedBitstreamContext *ctx)
ff_h2645_packet_uninit(&h264->common.read_packet); ff_h2645_packet_uninit(&h264->common.read_packet);
for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
ff_refstruct_unref(&h264->sps[i]); av_refstruct_unref(&h264->sps[i]);
for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
ff_refstruct_unref(&h264->pps[i]); av_refstruct_unref(&h264->pps[i]);
} }
static void cbs_h265_flush(CodedBitstreamContext *ctx) static void cbs_h265_flush(CodedBitstreamContext *ctx)
@ -1937,11 +1937,11 @@ static void cbs_h265_flush(CodedBitstreamContext *ctx)
CodedBitstreamH265Context *h265 = ctx->priv_data; CodedBitstreamH265Context *h265 = ctx->priv_data;
for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
ff_refstruct_unref(&h265->vps[i]); av_refstruct_unref(&h265->vps[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
ff_refstruct_unref(&h265->sps[i]); av_refstruct_unref(&h265->sps[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
ff_refstruct_unref(&h265->pps[i]); av_refstruct_unref(&h265->pps[i]);
h265->active_vps = NULL; h265->active_vps = NULL;
h265->active_sps = NULL; h265->active_sps = NULL;
@ -1956,11 +1956,11 @@ static void cbs_h265_close(CodedBitstreamContext *ctx)
ff_h2645_packet_uninit(&h265->common.read_packet); ff_h2645_packet_uninit(&h265->common.read_packet);
for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
ff_refstruct_unref(&h265->vps[i]); av_refstruct_unref(&h265->vps[i]);
for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
ff_refstruct_unref(&h265->sps[i]); av_refstruct_unref(&h265->sps[i]);
for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
ff_refstruct_unref(&h265->pps[i]); av_refstruct_unref(&h265->pps[i]);
} }
static void cbs_h266_flush(CodedBitstreamContext *ctx) static void cbs_h266_flush(CodedBitstreamContext *ctx)
@ -1968,12 +1968,12 @@ static void cbs_h266_flush(CodedBitstreamContext *ctx)
CodedBitstreamH266Context *h266 = ctx->priv_data; CodedBitstreamH266Context *h266 = ctx->priv_data;
for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++)
ff_refstruct_unref(&h266->vps[i]); av_refstruct_unref(&h266->vps[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++)
ff_refstruct_unref(&h266->sps[i]); av_refstruct_unref(&h266->sps[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++)
ff_refstruct_unref(&h266->pps[i]); av_refstruct_unref(&h266->pps[i]);
ff_refstruct_unref(&h266->ph_ref); av_refstruct_unref(&h266->ph_ref);
} }
static void cbs_h266_close(CodedBitstreamContext *ctx) static void cbs_h266_close(CodedBitstreamContext *ctx)
@ -1984,7 +1984,7 @@ static void cbs_h266_close(CodedBitstreamContext *ctx)
ff_h2645_packet_uninit(&h266->common.read_packet); ff_h2645_packet_uninit(&h266->common.read_packet);
} }
static void cbs_h264_free_sei(FFRefStructOpaque unused, void *content) static void cbs_h264_free_sei(AVRefStructOpaque unused, void *content)
{ {
H264RawSEI *sei = content; H264RawSEI *sei = content;
ff_cbs_sei_free_message_list(&sei->message_list); ff_cbs_sei_free_message_list(&sei->message_list);
@ -2010,7 +2010,7 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = {
CBS_UNIT_TYPE_END_OF_LIST CBS_UNIT_TYPE_END_OF_LIST
}; };
static void cbs_h265_free_sei(FFRefStructOpaque unused, void *content) static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
{ {
H265RawSEI *sei = content; H265RawSEI *sei = content;
ff_cbs_sei_free_message_list(&sei->message_list); ff_cbs_sei_free_message_list(&sei->message_list);
@ -2037,7 +2037,7 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = {
CBS_UNIT_TYPE_END_OF_LIST CBS_UNIT_TYPE_END_OF_LIST
}; };
static void cbs_h266_free_sei(FFRefStructOpaque unused, void *content) static void cbs_h266_free_sei(AVRefStructOpaque unused, void *content)
{ {
H266RawSEI *sei = content; H266RawSEI *sei = content;
ff_cbs_sei_free_message_list(&sei->message_list); ff_cbs_sei_free_message_list(&sei->message_list);

View file

@ -1078,7 +1078,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
ub(4, sps_seq_parameter_set_id); ub(4, sps_seq_parameter_set_id);
ub(4, sps_video_parameter_set_id); ub(4, sps_video_parameter_set_id);
if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) { if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
H266RawVPS *vps = ff_refstruct_allocz(sizeof(*vps)); H266RawVPS *vps = av_refstruct_allocz(sizeof(*vps));
if (!vps) if (!vps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
vps->vps_max_layers_minus1 = 0; vps->vps_max_layers_minus1 = 0;

View file

@ -28,7 +28,7 @@
#include "codec_id.h" #include "codec_id.h"
#include "get_bits.h" #include "get_bits.h"
#include "put_bits.h" #include "put_bits.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
enum CBSContentType { enum CBSContentType {
@ -93,7 +93,7 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
} ref; } ref;
struct { struct {
void (*content_free)(FFRefStructOpaque opaque, void *content); void (*content_free)(AVRefStructOpaque opaque, void *content);
int (*content_clone)(void **new_content, CodedBitstreamUnit *unit); int (*content_clone)(void **new_content, CodedBitstreamUnit *unit);
} complex; } complex;
} type; } type;

View file

@ -23,24 +23,24 @@
#include "cbs_h265.h" #include "cbs_h265.h"
#include "cbs_h266.h" #include "cbs_h266.h"
#include "cbs_sei.h" #include "cbs_sei.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static void cbs_free_user_data_registered(FFRefStructOpaque unused, void *obj) static void cbs_free_user_data_registered(AVRefStructOpaque unused, void *obj)
{ {
SEIRawUserDataRegistered *udr = obj; SEIRawUserDataRegistered *udr = obj;
ff_refstruct_unref(&udr->data); av_refstruct_unref(&udr->data);
} }
static void cbs_free_user_data_unregistered(FFRefStructOpaque unused, void *obj) static void cbs_free_user_data_unregistered(AVRefStructOpaque unused, void *obj)
{ {
SEIRawUserDataUnregistered *udu = obj; SEIRawUserDataUnregistered *udu = obj;
ff_refstruct_unref(&udu->data); av_refstruct_unref(&udu->data);
} }
int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message, int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
const SEIMessageTypeDescriptor *desc) const SEIMessageTypeDescriptor *desc)
{ {
void (*free_func)(FFRefStructOpaque, void*); void (*free_func)(AVRefStructOpaque, void*);
av_assert0(message->payload == NULL && av_assert0(message->payload == NULL &&
message->payload_ref == NULL); message->payload_ref == NULL);
@ -54,7 +54,7 @@ int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
free_func = NULL; free_func = NULL;
} }
message->payload_ref = ff_refstruct_alloc_ext(desc->size, 0, message->payload_ref = av_refstruct_alloc_ext(desc->size, 0,
NULL, free_func); NULL, free_func);
if (!message->payload_ref) if (!message->payload_ref)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -92,8 +92,8 @@ void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
{ {
for (int i = 0; i < list->nb_messages; i++) { for (int i = 0; i < list->nb_messages; i++) {
SEIRawMessage *message = &list->messages[i]; SEIRawMessage *message = &list->messages[i];
ff_refstruct_unref(&message->payload_ref); av_refstruct_unref(&message->payload_ref);
ff_refstruct_unref(&message->extension_data); av_refstruct_unref(&message->extension_data);
} }
av_free(list->messages); av_free(list->messages);
} }
@ -299,7 +299,7 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
if (payload_ref) { if (payload_ref) {
/* The following just increments payload_ref's refcount, /* The following just increments payload_ref's refcount,
* so that payload_ref is now owned by us. */ * so that payload_ref is now owned by us. */
payload_ref = ff_refstruct_ref(payload_ref); payload_ref = av_refstruct_ref(payload_ref);
} }
message = &list->messages[list->nb_messages - 1]; message = &list->messages[list->nb_messages - 1];
@ -352,8 +352,8 @@ static void cbs_sei_delete_message(SEIRawMessageList *list,
av_assert0(0 <= position && position < list->nb_messages); av_assert0(0 <= position && position < list->nb_messages);
message = &list->messages[position]; message = &list->messages[position];
ff_refstruct_unref(&message->payload_ref); av_refstruct_unref(&message->payload_ref);
ff_refstruct_unref(&message->extension_data); av_refstruct_unref(&message->extension_data);
--list->nb_messages; --list->nb_messages;

View file

@ -22,11 +22,11 @@
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "container_fifo.h" #include "container_fifo.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
struct ContainerFifo { struct ContainerFifo {
AVFifo *fifo; AVFifo *fifo;
FFRefStructPool *pool; AVRefStructPool *pool;
void* (*container_alloc)(void); void* (*container_alloc)(void);
void (*container_reset)(void *obj); void (*container_reset)(void *obj);
@ -36,7 +36,7 @@ struct ContainerFifo {
}; };
static int container_fifo_init_entry(FFRefStructOpaque opaque, void *obj) static int container_fifo_init_entry(AVRefStructOpaque opaque, void *obj)
{ {
ContainerFifo *cf = opaque.nc; ContainerFifo *cf = opaque.nc;
void **pobj = obj; void **pobj = obj;
@ -48,13 +48,13 @@ static int container_fifo_init_entry(FFRefStructOpaque opaque, void *obj)
return 0; return 0;
} }
static void container_fifo_reset_entry(FFRefStructOpaque opaque, void *obj) static void container_fifo_reset_entry(AVRefStructOpaque opaque, void *obj)
{ {
ContainerFifo *cf = opaque.nc; ContainerFifo *cf = opaque.nc;
cf->container_reset(*(void**)obj); cf->container_reset(*(void**)obj);
} }
static void container_fifo_free_entry(FFRefStructOpaque opaque, void *obj) static void container_fifo_free_entry(AVRefStructOpaque opaque, void *obj)
{ {
ContainerFifo *cf = opaque.nc; ContainerFifo *cf = opaque.nc;
cf->container_free(*(void**)obj); cf->container_free(*(void**)obj);
@ -83,7 +83,7 @@ ff_container_fifo_alloc(void* (*container_alloc)(void),
if (!cf->fifo) if (!cf->fifo)
goto fail; goto fail;
cf->pool = ff_refstruct_pool_alloc_ext(sizeof(void*), 0, cf, cf->pool = av_refstruct_pool_alloc_ext(sizeof(void*), 0, cf,
container_fifo_init_entry, container_fifo_init_entry,
container_fifo_reset_entry, container_fifo_reset_entry,
container_fifo_free_entry, container_fifo_free_entry,
@ -109,11 +109,11 @@ void ff_container_fifo_free(ContainerFifo **pcf)
if (cf->fifo) { if (cf->fifo) {
void *obj; void *obj;
while (av_fifo_read(cf->fifo, &obj, 1) >= 0) while (av_fifo_read(cf->fifo, &obj, 1) >= 0)
ff_refstruct_unref(&obj); av_refstruct_unref(&obj);
av_fifo_freep2(&cf->fifo); av_fifo_freep2(&cf->fifo);
} }
ff_refstruct_pool_uninit(&cf->pool); av_refstruct_pool_uninit(&cf->pool);
av_freep(pcf); av_freep(pcf);
} }
@ -128,7 +128,7 @@ int ff_container_fifo_read(ContainerFifo *cf, void *obj)
return ret; return ret;
ret = cf->fifo_read(obj, *psrc); ret = cf->fifo_read(obj, *psrc);
ff_refstruct_unref(&psrc); av_refstruct_unref(&psrc);
return ret; return ret;
} }
@ -138,7 +138,7 @@ int ff_container_fifo_write(ContainerFifo *cf, void *obj)
void **pdst; void **pdst;
int ret; int ret;
pdst = ff_refstruct_pool_get(cf->pool); pdst = av_refstruct_pool_get(cf->pool);
if (!pdst) if (!pdst)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -152,7 +152,7 @@ int ff_container_fifo_write(ContainerFifo *cf, void *obj)
return 0; return 0;
fail: fail:
ff_refstruct_unref(&pdst); av_refstruct_unref(&pdst);
return ret; return ret;
} }

View file

@ -53,7 +53,7 @@
#include "lcevcdec.h" #include "lcevcdec.h"
#include "packet_internal.h" #include "packet_internal.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadprogress.h" #include "threadprogress.h"
@ -1684,7 +1684,7 @@ static void attach_post_process_data(AVCodecContext *avctx, AVFrame *frame)
if (dc->lcevc_frame) { if (dc->lcevc_frame) {
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data; FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
fdd->post_process_opaque = ff_refstruct_ref(dc->lcevc); fdd->post_process_opaque = av_refstruct_ref(dc->lcevc);
fdd->post_process_opaque_free = ff_lcevc_unref; fdd->post_process_opaque_free = ff_lcevc_unref;
fdd->post_process = ff_lcevc_process; fdd->post_process = ff_lcevc_process;
@ -1833,11 +1833,11 @@ static void check_progress_consistency(const ProgressFrame *f)
int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f) int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
{ {
FFRefStructPool *pool = avctx->internal->progress_frame_pool; AVRefStructPool *pool = avctx->internal->progress_frame_pool;
av_assert1(!f->f && !f->progress); av_assert1(!f->f && !f->progress);
f->progress = ff_refstruct_pool_get(pool); f->progress = av_refstruct_pool_get(pool);
if (!f->progress) if (!f->progress)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -1859,7 +1859,7 @@ int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int fl
ret = ff_thread_get_buffer(avctx, f->progress->f, flags); ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
if (ret < 0) { if (ret < 0) {
f->f = NULL; f->f = NULL;
ff_refstruct_unref(&f->progress); av_refstruct_unref(&f->progress);
return ret; return ret;
} }
return 0; return 0;
@ -1870,14 +1870,14 @@ void ff_progress_frame_ref(ProgressFrame *dst, const ProgressFrame *src)
av_assert1(src->progress && src->f && src->f == src->progress->f); av_assert1(src->progress && src->f && src->f == src->progress->f);
av_assert1(!dst->f && !dst->progress); av_assert1(!dst->f && !dst->progress);
dst->f = src->f; dst->f = src->f;
dst->progress = ff_refstruct_ref(src->progress); dst->progress = av_refstruct_ref(src->progress);
} }
void ff_progress_frame_unref(ProgressFrame *f) void ff_progress_frame_unref(ProgressFrame *f)
{ {
check_progress_consistency(f); check_progress_consistency(f);
f->f = NULL; f->f = NULL;
ff_refstruct_unref(&f->progress); av_refstruct_unref(&f->progress);
} }
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src) void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
@ -1907,7 +1907,7 @@ enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
} }
#endif /* !HAVE_THREADS */ #endif /* !HAVE_THREADS */
static av_cold int progress_frame_pool_init_cb(FFRefStructOpaque opaque, void *obj) static av_cold int progress_frame_pool_init_cb(AVRefStructOpaque opaque, void *obj)
{ {
const AVCodecContext *avctx = opaque.nc; const AVCodecContext *avctx = opaque.nc;
ProgressInternal *progress = obj; ProgressInternal *progress = obj;
@ -1924,7 +1924,7 @@ static av_cold int progress_frame_pool_init_cb(FFRefStructOpaque opaque, void *o
return 0; return 0;
} }
static void progress_frame_pool_reset_cb(FFRefStructOpaque unused, void *obj) static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
{ {
ProgressInternal *progress = obj; ProgressInternal *progress = obj;
@ -1932,7 +1932,7 @@ static void progress_frame_pool_reset_cb(FFRefStructOpaque unused, void *obj)
av_frame_unref(progress->f); av_frame_unref(progress->f);
} }
static av_cold void progress_frame_pool_free_entry_cb(FFRefStructOpaque opaque, void *obj) static av_cold void progress_frame_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
{ {
ProgressInternal *progress = obj; ProgressInternal *progress = obj;
@ -2047,8 +2047,8 @@ int ff_decode_preinit(AVCodecContext *avctx)
if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_USES_PROGRESSFRAMES) { if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_USES_PROGRESSFRAMES) {
avci->progress_frame_pool = avci->progress_frame_pool =
ff_refstruct_pool_alloc_ext(sizeof(ProgressInternal), av_refstruct_pool_alloc_ext(sizeof(ProgressInternal),
FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR, AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR,
avctx, progress_frame_pool_init_cb, avctx, progress_frame_pool_init_cb,
progress_frame_pool_reset_cb, progress_frame_pool_reset_cb,
progress_frame_pool_free_entry_cb, NULL); progress_frame_pool_free_entry_cb, NULL);
@ -2264,11 +2264,11 @@ int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_pr
return AVERROR(EINVAL); return AVERROR(EINVAL);
frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data; frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
*hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, *hwaccel_picture_private = av_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
frames_ctx->device_ctx, frames_ctx->device_ctx,
hwaccel->free_frame_priv); hwaccel->free_frame_priv);
} else { } else {
*hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size); *hwaccel_picture_private = av_refstruct_allocz(hwaccel->frame_priv_data_size);
} }
if (!*hwaccel_picture_private) if (!*hwaccel_picture_private)
@ -2305,7 +2305,7 @@ void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext *src)
const DecodeContext *src_dc = decode_ctx(src->internal); const DecodeContext *src_dc = decode_ctx(src->internal);
DecodeContext *dst_dc = decode_ctx(dst->internal); DecodeContext *dst_dc = decode_ctx(dst->internal);
ff_refstruct_replace(&dst_dc->lcevc, src_dc->lcevc); av_refstruct_replace(&dst_dc->lcevc, src_dc->lcevc);
} }
void ff_decode_internal_uninit(AVCodecContext *avctx) void ff_decode_internal_uninit(AVCodecContext *avctx)
@ -2313,5 +2313,5 @@ void ff_decode_internal_uninit(AVCodecContext *avctx)
AVCodecInternal *avci = avctx->internal; AVCodecInternal *avci = avctx->internal;
DecodeContext *dc = decode_ctx(avci); DecodeContext *dc = decode_ctx(avci);
ff_refstruct_unref(&dc->lcevc); av_refstruct_unref(&dc->lcevc);
} }

View file

@ -24,14 +24,14 @@
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "dovi_rpu.h" #include "dovi_rpu.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
void ff_dovi_ctx_unref(DOVIContext *s) void ff_dovi_ctx_unref(DOVIContext *s)
{ {
ff_refstruct_unref(&s->dm); av_refstruct_unref(&s->dm);
for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
ff_refstruct_unref(&s->vdr[i]); av_refstruct_unref(&s->vdr[i]);
ff_refstruct_unref(&s->ext_blocks); av_refstruct_unref(&s->ext_blocks);
av_free(s->rpu_buf); av_free(s->rpu_buf);
*s = (DOVIContext) { *s = (DOVIContext) {
@ -41,10 +41,10 @@ void ff_dovi_ctx_unref(DOVIContext *s)
void ff_dovi_ctx_flush(DOVIContext *s) void ff_dovi_ctx_flush(DOVIContext *s)
{ {
ff_refstruct_unref(&s->dm); av_refstruct_unref(&s->dm);
for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
ff_refstruct_unref(&s->vdr[i]); av_refstruct_unref(&s->vdr[i]);
ff_refstruct_unref(&s->ext_blocks); av_refstruct_unref(&s->ext_blocks);
*s = (DOVIContext) { *s = (DOVIContext) {
.logctx = s->logctx, .logctx = s->logctx,
@ -62,10 +62,10 @@ void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
s->header = s0->header; s->header = s0->header;
s->mapping = s0->mapping; s->mapping = s0->mapping;
s->color = s0->color; s->color = s0->color;
ff_refstruct_replace(&s->dm, s0->dm); av_refstruct_replace(&s->dm, s0->dm);
for (int i = 0; i <= DOVI_MAX_DM_ID; i++) for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
ff_refstruct_replace(&s->vdr[i], s0->vdr[i]); av_refstruct_replace(&s->vdr[i], s0->vdr[i]);
ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks); av_refstruct_replace(&s->ext_blocks, s0->ext_blocks);
} }
int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr) int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)

View file

@ -28,7 +28,7 @@
#include "dovi_rpu.h" #include "dovi_rpu.h"
#include "golomb.h" #include "golomb.h"
#include "get_bits.h" #include "get_bits.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
int ff_dovi_get_metadata(DOVIContext *s, AVDOVIMetadata **out_metadata) int ff_dovi_get_metadata(DOVIContext *s, AVDOVIMetadata **out_metadata)
{ {
@ -291,7 +291,7 @@ static int parse_ext_blocks(DOVIContext *s, GetBitContext *gb, int ver,
align_get_bits(gb); align_get_bits(gb);
if (num_ext_blocks && !ext) { if (num_ext_blocks && !ext) {
ext = s->ext_blocks = ff_refstruct_allocz(sizeof(*s->ext_blocks)); ext = s->ext_blocks = av_refstruct_allocz(sizeof(*s->ext_blocks));
if (!ext) if (!ext)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -556,7 +556,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
int vdr_rpu_id = get_ue_golomb_31(gb); int vdr_rpu_id = get_ue_golomb_31(gb);
VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
if (!s->vdr[vdr_rpu_id]) { if (!s->vdr[vdr_rpu_id]) {
s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping)); s->vdr[vdr_rpu_id] = av_refstruct_allocz(sizeof(AVDOVIDataMapping));
if (!s->vdr[vdr_rpu_id]) { if (!s->vdr[vdr_rpu_id]) {
ff_dovi_ctx_unref(s); ff_dovi_ctx_unref(s);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -675,7 +675,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
} }
if (!s->dm) { if (!s->dm) {
s->dm = ff_refstruct_allocz(sizeof(AVDOVIColorMetadata)); s->dm = av_refstruct_allocz(sizeof(AVDOVIColorMetadata));
if (!s->dm) { if (!s->dm) {
ff_dovi_ctx_unref(s); ff_dovi_ctx_unref(s);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -735,7 +735,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
} }
} else { } else {
s->color = &ff_dovi_color_default; s->color = &ff_dovi_color_default;
ff_refstruct_unref(&s->ext_blocks); av_refstruct_unref(&s->ext_blocks);
} }
return 0; return 0;

View file

@ -29,7 +29,7 @@
#include "itut35.h" #include "itut35.h"
#include "put_bits.h" #include "put_bits.h"
#include "put_golomb.h" #include "put_golomb.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static struct { static struct {
uint64_t pps; // maximum pixels per second uint64_t pps; // maximum pixels per second
@ -601,7 +601,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
use_prev_vdr_rpu = 0; use_prev_vdr_rpu = 0;
if (!s->vdr[vdr_rpu_id]) { if (!s->vdr[vdr_rpu_id]) {
s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping)); s->vdr[vdr_rpu_id] = av_refstruct_allocz(sizeof(AVDOVIDataMapping));
if (!s->vdr[vdr_rpu_id]) if (!s->vdr[vdr_rpu_id])
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -625,12 +625,12 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
* references requires extended compression */ * references requires extended compression */
for (int i = 0; i <= DOVI_MAX_DM_ID; i++) { for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
if (i != vdr_rpu_id) if (i != vdr_rpu_id)
ff_refstruct_unref(&s->vdr[i]); av_refstruct_unref(&s->vdr[i]);
} }
} }
if (metadata->num_ext_blocks && !s->ext_blocks) { if (metadata->num_ext_blocks && !s->ext_blocks) {
s->ext_blocks = ff_refstruct_allocz(sizeof(*s->ext_blocks)); s->ext_blocks = av_refstruct_allocz(sizeof(*s->ext_blocks));
if (!s->ext_blocks) if (!s->ext_blocks)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -640,7 +640,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
vdr_dm_metadata_present = 1; vdr_dm_metadata_present = 1;
if (vdr_dm_metadata_present && !s->dm) { if (vdr_dm_metadata_present && !s->dm) {
s->dm = ff_refstruct_allocz(sizeof(AVDOVIColorMetadata)); s->dm = av_refstruct_allocz(sizeof(AVDOVIColorMetadata));
if (!s->dm) if (!s->dm)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -864,7 +864,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
} }
} else { } else {
s->color = &ff_dovi_color_default; s->color = &ff_dovi_color_default;
ff_refstruct_unref(&s->ext_blocks); av_refstruct_unref(&s->ext_blocks);
} }
flush_put_bits(pb); flush_put_bits(pb);

View file

@ -31,7 +31,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "ffv1.h" #include "ffv1.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
av_cold int ff_ffv1_common_init(AVCodecContext *avctx) av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
{ {
@ -53,7 +53,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
return 0; return 0;
} }
static void planes_free(FFRefStructOpaque opaque, void *obj) static void planes_free(AVRefStructOpaque opaque, void *obj)
{ {
PlaneContext *planes = obj; PlaneContext *planes = obj;
@ -67,7 +67,7 @@ static void planes_free(FFRefStructOpaque opaque, void *obj)
PlaneContext* ff_ffv1_planes_alloc(void) PlaneContext* ff_ffv1_planes_alloc(void)
{ {
return ff_refstruct_alloc_ext(sizeof(PlaneContext) * MAX_PLANES, return av_refstruct_alloc_ext(sizeof(PlaneContext) * MAX_PLANES,
0, NULL, planes_free); 0, NULL, planes_free);
} }
@ -233,10 +233,10 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
av_freep(&sc->sample_buffer); av_freep(&sc->sample_buffer);
av_freep(&sc->sample_buffer32); av_freep(&sc->sample_buffer32);
ff_refstruct_unref(&sc->plane); av_refstruct_unref(&sc->plane);
} }
ff_refstruct_unref(&s->slice_damaged); av_refstruct_unref(&s->slice_damaged);
av_freep(&avctx->stats_out); av_freep(&avctx->stats_out);
for (j = 0; j < s->quant_table_count; j++) { for (j = 0; j < s->quant_table_count; j++) {

View file

@ -38,7 +38,7 @@
#include "mathops.h" #include "mathops.h"
#include "ffv1.h" #include "ffv1.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
@ -780,8 +780,8 @@ static int read_header(FFV1Context *f)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
ff_refstruct_unref(&f->slice_damaged); av_refstruct_unref(&f->slice_damaged);
f->slice_damaged = ff_refstruct_allocz(f->slice_count * sizeof(*f->slice_damaged)); f->slice_damaged = av_refstruct_allocz(f->slice_count * sizeof(*f->slice_damaged));
if (!f->slice_damaged) if (!f->slice_damaged)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -810,7 +810,7 @@ static int read_header(FFV1Context *f)
&& (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height);
} }
ff_refstruct_unref(&sc->plane); av_refstruct_unref(&sc->plane);
sc->plane = ff_ffv1_planes_alloc(); sc->plane = ff_ffv1_planes_alloc();
if (!sc->plane) if (!sc->plane)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -1059,7 +1059,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
FFV1SliceContext *sc = &fdst->slices[i]; FFV1SliceContext *sc = &fdst->slices[i];
const FFV1SliceContext *sc0 = &fsrc->slices[i]; const FFV1SliceContext *sc0 = &fsrc->slices[i];
ff_refstruct_replace(&sc->plane, sc0->plane); av_refstruct_replace(&sc->plane, sc0->plane);
if (fsrc->version < 3) { if (fsrc->version < 3) {
sc->slice_x = sc0->slice_x; sc->slice_x = sc0->slice_x;
@ -1069,7 +1069,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
} }
} }
ff_refstruct_replace(&fdst->slice_damaged, fsrc->slice_damaged); av_refstruct_replace(&fdst->slice_damaged, fsrc->slice_damaged);
av_assert1(fdst->max_slice_count == fsrc->max_slice_count); av_assert1(fdst->max_slice_count == fsrc->max_slice_count);

View file

@ -32,7 +32,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
typedef struct FramePool { typedef struct FramePool {
/** /**
@ -53,7 +53,7 @@ typedef struct FramePool {
int samples; int samples;
} FramePool; } FramePool;
static void frame_pool_free(FFRefStructOpaque unused, void *obj) static void frame_pool_free(AVRefStructOpaque unused, void *obj)
{ {
FramePool *pool = obj; FramePool *pool = obj;
int i; int i;
@ -77,7 +77,7 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
return 0; return 0;
} }
pool = ff_refstruct_alloc_ext(sizeof(*pool), 0, NULL, frame_pool_free); pool = av_refstruct_alloc_ext(sizeof(*pool), 0, NULL, frame_pool_free);
if (!pool) if (!pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -157,12 +157,12 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
default: av_assert0(0); default: av_assert0(0);
} }
ff_refstruct_unref(&avctx->internal->pool); av_refstruct_unref(&avctx->internal->pool);
avctx->internal->pool = pool; avctx->internal->pool = pool;
return 0; return 0;
fail: fail:
ff_refstruct_unref(&pool); av_refstruct_unref(&pool);
return ret; return ret;
} }

View file

@ -32,6 +32,7 @@
#include "libavutil/film_grain_params.h" #include "libavutil/film_grain_params.h"
#include "libavutil/mastering_display_metadata.h" #include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/refstruct.h"
#include "libavutil/stereo3d.h" #include "libavutil/stereo3d.h"
#include "atsc_a53.h" #include "atsc_a53.h"
@ -42,7 +43,6 @@
#include "golomb.h" #include "golomb.h"
#include "h2645_sei.h" #include "h2645_sei.h"
#include "itut35.h" #include "itut35.h"
#include "refstruct.h"
#define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI) #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
#define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI) #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
@ -496,8 +496,8 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type,
case SEI_TYPE_DISPLAY_ORIENTATION: case SEI_TYPE_DISPLAY_ORIENTATION:
return decode_display_orientation(&h->display_orientation, gb); return decode_display_orientation(&h->display_orientation, gb);
case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS: case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
ff_refstruct_unref(&h->film_grain_characteristics); av_refstruct_unref(&h->film_grain_characteristics);
h->film_grain_characteristics = ff_refstruct_allocz(sizeof(*h->film_grain_characteristics)); h->film_grain_characteristics = av_refstruct_allocz(sizeof(*h->film_grain_characteristics));
if (!h->film_grain_characteristics) if (!h->film_grain_characteristics)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb); return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb);
@ -559,7 +559,7 @@ int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
dst->mastering_display = src->mastering_display; dst->mastering_display = src->mastering_display;
dst->content_light = src->content_light; dst->content_light = src->content_light;
ff_refstruct_replace(&dst->film_grain_characteristics, av_refstruct_replace(&dst->film_grain_characteristics,
src->film_grain_characteristics); src->film_grain_characteristics);
return 0; return 0;
@ -934,6 +934,6 @@ void ff_h2645_sei_reset(H2645SEI *s)
s->mastering_display.present = 0; s->mastering_display.present = 0;
s->content_light.present = 0; s->content_light.present = 0;
ff_refstruct_unref(&s->film_grain_characteristics); av_refstruct_unref(&s->film_grain_characteristics);
ff_aom_uninit_film_grain_params(&s->aom_film_grain); ff_aom_uninit_film_grain_params(&s->aom_film_grain);
} }

View file

@ -47,7 +47,7 @@
#include "h264data.h" #include "h264data.h"
#include "mpegutils.h" #include "mpegutils.h"
#include "parser.h" #include "parser.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "startcode.h" #include "startcode.h"
typedef struct H264ParseContext { typedef struct H264ParseContext {
@ -374,7 +374,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
goto fail; goto fail;
} }
ff_refstruct_replace(&p->ps.pps, p->ps.pps_list[pps_id]); av_refstruct_replace(&p->ps.pps, p->ps.pps_list[pps_id]);
p->ps.sps = p->ps.pps->sps; p->ps.sps = p->ps.pps->sps;
sps = p->ps.sps; sps = p->ps.sps;

View file

@ -32,7 +32,7 @@
#include "h264dec.h" #include "h264dec.h"
#include "hwaccel_internal.h" #include "hwaccel_internal.h"
#include "mpegutils.h" #include "mpegutils.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadframe.h" #include "threadframe.h"
@ -46,35 +46,35 @@ void ff_h264_unref_picture(H264Picture *pic)
ff_thread_release_ext_buffer(&pic->tf); ff_thread_release_ext_buffer(&pic->tf);
av_frame_unref(pic->f_grain); av_frame_unref(pic->f_grain);
ff_refstruct_unref(&pic->hwaccel_picture_private); av_refstruct_unref(&pic->hwaccel_picture_private);
ff_refstruct_unref(&pic->qscale_table_base); av_refstruct_unref(&pic->qscale_table_base);
ff_refstruct_unref(&pic->mb_type_base); av_refstruct_unref(&pic->mb_type_base);
ff_refstruct_unref(&pic->pps); av_refstruct_unref(&pic->pps);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
ff_refstruct_unref(&pic->motion_val_base[i]); av_refstruct_unref(&pic->motion_val_base[i]);
ff_refstruct_unref(&pic->ref_index[i]); av_refstruct_unref(&pic->ref_index[i]);
} }
ff_refstruct_unref(&pic->decode_error_flags); av_refstruct_unref(&pic->decode_error_flags);
memset((uint8_t*)pic + off, 0, sizeof(*pic) - off); memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
} }
static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src) static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src)
{ {
ff_refstruct_replace(&dst->qscale_table_base, src->qscale_table_base); av_refstruct_replace(&dst->qscale_table_base, src->qscale_table_base);
ff_refstruct_replace(&dst->mb_type_base, src->mb_type_base); av_refstruct_replace(&dst->mb_type_base, src->mb_type_base);
ff_refstruct_replace(&dst->pps, src->pps); av_refstruct_replace(&dst->pps, src->pps);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
ff_refstruct_replace(&dst->motion_val_base[i], src->motion_val_base[i]); av_refstruct_replace(&dst->motion_val_base[i], src->motion_val_base[i]);
ff_refstruct_replace(&dst->ref_index[i], src->ref_index[i]); av_refstruct_replace(&dst->ref_index[i], src->ref_index[i]);
} }
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
ff_refstruct_replace(&dst->decode_error_flags, src->decode_error_flags); av_refstruct_replace(&dst->decode_error_flags, src->decode_error_flags);
dst->qscale_table = src->qscale_table; dst->qscale_table = src->qscale_table;
dst->mb_type = src->mb_type; dst->mb_type = src->mb_type;

View file

@ -34,7 +34,7 @@
#include "h2645_vui.h" #include "h2645_vui.h"
#include "h264_ps.h" #include "h264_ps.h"
#include "golomb.h" #include "golomb.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#define MIN_LOG2_MAX_FRAME_NUM 4 #define MIN_LOG2_MAX_FRAME_NUM 4
@ -86,7 +86,7 @@ static const int level_max_dpb_mbs[][2] = {
static void remove_pps(H264ParamSets *s, int id) static void remove_pps(H264ParamSets *s, int id)
{ {
ff_refstruct_unref(&s->pps_list[id]); av_refstruct_unref(&s->pps_list[id]);
} }
static void remove_sps(H264ParamSets *s, int id) static void remove_sps(H264ParamSets *s, int id)
@ -100,7 +100,7 @@ static void remove_sps(H264ParamSets *s, int id)
remove_pps(s, i); remove_pps(s, i);
} }
#endif #endif
ff_refstruct_unref(&s->sps_list[id]); av_refstruct_unref(&s->sps_list[id]);
} }
static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx, static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx,
@ -272,12 +272,12 @@ void ff_h264_ps_uninit(H264ParamSets *ps)
int i; int i;
for (i = 0; i < MAX_SPS_COUNT; i++) for (i = 0; i < MAX_SPS_COUNT; i++)
ff_refstruct_unref(&ps->sps_list[i]); av_refstruct_unref(&ps->sps_list[i]);
for (i = 0; i < MAX_PPS_COUNT; i++) for (i = 0; i < MAX_PPS_COUNT; i++)
ff_refstruct_unref(&ps->pps_list[i]); av_refstruct_unref(&ps->pps_list[i]);
ff_refstruct_unref(&ps->pps); av_refstruct_unref(&ps->pps);
ps->sps = NULL; ps->sps = NULL;
} }
@ -290,7 +290,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
SPS *sps; SPS *sps;
int ret; int ret;
sps = ff_refstruct_allocz(sizeof(*sps)); sps = av_refstruct_allocz(sizeof(*sps));
if (!sps) if (!sps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -578,7 +578,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
* otherwise drop all PPSes that depend on it */ * otherwise drop all PPSes that depend on it */
if (ps->sps_list[sps_id] && if (ps->sps_list[sps_id] &&
!memcmp(ps->sps_list[sps_id], sps, sizeof(*sps))) { !memcmp(ps->sps_list[sps_id], sps, sizeof(*sps))) {
ff_refstruct_unref(&sps); av_refstruct_unref(&sps);
} else { } else {
remove_sps(ps, sps_id); remove_sps(ps, sps_id);
ps->sps_list[sps_id] = sps; ps->sps_list[sps_id] = sps;
@ -587,7 +587,7 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
return 0; return 0;
fail: fail:
ff_refstruct_unref(&sps); av_refstruct_unref(&sps);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -686,11 +686,11 @@ static int more_rbsp_data_in_pps(const SPS *sps, void *logctx)
return 1; return 1;
} }
static void pps_free(FFRefStructOpaque unused, void *obj) static void pps_free(AVRefStructOpaque unused, void *obj)
{ {
PPS *pps = obj; PPS *pps = obj;
ff_refstruct_unref(&pps->sps); av_refstruct_unref(&pps->sps);
} }
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
@ -708,7 +708,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free); pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free);
if (!pps) if (!pps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -733,7 +733,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
pps->sps = ff_refstruct_ref_c(ps->sps_list[pps->sps_id]); pps->sps = av_refstruct_ref_c(ps->sps_list[pps->sps_id]);
sps = pps->sps; sps = pps->sps;
if (sps->bit_depth_luma > 14) { if (sps->bit_depth_luma > 14) {
@ -840,6 +840,6 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct
return 0; return 0;
fail: fail:
ff_refstruct_unref(&pps); av_refstruct_unref(&pps);
return ret; return ret;
} }

View file

@ -45,7 +45,7 @@
#include "mathops.h" #include "mathops.h"
#include "mpegutils.h" #include "mpegutils.h"
#include "rectangle.h" #include "rectangle.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadframe.h" #include "threadframe.h"
@ -166,19 +166,19 @@ static int init_table_pools(H264Context *h)
const int b4_stride = h->mb_width * 4 + 1; const int b4_stride = h->mb_width * 4 + 1;
const int b4_array_size = b4_stride * h->mb_height * 4; const int b4_array_size = b4_stride * h->mb_height * 4;
h->qscale_table_pool = ff_refstruct_pool_alloc(big_mb_num + h->mb_stride, 0); h->qscale_table_pool = av_refstruct_pool_alloc(big_mb_num + h->mb_stride, 0);
h->mb_type_pool = ff_refstruct_pool_alloc((big_mb_num + h->mb_stride) * h->mb_type_pool = av_refstruct_pool_alloc((big_mb_num + h->mb_stride) *
sizeof(uint32_t), 0); sizeof(uint32_t), 0);
h->motion_val_pool = ff_refstruct_pool_alloc(2 * (b4_array_size + 4) * h->motion_val_pool = av_refstruct_pool_alloc(2 * (b4_array_size + 4) *
sizeof(int16_t), 0); sizeof(int16_t), 0);
h->ref_index_pool = ff_refstruct_pool_alloc(4 * mb_array_size, 0); h->ref_index_pool = av_refstruct_pool_alloc(4 * mb_array_size, 0);
if (!h->qscale_table_pool || !h->mb_type_pool || !h->motion_val_pool || if (!h->qscale_table_pool || !h->mb_type_pool || !h->motion_val_pool ||
!h->ref_index_pool) { !h->ref_index_pool) {
ff_refstruct_pool_uninit(&h->qscale_table_pool); av_refstruct_pool_uninit(&h->qscale_table_pool);
ff_refstruct_pool_uninit(&h->mb_type_pool); av_refstruct_pool_uninit(&h->mb_type_pool);
ff_refstruct_pool_uninit(&h->motion_val_pool); av_refstruct_pool_uninit(&h->motion_val_pool);
ff_refstruct_pool_uninit(&h->ref_index_pool); av_refstruct_pool_uninit(&h->ref_index_pool);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -211,7 +211,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
goto fail; goto fail;
if (h->decode_error_flags_pool) { if (h->decode_error_flags_pool) {
pic->decode_error_flags = ff_refstruct_pool_get(h->decode_error_flags_pool); pic->decode_error_flags = av_refstruct_pool_get(h->decode_error_flags_pool);
if (!pic->decode_error_flags) if (!pic->decode_error_flags)
goto fail; goto fail;
atomic_init(pic->decode_error_flags, 0); atomic_init(pic->decode_error_flags, 0);
@ -236,8 +236,8 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
goto fail; goto fail;
} }
pic->qscale_table_base = ff_refstruct_pool_get(h->qscale_table_pool); pic->qscale_table_base = av_refstruct_pool_get(h->qscale_table_pool);
pic->mb_type_base = ff_refstruct_pool_get(h->mb_type_pool); pic->mb_type_base = av_refstruct_pool_get(h->mb_type_pool);
if (!pic->qscale_table_base || !pic->mb_type_base) if (!pic->qscale_table_base || !pic->mb_type_base)
goto fail; goto fail;
@ -245,15 +245,15 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
pic->qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1; pic->qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
pic->motion_val_base[i] = ff_refstruct_pool_get(h->motion_val_pool); pic->motion_val_base[i] = av_refstruct_pool_get(h->motion_val_pool);
pic->ref_index[i] = ff_refstruct_pool_get(h->ref_index_pool); pic->ref_index[i] = av_refstruct_pool_get(h->ref_index_pool);
if (!pic->motion_val_base[i] || !pic->ref_index[i]) if (!pic->motion_val_base[i] || !pic->ref_index[i])
goto fail; goto fail;
pic->motion_val[i] = pic->motion_val_base[i] + 4; pic->motion_val[i] = pic->motion_val_base[i] + 4;
} }
pic->pps = ff_refstruct_ref_c(h->ps.pps); pic->pps = av_refstruct_ref_c(h->ps.pps);
pic->mb_width = h->mb_width; pic->mb_width = h->mb_width;
pic->mb_height = h->mb_height; pic->mb_height = h->mb_height;
@ -358,11 +358,11 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
// SPS/PPS // SPS/PPS
for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++)
ff_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); av_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++)
ff_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); av_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]);
ff_refstruct_replace(&h->ps.pps, h1->ps.pps); av_refstruct_replace(&h->ps.pps, h1->ps.pps);
h->ps.sps = h1->ps.sps; h->ps.sps = h1->ps.sps;
if (need_reinit || !inited) { if (need_reinit || !inited) {
@ -1050,7 +1050,7 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl
int needs_reinit = 0, must_reinit, ret; int needs_reinit = 0, must_reinit, ret;
if (first_slice) if (first_slice)
ff_refstruct_replace(&h->ps.pps, h->ps.pps_list[sl->pps_id]); av_refstruct_replace(&h->ps.pps, h->ps.pps_list[sl->pps_id]);
if (h->ps.sps != h->ps.pps->sps) { if (h->ps.sps != h->ps.pps->sps) {
h->ps.sps = h->ps.pps->sps; h->ps.sps = h->ps.pps->sps;

View file

@ -52,7 +52,7 @@
#include "mpegutils.h" #include "mpegutils.h"
#include "profiles.h" #include "profiles.h"
#include "rectangle.h" #include "rectangle.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadframe.h" #include "threadframe.h"
@ -156,10 +156,10 @@ void ff_h264_free_tables(H264Context *h)
av_freep(&h->mb2b_xy); av_freep(&h->mb2b_xy);
av_freep(&h->mb2br_xy); av_freep(&h->mb2br_xy);
ff_refstruct_pool_uninit(&h->qscale_table_pool); av_refstruct_pool_uninit(&h->qscale_table_pool);
ff_refstruct_pool_uninit(&h->mb_type_pool); av_refstruct_pool_uninit(&h->mb_type_pool);
ff_refstruct_pool_uninit(&h->motion_val_pool); av_refstruct_pool_uninit(&h->motion_val_pool);
ff_refstruct_pool_uninit(&h->ref_index_pool); av_refstruct_pool_uninit(&h->ref_index_pool);
#if CONFIG_ERROR_RESILIENCE #if CONFIG_ERROR_RESILIENCE
av_freep(&h->er.mb_index2xy); av_freep(&h->er.mb_index2xy);
@ -313,7 +313,7 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h)
ff_h264_sei_uninit(&h->sei); ff_h264_sei_uninit(&h->sei);
if (avctx->active_thread_type & FF_THREAD_FRAME) { if (avctx->active_thread_type & FF_THREAD_FRAME) {
h->decode_error_flags_pool = ff_refstruct_pool_alloc(sizeof(atomic_int), 0); h->decode_error_flags_pool = av_refstruct_pool_alloc(sizeof(atomic_int), 0);
if (!h->decode_error_flags_pool) if (!h->decode_error_flags_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -364,7 +364,7 @@ static av_cold int h264_decode_end(AVCodecContext *avctx)
h->cur_pic_ptr = NULL; h->cur_pic_ptr = NULL;
ff_refstruct_pool_uninit(&h->decode_error_flags_pool); av_refstruct_pool_uninit(&h->decode_error_flags_pool);
av_freep(&h->slice_ctx); av_freep(&h->slice_ctx);
h->nb_slice_ctx = 0; h->nb_slice_ctx = 0;

View file

@ -570,11 +570,11 @@ typedef struct H264Context {
H264SEIContext sei; H264SEIContext sei;
struct FFRefStructPool *qscale_table_pool; struct AVRefStructPool *qscale_table_pool;
struct FFRefStructPool *mb_type_pool; struct AVRefStructPool *mb_type_pool;
struct FFRefStructPool *motion_val_pool; struct AVRefStructPool *motion_val_pool;
struct FFRefStructPool *ref_index_pool; struct AVRefStructPool *ref_index_pool;
struct FFRefStructPool *decode_error_flags_pool; struct AVRefStructPool *decode_error_flags_pool;
int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
int non_gray; ///< Did we encounter a intra frame after a gray gap frame int non_gray; ///< Did we encounter a intra frame after a gray gap frame

View file

@ -52,7 +52,7 @@
#include "internal.h" #include "internal.h"
#include "profiles.h" #include "profiles.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadprogress.h" #include "threadprogress.h"
@ -92,8 +92,8 @@ static void pic_arrays_free(HEVCLayerContext *l)
av_freep(&l->sao_pixel_buffer_v[i]); av_freep(&l->sao_pixel_buffer_v[i]);
} }
ff_refstruct_pool_uninit(&l->tab_mvf_pool); av_refstruct_pool_uninit(&l->tab_mvf_pool);
ff_refstruct_pool_uninit(&l->rpl_tab_pool); av_refstruct_pool_uninit(&l->rpl_tab_pool);
} }
/* allocate arrays that depend on frame dimensions */ /* allocate arrays that depend on frame dimensions */
@ -139,8 +139,8 @@ static int pic_arrays_init(HEVCLayerContext *l, const HEVCSPS *sps)
if (!l->horizontal_bs || !l->vertical_bs) if (!l->horizontal_bs || !l->vertical_bs)
goto fail; goto fail;
l->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); l->tab_mvf_pool = av_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0);
l->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); l->rpl_tab_pool = av_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0);
if (!l->tab_mvf_pool || !l->rpl_tab_pool) if (!l->tab_mvf_pool || !l->rpl_tab_pool)
goto fail; goto fail;
@ -677,8 +677,8 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
int ret; int ret;
pic_arrays_free(l); pic_arrays_free(l);
ff_refstruct_unref(&l->sps); av_refstruct_unref(&l->sps);
ff_refstruct_unref(&s->vps); av_refstruct_unref(&s->vps);
if (!sps) if (!sps)
return 0; return 0;
@ -691,14 +691,14 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps)
ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
ff_videodsp_init (&s->vdsp, sps->bit_depth); ff_videodsp_init (&s->vdsp, sps->bit_depth);
l->sps = ff_refstruct_ref_c(sps); l->sps = av_refstruct_ref_c(sps);
s->vps = ff_refstruct_ref_c(sps->vps); s->vps = av_refstruct_ref_c(sps->vps);
return 0; return 0;
fail: fail:
pic_arrays_free(l); pic_arrays_free(l);
ff_refstruct_unref(&l->sps); av_refstruct_unref(&l->sps);
return ret; return ret;
} }
@ -3162,7 +3162,7 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
ff_refstruct_replace(&s->pps, pps); av_refstruct_replace(&s->pps, pps);
if (l->sps != sps) { if (l->sps != sps) {
const HEVCSPS *sps_base = s->layers[0].sps; const HEVCSPS *sps_base = s->layers[0].sps;
enum AVPixelFormat pix_fmt = sps->pix_fmt; enum AVPixelFormat pix_fmt = sps->pix_fmt;
@ -3811,10 +3811,10 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
dst->needs_fg = 1; dst->needs_fg = 1;
} }
dst->pps = ff_refstruct_ref_c(src->pps); dst->pps = av_refstruct_ref_c(src->pps);
dst->tab_mvf = ff_refstruct_ref(src->tab_mvf); dst->tab_mvf = av_refstruct_ref(src->tab_mvf);
dst->rpl_tab = ff_refstruct_ref(src->rpl_tab); dst->rpl_tab = av_refstruct_ref(src->rpl_tab);
dst->rpl = ff_refstruct_ref(src->rpl); dst->rpl = av_refstruct_ref(src->rpl);
dst->nb_rpl_elems = src->nb_rpl_elems; dst->nb_rpl_elems = src->nb_rpl_elems;
dst->poc = src->poc; dst->poc = src->poc;
@ -3823,7 +3823,7 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
dst->base_layer_frame = src->base_layer_frame; dst->base_layer_frame = src->base_layer_frame;
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
return 0; return 0;
@ -3835,11 +3835,11 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
pic_arrays_free(&s->layers[i]); pic_arrays_free(&s->layers[i]);
ff_refstruct_unref(&s->layers[i].sps); av_refstruct_unref(&s->layers[i].sps);
} }
ff_refstruct_unref(&s->vps); av_refstruct_unref(&s->vps);
ff_refstruct_unref(&s->pps); av_refstruct_unref(&s->pps);
ff_dovi_ctx_unref(&s->dovi_ctx); ff_dovi_ctx_unref(&s->dovi_ctx);
av_buffer_unref(&s->rpu_buf); av_buffer_unref(&s->rpu_buf);
@ -3945,16 +3945,16 @@ static int hevc_update_thread_context(AVCodecContext *dst,
} }
for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++)
ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); av_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++)
ff_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); av_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++)
ff_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); av_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
// PPS do not persist between frames // PPS do not persist between frames
ff_refstruct_unref(&s->pps); av_refstruct_unref(&s->pps);
s->poc_tid0 = s0->poc_tid0; s->poc_tid0 = s0->poc_tid0;
s->eos = s0->eos; s->eos = s0->eos;

View file

@ -480,8 +480,8 @@ typedef struct HEVCLayerContext {
uint8_t *sao_pixel_buffer_h[3]; uint8_t *sao_pixel_buffer_h[3];
uint8_t *sao_pixel_buffer_v[3]; uint8_t *sao_pixel_buffer_v[3];
struct FFRefStructPool *tab_mvf_pool; struct AVRefStructPool *tab_mvf_pool;
struct FFRefStructPool *rpl_tab_pool; struct AVRefStructPool *rpl_tab_pool;
} HEVCLayerContext; } HEVCLayerContext;
typedef struct HEVCContext { typedef struct HEVCContext {

View file

@ -30,7 +30,7 @@
#include "data.h" #include "data.h"
#include "ps.h" #include "ps.h"
#include "profiles.h" #include "profiles.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static const uint8_t default_scaling_list_intra[] = { static const uint8_t default_scaling_list_intra[] = {
16, 16, 16, 16, 17, 18, 21, 24, 16, 16, 16, 16, 17, 18, 21, 24,
@ -69,9 +69,9 @@ static void remove_sps(HEVCParamSets *s, int id)
/* drop all PPS that depend on this SPS */ /* drop all PPS that depend on this SPS */
for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
if (s->pps_list[i] && s->pps_list[i]->sps_id == id) if (s->pps_list[i] && s->pps_list[i]->sps_id == id)
ff_refstruct_unref(&s->pps_list[i]); av_refstruct_unref(&s->pps_list[i]);
ff_refstruct_unref(&s->sps_list[id]); av_refstruct_unref(&s->sps_list[id]);
} }
} }
@ -82,7 +82,7 @@ static void remove_vps(HEVCParamSets *s, int id)
for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)
if (s->sps_list[i] && s->sps_list[i]->vps_id == id) if (s->sps_list[i] && s->sps_list[i]->vps_id == id)
remove_sps(s, i); remove_sps(s, i);
ff_refstruct_unref(&s->vps_list[id]); av_refstruct_unref(&s->vps_list[id]);
} }
} }
@ -442,7 +442,7 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
return 0; return 0;
} }
static void hevc_vps_free(FFRefStructOpaque opaque, void *obj) static void hevc_vps_free(AVRefStructOpaque opaque, void *obj)
{ {
HEVCVPS *vps = obj; HEVCVPS *vps = obj;
@ -730,7 +730,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
return 0; return 0;
} }
vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, hevc_vps_free); vps = av_refstruct_alloc_ext(sizeof(*vps), 0, NULL, hevc_vps_free);
if (!vps) if (!vps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -864,7 +864,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
return 0; return 0;
err: err:
ff_refstruct_unref(&vps); av_refstruct_unref(&vps);
return ret; return ret;
} }
@ -1171,7 +1171,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
sps->vps_id); sps->vps_id);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
sps->vps = ff_refstruct_ref_c(vps_list[sps->vps_id]); sps->vps = av_refstruct_ref_c(vps_list[sps->vps_id]);
} }
sps->max_sub_layers = get_bits(gb, 3) + 1; sps->max_sub_layers = get_bits(gb, 3) + 1;
@ -1632,11 +1632,11 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
return 0; return 0;
} }
static void hevc_sps_free(FFRefStructOpaque opaque, void *obj) static void hevc_sps_free(AVRefStructOpaque opaque, void *obj)
{ {
HEVCSPS *sps = obj; HEVCSPS *sps = obj;
ff_refstruct_unref(&sps->vps); av_refstruct_unref(&sps->vps);
av_freep(&sps->data); av_freep(&sps->data);
} }
@ -1651,7 +1651,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
HEVCParamSets *ps, unsigned nuh_layer_id, HEVCParamSets *ps, unsigned nuh_layer_id,
int apply_defdispwin) int apply_defdispwin)
{ {
HEVCSPS *sps = ff_refstruct_alloc_ext(sizeof(*sps), 0, NULL, hevc_sps_free); HEVCSPS *sps = av_refstruct_alloc_ext(sizeof(*sps), 0, NULL, hevc_sps_free);
unsigned int sps_id; unsigned int sps_id;
int ret; int ret;
@ -1688,7 +1688,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
* otherwise drop all PPSes that depend on it */ * otherwise drop all PPSes that depend on it */
if (ps->sps_list[sps_id] && if (ps->sps_list[sps_id] &&
compare_sps(ps->sps_list[sps_id], sps)) { compare_sps(ps->sps_list[sps_id], sps)) {
ff_refstruct_unref(&sps); av_refstruct_unref(&sps);
} else { } else {
remove_sps(ps, sps_id); remove_sps(ps, sps_id);
ps->sps_list[sps_id] = sps; ps->sps_list[sps_id] = sps;
@ -1696,15 +1696,15 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
return 0; return 0;
err: err:
ff_refstruct_unref(&sps); av_refstruct_unref(&sps);
return ret; return ret;
} }
static void hevc_pps_free(FFRefStructOpaque unused, void *obj) static void hevc_pps_free(AVRefStructOpaque unused, void *obj)
{ {
HEVCPPS *pps = obj; HEVCPPS *pps = obj;
ff_refstruct_unref(&pps->sps); av_refstruct_unref(&pps->sps);
av_freep(&pps->column_width); av_freep(&pps->column_width);
av_freep(&pps->row_height); av_freep(&pps->row_height);
@ -2134,7 +2134,7 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
return 0; return 0;
} }
pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free); pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free);
if (!pps) if (!pps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -2171,7 +2171,7 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
sps = ps->sps_list[pps->sps_id]; sps = ps->sps_list[pps->sps_id];
vps = ps->vps_list[sps->vps_id]; vps = ps->vps_list[sps->vps_id];
pps->sps = ff_refstruct_ref_c(sps); pps->sps = av_refstruct_ref_c(sps);
pps->dependent_slice_segments_enabled_flag = get_bits1(gb); pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
pps->output_flag_present_flag = get_bits1(gb); pps->output_flag_present_flag = get_bits1(gb);
@ -2371,13 +2371,13 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
"Overread PPS by %d bits\n", -get_bits_left(gb)); "Overread PPS by %d bits\n", -get_bits_left(gb));
} }
ff_refstruct_unref(&ps->pps_list[pps_id]); av_refstruct_unref(&ps->pps_list[pps_id]);
ps->pps_list[pps_id] = pps; ps->pps_list[pps_id] = pps;
return 0; return 0;
err: err:
ff_refstruct_unref(&pps); av_refstruct_unref(&pps);
return ret; return ret;
} }
@ -2386,11 +2386,11 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps)
int i; int i;
for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++)
ff_refstruct_unref(&ps->vps_list[i]); av_refstruct_unref(&ps->vps_list[i]);
for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
ff_refstruct_unref(&ps->sps_list[i]); av_refstruct_unref(&ps->sps_list[i]);
for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
ff_refstruct_unref(&ps->pps_list[i]); av_refstruct_unref(&ps->pps_list[i]);
} }
int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type)

View file

@ -29,7 +29,7 @@
#include "hevc.h" #include "hevc.h"
#include "hevcdec.h" #include "hevcdec.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
void ff_hevc_unref_frame(HEVCFrame *frame, int flags) void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
{ {
@ -39,15 +39,15 @@ void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
av_frame_unref(frame->frame_grain); av_frame_unref(frame->frame_grain);
frame->needs_fg = 0; frame->needs_fg = 0;
ff_refstruct_unref(&frame->pps); av_refstruct_unref(&frame->pps);
ff_refstruct_unref(&frame->tab_mvf); av_refstruct_unref(&frame->tab_mvf);
ff_refstruct_unref(&frame->rpl); av_refstruct_unref(&frame->rpl);
frame->nb_rpl_elems = 0; frame->nb_rpl_elems = 0;
ff_refstruct_unref(&frame->rpl_tab); av_refstruct_unref(&frame->rpl_tab);
frame->refPicList = NULL; frame->refPicList = NULL;
ff_refstruct_unref(&frame->hwaccel_picture_private); av_refstruct_unref(&frame->hwaccel_picture_private);
} }
} }
@ -135,16 +135,16 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
if (ret < 0) if (ret < 0)
return NULL; return NULL;
frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl)); frame->rpl = av_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
if (!frame->rpl) if (!frame->rpl)
goto fail; goto fail;
frame->nb_rpl_elems = s->pkt.nb_nals; frame->nb_rpl_elems = s->pkt.nb_nals;
frame->tab_mvf = ff_refstruct_pool_get(l->tab_mvf_pool); frame->tab_mvf = av_refstruct_pool_get(l->tab_mvf_pool);
if (!frame->tab_mvf) if (!frame->tab_mvf)
goto fail; goto fail;
frame->rpl_tab = ff_refstruct_pool_get(l->rpl_tab_pool); frame->rpl_tab = av_refstruct_pool_get(l->rpl_tab_pool);
if (!frame->rpl_tab) if (!frame->rpl_tab)
goto fail; goto fail;
frame->ctb_count = l->sps->ctb_width * l->sps->ctb_height; frame->ctb_count = l->sps->ctb_width * l->sps->ctb_height;
@ -161,7 +161,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
if (ret < 0) if (ret < 0)
goto fail; goto fail;
frame->pps = ff_refstruct_ref_c(s->pps); frame->pps = av_refstruct_ref_c(s->pps);
return frame; return frame;
fail: fail:

View file

@ -26,7 +26,7 @@
#include <stdint.h> #include <stdint.h>
#include "avcodec.h" #include "avcodec.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#define HWACCEL_CAP_ASYNC_SAFE (1 << 0) #define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
#define HWACCEL_CAP_THREAD_SAFE (1 << 1) #define HWACCEL_CAP_THREAD_SAFE (1 << 1)
@ -155,7 +155,7 @@ typedef struct FFHWAccel {
* @param hwctx a pointer to an AVHWDeviceContext. * @param hwctx a pointer to an AVHWDeviceContext.
* @param data the per-frame hardware accelerator private data to be freed. * @param data the per-frame hardware accelerator private data to be freed.
*/ */
void (*free_frame_priv)(FFRefStructOpaque hwctx, void *data); void (*free_frame_priv)(AVRefStructOpaque hwctx, void *data);
/** /**
* Callback to flush the hwaccel state. * Callback to flush the hwaccel state.

View file

@ -68,7 +68,7 @@ typedef struct AVCodecInternal {
struct FramePool *pool; struct FramePool *pool;
struct FFRefStructPool *progress_frame_pool; struct AVRefStructPool *progress_frame_pool;
void *thread_ctx; void *thread_ctx;

View file

@ -23,6 +23,8 @@
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/refstruct.h"
#include "decode.h" #include "decode.h"
#include "lcevcdec.h" #include "lcevcdec.h"
@ -233,7 +235,7 @@ static void event_callback(LCEVC_DecoderHandle dec, LCEVC_Event event,
} }
} }
static void lcevc_free(FFRefStructOpaque unused, void *obj) static void lcevc_free(AVRefStructOpaque unused, void *obj)
{ {
FFLCEVCContext *lcevc = obj; FFLCEVCContext *lcevc = obj;
if (lcevc->initialized) if (lcevc->initialized)
@ -305,7 +307,7 @@ int ff_lcevc_alloc(FFLCEVCContext **plcevc)
{ {
FFLCEVCContext *lcevc = NULL; FFLCEVCContext *lcevc = NULL;
#if CONFIG_LIBLCEVC_DEC #if CONFIG_LIBLCEVC_DEC
lcevc = ff_refstruct_alloc_ext(sizeof(*lcevc), 0, NULL, lcevc_free); lcevc = av_refstruct_alloc_ext(sizeof(*lcevc), 0, NULL, lcevc_free);
if (!lcevc) if (!lcevc)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
#endif #endif
@ -315,5 +317,5 @@ int ff_lcevc_alloc(FFLCEVCContext **plcevc)
void ff_lcevc_unref(void *opaque) void ff_lcevc_unref(void *opaque)
{ {
ff_refstruct_unref(&opaque); av_refstruct_unref(&opaque);
} }

View file

@ -27,7 +27,6 @@
#else #else
typedef uintptr_t LCEVC_DecoderHandle; typedef uintptr_t LCEVC_DecoderHandle;
#endif #endif
#include "refstruct.h"
typedef struct FFLCEVCContext { typedef struct FFLCEVCContext {
LCEVC_DecoderHandle decoder; LCEVC_DecoderHandle decoder;

View file

@ -26,24 +26,24 @@
#include "avcodec.h" #include "avcodec.h"
#include "mpegpicture.h" #include "mpegpicture.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static void mpv_pic_reset(FFRefStructOpaque unused, void *obj) static void mpv_pic_reset(AVRefStructOpaque unused, void *obj)
{ {
MPVPicture *pic = obj; MPVPicture *pic = obj;
av_frame_unref(pic->f); av_frame_unref(pic->f);
ff_thread_progress_reset(&pic->progress); ff_thread_progress_reset(&pic->progress);
ff_refstruct_unref(&pic->hwaccel_picture_private); av_refstruct_unref(&pic->hwaccel_picture_private);
ff_refstruct_unref(&pic->mbskip_table); av_refstruct_unref(&pic->mbskip_table);
ff_refstruct_unref(&pic->qscale_table_base); av_refstruct_unref(&pic->qscale_table_base);
ff_refstruct_unref(&pic->mb_type_base); av_refstruct_unref(&pic->mb_type_base);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
ff_refstruct_unref(&pic->motion_val_base[i]); av_refstruct_unref(&pic->motion_val_base[i]);
ff_refstruct_unref(&pic->ref_index[i]); av_refstruct_unref(&pic->ref_index[i]);
pic->motion_val[i] = NULL; pic->motion_val[i] = NULL;
} }
@ -64,7 +64,7 @@ static void mpv_pic_reset(FFRefStructOpaque unused, void *obj)
pic->coded_picture_number = 0; pic->coded_picture_number = 0;
} }
static int av_cold mpv_pic_init(FFRefStructOpaque opaque, void *obj) static int av_cold mpv_pic_init(AVRefStructOpaque opaque, void *obj)
{ {
MPVPicture *pic = obj; MPVPicture *pic = obj;
int ret, init_progress = (uintptr_t)opaque.nc; int ret, init_progress = (uintptr_t)opaque.nc;
@ -79,7 +79,7 @@ static int av_cold mpv_pic_init(FFRefStructOpaque opaque, void *obj)
return 0; return 0;
} }
static void av_cold mpv_pic_free(FFRefStructOpaque unused, void *obj) static void av_cold mpv_pic_free(AVRefStructOpaque unused, void *obj)
{ {
MPVPicture *pic = obj; MPVPicture *pic = obj;
@ -87,17 +87,17 @@ static void av_cold mpv_pic_free(FFRefStructOpaque unused, void *obj)
av_frame_free(&pic->f); av_frame_free(&pic->f);
} }
av_cold FFRefStructPool *ff_mpv_alloc_pic_pool(int init_progress) av_cold AVRefStructPool *ff_mpv_alloc_pic_pool(int init_progress)
{ {
return ff_refstruct_pool_alloc_ext(sizeof(MPVPicture), return av_refstruct_pool_alloc_ext(sizeof(MPVPicture),
FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR, AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR,
(void*)(uintptr_t)init_progress, (void*)(uintptr_t)init_progress,
mpv_pic_init, mpv_pic_reset, mpv_pic_free, NULL); mpv_pic_init, mpv_pic_reset, mpv_pic_free, NULL);
} }
void ff_mpv_unref_picture(MPVWorkPicture *pic) void ff_mpv_unref_picture(MPVWorkPicture *pic)
{ {
ff_refstruct_unref(&pic->ptr); av_refstruct_unref(&pic->ptr);
memset(pic, 0, sizeof(*pic)); memset(pic, 0, sizeof(*pic));
} }
@ -121,13 +121,13 @@ static void set_workpic_from_pic(MPVWorkPicture *wpic, const MPVPicture *pic)
void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src) void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src)
{ {
av_assert1(dst != src); av_assert1(dst != src);
ff_refstruct_replace(&dst->ptr, src->ptr); av_refstruct_replace(&dst->ptr, src->ptr);
memcpy(dst, src, sizeof(*dst)); memcpy(dst, src, sizeof(*dst));
} }
void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic) void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic)
{ {
ff_refstruct_replace(&wpic->ptr, pic); av_refstruct_replace(&wpic->ptr, pic);
if (!pic) { if (!pic) {
memset(wpic, 0, sizeof(*wpic)); memset(wpic, 0, sizeof(*wpic));
return; return;
@ -207,7 +207,7 @@ static int alloc_picture_tables(BufferPoolContext *pools, MPVPicture *pic,
int mb_height) int mb_height)
{ {
#define GET_BUFFER(name, buf_suffix, idx_suffix) do { \ #define GET_BUFFER(name, buf_suffix, idx_suffix) do { \
pic->name ## buf_suffix idx_suffix = ff_refstruct_pool_get(pools->name ## _pool); \ pic->name ## buf_suffix idx_suffix = av_refstruct_pool_get(pools->name ## _pool); \
if (!pic->name ## buf_suffix idx_suffix) \ if (!pic->name ## buf_suffix idx_suffix) \
return AVERROR(ENOMEM); \ return AVERROR(ENOMEM); \
} while (0) } while (0)

View file

@ -42,11 +42,11 @@ typedef struct ScratchpadContext {
} ScratchpadContext; } ScratchpadContext;
typedef struct BufferPoolContext { typedef struct BufferPoolContext {
struct FFRefStructPool *mbskip_table_pool; struct AVRefStructPool *mbskip_table_pool;
struct FFRefStructPool *qscale_table_pool; struct AVRefStructPool *qscale_table_pool;
struct FFRefStructPool *mb_type_pool; struct AVRefStructPool *mb_type_pool;
struct FFRefStructPool *motion_val_pool; struct AVRefStructPool *motion_val_pool;
struct FFRefStructPool *ref_index_pool; struct AVRefStructPool *ref_index_pool;
int alloc_mb_width; ///< mb_width used to allocate tables int alloc_mb_width; ///< mb_width used to allocate tables
int alloc_mb_height; ///< mb_height used to allocate tables int alloc_mb_height; ///< mb_height used to allocate tables
int alloc_mb_stride; ///< mb_stride used to allocate tables int alloc_mb_stride; ///< mb_stride used to allocate tables
@ -114,7 +114,7 @@ typedef struct MPVWorkPicture {
/** /**
* Allocate a pool of MPVPictures. * Allocate a pool of MPVPictures.
*/ */
struct FFRefStructPool *ff_mpv_alloc_pic_pool(int init_progress); struct AVRefStructPool *ff_mpv_alloc_pic_pool(int init_progress);
/** /**
* Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself) * Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself)

View file

@ -41,7 +41,7 @@
#include "mpegutils.h" #include "mpegutils.h"
#include "mpegvideo.h" #include "mpegvideo.h"
#include "mpegvideodata.h" #include "mpegvideodata.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
int16_t *block, int n, int qscale) int16_t *block, int n, int qscale)
@ -499,11 +499,11 @@ void ff_mpv_common_defaults(MpegEncContext *s)
static void free_buffer_pools(BufferPoolContext *pools) static void free_buffer_pools(BufferPoolContext *pools)
{ {
ff_refstruct_pool_uninit(&pools->mbskip_table_pool); av_refstruct_pool_uninit(&pools->mbskip_table_pool);
ff_refstruct_pool_uninit(&pools->qscale_table_pool); av_refstruct_pool_uninit(&pools->qscale_table_pool);
ff_refstruct_pool_uninit(&pools->mb_type_pool); av_refstruct_pool_uninit(&pools->mb_type_pool);
ff_refstruct_pool_uninit(&pools->motion_val_pool); av_refstruct_pool_uninit(&pools->motion_val_pool);
ff_refstruct_pool_uninit(&pools->ref_index_pool); av_refstruct_pool_uninit(&pools->ref_index_pool);
pools->alloc_mb_height = pools->alloc_mb_width = pools->alloc_mb_stride = 0; pools->alloc_mb_height = pools->alloc_mb_width = pools->alloc_mb_stride = 0;
} }
@ -557,7 +557,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed? s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed?
#define ALLOC_POOL(name, size, flags) do { \ #define ALLOC_POOL(name, size, flags) do { \
pools->name ##_pool = ff_refstruct_pool_alloc((size), (flags)); \ pools->name ##_pool = av_refstruct_pool_alloc((size), (flags)); \
if (!pools->name ##_pool) \ if (!pools->name ##_pool) \
return AVERROR(ENOMEM); \ return AVERROR(ENOMEM); \
} while (0) } while (0)
@ -578,7 +578,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
} }
if (s->codec_id == AV_CODEC_ID_MPEG4) { if (s->codec_id == AV_CODEC_ID_MPEG4) {
ALLOC_POOL(mbskip_table, mb_array_size + 2, ALLOC_POOL(mbskip_table, mb_array_size + 2,
!s->encoding ? FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME : 0); !s->encoding ? AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME : 0);
if (!s->encoding) { if (!s->encoding) {
/* cbp, pred_dir */ /* cbp, pred_dir */
if (!(s->cbp_table = av_mallocz(mb_array_size)) || if (!(s->cbp_table = av_mallocz(mb_array_size)) ||
@ -626,7 +626,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
/* FIXME: The output of H.263 with OBMC depends upon /* FIXME: The output of H.263 with OBMC depends upon
* the earlier content of the buffer; therefore we set * the earlier content of the buffer; therefore we set
* the flags to always reset returned buffers here. */ * the flags to always reset returned buffers here. */
ALLOC_POOL(motion_val, mv_size, FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); ALLOC_POOL(motion_val, mv_size, AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
ALLOC_POOL(ref_index, ref_index_size, 0); ALLOC_POOL(ref_index, ref_index_size, 0);
} }
#undef ALLOC_POOL #undef ALLOC_POOL

View file

@ -128,7 +128,7 @@ typedef struct MpegEncContext {
int mb_num; ///< number of MBs of a picture int mb_num; ///< number of MBs of a picture
ptrdiff_t linesize; ///< line size, in bytes, may be different from width ptrdiff_t linesize; ///< line size, in bytes, may be different from width
ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width
struct FFRefStructPool *picture_pool; ///< Pool for MPVPictures struct AVRefStructPool *picture_pool; ///< Pool for MPVPictures
MPVPicture **input_picture;///< next pictures on display order for encoding MPVPicture **input_picture;///< next pictures on display order for encoding
MPVPicture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding MPVPicture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding

View file

@ -38,7 +38,7 @@
#include "mpegvideo.h" #include "mpegvideo.h"
#include "mpegvideodec.h" #include "mpegvideodec.h"
#include "mpeg4videodec.h" #include "mpeg4videodec.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadprogress.h" #include "threadprogress.h"
#include "wmv2dec.h" #include "wmv2dec.h"
@ -164,7 +164,7 @@ int ff_mpv_decode_close(AVCodecContext *avctx)
{ {
MpegEncContext *s = avctx->priv_data; MpegEncContext *s = avctx->priv_data;
ff_refstruct_pool_uninit(&s->picture_pool); av_refstruct_pool_uninit(&s->picture_pool);
ff_mpv_common_end(s); ff_mpv_common_end(s);
return 0; return 0;
} }
@ -216,7 +216,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s)
static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference)
{ {
AVCodecContext *avctx = s->avctx; AVCodecContext *avctx = s->avctx;
MPVPicture *pic = ff_refstruct_pool_get(s->picture_pool); MPVPicture *pic = av_refstruct_pool_get(s->picture_pool);
int ret; int ret;
if (!pic) if (!pic)

View file

@ -75,7 +75,7 @@
#include "wmv2enc.h" #include "wmv2enc.h"
#include "rv10enc.h" #include "rv10enc.h"
#include "packet_internal.h" #include "packet_internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include <limits.h> #include <limits.h>
#include "sp5x.h" #include "sp5x.h"
@ -1033,12 +1033,12 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
ff_rate_control_uninit(&s->rc_context); ff_rate_control_uninit(&s->rc_context);
ff_mpv_common_end(s); ff_mpv_common_end(s);
ff_refstruct_pool_uninit(&s->picture_pool); av_refstruct_pool_uninit(&s->picture_pool);
if (s->input_picture && s->reordered_input_picture) { if (s->input_picture && s->reordered_input_picture) {
for (int i = 0; i < MAX_B_FRAMES + 1; i++) { for (int i = 0; i < MAX_B_FRAMES + 1; i++) {
ff_refstruct_unref(&s->input_picture[i]); av_refstruct_unref(&s->input_picture[i]);
ff_refstruct_unref(&s->reordered_input_picture[i]); av_refstruct_unref(&s->reordered_input_picture[i]);
} }
} }
for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++) for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
@ -1232,7 +1232,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0], ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0],
pic_arg->linesize[1], s->linesize, s->uvlinesize); pic_arg->linesize[1], s->linesize, s->uvlinesize);
pic = ff_refstruct_pool_get(s->picture_pool); pic = av_refstruct_pool_get(s->picture_pool);
if (!pic) if (!pic)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -1311,7 +1311,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
return 0; return 0;
fail: fail:
ff_refstruct_unref(&pic); av_refstruct_unref(&pic);
return ret; return ret;
} }
@ -1541,7 +1541,7 @@ static int set_bframe_chain_length(MpegEncContext *s)
s->next_pic.ptr && s->next_pic.ptr &&
skip_check(s, s->input_picture[0], s->next_pic.ptr)) { skip_check(s, s->input_picture[0], s->next_pic.ptr)) {
// FIXME check that the gop check above is +-1 correct // FIXME check that the gop check above is +-1 correct
ff_refstruct_unref(&s->input_picture[0]); av_refstruct_unref(&s->input_picture[0]);
ff_vbv_update(s, 0); ff_vbv_update(s, 0);
@ -1607,7 +1607,7 @@ static int set_bframe_chain_length(MpegEncContext *s)
} else if (s->b_frame_strategy == 2) { } else if (s->b_frame_strategy == 2) {
b_frames = estimate_best_b_count(s); b_frames = estimate_best_b_count(s);
if (b_frames < 0) { if (b_frames < 0) {
ff_refstruct_unref(&s->input_picture[0]); av_refstruct_unref(&s->input_picture[0]);
return b_frames; return b_frames;
} }
} }
@ -1714,7 +1714,7 @@ static int select_input_picture(MpegEncContext *s)
} }
return 0; return 0;
fail: fail:
ff_refstruct_unref(&s->reordered_input_picture[0]); av_refstruct_unref(&s->reordered_input_picture[0]);
return ret; return ret;
} }

View file

@ -36,7 +36,7 @@
#include "decode.h" #include "decode.h"
#include "nvdec.h" #include "nvdec.h"
#include "internal.h" #include "internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#if !NVDECAPI_CHECK_VERSION(9, 0) #if !NVDECAPI_CHECK_VERSION(9, 0)
#define cudaVideoSurfaceFormat_YUV444 2 #define cudaVideoSurfaceFormat_YUV444 2
@ -163,7 +163,7 @@ static int nvdec_test_capabilities(NVDECDecoder *decoder,
return 0; return 0;
} }
static void nvdec_decoder_free(FFRefStructOpaque unused, void *obj) static void nvdec_decoder_free(AVRefStructOpaque unused, void *obj)
{ {
NVDECDecoder *decoder = obj; NVDECDecoder *decoder = obj;
@ -192,7 +192,7 @@ static int nvdec_decoder_create(NVDECDecoder **out, AVBufferRef *hw_device_ref,
CUcontext dummy; CUcontext dummy;
int ret; int ret;
decoder = ff_refstruct_alloc_ext(sizeof(*decoder), 0, decoder = av_refstruct_alloc_ext(sizeof(*decoder), 0,
NULL, nvdec_decoder_free); NULL, nvdec_decoder_free);
if (!decoder) if (!decoder)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -234,11 +234,11 @@ static int nvdec_decoder_create(NVDECDecoder **out, AVBufferRef *hw_device_ref,
return 0; return 0;
fail: fail:
ff_refstruct_unref(&decoder); av_refstruct_unref(&decoder);
return ret; return ret;
} }
static int nvdec_decoder_frame_init(FFRefStructOpaque opaque, void *obj) static int nvdec_decoder_frame_init(AVRefStructOpaque opaque, void *obj)
{ {
NVDECFramePool *pool = opaque.nc; NVDECFramePool *pool = opaque.nc;
unsigned int *intp = obj; unsigned int *intp = obj;
@ -251,7 +251,7 @@ static int nvdec_decoder_frame_init(FFRefStructOpaque opaque, void *obj)
return 0; return 0;
} }
static void nvdec_decoder_frame_pool_free(FFRefStructOpaque opaque) static void nvdec_decoder_frame_pool_free(AVRefStructOpaque opaque)
{ {
av_free(opaque.nc); av_free(opaque.nc);
} }
@ -269,8 +269,8 @@ int ff_nvdec_decode_uninit(AVCodecContext *avctx)
ctx->nb_slices = 0; ctx->nb_slices = 0;
ctx->slice_offsets_allocated = 0; ctx->slice_offsets_allocated = 0;
ff_refstruct_unref(&ctx->decoder); av_refstruct_unref(&ctx->decoder);
ff_refstruct_pool_uninit(&ctx->decoder_pool); av_refstruct_pool_uninit(&ctx->decoder_pool);
return 0; return 0;
} }
@ -426,7 +426,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
} }
pool->dpb_size = frames_ctx->initial_pool_size; pool->dpb_size = frames_ctx->initial_pool_size;
ctx->decoder_pool = ff_refstruct_pool_alloc_ext(sizeof(unsigned int), 0, pool, ctx->decoder_pool = av_refstruct_pool_alloc_ext(sizeof(unsigned int), 0, pool,
nvdec_decoder_frame_init, nvdec_decoder_frame_init,
NULL, NULL, nvdec_decoder_frame_pool_free); NULL, NULL, nvdec_decoder_frame_pool_free);
if (!ctx->decoder_pool) { if (!ctx->decoder_pool) {
@ -447,9 +447,9 @@ static void nvdec_fdd_priv_free(void *priv)
if (!cf) if (!cf)
return; return;
ff_refstruct_unref(&cf->idx_ref); av_refstruct_unref(&cf->idx_ref);
ff_refstruct_unref(&cf->ref_idx_ref); av_refstruct_unref(&cf->ref_idx_ref);
ff_refstruct_unref(&cf->decoder); av_refstruct_unref(&cf->decoder);
av_freep(&priv); av_freep(&priv);
} }
@ -472,9 +472,9 @@ static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy)); CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy));
finish: finish:
ff_refstruct_unref(&unmap_data->idx_ref); av_refstruct_unref(&unmap_data->idx_ref);
ff_refstruct_unref(&unmap_data->ref_idx_ref); av_refstruct_unref(&unmap_data->ref_idx_ref);
ff_refstruct_unref(&unmap_data->decoder); av_refstruct_unref(&unmap_data->decoder);
av_free(unmap_data); av_free(unmap_data);
} }
@ -529,8 +529,8 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
goto copy_fail; goto copy_fail;
unmap_data->idx = cf->idx; unmap_data->idx = cf->idx;
unmap_data->idx_ref = ff_refstruct_ref(cf->idx_ref); unmap_data->idx_ref = av_refstruct_ref(cf->idx_ref);
unmap_data->decoder = ff_refstruct_ref(cf->decoder); unmap_data->decoder = av_refstruct_ref(cf->decoder);
av_pix_fmt_get_chroma_sub_sample(hwctx->sw_format, &shift_h, &shift_v); av_pix_fmt_get_chroma_sub_sample(hwctx->sw_format, &shift_h, &shift_v);
for (i = 0; frame->linesize[i]; i++) { for (i = 0; frame->linesize[i]; i++) {
@ -575,9 +575,9 @@ int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
if (!cf) if (!cf)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
cf->decoder = ff_refstruct_ref(ctx->decoder); cf->decoder = av_refstruct_ref(ctx->decoder);
cf->idx_ref = ff_refstruct_pool_get(ctx->decoder_pool); cf->idx_ref = av_refstruct_pool_get(ctx->decoder_pool);
if (!cf->idx_ref) { if (!cf->idx_ref) {
av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n"); av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
@ -611,7 +611,7 @@ int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_
if (has_sep_ref) { if (has_sep_ref) {
if (!cf->ref_idx_ref) { if (!cf->ref_idx_ref) {
cf->ref_idx_ref = ff_refstruct_pool_get(ctx->decoder_pool); cf->ref_idx_ref = av_refstruct_pool_get(ctx->decoder_pool);
if (!cf->ref_idx_ref) { if (!cf->ref_idx_ref) {
av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n"); av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
@ -620,7 +620,7 @@ int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_
} }
cf->ref_idx = *cf->ref_idx_ref; cf->ref_idx = *cf->ref_idx_ref;
} else { } else {
ff_refstruct_unref(&cf->ref_idx_ref); av_refstruct_unref(&cf->ref_idx_ref);
cf->ref_idx = cf->idx; cf->ref_idx = cf->idx;
} }

View file

@ -52,7 +52,7 @@ typedef struct NVDECFrame {
typedef struct NVDECContext { typedef struct NVDECContext {
CUVIDPICPARAMS pic_params; CUVIDPICPARAMS pic_params;
struct FFRefStructPool *decoder_pool; struct AVRefStructPool *decoder_pool;
struct NVDECDecoder *decoder; ///< RefStruct reference struct NVDECDecoder *decoder; ///< RefStruct reference

View file

@ -34,7 +34,7 @@
#include "internal.h" #include "internal.h"
#include "packet_internal.h" #include "packet_internal.h"
#include "pthread_internal.h" #include "pthread_internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadframe.h" #include "threadframe.h"
#include "version_major.h" #include "version_major.h"
@ -405,7 +405,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
dst->hwaccel_flags = src->hwaccel_flags; dst->hwaccel_flags = src->hwaccel_flags;
ff_refstruct_replace(&dst->internal->pool, src->internal->pool); av_refstruct_replace(&dst->internal->pool, src->internal->pool);
ff_decode_internal_sync(dst, src); ff_decode_internal_sync(dst, src);
} }
@ -780,7 +780,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
av_freep(&ctx->priv_data); av_freep(&ctx->priv_data);
} }
ff_refstruct_unref(&ctx->internal->pool); av_refstruct_unref(&ctx->internal->pool);
av_packet_free(&ctx->internal->in_pkt); av_packet_free(&ctx->internal->in_pkt);
av_packet_free(&ctx->internal->last_pkt_props); av_packet_free(&ctx->internal->last_pkt_props);
ff_decode_internal_uninit(ctx); ff_decode_internal_uninit(ctx);
@ -1062,7 +1062,7 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
if (!(avctx->active_thread_type & FF_THREAD_FRAME)) if (!(avctx->active_thread_type & FF_THREAD_FRAME))
return ff_get_buffer(avctx, f->f, flags); return ff_get_buffer(avctx, f->f, flags);
f->progress = ff_refstruct_allocz(sizeof(*f->progress)); f->progress = av_refstruct_allocz(sizeof(*f->progress));
if (!f->progress) if (!f->progress)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -1071,13 +1071,13 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
ret = ff_thread_get_buffer(avctx, f->f, flags); ret = ff_thread_get_buffer(avctx, f->f, flags);
if (ret) if (ret)
ff_refstruct_unref(&f->progress); av_refstruct_unref(&f->progress);
return ret; return ret;
} }
void ff_thread_release_ext_buffer(ThreadFrame *f) void ff_thread_release_ext_buffer(ThreadFrame *f)
{ {
ff_refstruct_unref(&f->progress); av_refstruct_unref(&f->progress);
f->owner[0] = f->owner[1] = NULL; f->owner[0] = f->owner[1] = NULL;
if (f->f) if (f->f)
av_frame_unref(f->f); av_frame_unref(f->f);
@ -1098,7 +1098,7 @@ enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
memcpy(&ref, (const char*)p->parent->threads[0].avctx->priv_data + offset, sizeof(ref)); memcpy(&ref, (const char*)p->parent->threads[0].avctx->priv_data + offset, sizeof(ref));
av_assert1(ref); av_assert1(ref);
ff_refstruct_replace((char*)avctx->priv_data + offset, ref); av_refstruct_replace((char*)avctx->priv_data + offset, ref);
return FF_THREAD_IS_COPY; return FF_THREAD_IS_COPY;
} }

View file

@ -35,7 +35,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "qsv_internal.h" #include "qsv_internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
#define QSV_HAVE_USER_PLUGIN !QSV_ONEVPL #define QSV_HAVE_USER_PLUGIN !QSV_ONEVPL
@ -745,7 +745,7 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
return 0; return 0;
} }
static void mids_buf_free(FFRefStructOpaque opaque, void *obj) static void mids_buf_free(AVRefStructOpaque opaque, void *obj)
{ {
AVBufferRef *hw_frames_ref = opaque.nc; AVBufferRef *hw_frames_ref = opaque.nc;
av_buffer_unref(&hw_frames_ref); av_buffer_unref(&hw_frames_ref);
@ -765,7 +765,7 @@ static QSVMid *qsv_create_mids(AVBufferRef *hw_frames_ref)
if (!hw_frames_ref1) if (!hw_frames_ref1)
return NULL; return NULL;
mids = ff_refstruct_alloc_ext(nb_surfaces * sizeof(*mids), 0, mids = av_refstruct_alloc_ext(nb_surfaces * sizeof(*mids), 0,
hw_frames_ref1, mids_buf_free); hw_frames_ref1, mids_buf_free);
if (!mids) { if (!mids) {
av_buffer_unref(&hw_frames_ref1); av_buffer_unref(&hw_frames_ref1);
@ -806,7 +806,7 @@ static int qsv_setup_mids(mfxFrameAllocResponse *resp, AVBufferRef *hw_frames_re
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
resp->mids[resp->NumFrameActual + 1] = ff_refstruct_ref(mids); resp->mids[resp->NumFrameActual + 1] = av_refstruct_ref(mids);
return 0; return 0;
} }
@ -899,7 +899,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
} }
ret = qsv_setup_mids(resp, frames_ref, mids); ret = qsv_setup_mids(resp, frames_ref, mids);
ff_refstruct_unref(&mids); av_refstruct_unref(&mids);
av_buffer_unref(&frames_ref); av_buffer_unref(&frames_ref);
if (ret < 0) { if (ret < 0) {
av_log(ctx->logctx, AV_LOG_ERROR, av_log(ctx->logctx, AV_LOG_ERROR,
@ -919,7 +919,7 @@ static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
return MFX_ERR_NONE; return MFX_ERR_NONE;
av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]); av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]);
ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]); av_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]);
av_freep(&resp->mids); av_freep(&resp->mids);
return MFX_ERR_NONE; return MFX_ERR_NONE;
} }
@ -1139,7 +1139,7 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession,
/* allocate the memory ids for the external frames */ /* allocate the memory ids for the external frames */
if (frames_hwctx->nb_surfaces) { if (frames_hwctx->nb_surfaces) {
ff_refstruct_unref(&qsv_frames_ctx->mids); av_refstruct_unref(&qsv_frames_ctx->mids);
qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx); qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx);
if (!qsv_frames_ctx->mids) if (!qsv_frames_ctx->mids)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);

View file

@ -51,7 +51,7 @@
#include "hwconfig.h" #include "hwconfig.h"
#include "qsv.h" #include "qsv.h"
#include "qsv_internal.h" #include "qsv_internal.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#if QSV_ONEVPL #if QSV_ONEVPL
#include <mfxdispatcher.h> #include <mfxdispatcher.h>
@ -984,7 +984,7 @@ static void qsv_decode_close_qsvcontext(QSVContext *q)
ff_qsv_close_internal_session(&q->internal_qs); ff_qsv_close_internal_session(&q->internal_qs);
av_buffer_unref(&q->frames_ctx.hw_frames_ctx); av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
ff_refstruct_unref(&q->frames_ctx.mids); av_refstruct_unref(&q->frames_ctx.mids);
av_buffer_pool_uninit(&q->pool); av_buffer_pool_uninit(&q->pool);
} }

View file

@ -42,7 +42,7 @@
#include "qsv.h" #include "qsv.h"
#include "qsv_internal.h" #include "qsv_internal.h"
#include "qsvenc.h" #include "qsvenc.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
struct profile_names { struct profile_names {
mfxU16 profile; mfxU16 profile;
@ -2716,7 +2716,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
ff_qsv_close_internal_session(&q->internal_qs); ff_qsv_close_internal_session(&q->internal_qs);
av_buffer_unref(&q->frames_ctx.hw_frames_ctx); av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
ff_refstruct_unref(&q->frames_ctx.mids); av_refstruct_unref(&q->frames_ctx.mids);
cur = q->work_frames; cur = q->work_frames;
while (cur) { while (cur) {

View file

@ -30,7 +30,7 @@
#include "codec_internal.h" #include "codec_internal.h"
#include "decode.h" #include "decode.h"
#include "hwconfig.h" #include "hwconfig.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "libavutil/buffer.h" #include "libavutil/buffer.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/frame.h" #include "libavutil/frame.h"
@ -126,11 +126,11 @@ static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, in
static int rkmpp_close_decoder(AVCodecContext *avctx) static int rkmpp_close_decoder(AVCodecContext *avctx)
{ {
RKMPPDecodeContext *rk_context = avctx->priv_data; RKMPPDecodeContext *rk_context = avctx->priv_data;
ff_refstruct_unref(&rk_context->decoder); av_refstruct_unref(&rk_context->decoder);
return 0; return 0;
} }
static void rkmpp_release_decoder(FFRefStructOpaque unused, void *obj) static void rkmpp_release_decoder(AVRefStructOpaque unused, void *obj)
{ {
RKMPPDecoder *decoder = obj; RKMPPDecoder *decoder = obj;
@ -161,7 +161,7 @@ static int rkmpp_init_decoder(AVCodecContext *avctx)
avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME; avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME;
// create a decoder and a ref to it // create a decoder and a ref to it
decoder = ff_refstruct_alloc_ext(sizeof(*decoder), 0, decoder = av_refstruct_alloc_ext(sizeof(*decoder), 0,
NULL, rkmpp_release_decoder); NULL, rkmpp_release_decoder);
if (!decoder) { if (!decoder) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
@ -304,7 +304,7 @@ static void rkmpp_release_frame(void *opaque, uint8_t *data)
RKMPPFrameContext *framecontext = opaque; RKMPPFrameContext *framecontext = opaque;
mpp_frame_deinit(&framecontext->frame); mpp_frame_deinit(&framecontext->frame);
ff_refstruct_unref(&framecontext->decoder_ref); av_refstruct_unref(&framecontext->decoder_ref);
av_free(desc); av_free(desc);
} }
@ -449,7 +449,7 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame)
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
framecontext->decoder_ref = ff_refstruct_ref(rk_context->decoder); framecontext->decoder_ref = av_refstruct_ref(rk_context->decoder);
frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref); frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref);
if (!frame->hw_frames_ctx) { if (!frame->hw_frames_ctx) {

View file

@ -40,7 +40,7 @@
#include "codec_par.h" #include "codec_par.h"
#include "decode.h" #include "decode.h"
#include "hwconfig.h" #include "hwconfig.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadframe.h" #include "threadframe.h"
#include "internal.h" #include "internal.h"
@ -856,7 +856,7 @@ int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
av_assert0(!dst->progress); av_assert0(!dst->progress);
if (src->progress) if (src->progress)
dst->progress = ff_refstruct_ref(src->progress); dst->progress = av_refstruct_ref(src->progress);
return 0; return 0;
} }
@ -872,7 +872,7 @@ int ff_thread_replace_frame(ThreadFrame *dst, const ThreadFrame *src)
if (ret < 0) if (ret < 0)
return ret; return ret;
ff_refstruct_replace(&dst->progress, src->progress); av_refstruct_replace(&dst->progress, src->progress);
return 0; return 0;
} }

View file

@ -29,7 +29,7 @@
#include <poll.h> #include <poll.h>
#include "libavcodec/avcodec.h" #include "libavcodec/avcodec.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "v4l2_context.h" #include "v4l2_context.h"
#include "v4l2_buffers.h" #include "v4l2_buffers.h"
#include "v4l2_m2m.h" #include "v4l2_m2m.h"
@ -230,7 +230,7 @@ static void v4l2_free_buffer(void *opaque, uint8_t *unused)
ff_v4l2_buffer_enqueue(avbuf); ff_v4l2_buffer_enqueue(avbuf);
} }
ff_refstruct_unref(&avbuf->context_ref); av_refstruct_unref(&avbuf->context_ref);
} }
} }
@ -241,7 +241,7 @@ static int v4l2_buf_increase_ref(V4L2Buffer *in)
if (in->context_ref) if (in->context_ref)
atomic_fetch_add(&in->context_refcount, 1); atomic_fetch_add(&in->context_refcount, 1);
else { else {
in->context_ref = ff_refstruct_ref(s->self_ref); in->context_ref = av_refstruct_ref(s->self_ref);
in->context_refcount = 1; in->context_refcount = 1;
} }

View file

@ -32,7 +32,7 @@
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
#include "libavutil/pixfmt.h" #include "libavutil/pixfmt.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "v4l2_context.h" #include "v4l2_context.h"
#include "v4l2_fmt.h" #include "v4l2_fmt.h"
#include "v4l2_m2m.h" #include "v4l2_m2m.h"
@ -248,7 +248,7 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *s)
return 0; return 0;
} }
static void v4l2_m2m_destroy_context(FFRefStructOpaque unused, void *context) static void v4l2_m2m_destroy_context(AVRefStructOpaque unused, void *context)
{ {
V4L2m2mContext *s = context; V4L2m2mContext *s = context;
@ -282,7 +282,7 @@ int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
ff_v4l2_context_release(&s->output); ff_v4l2_context_release(&s->output);
s->self_ref = NULL; s->self_ref = NULL;
ff_refstruct_unref(&priv->context); av_refstruct_unref(&priv->context);
return 0; return 0;
} }
@ -327,7 +327,7 @@ int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv)
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s) int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
{ {
*s = ff_refstruct_alloc_ext(sizeof(**s), 0, NULL, *s = av_refstruct_alloc_ext(sizeof(**s), 0, NULL,
&v4l2_m2m_destroy_context); &v4l2_m2m_destroy_context);
if (!*s) if (!*s)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -344,7 +344,7 @@ int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
priv->context->frame = av_frame_alloc(); priv->context->frame = av_frame_alloc();
if (!priv->context->frame) { if (!priv->context->frame) {
ff_refstruct_unref(&priv->context); av_refstruct_unref(&priv->context);
*s = NULL; /* freed when unreferencing context */ *s = NULL; /* freed when unreferencing context */
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }

View file

@ -31,7 +31,7 @@
#include "vaapi_encode.h" #include "vaapi_encode.h"
#include "encode.h" #include "encode.h"
#include "avcodec.h" #include "avcodec.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[] = { const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[] = {
HW_CONFIG_ENCODER_FRAMES(VAAPI, VAAPI), HW_CONFIG_ENCODER_FRAMES(VAAPI, VAAPI),
@ -316,7 +316,7 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
pic->recon_surface = (VASurfaceID)(uintptr_t)base_pic->recon_image->data[3]; pic->recon_surface = (VASurfaceID)(uintptr_t)base_pic->recon_image->data[3];
av_log(avctx, AV_LOG_DEBUG, "Recon surface is %#x.\n", pic->recon_surface); av_log(avctx, AV_LOG_DEBUG, "Recon surface is %#x.\n", pic->recon_surface);
pic->output_buffer_ref = ff_refstruct_pool_get(ctx->output_buffer_pool); pic->output_buffer_ref = av_refstruct_pool_get(ctx->output_buffer_pool);
if (!pic->output_buffer_ref) { if (!pic->output_buffer_ref) {
err = AVERROR(ENOMEM); err = AVERROR(ENOMEM);
goto fail; goto fail;
@ -649,7 +649,7 @@ fail_at_end:
av_freep(&pic->param_buffers); av_freep(&pic->param_buffers);
av_freep(&pic->slices); av_freep(&pic->slices);
av_freep(&pic->roi); av_freep(&pic->roi);
ff_refstruct_unref(&pic->output_buffer_ref); av_refstruct_unref(&pic->output_buffer_ref);
pic->output_buffer = VA_INVALID_ID; pic->output_buffer = VA_INVALID_ID;
return err; return err;
} }
@ -759,8 +759,8 @@ static int vaapi_encode_get_coded_data(AVCodecContext *avctx,
goto end; goto end;
end: end:
ff_refstruct_unref(&ctx->coded_buffer_ref); av_refstruct_unref(&ctx->coded_buffer_ref);
ff_refstruct_unref(&pic->output_buffer_ref); av_refstruct_unref(&pic->output_buffer_ref);
pic->output_buffer = VA_INVALID_ID; pic->output_buffer = VA_INVALID_ID;
return ret; return ret;
@ -781,7 +781,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
if (pic->non_independent_frame) { if (pic->non_independent_frame) {
av_assert0(!ctx->coded_buffer_ref); av_assert0(!ctx->coded_buffer_ref);
ctx->coded_buffer_ref = ff_refstruct_ref(pic->output_buffer_ref); ctx->coded_buffer_ref = av_refstruct_ref(pic->output_buffer_ref);
if (pic->tail_size) { if (pic->tail_size) {
if (base_ctx->tail_pkt->size) { if (base_ctx->tail_pkt->size) {
@ -809,7 +809,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
ctx->codec->flags & FLAG_TIMESTAMP_NO_DELAY); ctx->codec->flags & FLAG_TIMESTAMP_NO_DELAY);
end: end:
ff_refstruct_unref(&pic->output_buffer_ref); av_refstruct_unref(&pic->output_buffer_ref);
pic->output_buffer = VA_INVALID_ID; pic->output_buffer = VA_INVALID_ID;
return err; return err;
} }
@ -825,7 +825,7 @@ static int vaapi_encode_discard(AVCodecContext *avctx, FFHWBaseEncodePicture *ba
"%"PRId64"/%"PRId64".\n", "%"PRId64"/%"PRId64".\n",
base_pic->display_order, base_pic->encode_order); base_pic->display_order, base_pic->encode_order);
ff_refstruct_unref(&pic->output_buffer_ref); av_refstruct_unref(&pic->output_buffer_ref);
pic->output_buffer = VA_INVALID_ID; pic->output_buffer = VA_INVALID_ID;
} }
@ -1987,7 +1987,7 @@ static av_cold int vaapi_encode_init_roi(AVCodecContext *avctx)
return 0; return 0;
} }
static void vaapi_encode_free_output_buffer(FFRefStructOpaque opaque, static void vaapi_encode_free_output_buffer(AVRefStructOpaque opaque,
void *obj) void *obj)
{ {
AVCodecContext *avctx = opaque.nc; AVCodecContext *avctx = opaque.nc;
@ -2000,7 +2000,7 @@ static void vaapi_encode_free_output_buffer(FFRefStructOpaque opaque,
av_log(avctx, AV_LOG_DEBUG, "Freed output buffer %#x\n", buffer_id); av_log(avctx, AV_LOG_DEBUG, "Freed output buffer %#x\n", buffer_id);
} }
static int vaapi_encode_alloc_output_buffer(FFRefStructOpaque opaque, void *obj) static int vaapi_encode_alloc_output_buffer(AVRefStructOpaque opaque, void *obj)
{ {
AVCodecContext *avctx = opaque.nc; AVCodecContext *avctx = opaque.nc;
FFHWBaseEncodeContext *base_ctx = avctx->priv_data; FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
@ -2187,7 +2187,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
} }
ctx->output_buffer_pool = ctx->output_buffer_pool =
ff_refstruct_pool_alloc_ext(sizeof(VABufferID), 0, avctx, av_refstruct_pool_alloc_ext(sizeof(VABufferID), 0, avctx,
&vaapi_encode_alloc_output_buffer, NULL, &vaapi_encode_alloc_output_buffer, NULL,
vaapi_encode_free_output_buffer, NULL); vaapi_encode_free_output_buffer, NULL);
if (!ctx->output_buffer_pool) { if (!ctx->output_buffer_pool) {
@ -2288,7 +2288,7 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
vaapi_encode_free(avctx, pic); vaapi_encode_free(avctx, pic);
} }
ff_refstruct_pool_uninit(&ctx->output_buffer_pool); av_refstruct_pool_uninit(&ctx->output_buffer_pool);
if (ctx->va_context != VA_INVALID_ID) { if (ctx->va_context != VA_INVALID_ID) {
if (ctx->hwctx) if (ctx->hwctx)

View file

@ -202,7 +202,7 @@ typedef struct VAAPIEncodeContext {
AVVAAPIDeviceContext *hwctx; AVVAAPIDeviceContext *hwctx;
// Pool of (reusable) bitstream output buffers. // Pool of (reusable) bitstream output buffers.
struct FFRefStructPool *output_buffer_pool; struct AVRefStructPool *output_buffer_pool;
// Global parameters which will be applied at the start of the // Global parameters which will be applied at the start of the
// sequence (includes rate control parameters below). // sequence (includes rate control parameters below).

View file

@ -50,7 +50,7 @@
#include "jpegquanttables.h" #include "jpegquanttables.h"
#include "mathops.h" #include "mathops.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "videodsp.h" #include "videodsp.h"
#include "vp3data.h" #include "vp3data.h"
@ -370,7 +370,7 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx)
/* release all frames */ /* release all frames */
vp3_decode_flush(avctx); vp3_decode_flush(avctx);
ff_refstruct_unref(&s->coeff_vlc); av_refstruct_unref(&s->coeff_vlc);
return 0; return 0;
} }
@ -2346,7 +2346,7 @@ static av_cold int allocate_tables(AVCodecContext *avctx)
} }
static av_cold void free_vlc_tables(FFRefStructOpaque unused, void *obj) static av_cold void free_vlc_tables(AVRefStructOpaque unused, void *obj)
{ {
CoeffVLCs *vlcs = obj; CoeffVLCs *vlcs = obj;
@ -2459,7 +2459,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
} }
if (!avctx->internal->is_copy) { if (!avctx->internal->is_copy) {
CoeffVLCs *vlcs = ff_refstruct_alloc_ext(sizeof(*s->coeff_vlc), 0, CoeffVLCs *vlcs = av_refstruct_alloc_ext(sizeof(*s->coeff_vlc), 0,
NULL, free_vlc_tables); NULL, free_vlc_tables);
if (!vlcs) if (!vlcs)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -2527,7 +2527,7 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
const Vp3DecodeContext *s1 = src->priv_data; const Vp3DecodeContext *s1 = src->priv_data;
int qps_changed = 0; int qps_changed = 0;
ff_refstruct_replace(&s->coeff_vlc, s1->coeff_vlc); av_refstruct_replace(&s->coeff_vlc, s1->coeff_vlc);
// copy previous frame data // copy previous frame data
ref_frames(s, s1); ref_frames(s, s1);

View file

@ -36,7 +36,7 @@
#include "hwconfig.h" #include "hwconfig.h"
#include "mathops.h" #include "mathops.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "vp8.h" #include "vp8.h"
#include "vp89_rac.h" #include "vp89_rac.h"
@ -107,7 +107,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref)
ref ? AV_GET_BUFFER_FLAG_REF : 0); ref ? AV_GET_BUFFER_FLAG_REF : 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height); f->seg_map = av_refstruct_allocz(s->mb_width * s->mb_height);
if (!f->seg_map) { if (!f->seg_map) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
@ -119,15 +119,15 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref)
return 0; return 0;
fail: fail:
ff_refstruct_unref(&f->seg_map); av_refstruct_unref(&f->seg_map);
ff_progress_frame_unref(&f->tf); ff_progress_frame_unref(&f->tf);
return ret; return ret;
} }
static void vp8_release_frame(VP8Frame *f) static void vp8_release_frame(VP8Frame *f)
{ {
ff_refstruct_unref(&f->seg_map); av_refstruct_unref(&f->seg_map);
ff_refstruct_unref(&f->hwaccel_picture_private); av_refstruct_unref(&f->hwaccel_picture_private);
ff_progress_frame_unref(&f->tf); ff_progress_frame_unref(&f->tf);
} }
@ -2905,8 +2905,8 @@ av_cold int ff_vp8_decode_init(AVCodecContext *avctx)
static void vp8_replace_frame(VP8Frame *dst, const VP8Frame *src) static void vp8_replace_frame(VP8Frame *dst, const VP8Frame *src)
{ {
ff_progress_frame_replace(&dst->tf, &src->tf); ff_progress_frame_replace(&dst->tf, &src->tf);
ff_refstruct_replace(&dst->seg_map, src->seg_map); av_refstruct_replace(&dst->seg_map, src->seg_map);
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
} }

View file

@ -31,7 +31,7 @@
#include "hwconfig.h" #include "hwconfig.h"
#include "profiles.h" #include "profiles.h"
#include "progressframe.h" #include "progressframe.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "pthread_internal.h" #include "pthread_internal.h"
@ -97,8 +97,8 @@ static void vp9_tile_data_free(VP9TileData *td)
static void vp9_frame_unref(VP9Frame *f) static void vp9_frame_unref(VP9Frame *f)
{ {
ff_progress_frame_unref(&f->tf); ff_progress_frame_unref(&f->tf);
ff_refstruct_unref(&f->extradata); av_refstruct_unref(&f->extradata);
ff_refstruct_unref(&f->hwaccel_picture_private); av_refstruct_unref(&f->hwaccel_picture_private);
f->segmentation_map = NULL; f->segmentation_map = NULL;
} }
@ -113,9 +113,9 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
sz = 64 * s->sb_cols * s->sb_rows; sz = 64 * s->sb_cols * s->sb_rows;
if (sz != s->frame_extradata_pool_size) { if (sz != s->frame_extradata_pool_size) {
ff_refstruct_pool_uninit(&s->frame_extradata_pool); av_refstruct_pool_uninit(&s->frame_extradata_pool);
s->frame_extradata_pool = ff_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)), s->frame_extradata_pool = av_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)),
FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
if (!s->frame_extradata_pool) { if (!s->frame_extradata_pool) {
s->frame_extradata_pool_size = 0; s->frame_extradata_pool_size = 0;
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
@ -123,7 +123,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
} }
s->frame_extradata_pool_size = sz; s->frame_extradata_pool_size = sz;
} }
f->extradata = ff_refstruct_pool_get(s->frame_extradata_pool); f->extradata = av_refstruct_pool_get(s->frame_extradata_pool);
if (!f->extradata) { if (!f->extradata) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
@ -147,13 +147,13 @@ static void vp9_frame_replace(VP9Frame *dst, const VP9Frame *src)
{ {
ff_progress_frame_replace(&dst->tf, &src->tf); ff_progress_frame_replace(&dst->tf, &src->tf);
ff_refstruct_replace(&dst->extradata, src->extradata); av_refstruct_replace(&dst->extradata, src->extradata);
dst->segmentation_map = src->segmentation_map; dst->segmentation_map = src->segmentation_map;
dst->mv = src->mv; dst->mv = src->mv;
dst->uses_2pass = src->uses_2pass; dst->uses_2pass = src->uses_2pass;
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
} }
@ -1239,7 +1239,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
vp9_frame_unref(&s->s.frames[i]); vp9_frame_unref(&s->s.frames[i]);
ff_refstruct_pool_uninit(&s->frame_extradata_pool); av_refstruct_pool_uninit(&s->frame_extradata_pool);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
ff_progress_frame_unref(&s->s.refs[i]); ff_progress_frame_unref(&s->s.refs[i]);
ff_progress_frame_unref(&s->next_refs[i]); ff_progress_frame_unref(&s->next_refs[i]);
@ -1802,7 +1802,7 @@ static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecCo
vp9_frame_replace(&s->s.frames[i], &ssrc->s.frames[i]); vp9_frame_replace(&s->s.frames[i], &ssrc->s.frames[i]);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
ff_progress_frame_replace(&s->s.refs[i], &ssrc->next_refs[i]); ff_progress_frame_replace(&s->s.refs[i], &ssrc->next_refs[i]);
ff_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool); av_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool);
s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size; s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
s->s.h.invisible = ssrc->s.h.invisible; s->s.h.invisible = ssrc->s.h.invisible;

View file

@ -160,7 +160,7 @@ typedef struct VP9Context {
uint8_t mvstep[3][2]; uint8_t mvstep[3][2];
// frame specific buffer pools // frame specific buffer pools
struct FFRefStructPool *frame_extradata_pool; struct AVRefStructPool *frame_extradata_pool;
int frame_extradata_pool_size; int frame_extradata_pool_size;
} VP9Context; } VP9Context;

View file

@ -606,7 +606,7 @@ static int vk_av1_end_frame(AVCodecContext *avctx)
return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
} }
static void vk_av1_free_frame_priv(FFRefStructOpaque _hwctx, void *data) static void vk_av1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
{ {
AVHWDeviceContext *hwctx = _hwctx.nc; AVHWDeviceContext *hwctx = _hwctx.nc;
AV1VulkanDecodePicture *ap = data; AV1VulkanDecodePicture *ap = data;

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "vulkan_video.h" #include "vulkan_video.h"
#include "vulkan_decode.h" #include "vulkan_decode.h"
#include "config_components.h" #include "config_components.h"
@ -102,7 +102,7 @@ int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
return err; return err;
} }
ff_refstruct_replace(&dst_ctx->shared_ctx, src_ctx->shared_ctx); av_refstruct_replace(&dst_ctx->shared_ctx, src_ctx->shared_ctx);
if (src_ctx->session_params) { if (src_ctx->session_params) {
err = av_buffer_replace(&dst_ctx->session_params, src_ctx->session_params); err = av_buffer_replace(&dst_ctx->session_params, src_ctx->session_params);
@ -571,7 +571,7 @@ void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *
av_frame_free(&vp->dpb_frame); av_frame_free(&vp->dpb_frame);
} }
static void free_common(FFRefStructOpaque unused, void *obj) static void free_common(AVRefStructOpaque unused, void *obj)
{ {
FFVulkanDecodeShared *ctx = obj; FFVulkanDecodeShared *ctx = obj;
FFVulkanContext *s = &ctx->s; FFVulkanContext *s = &ctx->s;
@ -605,7 +605,7 @@ static int vulkan_decode_bootstrap(AVCodecContext *avctx, AVBufferRef *frames_re
if (dec->shared_ctx) if (dec->shared_ctx)
return 0; return 0;
dec->shared_ctx = ff_refstruct_alloc_ext(sizeof(*ctx), 0, NULL, dec->shared_ctx = av_refstruct_alloc_ext(sizeof(*ctx), 0, NULL,
free_common); free_common);
if (!dec->shared_ctx) if (!dec->shared_ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -618,13 +618,13 @@ static int vulkan_decode_bootstrap(AVCodecContext *avctx, AVBufferRef *frames_re
if (!(ctx->s.extensions & FF_VK_EXT_VIDEO_DECODE_QUEUE)) { if (!(ctx->s.extensions & FF_VK_EXT_VIDEO_DECODE_QUEUE)) {
av_log(avctx, AV_LOG_ERROR, "Device does not support the %s extension!\n", av_log(avctx, AV_LOG_ERROR, "Device does not support the %s extension!\n",
VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME); VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME);
ff_refstruct_unref(&dec->shared_ctx); av_refstruct_unref(&dec->shared_ctx);
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
err = ff_vk_load_functions(device, &ctx->s.vkfn, ctx->s.extensions, 1, 1); err = ff_vk_load_functions(device, &ctx->s.vkfn, ctx->s.extensions, 1, 1);
if (err < 0) { if (err < 0) {
ff_refstruct_unref(&dec->shared_ctx); av_refstruct_unref(&dec->shared_ctx);
return err; return err;
} }
@ -1073,7 +1073,7 @@ int ff_vk_decode_uninit(AVCodecContext *avctx)
av_freep(&dec->hevc_headers); av_freep(&dec->hevc_headers);
av_buffer_unref(&dec->session_params); av_buffer_unref(&dec->session_params);
ff_refstruct_unref(&dec->shared_ctx); av_refstruct_unref(&dec->shared_ctx);
av_freep(&dec->slice_off); av_freep(&dec->slice_off);
return 0; return 0;
} }

View file

@ -541,7 +541,7 @@ static int vk_h264_end_frame(AVCodecContext *avctx)
return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
} }
static void vk_h264_free_frame_priv(FFRefStructOpaque _hwctx, void *data) static void vk_h264_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
{ {
AVHWDeviceContext *hwctx = _hwctx.nc; AVHWDeviceContext *hwctx = _hwctx.nc;
H264VulkanDecodePicture *hp = data; H264VulkanDecodePicture *hp = data;

View file

@ -897,7 +897,7 @@ static int vk_hevc_end_frame(AVCodecContext *avctx)
return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp);
} }
static void vk_hevc_free_frame_priv(FFRefStructOpaque _hwctx, void *data) static void vk_hevc_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
{ {
AVHWDeviceContext *hwctx = _hwctx.nc; AVHWDeviceContext *hwctx = _hwctx.nc;
HEVCVulkanDecodePicture *hp = data; HEVCVulkanDecodePicture *hp = data;

View file

@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavcodec/refstruct.h" #include "libavutil/refstruct.h"
#include "cabac.h" #include "cabac.h"
#include "ctu.h" #include "ctu.h"
@ -209,7 +209,7 @@ static void set_qp_c(VVCLocalContext *lc)
static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu) static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
{ {
TransformUnit *tu = ff_refstruct_pool_get(fc->tu_pool); TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
if (!tu) if (!tu)
return NULL; return NULL;
@ -1184,7 +1184,7 @@ static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
const int rx = x0 >> sps->ctb_log2_size_y; const int rx = x0 >> sps->ctb_log2_size_y;
const int ry = y0 >> sps->ctb_log2_size_y; const int ry = y0 >> sps->ctb_log2_size_y;
CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx; CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
CodingUnit *cu = ff_refstruct_pool_get(fc->cu_pool); CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
if (!cu) if (!cu)
return NULL; return NULL;
@ -2550,11 +2550,11 @@ void ff_vvc_ctu_free_cus(CodingUnit **cus)
while (*head) { while (*head) {
TransformUnit *tu = *head; TransformUnit *tu = *head;
*head = tu->next; *head = tu->next;
ff_refstruct_unref(&tu); av_refstruct_unref(&tu);
} }
cu->tus.tail = NULL; cu->tus.tail = NULL;
ff_refstruct_unref(&cu); av_refstruct_unref(&cu);
} }
} }

View file

@ -25,7 +25,7 @@
#include "libavcodec/hwaccel_internal.h" #include "libavcodec/hwaccel_internal.h"
#include "libavcodec/hwconfig.h" #include "libavcodec/hwconfig.h"
#include "libavcodec/profiles.h" #include "libavcodec/profiles.h"
#include "libavcodec/refstruct.h" #include "libavutil/refstruct.h"
#include "libavutil/cpu.h" #include "libavutil/cpu.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/thread.h" #include "libavutil/thread.h"
@ -352,8 +352,8 @@ static void pic_arrays_free(VVCFrameContext *fc)
{ {
free_cus(fc); free_cus(fc);
frame_context_for_each_tl(fc, tl_free); frame_context_for_each_tl(fc, tl_free);
ff_refstruct_pool_uninit(&fc->rpl_tab_pool); av_refstruct_pool_uninit(&fc->rpl_tab_pool);
ff_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool); av_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool);
memset(&fc->tab.sz, 0, sizeof(fc->tab.sz)); memset(&fc->tab.sz, 0, sizeof(fc->tab.sz));
} }
@ -378,16 +378,16 @@ static int pic_arrays_init(VVCContext *s, VVCFrameContext *fc)
memset(fc->tab.slice_idx, -1, sizeof(*fc->tab.slice_idx) * ctu_count); memset(fc->tab.slice_idx, -1, sizeof(*fc->tab.slice_idx) * ctu_count);
if (fc->tab.sz.ctu_count != ctu_count) { if (fc->tab.sz.ctu_count != ctu_count) {
ff_refstruct_pool_uninit(&fc->rpl_tab_pool); av_refstruct_pool_uninit(&fc->rpl_tab_pool);
fc->rpl_tab_pool = ff_refstruct_pool_alloc(ctu_count * sizeof(RefPicListTab), 0); fc->rpl_tab_pool = av_refstruct_pool_alloc(ctu_count * sizeof(RefPicListTab), 0);
if (!fc->rpl_tab_pool) if (!fc->rpl_tab_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
if (fc->tab.sz.pic_size_in_min_pu != pic_size_in_min_pu) { if (fc->tab.sz.pic_size_in_min_pu != pic_size_in_min_pu) {
ff_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool); av_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool);
fc->tab_dmvr_mvf_pool = ff_refstruct_pool_alloc( fc->tab_dmvr_mvf_pool = av_refstruct_pool_alloc(
pic_size_in_min_pu * sizeof(MvField), FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); pic_size_in_min_pu * sizeof(MvField), AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
if (!fc->tab_dmvr_mvf_pool) if (!fc->tab_dmvr_mvf_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -468,8 +468,8 @@ static void slices_free(VVCFrameContext *fc)
for (int i = 0; i < fc->nb_slices_allocated; i++) { for (int i = 0; i < fc->nb_slices_allocated; i++) {
SliceContext *slice = fc->slices[i]; SliceContext *slice = fc->slices[i];
if (slice) { if (slice) {
ff_refstruct_unref(&slice->ref); av_refstruct_unref(&slice->ref);
ff_refstruct_unref(&slice->sh.r); av_refstruct_unref(&slice->sh.r);
eps_free(slice); eps_free(slice);
av_free(slice); av_free(slice);
} }
@ -598,16 +598,16 @@ static int ref_frame(VVCFrame *dst, const VVCFrame *src)
if (ret < 0) if (ret < 0)
return ret; return ret;
ff_refstruct_replace(&dst->sps, src->sps); av_refstruct_replace(&dst->sps, src->sps);
ff_refstruct_replace(&dst->pps, src->pps); av_refstruct_replace(&dst->pps, src->pps);
ff_refstruct_replace(&dst->progress, src->progress); av_refstruct_replace(&dst->progress, src->progress);
ff_refstruct_replace(&dst->tab_dmvr_mvf, src->tab_dmvr_mvf); av_refstruct_replace(&dst->tab_dmvr_mvf, src->tab_dmvr_mvf);
ff_refstruct_replace(&dst->rpl_tab, src->rpl_tab); av_refstruct_replace(&dst->rpl_tab, src->rpl_tab);
ff_refstruct_replace(&dst->rpl, src->rpl); av_refstruct_replace(&dst->rpl, src->rpl);
ff_refstruct_replace(&dst->hwaccel_picture_private, av_refstruct_replace(&dst->hwaccel_picture_private,
src->hwaccel_picture_private); src->hwaccel_picture_private);
dst->nb_rpl_elems = src->nb_rpl_elems; dst->nb_rpl_elems = src->nb_rpl_elems;
@ -628,8 +628,8 @@ static av_cold void frame_context_free(VVCFrameContext *fc)
{ {
slices_free(fc); slices_free(fc);
ff_refstruct_pool_uninit(&fc->tu_pool); av_refstruct_pool_uninit(&fc->tu_pool);
ff_refstruct_pool_uninit(&fc->cu_pool); av_refstruct_pool_uninit(&fc->cu_pool);
for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) { for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
ff_vvc_unref_frame(fc, &fc->DPB[i], ~0); ff_vvc_unref_frame(fc, &fc->DPB[i], ~0);
@ -656,11 +656,11 @@ static av_cold int frame_context_init(VVCFrameContext *fc, AVCodecContext *avctx
if (!fc->DPB[j].frame) if (!fc->DPB[j].frame)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
fc->cu_pool = ff_refstruct_pool_alloc(sizeof(CodingUnit), 0); fc->cu_pool = av_refstruct_pool_alloc(sizeof(CodingUnit), 0);
if (!fc->cu_pool) if (!fc->cu_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
fc->tu_pool = ff_refstruct_pool_alloc(sizeof(TransformUnit), 0); fc->tu_pool = av_refstruct_pool_alloc(sizeof(TransformUnit), 0);
if (!fc->tu_pool) if (!fc->tu_pool)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -743,7 +743,7 @@ static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc,
if (ret < 0) if (ret < 0)
return ret; return ret;
ff_refstruct_replace(&sc->ref, unit->content_ref); av_refstruct_replace(&sc->ref, unit->content_ref);
if (is_first_slice) { if (is_first_slice) {
ret = frame_start(s, fc, sc); ret = frame_start(s, fc, sc);

View file

@ -138,11 +138,11 @@ typedef struct VVCFrameContext {
uint64_t decode_order; uint64_t decode_order;
struct FFRefStructPool *tab_dmvr_mvf_pool; struct AVRefStructPool *tab_dmvr_mvf_pool;
struct FFRefStructPool *rpl_tab_pool; struct AVRefStructPool *rpl_tab_pool;
struct FFRefStructPool *cu_pool; struct AVRefStructPool *cu_pool;
struct FFRefStructPool *tu_pool; struct AVRefStructPool *tu_pool;
struct { struct {
int16_t *slice_idx; int16_t *slice_idx;

View file

@ -24,7 +24,7 @@
#include "libavcodec/cbs_h266.h" #include "libavcodec/cbs_h266.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavcodec/refstruct.h" #include "libavutil/refstruct.h"
#include "data.h" #include "data.h"
#include "ps.h" #include "ps.h"
#include "dec.h" #include "dec.h"
@ -200,21 +200,21 @@ static int sps_derive(VVCSPS *sps, void *log_ctx)
return 0; return 0;
} }
static void sps_free(FFRefStructOpaque opaque, void *obj) static void sps_free(AVRefStructOpaque opaque, void *obj)
{ {
VVCSPS *sps = obj; VVCSPS *sps = obj;
ff_refstruct_unref(&sps->r); av_refstruct_unref(&sps->r);
} }
static const VVCSPS *sps_alloc(const H266RawSPS *rsps, void *log_ctx) static const VVCSPS *sps_alloc(const H266RawSPS *rsps, void *log_ctx)
{ {
int ret; int ret;
VVCSPS *sps = ff_refstruct_alloc_ext(sizeof(*sps), 0, NULL, sps_free); VVCSPS *sps = av_refstruct_alloc_ext(sizeof(*sps), 0, NULL, sps_free);
if (!sps) if (!sps)
return NULL; return NULL;
ff_refstruct_replace(&sps->r, rsps); av_refstruct_replace(&sps->r, rsps);
ret = sps_derive(sps, log_ctx); ret = sps_derive(sps, log_ctx);
if (ret < 0) if (ret < 0)
@ -223,7 +223,7 @@ static const VVCSPS *sps_alloc(const H266RawSPS *rsps, void *log_ctx)
return sps; return sps;
fail: fail:
ff_refstruct_unref(&sps); av_refstruct_unref(&sps);
return NULL; return NULL;
} }
@ -248,7 +248,7 @@ static int decode_sps(VVCParamSets *ps, const H266RawSPS *rsps, void *log_ctx, i
if (!sps) if (!sps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ff_refstruct_unref(&ps->sps_list[sps_id]); av_refstruct_unref(&ps->sps_list[sps_id]);
ps->sps_list[sps_id] = sps; ps->sps_list[sps_id] = sps;
ps->sps_id_used |= (1 << sps_id); ps->sps_id_used |= (1 << sps_id);
@ -572,11 +572,11 @@ static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
return 0; return 0;
} }
static void pps_free(FFRefStructOpaque opaque, void *obj) static void pps_free(AVRefStructOpaque opaque, void *obj)
{ {
VVCPPS *pps = obj; VVCPPS *pps = obj;
ff_refstruct_unref(&pps->r); av_refstruct_unref(&pps->r);
av_freep(&pps->col_bd); av_freep(&pps->col_bd);
av_freep(&pps->row_bd); av_freep(&pps->row_bd);
@ -588,12 +588,12 @@ static void pps_free(FFRefStructOpaque opaque, void *obj)
static const VVCPPS *pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps) static const VVCPPS *pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps)
{ {
int ret; int ret;
VVCPPS *pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free); VVCPPS *pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free);
if (!pps) if (!pps)
return NULL; return NULL;
ff_refstruct_replace(&pps->r, rpps); av_refstruct_replace(&pps->r, rpps);
ret = pps_derive(pps, sps); ret = pps_derive(pps, sps);
if (ret < 0) if (ret < 0)
@ -602,7 +602,7 @@ static const VVCPPS *pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps)
return pps; return pps;
fail: fail:
ff_refstruct_unref(&pps); av_refstruct_unref(&pps);
return NULL; return NULL;
} }
@ -621,7 +621,7 @@ static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps)
if (!pps) if (!pps)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ff_refstruct_unref(&ps->pps_list[pps_id]); av_refstruct_unref(&ps->pps_list[pps_id]);
ps->pps_list[pps_id] = pps; ps->pps_list[pps_id] = pps;
return ret; return ret;
@ -868,7 +868,7 @@ static int decode_ph(VVCFrameParamSets *fps, const H266RawPictureHeader *rph, vo
const H266RawPPS *pps = fps->pps->r; const H266RawPPS *pps = fps->pps->r;
ph->r = rph; ph->r = rph;
ff_refstruct_replace(&ph->rref, rph_ref); av_refstruct_replace(&ph->rref, rph_ref);
ret = ph_derive(ph, sps, pps, poc_tid0, is_clvss); ret = ph_derive(ph, sps, pps, poc_tid0, is_clvss);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -890,15 +890,15 @@ static int decode_frame_ps(VVCFrameParamSets *fps, const VVCParamSets *ps,
if (!rpps) if (!rpps)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
ff_refstruct_replace(&fps->sps, ps->sps_list[rpps->pps_seq_parameter_set_id]); av_refstruct_replace(&fps->sps, ps->sps_list[rpps->pps_seq_parameter_set_id]);
ff_refstruct_replace(&fps->pps, ps->pps_list[rpps->pps_pic_parameter_set_id]); av_refstruct_replace(&fps->pps, ps->pps_list[rpps->pps_pic_parameter_set_id]);
ret = decode_ph(fps, ph, h266->ph_ref, poc_tid0, is_clvss); ret = decode_ph(fps, ph, h266->ph_ref, poc_tid0, is_clvss);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ph->ph_explicit_scaling_list_enabled_flag) if (ph->ph_explicit_scaling_list_enabled_flag)
ff_refstruct_replace(&fps->sl, ps->scaling_list[ph->ph_scaling_list_aps_id]); av_refstruct_replace(&fps->sl, ps->scaling_list[ph->ph_scaling_list_aps_id]);
if (ph->ph_lmcs_enabled_flag) { if (ph->ph_lmcs_enabled_flag) {
ret = lmcs_derive_lut(&fps->lmcs, ps->lmcs_list[ph->ph_lmcs_aps_id], fps->sps->r); ret = lmcs_derive_lut(&fps->lmcs, ps->lmcs_list[ph->ph_lmcs_aps_id], fps->sps->r);
@ -907,7 +907,7 @@ static int decode_frame_ps(VVCFrameParamSets *fps, const VVCParamSets *ps,
} }
for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
ff_refstruct_replace(&fps->alf_list[i], ps->alf_list[i]); av_refstruct_replace(&fps->alf_list[i], ps->alf_list[i]);
return 0; return 0;
} }
@ -951,26 +951,26 @@ int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s)
void ff_vvc_frame_ps_free(VVCFrameParamSets *fps) void ff_vvc_frame_ps_free(VVCFrameParamSets *fps)
{ {
ff_refstruct_unref(&fps->sps); av_refstruct_unref(&fps->sps);
ff_refstruct_unref(&fps->pps); av_refstruct_unref(&fps->pps);
ff_refstruct_unref(&fps->ph.rref); av_refstruct_unref(&fps->ph.rref);
ff_refstruct_unref(&fps->sl); av_refstruct_unref(&fps->sl);
for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
ff_refstruct_unref(&fps->alf_list[i]); av_refstruct_unref(&fps->alf_list[i]);
} }
void ff_vvc_ps_uninit(VVCParamSets *ps) void ff_vvc_ps_uninit(VVCParamSets *ps)
{ {
for (int i = 0; i < FF_ARRAY_ELEMS(ps->scaling_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(ps->scaling_list); i++)
ff_refstruct_unref(&ps->scaling_list[i]); av_refstruct_unref(&ps->scaling_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(ps->lmcs_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(ps->lmcs_list); i++)
ff_refstruct_unref(&ps->lmcs_list[i]); av_refstruct_unref(&ps->lmcs_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(ps->alf_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(ps->alf_list); i++)
ff_refstruct_unref(&ps->alf_list[i]); av_refstruct_unref(&ps->alf_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
ff_refstruct_unref(&ps->sps_list[i]); av_refstruct_unref(&ps->sps_list[i]);
for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
ff_refstruct_unref(&ps->pps_list[i]); av_refstruct_unref(&ps->pps_list[i]);
} }
static void alf_coeff(int16_t *coeff, static void alf_coeff(int16_t *coeff,
@ -1049,23 +1049,23 @@ static void alf_derive(VVCALF *alf, const H266RawAPS *aps)
alf_cc(alf, aps); alf_cc(alf, aps);
} }
static void alf_free(FFRefStructOpaque unused, void *obj) static void alf_free(AVRefStructOpaque unused, void *obj)
{ {
VVCALF *alf = obj; VVCALF *alf = obj;
ff_refstruct_unref(&alf->r); av_refstruct_unref(&alf->r);
} }
static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps) static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps)
{ {
VVCALF *a = ff_refstruct_alloc_ext(sizeof(*a), 0, NULL, alf_free); VVCALF *a = av_refstruct_alloc_ext(sizeof(*a), 0, NULL, alf_free);
if (!a) if (!a)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
alf_derive(a, aps); alf_derive(a, aps);
ff_refstruct_replace(&a->r, aps); av_refstruct_replace(&a->r, aps);
ff_refstruct_replace(alf, a); av_refstruct_replace(alf, a);
ff_refstruct_unref(&a); av_refstruct_unref(&a);
return 0; return 0;
} }
@ -1145,13 +1145,13 @@ static void scaling_derive(VVCScalingList *sl, const H266RawAPS *aps)
static int aps_decode_scaling(const VVCScalingList **scaling, const H266RawAPS *aps) static int aps_decode_scaling(const VVCScalingList **scaling, const H266RawAPS *aps)
{ {
VVCScalingList *sl = ff_refstruct_allocz(sizeof(*sl)); VVCScalingList *sl = av_refstruct_allocz(sizeof(*sl));
if (!sl) if (!sl)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
scaling_derive(sl, aps); scaling_derive(sl, aps);
ff_refstruct_replace(scaling, sl); av_refstruct_replace(scaling, sl);
ff_refstruct_unref(&sl); av_refstruct_unref(&sl);
return 0; return 0;
} }
@ -1169,7 +1169,7 @@ int ff_vvc_decode_aps(VVCParamSets *ps, const CodedBitstreamUnit *unit)
ret = aps_decode_alf(&ps->alf_list[aps->aps_adaptation_parameter_set_id], aps); ret = aps_decode_alf(&ps->alf_list[aps->aps_adaptation_parameter_set_id], aps);
break; break;
case VVC_ASP_TYPE_LMCS: case VVC_ASP_TYPE_LMCS:
ff_refstruct_replace(&ps->lmcs_list[aps->aps_adaptation_parameter_set_id], aps); av_refstruct_replace(&ps->lmcs_list[aps->aps_adaptation_parameter_set_id], aps);
break; break;
case VVC_ASP_TYPE_SCALING: case VVC_ASP_TYPE_SCALING:
ret = aps_decode_scaling(&ps->scaling_list[aps->aps_adaptation_parameter_set_id], aps); ret = aps_decode_scaling(&ps->scaling_list[aps->aps_adaptation_parameter_set_id], aps);
@ -1352,7 +1352,7 @@ int ff_vvc_decode_sh(VVCSH *sh, const VVCFrameParamSets *fps, const CodedBitstre
if (!fps->sps || !fps->pps) if (!fps->sps || !fps->pps)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
ff_refstruct_replace(&sh->r, unit->content_ref); av_refstruct_replace(&sh->r, unit->content_ref);
ret = sh_derive(sh, fps); ret = sh_derive(sh, fps);
if (ret < 0) if (ret < 0)

View file

@ -24,7 +24,7 @@
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/thread.h" #include "libavutil/thread.h"
#include "libavcodec/refstruct.h" #include "libavutil/refstruct.h"
#include "libavcodec/thread.h" #include "libavcodec/thread.h"
#include "libavcodec/decode.h" #include "libavcodec/decode.h"
@ -49,18 +49,18 @@ void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, int flags)
frame->flags &= ~flags; frame->flags &= ~flags;
if (!frame->flags) { if (!frame->flags) {
av_frame_unref(frame->frame); av_frame_unref(frame->frame);
ff_refstruct_unref(&frame->sps); av_refstruct_unref(&frame->sps);
ff_refstruct_unref(&frame->pps); av_refstruct_unref(&frame->pps);
ff_refstruct_unref(&frame->progress); av_refstruct_unref(&frame->progress);
ff_refstruct_unref(&frame->tab_dmvr_mvf); av_refstruct_unref(&frame->tab_dmvr_mvf);
ff_refstruct_unref(&frame->rpl); av_refstruct_unref(&frame->rpl);
frame->nb_rpl_elems = 0; frame->nb_rpl_elems = 0;
ff_refstruct_unref(&frame->rpl_tab); av_refstruct_unref(&frame->rpl_tab);
frame->collocated_ref = NULL; frame->collocated_ref = NULL;
ff_refstruct_unref(&frame->hwaccel_picture_private); av_refstruct_unref(&frame->hwaccel_picture_private);
} }
} }
@ -87,7 +87,7 @@ void ff_vvc_flush_dpb(VVCFrameContext *fc)
ff_vvc_unref_frame(fc, &fc->DPB[i], ~0); ff_vvc_unref_frame(fc, &fc->DPB[i], ~0);
} }
static void free_progress(FFRefStructOpaque unused, void *obj) static void free_progress(AVRefStructOpaque unused, void *obj)
{ {
FrameProgress *p = (FrameProgress *)obj; FrameProgress *p = (FrameProgress *)obj;
@ -99,13 +99,13 @@ static void free_progress(FFRefStructOpaque unused, void *obj)
static FrameProgress *alloc_progress(void) static FrameProgress *alloc_progress(void)
{ {
FrameProgress *p = ff_refstruct_alloc_ext(sizeof(*p), 0, NULL, free_progress); FrameProgress *p = av_refstruct_alloc_ext(sizeof(*p), 0, NULL, free_progress);
if (p) { if (p) {
p->has_lock = !ff_mutex_init(&p->lock, NULL); p->has_lock = !ff_mutex_init(&p->lock, NULL);
p->has_cond = !ff_cond_init(&p->cond, NULL); p->has_cond = !ff_cond_init(&p->cond, NULL);
if (!p->has_lock || !p->has_cond) if (!p->has_lock || !p->has_cond)
ff_refstruct_unref(&p); av_refstruct_unref(&p);
} }
return p; return p;
} }
@ -121,23 +121,23 @@ static VVCFrame *alloc_frame(VVCContext *s, VVCFrameContext *fc)
if (frame->frame->buf[0]) if (frame->frame->buf[0])
continue; continue;
frame->sps = ff_refstruct_ref_c(fc->ps.sps); frame->sps = av_refstruct_ref_c(fc->ps.sps);
frame->pps = ff_refstruct_ref_c(fc->ps.pps); frame->pps = av_refstruct_ref_c(fc->ps.pps);
ret = ff_thread_get_buffer(s->avctx, frame->frame, AV_GET_BUFFER_FLAG_REF); ret = ff_thread_get_buffer(s->avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
frame->rpl = ff_refstruct_allocz(s->current_frame.nb_units * sizeof(RefPicListTab)); frame->rpl = av_refstruct_allocz(s->current_frame.nb_units * sizeof(RefPicListTab));
if (!frame->rpl) if (!frame->rpl)
goto fail; goto fail;
frame->nb_rpl_elems = s->current_frame.nb_units; frame->nb_rpl_elems = s->current_frame.nb_units;
frame->tab_dmvr_mvf = ff_refstruct_pool_get(fc->tab_dmvr_mvf_pool); frame->tab_dmvr_mvf = av_refstruct_pool_get(fc->tab_dmvr_mvf_pool);
if (!frame->tab_dmvr_mvf) if (!frame->tab_dmvr_mvf)
goto fail; goto fail;
frame->rpl_tab = ff_refstruct_pool_get(fc->rpl_tab_pool); frame->rpl_tab = av_refstruct_pool_get(fc->rpl_tab_pool);
if (!frame->rpl_tab) if (!frame->rpl_tab)
goto fail; goto fail;
frame->ctb_count = pps->ctb_width * pps->ctb_height; frame->ctb_count = pps->ctb_width * pps->ctb_height;

View file

@ -28,7 +28,7 @@
#include "bytestream.h" #include "bytestream.h"
#include "codec_internal.h" #include "codec_internal.h"
#include "get_bits.h" #include "get_bits.h"
#include "refstruct.h" #include "libavutil/refstruct.h"
#include "thread.h" #include "thread.h"
#include "threadprogress.h" #include "threadprogress.h"
#include "unary.h" #include "unary.h"
@ -110,7 +110,7 @@ typedef struct WavpackContext {
DSDContext *dsdctx; ///< RefStruct reference DSDContext *dsdctx; ///< RefStruct reference
ThreadProgress *curr_progress, *prev_progress; ///< RefStruct references ThreadProgress *curr_progress, *prev_progress; ///< RefStruct references
FFRefStructPool *progress_pool; ///< RefStruct reference AVRefStructPool *progress_pool; ///< RefStruct reference
int dsd_channels; int dsd_channels;
} WavpackContext; } WavpackContext;
@ -992,9 +992,9 @@ static int wv_dsd_reset(WavpackContext *s, int channels)
int i; int i;
s->dsd_channels = 0; s->dsd_channels = 0;
ff_refstruct_unref(&s->dsdctx); av_refstruct_unref(&s->dsdctx);
ff_refstruct_unref(&s->curr_progress); av_refstruct_unref(&s->curr_progress);
ff_refstruct_unref(&s->prev_progress); av_refstruct_unref(&s->prev_progress);
if (!channels) if (!channels)
return 0; return 0;
@ -1003,7 +1003,7 @@ static int wv_dsd_reset(WavpackContext *s, int channels)
channels > SIZE_MAX / sizeof(*s->dsdctx)) channels > SIZE_MAX / sizeof(*s->dsdctx))
return AVERROR(EINVAL); return AVERROR(EINVAL);
s->dsdctx = ff_refstruct_allocz(channels * sizeof(*s->dsdctx)); s->dsdctx = av_refstruct_allocz(channels * sizeof(*s->dsdctx));
if (!s->dsdctx) if (!s->dsdctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
s->dsd_channels = channels; s->dsd_channels = channels;
@ -1022,26 +1022,26 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
WavpackContext *fsrc = src->priv_data; WavpackContext *fsrc = src->priv_data;
WavpackContext *fdst = dst->priv_data; WavpackContext *fdst = dst->priv_data;
ff_refstruct_replace(&fdst->curr_progress, fsrc->curr_progress); av_refstruct_replace(&fdst->curr_progress, fsrc->curr_progress);
ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx); av_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx);
fdst->dsd_channels = fsrc->dsd_channels; fdst->dsd_channels = fsrc->dsd_channels;
return 0; return 0;
} }
static av_cold int progress_pool_init_cb(FFRefStructOpaque opaque, void *obj) static av_cold int progress_pool_init_cb(AVRefStructOpaque opaque, void *obj)
{ {
ThreadProgress *progress = obj; ThreadProgress *progress = obj;
return ff_thread_progress_init(progress, 1); return ff_thread_progress_init(progress, 1);
} }
static void progress_pool_reset_cb(FFRefStructOpaque opaque, void *obj) static void progress_pool_reset_cb(AVRefStructOpaque opaque, void *obj)
{ {
ThreadProgress *progress = obj; ThreadProgress *progress = obj;
ff_thread_progress_reset(progress); ff_thread_progress_reset(progress);
} }
static av_cold void progress_pool_free_entry_cb(FFRefStructOpaque opaque, void *obj) static av_cold void progress_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
{ {
ThreadProgress *progress = obj; ThreadProgress *progress = obj;
ff_thread_progress_destroy(progress); ff_thread_progress_destroy(progress);
@ -1058,8 +1058,8 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
#if HAVE_THREADS #if HAVE_THREADS
if (ff_thread_sync_ref(avctx, offsetof(WavpackContext, progress_pool)) == FF_THREAD_IS_FIRST_THREAD) { if (ff_thread_sync_ref(avctx, offsetof(WavpackContext, progress_pool)) == FF_THREAD_IS_FIRST_THREAD) {
s->progress_pool = ff_refstruct_pool_alloc_ext(sizeof(*s->curr_progress), s->progress_pool = av_refstruct_pool_alloc_ext(sizeof(*s->curr_progress),
FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR, NULL, AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR, NULL,
progress_pool_init_cb, progress_pool_init_cb,
progress_pool_reset_cb, progress_pool_reset_cb,
progress_pool_free_entry_cb, NULL); progress_pool_free_entry_cb, NULL);
@ -1080,7 +1080,7 @@ static av_cold int wavpack_decode_end(AVCodecContext *avctx)
av_freep(&s->fdec); av_freep(&s->fdec);
s->fdec_num = 0; s->fdec_num = 0;
ff_refstruct_pool_uninit(&s->progress_pool); av_refstruct_pool_uninit(&s->progress_pool);
wv_dsd_reset(s, 0); wv_dsd_reset(s, 0);
return 0; return 0;
@ -1552,8 +1552,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, AVFrame *frame, int block
av_assert1(!!wc->progress_pool == !!(avctx->active_thread_type & FF_THREAD_FRAME)); av_assert1(!!wc->progress_pool == !!(avctx->active_thread_type & FF_THREAD_FRAME));
if (wc->progress_pool) { if (wc->progress_pool) {
if (wc->dsdctx) { if (wc->dsdctx) {
ff_refstruct_unref(&wc->prev_progress); av_refstruct_unref(&wc->prev_progress);
wc->prev_progress = ff_refstruct_pool_get(wc->progress_pool); wc->prev_progress = av_refstruct_pool_get(wc->progress_pool);
if (!wc->prev_progress) if (!wc->prev_progress)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
FFSWAP(ThreadProgress*, wc->prev_progress, wc->curr_progress); FFSWAP(ThreadProgress*, wc->prev_progress, wc->curr_progress);

View file

@ -75,6 +75,7 @@ HEADERS = adler32.h \
random_seed.h \ random_seed.h \
rc4.h \ rc4.h \
rational.h \ rational.h \
refstruct.h \
replaygain.h \ replaygain.h \
ripemd.h \ ripemd.h \
samplefmt.h \ samplefmt.h \
@ -163,6 +164,7 @@ OBJS = adler32.o \
pixelutils.o \ pixelutils.o \
random_seed.o \ random_seed.o \
rational.o \ rational.o \
refstruct.o \
reverse.o \ reverse.o \
rc4.o \ rc4.o \
ripemd.o \ ripemd.o \

View file

@ -22,12 +22,12 @@
#include "refstruct.h" #include "refstruct.h"
#include "libavutil/avassert.h" #include "avassert.h"
#include "libavutil/error.h" #include "error.h"
#include "libavutil/macros.h" #include "macros.h"
#include "libavutil/mem.h" #include "mem.h"
#include "libavutil/mem_internal.h" #include "mem_internal.h"
#include "libavutil/thread.h" #include "thread.h"
#ifndef REFSTRUCT_CHECKED #ifndef REFSTRUCT_CHECKED
#ifndef ASSERT_LEVEL #ifndef ASSERT_LEVEL
@ -58,8 +58,8 @@ typedef struct RefCount {
* the user does not throw away references. * the user does not throw away references.
*/ */
atomic_uintptr_t refcount; atomic_uintptr_t refcount;
FFRefStructOpaque opaque; AVRefStructOpaque opaque;
void (*free_cb)(FFRefStructOpaque opaque, void *obj); void (*free_cb)(AVRefStructOpaque opaque, void *obj);
void (*free)(void *ref); void (*free)(void *ref);
#if REFSTRUCT_CHECKED #if REFSTRUCT_CHECKED
@ -86,8 +86,8 @@ static void *get_userdata(void *buf)
return (char*)buf + REFCOUNT_OFFSET; return (char*)buf + REFCOUNT_OFFSET;
} }
static void refcount_init(RefCount *ref, FFRefStructOpaque opaque, static void refcount_init(RefCount *ref, AVRefStructOpaque opaque,
void (*free_cb)(FFRefStructOpaque opaque, void *obj)) void (*free_cb)(AVRefStructOpaque opaque, void *obj))
{ {
atomic_init(&ref->refcount, 1); atomic_init(&ref->refcount, 1);
ref->opaque = opaque; ref->opaque = opaque;
@ -99,8 +99,8 @@ static void refcount_init(RefCount *ref, FFRefStructOpaque opaque,
#endif #endif
} }
void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, void *av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque,
void (*free_cb)(FFRefStructOpaque opaque, void *obj)) void (*free_cb)(AVRefStructOpaque opaque, void *obj))
{ {
void *buf, *obj; void *buf, *obj;
@ -111,13 +111,13 @@ void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque op
return NULL; return NULL;
refcount_init(buf, opaque, free_cb); refcount_init(buf, opaque, free_cb);
obj = get_userdata(buf); obj = get_userdata(buf);
if (!(flags & FF_REFSTRUCT_FLAG_NO_ZEROING)) if (!(flags & AV_REFSTRUCT_FLAG_NO_ZEROING))
memset(obj, 0, size); memset(obj, 0, size);
return obj; return obj;
} }
void ff_refstruct_unref(void *objp) void av_refstruct_unref(void *objp)
{ {
void *obj; void *obj;
RefCount *ref; RefCount *ref;
@ -137,7 +137,7 @@ void ff_refstruct_unref(void *objp)
return; return;
} }
void *ff_refstruct_ref(void *obj) void *av_refstruct_ref(void *obj)
{ {
RefCount *ref = get_refcount(obj); RefCount *ref = get_refcount(obj);
@ -146,7 +146,7 @@ void *ff_refstruct_ref(void *obj)
return obj; return obj;
} }
const void *ff_refstruct_ref_c(const void *obj) const void *av_refstruct_ref_c(const void *obj)
{ {
/* Casting const away here is fine, as it is only supposed /* Casting const away here is fine, as it is only supposed
* to apply to the user's data and not our bookkeeping data. */ * to apply to the user's data and not our bookkeeping data. */
@ -157,21 +157,21 @@ const void *ff_refstruct_ref_c(const void *obj)
return obj; return obj;
} }
void ff_refstruct_replace(void *dstp, const void *src) void av_refstruct_replace(void *dstp, const void *src)
{ {
const void *dst; const void *dst;
memcpy(&dst, dstp, sizeof(dst)); memcpy(&dst, dstp, sizeof(dst));
if (src == dst) if (src == dst)
return; return;
ff_refstruct_unref(dstp); av_refstruct_unref(dstp);
if (src) { if (src) {
dst = ff_refstruct_ref_c(src); dst = av_refstruct_ref_c(src);
memcpy(dstp, &dst, sizeof(dst)); memcpy(dstp, &dst, sizeof(dst));
} }
} }
int ff_refstruct_exclusive(const void *obj) int av_refstruct_exclusive(const void *obj)
{ {
const RefCount *ref = cget_refcount(obj); const RefCount *ref = cget_refcount(obj);
/* Casting const away here is safe, because it is a load. /* Casting const away here is safe, because it is a load.
@ -180,13 +180,13 @@ int ff_refstruct_exclusive(const void *obj)
return atomic_load_explicit((atomic_uintptr_t*)&ref->refcount, memory_order_acquire) == 1; return atomic_load_explicit((atomic_uintptr_t*)&ref->refcount, memory_order_acquire) == 1;
} }
struct FFRefStructPool { struct AVRefStructPool {
size_t size; size_t size;
FFRefStructOpaque opaque; AVRefStructOpaque opaque;
int (*init_cb)(FFRefStructOpaque opaque, void *obj); int (*init_cb)(AVRefStructOpaque opaque, void *obj);
void (*reset_cb)(FFRefStructOpaque opaque, void *obj); void (*reset_cb)(AVRefStructOpaque opaque, void *obj);
void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj); void (*free_entry_cb)(AVRefStructOpaque opaque, void *obj);
void (*free_cb)(FFRefStructOpaque opaque); void (*free_cb)(AVRefStructOpaque opaque);
int uninited; int uninited;
unsigned entry_flags; unsigned entry_flags;
@ -199,13 +199,13 @@ struct FFRefStructPool {
* the RefCount's opaque pointer is used as next pointer * the RefCount's opaque pointer is used as next pointer
* for available entries. * for available entries.
* While the entries are in use, the opaque is a pointer * While the entries are in use, the opaque is a pointer
* to the corresponding FFRefStructPool. * to the corresponding AVRefStructPool.
*/ */
RefCount *available_entries; RefCount *available_entries;
AVMutex mutex; AVMutex mutex;
}; };
static void pool_free(FFRefStructPool *pool) static void pool_free(AVRefStructPool *pool)
{ {
ff_mutex_destroy(&pool->mutex); ff_mutex_destroy(&pool->mutex);
if (pool->free_cb) if (pool->free_cb)
@ -213,7 +213,7 @@ static void pool_free(FFRefStructPool *pool)
av_free(get_refcount(pool)); av_free(get_refcount(pool));
} }
static void pool_free_entry(FFRefStructPool *pool, RefCount *ref) static void pool_free_entry(AVRefStructPool *pool, RefCount *ref)
{ {
if (pool->free_entry_cb) if (pool->free_entry_cb)
pool->free_entry_cb(pool->opaque, get_userdata(ref)); pool->free_entry_cb(pool->opaque, get_userdata(ref));
@ -223,7 +223,7 @@ static void pool_free_entry(FFRefStructPool *pool, RefCount *ref)
static void pool_return_entry(void *ref_) static void pool_return_entry(void *ref_)
{ {
RefCount *ref = ref_; RefCount *ref = ref_;
FFRefStructPool *pool = ref->opaque.nc; AVRefStructPool *pool = ref->opaque.nc;
ff_mutex_lock(&pool->mutex); ff_mutex_lock(&pool->mutex);
if (!pool->uninited) { if (!pool->uninited) {
@ -240,14 +240,14 @@ static void pool_return_entry(void *ref_)
pool_free(pool); pool_free(pool);
} }
static void pool_reset_entry(FFRefStructOpaque opaque, void *entry) static void pool_reset_entry(AVRefStructOpaque opaque, void *entry)
{ {
FFRefStructPool *pool = opaque.nc; AVRefStructPool *pool = opaque.nc;
pool->reset_cb(pool->opaque, entry); pool->reset_cb(pool->opaque, entry);
} }
static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) static int refstruct_pool_get_ext(void *datap, AVRefStructPool *pool)
{ {
void *ret = NULL; void *ret = NULL;
@ -266,7 +266,7 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool)
if (!ret) { if (!ret) {
RefCount *ref; RefCount *ref;
ret = ff_refstruct_alloc_ext(pool->size, pool->entry_flags, pool, ret = av_refstruct_alloc_ext(pool->size, pool->entry_flags, pool,
pool->reset_cb ? pool_reset_entry : NULL); pool->reset_cb ? pool_reset_entry : NULL);
if (!ret) if (!ret)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -275,9 +275,9 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool)
if (pool->init_cb) { if (pool->init_cb) {
int err = pool->init_cb(pool->opaque, ret); int err = pool->init_cb(pool->opaque, ret);
if (err < 0) { if (err < 0) {
if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR) if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR)
pool->reset_cb(pool->opaque, ret); pool->reset_cb(pool->opaque, ret);
if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR) if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR)
pool->free_entry_cb(pool->opaque, ret); pool->free_entry_cb(pool->opaque, ret);
av_free(ref); av_free(ref);
return err; return err;
@ -286,7 +286,7 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool)
} }
atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed); atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed);
if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) if (pool->pool_flags & AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME)
memset(ret, 0, pool->size); memset(ret, 0, pool->size);
memcpy(datap, &ret, sizeof(ret)); memcpy(datap, &ret, sizeof(ret));
@ -294,7 +294,7 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool)
return 0; return 0;
} }
void *ff_refstruct_pool_get(FFRefStructPool *pool) void *av_refstruct_pool_get(AVRefStructPool *pool)
{ {
void *ret; void *ret;
refstruct_pool_get_ext(&ret, pool); refstruct_pool_get_ext(&ret, pool);
@ -308,14 +308,14 @@ void *ff_refstruct_pool_get(FFRefStructPool *pool)
*/ */
static void pool_unref(void *ref) static void pool_unref(void *ref)
{ {
FFRefStructPool *pool = get_userdata(ref); AVRefStructPool *pool = get_userdata(ref);
if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1)
pool_free(pool); pool_free(pool);
} }
static void refstruct_pool_uninit(FFRefStructOpaque unused, void *obj) static void refstruct_pool_uninit(AVRefStructOpaque unused, void *obj)
{ {
FFRefStructPool *pool = obj; AVRefStructPool *pool = obj;
RefCount *entry; RefCount *entry;
ff_mutex_lock(&pool->mutex); ff_mutex_lock(&pool->mutex);
@ -332,19 +332,19 @@ static void refstruct_pool_uninit(FFRefStructOpaque unused, void *obj)
} }
} }
FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags) AVRefStructPool *av_refstruct_pool_alloc(size_t size, unsigned flags)
{ {
return ff_refstruct_pool_alloc_ext(size, flags, NULL, NULL, NULL, NULL, NULL); return av_refstruct_pool_alloc_ext(size, flags, NULL, NULL, NULL, NULL, NULL);
} }
FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, AVRefStructPool *av_refstruct_pool_alloc_ext_c(size_t size, unsigned flags,
FFRefStructOpaque opaque, AVRefStructOpaque opaque,
int (*init_cb)(FFRefStructOpaque opaque, void *obj), int (*init_cb)(AVRefStructOpaque opaque, void *obj),
void (*reset_cb)(FFRefStructOpaque opaque, void *obj), void (*reset_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_entry_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_cb)(FFRefStructOpaque opaque)) void (*free_cb)(AVRefStructOpaque opaque))
{ {
FFRefStructPool *pool = ff_refstruct_alloc_ext(sizeof(*pool), 0, NULL, AVRefStructPool *pool = av_refstruct_alloc_ext(sizeof(*pool), 0, NULL,
refstruct_pool_uninit); refstruct_pool_uninit);
int err; int err;
@ -358,26 +358,26 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags,
pool->reset_cb = reset_cb; pool->reset_cb = reset_cb;
pool->free_entry_cb = free_entry_cb; pool->free_entry_cb = free_entry_cb;
pool->free_cb = free_cb; pool->free_cb = free_cb;
#define COMMON_FLAGS FF_REFSTRUCT_POOL_FLAG_NO_ZEROING #define COMMON_FLAGS AV_REFSTRUCT_POOL_FLAG_NO_ZEROING
pool->entry_flags = flags & COMMON_FLAGS; pool->entry_flags = flags & COMMON_FLAGS;
// Filter out nonsense combinations to avoid checks later. // Filter out nonsense combinations to avoid checks later.
if (!pool->reset_cb) if (!pool->reset_cb)
flags &= ~FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR; flags &= ~AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR;
if (!pool->free_entry_cb) if (!pool->free_entry_cb)
flags &= ~FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR; flags &= ~AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR;
pool->pool_flags = flags; pool->pool_flags = flags;
if (flags & FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) { if (flags & AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) {
// We will zero the buffer before every use, so zeroing // We will zero the buffer before every use, so zeroing
// upon allocating the buffer is unnecessary. // upon allocating the buffer is unnecessary.
pool->entry_flags |= FF_REFSTRUCT_FLAG_NO_ZEROING; pool->entry_flags |= AV_REFSTRUCT_FLAG_NO_ZEROING;
} }
atomic_init(&pool->refcount, 1); atomic_init(&pool->refcount, 1);
err = ff_mutex_init(&pool->mutex, NULL); err = ff_mutex_init(&pool->mutex, NULL);
if (err) { if (err) {
// Don't call ff_refstruct_uninit() on pool, as it hasn't been properly // Don't call av_refstruct_uninit() on pool, as it hasn't been properly
// set up and is just a POD right now. // set up and is just a POD right now.
av_free(get_refcount(pool)); av_free(get_refcount(pool));
return NULL; return NULL;

View file

@ -16,8 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef AVCODEC_REFSTRUCT_H #ifndef AVUTIL_REFSTRUCT_H
#define AVCODEC_REFSTRUCT_H #define AVUTIL_REFSTRUCT_H
#include <stddef.h> #include <stddef.h>
@ -51,20 +51,20 @@
* This union is used for all opaque parameters in this API to spare the user * This union is used for all opaque parameters in this API to spare the user
* to cast const away in case the opaque to use is const-qualified. * to cast const away in case the opaque to use is const-qualified.
* *
* The functions provided by this API with an FFRefStructOpaque come in pairs * The functions provided by this API with an AVRefStructOpaque come in pairs
* named foo_c and foo. The foo function accepts void* as opaque and is just * named foo_c and foo. The foo function accepts void* as opaque and is just
* a wrapper around the foo_c function; "_c" means "(potentially) const". * a wrapper around the foo_c function; "_c" means "(potentially) const".
*/ */
typedef union { typedef union {
void *nc; void *nc;
const void *c; const void *c;
} FFRefStructOpaque; } AVRefStructOpaque;
/** /**
* If this flag is set in ff_refstruct_alloc_ext_c(), the object will not * If this flag is set in av_refstruct_alloc_ext_c(), the object will not
* be initially zeroed. * be initially zeroed.
*/ */
#define FF_REFSTRUCT_FLAG_NO_ZEROING (1 << 0) #define AV_REFSTRUCT_FLAG_NO_ZEROING (1 << 0)
/** /**
* Allocate a refcounted object of usable size `size` managed via * Allocate a refcounted object of usable size `size` managed via
@ -74,37 +74,37 @@ typedef union {
* the returned object is initially zeroed. * the returned object is initially zeroed.
* *
* @param size Desired usable size of the returned object. * @param size Desired usable size of the returned object.
* @param flags A bitwise combination of FF_REFSTRUCT_FLAG_* flags. * @param flags A bitwise combination of av_refstruct_FLAG_* flags.
* @param opaque A pointer that will be passed to the free_cb callback. * @param opaque A pointer that will be passed to the free_cb callback.
* @param free_cb A callback for freeing this object's content * @param free_cb A callback for freeing this object's content
* when its reference count reaches zero; * when its reference count reaches zero;
* it must not free the object itself. * it must not free the object itself.
* @return A pointer to an object of the desired size or NULL on failure. * @return A pointer to an object of the desired size or NULL on failure.
*/ */
void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, void *av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque,
void (*free_cb)(FFRefStructOpaque opaque, void *obj)); void (*free_cb)(AVRefStructOpaque opaque, void *obj));
/** /**
* A wrapper around ff_refstruct_alloc_ext_c() for the common case * A wrapper around av_refstruct_alloc_ext_c() for the common case
* of a non-const qualified opaque. * of a non-const qualified opaque.
* *
* @see ff_refstruct_alloc_ext_c() * @see av_refstruct_alloc_ext_c()
*/ */
static inline static inline
void *ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void *av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque,
void (*free_cb)(FFRefStructOpaque opaque, void *obj)) void (*free_cb)(AVRefStructOpaque opaque, void *obj))
{ {
return ff_refstruct_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque}, return av_refstruct_alloc_ext_c(size, flags, (AVRefStructOpaque){.nc = opaque},
free_cb); free_cb);
} }
/** /**
* Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL) * Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
*/ */
static inline static inline
void *ff_refstruct_allocz(size_t size) void *av_refstruct_allocz(size_t size)
{ {
return ff_refstruct_alloc_ext(size, 0, NULL, NULL); return av_refstruct_alloc_ext(size, 0, NULL, NULL);
} }
/** /**
@ -116,7 +116,7 @@ void *ff_refstruct_allocz(size_t size)
* @param objp Pointer to a pointer that is either NULL or points to an object * @param objp Pointer to a pointer that is either NULL or points to an object
* managed via this API. `*objp` is set to NULL on return. * managed via this API. `*objp` is set to NULL on return.
*/ */
void ff_refstruct_unref(void *objp); void av_refstruct_unref(void *objp);
/** /**
* Create a new reference to an object managed via this API, * Create a new reference to an object managed via this API,
@ -124,13 +124,13 @@ void ff_refstruct_unref(void *objp);
* and return obj. * and return obj.
* @return a pointer equal to obj. * @return a pointer equal to obj.
*/ */
void *ff_refstruct_ref(void *obj); void *av_refstruct_ref(void *obj);
/** /**
* Analog of ff_refstruct_ref(), but for constant objects. * Analog of av_refstruct_ref(), but for constant objects.
* @see ff_refstruct_ref() * @see av_refstruct_ref()
*/ */
const void *ff_refstruct_ref_c(const void *obj); const void *av_refstruct_ref_c(const void *obj);
/** /**
* Ensure `*dstp` refers to the same object as src. * Ensure `*dstp` refers to the same object as src.
@ -144,7 +144,7 @@ const void *ff_refstruct_ref_c(const void *obj);
* managed via this API. * managed via this API.
* @param src A pointer to an object managed via this API or NULL. * @param src A pointer to an object managed via this API or NULL.
*/ */
void ff_refstruct_replace(void *dstp, const void *src); void av_refstruct_replace(void *dstp, const void *src);
/** /**
* Check whether the reference count of an object managed * Check whether the reference count of an object managed
@ -153,10 +153,10 @@ void ff_refstruct_replace(void *dstp, const void *src);
* @param obj A pointer to an object managed via this API. * @param obj A pointer to an object managed via this API.
* @return 1 if the reference count of obj is 1; 0 otherwise. * @return 1 if the reference count of obj is 1; 0 otherwise.
*/ */
int ff_refstruct_exclusive(const void *obj); int av_refstruct_exclusive(const void *obj);
/** /**
* FFRefStructPool is an API for a thread-safe pool of objects managed * AVRefStructPool is an API for a thread-safe pool of objects managed
* via the RefStruct API. * via the RefStruct API.
* *
* Frequently allocating and freeing large or complicated objects may be slow * Frequently allocating and freeing large or complicated objects may be slow
@ -164,16 +164,16 @@ int ff_refstruct_exclusive(const void *obj);
* needs a set of interchangable objects. * needs a set of interchangable objects.
* *
* At the beginning, the user must call allocate the pool via * At the beginning, the user must call allocate the pool via
* ff_refstruct_pool_alloc() or its analogue ff_refstruct_pool_alloc_ext(). * av_refstruct_pool_alloc() or its analogue av_refstruct_pool_alloc_ext().
* Then whenever an object is needed, call ff_refstruct_pool_get() to * Then whenever an object is needed, call av_refstruct_pool_get() to
* get a new or reused object from the pool. This new object works in all * get a new or reused object from the pool. This new object works in all
* aspects the same way as the ones created by ff_refstruct_alloc_ext(). * aspects the same way as the ones created by av_refstruct_alloc_ext().
* However, when the last reference to this object is unreferenced, it is * However, when the last reference to this object is unreferenced, it is
* (optionally) reset and returned to the pool instead of being freed and * (optionally) reset and returned to the pool instead of being freed and
* will be reused for subsequent ff_refstruct_pool_get() calls. * will be reused for subsequent av_refstruct_pool_get() calls.
* *
* When the caller is done with the pool and no longer needs to create any new * When the caller is done with the pool and no longer needs to create any new
* objects, ff_refstruct_pool_uninit() must be called to mark the pool as * objects, av_refstruct_pool_uninit() must be called to mark the pool as
* freeable. Then entries returned to the pool will then be freed. * freeable. Then entries returned to the pool will then be freed.
* Once all the entries are freed, the pool will automatically be freed. * Once all the entries are freed, the pool will automatically be freed.
* *
@ -184,56 +184,56 @@ int ff_refstruct_exclusive(const void *obj);
/** /**
* The buffer pool. This structure is opaque and not meant to be accessed * The buffer pool. This structure is opaque and not meant to be accessed
* directly. It is allocated with the allocators below and freed with * directly. It is allocated with the allocators below and freed with
* ff_refstruct_pool_uninit(). * av_refstruct_pool_uninit().
*/ */
typedef struct FFRefStructPool FFRefStructPool; typedef struct AVRefStructPool AVRefStructPool;
/** /**
* If this flag is not set, every object in the pool will be zeroed before * If this flag is not set, every object in the pool will be zeroed before
* the init callback is called or before it is turned over to the user * the init callback is called or before it is turned over to the user
* for the first time if no init callback has been provided. * for the first time if no init callback has been provided.
*/ */
#define FF_REFSTRUCT_POOL_FLAG_NO_ZEROING FF_REFSTRUCT_FLAG_NO_ZEROING #define AV_REFSTRUCT_POOL_FLAG_NO_ZEROING AV_REFSTRUCT_FLAG_NO_ZEROING
/** /**
* If this flag is set and both init_cb and reset_cb callbacks are provided, * If this flag is set and both init_cb and reset_cb callbacks are provided,
* then reset_cb will be called if init_cb fails. * then reset_cb will be called if init_cb fails.
* The object passed to reset_cb will be in the state left by init_cb. * The object passed to reset_cb will be in the state left by init_cb.
*/ */
#define FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR (1 << 16) #define AV_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR (1 << 16)
/** /**
* If this flag is set and both init_cb and free_entry_cb callbacks are * If this flag is set and both init_cb and free_entry_cb callbacks are
* provided, then free_cb will be called if init_cb fails. * provided, then free_cb will be called if init_cb fails.
* *
* It will be called after reset_cb in case reset_cb and the * It will be called after reset_cb in case reset_cb and the
* FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR flag are also set. * av_refstruct_POOL_FLAG_RESET_ON_INIT_ERROR flag are also set.
* *
* The object passed to free_cb will be in the state left by * The object passed to free_cb will be in the state left by
* the callbacks applied earlier (init_cb potentially followed by reset_cb). * the callbacks applied earlier (init_cb potentially followed by reset_cb).
*/ */
#define FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR (1 << 17) #define AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR (1 << 17)
/** /**
* If this flag is set, the entries will be zeroed before * If this flag is set, the entries will be zeroed before
* being returned to the user (after the init or reset callbacks * being returned to the user (after the init or reset callbacks
* have been called (if provided)). Furthermore, to avoid zeroing twice * have been called (if provided)). Furthermore, to avoid zeroing twice
* it also makes the pool behave as if the FF_REFSTRUCT_POOL_FLAG_NO_ZEROING * it also makes the pool behave as if the av_refstruct_POOL_FLAG_NO_ZEROING
* flag had been provided. * flag had been provided.
*/ */
#define FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME (1 << 18) #define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME (1 << 18)
/** /**
* Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL) * Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
*/ */
FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags); AVRefStructPool *av_refstruct_pool_alloc(size_t size, unsigned flags);
/** /**
* Allocate an FFRefStructPool, potentially using complex callbacks. * Allocate an AVRefStructPool, potentially using complex callbacks.
* *
* @param size size of the entries of the pool * @param size size of the entries of the pool
* @param flags a bitwise combination of FF_REFSTRUCT_POOL_FLAG_* flags * @param flags a bitwise combination of av_refstruct_POOL_FLAG_* flags
* @param opaque A pointer that will be passed to the callbacks below. * @param opaque A pointer that will be passed to the callbacks below.
* @param init A callback that will be called directly after a new entry * @param init A callback that will be called directly after a new entry
* has been allocated. obj has already been zeroed unless * has been allocated. obj has already been zeroed unless
* the FF_REFSTRUCT_POOL_FLAG_NO_ZEROING flag is in use. * the av_refstruct_POOL_FLAG_NO_ZEROING flag is in use.
* @param reset A callback that will be called after an entry has been * @param reset A callback that will be called after an entry has been
* returned to the pool and before it is reused. * returned to the pool and before it is reused.
* @param free_entry A callback that will be called when an entry is freed * @param free_entry A callback that will be called when an entry is freed
@ -241,28 +241,28 @@ FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags);
* @param free A callback that will be called when the pool itself is * @param free A callback that will be called when the pool itself is
* freed (after the last entry has been returned and freed). * freed (after the last entry has been returned and freed).
*/ */
FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, AVRefStructPool *av_refstruct_pool_alloc_ext_c(size_t size, unsigned flags,
FFRefStructOpaque opaque, AVRefStructOpaque opaque,
int (*init_cb)(FFRefStructOpaque opaque, void *obj), int (*init_cb)(AVRefStructOpaque opaque, void *obj),
void (*reset_cb)(FFRefStructOpaque opaque, void *obj), void (*reset_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_entry_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_cb)(FFRefStructOpaque opaque)); void (*free_cb)(AVRefStructOpaque opaque));
/** /**
* A wrapper around ff_refstruct_pool_alloc_ext_c() for the common case * A wrapper around av_refstruct_pool_alloc_ext_c() for the common case
* of a non-const qualified opaque. * of a non-const qualified opaque.
* *
* @see ff_refstruct_pool_alloc_ext_c() * @see av_refstruct_pool_alloc_ext_c()
*/ */
static inline static inline
FFRefStructPool *ff_refstruct_pool_alloc_ext(size_t size, unsigned flags, AVRefStructPool *av_refstruct_pool_alloc_ext(size_t size, unsigned flags,
void *opaque, void *opaque,
int (*init_cb)(FFRefStructOpaque opaque, void *obj), int (*init_cb)(AVRefStructOpaque opaque, void *obj),
void (*reset_cb)(FFRefStructOpaque opaque, void *obj), void (*reset_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_entry_cb)(AVRefStructOpaque opaque, void *obj),
void (*free_cb)(FFRefStructOpaque opaque)) void (*free_cb)(AVRefStructOpaque opaque))
{ {
return ff_refstruct_pool_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque}, return av_refstruct_pool_alloc_ext_c(size, flags, (AVRefStructOpaque){.nc = opaque},
init_cb, reset_cb, free_entry_cb, free_cb); init_cb, reset_cb, free_entry_cb, free_cb);
} }
@ -270,13 +270,13 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext(size_t size, unsigned flags,
* Get an object from the pool, reusing an old one from the pool when * Get an object from the pool, reusing an old one from the pool when
* available. * available.
* *
* Every call to this function must happen before ff_refstruct_pool_uninit(). * Every call to this function must happen before av_refstruct_pool_uninit().
* Otherwise undefined behaviour may occur. * Otherwise undefined behaviour may occur.
* *
* @param pool the pool from which to get the object * @param pool the pool from which to get the object
* @return a reference to the object on success, NULL on error. * @return a reference to the object on success, NULL on error.
*/ */
void *ff_refstruct_pool_get(FFRefStructPool *pool); void *av_refstruct_pool_get(AVRefStructPool *pool);
/** /**
* Mark the pool as being available for freeing. It will actually be freed * Mark the pool as being available for freeing. It will actually be freed
@ -289,9 +289,9 @@ void *ff_refstruct_pool_get(FFRefStructPool *pool);
* @param poolp pointer to a pointer to either NULL or a pool to be freed. * @param poolp pointer to a pointer to either NULL or a pool to be freed.
* `*poolp` will be set to NULL. * `*poolp` will be set to NULL.
*/ */
static inline void ff_refstruct_pool_uninit(FFRefStructPool **poolp) static inline void av_refstruct_pool_uninit(AVRefStructPool **poolp)
{ {
ff_refstruct_unref(poolp); av_refstruct_unref(poolp);
} }
#endif /* AVCODEC_REFSTRUCT_H */ #endif /* AVUTIL_REFSTRUCT_H */

View file

@ -79,7 +79,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 59 #define LIBAVUTIL_VERSION_MAJOR 59
#define LIBAVUTIL_VERSION_MINOR 50 #define LIBAVUTIL_VERSION_MINOR 51
#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \