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 09F6A4A072 for ; Mon, 18 Mar 2024 21:33:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA6FA68D3C2; Mon, 18 Mar 2024 23:32:04 +0200 (EET) Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C79868D282 for ; Mon, 18 Mar 2024 23:31:53 +0200 (EET) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-514a8259ec1so1020037e87.1 for ; Mon, 18 Mar 2024 14:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710797513; x=1711402313; 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=UN3q0/8h/LwFE70loWolMQkFDgXT8sfC0nyet/Sef8c=; b=KTndFbR5L9UtYGFfdNIg8YxHsZasY66DWUCx36x7/Xh5T8zqGuMpzWpl6hxl27e3aE EeqVW7+IlBR02snfZyaqAcVaz/pM2nwecqKgcwBysjN1+0uCjRxQjS9XyQsUBqdhjwMl Dah6ZnEwodj9eBoNJ2n02HDmR2uIDrAjT9fVAPZc2Ge7vNEdoXC9Bp2/C3P+sHmtniDo rv9sZ027XO4n4sdNX2biBpSQFd+ZM+sT7SYx+rrhCag8VBz7gW/TmL80ajEoKAEB8NCj 091ECRStQG9Y2jckjPawl9JAz98TwOP69APrHagRpp+aq43PoDJ2cJHKovpjdoFtyTaZ WDZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710797513; x=1711402313; 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=UN3q0/8h/LwFE70loWolMQkFDgXT8sfC0nyet/Sef8c=; b=pjoDnGtbUZGf+5rOKjlZ2eEz1rl+CC7Obv97O61b154ySnmAiU6VgfRu9nZEyXh6H/ 4zP66oeOFqLZig0hXt1X1YGeWX4tlLJ5o8wQMgZYLlWvXB3xwEFyZzjXSXoYb/3lP1MO 5IklsKxEfZnWOU/bz/boxzqo6IRoI+/WvN/kV9eYylS3pbVaQw9bDmbdK7fJX742U5Gg 71003poUsl6WdFU218qfY/PeqvxyHhAc78VX0uEdu3QHmCav9PSPW4LyUS0Fz2lvT8aN DA5E+0DHht4HdkCZpggEXMuPsu51Ty5OZ1MWZtutSPEgPLWY7QicvmJIUyYeDKIaxMpF 4Mng== X-Gm-Message-State: AOJu0Ywezx/o5Yf3whS/1CuWZWmTJMs/svhOxD8yLGx80EZP0Qhct/M3 dC6yq9POC3BbjAKaNvbaP3TEGNgEE9alg59INdeCPSnqZVOE+bauPllo4ZkK X-Google-Smtp-Source: AGHT+IFL+72LI4MbH7418UlLvbXoY00v0Zv5WNDCG9CmcKNpY+B8rmhYskUEiAvFNKcjAUiEwCOGtA== X-Received: by 2002:a19:9118:0:b0:513:c658:7997 with SMTP id t24-20020a199118000000b00513c6587997mr8126429lfd.24.1710797512802; Mon, 18 Mar 2024 14:31:52 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id c13-20020a056512324d00b00514b5462dc7sm186929lfr.56.2024.03.18.14.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 14:31:52 -0700 (PDT) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Mar 2024 23:31:30 +0200 Message-ID: <20240318213141.1376789-8-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318213141.1376789-1-jeebjp@gmail.com> References: <20240318213141.1376789-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v10 07/14] 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: This was requested to be added in review. --- libavutil/frame.c | 43 ++++++++++++++++++++++++++++++------------- libavutil/frame.h | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 9d3eae4bae..922185b823 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -781,29 +781,46 @@ 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) +AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + const AVBufferRef *buf, + unsigned int flags) { - AVBufferRef *buf = NULL; - AVFrameSideData *sd_dst = NULL; - int ret = AVERROR_BUG; + AVBufferRef *new_buf = NULL; + AVFrameSideData *sd_dst = NULL; - if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) - return AVERROR(EINVAL); + if (!sd || !buf || !nb_sd || (*nb_sd && !*sd)) + return NULL; - buf = av_buffer_ref(src->buf); + new_buf = av_buffer_ref(buf); if (!buf) - return AVERROR(ENOMEM); + return NULL; if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) - remove_side_data(sd, nb_sd, src->type); + remove_side_data(sd, nb_sd, type); - sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); + sd_dst = add_side_data_from_buf(sd, nb_sd, type, new_buf); if (!sd_dst) { - av_buffer_unref(&buf); - return AVERROR(ENOMEM); + av_buffer_unref(&new_buf); + return NULL; } + return sd_dst; +} + +int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *src, unsigned int flags) +{ + AVFrameSideData *sd_dst = NULL; + int ret = AVERROR_BUG; + + if (!src) + return AVERROR(EINVAL); + + sd_dst = av_frame_side_data_add(sd, nb_sd, src->type, src->buf, flags); + if (!sd_dst) + 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); diff --git a/libavutil/frame.h b/libavutil/frame.h index ce93421d60..a7e62ded15 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1021,6 +1021,27 @@ 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 from an existing 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 type type of the added side data + * @param buf AVBufferRef for which a new reference will be made + * @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. + */ +AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + const AVBufferRef *buf, + unsigned int flags); + /** * Add a new side data entry to an array based on existing side data, taking * a reference towards the contained AVBufferRef. -- 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".