From patchwork Thu Oct 31 09:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21782 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 335C5C31E9 for ; Thu, 31 Oct 2024 09:52:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 526A6653B0; Thu, 31 Oct 2024 10:52:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LppGKVfi"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 01BFD618BF for ; Thu, 31 Oct 2024 10:52:43 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4314ff68358so1142265e9.1 for ; Thu, 31 Oct 2024 02:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368362; x=1730973162; 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=8/ci8H8fsu9Yoc9n9x2IcuZezTp6fDZVQyj4WcMUPxU=; b=LppGKVfigT60et+TPLytYaFzFXjh5zOcwTTD6p/WRCu8tgIe/GHAT5bBejO3mQvNzJ kiWBdnd/0dfX8BkLTgUoksdvkY24I2/4EBOK/w0eMDWz0HOUeEPm5Tb+VYmVlAfaUNIx eYdoapogdUGI14bYhQuGPPNslJGY/lqlf/ivZpibIWKM50jOQPHh3VX7Y9OsI9SKTUbs B5wpq7A7Z/891q2xo6UI5CdJMtPtshTmSFxnPIbkquoh4sV4EbUe28iSnSfCzxhqGd9B NMKi6P1J2rbvCw9F+O1m/2XonaygZq1rlz7o08Z8+x2zHIvcEUPgqilGnV60IFfPQC+0 f9oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368362; x=1730973162; 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=8/ci8H8fsu9Yoc9n9x2IcuZezTp6fDZVQyj4WcMUPxU=; b=aIdVU62af75xjSPo9Lcdz1SDIgdTHZA3BjkBYq2LVPymZanSrMrv80bmjxLAXv7Oh4 mAGTcfQlLjI6aeYvclhkfSVs15If5BKd389mdmmSFiz+P/1a66u4DI7N2CwKueoRDAC4 f1e6A7NYwtusFJocONIa34wzgaVZdCBFgZfcS7aqCia/f+3bLSY9X0zGGmZrhf0W4CcZ L3wn/VEGkJ4HpNSnOKJ5fsa88M9Nw9Y9xGSfyI3sndxl629vKmzzCJ9CV+BnVzyknfvN ug+jAGLkSGVa+8gpJ8689wvY/+y0vNn1dcM8K+rEehlJgbBS7WGravoiMLjVfqSLNRsQ LfIA== X-Gm-Message-State: AOJu0YyOx6gc72uDPGr+rUOXJKlpqQhPi9E9afxLnF5vyhpQmZC2pJN2 OAywsZKPJ/rXRngZb1IowLBi22T8xmc/LJEFE+QvNVkfwg/XnV/8JRCvgIST6cxWiQsLEl3euDT O X-Google-Smtp-Source: AGHT+IHM+uNXgDWRhfJGYPQMhJ0Z5bsNMBQlbqUtSVgl39pmAWyU7hFN+JcAQynmwUyVjswMO7lySw== X-Received: by 2002:a05:600c:4449:b0:42c:b870:c52e with SMTP id 5b1f17b1804b1-4319ac85e9amr69282405e9.1.1730368362196; Thu, 31 Oct 2024 02:52:42 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:41 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Jacopo Mondi , Laurent Pinchart Subject: [PATCH v4 1/7] controls: rpi: Add a vendor rpi::ScalerCrops control Date: Thu, 31 Oct 2024 09:49:51 +0000 Message-Id: <20241031094957.18471-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 Reviewed-by: Laurent Pinchart --- src/ipa/rpi/common/ipa_base.cpp | 12 ++++++++++++ src/libcamera/control_ids_rpi.yaml | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index ee3848b54f21..468f36a82ab2 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -96,6 +96,13 @@ 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 +166,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 +1081,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 42c4bf5d408f..34bbdfc863c5 100644 --- a/src/libcamera/control_ids_rpi.yaml +++ b/src/libcamera/control_ids_rpi.yaml @@ -30,4 +30,29 @@ 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. + + If both rpi::ScalerCrops and ScalerCrop controls are present in a + ControlList, the latter is discarded, and crops are obtained from this + control. + + 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 Thu Oct 31 09:49:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21783 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 5E589C3292 for ; Thu, 31 Oct 2024 09:52:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC2CF653AA; Thu, 31 Oct 2024 10:52:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gclw96W/"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 90566618BF for ; Thu, 31 Oct 2024 10:52:43 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43155a6c3a6so1119225e9.1 for ; Thu, 31 Oct 2024 02:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368363; x=1730973163; 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=gF1CRK5658pUZV0uzy7B6zhR0H6HtzA+lmLE8dz6KjA=; b=gclw96W/7CaT7qDizkE+cbMrMwEvaAzUfQ4KN7VW2UV2chMq2Uo20+6u0p/XcZHYUO oW4L6hw+Jr+o9VR0huTj38NnJDKUpa+E/XaPMGSN2HS/1V+gS3YI8p7aevFVwrbytc4y xt+BEUnbne/5b3ZxQBiZQj7mbwBBZNSDFyAYuqz92Z1h3hfbOmq7LSPG2a3XdctseH2+ o5QaodNQnjogcY79npXyYX8EWIhOVOHoYoB2gBlPIKMg9rUzFSWWTC54ozRcUMf0dZGC /+R0o4TuXd6OMXzlcSq3/3UsWrh/OdtLY2IXNofmtUz2wSLFvhsHen08y8Ux2ZKgw4yb wolw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368363; x=1730973163; 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=gF1CRK5658pUZV0uzy7B6zhR0H6HtzA+lmLE8dz6KjA=; b=tQDnj+3XK0sg2PZgvQxh3/aCjQsaLWonual4gzNobkTKoE21tXx6wLDRQ2+qF/AS4q wuzpaKW+pD45DmtNFRTSOhMpkgyJ52ybq4P/LTugQZEh/PTPk3uawn4ATQ1x1l5wZi4o T7KNZTIuHBAsyUJJg8S9vCk0aSL0qaCiAocn8Odf0t6INJvM4bAm4jKcA3ZIMgEzC9Q+ gWHx40r60Q9+YzmeZMIhYtpiQwDVWm2trlcGuPYVX7f8/kD6XISmhgi+KLVINzY2rcQg zaARLFsJ2uHSRZ/Ds63Ucab/rezFw+zkwW8a5TWQRubYdzHxTsVAg6Hqtaakf9A7xYBa kOng== X-Gm-Message-State: AOJu0YwWRKI6XrPzkrp0Lr+3TGonKAX4DOA5C7pGTJxUfM23/cIxealD DkohPX6Pe2f+nxG1XsSggInb8ErkUXdZryWfi/Pr1+njAb0lVvTPipxU0vSx6YGGZTNOOF2Dt/0 S X-Google-Smtp-Source: AGHT+IGnZKl1k4SGUoAE/692lZgoEpCE4p/mc7gB1jKD+YfgwS/3NtI5UCiRzSsZjvD6qSeN0o+Deg== X-Received: by 2002:a05:600c:4f0c:b0:431:4983:e8fe with SMTP id 5b1f17b1804b1-4319ad41c64mr69708655e9.9.1730368362846; Thu, 31 Oct 2024 02:52:42 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:42 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 2/7] pipeline: rpi: Remove CameraData::scalerCrop_ Date: Thu, 31 Oct 2024 09:49:52 +0000 Message-Id: <20241031094957.18471-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 Thu Oct 31 09:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21784 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 7B115C31E9 for ; Thu, 31 Oct 2024 09:52:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34BB1653AB; Thu, 31 Oct 2024 10:52:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="qsO2Un/s"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C3A36539F for ; Thu, 31 Oct 2024 10:52:44 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43160c5bad8so830845e9.3 for ; Thu, 31 Oct 2024 02:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368364; x=1730973164; 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=IUr6Lw+NnsqPBWYBrmq0WF1o8u+vmudIqx4yHm1X3FA=; b=qsO2Un/sz2dJtmpX/ogxcn42+QAxuSv7c3sBTgdtKOYXOQgJNUh7IcoUfJB96F3BXn dPGFoJdF90en8I+wfkKLX49uFnMZeYl4x/NGl95t7TDHDNv5utocTBL92iBfUkt+mWdl vxJsEJRyGXzTxYWsuRewbpYhKp2He1VYuv2eQMUyh52VmBdZmSTzht3fb+lI7fi/CgpQ 9LFLjXwNlsZZ346uKbob/OXCiKFOftReWrISMQ4dlWS21K7MWbtxUr0y39xLzQcB849t GhV7AqRagFQmKg/WAvbrRs45ig3IdVmF1ar6jsSYllZ6oqK3E6x08ByED1wJ3yzxYs3T Z1Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368364; x=1730973164; 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=IUr6Lw+NnsqPBWYBrmq0WF1o8u+vmudIqx4yHm1X3FA=; b=l6y8UfvrzA4LBJ6QQVvlL5axUnfbrpAmLE9VQKlgCkwD2zQKSDsgKhi7YmqQ6zS+N+ EIhf60rB8pX97J0mf3hLhpUMmnZnwOzO95sNV8idH+ja9E49/f11E0dVZ5+mCXJ6jCVB KRvuJ2Rrz1ToM87oLQbTfW4U0+NhuB9RiyDq88jTOQfC+rGTU9MZ2z4QJux/RkYgXnyp 4C5G1rbL2gAGhRNfXycSIsb6i+b6e0kbpFsUlVptR1qMb/sg8PxyARSqpjc/d3BVitOb nyZmOWqvlv6QEIdRFCuOdtOa48Dj3NDZfGHOuRkNC5aec5WoWAXt10FWLmxUrKdAJ246 20zQ== X-Gm-Message-State: AOJu0YwvhFnp/fOi8Y/zCOGjCs1Ua3u0r38PMY1bFim/S7H8NdUvHl09 LqnzQfWUL5eqE7jJ1RsRV73+/KoHwJQlZx0lm3Bov2Km12Nx+VvUuhtIb19mNXDY7IzTyqUJ6Rg X X-Google-Smtp-Source: AGHT+IEfsgogO3s8OyY/F+bsq57H50OrFcJaMzzpsGSRu0B759IzBj35G6VsgkgKJTFAGDJYvk1vgQ== X-Received: by 2002:a05:600c:468d:b0:42c:aeee:da86 with SMTP id 5b1f17b1804b1-4319ad75782mr72843645e9.8.1730368363698; Thu, 31 Oct 2024 02:52:43 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:43 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 3/7] pipeline: rpi: Pass crop rectangle as a parameter to platformSetIspCrop() Date: Thu, 31 Oct 2024 09:49:53 +0000 Message-Id: <20241031094957.18471-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 Thu Oct 31 09:49:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21785 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 63B15C330B for ; Thu, 31 Oct 2024 09:52:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E9F1C618BF; Thu, 31 Oct 2024 10:52:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="J0USs6LM"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53A71653AF for ; Thu, 31 Oct 2024 10:52:45 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-43158124a54so1109425e9.3 for ; Thu, 31 Oct 2024 02:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368364; x=1730973164; 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=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=; b=J0USs6LM3VriXFTAZUMOg0W8fg2vGZIfmV4fH9KhIyRQqjBUC2Tvqddej9ml7O/DGC l9GOIldKlfLv/Sc5bnmlcREz8Zmbs5zPMqqPDv2RoGMZVzKQ2zGFXbJzISUNLwIkuqoY 4PXZIi0iCvQd/FGtY6y3eUwUJJ5+LwXuR970Y8nBmQuZ3SFHAkfxgTG5UD9gMUh5WMEK ouRPjzC+eYaScrSOcdUF6Hy7CqI1xySiq/mLWc3An4VOG9IYWK3WV78sjL4uuBSw3YB0 4q65aei2wqDhmdS88Qz6PpsdPRkgJw99MfbcGN4RYDiqHi1RMH6Xn9x2v/v9WdaoHRAw 6s1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368364; x=1730973164; 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=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=; b=Gbqe6Ph1dKm78CN0+mLWq+B+1XMiV+15z/PiUJFKUHjSJgqewg2uS7XovaR/9wYWPn uMFd78doydK5nW94KedC+mE343O8n5q7Eb6EYuep/799JO+fEGtMYWu+L1/7VrzI+r7D 2OjUmdcrpcGsZHC1aQepFZ9LJlySt0dIUzbi9gn823fi/gM/2/LpKMKg9FDRoJmYrzVt 9+PLgSmG+DGZ14LY84PH4PJJinDo1rPUe006Kj9pV8s61mgScGZQ+5t9bMu+yylPgTkQ /5xkCmSBrkX9TnJ1TN/Nl1hRzxRd2AMXPVJaNp/3t2SohLu8J9LO38ciBmy/A3EYNFB9 eUrQ== X-Gm-Message-State: AOJu0YyWGB/6h5wo2/XjZW2SsQF/NtH/ZOpyYGaGXpJ5dtUHhW4VFiOx 9PxfnPlIjg34Z3b7fXBISDp5alPzIM2ARa3Eq1R3zKNgFhRyxxb85ZB6pP0aksnH8A1U28bymK+ k X-Google-Smtp-Source: AGHT+IHPQqBn66fMpCnO4zjtz0GfR/XByTzzXoFTRA+zE20YJi2c9wq2b5TyhJoNRgaHiqNfbbNcXA== X-Received: by 2002:a05:600c:190a:b0:431:4e73:a515 with SMTP id 5b1f17b1804b1-4319ac9ad38mr69864535e9.3.1730368364380; Thu, 31 Oct 2024 02:52:44 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:44 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 4/7] pipeline: rpi: Introduce CameraData::CropParams Date: Thu, 31 Oct 2024 09:49:54 +0000 Message-Id: <20241031094957.18471-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 | 17 +++++++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 12 ++++++-- 3 files changed, 43 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..88bd603193f4 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -133,8 +133,21 @@ 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_) + { + } + + /* 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 Thu Oct 31 09:49:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21786 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 9E5ECC330C for ; Thu, 31 Oct 2024 09:52:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8C132653AF; Thu, 31 Oct 2024 10:52:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="V69RPKKX"; 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 5CA1E653B1 for ; Thu, 31 Oct 2024 10:52:46 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4315ce4d250so1110695e9.2 for ; Thu, 31 Oct 2024 02:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368365; x=1730973165; 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=m+HMPpTvzYXkSdblmG4sRCzch1p6qCvF2EX9uYU6P/c=; b=V69RPKKXF2BW8FsHwomgaEnlEQ0VDPeWFi52N/fpBxfd4TGE6sA6By/ftFHZnktW3K 7ox8NHMjhHwCa29a+Y0rVkQZvKLgJMvYyaLKR7f20WTMOaI529HCffIa6lOnnvBO4jgE LdejEzXCNFdJaFxVxJ+AC6Brf2UTh6NY+ScbgYpimup/LQtDWGutvkPMbwbYWnfEakXO X9Bvggt2zzunVBlLl0K72qZmWWH6UizYwXOTBCg6Lr3eolWa7OGJcuQdW6nr9rqzRATN sWK+Oa8PKX9yfoC5tpw/wn6rG3W7uc+o5rElkmZNGLwj+rlQbIJm9P/TX3iGRzmsIDdc LPAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368365; x=1730973165; 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=m+HMPpTvzYXkSdblmG4sRCzch1p6qCvF2EX9uYU6P/c=; b=ezB2egE3kMrm+v9Nv3As3M2e99qiu5NlHv4Lm8ZhtUr67pRor9TelhdmQyVxyCiq8w 3tcmKD6eKa9fgQusEyVIFiYRyoPCtpcOWSYX33G3edbhhRvSs/LJyEnYKpEagHOP4xgw KtgMr3LvL1nvfeNalRqS5sIANO7N5EFGOpralHSyzV1Nnpawj2MxkQeT/mZQRwtwyFcm zyfoAc/DFmYOtLKCJ6O4ovXTU2k8TR3O9V7AzlfWM16AgR7F/9dHjG4TfliEudy0ZDiU eFm0zgI5VFEQCfXZGxJLBgF5yh4ntfNFrfUr8kKMAB0OVX2KtWvnwJ0q8gRU6ToggpXK f7pw== X-Gm-Message-State: AOJu0Ywf2CWWYwOHD4qCAp8hb5GN0YDE94svEyuJr7N3Ac5NkIVC4QXF QMGqXdmSdwNhH2ZJC/3p6gdZIF4KFZx17eksS2krnDY6/GT0PJ1lpfm4RxfUBeSAmxT3hPmokMp m X-Google-Smtp-Source: AGHT+IGTxlcZIevLQcruaS0eSC8GVIDqQMmKIGOgNrbEHrrIBm8FFcL8dvZj5tXfimS28lgTCMPC2Q== X-Received: by 2002:a05:600c:4fd4:b0:42c:aeee:e604 with SMTP id 5b1f17b1804b1-4319ad41ba8mr69907905e9.8.1730368365060; Thu, 31 Oct 2024 02:52:45 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:44 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 5/7] pipeline: rpi: Track which ISP output is configured for a stream Date: Thu, 31 Oct 2024 09:49:55 +0000 Message-Id: <20241031094957.18471-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 88bd603193f4..9912796ec472 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_) { } @@ -144,6 +144,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 Thu Oct 31 09:49:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21787 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 967ADC330D for ; Thu, 31 Oct 2024 09:52:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 79F5A653BA; Thu, 31 Oct 2024 10:52:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SBro7SQL"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C19ED653B2 for ; Thu, 31 Oct 2024 10:52:46 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4315b957ae8so840205e9.1 for ; Thu, 31 Oct 2024 02:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368366; x=1730973166; 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=KemNgYMBW8186eLynbOGC1vQGWAH0T0PqLUvHvsVvSM=; b=SBro7SQLZlnSTSI/wNKPWehrMz8MkjH3roMTcXUfOHX/4xn+T3GMek0/dzKzJBuicZ W5QjyKMpyYUZv6lK1lIK0FP6amTclI6uxzb0HzpMuAbSyZVKSqfqRu2ZYkv1ToTLnxik iTqJ2LnCdV9ULtXBHw9AE3U6bu/QjpqiLm3hbyWxm4LTL1Mf8eNZfH8bdxhDxWENXa5Z 7vUCLbwatgiMplCAQtbMtk1nmAqiQlRz3KesJdeGaewkfBTcv5D73+rzVOm1H4CvqZRT JOa3NG/gxLSET74Y7v3G/YbXp1bpDGLbpK+ZU4MiWTYS52JsfuObwzAmK+H/XQ5vKWpn 8ZMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368366; x=1730973166; 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=KemNgYMBW8186eLynbOGC1vQGWAH0T0PqLUvHvsVvSM=; b=OzT6oSq/rPaA50x4LscwZ0jsIfnmvvm8apUrbVGr9zNnyJ1E5q4+XUdJ4/yqiLMB4z 6ZB7SNwWTrrk21AGtUgO/ndAXydOreYwbPnSWBmURHmhttLZNDTFUKQJokK0/Qo4oGR4 X+SWtogP4x2M2N5YHoiWKKVVDp8Zue/oFIVkkHWAKoU8JLA2RX8P8doDvvlHNkric+4i 3lB6mIUUOZo3QLMj0KR5Xoc9eWvWkatCYUtI6AcU8XACiQ+FcWbd1quieBYWxUU3pL7K kqqJS7k29AgjFI3jlrwMd/yKXqYFQf4l/WWotzj/9QQTteZ2SwXo70IiHMUAkw1GzaGo daqw== X-Gm-Message-State: AOJu0Yxk9lXCGibzVYZjITGJwlJmVFzkR//ZsP3cJ/8+LajClwNbF0bc 24Ej+/5i/8DanRdPcBul2xSUdDjhLDYnL9r7k2H2/UqlwcopoHZ6hUt6ZSyd2Bj44FF02ZGdZ0m i X-Google-Smtp-Source: AGHT+IEzAw/J1YRG6wiA44boXhNlJSqttOw0iEQtR2qF9W2XLUsukVSZZ9XzGhDnUVhpMjcvlZtNTA== X-Received: by 2002:a05:600c:3b9e:b0:430:52ec:1e2a with SMTP id 5b1f17b1804b1-4319ad3ea5cmr72784735e9.7.1730368365924; Thu, 31 Oct 2024 02:52:45 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:45 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v4 6/7] pipeline: rpi: Pass ISP output index into platformSetIspCrop() Date: Thu, 31 Oct 2024 09:49:56 +0000 Message-Id: <20241031094957.18471-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 9912796ec472..aae0c2f35888 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 Thu Oct 31 09:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21788 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 72B8AC3292 for ; Thu, 31 Oct 2024 09:52:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 981E6653AB; Thu, 31 Oct 2024 10:52:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="O8hLKb+5"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6759F653A9 for ; Thu, 31 Oct 2024 10:52:47 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4314e64eba4so422625e9.2 for ; Thu, 31 Oct 2024 02:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1730368367; x=1730973167; 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=X/8CZh5p/MrzA7UDIgjfjtdpHXu5yfJKtsg4HkJ59cg=; b=O8hLKb+5Y7EerScYKo5vM51IlMJaKU0Mj770Oks+xzoJsXOc1A2CbbwTtcCXoVSdJ/ kkh9wDhGLkYq+sUeCsD4/IveBP8iiHsn63eqfg0aWD8GFUQpEL5Z+TKsT25GQ7etoAoR lDDfWkaTqPu/5Bg5a1UFRn0XNLDyImfxJU2XVPAcGL361vNPUXVy7+c+ZLav28HANzis Ix5H89pePuKJ5jCmip8at/CoU1VJCcxGt1A60uVhTab2d8MB3oi7GPZs1bXjE5wK2YbE NrMGn5CpNgnh04y07/Hiz3dnQYo5iAfwTkrilMTJ3Iy+jM4aSvSf+b4v8yWWeC12vQrV g5ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730368367; x=1730973167; 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=X/8CZh5p/MrzA7UDIgjfjtdpHXu5yfJKtsg4HkJ59cg=; b=Il7wJO/iwOeghDPk7fpLOABBnuKl3begi6cl9kOA+pBLqTS/NYDgK3NmnAOiNB1djU Dq80ZhrM3nMndLBiCh9F67CfpVrGWs8OE1n30bmb7L17kMUErnL2StAfvKhJTepiz2yl YOQWtfgDB7AO6kA/XlZpXqOoHVSLnpt04oh02iJ/+EEQInwGy19a9jbxqy/KjoDdUCOv sKXcPnn7hpb+zJaBVWSzgqVFIj9sHaHasFnS5mbSaulCwPlx14s+a0cSC2Gy/2W+tAW7 HFwOmQdG7SQyb9X0U5jT8k4kPo4DoJX64xY/OH1XnYRTHm3aJy4pzk0I9/zIGci9e+VM uBdQ== X-Gm-Message-State: AOJu0Yz3dNWWL1H5EknGA5BfndOpktxgtMjgr8lQhQlII/HmtO4eGSpx mqAL/Zi71+G7fcLmRTn8EWjgXio/hHQ/WKbu9w4RjYRan6/80cJE9DugXKKtqaEBjkbNfY0fPlO u X-Google-Smtp-Source: AGHT+IHN9Tr5riV7Xf/eKQ+hy/AFqibJtE81+OejXMClrP3o/L969b/O1/uXi2K08gokgEqvFGI5dQ== X-Received: by 2002:a05:600c:3b9e:b0:42c:b55f:f4f with SMTP id 5b1f17b1804b1-4319ad4094emr72052595e9.6.1730368366594; Thu, 31 Oct 2024 02:52:46 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 02:52:46 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Jacopo Mondi Subject: [PATCH v4 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops Date: Thu, 31 Oct 2024 09:49:57 +0000 Message-Id: <20241031094957.18471-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031094957.18471-1-naush@raspberrypi.com> References: <20241031094957.18471-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 latter takes priority over the former. If only controls::ScalerCrop is provided, the pipeline handler 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 Reviewed-by: Laurent Pinchart --- .../pipeline/rpi/common/pipeline_base.cpp | 77 +++++++++++++++---- 1 file changed, 60 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..917c45b3f052 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_.at(0).ispCrop), + data->scaleIspCrop(data->cropParams_.at(1).ispCrop), + ctrlMap[&controls::ScalerCrop].def()); + } } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1295,11 +1311,30 @@ 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::rpi::ScalerCrops is preset, 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. Otherwise + * if controls::ScalerCrop is present, apply the same crop to all ISP + * output streams. + */ + 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 +1350,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_.at(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_.at(i).ispCrop) { + cropParams_.at(i).ispCrop = ispCrop; + platformSetIspCrop(cropParams_.at(i).ispIndex, ispCrop); } } } @@ -1478,10 +1513,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 */