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 73CD748ACB for ; Thu, 29 Feb 2024 16:44:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 52A1368D1FE; Thu, 29 Feb 2024 18:43:32 +0200 (EET) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1385A68D1A4 for ; Thu, 29 Feb 2024 18:43:22 +0200 (EET) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5131a9b3d5bso1225603e87.0 for ; Thu, 29 Feb 2024 08:43:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225001; x=1709829801; 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=RRYdj0b2fAhaxAXQp1VM/OeseYX3D/CePotAVwaSfAs=; b=b0AYh96JNHo39LNiL3Nc+KTmnIA8TgR33dawg/1jWl2SMTR9wP66LHzTWoRFpomNKt hZ9NAgNUVRvZ6yHaZ+/PLYadhyVetr7TctJxcT0LjxjlxwgY0+yqgJSSHBtiv8VDW6ij ku1C+hp4NJ9w4A60R/W4SwgHZ8ukJaLSNbVmCOUZ5l9Uy3nXhorfeZ2yYlloQt7LyURT W621UYLqtKhr91Qlv7Jj4+7tXooXOpKnSwytJZxvnFxjlPkifpIjfp33jjKp0+0faMg6 /wIg3JJKMvFmaB0CicoV5ODK6C+UnSQXC//j37x2ngPt9IdJuOZR/v1ypNwX/1PwgyaZ pbWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225001; x=1709829801; 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=RRYdj0b2fAhaxAXQp1VM/OeseYX3D/CePotAVwaSfAs=; b=tSK3fmFwLJ2+4WsA1i/eBRgWI2FrJ38R6EjhU71qPMqwxUG4iOecJqjl7/FjBjnIit IAK5gmW8uJTJaOF3fpq90y80F0dnWlYNNY5O/16xPuZGBXEtz/bZfiBzsV5+y2bDi9b2 TEgKAHFaVYKdVwzlbRw5ab99Af/YaqwUaV10ScoSpsRtb0sv9GmeDRrN2PZy3Gtar16p FU05gFOWCryGZPEaPz3nQ2b7tah6HwgDSCJInmcbaJ2GgytcS0YAaS28XTicNlLDS3W+ 6nbzO86QrlYKP4JVzaOB8maygVJQxC+9oK5E3KumkSP4UEgiAUCDyBXLixYKYMOvjGAr XM5w== X-Gm-Message-State: AOJu0YwySkWKRt7/TtLtz9ilIBwpsZ/ctYLuIyhaHEh8yZZceovwZFFN 0MZiJWgtXTFDB8qoPZE8PZnxw+NwKt2GuUpv0EKvPFsuKWAaXolN/KuHyC/K X-Google-Smtp-Source: AGHT+IF2W9rtLNogJyj8OSywbm/o6nDg4D6RrKhEdIAWvSAOQv3lviTDgYL8vaNKQpy1+9wdhrsfMg== X-Received: by 2002:a05:6512:1250:b0:513:2c29:216c with SMTP id fb16-20020a056512125000b005132c29216cmr689856lfb.11.1709225001122; Thu, 29 Feb 2024 08:43:21 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id k6-20020ac24566000000b00513290734cbsm206248lfm.292.2024.02.29.08.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:43:20 -0800 (PST) From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Feb 2024 18:42:54 +0200 Message-ID: <20240229164307.3535613-8-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229164307.3535613-1-jeebjp@gmail.com> References: <20240229164307.3535613-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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 | 57 +++++++++++++++++++++++++++++++---------------- libavutil/frame.h | 20 +++++++++++++++++ 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 99c9ce4119..3a2084d1ca 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -889,36 +889,55 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, return ret; } -int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd, - const AVFrameSideData *src, - unsigned int flags) +AVFrameSideData *av_frame_side_data_from_buf(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + const AVBufferRef *buf, + unsigned int flags) { - if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) - return AVERROR(EINVAL); + if (!sd || !buf || !nb_sd || (*nb_sd && !*sd)) + return NULL; + + if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) + remove_side_data(sd, nb_sd, type); { - AVBufferRef *buf = av_buffer_ref(src->buf); - AVFrameSideData *sd_dst = NULL; + AVBufferRef *new_buf = av_buffer_ref(buf); + AVFrameSideData *sd_dst = NULL; if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) - 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; } - { - int 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 sd_dst; + } +} - return 0; +int av_frame_side_data_from_sd(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_from_buf(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); + return ret; } + + return 0; } AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, diff --git a/libavutil/frame.h b/libavutil/frame.h index 47d0096bc4..908fd4a90d 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1081,6 +1081,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 a set from an existing AVBufferRef. + * + * @param sd pointer to array of side data to which to add another entry. + * @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_SET_FLAG_* flags, or 0. + * + * @return newly added side data on success, NULL on error. In case of + * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries + * of matching AVFrameSideDataType will be removed before the + * addition is attempted. + */ +AVFrameSideData *av_frame_side_data_from_buf(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + const AVBufferRef *buf, + unsigned int flags); + /** * Add a new side data entry to a set 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".