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 46C2D49FA8 for ; Sun, 17 Mar 2024 20:02:19 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1913168D211; Sun, 17 Mar 2024 22:01:24 +0200 (EET) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A690168D1B4 for ; Sun, 17 Mar 2024 22:01:12 +0200 (EET) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-512b3b04995so3326690e87.3 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=1710705672; x=1711310472; 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=qt6a8/F8bqj+RTz8gRZJFV2uZaNZU+zonBEJlN8Ye0c=; b=U6Z5YraqA2BHGSZe4a3yVN6p92egKbJLEZm6hL9pRLc9Hy19CyofBFHEXLQLNEkY9j 5yvvBhMdp5b8/UeWN7sHQshXwNN0T95Bv6jI8msFGi2huuTOBbFwNL1pORMGguaxrnEJ RCoPGdK4cu/aQnnTQJIsIa7iak6l27sF0xyHilaq9fritHTz5T0y1wQrMJcxuorkhbY2 yCm5h3v6aeG9gFdUeP7ki9noc2rYQ6QUU5B4Gwt3Zh7FHLtczZ1hMw/Hh2onqhs2/hlV WZWMkBiSpZyfl1D/pGeuMzHJqhsk+tmU/UEO8lV9I7lE/PPGyKGDfH/bn9OiIvhxQX2y 0gVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710705672; x=1711310472; 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=qt6a8/F8bqj+RTz8gRZJFV2uZaNZU+zonBEJlN8Ye0c=; b=Ww8GzcxnsOytSqkPv5OMbokeZyZVhbb2l1xScRY6+5l0fLSUZKCb9lqS37bi89+YXU JOcoawUKbGGHlCKfJpPAVYxZax21NZk5zFdra3gl5zYW2fc8dgrzl+iiI/5Um/biB0bo x1C7MBmCPdJaL6DyBkxj/OH0PLg7ogf7CD9SHZPhrT7XEigC4AejwLT3W6gq0ZV/VgKI h+O65+PNlaCJHxtdv7S+W+nUiIQLu3KCqyz/9YUfUpRuNmwCLqjuzC5WVS3A+ml4didG iuh5SPAySzxKbO2bEmXtppK09PSTaRvM18+gSkbtOrHvkwklo/JE3Y9qoSfpptw8MPXV miMw== X-Gm-Message-State: AOJu0Yy2ZIOv7N1YogMm3hU257weJCq6qZbuIP9+UsfgxAJJqYsblABa rNYe71YyV8acfKYRARCxwJdOcecLp527MpFa84oyGdiEEuUneJ/4MIl6ULr3 X-Google-Smtp-Source: AGHT+IFBV98AjTGYetm22EYXJzDebnbpZCKxK7gwy5wLzd9Pt/Dk3vxaeVvTElWtVaJSSxdguKRnwQ== X-Received: by 2002:a05:6512:3b9b:b0:513:e918:42e9 with SMTP id g27-20020a0565123b9b00b00513e91842e9mr1326814lfv.62.1710705671809; 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:44 +0200 Message-ID: <20240317200100.152097-8-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 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 46f976a3ed..30db83a5e5 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_to_set_from_buf(sd, nb_sd, src->type, buf); + sd_dst = add_side_data_to_set_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".