From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A0AEA4BF90 for ; Tue, 4 Feb 2025 21:13:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 25B9968B6B9; Tue, 4 Feb 2025 23:13:18 +0200 (EET) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEBC368A57C for ; Tue, 4 Feb 2025 23:13:11 +0200 (EET) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2161eb95317so108061685ad.1 for ; Tue, 04 Feb 2025 13:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738703589; x=1739308389; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=lIrZ7pG0gALpW8cyC1fSMYd5ldaXy6z3AFiyCGVVlU8=; b=mK3mpYLqDfWqaGEzxp3vL8YCJxChF6tZuqtqFilqwFRS7rRqmHAaHb55SLgx8RR/zz 0ZAfPfdSka885EdnpXp6z0Ot3ECL07U0xxQ2F1xLSfBpXWFIDCUEVAOcZ1CxckU8Y17M u2WEWfsdSF8Pi0IaTR+mg2gV6wBA+ccGtyanJQnUhfhKKyGZVltQUZWdqm6nwToNqHZR UXvmTsix0akAZZtb0JWdw5o+iRZoaUVrDEcfd4vN/ziQV9sTPe+6vbKP6RfgX7pxP2On XOYYYjY6cL+Jv/LJsZm7V/dbNZbeWtbH4aiWO2X/6JrQBRFSrpBLbIc0sJjkyPsfIw6R RS5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738703589; x=1739308389; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lIrZ7pG0gALpW8cyC1fSMYd5ldaXy6z3AFiyCGVVlU8=; b=UvaoR7Q7F2KKJj/safFaCsHOypnwxBEHcMOFq3If1XBhHUI7CKydWZqfRWtnqBkjiB tRvNDQJ+cUSq1+WloIwxedlxNYDg64OSy3yBxrG4SFWhoWH/lKdUr0V5iREFU3QNTUlY 9CC5apJGLKAVdTfzo/9wYY1CrK/Fjdr9Umf3hIiDZsd0F5hMEQdqO0O5dMUj5gKNUhBu 7RQKF9c0RaKJtRQMoFZVNG5j0guudSB89bpOuJ9y2GOd3MSLFwHVtyosDMVSjhRrnZRj nzGDEMVjZceuN72F2albbQCIefecTBjgKYoru0e01zEG7ThKuxAVidxAIflWcWCtGDpH uVAQ== X-Gm-Message-State: AOJu0YzHGr4GTO/NMS8EQGbhq6yU/bIAHAKasi1qTRW5fqBhWHVIDYog ssqN0JqPSBcHY32dnR4kOh05TsTdmuX4seQ6k0jq3dzEHRBRRqr7ckwIuUG6 X-Gm-Gg: ASbGncvG8pLeOpLiwf9epkkBAJOGvd2wjrj8JhqZ8A1I0QuYqtS4e1HN1jlVPciGVjO Tqsikf414488Evx9eD2T8PWM3j4AmMdOHnbWrCwpVPXqvMVbbwUJKVX4vrmRM3D3nOebPd8x4hL H38tUHNIiY0T13Uue6BRRK1F2FIMPPjMH8mEUtO1eGURoDDd6SG+WIcDilx7rbpewIsSr0ItEAL XDdo6ctdEUr8A02NZgC18eAdOyfyFMDZdSmkbGz7eQfc+vOnSFU+EF+cGjila1cfkdEMLBQvDIn YEd30nqBRZmIqUV7EK+PEpvDzWexzDKW X-Google-Smtp-Source: AGHT+IFgF8bF6Z9BxT6F6M0IHdcI2xTc9LsiltSiadacjgMkfNmkNX1UQuzRNs/MIf1uaTh2tYVBnA== X-Received: by 2002:a05:6a20:9d8f:b0:1e1:bd5b:b82a with SMTP id adf61e73a8af0-1ede88d589cmr464828637.40.1738703589263; Tue, 04 Feb 2025 13:13:09 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:8cb0:4f4f:5762:f631]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72fe631be48sm11024597b3a.3.2025.02.04.13.13.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 13:13:08 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Feb 2025 18:12:55 -0300 Message-ID: <20250204211256.10228-1-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/decode: make ff_frame_new_side_data_from_buf behave like the function it's a wrapper for X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: It's less confusing to have ff_frame_new_side_data_from_buf() be a drop in replacement for av_frame_side_data_add(), and the addition of the missing flags field will make it more versatile, as will be seen in the following commit. Signed-off-by: James Almer --- libavcodec/av1dec.c | 6 ++++-- libavcodec/decode.c | 13 +++++-------- libavcodec/decode.h | 11 +++++++---- libavcodec/h2645_sei.c | 12 ++++++++---- libavcodec/hevc/hevcdec.c | 7 +++++-- libavcodec/hevc/refs.c | 6 ++++-- libavcodec/libdav1d.c | 6 ++++-- libavcodec/libjxldec.c | 6 ++++-- libavcodec/mpeg12dec.c | 6 ++++-- 9 files changed, 45 insertions(+), 28 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 7c54e36220..11b6100f9f 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -983,9 +983,11 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, if (!ret) break; - ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, &buf); - if (ret < 0) + ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, &buf, 0); + if (ret < 0) { + av_buffer_unref(&buf); return ret; + } #if FF_API_CODEC_PROPS FF_DISABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/decode.c b/libavcodec/decode.c index cac7e620d2..794e84c1a2 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2118,29 +2118,26 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, - AVBufferRef **buf) + AVBufferRef **buf, int flags) { int ret = 0; if (side_data_pref(avctx, sd, nb_sd, type)) - goto finish; + return 0; - if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0)) + if (!av_frame_side_data_add(sd, nb_sd, type, buf, flags)) ret = AVERROR(ENOMEM); -finish: - av_buffer_unref(buf); - return ret; } int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, - AVBufferRef **buf) + AVBufferRef **buf, int flags) { return ff_frame_new_side_data_from_buf_ext(avctx, &frame->side_data, &frame->nb_side_data, - type, buf); + type, buf, flags); } int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 2c3719a8d0..dc2802d782 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -168,12 +168,15 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, /** * Similar to `ff_frame_new_side_data`, but using an existing buffer ref. * - * *buf is ALWAYS consumed by this function and NULL written in its place, even - * on failure. + * @param buf Pointer to AVBufferRef to add to the array. On success, + * the function takes ownership of the AVBufferRef and *buf is + * set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set + * in which case the ownership will remain with the caller. + * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. */ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, - AVBufferRef **buf); + AVBufferRef **buf, int flags); /** * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData @@ -182,7 +185,7 @@ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, - AVBufferRef **buf); + AVBufferRef **buf, int flags); struct AVMasteringDisplayMetadata; struct AVContentLightMetadata; diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index 2494daaf3c..d48a9b5f2c 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -610,10 +610,12 @@ static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, } ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd, - AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf); + AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf, 0); - if (ret < 0) + if (ret < 0) { + av_buffer_unref(&buf); return ret; + } dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000); dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000); @@ -830,9 +832,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (sei->lcevc.info) { HEVCSEILCEVC *lcevc = &sei->lcevc; - ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_LCEVC, &lcevc->info); - if (ret < 0) + ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_LCEVC, &lcevc->info, 0); + if (ret < 0) { + av_buffer_unref(&lcevc->info); return ret; + } } if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) { diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index e9c045f7a1..cf4062c75c 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3085,9 +3085,12 @@ static int set_side_data(HEVCContext *s) if (!info_ref) return AVERROR(ENOMEM); - ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, &info_ref); - if (ret < 0) + ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, + &info_ref, 0); + if (ret < 0) { + av_buffer_unref(&info_ref); return ret; + } } if (s->rpu_buf) { diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index dd7f7f95a8..04cecd9770 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -97,9 +97,11 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l) if (s->sei.common.lcevc.info) { HEVCSEILCEVC *lcevc = &s->sei.common.lcevc; ret = ff_frame_new_side_data_from_buf(s->avctx, frame->tf.f, - AV_FRAME_DATA_LCEVC, &lcevc->info); - if (ret < 0) + AV_FRAME_DATA_LCEVC, &lcevc->info, 0); + if (ret < 0) { + av_buffer_unref(&lcevc->info); goto fail; + } } // add view ID side data if it's nontrivial diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index f4cbc927b5..d2c7342e55 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -533,9 +533,11 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) if (!res) break; - res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf); - if (res < 0) + res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf, 0); + if (res < 0) { + av_buffer_unref(&buf); goto fail; + } #if FF_API_CODEC_PROPS FF_DISABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c index 96c338d1b4..a9261f5016 100644 --- a/libavcodec/libjxldec.c +++ b/libavcodec/libjxldec.c @@ -483,9 +483,11 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) /* full image is one frame, even if animated */ av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n"); if (ctx->iccp) { - ret = ff_frame_new_side_data_from_buf(avctx, ctx->frame, AV_FRAME_DATA_ICC_PROFILE, &ctx->iccp); - if (ret < 0) + ret = ff_frame_new_side_data_from_buf(avctx, ctx->frame, AV_FRAME_DATA_ICC_PROFILE, &ctx->iccp, 0); + if (ret < 0) { + av_buffer_unref(&ctx->iccp); return ret; + } } if (ctx->basic_info.have_animation) { ctx->frame->pts = av_rescale_q(ctx->accumulated_pts, ctx->anim_timebase, avctx->pkt_timebase); diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 0002f016e9..b181852b6e 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1308,9 +1308,11 @@ static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size) if (s1->a53_buf_ref) { ret = ff_frame_new_side_data_from_buf( s->avctx, s->cur_pic.ptr->f, AV_FRAME_DATA_A53_CC, - &s1->a53_buf_ref); - if (ret < 0) + &s1->a53_buf_ref, 0); + if (ret < 0) { + av_buffer_unref(&s1->a53_buf_ref); return ret; + } } if (s1->has_stereo3d) { -- 2.48.1 _______________________________________________ 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".