From patchwork Mon Sep 30 14:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21426 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C91AFC0F1B for ; Mon, 30 Sep 2024 14:14:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 11C976351B; Mon, 30 Sep 2024 16:14:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="T8wsFsMY"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B209B63502 for ; Mon, 30 Sep 2024 16:13:58 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-37cd2cb5615so273078f8f.2 for ; Mon, 30 Sep 2024 07:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705638; x=1728310438; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EQFExxm0qpcWemMa3lAXV5NHRANGRK2YCcMz0z9hqDc=; b=T8wsFsMYP0zOxr5dKr4bvMkHry4K5jdCD1MXurm8Z8J73X5GVn6aOzMcxZT4JLYmto XGqzLzzoFtzQ5ovbcSu5taViFQRreyik+LuyuOcJwOgpUmPQerRoIFnytTTHpDbkKGlB 5yBA9COMDPgCIcNWwP3cWgbGI7dGQEYT/Bewy3XCgonwEfRBxezSEgGDxFWkywvDIGiO 8ea68Xflgj4yHzhcrnxP4ko++qzmgvV8omynDeRwBo1zlTbQ/P1IBEJ88BnRBgsORBxd /vp7JfQwWdR8JUi3hlWzkXp9FPypSOKgC0zrOyt83ejBVVEyA709si7KFwCmFLm9qJpM OIHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705638; x=1728310438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EQFExxm0qpcWemMa3lAXV5NHRANGRK2YCcMz0z9hqDc=; b=kCPjtkKQ7O3vfY3OXctShnrinGQnmqv07Nl0ZybeBNYsv72WIKl7xfQZrFM3WRwhdf 9Th45mNoIC3dFJ6Y6b9q/1iL00CkoBMVQppBBJaIBCf0StVK/A4uszpgNvQSjj+YtipJ tSPo4QkE0BQofS1/uvjo787GvP7b8cDdIC8rbKOGgfu2mXASyNX8qi4Z1wtnJ+g+KXDU bM00KsjHVmTGou8K6AhzK7zdnH8AJvuMTA4tPNOM/7Mp1yAjyWvsNiuqUTp8aG0q04Sa OlqK98+zlSlThP9oakPeV6frWKJ+ACziz3H+XpXNXjsufJWs0T6o2ASou90bBonCxVLR 5uhw== X-Gm-Message-State: AOJu0YyUbFw5VVRHvLdTxqUTbiJsPuHnuImtKhB1bNq5q41vMqhb1iMn cYQ6kyvmj67IA49uJxbqfb42vhgcKCQ/aRneeJW2MNv2/LHR8P3NZzvyd8H71nI54/QlnfCYCPQ m X-Google-Smtp-Source: AGHT+IGFhJxmx27aC/ao+Fd9llOgog8QyIp6ToM9Wtp6+6bWPJ69Fs0qZpn6bAV9GE8aGu2+7Nsydg== X-Received: by 2002:a5d:64ec:0:b0:376:3ef8:61ab with SMTP id ffacd0b85a97d-37cde3f79famr2503105f8f.8.1727705637789; Mon, 30 Sep 2024 07:13:57 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:13:57 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH v2 1/7] controls: rpi: Add a vendor rpi::ScalerCrops control Date: Mon, 30 Sep 2024 15:14:09 +0100 Message-Id: <20240930141415.8857-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a vendor control rpi::ScalerCrops that is analogous to the current core::ScalerCrop, but can apply a different crop to each configured stream. This control takes a span of Rectangle structures - the order of rectangles must match the order of streams configured by the application. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/rpi/common/ipa_base.cpp | 14 ++++++++++++++ src/libcamera/control_ids_rpi.yaml | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index ee3848b54f21..d408cdb74255 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -96,6 +96,15 @@ const ControlInfoMap::Map ipaAfControls{ { &controls::LensPosition, ControlInfo(0.0f, 32.0f, 1.0f) } }; +/* Platform specific controls */ +const std::map platformControls { + { "pisp", + { + { &controls::rpi::ScalerCrops, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) } + } + }, +}; + } /* namespace */ LOG_DEFINE_CATEGORY(IPARPI) @@ -159,6 +168,10 @@ int32_t IpaBase::init(const IPASettings &settings, const InitParams ¶ms, Ini if (lensPresent_) ctrlMap.merge(ControlInfoMap::Map(ipaAfControls)); + auto platformCtrlsIt = platformControls.find(controller_.getTarget()); + if (platformCtrlsIt != platformControls.end()) + ctrlMap.merge(ControlInfoMap::Map(platformCtrlsIt->second)); + monoSensor_ = params.sensorInfo.cfaPattern == properties::draft::ColorFilterArrangementEnum::MONO; if (!monoSensor_) ctrlMap.merge(ControlInfoMap::Map(ipaColourControls)); @@ -1070,6 +1083,7 @@ void IpaBase::applyControls(const ControlList &controls) break; } + case controls::rpi::SCALER_CROPS: case controls::SCALER_CROP: { /* We do nothing with this, but should avoid the warning below. */ break; diff --git a/src/libcamera/control_ids_rpi.yaml b/src/libcamera/control_ids_rpi.yaml index cb097f887e16..a0fc1cd897b5 100644 --- a/src/libcamera/control_ids_rpi.yaml +++ b/src/libcamera/control_ids_rpi.yaml @@ -26,4 +26,25 @@ controls: \sa StatsOutputEnable + - ScalerCrops: + type: Rectangle + size: [n] + description: | + An array of rectangles, where each singular value has identical + functionality to the ScalerCrop control. This control allows the + Raspberry Pi pipeline handler to control individual scaler crops per + output stream. + + The order of rectangles passed into the control must match the order of + streams configured by the application. The pipeline handler will only + configure crop retangles up-to the number of output streams configured. + All subsequent rectangles passed into this control are ignored by the + pipeline handler. + + Note that using different crop rectangles for each output stream with + this control is only applicable on the Pi5/PiSP platform. This control + should also be considered temporary/draft and will be replaced with + official libcamera API support for per-stream controls in the future. + + \sa ScalerCrop ... From patchwork Mon Sep 30 14:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21427 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9E0BEC32D4 for ; Mon, 30 Sep 2024 14:14:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5ABCD63516; Mon, 30 Sep 2024 16:14:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="XcQ31T/W"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7196763502 for ; Mon, 30 Sep 2024 16:13:59 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42f5a663ed5so4354655e9.0 for ; Mon, 30 Sep 2024 07:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705639; x=1728310439; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9+m41jvKqkJNcbigGAyNEkXfOS5vdXGwZcA9O2yM+Fc=; b=XcQ31T/WSNFk8LrpqbBA8ysSFLW+9yy10FlTZrRvzntxzUtbcmeS2a7x3gnLSYnnk3 uWLPAELE8ZSjF07BemdwOhLTzFwaWUGLhZ6lwo/Qk9NXupowleAwuAiqBDl/d3nrKlhF fsUkBE6/RLh75PU+yBeTVT1uqGXRTNLlrBflaKdLsciTwHNFL+B5/p7sapHN2jbOqX6o xtcJMhTjy+uDaJXcj0q5396zZgIv932M8vX3zj/0RCGTeW0tvRJeDr9MvYt4ISOsckAT qKGK6vp0KtJB8As2VKmingaAi3BjyWVkJs1ogZQyYyQVkBQTI8owMmxeoBuoZxDKQ3CN 5EPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705639; x=1728310439; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9+m41jvKqkJNcbigGAyNEkXfOS5vdXGwZcA9O2yM+Fc=; b=Sbcc1ZvRBhfbIZEmbEaRcTQ5jILU0oN0Pb91gEowW6l3Jh36PkwGKiou2C5kJtgzZB CmwQmZ+IoD0LosCJdPxOp6qiqbRzVAFcAPzEL/Yz2iFXwQH2OM3dFTIDYmqT3qIF7bDw wVMn4YNK9wsWYumL61mPqeBELQKEcbWUxBngKOBMetQo0sDxsblN+hMhF4MFfNIC1SZ0 8P3ZAyxRDYAoBTNL4h1saVVXEPOyG7uaeUa5WdZyxGnlyS9I5aLhtqhKf32/TEUwA8TZ G0w93vxDtM2ZlXbwGF3r7V6FFi8pRbUxkE09KhNmZXB7VkO9rtSX1VTd+Uougs2Yo7bD xFJA== X-Gm-Message-State: AOJu0YzrlFl9jeRo/hDmGOFFeBTIa7jgVkTwwSzaS6y31trdt7WIij5H khNpo9ear7WudrEO3eAabjsW0ZnEBW9vJYVIUDWtBjZVpECNRBpjA2SVETcDX20emROWLwRAp+U A X-Google-Smtp-Source: AGHT+IEBvRrrlXiwX9/Z/UvkfQHGc8Z+SH/gzvgJivJPObfS7dzZhfue9WelhHjvaBaTgW8uybKt+w== X-Received: by 2002:a05:600c:350f:b0:42c:ba61:d20b with SMTP id 5b1f17b1804b1-42f58416273mr40066985e9.3.1727705638620; Mon, 30 Sep 2024 07:13:58 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:13:58 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 2/7] pipeline: rpi: Remove CameraData::scalerCrop_ Date: Mon, 30 Sep 2024 15:14:10 +0100 Message-Id: <20240930141415.8857-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Do not cache the scalerCrop_ parameter. The cached value is used to update the request metadata, but since this is not an expensive operation (and can only occur once per frame), caching it is of limited value. This will simplify logic in a future commit where we can specify a crop per-output stream. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 18 +++--------------- .../pipeline/rpi/common/pipeline_base.h | 1 - 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 3041fd1ed9fd..11f1bfd4a5da 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -544,12 +544,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) return ret; } - /* - * Set the scaler crop to the value we are using (scaled to native sensor - * coordinates). - */ - data->scalerCrop_ = data->scaleIspCrop(data->ispCrop_); - /* * Update the ScalerCropMaximum to the correct value for this camera mode. * For us, it's the same as the "analogue crop". @@ -569,7 +563,8 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) /* Add the ScalerCrop control limits based on the current mode. */ Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_)); - ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, data->scalerCrop_); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(data->ispCrop_)); data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1320,13 +1315,6 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != ispCrop_) { ispCrop_ = ispCrop; platformSetIspCrop(); - - /* - * Also update the ScalerCrop in the metadata with what we actually - * used. But we must first rescale that from ISP (camera mode) pixels - * back into sensor native pixels. - */ - scalerCrop_ = scaleIspCrop(ispCrop_); } } } @@ -1483,7 +1471,7 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - request->metadata().set(controls::ScalerCrop, scalerCrop_); + request->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_)); } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index f9cecf70f179..5161c16e518f 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -134,7 +134,6 @@ public: /* For handling digital zoom. */ IPACameraSensorInfo sensorInfo_; Rectangle ispCrop_; /* crop in ISP (camera mode) pixels */ - Rectangle scalerCrop_; /* crop in sensor native pixels */ Size ispMinCropSize_; unsigned int dropFrameCount_; From patchwork Mon Sep 30 14:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21428 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 528B6C3257 for ; Mon, 30 Sep 2024 14:14:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D41AF63521; Mon, 30 Sep 2024 16:14:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="eE3ePZKw"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E370E63502 for ; Mon, 30 Sep 2024 16:14:00 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-37cd5501ec1so243998f8f.0 for ; Mon, 30 Sep 2024 07:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705640; x=1728310440; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XrWcUJQsFkTVobFUCVSgV/d6Wx/qIdBspGHAklWbwc0=; b=eE3ePZKw+z+TbwGeH/fXbIWDm8FpLBJeUAJyeI4u9FWwy86y0xNhwaihWZq/evTbJU hjHsCG6Ivg6sqPvudXo65jUY5VRXQtt8d5M1ku6l581Kj75NFow6xpGM/HQKi6fxtOQb pUD7E7PHngtyUVMBsOsxrAFs6TVtmjihw6e3XxrJF8yTunajRep8GJVN87RTlWo2F1Rq e/0cxL+ouXDuHrkE4Anyy+WPMTYc/xZO0oS0xa667sWRhR5pfTKMuycdGhCuk5lRIEHB UQ7w+W3MfzP9PfETJUKB25TmkVsaRuIW7Y/dCRcrJjPydk1BAT+acaXMB3YpShXhXw0b O6sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705640; x=1728310440; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XrWcUJQsFkTVobFUCVSgV/d6Wx/qIdBspGHAklWbwc0=; b=wLsWnGj+YS8adBCQvBmQO59D2aInFk22OZRC48Sg9sT8E1IccMh2ke33UIP7Q3L/6b /CrHik+9VLlIhKISxgxF838bISkMCPsN6V0ZlMGZ62RHpa1Tng4UEHiw3Uch6E3Bmx+i Md8A+eNbM02sqilyHISgyviaP9K+gXePP0BS5djJj5MQBLGCVBbrNC61JyyEKheB9cVu AbqKLRZLK1IH57Rku9UXMyx9lmIF6U6YqbtAupz0j14+RgqhMFmpdjpjYs5lcR56sp/Y okBsg80Vx0o3kKGwpUQXo/0GV5e7xuAaBmDPOkPfQGEYMbTRWLjy6sfnALVsjwr6zVQ1 Cquw== X-Gm-Message-State: AOJu0Yw9CjC61leJ0SnfetU1m2txK/v8cEWI1vE2ZkgVs4rf4+Js+oSH S1IvaUUEY18oCIOy4jrsdBHjU4naPPrnkWvw3THEK6UyamcvPCl99At9wWfzuiSfuU1mVt8/5zc q X-Google-Smtp-Source: AGHT+IFRVRJ3Wixy/fxnsnqXGcu3q3YbReZuKqMfk/9X82mwkcKJ/r50Mg2usG/e8/1K85/jc5XyEw== X-Received: by 2002:a05:6000:1acb:b0:374:cef0:fd2a with SMTP id ffacd0b85a97d-37cde3f8899mr2513893f8f.7.1727705639732; Mon, 30 Sep 2024 07:13:59 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:13:59 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 3/7] pipeline: rpi: Pass crop rectangle as a parameter to platformSetIspCrop() Date: Mon, 30 Sep 2024 15:14:11 +0100 Message-Id: <20240930141415.8857-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This will be required when we program separate crop values to each ISP output in a future commit. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 2 +- src/libcamera/pipeline/rpi/common/pipeline_base.h | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 11f1bfd4a5da..2de6111bacfd 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1314,7 +1314,7 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != ispCrop_) { ispCrop_ = ispCrop; - platformSetIspCrop(); + platformSetIspCrop(ispCrop); } } } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 5161c16e518f..d65b695c30b5 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -83,7 +83,7 @@ public: Rectangle scaleIspCrop(const Rectangle &ispCrop) const; void applyScalerCrop(const ControlList &controls); - virtual void platformSetIspCrop() = 0; + virtual void platformSetIspCrop(const Rectangle &ispCrop) = 0; void cameraTimeout(); void frameStarted(uint32_t sequence); diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index e5b6ef2b37cd..0ea032293bc9 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -109,9 +109,10 @@ public: Config config_; private: - void platformSetIspCrop() override + void platformSetIspCrop(const Rectangle &ispCrop) override { - isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &ispCrop_); + Rectangle crop = ispCrop; + isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop); } int platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig) override; @@ -707,7 +708,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi Size size = unicamFormat.size.boundedToAspectRatio(maxSize); ispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(); + platformSetIspCrop(ispCrop_); return 0; } From patchwork Mon Sep 30 14:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21429 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9505FC32D4 for ; Mon, 30 Sep 2024 14:14:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 371A46351A; Mon, 30 Sep 2024 16:14:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="N5uYPbGV"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D80106351E for ; Mon, 30 Sep 2024 16:14:01 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42ca4e0014dso5941945e9.2 for ; Mon, 30 Sep 2024 07:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705641; x=1728310441; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hK15FfCcZU6znAebgYoIiMQvQPDECUqm2aTM2ldSG6M=; b=N5uYPbGVG3ZWSQiw8aZbUp17yEm+yOnX8HjRDlycI527JTQsMzR6j9cNs0iILtRusG 1Bs+GTRBEVcWxh9/jOKskO3Q0xaWswlpfNTjP3Wyj5VKjt/J188RI0vkB8uW2SiBttmo w/9odMvRu9MAboZPJUVSWT1M5a67aSTUkyEWjSu6dA1ddHiX3z1Y7ZmpOGU2Bx3/xqVl Im3svhujvWEnPgciV5ABP2dlPHNlEfiNvegocYxUca9oPP6YrwWsTQtE9N92mVHtGzTO luNu7/v7qn5GATOLPNBbv58VUBmGyhRZTLaMZiBR50ma0MoiSM5wx8D98v3GOuNmydjQ kLig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705641; x=1728310441; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hK15FfCcZU6znAebgYoIiMQvQPDECUqm2aTM2ldSG6M=; b=kigMtu/6vG61ry6NJ9ePx4w46EkNYtM+hgRiXsjSkQjeHeqvTdc10sJ3IHg2gilRsj 8PjqFDYPEK+y4kB9aNh+yEL2vsvJon5TtxGB/81uDha/O+VEBaWlGN4x8Uae9tAZeUCq 5YZ5tyfV8JVXmsO0FMHVtFoInfEcfLzllhfGNHmEiMEHAyC15P+MBWF7C+YHoKHL0oTq Xm3hMsw2u5NUjqHz3urD/edXdWeRulc/JFQtdmQ2wou+bnuV8empFFM709w/ihw2iXds bIxkXeD6TkeiJhmOuYoYb24wzkcGh2DEZS5RHheoduXpTYIEGaLLyEG2jzM7zVUBB+ye /aKg== X-Gm-Message-State: AOJu0YyQ9p6h4BIPN8xvqYGt5DWG1D6vFjyqkhgoNukLky5EiqIESczn 7LrP8Q/BQYReo3U1GbO0hHdLYjUGw090iI0uZV2cgfi6wkgytPZCAWU8wGOoUqSwSUb51oMbrnw c X-Google-Smtp-Source: AGHT+IHRboinuZhNHPCEwmpLBlTA0FJ1mV/iVvWbbwypghPBAOh7gs3/obqDDr2RfMU3wj50OiZ+OA== X-Received: by 2002:a05:600c:3145:b0:42c:df54:18f6 with SMTP id 5b1f17b1804b1-42f5e38b8d9mr28227495e9.3.1727705640924; Mon, 30 Sep 2024 07:14:00 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:14:00 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 4/7] pipeline: rpi: Introduce CameraData::CropParams Date: Mon, 30 Sep 2024 15:14:12 +0100 Message-Id: <20240930141415.8857-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In preparation for assigning separate crop windows for each stream, add a new CropParams structure that stores the existing ispCrop_ and ispMinCropSize_ as fields. Use a new std::map to store a CropParams structure where the map key is the index of the stream configuration in the CameraConfiguration vector. At preset, only a single CropParams structure will be set at key == 0 to preserve the existing crop handling logic. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 28 +++++++++++++------ .../pipeline/rpi/common/pipeline_base.h | 21 ++++++++++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 12 ++++++-- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 2de6111bacfd..220c7b962280 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -533,6 +533,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) * Platform specific internal stream configuration. This also assigns * external streams which get configured below. */ + data->cropParams_.clear(); ret = data->platformConfigure(rpiConfig); if (ret) return ret; @@ -561,10 +562,14 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) for (auto const &c : result.controlInfo) ctrlMap.emplace(c.first, c.second); - /* Add the ScalerCrop control limits based on the current mode. */ - Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_)); - ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, - data->scaleIspCrop(data->ispCrop_)); + const auto cropParamsIt = data->cropParams_.find(0); + if (cropParamsIt != data->cropParams_.end()) { + const CameraData::CropParams &cropParams = cropParamsIt->second; + /* Add the ScalerCrop control limits based on the current mode. */ + Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize)); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(cropParams.ispCrop)); + } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1291,8 +1296,10 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { const auto &scalerCrop = controls.get(controls::ScalerCrop); - if (scalerCrop) { + const auto cropParamsIt = cropParams_.find(0); + if (scalerCrop && cropParamsIt != cropParams_.end()) { Rectangle nativeCrop = *scalerCrop; + CropParams &cropParams = cropParamsIt->second; if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -1308,12 +1315,12 @@ void CameraData::applyScalerCrop(const ControlList &controls) * 2. With the same mid-point, if possible. * 3. But it can't go outside the sensor area. */ - Size minSize = ispMinCropSize_.expandedToAspectRatio(nativeCrop.size()); + Size minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); Size size = ispCrop.size().expandedTo(minSize); ispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize)); - if (ispCrop != ispCrop_) { - ispCrop_ = ispCrop; + if (ispCrop != cropParams.ispCrop) { + cropParams.ispCrop = ispCrop; platformSetIspCrop(ispCrop); } } @@ -1471,7 +1478,10 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - request->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_)); + const auto cropParamsIt = cropParams_.find(0); + if (cropParamsIt != cropParams_.end()) + request->metadata().set(controls::ScalerCrop, + scaleIspCrop(cropParamsIt->second.ispCrop)); } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index d65b695c30b5..75babbe17f31 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -133,8 +133,25 @@ public: /* For handling digital zoom. */ IPACameraSensorInfo sensorInfo_; - Rectangle ispCrop_; /* crop in ISP (camera mode) pixels */ - Size ispMinCropSize_; + + struct CropParams { + CropParams(Rectangle ispCrop_, Size ispMinCropSize_) + : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_) + { + } + + CropParams() + { + } + + /* Crop in ISP (camera mode) pixels */ + Rectangle ispCrop; + /* Minimum crop size in ISP output pixels */ + Size ispMinCropSize; + }; + + /* Mapping of CropParams keyed by the output stream order in CameraConfiguration */ + std::map cropParams_; unsigned int dropFrameCount_; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 0ea032293bc9..8080f55a1cf4 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -702,13 +702,19 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi /* Figure out the smallest selection the ISP will allow. */ Rectangle testCrop(0, 0, 1, 1); isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop); - ispMinCropSize_ = testCrop.size(); /* Adjust aspect ratio by providing crops on the input image. */ Size size = unicamFormat.size.boundedToAspectRatio(maxSize); - ispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center()); + Rectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(ispCrop_); + platformSetIspCrop(ispCrop); + /* + * Set the scaler crop to the value we are using (scaled to native sensor + * coordinates). + */ + cropParams_.emplace(std::piecewise_construct, + std::forward_as_tuple(0), + std::forward_as_tuple(ispCrop, testCrop.size())); return 0; } From patchwork Mon Sep 30 14:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21430 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8B9C7C32DB for ; Mon, 30 Sep 2024 14:14:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AEB0B63516; Mon, 30 Sep 2024 16:14:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qs+fxVBV"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B00CC6351F for ; Mon, 30 Sep 2024 16:14:02 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42caeb4d671so6138825e9.2 for ; Mon, 30 Sep 2024 07:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705642; x=1728310442; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KjkCxnvGYGkI5PTky/1pzr2+gdc74PnXCKK21TvDtuE=; b=qs+fxVBV29iMas5ozsSxFCFKON2mG1A+S3L2FCAJ2HA+ZQBk20kUspmA78ZLwwPzug ZicwrKZZIvGn20DH0VZa6V2Fus4G1sAXQ/zLZLAWJosxJeZW9ZkrX6rZtgL8VdTo29se 1CCfJOmA0pWbXvljouPAbTi1ezggMT0L1UA9oD4E6rAZPFIK678le7m4XXJ7oviEcuY6 0gPG0qcpYV+rEePjaWNjIFqFrfH+G8ar1gsCZgsOOlQyO2OuCiNdMLwdMirUTACY61WH 0Nhms5xzI9p2N+q0hLzrmYfesFGP9cEc7EHSvKFYEXVGtAqb/kp0P6Wo5z0znH8naYf7 WLew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705642; x=1728310442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KjkCxnvGYGkI5PTky/1pzr2+gdc74PnXCKK21TvDtuE=; b=skkWRsr/AJxxbkt8bFiyzQz5mU7kPfMaDCwJ6YQZwJgQUu3nlgDOF1HarShoZtpMMS xlKT+BTnmZYM/P3mSm/9NQyWmQEr/Co+k3plmBG8xKhyDaDXsvfxJ6WBoMHSvaOtDNKy FezLG/1MZHgTEmWyX0p1ecGUmrcPMUk1RogHKAKkbPKJauRWZQexINP1kxGwZKSCSdhB FIe3unFJEJXhQG/m/abcYTNJsigg0A8YDsgigPlZA1x9kD57eOdGpNTcadY7mmYlvFeq cU1lpQwuyRM24Tizti4Xwo2yibet9731FRJmwNOFrVAS9vSVnTb2sACfQ/C68RYZu/IP cgBA== X-Gm-Message-State: AOJu0Yz77KbY0qzf+AXTxdRPDH7PPMFeeua4/jkXyAHujOvdhOrCiRBJ H0ufNJgAxzbZ8XgtrlD0xGtpRIK2X5IYombaD+yvpX5epHFWBPTeib/MHLNzDDjqdsdbF0lO7v8 s X-Google-Smtp-Source: AGHT+IHRU5cOhPu0iGoc7ILf+FvE+JaJkVhp2qdmNh5aWjxFbiqmjgTWLF2fmnBcUhSmXliLgaKtxQ== X-Received: by 2002:a05:600c:3b87:b0:42c:ba83:3efa with SMTP id 5b1f17b1804b1-42f5e30dd5cmr30020155e9.0.1727705641724; Mon, 30 Sep 2024 07:14:01 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:14:01 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 5/7] pipeline: rpi: Track which ISP output is configured for a stream Date: Mon, 30 Sep 2024 15:14:13 +0100 Message-Id: <20240930141415.8857-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a ispIndex field to CropParams that is used to track which ISP output (0/1) will be used for a given stream during configuration. Tracking this information is required for an upcoming change where crop rectangles can be specified for each configured stream. Currently, the value is fixed to 0. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.h | 6 ++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 75babbe17f31..9d23a1994f00 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -135,8 +135,8 @@ public: IPACameraSensorInfo sensorInfo_; struct CropParams { - CropParams(Rectangle ispCrop_, Size ispMinCropSize_) - : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_) + CropParams(Rectangle ispCrop_, Size ispMinCropSize_, unsigned int ispIndex_) + : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_), ispIndex(ispIndex_) { } @@ -148,6 +148,8 @@ public: Rectangle ispCrop; /* Minimum crop size in ISP output pixels */ Size ispMinCropSize; + /* Index of the ISP output channel for this crop */ + unsigned int ispIndex; }; /* Mapping of CropParams keyed by the output stream order in CameraConfiguration */ diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 8080f55a1cf4..cfed214ddbd4 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -714,7 +714,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi */ cropParams_.emplace(std::piecewise_construct, std::forward_as_tuple(0), - std::forward_as_tuple(ispCrop, testCrop.size())); + std::forward_as_tuple(ispCrop, testCrop.size(), 0)); return 0; } From patchwork Mon Sep 30 14:14:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21431 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1D85CC32DC for ; Mon, 30 Sep 2024 14:14:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 770D46351F; Mon, 30 Sep 2024 16:14:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HqFz9LL9"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5CE6563515 for ; Mon, 30 Sep 2024 16:14:03 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cae563348so6164465e9.0 for ; Mon, 30 Sep 2024 07:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705642; x=1728310442; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zt0s6lzWL4fOCXcqP0tX9PfDzIzeRQYXMu6WNo5LCG0=; b=HqFz9LL93oQrvaG7jPvAovf7F3C+DI5Dg1IboBKzjpXw8ztm+juOjazVMMP8H9w0JR Xz9i9z4Ld5Sp+ny+sdw8DuMpJ7aIGjfK49MecsfnQXEUXIEdumE+fjC5ZnjaQeAry8er FjiT0FX7c0IcVZH6sIh4T+0TAOnaMv8YUFWblpK8T8aak7knCd+5yJw0RVcsfZMuEXfA lxp/ZVK2LfcNiCcDYKKZtAtqdRsVKHSOt0waTs2D4BsLzW2SEtRmY9UwC4e9ouGioTkV UohE7L3EaTVILieiGR8yJefxyh/zDLEaFI+fqR/Y6WnWSKHY2kuU1syDpwWapkSNkOSL OPXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705642; x=1728310442; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zt0s6lzWL4fOCXcqP0tX9PfDzIzeRQYXMu6WNo5LCG0=; b=AhEUqnAfWivULBVUjmHaho4F80y/ZjVvo9mHmjTIh6XobA0bir+mQeYa2uKmOz7rH4 dcQD7rm6palPEjVY1QRRKl5g1cy+UnvlkBOH4Suyt0JmBOewfFt6Qjkp/GxM0l9yMyqO DwBJgxYOjGxmXKASB7do1DEZvHuIXEDbZNhnhRMteG7703GmWZlj9hTcJxrcTTaDp463 4FMXs/S+bY3FrQlmouy5yFLpYENiH9UP8SIaJPxPitf1mR3N73Jio4IN2z4R34NFULdV mmsbB3dySBcc/ffTLsw3FROh/3E6VeU83gj8vlnnID2g/aeJ8tGa++ATRG9NrLUYGV58 tX0A== X-Gm-Message-State: AOJu0YzhH6JVTen7Ydpm7W7M+QiwxsbM2+ADhAZX4o5MfNIOWmT94Ipa kzLNFwTvc7L3hqrTOL7OTP/jbR3Q8/osesdfjxbnouPsPtEJEreCOQJO/gmoEFTgIaErdGezGs/ A X-Google-Smtp-Source: AGHT+IEhfQLVZFkkE4E3I1TehvT+Hw6MtoPiqs8nHDnlXHLxpu4LBa13ZULcEhuNJFG+wil6kdSnVw== X-Received: by 2002:a05:600c:4711:b0:42c:b995:20c2 with SMTP id 5b1f17b1804b1-42f5e389525mr28924775e9.3.1727705642532; Mon, 30 Sep 2024 07:14:02 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:14:02 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 6/7] pipeline: rpi: Pass ISP output index into platformSetIspCrop() Date: Mon, 30 Sep 2024 15:14:14 +0100 Message-Id: <20240930141415.8857-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" At this point, the index is unused, but will be in a future commit where we can set different crops on each ISP output. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 2 +- src/libcamera/pipeline/rpi/common/pipeline_base.h | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 220c7b962280..267e6bd9cd70 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1321,7 +1321,7 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != cropParams.ispCrop) { cropParams.ispCrop = ispCrop; - platformSetIspCrop(ispCrop); + platformSetIspCrop(cropParams.ispIndex, ispCrop); } } } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 9d23a1994f00..3c47411f745a 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -83,7 +83,7 @@ public: Rectangle scaleIspCrop(const Rectangle &ispCrop) const; void applyScalerCrop(const ControlList &controls); - virtual void platformSetIspCrop(const Rectangle &ispCrop) = 0; + virtual void platformSetIspCrop(unsigned int index, const Rectangle &ispCrop) = 0; void cameraTimeout(); void frameStarted(uint32_t sequence); diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index cfed214ddbd4..fd8d84b14f15 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -109,7 +109,7 @@ public: Config config_; private: - void platformSetIspCrop(const Rectangle &ispCrop) override + void platformSetIspCrop([[maybe_unused]] unsigned int index, const Rectangle &ispCrop) override { Rectangle crop = ispCrop; isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop); @@ -707,7 +707,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi Size size = unicamFormat.size.boundedToAspectRatio(maxSize); Rectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(ispCrop); + platformSetIspCrop(0, ispCrop); /* * Set the scaler crop to the value we are using (scaled to native sensor * coordinates). From patchwork Mon Sep 30 14:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21432 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 52087C3257 for ; Mon, 30 Sep 2024 14:14:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C09F263523; Mon, 30 Sep 2024 16:14:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dnYd0snh"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F9136351A for ; Mon, 30 Sep 2024 16:14:04 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-37cdc7bd941so145878f8f.0 for ; Mon, 30 Sep 2024 07:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705644; x=1728310444; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Td/TBRZGbHBx4CYqK/k1N9Zms1qp/+XMuth4qZeDX9k=; b=dnYd0snhGb3e/lnlkCPEDvS31/B3H552CCgJuoQAUXuV3abMQE1f1Qr1NZhSg8rKy+ NbyPwSWrL4DvijqbC/aFMWt3PsjFLJ0J71MYRjXw2EozwF+54ze5gJeKtmIvK40JCQgq CqQGSr/Nls675ePPCk3FNq/li6Eh7r/HVRlK0zjtNWkxsMNcrKjeSw8EA87JBjLoKXsK 5JQyfeAg37G+e4q3EUH8A09Y9qyh1eY5XPrkIvXd7z4nP/lhP5P8RwQhCf/TrJrbIVbM SV3e+Sz+Ak5TWViNpr4sKODnvMFiCT+HQVIhUE7QcNALcr3kZwiFDSWpaCZtTpm/Z0uY HZ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705644; x=1728310444; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Td/TBRZGbHBx4CYqK/k1N9Zms1qp/+XMuth4qZeDX9k=; b=SXFWcQyEOtRiHWoAgQBlsfxsukBncQLR15aa+Pgrov/3XZhWgRAmHg71zRr/OZBXaq evfaEjATt0trw7NKXqOzUYrCOQi0poGOM0GpEC7mdveGnQbdh5Tgmc9TEKJTzJVg0gnQ WlGUQEdBF9eTc0BndGwmtB9Fj6SiI0mVqR4rwji/xAN5fVWeTrFOe2NFtfpe+KpGUR0P mnsyBm6VxUvuZK1kA6Czw4qRxRQTRK2uRNyh3Bn/0WxGbXUTB71Cdd20KzfuyUXmIK8B f3LcisjsQxb7MCMCUgxEPE5t7Ti6G2YOlOtcmEHJUXtamSn07MN5eR5lVwtFQy9Z6Ymu Bsww== X-Gm-Message-State: AOJu0YyCZLxb9LXX5K37g+7CJKiJzCg1ZNeCjaDgSVKzZMqrL2gRMYM0 tGj4AKs5jxSC5GGWZn5FcO7oaoo0fs7/u8TjFHbSZxTGn2wSw1B4LKfo8b+l0Katb8l8r9H+s+f A X-Google-Smtp-Source: AGHT+IHQepeeSWAHIz4G/igmDNRsPs4UrioTef6jHOdIEA07eyPm1uy1VTif4T5vEVZeNCYmrNbdAA== X-Received: by 2002:a5d:6c6e:0:b0:374:cd01:8b72 with SMTP id ffacd0b85a97d-37cde446cffmr2482820f8f.9.1727705643603; Mon, 30 Sep 2024 07:14:03 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:14:02 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH v2 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops Date: Mon, 30 Sep 2024 15:14:15 +0100 Message-Id: <20240930141415.8857-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-1-naush@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Handle multiple scaler crops being set through the rpi::ScalerCrops control. We now populate the cropParams_ map in the loop where we handle the output stream configuration items. The key of this map is the index of the stream configuration structure set by the application. This will also be the same index used to specify the crop rectangles through the ScalerCrops control. CameraData::applyScalerCrop() has been adapted to look at either controls::ScalerCrop or controls::rpi::ScalerCrops. The former takes priority over the latter, and if present, will apply the same scaler crop to all output streams. Finally return all crops through the same ScalerCrops control via request metadata. The first configure stream's crop rectangle is also returned via the ScalerCrop control in the request metadata. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 76 ++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 267e6bd9cd70..9393e79ae4c7 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -181,12 +181,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() rawStreams_.clear(); outStreams_.clear(); + unsigned int rawStreamIndex = 0; + unsigned int outStreamIndex = 0; - for (const auto &[index, cfg] : utils::enumerate(config_)) { + for (auto &cfg : config_) { if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) - rawStreams_.emplace_back(index, &cfg); + rawStreams_.emplace_back(rawStreamIndex++, &cfg); else - outStreams_.emplace_back(index, &cfg); + outStreams_.emplace_back(outStreamIndex++, &cfg); } /* Sort the streams so the highest resolution is first. */ @@ -565,10 +567,24 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) const auto cropParamsIt = data->cropParams_.find(0); if (cropParamsIt != data->cropParams_.end()) { const CameraData::CropParams &cropParams = cropParamsIt->second; - /* Add the ScalerCrop control limits based on the current mode. */ + /* + * Add the ScalerCrop control limits based on the current mode and + * the first configured stream. + */ Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize)); ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, data->scaleIspCrop(cropParams.ispCrop)); + if (data->cropParams_.size() == 2) { + /* + * The control map for rpi::ScalerCrops has the min value + * as the default crop for stream 0, max value as the default + * value for stream 1. + */ + ctrlMap[&controls::rpi::ScalerCrops] = + ControlInfo(data->scaleIspCrop(data->cropParams_[0].ispCrop), + data->scaleIspCrop(data->cropParams_[1].ispCrop), + ctrlMap[&controls::ScalerCrop].def()); + } } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1295,11 +1311,29 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { - const auto &scalerCrop = controls.get(controls::ScalerCrop); - const auto cropParamsIt = cropParams_.find(0); - if (scalerCrop && cropParamsIt != cropParams_.end()) { - Rectangle nativeCrop = *scalerCrop; - CropParams &cropParams = cropParamsIt->second; + const auto &scalerCropRPi = controls.get>(controls::rpi::ScalerCrops); + const auto &scalerCropCore = controls.get(controls::ScalerCrop); + std::vector scalerCrops; + + /* + * First thing to do is create a vector of crops to apply to each ISP output + * based on either controls::ScalerCrop or controls::rpi::ScalerCrops if + * present. + * + * If controls::ScalerCrop is present, apply the same crop to all ISP output + * streams. Otherwise if controls::rpi::ScalerCrops, apply the given crops + * to the ISP output streams, indexed by the same order in which they had + * been configured. This is not the same as the ISP output index. + */ + for (unsigned int i = 0; i < cropParams_.size(); i++) { + if (scalerCropRPi && i < scalerCropRPi->size()) + scalerCrops.push_back(scalerCropRPi->data()[i]); + else if (scalerCropCore) + scalerCrops.push_back(*scalerCropCore); + } + + for (auto const &[i, scalerCrop] : utils::enumerate(scalerCrops)) { + Rectangle nativeCrop = scalerCrop; if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -1315,13 +1349,13 @@ void CameraData::applyScalerCrop(const ControlList &controls) * 2. With the same mid-point, if possible. * 3. But it can't go outside the sensor area. */ - Size minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); + Size minSize = cropParams_[i].ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); Size size = ispCrop.size().expandedTo(minSize); ispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize)); - if (ispCrop != cropParams.ispCrop) { - cropParams.ispCrop = ispCrop; - platformSetIspCrop(cropParams.ispIndex, ispCrop); + if (ispCrop != cropParams_[i].ispCrop) { + cropParams_[i].ispCrop = ispCrop; + platformSetIspCrop(cropParams_[i].ispIndex, ispCrop); } } } @@ -1478,10 +1512,18 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - const auto cropParamsIt = cropParams_.find(0); - if (cropParamsIt != cropParams_.end()) - request->metadata().set(controls::ScalerCrop, - scaleIspCrop(cropParamsIt->second.ispCrop)); + if (cropParams_.size()) { + std::vector crops; + + for (auto const &[k, v] : cropParams_) + crops.push_back(scaleIspCrop(v.ispCrop)); + + request->metadata().set(controls::ScalerCrop, crops[0]); + if (crops.size() > 1) { + request->metadata().set(controls::rpi::ScalerCrops, + Span(crops.data(), crops.size())); + } + } } } /* namespace libcamera */