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 41B9649DD6 for ; Mon, 11 Mar 2024 20:59:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E8B2268D14B; Mon, 11 Mar 2024 22:58:58 +0200 (EET) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D66068D0E0 for ; Mon, 11 Mar 2024 22:58:48 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-513173e8191so4807437e87.1 for ; Mon, 11 Mar 2024 13:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710190728; x=1710795528; 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=U07xMKEBkfkFzamRQVoeJwv8BVyOBrrsvCOFrsKgi3kSzLoJlbHyH7igzwEJICqwIl YUjnPQkLrdeyksCT4TWdcUzoPPznCQaYXZW+Y+o7wsFH02ZXK2kZHVPdkHIJhq0m8/bl e3Dt6qBvYbclH59xBkyutslrDbjFlVuaMO+gI7du/KE4aOXOlaAVhc1W8gRlSgLlFAMG JhH+FzKeJjrMApvjCxiK3i72qlZNL6MBZ2Ch9We5+ybvjseBuo5kzrmfbwvJLUbSABTs VnSXuPu35xWwWZDc2zPyn9I+LZJNtMALn3/VBHN27rblk83avULAPD2csMRVhk2Bl3Py dETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710190728; x=1710795528; 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=fE1aWg3Ohqt+q0Cn/FXq8DiasAdlASh4vT9nnQFohorUIpjdOS7sJFE1Xr+Ln4TAb5 uniinCtJV4DV3zQKbWBHuS/YV1A6ybUWGGo2eduB31VfjZvXfiFOjfAO9Xp7gfKlnG/g fSAcbKtOfoMrfsRH8iyjDjZGnO6YzZoTPzQ7+HeXr2umKAh8hIyjGXUIYXNRyJZEAETJ R4G87ngtcQ3ZknpsUg4O0CQRxjLfd4wZmDDpMZKgoTjVGSJ6IlsUNee3HDliOfFYxiqA BuCZEGyoSprkd9yuns3a4Q7sGUoD0/NJwJFqPkjc6YBjE34QHPSGr/nbcy1ptQ4wcvbE 2Xsg== X-Gm-Message-State: AOJu0YyaVsOSLz5oXA5YbP51q5/VM8axx727JpYWVKMLcaBXZyOFwKGM MLIk8rC95akYB49lp9bpmqvfZvMWrasv1Se08vsvrvi8A+eq0Auy7D4Qhlka X-Google-Smtp-Source: AGHT+IE1nX1J4vkHoRJHeeidShYgp2N2qRlN0RJs55xizFmVf+mdF1CCxvtkvVT9GMALV6Utl9fKcA== X-Received: by 2002:a05:6512:124f:b0:513:a8fc:95d7 with SMTP id fb15-20020a056512124f00b00513a8fc95d7mr3499550lfb.38.1710190727599; Mon, 11 Mar 2024 13:58:47 -0700 (PDT) Received: from maomao.mshome.net (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id c17-20020ac25f71000000b0051333104075sm1249247lfc.259.2024.03.11.13.58.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 13:58:47 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Mar 2024 22:58:29 +0200 Message-ID: <20240311205844.3569895-7-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240311205844.3569895-1-jeebjp@gmail.com> References: <20240311205844.3569895-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v8 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".