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 660DF4A477 for ; Thu, 28 Mar 2024 11:23:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F2D368D681; Thu, 28 Mar 2024 13:23:48 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4108668D5CD for ; Thu, 28 Mar 2024 13:23:41 +0200 (EET) Authentication-Results: mail0.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=ml8SBFGL; dkim-atps=neutral Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EE7B3240DAC for ; Thu, 28 Mar 2024 12:23:40 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id v5ha5hB0_l7U for ; Thu, 28 Mar 2024 12:23:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1711625018; bh=fSXVcAtO+mOYarQMX/Pu6WAIV9GCR5gVg0JEPsoft6g=; h=Subject:From:To:In-Reply-To:References:Date:From; b=ml8SBFGL69dilPE7hnzttYAmRa05EeqiK/dwa6l3NYxi0CP95GSgxLmorC064y7yV VDudKlU+udaxzHVrz5jgzJsG8516YtXvBbcazJfZy98SxCaMO+s7sl7N0p/vsjAgci /ggPHcisI8GtIkcq/dgDTUeSoXmf7oS+2FQrJv+CW1Axme+TG93yWdL7UNr8OLm9Fp 3q5ldO+CfjrReEYaD8WrYY1v7xMv/ukx19YC13nC00reIbq70PolPsGKDcnLARJVY8 1Hqq2j6QwE3Ghr7yezhqKRoE9vUlnSbABTik0DsEuGapAD4DwpcMXGkGt+vgWRC0mB l1dnaqQznGM+A== Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id AFF242404AF for ; Thu, 28 Mar 2024 12:23:38 +0100 (CET) Received: by lain.khirnov.net (Postfix, from userid 1000) id 9B2FE1601B9; Thu, 28 Mar 2024 12:23:38 +0100 (CET) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20240328031210.21407-1-jamrial@gmail.com> References: <20240328031210.21407-1-jamrial@gmail.com> Mail-Followup-To: FFmpeg development discussions and patches Date: Thu, 28 Mar 2024 12:23:38 +0100 Message-ID: <171162501860.7287.7383716984700357542@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 1/7 v4] avutil/frame: add a flag to allow overwritting existing entries 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: Quoting James Almer (2024-03-28 04:12:04) > Enable it only for side data types that don't allow more than one entry. > > Signed-off-by: James Almer > --- > libavutil/frame.c | 59 ++++++++++++++++++++++++++++--- > libavutil/frame.h | 27 +++++++++----- > libavutil/tests/side_data_array.c | 52 +++++++++++++++------------ > tests/ref/fate/side_data_array | 22 ++++++------ > 4 files changed, 115 insertions(+), 45 deletions(-) > > diff --git a/libavutil/frame.c b/libavutil/frame.c > index ef1613c344..d9bd19b2aa 100644 > --- a/libavutil/frame.c > +++ b/libavutil/frame.c > @@ -799,12 +799,34 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, > enum AVFrameSideDataType type, > size_t size, unsigned int flags) > { > - AVBufferRef *buf = av_buffer_alloc(size); > + const AVSideDataDescriptor *desc = av_frame_side_data_desc(type); > + AVBufferRef *buf; > AVFrameSideData *ret = NULL; > > if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) > remove_side_data(sd, nb_sd, type); > + if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) { desc == NULL means type is invalid > + for (int i = 0; i < *nb_sd; i++) { > + AVFrameSideData *entry = ((*sd)[i]); > + if (entry->type != type) > + continue; Why are you not calling av_frame_side_data_get()? > @@ -822,13 +845,41 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, > if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) > return AVERROR(EINVAL); > > + desc = av_frame_side_data_desc(src->type); > + if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) > + remove_side_data(sd, nb_sd, src->type); > + if (!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) { > + for (int i = 0; i < *nb_sd; i++) { > + AVFrameSideData *entry = ((*sd)[i]); > + AVDictionary *dict = NULL; > + > + if (entry->type != src->type) > + continue; > + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE)) > + return AVERROR(EEXIST); > + > + ret = av_dict_copy(&dict, src->metadata, 0); > + if (ret < 0) > + return ret; > + > + ret = av_buffer_replace(&entry->buf, src->buf); > + if (ret < 0) { > + av_dict_free(&dict); > + return ret; > + } > + > + av_dict_free(&entry->metadata); > + entry->metadata = dict; > + entry->data = src->data; > + entry->size = src->size; > + return 0; > + } This whole block looks very similar to the one you're adding to av_frame_side_data_new(). > + } > + > buf = av_buffer_ref(src->buf); > if (!buf) > return AVERROR(ENOMEM); > > - if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) > - remove_side_data(sd, nb_sd, src->type); > - > sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); > if (!sd_dst) { > av_buffer_unref(&buf); > diff --git a/libavutil/frame.h b/libavutil/frame.h > index 3b6d746a16..2ea129888e 100644 > --- a/libavutil/frame.h > +++ b/libavutil/frame.h > @@ -1040,7 +1040,14 @@ const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType typ > */ > 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. This should mention that it only applies to MULTI side data types. -- Anton Khirnov _______________________________________________ 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".