From patchwork Thu Dec 23 08:01:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15218 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 435B4BF415 for ; Thu, 23 Dec 2021 08:01:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E65D60909; Thu, 23 Dec 2021 09:01:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="V2dr61pd"; 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 595AA60908 for ; Thu, 23 Dec 2021 09:01:51 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id g132so3097458wmg.2 for ; Thu, 23 Dec 2021 00:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1xgOi85a1Kf11O4bZiB4HzBhTUoQ8d1X9czgP0d1Soc=; b=V2dr61pdNkmcA4lKvpZQ0B1STFsYrJ3gmbzqn2i3bOo9/MC7PuqUicgwW6zJuso9Cm J9wbFBv5Ws7GQkhCY2YlOs6VvdiWnk+qS3dKurV6ocm2u57EqC7UyCm60kdGuNMOI5R1 jU0JCPhgebWiXMG4xQl5Ssspn84ie3VVC93bh0hazjgsCd8M/vskymEnr9Ai0fhUcK+h RRiXkXdC7jEWO8YMvq2QiOUUUxx7WWJEU3shF1FbRuCAreXS33q/S9haSGxinKIMikIc HQSjyoM0LMkVJ6gY1hc0ED7ncQefUtnx0jP5MChRDm00bCJAuDfr+5vQdz3xK/ziAfsI FoxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1xgOi85a1Kf11O4bZiB4HzBhTUoQ8d1X9czgP0d1Soc=; b=3gapPzRJvxYXBfv88FOJVeGOlMZaoDgC77JiosGBetiwsDjr2sgut2oeDonh1bxT5h NgmObXCSS9TAMFdt/cnmzZgVDWabrg9UC9tVRz7j+kwxZJzOxAWEavIUQngXysjGUPMS CnWLajUzQbmiVWIktTAoex+OINT1sWbC8S2zJoupgf7Y/xe0tn+Uu4cEsxWC8/c9GUKm ibZffDlvT/poHZRrKg7bT65MNYeW+79XI1Fw5azMpUMLQHZhhUhT42oQ6SFrk2e5OKV5 PrssopGCwyxotKx+5cT7o/MvQ8cAazGuDnDozoCmGX4E6osOJDys1sxCoUzVsd0/J0/d ZvOw== X-Gm-Message-State: AOAM530VzS5J6u8Zj9RZggwQo04GGpojKC3TntS8NF686TLQc5l/PpCX wNXICxUE5y9tB8ScrbeKXIh1jf4BUCAHZw== X-Google-Smtp-Source: ABdhPJzwYIatLBPU1aVT0B5xP/8SwF8iplS+KWl4vQ0y9OZJ1HwdXmi0xavSsMaioTsezvJ2vyXlZA== X-Received: by 2002:a05:600c:5009:: with SMTP id n9mr907038wmr.162.1640246510594; Thu, 23 Dec 2021 00:01:50 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id a3sm4692730wri.98.2021.12.23.00.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 00:01:50 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 23 Dec 2021 08:01:10 +0000 Message-Id: <20211223080110.9766-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211223080110.9766-1-david.plowman@raspberrypi.com> References: <20211223080110.9766-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] ipa: raspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control when present 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" If the sensor exposes the V4L2_CID_NOTIFY_GAINS controls, assume it wants to be told the colour gains. We want these to be applied as soon as possible so we add a new setSensorControls signal to the IPA which passes these back to the pipeline handler without using the DelayedControls mechanism. Signed-off-by: David Plowman --- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 22 +++++++++++++++++++ .../pipeline/raspberrypi/raspberrypi.cpp | 10 +++++++++ 3 files changed, 33 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index acd3cafe..e7647724 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -123,6 +123,7 @@ interface IPARPiEventInterface { statsMetadataComplete(uint32 bufferId, libcamera.ControlList controls); runIsp(uint32 bufferId); embeddedComplete(uint32 bufferId); + setSensorControls(libcamera.ControlList controls); setIspControls(libcamera.ControlList controls); setDelayedControls(libcamera.ControlList controls); }; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0ed41385..8c20c066 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1061,6 +1061,28 @@ void IPARPi::processStats(unsigned int bufferId) setDelayedControls.emit(ctrls); } + + auto itCtrl = sensorCtrls_.find(V4L2_CID_NOTIFY_GAINS); + if (itCtrl != sensorCtrls_.end()) { + struct AwbStatus awbStatus; + if (rpiMetadata_.Get("awb.status", awbStatus) == 0) { + /* + * This control is a linear gain value where the default is + * defined to correspond to a gain of 1. The order of the gains + * is always B, Gb, Gr, R. + */ + int unity = itCtrl->second.def().get(); + ControlList ctrls(sensorCtrls_); + int32_t gains[4] = { static_cast(awbStatus.gain_b * unity), + unity, unity, + static_cast(awbStatus.gain_r * unity) }; + ControlValue c(Span{ reinterpret_cast(gains), + sizeof(gains) }); + ctrls.set(V4L2_CID_NOTIFY_GAINS, c); + + setSensorControls.emit(ctrls); + } + } } void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b5c687da..59d3bbd8 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -196,6 +196,7 @@ public: void statsMetadataComplete(uint32_t bufferId, const ControlList &controls); void runIsp(uint32_t bufferId); void embeddedComplete(uint32_t bufferId); + void setSensorControls(const ControlList &controls); void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); void setSensorControls(ControlList &controls); @@ -1405,6 +1406,7 @@ int RPiCameraData::loadIPA(ipa::RPi::SensorConfig *sensorConfig) ipa_->statsMetadataComplete.connect(this, &RPiCameraData::statsMetadataComplete); ipa_->runIsp.connect(this, &RPiCameraData::runIsp); ipa_->embeddedComplete.connect(this, &RPiCameraData::embeddedComplete); + ipa_->setSensorControls.connect(this, &RPiCameraData::setSensorControls); ipa_->setIspControls.connect(this, &RPiCameraData::setIspControls); ipa_->setDelayedControls.connect(this, &RPiCameraData::setDelayedControls); @@ -1524,6 +1526,14 @@ void RPiCameraData::embeddedComplete(uint32_t bufferId) handleState(); } +void RPiCameraData::setSensorControls(const ControlList &controls) +{ + ControlList ctrls = controls; + + sensor_->setControls(&ctrls); + handleState(); +} + void RPiCameraData::setIspControls(const ControlList &controls) { ControlList ctrls = controls;