From patchwork Sun Nov 26 19:58:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 44817 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880331pzb; Sun, 26 Nov 2023 12:00:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrbVwOdtIJhu0Nw6L6yP7DQGELOPwhA1TwDTlRvq8F4XenD1xoayqyy/FanyiQqP4m9EEL X-Received: by 2002:a17:906:c30c:b0:a04:9f07:cb7 with SMTP id s12-20020a170906c30c00b00a049f070cb7mr5811481ejz.2.1701028828801; Sun, 26 Nov 2023 12:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028828; cv=none; d=google.com; s=arc-20160816; b=Iiw9/czBjFqAK5HitwzZacXn/KVCeOXaz7SsTxbTQi9rcZtf2FHrnQbZdrTB1fkiEI fXtffh9Yxe1CuwUruLwHSBX42eLANho66x5+gaaT/2BTdYMMyGVNER2d6tfOb5HuxgYX QERpBJZqvI4SB2YncbqHQzGdWv4RSB4hE1nxwYHOJ7KTUylkL1xcK+Y0N7LK07urYqvr gvwVphkYbcx/ZhGEtVFcDegwTiXdi5qBZ16yWK5SSZ9VCTagz+tk3K1KKyZtc7v9n9E9 /D/ia0Ac1LMRJpGBEmHDfx8zkpU5fomzZ0ZaY5eYgwmg9vALZ/qAPnkbVNYnyizs+Oxl /3jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=vgTpJ+pQvFzJbZNJvxc1dOe2AtP4g7rdxQ7yWI3edWw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=TKyWPsymF8vYF3uaA5/55iCkqgu6qPa5UBBWVZUAepIg4vYniYAdt12LVSRrjc9eVK jbOgA0UdyP3qyRaDfOmId4ZBdaI5tdJuNwFtDeCQTWrZk883daZwo/2f/hzWKIdz7jVd WgqoiY1qipBSLCeH0+l+uVcl5MvC0DzxKKVr2ZYfmMqphSx0z3Lpb0EkoMGUBgL4eeAd 7GgExejam9WlR7y6uYzLYTkQsl005TXZJwx9tPY5z6a6mrDrWBk5Enyu0aRXpLlqoVcX 6ib3fcecAamsW3+EUjO2IzJGqe5QbXyaxC50jQ1XPTIC6X28bs3MKbbHOxO7tbjxH9pU u4eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TqVVzFBU; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a11-20020a170906190b00b009fea91c1ec9si4256533eje.297.2023.11.26.12.00.28; Sun, 26 Nov 2023 12:00:28 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TqVVzFBU; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1638F68CF81; Sun, 26 Nov 2023 21:59:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0133468CF71 for ; Sun, 26 Nov 2023 21:58:51 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-507cd62472dso4670712e87.0 for ; Sun, 26 Nov 2023 11:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028731; x=1701633531; 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=/PQK9vsRBA3AipKqaL/Nrb6qEl8CzWv4bCOxL3HtR20=; b=TqVVzFBUizEoxzVoTZt5qDl1NsM7VcQELy8OYZS1/WIWE4qiqPoUQCFlxNp1yce5Ox QgHzBSmvWbzgZ6dUUuisCJVFmlNObudt0wh1c+sM/hw+1zX56iStE4Tb7rOryhenUL7B s+BHkrCGC48sgGS7N2hDC+H2mNdMAqfBpWQWZKem0qcLx4SlUJNaPUeIcLCPRk7SFw17 SF3V4fU0REsJlf5Li6omhvA1SSMoIjyVdjcomDVUvpE2DS4WptNA1ysaJKj7i3/Jz8m8 iNMwWYmIpIGCJMzX7pRgEln0/CzSRJomKVzPPZaWf4a750edkKuhzIWDxqF/IWZV4S/F cklw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028731; x=1701633531; 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=/PQK9vsRBA3AipKqaL/Nrb6qEl8CzWv4bCOxL3HtR20=; b=QQJW0XMi6pYBYRAXKaPeXXL2l4jgvPFqEKKarHmt5uREwpvexinjfGLifrUbwiP3+f 7dHboLGU9AKuOdF6r2G3JNVMOFQGRjh7qe+Szwjt5h228GOtRFFbusaK0w4jt2iuU+0/ eIHuO6XyNhUp+Uc5wKxHHem8p6mftAcelKVZkVNB7DAllumaDULoc+HFqHKQBAksfckS H8GiShAlaV1UV2yBSE52sbx1863lG4o8rNjdUD6t33MBKxoaaaXZ2J2VChtK4TUvFAJp NbzcIFRVzp7GaD86jEl3+GyLmLXuZgu8uYkKtLv6p7jjhnNIKpnZN/tXd15RrG3e+Coa Ra4A== X-Gm-Message-State: AOJu0Yzjdr3wkKIJln5kyCpEc8E7b54dkFRJxc/qiIjeeOUwmODos9lK +I40JNhqlRAmprLUncuJkZTe9dXS1aA= X-Received: by 2002:ac2:5f09:0:b0:507:9ef4:8309 with SMTP id 9-20020ac25f09000000b005079ef48309mr2357722lfq.25.1701028731101; Sun, 26 Nov 2023 11:58:51 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id k16-20020ac24f10000000b00500d1a72734sm1281833lfr.130.2023.11.26.11.58.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:50 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:29 +0200 Message-ID: <20231126195838.392467-11-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231126195838.392467-1-jeebjp@gmail.com> References: <20231126195838.392467-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 10/14] avcodec: add helper for configuring AVCodecContext's side data set 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dAMQ98f0OZH2 This allows API clients that wish to configure multiple entries at a time to do so without writing the looping code themselves. --- libavcodec/avcodec.c | 28 ++++++++++++++++++++++++++++ libavcodec/avcodec.h | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 2dda310e91..9b56af8114 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -718,3 +718,31 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return ff_decode_receive_frame(avctx, frame); return ff_encode_receive_frame(avctx, frame); } + +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideDataSet *set, + unsigned int flags) +{ + if (!avctx) + return AVERROR(EINVAL); + + if (!set) { + av_frame_side_data_set_uninit(&avctx->frame_sd_set); + return 0; + } + + if (set->nb_sd > 0 && set->nb_sd == avctx->frame_sd_set.nb_sd && + set->sd == avctx->frame_sd_set.sd) + return AVERROR(EINVAL); + + for (int i = 0; i < set->nb_sd; i++) { + int ret = av_frame_side_data_set_entry_from_sd( + &avctx->frame_sd_set, set->sd[i], flags); + if (ret < 0) { + av_frame_side_data_set_uninit(&avctx->frame_sd_set); + return ret; + } + } + + return 0; +} diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 0c1a8ade49..40261594f1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3154,6 +3154,26 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); */ int avcodec_is_open(AVCodecContext *s); +/** + * Add multiple side data entries to an AVCodecContext set in one go, for + * example from an AVFrame. + * + * In case the function fails to add a side data entry, it will clear the + * whole side data set. + * + * @param avctx context to which the side data should be added + * @param set a set from which the side data should be added from. + * if null, clears out the side data for this context. + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return negative error code on failure, >=0 on success. + * + * @see av_frame_side_data_set_new_entry regarding the flags. + */ +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideDataSet *set, + unsigned int flags); + /** * @} */