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 2695C4A470 for ; Thu, 28 Mar 2024 11:28:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5438868D6EB; Thu, 28 Mar 2024 13:28:00 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D040C68D59D for ; Thu, 28 Mar 2024 13:27:53 +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=jcYbGNt9; dkim-atps=neutral Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8FAF0240DAC for ; Thu, 28 Mar 2024 12:27:53 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id CsXgAdiL5Kxe for ; Thu, 28 Mar 2024 12:27:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1711625272; bh=EuHwRpkhgC+AYGOaaiLM9L0d2zwvpEgvEv41FYxKKac=; h=Subject:From:To:In-Reply-To:References:Date:From; b=jcYbGNt9ogUhgb64MYKZdC9Yn28VyxVxnkAFj7yWSH70xYlKdkf5KQp83GFSFM18A qjsT1AQVZ6VTnSQMnmtl7yE/FdbPA/idMq18VQ8rA0Ba4KlJ5hZhgJlcl1M7sJp7vR +F+dzr0EKCMK6O+mOzawDC7ybOgpg3jnQ/VVtTtWT/Z1NS48XiUbTLrAjwLAfMErHW GmtKkOw7iInD4WvEmNWk5Ymf9Ct22PmXVaaC2dqnL4WdLiwHKGIEDCJ8Znor+ru/mL F0QDpxU+EY3W3mgBCUiJsa56IXfbcXvPCIPCY0Ga9fLV6nxVw4jcfY+93IAkRIpwRF ZwUAC8lkgq5Qw== 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 E44102404AF for ; Thu, 28 Mar 2024 12:27:52 +0100 (CET) Received: by lain.khirnov.net (Postfix, from userid 1000) id D19DA1601B9; Thu, 28 Mar 2024 12:27:52 +0100 (CET) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20240328031210.21407-2-jamrial@gmail.com> References: <20240328031210.21407-1-jamrial@gmail.com> <20240328031210.21407-2-jamrial@gmail.com> Mail-Followup-To: FFmpeg development discussions and patches Date: Thu, 28 Mar 2024 12:27:52 +0100 Message-ID: <171162527283.7287.16403425396625504098@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 2/7 v4] avutil/frame: add helper for adding side data w/ AVBufferRef to 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: Quoting James Almer (2024-03-28 04:12:05) > Signed-off-by: James Almer > --- > libavutil/frame.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ > libavutil/frame.h | 34 ++++++++++++++++++++++++++++++ > 2 files changed, 87 insertions(+) > > diff --git a/libavutil/frame.c b/libavutil/frame.c > index d9bd19b2aa..a165e56a64 100644 > --- a/libavutil/frame.c > +++ b/libavutil/frame.c > @@ -834,6 +834,59 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, > return ret; > } > > +AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, > + enum AVFrameSideDataType type, > + AVBufferRef **pbuf, unsigned int flags) > +{ > + const AVSideDataDescriptor *desc = av_frame_side_data_desc(type); > + AVFrameSideData *sd_dst = NULL; > + AVBufferRef *buf; > + > + if (!sd || !pbuf || !*pbuf || !nb_sd || (*nb_sd && !*sd)) Overzealous checks like these tend to hide bugs. Any of these conditions being false means the caller is insane and we should crash. > + return 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)) { > + for (int i = 0; i < *nb_sd; i++) { > + AVFrameSideData *entry = ((*sd)[i]); > + > + if (entry->type != type) > + continue; > + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE)) > + return NULL; > + > + buf = *pbuf; > + if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) { > + int ret = av_buffer_replace(&entry->buf, buf); > + if (ret < 0) > + return NULL; > + } else > + *pbuf = NULL; > + > + av_dict_free(&entry->metadata); > + entry->data = buf->data; > + entry->size = buf->size; > + return entry; This again looks like a minor variation of the block you've added twice already. > + } > + } > + > + buf = (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) ? > + av_buffer_ref(*pbuf) : *pbuf; > + > + sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); > + if (!sd_dst) { > + if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) > + av_buffer_unref(&buf); > + return NULL; > + } > + > + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) > + *pbuf = NULL; > + > + return sd_dst; > +} > + > int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, > const AVFrameSideData *src, unsigned int flags) > { > diff --git a/libavutil/frame.h b/libavutil/frame.h > index 2ea129888e..3e5d170a5b 100644 > --- a/libavutil/frame.h > +++ b/libavutil/frame.h > @@ -1048,6 +1048,10 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); > * Don't add a new entry if another of the same type exists. > */ > #define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1) > +/** > + * Create a new reference instead of taking ownership of the passed in one. > + */ > +#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2) Who needs this? -- 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".