From patchwork Sun Nov 26 19:58:20 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: 44808 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879692pzb; Sun, 26 Nov 2023 11:59:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+9ZhHllZZNpjIeBXTKCxzdyGAKEvHCNlCUWjgjNjsXmE+SCpcaVy+8jBfs50dTWplmtms X-Received: by 2002:a2e:7113:0:b0:2c5:509:c080 with SMTP id m19-20020a2e7113000000b002c50509c080mr5315039ljc.3.1701028748730; Sun, 26 Nov 2023 11:59:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028748; cv=none; d=google.com; s=arc-20160816; b=iFNYDG1LDNqBql93Lgo3tRwTBTt+Vlaal7TaWU8WartqSgkVcvZvA7RjAWcUw/Ocz+ zibcM1j9V3qDrVonnDa9jx+qVUaMbAGdQrIQ8cqV1COEUSoa2IcZDDw6gtuLyz++soYU 6Sy8GpnhTkt84QBAnXjWAOeeYfcQkoMLlpLqL9ipfhLzQFx1QvvqjNO/odRjHoAdxUpR GgB/WxAjzO1+c+ikD7V7SDuMckVqA37hTWQ9hebr6tfmatpbqX9sWCx0Qc2qJuBBBUq0 9KVcqBJY+4a+wqDVVaOGDfYTa6ahkbBn1eHNIH3Xf3AJ3e041/WZqThZyHbVwuq0mCSh 6Oww== 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=1G3Y1J0+gS+rzzvy7Y3rUZAKbfyNnP2YSdKb8Mlh13Q=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Z5cJapGtpTdYU9zk/EqnTDzTwKs8TAcczzz8U7fKgfiadyyvCgT1+GVwC97DVLyCcy TCkH2L+LD8VoHJmj4TOGqgqfjG6T01vYVn6+qEWM+eTizHYKgv2cJruXgdK4TA2fGCRl bs+sqB4bBRIRQRHECvHiVNDJ+asXxPF9hJ0Fa2cub1ROKhhfbOTo2OCZFUXMBKEpMQZz tCVkZnKu+gU1Uh+U2tPgtfU2Qfn0dJU7VK2E73epsKJhEo/7k1+QMjNsU90bHDVV1jOv 01jCcwAHzUMBEdemBsNW+zCuEBvHOqwmO+/pT3xT6s/h/xtpyLG6Na5aUUzyk7Krri0K GgNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ZCCHMkcd; 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 nb24-20020a1709071c9800b009fd1b3720a7si4447257ejc.64.2023.11.26.11.59.08; Sun, 26 Nov 2023 11:59:08 -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=ZCCHMkcd; 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 05BD168CF67; Sun, 26 Nov 2023 21:58:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76DCE68CBF2 for ; Sun, 26 Nov 2023 21:58:48 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2c8880fbb33so45883451fa.0 for ; Sun, 26 Nov 2023 11:58:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028727; x=1701633527; 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=BQ+u/TNmkCHjz6srQkEj5nFTBgpT/Uoo9XCMqUS1qBc=; b=ZCCHMkcdOWFwGwg7rgVZcysVF1ET1f0SDioB8NpQ6uF1yx7oPbqReOmbCWMcKqbpM7 B7ATTbNJXmiv8l6DFXf5Wu6NsEODrLWnY8pNE48Wlp4/e3VPENY+7avURbDRgpXKY93T 0tA/Ih+qnrT4MY/GAF1eiaCmb3Oj3bRNEWC2x9h9ygJpjZ0kqpyUyLRYVEcjfHtelnMX VA0C0C4UJX2ensSOYPC0cED0cZ8cAVPSVxEk6d5/JXrrjHCoL0GKOMFzZ0zNMBURkoxK mTTK9aGag8XIzp5JqXM9mQdP4HpZSnHguvxiDw1lxxLmGKtKRNcF7Xx4qAd+0Z/kAI2t qd3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028727; x=1701633527; 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=BQ+u/TNmkCHjz6srQkEj5nFTBgpT/Uoo9XCMqUS1qBc=; b=SnOQnBxYoMcA0Ns3fP04GP7JTu5fc1S0OC6iDUiWz1DqxRAMlCJVeQkP/OEVquy8w+ HEQaxWCyeb1cjfCUfR4hLop0MLt26Gqm1FYT+Ivdh89Zq3vnlGF45vAPXnQ2DfhwqYpL a1ZlTAm8MfhAUBSEgWrTHLCP68lhtEYX/YCgJdvVAI8W1trw/xH5xOfvd33whnPEjjqX opNDAhidFEtgwjOIbQZChGiDo5qjnTfc3CCjsntbSzkj0MNnthaMDPgrZ7JdoO5/Aw9U yVyG+V2uDNZeAT61U8XIuS1GpUwEKFu/ybvmcjdzxFrrEAkw2Bwnej9lBAukMtpnFrIZ eBOQ== X-Gm-Message-State: AOJu0YwVqHHS6Jc/3ShtRyzXF3r3WxmK0sLAcVwZiT0JrDTJpnUQxxeg D75rhajrDThC1/kwPV7hORXJHV5DTdU= X-Received: by 2002:a19:4355:0:b0:507:9996:f62b with SMTP id m21-20020a194355000000b005079996f62bmr4758971lfj.56.1701028727320; Sun, 26 Nov 2023 11:58:47 -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.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:47 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:20 +0200 Message-ID: <20231126195838.392467-2-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 01/14] avutil/frame: add AVFrameSideDataSet for passing sets of side data 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: /a5OpJ5Xd6bq --- libavutil/frame.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavutil/frame.h b/libavutil/frame.h index c0c1b23db7..6155226c1d 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -251,6 +251,14 @@ typedef struct AVFrameSideData { AVBufferRef *buf; } AVFrameSideData; +/** + * Structure to hold a set of AVFrameSideData + */ +typedef struct AVFrameSideDataSet { + AVFrameSideData **sd; + int nb_sd; +} AVFrameSideDataSet; + /** * Structure describing a single Region Of Interest. * From patchwork Sun Nov 26 19:58:21 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: 44809 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879722pzb; Sun, 26 Nov 2023 11:59:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJams2pfXEUwBwXevIN2TxmvJ47NuxDw8UrbTJpiNxeByzSgP1/GiaYoW4458E+Y2JQ+Jd X-Received: by 2002:a17:906:11e:b0:a01:ae9a:c1d3 with SMTP id 30-20020a170906011e00b00a01ae9ac1d3mr8550907eje.11.1701028757216; Sun, 26 Nov 2023 11:59:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028757; cv=none; d=google.com; s=arc-20160816; b=qp1/kgeM4JcZQwSAUHQsnDupk8ZDghM8wqIRPe9QjZQa3odycKM4y1FcN3jECavunW DVZP7wUVzXc8vn9xFdkwpG/OGIaC/VD36D2AYdUVO8OPoJPjsjlzTg+zvhwEq1G9zkO6 yQfFyUh8PCLnBGdWUemGzjIYNX7qoXTzogTaNAXEhNmTwmz5ef4SZl/PvOKRecfLfLiJ 85MN5PnE8lMwKhvj0FEXhX9O7cMD1tFuLHeGumQYaBIHvdzk6jaRgmvxx7RLtZLiEUzX cwu1KK2ksBR7IQ3iaB4RcXi/x0eShkZ8w5juCUXojIKR0QVkCxSc+hV4Zw6es+C597oV tF2g== 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=AK2pCMkUnO1U5OrYtGWHOlPojgU8aVEuuyoC3/Yyw+E=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HPJ6QtDVYbUrUnpcyhV9hE7u2LbQzni4unUrnZMFiR96U/EOum8rZxSoJypYTzlPof +7Vipvf4U3JxRBLM70HtgogpnwL+Hq/aA45B7UiwVvqHGIkZ89vFMMFz0zCytd9dkZcK G7Eb969dGY/enWsMs9sXLgatHtXai4aNXIev5a8dr3ybYu0thVuJJ6jnOg6KfvadRxSB RQ4dbfEewrOO7ZsTZjEQIRS+EfRCRfMsisQxXbuQ5Hr/wFyPZSo9xKyIZ/+IXmUWyatK yFNRgUYAOhJNacElNCXTsTLCRx3Z81ST0Kqdcd49TfEaXr53OUXZVNZ1Vnlsqe5Gu1CB Tf4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=mjcmxcS6; 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 n8-20020a1709061d0800b009e65813118csi4112107ejh.584.2023.11.26.11.59.16; Sun, 26 Nov 2023 11:59:17 -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=mjcmxcS6; 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 F2D8B68CBF2; Sun, 26 Nov 2023 21:58:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 CA0FD68CBF2 for ; Sun, 26 Nov 2023 21:58:48 +0200 (EET) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-50aa8c0af41so4655015e87.1 for ; Sun, 26 Nov 2023 11:58:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028728; x=1701633528; 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=LAKSe6+K9zynbBRmIP01MdptZky8V6VEeQXJv4IjXro=; b=mjcmxcS6fhbxuSyFRkmyyog2z0wRwkYOx9NgRlMfRrtFAvQBJ3TUJQHlTUB5TLyflq dL6BlNM2a1vEtgCEyZoVHkphCpbcwxkasZ525oh4zD1Gp262SiKDDUxZDv9ljzSSReQ5 q+Y25Xt5SLdAZLqtBOn6Q/1DOCaUWOjO0c6o5HkleuXrSqTNDxjWNRJwbr8R0kk6yfMj IcUnBroivGYXZWeoMk8jOIPTdHo/1a6CjKxgaUIYBp6oF6QZbraK1P70qKKRxJ8YwBaa O5V1i94h8wN7Hlhsi+MFWtm6nyFCyZ3AfKjIZ1TFLFCmcj/gLnurM+58RvcQhs7xOc4B lijQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028728; x=1701633528; 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=LAKSe6+K9zynbBRmIP01MdptZky8V6VEeQXJv4IjXro=; b=Lu8W+AB7rGNtTo9eXoqYxVWJVbf+ICn3Ma83mF+OTReq8vPJbkRXKXbOHAGT7WnUAv DFL5YU3egeBU/TPaugpOzJSEd0M0EeOCHcJBRBOr3ydwpHSF7Ca3d/JkWaDH78OTekAW i9YVzG07UQvYFpca+opfEOjOMD4fY/AaqiausBt3POVwNNjP1UkoBCScm0xQwZsTnHUI 8j4h4GyiBwUF3VMcG7FH9bhSruiQgJZpsjh6i6VZ96qJFRvhJhfDc9XBYjwcH0nILxYO /hXFXwqWwQx5ip0i1wkoe3RniD/FauDR86rzroUAgmtLbQfDqU88YysVL0NpPicFip9W Kn/g== X-Gm-Message-State: AOJu0YziRf4rpqTEU7k59J9BnPfFkBuXfg8mGdh6xGJ4qLlS8cdUDOzJ hBzvdelEKD1SN8RSpc/8J4huQgtB+mw= X-Received: by 2002:ac2:43a6:0:b0:50a:a8d4:25f9 with SMTP id t6-20020ac243a6000000b0050aa8d425f9mr3622280lfl.12.1701028727785; Sun, 26 Nov 2023 11:58:47 -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.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:47 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:21 +0200 Message-ID: <20231126195838.392467-3-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 02/14] avutil/frame: split side data list wiping out to non-AVFrame function 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: qHkIMqtPu8YJ This will make it possible to to reuse logic in further commits. --- libavutil/frame.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index a3f07ca089..d94710687b 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -75,14 +75,19 @@ static void free_side_data(AVFrameSideData **ptr_sd) av_freep(ptr_sd); } -static void wipe_side_data(AVFrame *frame) +static void wipe_side_data(AVFrameSideData ***sd, int *nb_side_data) { - for (int i = 0; i < frame->nb_side_data; i++) { - free_side_data(&frame->side_data[i]); + for (int i = 0; i < *nb_side_data; i++) { + free_side_data(&((*sd)[i])); } - frame->nb_side_data = 0; + *nb_side_data = 0; + + av_freep(sd); +} - av_freep(&frame->side_data); +static void frame_side_data_wipe(AVFrame *frame) +{ + wipe_side_data(&frame->side_data, &frame->nb_side_data); } AVFrame *av_frame_alloc(void) @@ -337,7 +342,7 @@ FF_ENABLE_DEPRECATION_WARNINGS sd_dst = av_frame_new_side_data(dst, sd_src->type, sd_src->size); if (!sd_dst) { - wipe_side_data(dst); + frame_side_data_wipe(dst); return AVERROR(ENOMEM); } memcpy(sd_dst->data, sd_src->data, sd_src->size); @@ -346,7 +351,7 @@ FF_ENABLE_DEPRECATION_WARNINGS sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); if (!sd_dst) { av_buffer_unref(&ref); - wipe_side_data(dst); + frame_side_data_wipe(dst); return AVERROR(ENOMEM); } } @@ -525,7 +530,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - wipe_side_data(dst); + frame_side_data_wipe(dst); av_dict_free(&dst->metadata); ret = frame_copy_props(dst, src, 0); if (ret < 0) @@ -624,7 +629,7 @@ void av_frame_unref(AVFrame *frame) if (!frame) return; - wipe_side_data(frame); + frame_side_data_wipe(frame); for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) av_buffer_unref(&frame->buf[i]); From patchwork Sun Nov 26 19:58:22 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: 44810 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879777pzb; Sun, 26 Nov 2023 11:59:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IH32ewk7dQcE/71Y6Ybgg/OClzZwkbMHtPxYOqG9qLtv3+/QBwXWJvBukOhCXehS4G8u3Hb X-Received: by 2002:a17:907:1315:b0:a04:ce3c:937e with SMTP id vj21-20020a170907131500b00a04ce3c937emr5802705ejb.45.1701028766480; Sun, 26 Nov 2023 11:59:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028766; cv=none; d=google.com; s=arc-20160816; b=CBDtTGoybgTPS4FBcGPHBvP0FaEjQJj9xYPir5MsKwV8PyHfNjlrmgzoB91L8Hyvka IItRnMMj3sc5CLkZAs8u1z0n+zSGcFKjCzEH9OgnTNneByp2gv38vBrSDUuiycNu57gI O1PVrHJXDR4luM/SleKutZLPOLzaLKpGAnMVTRswiJ81tQJU9HoD8OXiDgSMOcDWocVE xbydGOzPQmAFV5tZ7dKdJdGORLN2mdMFqMpkH9uquH5WsUDdMzH8nqZfxB64YWwhnZy5 PIBGTtHRxTnaFZ/i2T6AWqnQihFarQS3cUMZ75G+cDjBCJolMKCNPYTpfbPHtoHM8GAz pNTA== 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=/6ySNsDxll9WklmbGdbvhrdve3bSPpCDAB/MXEgahp4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=DrkImJXDKRjrNo6vh1kIiY2GWCHXBBJR55ImUPJwRMRWeqgsMfB+dRK7rdf6AU95sL 2Dyt3AIKWhCrXh7KGN8s+ifZvPmOaMuE1yAYYfPs7VCkJMYyBMeNhtPJxBy4ecsaOUir MxODFAffvvO0i8Da8pTihc16sd/ffJCWOggvfIs5ClPND0t2AxE2nTG8iDQ1k3KONe+S L9L1MQkeoitDDbUPMUp2RgJ5Lz+cVWdGOLBjYdc3RGnqflxaY1EvKc/JCc8Gdf1+rDyN gfdzwKE5KLcLT129rkIfgRqNgaQwb5Qk2+8g3OdHetvtdHpItbxI6PSE2Cg7m02+9Awn vivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=iADGvsGQ; 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 nb24-20020a1709071c9800b009fd1b3720a7si4447514ejc.64.2023.11.26.11.59.25; Sun, 26 Nov 2023 11:59:26 -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=iADGvsGQ; 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 EB48668CF7F; Sun, 26 Nov 2023 21:58:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 1EA8768CDBB for ; Sun, 26 Nov 2023 21:58:49 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-50ba71356ddso2508189e87.1 for ; Sun, 26 Nov 2023 11:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028728; x=1701633528; 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=3cIShpbuU067D/cw2QFpUROgisYES7iU2ju9yHinZPo=; b=iADGvsGQaVXCSgCoqX6eFExzenStfDxY3fGKpE8XnHMTjKs6NkP8rzx14nTEz9o3QH cC8KfUrgYtlSQ9NoeITj1eiqAn55lHYEa9AUidLyvfD+8w2ZXRumrEdn2AUWj5YqgQ3s SNlWRKK0m0zvvZBklv8BMBgHgVq8uN3K61dBf+/7RonnqVYumqBWFVhL6NsyzMlLQUKr Y4EkpXZn44hxiCvVbKcrdWdv4e6GjfoPaE0kOyJ6s4JINSLTlLkI8lhqd+1LHlzd3QvO t1l1d7DrDAfO1kBLd5HnR4Jl0PVbnb5PS5uDjvkWQcLQf7T0dDwwwlICHsIQ5/oLZAEW seZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028728; x=1701633528; 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=3cIShpbuU067D/cw2QFpUROgisYES7iU2ju9yHinZPo=; b=UVHKuaL01p9VODgoKNNEj3Ofmv6gjBIuiqPzDQGgnnUQs3F4Af2PkvFAKCXC6TTP3A 6/VkwUBT5Fkp9ysWXTZgMBnSer/lQgZw/o5vaQ5SkJIBqioLFAo4AinBcR8eOtVt4CIL SLKXf8xXKMVyv5kTMUIo+224oZXpNjlEDZfhZXz8IqSe+cxmx4KNZd30vAtnpwGaI6hO k1eJTCIUCppe71PPoFJRkwuntTVfIBE9s7jd17f1g8a9G2Jf81qDqRp67fWCX3HOcUcI ZeNGPqHT3V/rK6aum9RHYloa1phsyDqMNDgtHsyeu5t7zzvhzlQy6WKVAV6divfsCVDJ LPZg== X-Gm-Message-State: AOJu0YxChMSYQ0A4iBoozgyonSRxxuCcfekoVv7hYOrHIU4O/NSAm7dJ h1B8nwRhi660uVmITo+kjb+tpboOois= X-Received: by 2002:a05:6512:23a5:b0:500:8fcd:c3b5 with SMTP id c37-20020a05651223a500b005008fcdc3b5mr7190682lfv.12.1701028728192; Sun, 26 Nov 2023 11:58:48 -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.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:47 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:22 +0200 Message-ID: <20231126195838.392467-4-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 03/14] avutil/frame: add helper for uninitializing side data sets 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: yopMUXtr4gKo --- libavutil/frame.c | 5 +++++ libavutil/frame.h | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index d94710687b..941a0a8148 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -90,6 +90,11 @@ static void frame_side_data_wipe(AVFrame *frame) wipe_side_data(&frame->side_data, &frame->nb_side_data); } +void av_frame_side_data_set_uninit(AVFrameSideDataSet *set) +{ + wipe_side_data(&set->sd, &set->nb_sd); +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); diff --git a/libavutil/frame.h b/libavutil/frame.h index 6155226c1d..4fe9ac9411 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1057,6 +1057,14 @@ int av_frame_apply_cropping(AVFrame *frame, int flags); */ const char *av_frame_side_data_name(enum AVFrameSideDataType type); +/** + * Free all side data entries and their contents, then zeroes out the + * struct values. + * + * @param set the set which should be uninitialized + */ +void av_frame_side_data_set_uninit(AVFrameSideDataSet *set); + /** * @} */ From patchwork Sun Nov 26 19:58:23 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: 44811 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879834pzb; Sun, 26 Nov 2023 11:59:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrZ6yO58jtIcf+1ZSwnXJ3IIeODvXhbFnK9uQcGRfuBCfyTEEx1lRQYTAasA0keLzRNoVq X-Received: by 2002:a17:906:5b:b0:a02:99b5:d0dc with SMTP id 27-20020a170906005b00b00a0299b5d0dcmr7171910ejg.10.1701028775509; Sun, 26 Nov 2023 11:59:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028775; cv=none; d=google.com; s=arc-20160816; b=Ghf3IJ+QxlBFtIfGovzi7yJqEM9z/9TGsfchCzkM2hwnQTekvXEBKCrJdb0xm3cBpp OC9F7fIe1Vnbp9CtGD62nJvXLKKUL+qhmReK3Y+HU4QbmxurXs5FL4HtSCFy8kWG+DrP kUvNTpcH79KqOHB2qvI17piDP2y8vUmtK5TJ84PNHJKHzJfKZEJXbxiqWlCtRfbDzFge 9NjEsRbOHSvSVLdaEg+LPxmN058f/mwiyOOcPCR6UvgF16aZtdVpQq6p8i2mC0feU/+y MReC6uwk9MmY6iTytELbUIDHi3gmSSn5RFacHXc/vsNHD4cQS8h4glL0BRMmeotzfFWQ hgTQ== 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=G9WtvGwNaMRYfcc85MN/d9HFRR/iJNUSFZcZtWZDK/M=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=0nN82YWiTNKeq1Hg5GONNNlNqDy/xNi2r8yCo2JrwkolcrXNiyxyDnTyRTAgxEKL1o HY4MjJAdJ05aA++rLNbZnSS4RSPdTpJpC1CJfjYohvMgQMDF8DofiH+v/3tyZLMNaZOm 5sc7vCAQDANuWGBV/eVJth9Rv8mbrP01x8v77e5jq0MT4yGMahOK6FwZ2nAFJPnfiZh8 DVX5em6VFZ06MXEjRnuLRr/LHhYjA1uUeznSGZbYps7+n8jZXYhKYEfuIk9QXJKJQvMe tVI+P8I23C34Y7v4jyYwPRMULnLa5k6g/CfwpAGzCbf4f7woWoi5zzGmPM3SfjhjM0Gd jj5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=SDPvo4bD; 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 u24-20020a170906c41800b009fc6ac2810dsi4354702ejz.120.2023.11.26.11.59.35; Sun, 26 Nov 2023 11:59:35 -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=SDPvo4bD; 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 D09E068CF88; Sun, 26 Nov 2023 21:58:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9967468CF5C for ; Sun, 26 Nov 2023 21:58:49 +0200 (EET) Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50ba78c7ee2so2129820e87.3 for ; Sun, 26 Nov 2023 11:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028729; x=1701633529; 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=+iho3qtVEgfxrxxKhLyLoYNFM/rc4iRaWmJZ8aYQlQI=; b=SDPvo4bDlVl5/ZQ2NKPe+FKNCQ6ttwh2yHti/uTF0+46sSZ7r1/Pl4tGIxu28rdbPm jSmL3yYMFDexRC566cf2N4g1iWH13jT5qQuXYMw6K8BhmeJq0r2OMoLPAKnAgb8C9kTO 9cZzJez+ML1VzzaSRDT6gsTpy8R9duNDz+yG4SKuRMIba6ThPkA8jCQ2ItB6GJPH90cQ o9bmWrI1+rpf9QyKDAVrisij+3dt090ipht4huVx57jqqfR835SSDQmfKWkHV8gp+RhU 9P9sRbw0rsrOX50/2cvHpU0Y6wFqvmPaJB3wXmPENRBleCSKAYxx9EXqcTHQ2q5tm85A X/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028729; x=1701633529; 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=+iho3qtVEgfxrxxKhLyLoYNFM/rc4iRaWmJZ8aYQlQI=; b=uemaoj1ZfcFh2NA7XqvQbcUzDMEB17LMvqfKJvC2mwat3FXeZDR0diVTnib4BICg45 B+CLL3oy+xF9ZB4PJ0t+JL69/40pre6Z/2NI5DVtm1LToRZuzHKu0t2xVdtX+F2vdalf pgyunwk81O4bR+4tN1CwOA7ZlP7fHZiag7eFhZkIloJY5kcET78goM5fP4A/0H7J61hv A5WMSCYKaqZ5RzwNDVQJZ2xMy3EU9RD8xGCd7qpMibpDstlh1NPv68v4hsZQOuIHRRM8 Lz38LPenxvYhHePjIpdMWlpPZZ5WuO624MxyFPDZ6kNwiTbHcjwbr2ylfox2faeBA0Ri 8QIA== X-Gm-Message-State: AOJu0YxDui0lA8pyBKvA2Pn5lxdGwWxJCDRNEHnATmfaeDJwUwO1D0NR JsDN6vt4I1z8QfjfnKMMWtrZ05oN+AI= X-Received: by 2002:a05:6512:3f1e:b0:507:9803:ff8b with SMTP id y30-20020a0565123f1e00b005079803ff8bmr7357887lfa.44.1701028728592; Sun, 26 Nov 2023 11:58:48 -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.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:48 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:23 +0200 Message-ID: <20231126195838.392467-5-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 04/14] avutil/frame: split side_data_from_buf to base and AVFrame func 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: Oqkc53T53KaU --- libavutil/frame.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 941a0a8148..49da452fa5 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -787,23 +787,22 @@ FF_ENABLE_DEPRECATION_WARNINGS return NULL; } -AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, - enum AVFrameSideDataType type, - AVBufferRef *buf) +static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set, + enum AVFrameSideDataType type, + AVBufferRef *buf) { AVFrameSideData *ret, **tmp; if (!buf) return NULL; - if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + if (set->nb_sd > INT_MAX / sizeof(*set->sd) - 1) return NULL; - tmp = av_realloc(frame->side_data, - (frame->nb_side_data + 1) * sizeof(*frame->side_data)); + tmp = av_realloc(set->sd, (set->nb_sd + 1) * sizeof(*set->sd)); if (!tmp) return NULL; - frame->side_data = tmp; + set->sd = tmp; ret = av_mallocz(sizeof(*ret)); if (!ret) @@ -814,7 +813,23 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, ret->size = buf->size; ret->type = type; - frame->side_data[frame->nb_side_data++] = ret; + set->sd[set->nb_sd++] = ret; + + return ret; +} + +AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf) +{ + AVFrameSideDataSet set = { + .sd = frame->side_data, + .nb_sd = frame->nb_side_data, + }; + AVFrameSideData *ret = add_side_data_to_set_from_buf(&set, type, buf); + + frame->side_data = set.sd; + frame->nb_side_data = set.nb_sd; return ret; } From patchwork Sun Nov 26 19:58:24 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: 44812 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879868pzb; Sun, 26 Nov 2023 11:59:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGB04dEQkmFcTMXe0ul2TKKK27N7qkEAW9MSepI4AofaqfYSWoBTBzTrOfzLVW4jwczet/m X-Received: by 2002:a50:9318:0:b0:54a:946a:8f5b with SMTP id m24-20020a509318000000b0054a946a8f5bmr7172690eda.41.1701028784754; Sun, 26 Nov 2023 11:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028784; cv=none; d=google.com; s=arc-20160816; b=jyV71l/S8Hdgaq6a0VdN+wFeGiSXVGM5DG48edR51nMFPiqISNtNZOlduCbk+yubVJ 80zP/ZKKhtKdSYEWoDk9msOuEMkLP5nDt1kJ7TUonLYqrXfDBH8n4LJXVJBZjR2VgnKB gL1B1BNFqXbu1O0NdOq2Pm9Jo73UAOg1POP3oIbxQbOYTFOJ8jI1oL1ZcoHhhpXI/qZx 64GfknmDPsNnoOsfymv9IqxGqpWSMx21zDnjxwla4rp6tW0xoHxNODlH23TX2V5JAz0S BcxZSmBp4DtYW/veD2pfpMcSYNVQA/elYdPqzPTYlYMd5gfTYI5nucV5rdlUEC4HVLjb kOYw== 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=wwOxUVwTwI1CMdX/lxTF3hUCOqdofVAvI7xBknRGzs8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=eKwH/s7L3veHyvVQMe3jcjX8TLo0kq9O+qc8G/3Ofrv89rK6DRJbQxGP30JtVMoXVi bFjrjFIyKz6NUdqSc6quVTnsMA82ZGAxBID/AiJM7I9uk936BP7KqomyiQUcl843bWkr mgYNsYihW7Q/pcE3vSvwt3z6HTIxmqKp4tZ0Gyum+Om62VNNl3i6QjJoM0IALdfR5k2Z RKf+HWUzrADKkXIiXbgnLB12U/F+hRIBT36MiTUX5NZGc0Hy+DZJGcZ8MlT5IbE0r4TI gnAvviRws1TixNjKyFJ4Y9CCf2csT6RLSzXalE9M9DI0kK32ceuO8GN5K3tnw/IRpXlB HOFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="Z/qUUDCQ"; 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 c17-20020a50d651000000b00549117cb68esi4079789edj.262.2023.11.26.11.59.44; Sun, 26 Nov 2023 11:59:44 -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="Z/qUUDCQ"; 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 D161868CF8D; Sun, 26 Nov 2023 21:58:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E305868CF5C for ; Sun, 26 Nov 2023 21:58:49 +0200 (EET) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-50baa1ca01cso1682037e87.2 for ; Sun, 26 Nov 2023 11:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028729; x=1701633529; 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=PgmyVlYYyIivdE/nimvzUXR2H8VOwyzRs/bk94pKtx0=; b=Z/qUUDCQ7LQ1AeQFK9JaBLW0g/TdJpy6HfGpgudXTh9SCJaMX/E6maVzWbRg+yiDju XmP6Apd31Cw+M9LTnySRlJj8V5lGOc28mxLfNdwClmKzklx1EQs6cEP4yh2Kx86nE3oH iE9NLxm/w5HmxyqrUzr7WRdejcR7KWI7PQMz6pvbKfyvJBTReIklv6Xma+qCfAc0wkgK zW8WWyCjDV+/itApJx46oOmp9HWo4i+Jv61HYmlzYa+rRtCeO8jTecNoBXz0L2nZXX5Q l5K2dqI1XakitszvQZhYJPq7v0IRXWW4Vr7jEeThR/YTabPmzPeHVfb7POno7a+bkBEF GNpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028729; x=1701633529; 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=PgmyVlYYyIivdE/nimvzUXR2H8VOwyzRs/bk94pKtx0=; b=rXRFRGZqYGwl426W7URdtRMlKTeGHsGqVyGoGMyx0HtxBbZTY7iZMZ3+Aa2yrFzEl1 UjeMRC3JSnqGzeoqieL9NSd5zpzL3xtAtcy7wsKDsRk4CZRw2FhEinTzT+7ESEO2Pbaw qY9b162Ty1yBwunCveUcuuujErvxvAL6pXVZ+3Ljl75Raih4YDZ/MfcSz9VJ646bc27r KqWICvKTFn6xJxTmNZD9Ep4s06mYhOnW9wBLwLGvieKZXGV6oil3ljaBIjFo2+IRD3PR usl9JjNJmdwFyNTwi64q1uR2oSu5jJrS/9Mb/44kROaw8xB4xaKREwymKZcGNIXcRVOI 3iPQ== X-Gm-Message-State: AOJu0YyGK7VcAp761XNOKScteZrcVaBv5EgaiGt50RteLSOX1Pwo3Moj BsfIuW+HvEggPn+N0wNT52h/3PnoMdE= X-Received: by 2002:ac2:5df9:0:b0:50a:a9a1:212e with SMTP id z25-20020ac25df9000000b0050aa9a1212emr6048005lfq.60.1701028729007; Sun, 26 Nov 2023 11:58:49 -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.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:48 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:24 +0200 Message-ID: <20231126195838.392467-6-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 05/14] avutil/frame: split side data removal out to non-AVFrame function 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: i5BJM9NaeJOe This will make it possible to reuse logic in further commits. --- libavutil/frame.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 49da452fa5..587e212d1a 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -95,6 +95,21 @@ void av_frame_side_data_set_uninit(AVFrameSideDataSet *set) wipe_side_data(&set->sd, &set->nb_sd); } +static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, + const enum AVFrameSideDataType type) +{ + for (int i = *nb_side_data - 1; i >= 0; i--) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry->type != type) + continue; + + free_side_data(&entry); + + ((*sd)[i]) = ((*sd)[*nb_side_data - 1]); + (*nb_side_data)--; + } +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); @@ -943,14 +958,7 @@ FF_ENABLE_DEPRECATION_WARNINGS void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type) { - for (int i = frame->nb_side_data - 1; i >= 0; i--) { - AVFrameSideData *sd = frame->side_data[i]; - if (sd->type == type) { - free_side_data(&frame->side_data[i]); - frame->side_data[i] = frame->side_data[frame->nb_side_data - 1]; - frame->nb_side_data--; - } - } + remove_side_data(&frame->side_data, &frame->nb_side_data, type); } const char *av_frame_side_data_name(enum AVFrameSideDataType type) From patchwork Sun Nov 26 19:58:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 44813 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2879923pzb; Sun, 26 Nov 2023 11:59:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUNOkCLmLEc3Xt6O64RMDDd4d7JmMfTiXtYBIjXMYPFtJsGmYhFaO4RIacX4+4aMRrX9LC X-Received: by 2002:aa7:d70e:0:b0:54b:ae6:6141 with SMTP id t14-20020aa7d70e000000b0054b0ae66141mr4399578edq.2.1701028794164; Sun, 26 Nov 2023 11:59:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028794; cv=none; d=google.com; s=arc-20160816; b=QE1+dJ55lgmnOSSrdzCXFI5ZA+bYF88hZKbHEiOOi4KQUPsP3ZG5e990R0YGxutqhq y3C7Fv2W7O4nnIuPkN7WxcHASe5NFg1w5+J6YtU6imc1uJDON/lPoqEOkMnxuIownrVv RNKWqmQBjoEk/i2t1LYmQ1Qe1oqVyUyEONAb0ZB6JkV0zCg+6IKWtFyRxdmjPUFz67CX JS1VJJ6YXBNYXRev87i8ar87xfi+XBaRIMClGeETiJNVaZ/iixmA+tSO8GhofZy0d92P wSGyJEPjvrZCOCk/39SySngNWdmdliTXMq0gCUSLgC0cQrvd1jvLwOgksC9v9O90tvxy Txlg== 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=nR/wTxtGHEFg3Jis/GXIrI5k5bwkdoaaXhhq52YHJ1Y=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Ok8eIjAor31ZtefKpeDTITEbAR+KC2XwBGnJUKgB32BNk1q3c8rfIuleQuJk+ihimF ArYS9apeAHgJn69/lRvC3/gj0w4XVd1YPYmhn8s8nDBuSABQ9VLJlvvkMJfWuihVuQFN U1wNkhRt1x5j+oDEOFV4F14FE+XqwgQ62DU6Y12OOciletaL3nBEYyp/Hfq+ucFZdNse uIcVVXZGv4Nlg/VDA9+MAgqSn/aOlkzb1uz+u63JRItyTDJINwtrGh8cvOVhwyKvuNPZ Q+XiCeEUieccK76fgTcOTWRMYEdE9dBuuNgsupUU/jHwqBylX35g3jPAMu/bUOgTrcdB WhmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=FFq2SNR8; 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 f3-20020a50a6c3000000b00548ab7d9393si4213124edc.133.2023.11.26.11.59.53; Sun, 26 Nov 2023 11:59:54 -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=FFq2SNR8; 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 E61D868CF75; Sun, 26 Nov 2023 21:59:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7681B68CF64 for ; Sun, 26 Nov 2023 21:58:50 +0200 (EET) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-507adc3381cso4815212e87.3 for ; Sun, 26 Nov 2023 11:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028729; x=1701633529; 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=Gzl8qgf/nQDcxKg+bumJZr+Msx3y+VPLJ9rlW+OM8Gg=; b=FFq2SNR87TK0y/gBOfLOymaXjVYGUAKqe7kq7FkTvddw69I/B5rdicCyK9iEOrVPXQ iP7fQuFUHITTqctRgnz6Aez41m4A5qGF3dzBRV0k/KgD63GWxWsJ1uNYpOqRL9h8WkqZ 6fOAhwm7v2iYtJkRAWraaNOEuqQFZo6wnsObX/yRQkf0pyUsjkqrQjhT/XT9KwdWEsIH +LI7Ex/l1A6dCQKG0WZWLP/sVKbV/qJEzWWg1c5W3cVZY7s9ypcDO+1sLcKezdNV/tOQ JPiQnB1Hbm1K8Qdy3/6ixOgiXYiLmJcxi9v3v/BWKSq7vYc5hq6U5wile9IsRjqvWlvU LzvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028729; x=1701633529; 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=Gzl8qgf/nQDcxKg+bumJZr+Msx3y+VPLJ9rlW+OM8Gg=; b=witExIvARzDp1zDHxIKBuuNd9hKmdusAFYGcKXMlIvqhiLPqMhGpWsHIV/XDKUp0ai P+fG/iOmJrNoiOuDzi8E2r7nSnWX9qmBuZMB9aJ0YuyI6JfsgRaemPS+g4nsU2ciZNOM AJxH0tXiqCrYljUHWD1Sdow/wO05092d+UxHVBhZBTS7bkHO2O8Yq+j7LjdzK4hHA6lA kAcQhCaWTNQ7qtl58V1ZM/x7+KxlOniVE09YTPIU9SQgOZ3ZsalegayyGJB5V+w/FdQQ EGI9PWK7Z+y6BywH6h82/6sAM7WwS2D5RtcLFT5ynucoURTyD2vNv6D8G9uQ1/EJHb5t q9qg== X-Gm-Message-State: AOJu0YxljEjlS5IBpXn8dzhwxYsDw/BB+09x8gn6vtVwbuh23ckCbgR/ u9XoniPxH4wGHsS4h0QKHkdmhS1ov5U= X-Received: by 2002:a05:6512:31c6:b0:508:2022:7743 with SMTP id j6-20020a05651231c600b0050820227743mr8610898lfe.2.1701028729444; Sun, 26 Nov 2023 11:58:49 -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.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:49 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:25 +0200 Message-ID: <20231126195838.392467-7-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 06/14] avutil/frame: add helper for adding side data to 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: u7biuW4PuVct Additionally, add an API test to check that the no-duplicates addition works after duplicates have been inserted. --- libavutil/Makefile | 1 + libavutil/frame.c | 18 ++++++ libavutil/frame.h | 20 +++++++ libavutil/tests/side_data_set.c | 97 +++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 ++ tests/ref/fate/side_data_set | 14 +++++ 6 files changed, 154 insertions(+) create mode 100644 libavutil/tests/side_data_set.c create mode 100644 tests/ref/fate/side_data_set diff --git a/libavutil/Makefile b/libavutil/Makefile index 4711f8cde8..c000fa0c7e 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -266,6 +266,7 @@ TESTPROGS = adler32 \ ripemd \ sha \ sha512 \ + side_data_set \ softfloat \ tree \ twofish \ diff --git a/libavutil/frame.c b/libavutil/frame.c index 587e212d1a..9ac3db430f 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -861,6 +861,24 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, return ret; } +AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set, + enum AVFrameSideDataType type, + size_t size, + unsigned int flags) +{ + AVBufferRef *buf = av_buffer_alloc(size); + AVFrameSideData *ret = NULL; + + if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) + remove_side_data(&set->sd, &set->nb_sd, type); + + ret = add_side_data_to_set_from_buf(set, type, buf); + if (!ret) + av_buffer_unref(&buf); + + return ret; +} + AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 4fe9ac9411..093a76e30d 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1065,6 +1065,26 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type); */ void av_frame_side_data_set_uninit(AVFrameSideDataSet *set); +#define AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES (1 << 0) + +/** + * Add a new side data entry to a set. + * + * @param set a set to which the side data should be added + * @param type type of the added side data + * @param size size of the side data + * @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_set_new_entry(AVFrameSideDataSet *set, + enum AVFrameSideDataType type, + size_t size, + unsigned int flags); + /** * @} */ diff --git a/libavutil/tests/side_data_set.c b/libavutil/tests/side_data_set.c new file mode 100644 index 0000000000..820b3aac44 --- /dev/null +++ b/libavutil/tests/side_data_set.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023 Jan Ekström + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "libavutil/frame.c" +#include "libavutil/mastering_display_metadata.h" + +static void print_clls(const AVFrameSideDataSet set) +{ + for (int i = 0; i < set.nb_sd; i++) { + AVFrameSideData *sd = set.sd[i]; + + printf("sd %d, %s", + i, av_frame_side_data_name(sd->type)); + + if (sd->type != AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) { + putchar('\n'); + continue; + } + + printf(": MaxCLL: %u\n", + ((AVContentLightMetadata *)sd->data)->MaxCLL); + } +} + +int main(void) +{ + AVFrameSideDataSet set = { 0 }; + + av_assert0( + av_frame_side_data_set_new_entry( + &set, AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, 0, 0)); + + // test entries in the middle + for (int value = 1; value < 4; value++) { + AVFrameSideData *sd = av_frame_side_data_set_new_entry( + &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + sizeof(AVContentLightMetadata), 0); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = value; + } + + av_assert0( + av_frame_side_data_set_new_entry( + &set, AV_FRAME_DATA_SPHERICAL, 0, 0)); + + // test entries at the end + for (int value = 1; value < 4; value++) { + AVFrameSideData *sd = av_frame_side_data_set_new_entry( + &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + sizeof(AVContentLightMetadata), 0); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = value + 3; + } + + puts("Initial addition results with duplicates:"); + print_clls(set); + + { + AVFrameSideData *sd = av_frame_side_data_set_new_entry( + &set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + sizeof(AVContentLightMetadata), + AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = 1337; + } + + puts("\nFinal state after a single 'no-duplicates' addition:"); + print_clls(set); + + av_frame_side_data_set_uninit(&set); + + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 80153f4395..6864ea9c03 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -148,6 +148,10 @@ FATE_LIBAVUTIL += fate-sha512 fate-sha512: libavutil/tests/sha512$(EXESUF) fate-sha512: CMD = run libavutil/tests/sha512$(EXESUF) +FATE_LIBAVUTIL += fate-side_data_set +fate-side_data_set: libavutil/tests/side_data_set$(EXESUF) +fate-side_data_set: CMD = run libavutil/tests/side_data_set$(EXESUF) + FATE_LIBAVUTIL += fate-tree fate-tree: libavutil/tests/tree$(EXESUF) fate-tree: CMD = run libavutil/tests/tree$(EXESUF) diff --git a/tests/ref/fate/side_data_set b/tests/ref/fate/side_data_set new file mode 100644 index 0000000000..7d8c684d8f --- /dev/null +++ b/tests/ref/fate/side_data_set @@ -0,0 +1,14 @@ +Initial addition results with duplicates: +sd 0, Ambient viewing environment +sd 1, Content light level metadata: MaxCLL: 1 +sd 2, Content light level metadata: MaxCLL: 2 +sd 3, Content light level metadata: MaxCLL: 3 +sd 4, Spherical Mapping +sd 5, Content light level metadata: MaxCLL: 4 +sd 6, Content light level metadata: MaxCLL: 5 +sd 7, Content light level metadata: MaxCLL: 6 + +Final state after a single 'no-duplicates' addition: +sd 0, Ambient viewing environment +sd 1, Spherical Mapping +sd 2, Content light level metadata: MaxCLL: 1337 From patchwork Sun Nov 26 19:58:26 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: 44814 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880004pzb; Sun, 26 Nov 2023 12:00:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJZVF8J6n1PiyB6vGFsdWGf8QLFVVdpxIXFuBzkCHQc9yjDt2S5cneWrb4N/O2MuV+ywi3 X-Received: by 2002:a2e:8244:0:b0:2c5:19ab:726e with SMTP id j4-20020a2e8244000000b002c519ab726emr5662779ljh.47.1701028803726; Sun, 26 Nov 2023 12:00:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028803; cv=none; d=google.com; s=arc-20160816; b=gH6zMAJJ4P4YyFe3qCzkKqMvcPOhi/4gKl02c3CvdQS/F5ZUzTHfWS+AvTAA1AwqMG KuYaWimMWyRmRLxiiAEuRYgsQTRHSxeaTxE3qsEG2dtRi8WA7I9IMp5cVgmv8r2yrmyG +U6qCdfQbMIteXxvUTFZU+UrZyR0ITMgiZyik20b9e7lvo7Pmgyrz61ASpfzYiiVqpf7 J1Orw6n4t4ChOiYiGfO0JOuBQkqzd97uhhx6vrBdoIbek4WV3bMlAeaOTTANVxvyadZC detYBNfrs0UBpAlwDPMNhbXEpXHC6Yy9VW0DTZEpEMVs+hJFgocnGH0jgVqlr4lmZ9kf Nmyw== 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=zVaoIAl3RTJMs/fRqOWbWjKy7Sd89O0F4v/dGT6A9kw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HNnhu/GLTakQ9p/r8Ot2hv74F9o3tFcCh1DA9KqwuYtdH+/F/1gfxE5cW9Dm8rT1fx UxPBkjLSYL3PY3oTTSF/UxvSxFhW/ut6GhPKLNjpHXpneIuWoDUtBVExv6WLNhDWRkQw s4+cye2i0uige0GWXdvU9RgTKR5SkF+7VjKQCZy2sLozEN1UV3v2sNKZXUCWXF8rocXu SUdg2wZ6rsFZrMiS98pwEX77frLhAhmpnEuW7zfD/YhyEHKRaGpMyKlSgbR+0FEhOOFO FduqjFMODuvrBbbXZVmOFK5oeINbLrgyPoSGZdwBLx4jIZ8yYJHFc5ge+VLttIoMyPmc vjmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=SBkVb7LI; 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 l22-20020a170906795600b00a0c3af38c2fsi1649529ejo.229.2023.11.26.12.00.02; Sun, 26 Nov 2023 12:00:03 -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=SBkVb7LI; 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 F0CBC68CF74; Sun, 26 Nov 2023 21:59:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 CA1A868CF67 for ; Sun, 26 Nov 2023 21:58:50 +0200 (EET) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50a6ff9881fso5445573e87.1 for ; Sun, 26 Nov 2023 11:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028730; x=1701633530; 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=IAb3KEQ2ytKMZYTmiBiW6q5rxkfTpwMoskKVs1skQyU=; b=SBkVb7LIeRFsAb7TxzlnaOgoXJBSerqikCyDepl775/ilyysn+pwwiljjQ5ecqL4ts d0BrU+JrwT1ArWUW1nZK6/PP54E1+8Nz6JD54q9Dc7GVQcRJzv5sYwlm05xFpPaQYKiP N++voWmuMXh1MuNOneP6ilz+DRAjxESBJK9S3W/VKb5oJx62pNi0zYW2pczxUem2hRDv iB+xqIS+Nwbb2H10QFKTes0YMw4adT0ej0ztnwowptUv01qrumS07d4CiBVuA8Z4pqhQ vXsRkjgMYVfWQT7Lr0b0gRXeSmHbFfwb/BJ8Pg1fp7Lkhf7DYCIDJk88Wlm4r5My3dle ZKXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028730; x=1701633530; 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=IAb3KEQ2ytKMZYTmiBiW6q5rxkfTpwMoskKVs1skQyU=; b=dgKvIoSb/qeJktu9z/JiY6REjGuuW8Hfru7Iq6hNo4OaEUf388qsjgIfzl5b1xXnVW rk7BjppxMrTDf7bpJmaBPUzx/RalEf9olEogQhP3bBKAZKLcleT86g3sC0fNdcR0qBBu tlocvP9CS60KAI+/yRv7vQYRAE/hDQeXajHFoj9DdCGqLd3oPw3C4zbYcl/Vejlzuk5c D/MGvKcRDuM39VcLb+/PTpAit9C44Voulc6knj4IM84YyZtRXYhWDf+SGFvlhumd/bQd fFeabcVWXcVTcLetKN7SUejgppOdspXQK+mUhqEl74IjL3Opd1/3h2pik7zi9miCMhSr eKdA== X-Gm-Message-State: AOJu0YxwZepBOwH1J3u3lVmcZIBnt/XjuLT7uDXYRYYfHz0J0IEl74x1 ZPfn6tmR55yVhlD3S+Emy/WsoRYIlfs= X-Received: by 2002:ac2:55a5:0:b0:507:9b70:1f0e with SMTP id y5-20020ac255a5000000b005079b701f0emr5245568lfg.24.1701028729846; Sun, 26 Nov 2023 11:58:49 -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.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:49 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:26 +0200 Message-ID: <20231126195838.392467-8-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 07/14] avutil/frame: add helper for adding existing side data to 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: MLCRw4MMbBxM --- libavutil/frame.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ libavutil/frame.h | 16 +++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 9ac3db430f..e42d9cb758 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -110,6 +110,24 @@ static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, } } +static void remove_side_data_by_entry(AVFrameSideData ***sd, + int *nb_side_data, + const AVFrameSideData *target) +{ + for (int i = *nb_side_data - 1; i >= 0; i--) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry != target) + continue; + + free_side_data(&entry); + + ((*sd)[i]) = ((*sd)[*nb_side_data - 1]); + (*nb_side_data)--; + + return; + } +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); @@ -879,6 +897,38 @@ AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set, return ret; } +int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst, + const AVFrameSideData *src, + unsigned int flags) +{ + if (!dst || !src) + return AVERROR(EINVAL); + + { + AVBufferRef *buf = av_buffer_ref(src->buf); + AVFrameSideData *sd_dst = NULL; + + if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) + remove_side_data(&dst->sd, &dst->nb_sd, src->type); + + sd_dst = add_side_data_to_set_from_buf(dst, src->type, buf); + if (!sd_dst) { + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + { + int ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0); + if (ret < 0) { + remove_side_data_by_entry(&dst->sd, &dst->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 093a76e30d..9295c868ef 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1085,6 +1085,22 @@ AVFrameSideData *av_frame_side_data_set_new_entry(AVFrameSideDataSet *set, size_t size, unsigned int flags); +/** + * Add a new side data entry to a set based on existing side data. + * + * @param dst a set to which the side data should be added + * @param src side data which should be added to the set + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return negative error code on failure, >=0 on success. 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. + */ +int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst, + const AVFrameSideData *src, + unsigned int flags); + /** * @} */ From patchwork Sun Nov 26 19:58:27 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: 44815 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880100pzb; Sun, 26 Nov 2023 12:00:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IECz6HNxYxcZ0GZlDGDjrgqnuN939qj8qT31hQ7rxai1LEPDD3GUDPLA2Mj3YAxp2GUy1Bq X-Received: by 2002:a05:6402:345:b0:54a:f72d:38ba with SMTP id r5-20020a056402034500b0054af72d38bamr6275573edw.9.1701028812107; Sun, 26 Nov 2023 12:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028812; cv=none; d=google.com; s=arc-20160816; b=KRgC1jX7fsCFlqswxtC0H6Owsj03nt24MYYwZRgwzH7ujeuiLMszoeNvbCdeEDSJre 38P+sgHveRYq7nWA7pKGZmbCjRMoxugavKzdGjEKTCmIqjOOQIUNFQbBQQWNkZXC/2OP THBx83dKJZthwWUvSJ29gpBGaisaQmIyTLip8s8JDktGXN5YhCg4ylHwopOASCnKKj8Q 2F5HlVvwGUYwiQvniHZqc/cdr03pDORcaRMndbqQGQVXUKpjyVCmUZ/M39nZ8l62mcc3 QF4gXfdwLGONi/c0iYlAV144ktXxUv7EhoKj5nsGmMRX8QziXTMI9YSeT4uOfBESlVsJ A4TA== 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=A/N2ham5LYv6TRO3s/kiJ9ncmCiQU94K7C17dgbPtJ4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HxLR4yg5fVB47GZK35XNitJ9H+HurHpMd10OdSH5LYy3A1JKxvK3xl69pzgACy0qFZ JvmFoXiF0pjd14pdjNp+zdtPS41xVd1nSZOZMAcNittOUZvk9ZTSEHnBkw3JcV02qtVd v/AST6cZtfLd5hWQZVqjNHWuCUDd+FV7udlzD+CpP1YbyIIHmRJWDFWH/8y+JvOclVy8 0+NygKv2cP8W6s08ATkfz8woo+/ub9eBFRImv6j+y8xJC9/eXZxnqTBJj2ss7qlVfQFD sT67r6MbXj03Txj5sQYMBvZTzW6ygA22p6ZiDTdKb9YBLsJsqSDHi3FRkqjqpk1hP0T8 xJrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=OqdxGUlg; 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 22-20020a508e16000000b0054b4f63354dsi816635edw.493.2023.11.26.12.00.11; Sun, 26 Nov 2023 12:00:12 -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=OqdxGUlg; 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 EA01168CF6D; Sun, 26 Nov 2023 21:59:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E2CF68CC52 for ; Sun, 26 Nov 2023 21:58:51 +0200 (EET) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-507a3b8b113so4660301e87.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=1701028730; x=1701633530; 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=pVW+jxnfSCMkq8XoYTNyGRPHUvZX7IQXabIPzeH8S2w=; b=OqdxGUlgOuDmsfX+f9Rg/Om5r3eORSUD9CHJyAFaWEBcWp7Vy09ORGlCiyE4oNBkOc R809e6FSd/BOjhp4mCzICVbdK9cfmkDiQjtasR8Mjf10SqNv96wJfR1pIYMwcZ2NvNSV 1vLjfNP38X7nO4H/YpOTRmEdG0EBomKOgOfJ1FPAGRA7LiU0GsA0ldPWKYn2z31aAehj MDMDojcWTAc5OWAndaGMvfE0lz+aXBeJYHlaqdX4AG46OWOJULs2A0mpWph2pUgGbhPJ zh7VL5Ks4UFHc+RqmIx5tmowIpK2B6yQUr7h9GKqTLCvFDJ5HtxrdSKo6LwEO68TMLbn 5ODQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028730; x=1701633530; 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=pVW+jxnfSCMkq8XoYTNyGRPHUvZX7IQXabIPzeH8S2w=; b=sO8MFrikBpN1DjwEinp0Ns0waMwAoCs69l6s9h7qeIm985cY1iOSvwOrjQgoxKotl9 rOjMcfQggdQuTCEwOWVIWHiu3PQXakaNFjhnFeFEF7/IUl0r4ypoWqhhtHZKBvzCyVa6 VtzoHRpgCvCo3XE8CeycHMLw9igzhuGYe3CVCXwM52XQ1riaVRlxxWkRK+9oOlFkU5/i gfjOPXEzhyB99xxJr1wTzTaIM76S4Welp2qgByNeFv0KQzYymnDsyvTcffk5zaAEDd2u 2P0guujCQqU8TfoNBvGejAJKlwtKaHEyA0N9V/zPcuWXALI4Py3z8MiASzTzzNKYhS3V 33rA== X-Gm-Message-State: AOJu0YxSEck1eaKmXT12XlDrloTRlFiuuofTVsJD4ocNxyv9Smsrv31B gUHF8B6Kqf6kPtZPPqk8lDseRRhslS0= X-Received: by 2002:a05:6512:e88:b0:509:46fe:b002 with SMTP id bi8-20020a0565120e8800b0050946feb002mr3856646lfb.5.1701028730302; Sun, 26 Nov 2023 11:58:50 -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.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:49 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:27 +0200 Message-ID: <20231126195838.392467-9-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 08/14] avutil/frame: add helper for getting side data from 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: ieqvW/Grb3XL --- libavutil/frame.c | 22 +++++++++++++++++----- libavutil/frame.h | 12 ++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index e42d9cb758..e4004daa4b 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -929,16 +929,28 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst, } } -AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, - enum AVFrameSideDataType type) +AVFrameSideData *av_frame_side_data_set_get_entry(const AVFrameSideDataSet set, + enum AVFrameSideDataType type) { - for (int i = 0; i < frame->nb_side_data; i++) { - if (frame->side_data[i]->type == type) - return frame->side_data[i]; + for (int i = 0; i < set.nb_sd; i++) { + if (set.sd[i]->type == type) + return set.sd[i]; } return NULL; } +AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, + enum AVFrameSideDataType type) +{ + return av_frame_side_data_set_get_entry( + (const AVFrameSideDataSet){ + .sd = frame->side_data, + .nb_sd = frame->nb_side_data + }, + type + ); +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { int planes; diff --git a/libavutil/frame.h b/libavutil/frame.h index 9295c868ef..e8517bf6ad 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1101,6 +1101,18 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst, const AVFrameSideData *src, unsigned int flags); +/** + * Get a side data entry of a specific type from a set. + * + * @param set the set from which side data should be queried from + * @param type type of side data to be queried + * + * @return a pointer to the side data of a given type on success, NULL if there + * is no side data with such type in this set. + */ +AVFrameSideData *av_frame_side_data_set_get_entry(const AVFrameSideDataSet set, + enum AVFrameSideDataType type); + /** * @} */ From patchwork Sun Nov 26 19:58:28 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: 44816 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880198pzb; Sun, 26 Nov 2023 12:00:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiCmzNyONovO67HNrxRQBNwHKXMeh4drYSC5c1sgNCNm4vuSKZFzOBk6UZRlYCrf61F3E8 X-Received: by 2002:ac2:5319:0:b0:50b:aee8:6e87 with SMTP id c25-20020ac25319000000b0050baee86e87mr1063517lfh.15.1701028820580; Sun, 26 Nov 2023 12:00:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028820; cv=none; d=google.com; s=arc-20160816; b=B1XWqOowdyNlnh1d9uXjB/2OhJqPi1pSf+wALZeB92kd0K4h+4kkLVWaoYRMOHbAO6 z0dDVHxPB7yBrXzfm+t6GPayQur5e+pPMpwPDnkWjtQhVXRB79aKk6eKUnPn2IyZIppp GqemcCzVx1/mywD/k6XtlFsQyjskFSTJfEWTX8D/cOcm1DkzN6pLo+RbHFLFBiVrWbGR eSbekpQrCuQ20chUX78W1i7EI+LYy4w+pJ8GO3Gd7ARfJCx1PMvFMlNJJADc0drcMsKe j3Czb6CTQrX8c5NktH9ly4cjvSpq4HM52R6BSRqUVrv2bRfUbsS7Z1YMMzOGN6iJ02je t7eQ== 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=ywLkwqzSZQSZEjO++eOrObCtqfN4GPS5VloxjGDO3Ok=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=0bRPZYJ9OwBa6Vg3bEx8+0dW+JIwm78en0ESOMUgAfOJwe32okmR9LqUtr/TQmS4Od DUqlWDK9kC8+RLVknIq9jppYlo2vX6sjM9huxc4PGfUufu+ebMj/JGUwucw7zk9N14Vm OPCHsWW7XZHAccGI1hfuooOuCkgs7q/pTpF64BOmLMCWMgiVfw7t2HEIqRkepT6xLBub edk+WyFO4doWnyVEkWRbk/KZ2xRc0IVQliNWiWEqbUR4VOxIIn52haeY4zXN9K2q8oz5 hdQmm+sgpxTu2ZOBEXlrlLZfTnFrbbeWlq5ihwUWrl0frlWPx7jCgAabE4qMD+jIhupl LxTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=Fj8qpTzP; 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 jx21-20020a170906ca5500b0098d861f6513si4121411ejb.68.2023.11.26.12.00.20; Sun, 26 Nov 2023 12:00:20 -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=Fj8qpTzP; 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 05CB368CF9E; Sun, 26 Nov 2023 21:59:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 8E37568CF6B for ; Sun, 26 Nov 2023 21:58:51 +0200 (EET) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5079f3f3d7aso5133475e87.1 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=mOAdXU6pUlQr4xlr7mRlEdjaMVaghWl1VjLO20IsxD8=; b=Fj8qpTzP+qOsY0LB3ygKM6EY5ofOmN6E34dgzaxYeZomta6+j6odWsqciQJj7lqzXR aXB3hgnZUeJbOSbGxhEfHdHmgjoWMu07KTNSiF07dzplx0xCrtO21S6lowG8U1rQK/UU LB9873EcN3G43CQEtXIZ2rXHGp19e1X5dZTJdZb+CXzQSJtc5dUPlIb5OPXjRgahBQhv wf+k2kYuJRAu/EW4nrJxj4jDIXBb7ZJ3w0t4qMdyi42z+j+i9BB2UlbxpoxyIIibIkZS YXpj2B9+c8g/RLu+ptzuBWK/qryhd0ZuwVF4JTH5Oj8y8J2GJPT3EDzSwg4rvSz9+kWE iVuQ== 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=mOAdXU6pUlQr4xlr7mRlEdjaMVaghWl1VjLO20IsxD8=; b=mSiZEkUowi+HDa5f0nN/R8g8NG6Tz96YiRDEwKapl3YfjoUd3FIVMLxbTJ8wPshYIO VJUozOfMRlOTNO88JZdBtwTyBZQ9fD9RUilp94w7HUT4VJBzHuOVZETNRdyBOrVAMPs+ kuZJaP5H152+YU+g8GfApAUox6ifdIlpUN+76DqmqvOaMyxXEtx4U6cjvDrtXWvPV/qY cOAE+0bv5OJguXZQKj6Nl3+Lx+jGOiQtQT6YS9+wMSNMnGo5Ug2CiAsY/jTOCcBbFE6M 81sc/pML9ywH/5G3m+HSaPveuHA9tXc6xyTY8MpqJSoY9y3JPVeNxLrS2uGGFSrZeg0i g+hw== X-Gm-Message-State: AOJu0YzgbXMPBnNBA5w2BwEwl/V1zOGlCOF3P6dBox8zMcffPysKNLfx H/2VtHm8ygW3oXd0L/SGQiIVjHWJNcM= X-Received: by 2002:a05:6512:3d91:b0:50a:a6e2:ae73 with SMTP id k17-20020a0565123d9100b0050aa6e2ae73mr3678576lfv.44.1701028730707; Sun, 26 Nov 2023 11:58:50 -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:28 +0200 Message-ID: <20231126195838.392467-10-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 09/14] avcodec: add side data set to AVCodecContext 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: nHRVA8NcsfGg This allows configuring an encoder by using AVFrameSideData. --- libavcodec/avcodec.h | 7 +++++++ libavcodec/options.c | 1 + 2 files changed, 8 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7fb44e28f4..0c1a8ade49 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2116,6 +2116,13 @@ typedef struct AVCodecContext { * an error. */ int64_t frame_num; + + /** + * Set containing static side data, such as HDR10 CLL / MDCV structures. + * - encoding: set by user + * - decoding: unused + */ + AVFrameSideDataSet frame_sd_set; } AVCodecContext; /** diff --git a/libavcodec/options.c b/libavcodec/options.c index a9b35ee1c3..e42a29e834 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -180,6 +180,7 @@ void avcodec_free_context(AVCodecContext **pavctx) av_freep(&avctx->inter_matrix); av_freep(&avctx->rc_override); av_channel_layout_uninit(&avctx->ch_layout); + av_frame_side_data_set_uninit(&avctx->frame_sd_set); av_freep(pavctx); } 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); + /** * @} */ From patchwork Sun Nov 26 19:58:30 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: 44818 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880426pzb; Sun, 26 Nov 2023 12:00:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IETJ7Se+AgxP7GXQh6LjOrTDSYSQqlDbnH6Wwuh75LSzvXdpgXXxTZcrB46N04OdogAgkh0 X-Received: by 2002:a17:907:11c2:b0:a0f:78bc:649a with SMTP id va2-20020a17090711c200b00a0f78bc649amr758790ejb.74.1701028836995; Sun, 26 Nov 2023 12:00:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028836; cv=none; d=google.com; s=arc-20160816; b=ybKgzIgSw1velt3Svapp6xtwlnqdOHCpyey6NnEOvAL7FCPNrqM+GKYj8G7ht72LFT xrilAWZf4/+/KjOvttANcuobb/zdDaM3DvmjkNojbVp1mFsHZweTN6rH019BasRrZ2La ekKUWL2SKU9Ia3jMvp0NzWHLKqJgtcohQN0XOPJheDIztUF1bBdLYkBtqJ9swRPPlF96 M3aYeCGxtr37A/iBxGpctNdjTiHkzzTx9eXtIQi0yQ9gR1nM3ApteK/nGHnmqf9NeVHz husHhaUveDV8P/ssm2aj/MHid0obGIpq0j62swm8WETv+oofEHYa5PS84uM28tadDEmL c8WA== 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=dyNz1KgCBlrol+pa9hfhwgIyoycj4rcUrSGgdhJ92pU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=a0srow8G/qD8i6D200dQbGYJCGSjTsXovyI3AWsfCe9ij42cz9EjMY/erZgwTZddNb fFXJUBrYoGVkziP8CuLeEMyCG+s8UTv16Fr2y2BRGWvKy/DfkOSAlwAA/9ciSoCe0fgP 96plEJqyEMarb9QsnhyyPdNaVgF5ZXraevydllfOB775xr0z1j5m1l5Eyqixx0Dc+zlT MYcaiL9njtqJyB01ajwYDxasteh7WiI4VR+ggfPIGrDfJMBgmFR0vBbnHcbQfpb4zgDe Tw8l79FcJoLjLSpGPGEe/kUTIfIJREasKiT16xWH8NPz/JElMl1pNCZbLndNvj1vCWGh JYgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=QeIAE2EP; 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 qb34-20020a1709077ea200b00a097e421224si3200194ejc.748.2023.11.26.12.00.36; Sun, 26 Nov 2023 12:00:36 -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=QeIAE2EP; 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 4B6AC68CFA6; Sun, 26 Nov 2023 21:59:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7204F68CF71 for ; Sun, 26 Nov 2023 21:58:52 +0200 (EET) Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-507975d34e8so4931687e87.1 for ; Sun, 26 Nov 2023 11:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028732; x=1701633532; 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=CodGVD4u1YPkLhfLyC3RS6jO6M4nc9OHJLsgqTxmWqI=; b=QeIAE2EPe/muubAzXPYEHy4a/BAS2ipcrW7wP4+0WCd73C4vwY0BfAoLxX9PQx9OXx 9p1XyJSBSe8yXA59h7yyKynUqCLeU3H3FB/AtUaoZ0+xLqzUd14UngFZGhTaL2G+yD6n 6kmNv+4nz/OS8izru3T+e5d+n0oq+NQZKrAvMynmS7n7QBGizVHBKbEpi5+CAmsqreHv Rs6dhivvpBwF6aanesG6IoUMZMJCKuADEjClGZDdkWfaD1gKGvpTV2ggh3HM32xUnypW 9ZAmiIblNGXxUPLMiofcm42Z6gjkm4S0ehelPpL5frrYmQ3CawGl1TFPzd9wMNfsZlYz JlrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028732; x=1701633532; 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=CodGVD4u1YPkLhfLyC3RS6jO6M4nc9OHJLsgqTxmWqI=; b=BK2f9REChUzYUpHWTKl3qBryvw3dWl6tFqBUfBvKBNeoSVoepI5kPQ70+4o2u8znNA NgzXH/fWwBIxMOH4lwiiCWXsbHo0cU4o35ARXNo3jiCqvj9GtWHBibl0EyXPFxejBYe/ 43fQLfYDLQqnb2unHL7nHtUpiFlsVoHzvOJBGZ3Su0L1nlw+ynt3MybI7SN3vy+26IYu 8IRZGykO7tjQ5zLra42TGdIu1Ms9H4ajCh3qpwA8b8Q4mKR30OTnY7aUQ7r400qPgXKO cxCiPhH9VgYsBh9/gSROn4/v3ewLkEfbVGS670k6ueYXpHfjCBqy9jjjbaPfKOflYGvX Ni1A== X-Gm-Message-State: AOJu0YwksSKgot9/Ld+HVcqow7dH33sgU9KxFz/RkRiZzaJ7292bhZfi 9EXqGS0GRvZ0iWwYR8of0H0IP5nUgRM= X-Received: by 2002:a05:6512:3f1e:b0:507:9803:ff8b with SMTP id y30-20020a0565123f1e00b005079803ff8bmr7357945lfa.44.1701028731665; 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.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:51 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:30 +0200 Message-ID: <20231126195838.392467-12-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 11/14] ffmpeg: pass first video AVFrame's side data to encoder 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: mtzpWV2zhweS This enables further configuration of output based on the results of input decoding and filtering in a similar manner as the color information. --- fftools/ffmpeg_enc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index fa4539664f..8ec9cb7cd5 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -239,6 +239,19 @@ int enc_open(OutputStream *ost, const AVFrame *frame) enc_ctx->colorspace = frame->colorspace; enc_ctx->chroma_sample_location = frame->chroma_location; + ret = avcodec_configure_side_data( + enc_ctx, + &(const AVFrameSideDataSet){ + .sd = frame->side_data, + .nb_sd = frame->nb_side_data + }, + AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: %s!\n", + av_err2str(ret)); + return ret; + } + if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) || (frame->flags & AV_FRAME_FLAG_INTERLACED) #if FFMPEG_OPT_TOP From patchwork Sun Nov 26 19:58:31 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: 44819 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880509pzb; Sun, 26 Nov 2023 12:00:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFASLl+j2A9wlxpy077io/Oifd25xPxJAaVrPQhsbB0bTbifzmqBPbdnHgZfibAcMDA6Pkv X-Received: by 2002:a17:906:20de:b0:a01:811c:ce9 with SMTP id c30-20020a17090620de00b00a01811c0ce9mr7489442ejc.0.1701028845603; Sun, 26 Nov 2023 12:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028845; cv=none; d=google.com; s=arc-20160816; b=RvsK7pwGtw7lCzX48swF0mposUyj/RNw07TUbNp6idAU+5FI+V0DVdYz0OCGBh8k5q jiWr8nzAzUNQFeJqEMPwdejn4iQ+4hczp63Qm+XDF5lEAfPmSt0ndVhgsQgo6jN9vMyV cWDutc1OhEP64nb0hYAx5rJ6HFuuK2tiRxDAwNlFBYSf1iCG6sXI1v9SACa29KnJe/CJ yLM7l4FBqvvvaOai3Jl6K5gn6opkIv3fQMpnFBX0qrKe4ijuUUJOb0Su0LM9d7SgS9ID nOZW3lz/Jqr5LbIyFUe61C/0rqxLP5GOa8Y6laGmXWWO4hyYW+Z/HaZ5SBc7uwFJmAyN 3o4A== 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=vYChFm9xkIyQM1quWXJzjDJaaV3yHWHpua0BvsGmdag=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=dagfsVh1m+9Ds0Sg2z7BsuXyjINJppGlrvwTDQ1+iCKDbl97U4X4kwK3IvxHeYnWDP LRqVwHNCIi3bEQZBw65F6klfSC6lSsGGTqc2cnAh/bD1ZmRst8l8H9OQQ93UxEj/YNtc TNjHkVxY70ZTaBmBEIcigMnU/sqeP8iE6vLtSP4m/+6t6f44gmpJYt0w1VglCYKdthXq a5IHB+x2wTR9BEsqQmac7TNdsS3eMCHr74ApvqUMSPmQGQEbOkWOEm8Jjl7sR0kLBOAB 2zAY89ew5yZhqEIrP9gzgZ5uyNXfrD6V4nDqUEJgze3iRN1a6Qdi/vfJ5xV9a1QK+nA+ ORAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=nZ09mlta; 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 y5-20020a170906470500b009ddf665acd9si4383504ejq.433.2023.11.26.12.00.45; Sun, 26 Nov 2023 12:00:45 -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=nZ09mlta; 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 716CD68CFAC; Sun, 26 Nov 2023 21:59:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4869968CF7A for ; Sun, 26 Nov 2023 21:58:53 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-50a6ff9881fso5445600e87.1 for ; Sun, 26 Nov 2023 11:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028732; x=1701633532; 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=IGcY6hYBppdVSgVcaqqz1PA893cDP1FvRfZ56oPpRFM=; b=nZ09mltaAKnztecnMbvexmtkRsPxfvHPYjIlKrw0U6JhXFU6bbyEg7SlBrv1t8hkrF YVEhDsNskZdoWrcFwRrB0LRNvpibcggvp44CRW84btU7pyQzfhWGyc1/sGHDjIDUgSm2 3PoriyPMkykRKn4vEp70PZG/Abn6FqKBz2HAG8jVBalKiljYDuBL/xc2VWPu/M6ISAGu jlFP3xlEBjvfxhlSECpekxPD7ECawVXI/4UroeV7iQ+PSMT0dS3hqCadRrR6FuwgsFkI RS+FVlusJ5F3+eH2DhtX8eQ5bX1CEzIbPq3sgcLG2EB1evaD0DF8mds4D40ZZApMcfut ww8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028732; x=1701633532; 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=IGcY6hYBppdVSgVcaqqz1PA893cDP1FvRfZ56oPpRFM=; b=STMt9cjnubW6nYHFhiMLkIDZkXpoWmjfqadP3QRuxW2//1FsHMaQB1XYqZ9TgShR2v AC3gGzTestXM6r6x+hSMYTbUmArxweucbqbyOdKLqoSXB+i0Bl+vNaPBhc9CS0dLaZqV +lUix/RRS8YOf8QelS2M54mbB6bvqOGG3Wqr9U2i/H4LrynRmI0d67/Yv092Y62aFa/q trPG+1PkdSIJi2RBA5pEO22SnH4wpGOFnYdMoHr2utM0tiWG2XGJuqjviylLnHvPhZrK wvRGzOrgjaplms9YmO1wXwEofqU7/zqkOnIJnxVHGhjJ393h5kcG8vE3R6snqMZIcCno 0y5Q== X-Gm-Message-State: AOJu0YzMWlZFCYAFx6xdG6hjiRcezbzHfFlXKrgCL25s6B0k/zrac1qO cgitBTHznIKH1RGJuWyQUHMYmYrFKpk= X-Received: by 2002:a05:6512:3a8f:b0:50b:ac34:142f with SMTP id q15-20020a0565123a8f00b0050bac34142fmr2961355lfu.41.1701028732198; Sun, 26 Nov 2023 11:58:52 -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.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:51 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:31 +0200 Message-ID: <20231126195838.392467-13-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 12/14] avcodec/libsvtav1: add support for writing out CLL and MDCV 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: mKrfq+rNOFFu These two were added in 28e23d7f348c78d49a726c7469f9d4e38edec341 and 3558c1f2e97455e0b89edef31b9a72ab7fa30550 for version 0.9.0 of SVT-AV1, which is also our minimum requirement right now. In other words, no additional version limiting conditions seem to be required. Additionally, add a FATE test which verifies that pass-through of the MDCV/CLL side data is working during encoding. --- libavcodec/libsvtav1.c | 67 ++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 +++ tests/ref/fate/libsvtav1-hdr10 | 14 +++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/ref/fate/libsvtav1-hdr10 diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 862192945b..ee75570c00 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -27,6 +27,8 @@ #include "libavutil/common.h" #include "libavutil/frame.h" #include "libavutil/imgutils.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/avassert.h" @@ -146,6 +148,69 @@ static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc) } +static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst, + const AVMasteringDisplayMetadata *mdcv) +{ + if (mdcv->has_primaries) { + const struct EbSvtAv1ChromaPoints *const points[] = { + &dst->r, + &dst->g, + &dst->b, + }; + + for (int i = 0; i < 3; i++) { + const struct EbSvtAv1ChromaPoints *dst = points[i]; + const AVRational *src = mdcv->display_primaries[i]; + + AV_WB16(&dst->x, + av_rescale_q(1, src[0], (AVRational){ 1, (1 << 16) })); + AV_WB16(&dst->y, + av_rescale_q(1, src[1], (AVRational){ 1, (1 << 16) })); + } + + AV_WB16(&dst->white_point.x, + av_rescale_q(1, mdcv->white_point[0], + (AVRational){ 1, (1 << 16) })); + AV_WB16(&dst->white_point.y, + av_rescale_q(1, mdcv->white_point[1], + (AVRational){ 1, (1 << 16) })); + } + + if (mdcv->has_luminance) { + AV_WB32(&dst->max_luma, + av_rescale_q(1, mdcv->max_luminance, + (AVRational){ 1, (1 << 8) })); + AV_WB32(&dst->min_luma, + av_rescale_q(1, mdcv->min_luminance, + (AVRational){ 1, (1 << 14) })); + } +} + +static void handle_side_data(AVCodecContext *avctx, + EbSvtAv1EncConfiguration *param) +{ + const AVFrameSideDataSet set = avctx->frame_sd_set; + const AVFrameSideData *cll_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + AV_WB16(¶m->content_light_level.max_cll, cll->MaxCLL); + AV_WB16(¶m->content_light_level.max_fall, cll->MaxFALL); + } + + if (mdcv_sd) { + handle_mdcv(¶m->mastering_display, + (AVMasteringDisplayMetadata *)mdcv_sd->data); + } +} + static int config_enc_params(EbSvtAv1EncConfiguration *param, AVCodecContext *avctx) { @@ -280,6 +345,8 @@ FF_ENABLE_DEPRECATION_WARNINGS /* 2 = IDR, closed GOP, 1 = CRA, open GOP */ param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1; + handle_side_data(avctx, param); + #if SVT_AV1_CHECK_VERSION(0, 9, 1) while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) { EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value); diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 7eabebcc51..d787941c16 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -2,5 +2,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 H264, MOV, H264_DEMUXER) += fate-libx26 fate-libx264-simple: CMD = enc_external $(TARGET_SAMPLES)/h264-conformance/BA1_Sony_D.jsv \ mp4 "-c:v libx264" "-show_entries frame=width,height,pix_fmt,pts,pkt_dts -of flat" +# test for SVT-AV1 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBSVTAV1 HEVC, MOV, HEVC_DEMUXER LIBDAV1D_DECODER) += fate-libsvtav1-hdr10 +fate-libsvtav1-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libsvtav1" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libsvtav1-hdr10 b/tests/ref/fate/libsvtav1-hdr10 new file mode 100644 index 0000000000..6f0d34903b --- /dev/null +++ b/tests/ref/fate/libsvtav1-hdr10 @@ -0,0 +1,14 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.0.red_x="17367/65536" +frames.frame.0.side_data_list.side_data.0.red_y="45220/65536" +frames.frame.0.side_data_list.side_data.0.green_x="9830/65536" +frames.frame.0.side_data_list.side_data.0.green_y="3932/65536" +frames.frame.0.side_data_list.side_data.0.blue_x="44564/65536" +frames.frame.0.side_data_list.side_data.0.blue_y="20972/65536" +frames.frame.0.side_data_list.side_data.0.white_point_x="20493/65536" +frames.frame.0.side_data_list.side_data.0.white_point_y="21561/65536" +frames.frame.0.side_data_list.side_data.0.min_luminance="82/16384" +frames.frame.0.side_data_list.side_data.0.max_luminance="256000/256" +frames.frame.0.side_data_list.side_data.1.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.1.max_content=1000 +frames.frame.0.side_data_list.side_data.1.max_average=200 From patchwork Sun Nov 26 19:58:32 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: 44820 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880627pzb; Sun, 26 Nov 2023 12:00:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIUpM/7IgJ0B3/TzlZOv3PiGVAJvT+RPaeY1bQVH7qC21xi1WF9ef/rNFDG52jxs3r3cqQ X-Received: by 2002:a17:907:3e1c:b0:a04:bc39:c1c7 with SMTP id hp28-20020a1709073e1c00b00a04bc39c1c7mr7523222ejc.36.1701028854122; Sun, 26 Nov 2023 12:00:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028854; cv=none; d=google.com; s=arc-20160816; b=FZGBAUjHyzJnETeGczNyIY2a6m5gfNzEcSdnC4CuWYtpwrvSnS/gmXD1KrYmJHqLvR 6W/yQ9yYRjhRZsZM9SS8Bm3QDHMV/JkwkFx4Rw5F+RCFmXgy4xX5j5CghpB5GTclOS/6 jOndmCSi+9zTUCW8EjD22aQibUwHN7mSV16RPKG/P6gqpezbde/xHIp+1mR8XJ7AeqXX TDeWEuzNTsgWCdMAeWdRAGzqhB2LgSkoN8gKSoh7izlgGbevrnxhk2GzCNNa8pJnl5GR 6ajUuegncVJViIFaDBP4xq9LGWjLVF7sspsTmMPN9KZSKwxgW2fIAJ6DxS4enbtlN/Lp a6lA== 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=wiqdhrFYfLAn1P0+Jt+oSuK5wc25wM6GLIxaFGWOs0E=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=hJpXOhSN90tsPRNT3ZXP2CzCPHJVtfzmtabNJiHfyZ+DzPfsNA31bBAkDZzk/PpbXa 50gIPbm881eAeSuR6xHCqNgnCq47ht5HY9TQMZX/aFVN3z/iHlvmuNmC4RHdYDtcP12k 0daqCJXZ0NGnVdEJd2Jgcs3kNwPfFcU+v5tZV0ZPE5lVJwKNItWGc4kH8rSj7sS74f3T 6MfTJs7t0Uuu7s6OeCek8ug08Az6SSylUR5Ibjlum2ls495WYZEHklk6gRkTLCRhiph+ u9JoI9sSqrTukpwxDa9BQOjdJ8qCmXwcUh3nZJHYE17Qed7kzO75vPU3I369+XMMbmb0 2XLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=k7qMizNp; 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 o18-20020a17090611d200b00a02225edf60si3980156eja.176.2023.11.26.12.00.53; Sun, 26 Nov 2023 12:00:54 -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=k7qMizNp; 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 870DF68CFB3; Sun, 26 Nov 2023 21:59:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7F5A768CF84 for ; Sun, 26 Nov 2023 21:58:53 +0200 (EET) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5098e423ba2so5098602e87.2 for ; Sun, 26 Nov 2023 11:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028733; x=1701633533; 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=c5Ekev3VckQC9L/y8VxI7toL0nFKvSsBnF6hb7CZw6k=; b=k7qMizNpVPSvzVFFNakErh9/Qcx+1P8RCQpho5O0idzV0JpcVWYMiWHE2AAs9TFZcz ZFTdwPA62azmrA3eUkdH4w5tRPdMntRYiITHXS+4jlXHH0V+1sLnUQ7YFVgxnTuU91bW lbBO1VFZztNzKQNZE0xzPCwg/Q8RL+tmrAts0UB/D9aewQKNw6V2UR77DOBLuyWKk8jt jyS7e2RNYEW3kDxl4CNtJlnRAGx5taHC1VNFQtYgpQQjpzgOyKG64Z+xhsXOLLbg10eD 4kd4nyumuMnTpkBkHB0P4Z+1Ytm7rvxx72OrXFUwtYd3BRcmB0U9vAkP3e8cdGsRfgAn W1Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028733; x=1701633533; 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=c5Ekev3VckQC9L/y8VxI7toL0nFKvSsBnF6hb7CZw6k=; b=dQp5Uh9QjiqYPwZu65gFRz8wdvX2DjwuZmTa1d/RVjCERY5hJ8ASgpbfYXzMY6bWCb MnX4PhqRDXJJv8UmAuhyruPu11N0VJQnqKayQ02FGUclT0I+WtvTADDbH2vA3RCq6rnD fiZZ1Li2v0JjBus8by1GC3DX8bLAaf5VBPZp7mcJDJCkZu4nM4Go8laqAKMb/vtLmk56 +9lOj/Z2Qw9thJF6rPppsEYXUvoMy2XwY6BZClrUA89QXLwdXcB5r98SDg5Vxp6LsJfv yQ5tRLtPmmJb8iIxm5ATGRHJYADaIYRudmhA4g4ihuZTDJDH8LLX0JbCUa7rJ48ccVIp q12Q== X-Gm-Message-State: AOJu0YyuAAUrw1o4Xz2yCvAnz1SlVOXxz33hP6aqyx6ZyQetUfs/I4U1 hoY3kyWGpcYQuSiglMxocjp5vZ007dU= X-Received: by 2002:a05:6512:ad1:b0:509:46ff:6e57 with SMTP id n17-20020a0565120ad100b0050946ff6e57mr7812587lfu.8.1701028732666; Sun, 26 Nov 2023 11:58:52 -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.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:52 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:32 +0200 Message-ID: <20231126195838.392467-14-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 13/14] avcodec/libx264: add support for writing out CLL and MDCV 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: nJ2N0cMX+xoo Both of these two structures were first available with X264_BUILD 163, so make relevant functionality conditional on the version being at least such. Keep handle_side_data available in all cases as this way X264_init does not require additional version based conditions within it. Finally, add a FATE test which verifies that pass-through of the MDCV/CLL side data is working during encoding. --- configure | 2 + libavcodec/libx264.c | 78 ++++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 +++ tests/ref/fate/libx264-hdr10 | 15 +++++++ 4 files changed, 100 insertions(+) create mode 100644 tests/ref/fate/libx264-hdr10 diff --git a/configure b/configure index 838e627084..1b51fa7767 100755 --- a/configure +++ b/configure @@ -2514,6 +2514,7 @@ CONFIG_EXTRA=" jpegtables lgplv3 libx262 + libx264_hdr10 llauddsp llviddsp llvidencdsp @@ -6873,6 +6874,7 @@ enabled libx264 && require_pkg_config libx264 x264 "stdint.h x264.h" x require_cpp_condition libx264 x264.h "X264_BUILD >= 122" && { [ "$toolchain" != "msvc" ] || require_cpp_condition libx264 x264.h "X264_BUILD >= 158"; } && + check_cpp_condition libx264_hdr10 x264.h "X264_BUILD >= 163" && check_cpp_condition libx262 x264.h "X264_MPEG2" enabled libx265 && require_pkg_config libx265 x265 x265.h x265_api_get && require_cpp_condition libx265 x265.h "X265_BUILD >= 89" diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 182e20f622..9177c5d1c8 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -25,6 +25,7 @@ #include "libavutil/eval.h" #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "libavutil/stereo3d.h" @@ -871,6 +872,81 @@ static int convert_pix_fmt(enum AVPixelFormat pix_fmt) return AVERROR(EINVAL);\ } +#if CONFIG_LIBX264_HDR10 +static void handle_mdcv(x264_param_t *params, + const AVMasteringDisplayMetadata *mdcv) +{ + if (!mdcv->has_primaries && !mdcv->has_luminance) + return; + + params->mastering_display.b_mastering_display = 1; + + if (mdcv->has_primaries) { + int *const points[][2] = { + { + ¶ms->mastering_display.i_red_x, + ¶ms->mastering_display.i_red_y + }, + { + ¶ms->mastering_display.i_green_x, + ¶ms->mastering_display.i_green_y + }, + { + ¶ms->mastering_display.i_blue_x, + ¶ms->mastering_display.i_blue_y + }, + }; + + for (int i = 0; i < 3; i++) { + const AVRational *src = mdcv->display_primaries[i]; + int *dst[2] = { points[i][0], points[i][1] }; + + *dst[0] = av_rescale_q(1, src[0], (AVRational){ 1, 50000 }); + *dst[1] = av_rescale_q(1, src[1], (AVRational){ 1, 50000 }); + } + + params->mastering_display.i_white_x = + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }); + params->mastering_display.i_white_y = + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }); + } + + if (mdcv->has_luminance) { + params->mastering_display.i_display_max = + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }); + params->mastering_display.i_display_min = + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 }); + } +} +#endif // CONFIG_LIBX264_HDR10 + +static void handle_side_data(AVCodecContext *avctx, x264_param_t *params) +{ +#if CONFIG_LIBX264_HDR10 + const AVFrameSideDataSet set = avctx->frame_sd_set; + const AVFrameSideData *cll_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->content_light_level.i_max_cll = cll->MaxCLL; + params->content_light_level.i_max_fall = cll->MaxFALL; + + params->content_light_level.b_cll = 1; + } + + if (mdcv_sd) { + handle_mdcv(params, (AVMasteringDisplayMetadata *)mdcv_sd->data); + } +#endif // CONFIG_LIBX264_HDR10 +} + static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; @@ -1171,6 +1247,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1; + handle_side_data(avctx, &x4->params); + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index d787941c16..4095a4b51a 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -7,5 +7,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBSVTAV1 HEVC, MOV, HEVC_DEMUXER LIBDAV1D_DECO fate-libsvtav1-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libsvtav1" "-show_frames -show_entries frame=side_data_list -of flat" +# test for x264 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H264_DECODER) += fate-libx264-hdr10 +fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libx264-hdr10 b/tests/ref/fate/libx264-hdr10 new file mode 100644 index 0000000000..99c11677f0 --- /dev/null +++ b/tests/ref/fate/libx264-hdr10 @@ -0,0 +1,15 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.1.red_x="13250/50000" +frames.frame.0.side_data_list.side_data.1.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.1.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.1.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.1.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.1.blue_y="16000/50000" +frames.frame.0.side_data_list.side_data.1.white_point_x="15635/50000" +frames.frame.0.side_data_list.side_data.1.white_point_y="16450/50000" +frames.frame.0.side_data_list.side_data.1.min_luminance="50/10000" +frames.frame.0.side_data_list.side_data.1.max_luminance="10000000/10000" +frames.frame.0.side_data_list.side_data.2.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.2.max_content=1000 +frames.frame.0.side_data_list.side_data.2.max_average=200 From patchwork Sun Nov 26 19:58:33 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: 44821 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca6:b0:181:818d:5e7f with SMTP id fx38csp2880736pzb; Sun, 26 Nov 2023 12:01:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFP329gCBfzYutYgW4yjJL6LnD62rNx0+Z5P8Yo60AuGqXcnEhZJGCOgt+E3PBHSQtq+3HL X-Received: by 2002:a17:906:7082:b0:9be:e90:5016 with SMTP id b2-20020a170906708200b009be0e905016mr6320081ejk.24.1701028863311; Sun, 26 Nov 2023 12:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701028863; cv=none; d=google.com; s=arc-20160816; b=NJ3otYC5Jobi1bRfmwBKyLEMZLzQKwdThmdEYcjuQCVoQ4wr7NX9qTNhY9oqMYPVOY V7bhdDMdjiZ19j2wbQK202UryrvNZ91/UBGBJ/mltiogmtWB66t/5bl3X126T2d/KCbM VDCtOg/5o30v1zRHeSoPKexdfCwXkS84LS5Mu/bWEGpDEeUhyOqB9QaBzcmBPQGKav/c VAQyUNekeyggtUM9T30i90SdLJYH8nxup2arjgoSDLDL/GnAUq3ImWb0EHW8eFCrLWzo eIBaZ+EwRg7PVbZlG52nb5e32md/TfIC2dfFCxiWvaYyFDsbJN3SfeKPvUGrQXefPNxw QPlg== 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=zJdQwB6djVtYl42Wr9y9NYPNdkomrNBG+8ySxnj3V5o=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=WwZIubFtikjWYrRcMbKverGNkU2yluJFNlUt3UMLG9ELpkfVtIh8ErKIKO7iAhAkG3 iFUsAMMJtE5sab3WTXErD+aVncxB+933xqvUu3ffsgAB5GoCu5Lr98wUZOaO4IOY2HTn +TIth8/iKYBWuaEhDiE4zfONIfej/9YM7jK0RkzfgChIMxX5uC7yFWdwkZ114c0ji8NA Imq5RXPTPkJWcAWfk63KsQXxepTXHwJRfQ921QS94RFBgQNOVh17n7lrXlrXO+VUCxFj gQJ5/8Ee5ZvZ2sMGzebC0zt0uFp4ctaN6xOKh+yj/EG0eXjrV1YuDv5gzsmZAjixP5Ku nmEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=P5WMmLjW; 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 b22-20020a1709062b5600b00a0c3ac58a3bsi1738109ejg.353.2023.11.26.12.01.02; Sun, 26 Nov 2023 12:01:03 -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=P5WMmLjW; 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 95DF468CFBA; Sun, 26 Nov 2023 21:59:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 118F468CF89 for ; Sun, 26 Nov 2023 21:58:54 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2c50305c5c4so45701721fa.1 for ; Sun, 26 Nov 2023 11:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701028733; x=1701633533; 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=nwu3U7xuypC7/hnhLI4gkIecNHWah519xlQnz18MLf0=; b=P5WMmLjWSNaI9/8n8ywiiHzMyORJ+l15cYTv3hLTD7thUGNikpGNOzquN3a5ou+N38 NoBD6jVYn/d6U0G++pEPDENAEizHh3Gh1OlpUE0uRSenykcLn5TU7B3GhxFzrFyhtdz9 3ZCJTwbX5YyiV5VRNYCl2BGRxopduuJcDvH5h2QEQsBui75ONjb+RwjCyupHOAcv27hG XStVbRlG4bLB6NVJqYOM1XiAbjqbGQm0AFVR0OBG/A2URJOOMYOkHiPc5bH/GXg1zYbu FuZUdL5mMf4kZ3QBA9u0f0DMUDdpziM4WYEQfMCrdKACqzmufj69iXN+1lfX2G3D2utr n12g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701028733; x=1701633533; 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=nwu3U7xuypC7/hnhLI4gkIecNHWah519xlQnz18MLf0=; b=NIzfroRjytf7Z4Or1V3dUWRafTClL/QAjV6xgL52Iy5kouEwO3LCuuyzAUedOUAS3U e0RN/7hbcP0dcgnccD2pbEPG73nvxH021u+nWuQo2RnghdVOfA1dUmcgaAGJPJH1EKGp xvv7kxPuZP3Ad2n4OfPcmVko0n6tp/QRZdFNrqObuFQAfiHJTYSvdpAPJVmCPogZYJ35 DfAMxqQgELRlnVlCn/Xx9Yt3Mcznh+spRfBFsGGL7INQF5iWxoFHn46M1+wpIvtV5JTF fMRw57rZkYoLxzEVom4H42NecPL/Ko5lgD0ZS2k/0Jb4QYZeSAyp0nrLUXWU/ZaFqUon CTxQ== X-Gm-Message-State: AOJu0Yy65v0uGTIJvaeK/oTi2K+2Byhac2Gk3iLSeMvNtZdsdborLPqH O2i3ceYepZLjgHyMeIIWEL24tdWcpFw= X-Received: by 2002:ac2:5234:0:b0:50b:a6ff:129f with SMTP id i20-20020ac25234000000b0050ba6ff129fmr4258897lfl.59.1701028733238; Sun, 26 Nov 2023 11:58:53 -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.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 11:58:52 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2023 21:58:33 +0200 Message-ID: <20231126195838.392467-15-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 14/14] avcodec/libx265: add support for writing out CLL and MDCV 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: JAXeZQEb1g3k The newer of these two are the separate integers for content light level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea , with X265_BUILD 75. As we already require X265_BUILD of at least 89, no further conditions are required. --- libavcodec/libx265.c | 87 ++++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 +++ tests/ref/fate/libx265-hdr10 | 16 +++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/ref/fate/libx265-hdr10 diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 447e6da25f..96e50a6223 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -28,9 +28,11 @@ #include #include "libavutil/avassert.h" +#include "libavutil/bprint.h" #include "libavutil/buffer.h" #include "libavutil/internal.h" #include "libavutil/common.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" @@ -179,6 +181,84 @@ static av_cold int libx265_param_parse_int(AVCodecContext *avctx, return 0; } +static int handle_mdcv(const AVClass **avcl, const x265_api *api, + x265_param *params, + const AVMasteringDisplayMetadata *mdcv) +{ + int ret = AVERROR_BUG; + AVBPrint buf; + av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); + + // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u) + av_bprintf( + &buf, + "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")" + "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")", + av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }), + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 })); + + if (!av_bprint_is_complete(&buf)) { + av_log(avcl, AV_LOG_ERROR, + "MDCV string too long for its available space!\n"); + ret = AVERROR(ENOMEM); + goto end; + } + + if (api->param_parse(params, "master-display", buf.str) == + X265_PARAM_BAD_VALUE) { + av_log(avcl, AV_LOG_ERROR, + "Invalid value \"%s\" for param \"master-display\".\n", + buf.str); + ret = AVERROR(EINVAL); + goto end; + } + + ret = 0; + +end: + av_bprint_finalize(&buf, NULL); + + return ret; +} + +static int handle_side_data(AVCodecContext *avctx, const x265_api *api, + x265_param *params) +{ + const AVFrameSideDataSet set = avctx->frame_sd_set; + const AVFrameSideData *cll_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_set_get_entry( + set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->maxCLL = cll->MaxCLL; + params->maxFALL = cll->MaxFALL; + } + + if (mdcv_sd) { + int ret = handle_mdcv( + &avctx->av_class, api, params, + (AVMasteringDisplayMetadata *)mdcv_sd->data); + if (ret < 0) + return ret; + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; @@ -339,6 +419,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR_BUG; } + ret = handle_side_data(avctx, ctx->api, ctx->params); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n", + av_err2str(ret)); + return ret; + } + if (ctx->crf >= 0) { char crf[6]; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 4095a4b51a..30021efbcd 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -12,5 +12,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" +# test for x265 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += fate-libx265-hdr10 +fate-libx265-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libx265" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10 new file mode 100644 index 0000000000..571c837cac --- /dev/null +++ b/tests/ref/fate/libx265-hdr10 @@ -0,0 +1,16 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.2.red_x="13250/50000" +frames.frame.0.side_data_list.side_data.2.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.2.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.2.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000" +frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000" +frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000" +frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000" +frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000" +frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.3.max_content=1000 +frames.frame.0.side_data_list.side_data.3.max_average=200