From patchwork Thu Mar 28 16:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47595 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468355pzb; Thu, 28 Mar 2024 09:54:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXLcFOyJJ6T+i3TgclFFEVjjw6E0tEwtcKTnVgjSOXzLNUN3nRaLLshAIK6jjN5HQrPWAfU3EPBOByUEaeDJ5nQC1QfMGSeeg31Cw== X-Google-Smtp-Source: AGHT+IHy0HoOsH4UPn3zGCxPiyAkUWkwY4YL1v479MZKvNpDniFVgL9SDAcMUzq519sU//WZeM4x X-Received: by 2002:a17:906:2813:b0:a46:a3d1:679a with SMTP id r19-20020a170906281300b00a46a3d1679amr12827ejc.14.1711644863646; Thu, 28 Mar 2024 09:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644863; cv=none; d=google.com; s=arc-20160816; b=cELLeYQuRmZ7TAcCFRbpQxWJIWQ3m4/F4Hb3M7V/9M1uo2OK4j3Ph+2Dqv31hdhmnm YIIBgHaq2apsbTHlp3KbWM2viZE/LOfw1Lc6cPyLvhJ7eS4PEAoam2RhUO6INwATho4K zIv1qU60FxMwkuARt4MooJHmt7ADRw54jCN7S2IaOp4VhcnK1CEABBcKQieqa1F8ppXT s9lkJwpV86XbagfwFTXN5E/DcLzisUzpX29ujr7uHND7ucl87B3DynmK0pMVPpP/XQXP Zlu5PhJWzuMXFgRh9f3kSGHBZ81ojfm/EVW3CPbSMSfHrdYGtQBM8o1sVsDp/QITymAK 1S+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=xU70jvCGAdv+XPTghGTbVnRBsadhR/Hktf1NeGgnYcM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=b0MeYE9MR5uHKDAuNC1KANvyDyCDSndEbtfW86Bxbi+2y3dgRT1STTVOQ7U0tQegdE CBEqrJD2rTBcOTjoRSQb7Erjk+EzicANhKpsPBah0Iv1vvqX0zRD70abLrgQkvdyxzx1 QnJia4glpYLKMsJJpve68KCpdmnycU1T5YMfLjyCCqThl2GFR8nsRB5tqvWdw+6ME+ru UulYnOUiPoz8DTf5rkw1oQJNG+XbEbs7syBSo//T3GkXE+TEcVIC0HQ8yuYwbGNz+ap9 F4MyOMnj3e9ZOaYxFdBuRsebSUPk1DtKY2YePf+koDPjomsWncf8TE+DEtrTxe5Bn/jV FnRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=HrOdRXgB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x26-20020a1709060a5a00b00a4666ecd61bsi896655ejf.217.2024.03.28.09.54.23; Thu, 28 Mar 2024 09:54:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=HrOdRXgB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A15E568D732; Thu, 28 Mar 2024 18:53:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: azC9t+c52yU/ 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 */