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 93DBB49FB4 for ; Sun, 17 Mar 2024 20:02:10 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1090F68D20A; Sun, 17 Mar 2024 22:01:23 +0200 (EET) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 352FE68D1CB for ; Sun, 17 Mar 2024 22:01:12 +0200 (EET) Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-51325c38d10so4229698e87.1 for ; Sun, 17 Mar 2024 13:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710705671; x=1711310471; 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=IZWpwXhe8RWUtcBxWwVAbDpDCUE14ngk2xDfOmszF08=; b=YxO2gl5ndlNm7S67b5wZ5SxgcI6bmGB2H6QtavsEPCnlO8/YBEjx5nuMWREgmJKL8s OxYpyKK5zcg8FfKN/CTgTHPpgfEUblGOjK2k0xZalx83K/ECmhtJhOb0xkY+bi5MTxM8 3V++fM2aQoOfl+rL3fgk0M/imoH796J0I4AmucV+DVoTbp3+umOO5v4Fa63haJR2dBNA z/MYucTHkX3+j2uqFSyuJMaeERODUrXnp7bBS2Mz2yyEJ4ZdG/AseWSvyv52VXZ+ZVps G6AH5WNB4ZsIFm+a3nBqrzjDVIpnbEX4zPT8ryd0u20d6EcJ7x1D6iEU1rPvn81rOINn Yp2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710705671; x=1711310471; 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=IZWpwXhe8RWUtcBxWwVAbDpDCUE14ngk2xDfOmszF08=; b=Er+8WSc2hf5I80Irs9cB2aBzr7WXaIPCXeqZ6w/GeNi4e/5YFxkTuiKkLAApFXPRO7 9O34ZRbD0WHuz+3dQiGbRmoVjxNOYFxnroAuOScGLpMHNfy4MjQ8msHvYzRsyLwSHirN CBqm/EhywUyWQQ/wR5COjaGLbMvHDvawtzkfMEraYrr4EhYgPT8sJlmVNJVG1H6Rp1at luQfR7DcY8DIrKWMqYg+Sxpo/j1VOlOldK/dPyIBpqL/ISuVy4wkkShutuxi0V3k8wtU T89liIX0RXUuOfcj+Qb22iomiy3/ZTFVOFuvadYpNXIPIqz5h86Vq23ZrRJuw2vck28V kXQw== X-Gm-Message-State: AOJu0YwNL7Fyf65omLze6Kui9AtsF4bhAAKAGPZpqvgUUXWAnssbFsxf n6slXs2VZ6KoDoLpUy6u92SrrWQW3+3IgCI/xbIAq2QOOaczGwsvygMJLozZ X-Google-Smtp-Source: AGHT+IHDaue3nSu4+0DjR+JKhZgkud8ViHDTor1nTWhH7fpPx43QC6r8bCW3skQ37W/MQt/rkhlNJg== X-Received: by 2002:ac2:4dbb:0:b0:513:19ce:cbde with SMTP id h27-20020ac24dbb000000b0051319cecbdemr3699402lfe.22.1710705671395; Sun, 17 Mar 2024 13:01:11 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id y3-20020a056512044300b00513c844603fsm1340462lfk.41.2024.03.17.13.01.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 13:01:11 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 17 Mar 2024 22:00:43 +0200 Message-ID: <20240317200100.152097-7-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317200100.152097-1-jeebjp@gmail.com> References: <20240317200100.152097-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v9 06/14] avutil/frame: add helper for adding existing side data 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: --- libavutil/frame.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ libavutil/frame.h | 20 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 4074391a92..46f976a3ed 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -98,6 +98,23 @@ static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, } } +static void remove_side_data_by_entry(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *target) +{ + for (int i = *nb_sd - 1; i >= 0; i--) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry != target) + continue; + + free_side_data(&entry); + + ((*sd)[i]) = ((*sd)[*nb_sd - 1]); + (*nb_sd)--; + + return; + } +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); @@ -764,6 +781,38 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, return ret; } +int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *src, unsigned int flags) +{ + AVBufferRef *buf = NULL; + AVFrameSideData *sd_dst = NULL; + int ret = AVERROR_BUG; + + if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) + return AVERROR(EINVAL); + + 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_to_set_from_buf(sd, nb_sd, src->type, buf); + if (!sd_dst) { + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0); + if (ret < 0) { + remove_side_data_by_entry(sd, nb_sd, sd_dst); + return ret; + } + + return 0; +} + AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 5d68d1e7af..ce93421d60 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1021,6 +1021,26 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags); +/** + * Add a new side data entry to an array based on existing side data, taking + * a reference towards the contained AVBufferRef. + * + * @param sd pointer to array of side data to which to add another entry, + * or to NULL in order to start a new array. + * @param nb_sd pointer to an integer containing the number of entries in + * the array. + * @param src side data to be cloned, with a new reference utilized + * 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. + */ +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".