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 9671F4A265 for ; Mon, 25 Mar 2024 20:06:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A488968D4DB; Mon, 25 Mar 2024 22:06:27 +0200 (EET) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 15EF568D42F for ; Mon, 25 Mar 2024 22:06:21 +0200 (EET) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6ea80de0e97so1972006b3a.2 for ; Mon, 25 Mar 2024 13:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711397178; x=1712001978; 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=M0f4/Beh/W32e5ivz7IeFcECF54UMJBtPCVkk5P7VRQ=; b=Wi30fJCi2RPgy+RGqWeZQ6CTKmKULN/BMPZ/T/M/KXIDCCRgr4bxFjN2GTTADuviXk 52dDcaPEgw2UiyJLSqKazR0rD1kEJNj7N7xrENyEmV61UodemMMGDFg3lE4MuwFHSKIt domUF8tv4dFd1/fxj6dAVcNMGWeIj474ZSzmco/ELl+KI48S3VulmII/qduRC60Zb2q0 5GtOipTcQUee+/moTvJ3NnbyiU8TDW9LsizOoJh5KX/oa9A2ifm/oGeZINHF9mm2FVnY 8piMseZ/q6rDMgu+vgx4/FF2rxznRARL1vGsdfGmasgAFn4nhggk43S8Sh+nULqjrGpQ PfUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711397178; x=1712001978; 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=M0f4/Beh/W32e5ivz7IeFcECF54UMJBtPCVkk5P7VRQ=; b=W+bAaIaLK9zRi3LpaJ3Eb9qnzppXEK6btPtHGs9NBYUd0OTnTLaVNqLr+UCNTBvu5x IV+laxLMjj1TRl2wVk8kNr0FHUiBMuOeuBYt7+bfyARp6+YbA3j7M+y1MHfhr3g9nP0p w/YG1SFx5cPNHdXM+KLXsYAftm+osFnRLqof8MJ3IEGuMxnn0o7OKDLBToMII/oKO8yJ KQYr/rpaP1XVUOftRGDvTUDMIpZlWSjrjbhBDg1lsddZsX4J9a9BCKJqtFXwlBSiRJsy 6/pB7Wu+TrPtC20juzfnKOtac0qO8x7OWnw6sWznpBRSVcn80fn3wrYEuO2geYq2IeSO jPCg== X-Gm-Message-State: AOJu0YyHohJi8bx4WHtlY9WfW90vCRV7+ubnE7ewnQ9TgiGU+9EwOo0u 1IENC/3Afq1apkPQ+CC2Zq1BHqjPo9g05MWgZH7tejoKapPNt2Vka0jSATe5 X-Google-Smtp-Source: AGHT+IFrVFVwk41GbUfxeWAHaq7gH8nOQ8qXfor0UzzBuszw9u43I4CqIktXjYF4k5eN5FoZ8t+KrQ== X-Received: by 2002:a05:6a20:daa1:b0:1a3:a281:7e5f with SMTP id iy33-20020a056a20daa100b001a3a2817e5fmr9802719pzb.1.1711397178322; Mon, 25 Mar 2024 13:06:18 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id kt1-20020a056a004ba100b006ea98271e43sm4431120pfb.144.2024.03.25.13.06.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:06:17 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Mar 2024 17:05:57 -0300 Message-ID: <20240325200602.63020-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6 v2] avutil/frame: add a flag to not create duplicate entries in a side data array 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: Signed-off-by: James Almer --- libavutil/frame.c | 14 ++++++++++++++ libavutil/frame.h | 28 ++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index d7a32cdc92..a780e62fd0 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -774,6 +774,13 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, type); + if (flags & AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND) { + for (int i = 0; i < *nb_sd; i++) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry->type == type) + return entry; + } + } ret = add_side_data_from_buf(sd, nb_sd, type, buf); if (!ret) @@ -798,6 +805,13 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, src->type); + if (flags & AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND) { + for (int i = 0; i < *nb_sd; i++) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry->type == src->type) + return 0; + } + } sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); if (!sd_dst) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 8aa05ec127..7cc55a455e 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1003,7 +1003,14 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type); */ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); +/** + * Remove existing entries before adding new ones. + */ #define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0) +/** + * Don't add a new entry if another of the same type exists. + */ +#define AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND (1 << 1) /** * Add new side data entry to an array. @@ -1016,10 +1023,12 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); * @param size size of the side data * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. * - * @return newly added side data on success, NULL on error. In case of - * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching - * AVFrameSideDataType will be removed before the addition is - * attempted. + * @return newly added side data on success, NULL on error. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of + * matching AVFrameSideDataType will be removed before the addition + * is attempted. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND being set, if an + * entry of the same type already exists, it will be returned instead. */ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, @@ -1037,10 +1046,13 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, * for the buffer. * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. * - * @return negative error code on failure, >=0 on success. In case of - * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching - * AVFrameSideDataType will be removed before the addition is - * attempted. + * @return negative error code on failure, >=0 on success. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of + * matching AVFrameSideDataType will be removed before the addition + * is attempted. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND being set, if an + * entry of the same type as the one from src already exists, this + * function will be a no-op. */ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags); -- 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".