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 ESMTP id 5B2CB4A4B0 for ; Thu, 28 Mar 2024 16:54:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6244D68D72D; Thu, 28 Mar 2024 18:53:44 +0200 (EET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E85A68D66C for ; Thu, 28 Mar 2024 18:53:35 +0200 (EET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e0b889901bso11152935ad.1 for ; Thu, 28 Mar 2024 09:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644813; x=1712249613; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=x9qKa1umoZM/KVYEiT2Xn4Op+edIaLIoiVbekHhYHQA=; b=HrOdRXgBdRKh43OMe80snf1xMD9mzi/tp03fG1VQCHE2uuYa0o49cDKl0q32tLYOAY Ybnc8FT38YN3MgEXFwF3C3jM1PsmTpuStRXXwQtvDY5yTupgOd9ReWIc1VCacPlRaLn2 oLL9eaR9A8TFa2ZOSNXMHZcyygg/vyk8l/1afuQ+Xke4BcsuTBJnrXU0NL1A4MdK65MY CPSw4q3t0FHiASqAojCLOvh4DmSP6qKw77E0QcQm2hkSR/tfAIYn3zOAtMJpGlFi9wWz HW+g0iTDftgNQnvMM01v6s1gJPt+hxYntjTGygn4txp80C1x+2cItZ7CiEf55xdG0QKX qtlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644813; x=1712249613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x9qKa1umoZM/KVYEiT2Xn4Op+edIaLIoiVbekHhYHQA=; b=pEhSTiwJ3ZqStvdY3Z0P2YrmnGZhAVl/hht44rNK4h5S4ZjClQ8jENY95iYIMDBux/ BRznXP8vaL1aCDeqf5CmvZ8e2JmoUdqnS4PPaAyM9BSj9KcUqsWYTl3c06QEiJpQtyLc qkdxzl6eemWOwAfE1/yBQ5nRGPkmBXtOc7h1YC9H5JWMvZbwr36nz83rw10w1kLgU1hf 5whTW4Wp59SEjmPvkgiZdGe/Aa+hsac8rMvkVTde3NYsmIIxrFvo+OjjsOpVJq067MeE 5ZzNefUgg5elJ9aX0zHbvM4qC4uDsyCJf991DEioWg/qIH1pF9rqRsPYyIcXVEtkmJ7C WFJw== X-Gm-Message-State: AOJu0YyXi7JpD+ykc3hsQYnRFu3AdRm0nvbfPWGknRlYqWd9DEeVkWWC 7qT0JEYeZhAOETR/IdUGtpKzNcXxgHxKDAavMyWw2C1T4+9fPRjX2jnMoUQQ X-Google-Smtp-Source: AGHT+IEctyIX9x6awbDgBLtsFbB1i7lLsU4anhzHKn6gIGaAc+SutN4CsKb+LDxX8rQFwDsH4MKL9w== X-Received: by 2002:a17:902:654f:b0:1e0:cd88:cb16 with SMTP id d15-20020a170902654f00b001e0cd88cb16mr3047521pln.32.1711644813250; Thu, 28 Mar 2024 09:53:33 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id w4-20020a1709029a8400b001d8f111804asm1822860plp.113.2024.03.28.09.53.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:32 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:49 -0300 Message-ID: <20240328165250.64259-6-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7 v5] avcodec/decode: add AVFrameSideData helper wrappers that don't depend on frames 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: They will be useful to fill arrays stored in other structs. Signed-off-by: James Almer --- libavcodec/decode.c | 106 ++++++++++++++++++++++++++++++++++++-------- libavcodec/decode.h | 24 ++++++++++ 2 files changed, 112 insertions(+), 18 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 34bcb7cc64..1f6c2a8dde 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1799,16 +1799,16 @@ int ff_decode_preinit(AVCodecContext *avctx) * @retval 0 side data of this type can be added to frame * @retval 1 side data of this type should not be added to frame */ -static int side_data_pref(const AVCodecContext *avctx, AVFrame *frame, - enum AVFrameSideDataType type) +static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd, + int *nb_sd, enum AVFrameSideDataType type) { DecodeContext *dc = decode_ctx(avctx->internal); // Note: could be skipped for `type` without corresponding packet sd - if (av_frame_get_side_data(frame, type)) { + if (av_frame_side_data_get(*sd, *nb_sd, type)) { if (dc->side_data_pref_mask & (1ULL << type)) return 1; - av_frame_remove_side_data(frame, type); + av_frame_side_data_remove(sd, nb_sd, type); } return 0; @@ -1821,7 +1821,7 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, { AVFrameSideData *sd; - if (side_data_pref(avctx, frame, type)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) { if (psd) *psd = NULL; return 0; @@ -1834,34 +1834,71 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, return sd ? 0 : AVERROR(ENOMEM); } -int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, - AVFrame *frame, enum AVFrameSideDataType type, - AVBufferRef **buf, AVFrameSideData **psd) +int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **buf) { - AVFrameSideData *sd = NULL; int ret = 0; - if (side_data_pref(avctx, frame, type)) + if (side_data_pref(avctx, sd, nb_sd, type)) goto finish; - sd = av_frame_new_side_data_from_buf(frame, type, *buf); - if (sd) - *buf = NULL; - else + if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0)) ret = AVERROR(ENOMEM); finish: av_buffer_unref(buf); - if (psd) - *psd = sd; return ret; } +int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, + AVFrame *frame, enum AVFrameSideDataType type, + AVBufferRef **buf, AVFrameSideData **psd) +{ + return ff_frame_new_side_data_from_buf_ext(avctx, + &frame->side_data, &frame->nb_side_data, + type, buf); +} + +int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVMasteringDisplayMetadata **mdm) +{ + AVBufferRef *buf; + size_t size; + + if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { + *mdm = NULL; + return 0; + } + + *mdm = av_mastering_display_metadata_alloc_size(&size); + if (!*mdm) + return AVERROR(ENOMEM); + + buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0); + if (!buf) { + av_freep(mdm); + return AVERROR(ENOMEM); + } + + if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, + &buf, 0)) { + *mdm = NULL; + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + return 0; +} + int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm) { - if (side_data_pref(avctx, frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { *mdm = NULL; return 0; } @@ -1870,10 +1907,43 @@ int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, return *mdm ? 0 : AVERROR(ENOMEM); } +int ff_decode_content_light_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + AVContentLightMetadata **clm) +{ + AVBufferRef *buf; + size_t size; + + if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { + *clm = NULL; + return 0; + } + + *clm = av_content_light_metadata_alloc(&size); + if (!*clm) + return AVERROR(ENOMEM); + + buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0); + if (!buf) { + av_freep(clm); + return AVERROR(ENOMEM); + } + + if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + &buf, 0)) { + *clm = NULL; + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + return 0; +} + int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm) { - if (side_data_pref(avctx, frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { *clm = NULL; return 0; } diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 4ffbd9db8e..72a775ff9d 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -175,6 +175,15 @@ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf, AVFrameSideData **sd); +/** + * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **buf); + struct AVMasteringDisplayMetadata; struct AVContentLightMetadata; @@ -187,6 +196,14 @@ struct AVContentLightMetadata; int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, struct AVMasteringDisplayMetadata **mdm); +/** + * Same as `ff_decode_mastering_display_new`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVMasteringDisplayMetadata **mdm); + /** * Wrapper around av_content_light_metadata_create_side_data(), which * rejects side data overridden by the demuxer. Returns 0 on success, and a @@ -196,4 +213,11 @@ int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, struct AVContentLightMetadata **clm); +/** + * Same as `ff_decode_content_light_new`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_decode_content_light_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVContentLightMetadata **clm); #endif /* AVCODEC_DECODE_H */ -- 2.44.0 _______________________________________________ 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".