ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | Tue Feb 25 12:59:17 2025 +0100| [b306683d1228b1642a0d88a29071de5bdee999ff] | committer: James Almer
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.rheinha...@outlook.com> Signed-off-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b306683d1228b1642a0d88a29071de5bdee999ff --- libavcodec/decode.c | 28 +++++++++------------------- libavcodec/lcevcdec.c | 2 +- libavcodec/nvdec.c | 8 ++++---- libavcodec/nvdec_av1.c | 2 +- libavcodec/nvdec_h264.c | 4 ++-- libavcodec/nvdec_hevc.c | 4 ++-- libavcodec/nvdec_mjpeg.c | 2 +- libavcodec/nvdec_mpeg12.c | 2 +- libavcodec/nvdec_mpeg4.c | 2 +- libavcodec/nvdec_vc1.c | 2 +- libavcodec/nvdec_vp8.c | 2 +- libavcodec/nvdec_vp9.c | 2 +- libavcodec/videotoolbox.c | 2 +- libavutil/frame.c | 12 ++++-------- libavutil/frame.h | 10 +++------- 15 files changed, 33 insertions(+), 51 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index d726cac8c9..fca0c7ff58 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -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; diff --git a/libavcodec/lcevcdec.c b/libavcodec/lcevcdec.c index 4ca5dfa0a6..2fe06b8800 100644 --- a/libavcodec/lcevcdec.c +++ b/libavcodec/lcevcdec.c @@ -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; diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index 99351661ea..d444135fd7 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -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; diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c index 23183ffd9c..d07fe6324c 100644 --- a/libavcodec/nvdec_av1.c +++ b/libavcodec/nvdec_av1.c @@ -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) { diff --git a/libavcodec/nvdec_h264.c b/libavcodec/nvdec_h264.c index 48ad5873b8..54c98e611d 100644 --- a/libavcodec/nvdec_h264.c +++ b/libavcodec/nvdec_h264.c @@ -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) { diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c index dd3c6c627c..2b9df3e702 100644 --- a/libavcodec/nvdec_hevc.c +++ b/libavcodec/nvdec_hevc.c @@ -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) { diff --git a/libavcodec/nvdec_mjpeg.c b/libavcodec/nvdec_mjpeg.c index 4bdbde8d3a..f0c9416397 100644 --- a/libavcodec/nvdec_mjpeg.c +++ b/libavcodec/nvdec_mjpeg.c @@ -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) { diff --git a/libavcodec/nvdec_mpeg12.c b/libavcodec/nvdec_mpeg12.c index 0a24e42a59..ca0a1001dc 100644 --- a/libavcodec/nvdec_mpeg12.c +++ b/libavcodec/nvdec_mpeg12.c @@ -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) { diff --git a/libavcodec/nvdec_mpeg4.c b/libavcodec/nvdec_mpeg4.c index dae6de41c1..14ce352512 100644 --- a/libavcodec/nvdec_mpeg4.c +++ b/libavcodec/nvdec_mpeg4.c @@ -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) { diff --git a/libavcodec/nvdec_vc1.c b/libavcodec/nvdec_vc1.c index 647fe7bef9..da11342576 100644 --- a/libavcodec/nvdec_vc1.c +++ b/libavcodec/nvdec_vc1.c @@ -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) { diff --git a/libavcodec/nvdec_vp8.c b/libavcodec/nvdec_vp8.c index 2faacdfe8c..e273a6ec35 100644 --- a/libavcodec/nvdec_vp8.c +++ b/libavcodec/nvdec_vp8.c @@ -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) { diff --git a/libavcodec/nvdec_vp9.c b/libavcodec/nvdec_vp9.c index b564687246..f83ff93818 100644 --- a/libavcodec/nvdec_vp9.c +++ b/libavcodec/nvdec_vp9.c @@ -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) { diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index a744657957..ccba249140 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -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; diff --git a/libavutil/frame.c b/libavutil/frame.c index a529de7561..dcfc835626 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -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); diff --git a/libavutil/frame.h b/libavutil/frame.h index 4305fd9f4c..8493233ba2 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -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. _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".