From patchwork Mon Jun 27 16:27:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 16395 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 33D79BD808 for ; Mon, 27 Jun 2022 16:28:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C2BA26564F; Mon, 27 Jun 2022 18:28:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656347284; bh=xWarKmTw0az9pmRqeB1pNq0yAC4/im7vDuKrVEzDcl4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fMpii3qcE/qhqGM+2rVfYpFZKBxvAz8zYFgQAtJ4njbLzUZt5BYbTnxl9g5chE31l PA9lmxuPs9Wt5dtwMRaCTGp29G8NOslxMHYopgGI9hb49p+ZbV2pkMdTFyAhBzkmiU 8M1veIfJ/WKHTH4pR2qL4Vsoo3fB521GqNNvRTc6/AaivWUd0QF+4EpoifjhxjiQNI IIsVN8LvjX2cOFjyMy2IWl8UDnR7zGMzqVBhQyn9n5QdSqV8b6lUf66uk2904BpZSX 3ptZd/qYnjhmS99azCRRPfe1XJvL1pRBc0k8EvBTekuHTmZnD4ws7B7lrj8ZI7s0Y5 KYrsVA7MTJG/g== Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EE5D65635 for ; Mon, 27 Jun 2022 18:27:54 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id B172B20004; Mon, 27 Jun 2022 16:27:53 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Jun 2022 18:27:31 +0200 Message-Id: <20220627162732.33160-15-jacopo@jmondi.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627162732.33160-1-jacopo@jmondi.org> References: <20220627162732.33160-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 14/15] ipa: ipu3: Configure IPA with libcamera controls 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Pass to the IPA configure() function the list of libcamera controls::internal controls in place of sending to the IPA the raw V4L2 control values. As the controls::internal::ExposureTime is already expressed in micro-seconds, there's not need to multiply by the line duration. AnalogueGain still requires translation using the CameraSensorHelper class. While at it, rationalize the sequence of operations IPA::configure() to: - check the validity of the configuration - update the session configuration - configure algorithm - assign class member variables Signed-off-by: Jacopo Mondi --- src/ipa/ipu3/ipu3.cpp | 67 ++++++++++++---------------- src/libcamera/pipeline/ipu3/ipu3.cpp | 2 +- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 1f80a10bc48d..b67ff1948bc2 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -150,7 +150,7 @@ public: private: void updateSessionConfiguration(const IPAConfigInfo &info); - bool validateSensorControls(); + bool validateConfiguration(const IPAConfigInfo &config); void setControls(unsigned int frame); void calculateBdsGrid(const Size &bdsOutputSize); @@ -183,16 +183,6 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info) context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate; - const ControlInfoMap &sensorControls = info.sensorControls; - - const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second; - int32_t minExposure = v4l2Exposure.min().get(); - int32_t maxExposure = v4l2Exposure.max().get(); - - const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second; - int32_t minGain = v4l2Gain.min().get(); - int32_t maxGain = v4l2Gain.max().get(); - /* * When the AGC computes the new exposure values for a frame, it needs * to know the limits for shutter speed and analogue gain. @@ -200,8 +190,16 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info) * * \todo take VBLANK into account for maximum shutter speed */ - context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration; - context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration; + const ControlInfoMap &sensorControls = info.sensorControls; + + const auto &[expId, exposure] = *sensorControls.find(&controls::internal::ExposureTime); + context_.configuration.agc.minShutterSpeed = exposure.min().get() * 1.0us; + context_.configuration.agc.maxShutterSpeed = exposure.max().get() * 1.0us; + + const auto &[gainId, gain] = *sensorControls.find(&controls::internal::draft::SensorAnalogueGain); + int32_t minGain = gain.min().get(); + int32_t maxGain = gain.max().get(); + context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain); context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain); } @@ -209,18 +207,18 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &info) /** * \brief Validate that the sensor controls mandatory for the IPA exists */ -bool IPAIPU3::validateSensorControls() +bool IPAIPU3::validateConfiguration(const IPAConfigInfo &config) { - static const uint32_t ctrls[] = { - V4L2_CID_ANALOGUE_GAIN, - V4L2_CID_EXPOSURE, - V4L2_CID_VBLANK, + static constexpr std::array ctrls = { + &controls::internal::ExposureTime, + &controls::internal::FrameDuration, + &controls::internal::draft::SensorAnalogueGain, }; - for (auto c : ctrls) { - if (sensorCtrls_.find(c) == sensorCtrls_.end()) { + for (const ControlId *c : ctrls) { + if (config.sensorControls.find(c) == config.sensorControls.end()) { LOG(IPAIPU3, Error) << "Unable to find sensor control " - << utils::hex(c); + << c->name(); return false; } } @@ -369,30 +367,19 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo) return -ENODATA; } - sensorInfo_ = configInfo.sensorInfo; - - lensCtrls_ = configInfo.lensControls; - - /* - * Compute the sensor V4L2 controls to be used by the algorithms and - * to be set on the sensor. - */ - sensorCtrls_ = configInfo.sensorControls; - - calculateBdsGrid(configInfo.bdsOutputSize); + if (!validateConfiguration(configInfo)) { + LOG(IPAIPU3, Error) << "Sensor control validation failed."; + return -EINVAL; + } /* Clean IPAActiveState at each reconfiguration. */ context_.activeState = {}; IPAFrameContext initFrameContext; context_.frameContexts.fill(initFrameContext); - if (!validateSensorControls()) { - LOG(IPAIPU3, Error) << "Sensor control validation failed."; - return -EINVAL; - } - - /* Update the IPASessionConfiguration using the sensor settings. */ + /* Update the IPA configuration using the new settings. */ updateSessionConfiguration(configInfo); + calculateBdsGrid(configInfo.bdsOutputSize); for (auto const &algo : algorithms_) { int ret = algo->configure(context_, configInfo); @@ -400,6 +387,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo) return ret; } + sensorInfo_ = configInfo.sensorInfo; + lensCtrls_ = configInfo.lensControls; + sensorCtrls_ = configInfo.sensorControls; + return 0; } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 44e65d9f2d46..8bf51411581a 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -661,7 +661,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) } ipa::ipu3::IPAConfigInfo configInfo; - configInfo.sensorControls = data->cio2_.sensor()->v4l2Controls(); + configInfo.sensorControls = data->cio2_.sensor()->controls(); CameraLens *lens = data->cio2_.sensor()->focusLens(); if (lens)