1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avutil/frame: Port AVFrame.private_ref to RefStruct API

This is possible without deprecation period, because said field
is documented as only for our libav* libraries and not the general
public.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Andreas Rheinhardt
2025-02-25 12:59:17 +01:00
committed by James Almer
parent d6b215052b
commit b306683d12
15 changed files with 33 additions and 51 deletions

View File

@ -676,11 +676,11 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
/* the only case where decode data is not set should be decoders
* that do not call ff_get_buffer() */
av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
av_assert0(frame->private_ref ||
!(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
if (frame->private_ref) {
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
if (fdd->post_process) {
ret = fdd->post_process(avctx, frame);
@ -693,7 +693,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
}
/* free the per-frame decode data */
av_buffer_unref(&frame->private_ref);
av_refstruct_unref(&frame->private_ref);
return ret;
}
@ -1544,39 +1544,29 @@ static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
}
}
static void decode_data_free(void *opaque, uint8_t *data)
static void decode_data_free(AVRefStructOpaque unused, void *obj)
{
FrameDecodeData *fdd = (FrameDecodeData*)data;
FrameDecodeData *fdd = obj;
if (fdd->post_process_opaque_free)
fdd->post_process_opaque_free(fdd->post_process_opaque);
if (fdd->hwaccel_priv_free)
fdd->hwaccel_priv_free(fdd->hwaccel_priv);
av_freep(&fdd);
}
int ff_attach_decode_data(AVFrame *frame)
{
AVBufferRef *fdd_buf;
FrameDecodeData *fdd;
av_assert1(!frame->private_ref);
av_buffer_unref(&frame->private_ref);
av_refstruct_unref(&frame->private_ref);
fdd = av_mallocz(sizeof(*fdd));
fdd = av_refstruct_alloc_ext(sizeof(*fdd), 0, NULL, decode_data_free);
if (!fdd)
return AVERROR(ENOMEM);
fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free,
NULL, AV_BUFFER_FLAG_READONLY);
if (!fdd_buf) {
av_freep(&fdd);
return AVERROR(ENOMEM);
}
frame->private_ref = fdd_buf;
frame->private_ref = fdd;
return 0;
}
@ -1603,7 +1593,7 @@ static void attach_post_process_data(AVCodecContext *avctx, AVFrame *frame)
DecodeContext *dc = decode_ctx(avci);
if (dc->lcevc_frame) {
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
fdd->post_process_opaque = av_refstruct_ref(dc->lcevc);
fdd->post_process_opaque_free = ff_lcevc_unref;

View File

@ -278,7 +278,7 @@ static int lcevc_init(FFLCEVCContext *lcevc, void *logctx)
int ff_lcevc_process(void *logctx, AVFrame *frame)
{
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
FFLCEVCContext *lcevc = fdd->post_process_opaque;
int ret;

View File

@ -494,7 +494,7 @@ finish:
static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
{
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
NVDECFrame *cf = (NVDECFrame*)fdd->hwaccel_priv;
NVDECDecoder *decoder = cf->decoder;
@ -575,7 +575,7 @@ finish:
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
{
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
NVDECFrame *cf = NULL;
int ret;
@ -613,7 +613,7 @@ fail:
int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_sep_ref)
{
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
FrameDecodeData *fdd = frame->private_ref;
NVDECFrame *cf;
int ret;
@ -780,7 +780,7 @@ int ff_nvdec_get_ref_idx(AVFrame *frame)
if (!frame || !frame->private_ref)
return -1;
fdd = (FrameDecodeData*)frame->private_ref->data;
fdd = frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
if (!cf)
return -1;

View File

@ -64,7 +64,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -34,7 +34,7 @@
static void dpb_add(const H264Context *h, CUVIDH264DPBENTRY *dst, const H264Picture *src,
int frame_idx)
{
FrameDecodeData *fdd = (FrameDecodeData*)src->f->private_ref->data;
FrameDecodeData *fdd = src->f->private_ref;
const NVDECFrame *cf = fdd->hwaccel_priv;
dst->PicIdx = cf ? cf->idx : -1;
@ -66,7 +66,7 @@ static int nvdec_h264_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)h->cur_pic_ptr->f->private_ref->data;
fdd = h->cur_pic_ptr->f->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -34,7 +34,7 @@
static void dpb_add(CUVIDHEVCPICPARAMS *pp, int idx, const HEVCFrame *src)
{
FrameDecodeData *fdd = (FrameDecodeData*)src->f->private_ref->data;
FrameDecodeData *fdd = src->f->private_ref;
const NVDECFrame *cf = fdd->hwaccel_priv;
pp->RefPicIdx[idx] = cf ? cf->idx : -1;
@ -90,7 +90,7 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)s->cur_frame->f->private_ref->data;
fdd = s->cur_frame->f->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -45,7 +45,7 @@ static int nvdec_mjpeg_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -49,7 +49,7 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -48,7 +48,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -48,7 +48,7 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -50,7 +50,7 @@ static int nvdec_vp8_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -49,7 +49,7 @@ static int nvdec_vp9_start_frame(AVCodecContext *avctx,
if (ret < 0)
return ret;
fdd = (FrameDecodeData*)cur_frame->private_ref->data;
fdd = cur_frame->private_ref;
cf = (NVDECFrame*)fdd->hwaccel_priv;
*pp = (CUVIDPICPARAMS) {

View File

@ -167,7 +167,7 @@ int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
}
frame->buf[0] = buf;
fdd = (FrameDecodeData*)frame->private_ref->data;
fdd = frame->private_ref;
fdd->post_process = videotoolbox_postproc_frame;
frame->width = avctx->width;

View File

@ -19,12 +19,11 @@
#include "channel_layout.h"
#include "avassert.h"
#include "buffer.h"
#include "common.h"
#include "cpu.h"
#include "dict.h"
#include "frame.h"
#include "imgutils.h"
#include "mem.h"
#include "refstruct.h"
#include "samplefmt.h"
#include "side_data.h"
#include "hwcontext.h"
@ -219,8 +218,6 @@ int av_frame_get_buffer(AVFrame *frame, int align)
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
{
int ret;
dst->pict_type = src->pict_type;
dst->sample_aspect_ratio = src->sample_aspect_ratio;
dst->crop_top = src->crop_top;
@ -272,9 +269,8 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
}
ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
return ret;
av_refstruct_replace(&dst->private_ref, src->private_ref);
return av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
}
int av_frame_ref(AVFrame *dst, const AVFrame *src)
@ -516,7 +512,7 @@ void av_frame_unref(AVFrame *frame)
av_buffer_unref(&frame->hw_frames_ctx);
av_buffer_unref(&frame->opaque_ref);
av_buffer_unref(&frame->private_ref);
av_refstruct_unref(&frame->private_ref);
if (frame->extended_data != frame->data)
av_freep(&frame->extended_data);

View File

@ -739,17 +739,13 @@ typedef struct AVFrame {
*/
/**
* AVBufferRef for internal use by a single libav* library.
* RefStruct reference for internal use by a single libav* library.
* Must not be used to transfer data between libraries.
* Has to be NULL when ownership of the frame leaves the respective library.
*
* Code outside the FFmpeg libs should never check or change the contents of the buffer ref.
*
* FFmpeg calls av_buffer_unref() on it when the frame is unreferenced.
* av_frame_copy_props() calls create a new reference with av_buffer_ref()
* for the target frame's private_ref field.
* Code outside the FFmpeg libs must never check or change private_ref.
*/
AVBufferRef *private_ref;
void *private_ref;
/**
* Channel layout of the audio data.