From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avutil/frame: Port AVFrame.private_ref to RefStruct API Date: Tue, 25 Feb 2025 13:29:15 +0100 Message-ID: <AS8P250MB07449733FB84821D07B6D4388FC32@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <20250223220630.18756-1-jamrial@gmail.com> [-- Attachment #1: Type: text/plain, Size: 563 bytes --] James Almer: > It's been a year since the last bump, so lets get rid of old deprecated API > in time for ffmpeg 8.0 > I want to add the attached patch to that set. There will probably be a minor conflict with the FF_API_FRAME_KEY patch (your github account didn't have a branch of this, so I based it on master, not on your patchset), but that is trivial to fix. One more thing: Did you check whether you can now remove inclusions of version*.h and attributes.h (for attribute_deprecated) headers? I don't see you do this and it is often forgotten. - Andreas [-- Attachment #2: 0001-avutil-frame-Port-AVFrame.private_ref-to-RefStruct-A.patch --] [-- Type: text/x-patch, Size: 13520 bytes --] From 3a89a0be20d21688f4134cd80eae3bd71cfcd996 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Tue, 25 Feb 2025 12:59:17 +0100 Subject: [PATCH] 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> --- 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 cac7e620d2..c822bd55f5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -703,11 +703,11 @@ FF_ENABLE_DEPRECATION_WARNINGS /* 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); @@ -720,7 +720,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } /* free the per-frame decode data */ - av_buffer_unref(&frame->private_ref); + av_refstruct_unref(&frame->private_ref); return ret; } @@ -1623,39 +1623,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; } @@ -1682,7 +1672,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 6b408edb87..74fcdb6b11 100644 --- a/libavcodec/nvdec_av1.c +++ b/libavcodec/nvdec_av1.c @@ -62,7 +62,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u 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 1ae3dfd032..51813e1abe 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; @@ -65,7 +65,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 e01ce4c782..f071480b26 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; @@ -89,7 +89,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 850634bf1a..b48eb73cfa 100644 --- a/libavcodec/nvdec_mjpeg.c +++ b/libavcodec/nvdec_mjpeg.c @@ -43,7 +43,7 @@ static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, 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 99b2b14f1f..2e9c413b1d 100644 --- a/libavcodec/nvdec_mpeg12.c +++ b/libavcodec/nvdec_mpeg12.c @@ -47,7 +47,7 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer 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 80da11b5b1..21ee123996 100644 --- a/libavcodec/nvdec_mpeg4.c +++ b/libavcodec/nvdec_mpeg4.c @@ -46,7 +46,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, 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 0668863cb4..671c1ed5eb 100644 --- a/libavcodec/nvdec_vc1.c +++ b/libavcodec/nvdec_vc1.c @@ -46,7 +46,7 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u 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 ff3b3f259c..b052a8ad87 100644 --- a/libavcodec/nvdec_vp8.c +++ b/libavcodec/nvdec_vp8.c @@ -48,7 +48,7 @@ static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u 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 e196391c6d..21455a8fa2 100644 --- a/libavcodec/nvdec_vp9.c +++ b/libavcodec/nvdec_vp9.c @@ -47,7 +47,7 @@ static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u 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 a606c29ded..ec1783f7d5 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 492b467ebd..271dd37af2 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 "hwcontext.h" @@ -318,8 +317,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; - #if FF_API_FRAME_KEY FF_DISABLE_DEPRECATION_WARNINGS dst->key_frame = src->key_frame; @@ -393,9 +390,8 @@ FF_ENABLE_DEPRECATION_WARNINGS 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) @@ -637,7 +633,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 49260ae2dd..33a808ac9c 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -801,17 +801,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. -- 2.45.2 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-02-25 12:29 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-23 22:06 [FFmpeg-devel] [PATCH 00/31] Major library soname bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 01/30] avcodec: remove deprecated FF_API_SUBFRAMES James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 02/30] avcodec: remove deprecated FF_API_TICKS_PER_FRAME James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 03/30] avcodec: remove deprecated FF_API_DROPCHANGED James Almer 2025-02-24 9:44 ` Gyan Doshi 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 04/30] avcodec: remove deprecated FF_API_AVFFT James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 05/30] avcodec: remove deprecated FF_API_FF_PROFILE_LEVEL James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 06/30] avcodec: remove deprecated FF_API_AVCODEC_CLOSE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 07/30] avcodec: remove deprecated FF_API_BUFFER_MIN_SIZE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 08/30] avcodec: remove deprecated FF_API_VDPAU_ALLOC_GET_SET James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 09/30] avcodec: remove deprecated FF_API_QUALITY_FACTOR James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 10/30] avcodec/version_major: postpone some deprecations until the next bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 11/30] avdevice: remove deprecated FF_API_BKTR_DEVICE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 12/30] avdevice: remove deprecated FF_API_OPENGL_DEVICE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 13/30] avdevice: remove deprecated FF_API_SDL2_DEVICE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 14/30] avdevice/version_major: postpone some deprecations until the next bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 15/30] avformat: remove deprecated FF_API_LAVF_SHORTEST James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 16/30] avformat: remove deprecated FF_API_ALLOW_FLUSH James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 17/30] avformat: remove deprecated FF_API_AVSTREAM_SIDE_DATA James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 18/30] avformat: remove deprecated FF_API_GET_DUR_ESTIMATE_METHOD James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 19/30] avformat/version_major: postpone some deprecations until the next bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 20/30] avfilter: remove deprecated FF_API_LINK_PUBLIC James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 21/30] avfilter/version_major: postpone some deprecations until the next bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 22/30] avutil: remove deprecated FF_API_HDR_VIVID_THREE_SPLINE James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 23/30] avutil: remove deprecated FF_API_FRAME_PKT James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 24/30] avutil: remove deprecated FF_API_INTERLACED_FRAME James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 25/30] avutil: remove deprecated FF_API_FRAME_KEY James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 26/30] avutil: remove deprecated FF_API_PALETTE_HAS_CHANGED James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 27/30] avutil: remove deprecated FF_API_VULKAN_CONTIGUOUS_MEMORY James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 28/30] avutil: remove deprecated FF_API_H274_FILM_GRAIN_VCS James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 29/30] avutil/version_major: postpone some deprecations until the next bump James Almer 2025-02-23 22:06 ` [FFmpeg-devel] [PATCH 30/30] libs: bump major version for all libraries James Almer 2025-02-25 12:29 ` Andreas Rheinhardt [this message] 2025-02-25 14:31 ` [FFmpeg-devel] [PATCH] avutil/frame: Port AVFrame.private_ref to RefStruct API James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS8P250MB07449733FB84821D07B6D4388FC32@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git