From patchwork Thu Aug 18 09:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 17171 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 D1ACAC3272 for ; Thu, 18 Aug 2022 09:44:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 83F6361FA5; Thu, 18 Aug 2022 11:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660815885; bh=pbJvaxzfAzsk5G/K0+kuggQbpVvmu2trmNSewJgtmkE=; 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=22lzGsWEGTuKoVgH2XxbyrblOtZRH5vkjzrj5VsIDzZIMggySrsQxWr/q2QGUto1j Z8vwTgOIha/bTeIu/siC+wJiRL11STSfs6RZKkevGVbCc3a6mKTeMQ1CTeKUv1Zzcm AyATE8dxNQob9jLqNnA4D0Vynon4EZXMnRxvZJpKOoOgkIFr3K3YScB6hDjbMD006l 4JRUfASunssDP9gq2Ak2F0E7wI5EVCKIjVG4/4DoFdkNpxij/TgZBh9q7AhCTM05bU mtYUHq3vGxb712hwpxXwrJGWtEoQYyszn/V/JZdrkXZyBPeovev19Mh4tfw0DhOcvK IS5GrTg9r0oHg== Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A1ACA61FD3 for ; Thu, 18 Aug 2022 11:44:39 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id D3313FF802; Thu, 18 Aug 2022 09:44:38 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Thu, 18 Aug 2022 11:44:09 +0200 Message-Id: <20220818094410.1671-17-jacopo@jmondi.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220818094410.1671-1-jacopo@jmondi.org> References: <20220818094410.1671-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 16/17] ipa: ipu3: Store configuration data in context 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" The IPU3 IPA module stores per-configuration session data, such as the sensor and lens controls and the sensor information, in class member variables. As the IPAContext structure has exactly a place for session-specific configuration data, move those information in the context_ and remove them from the class. Signed-off-by: Jacopo Mondi --- src/ipa/ipu3/ipa_context.cpp | 15 ++++++++++ src/ipa/ipu3/ipa_context.h | 6 ++++ src/ipa/ipu3/ipu3.cpp | 54 ++++++++++++++++-------------------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index 536d76ecd63b..3c6f470e7f25 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -114,6 +114,21 @@ namespace libcamera::ipa::ipu3 { * \brief The default vblank value of the sensor */ +/** + * \var IPASessionConfiguration::sensorCtrls + * \brief The list of V4L2 sensor controls limits + */ + +/** + * \var IPASessionConfiguration::lensCtrls + * \brief The list of V4L2 lens controls limits + */ + +/** + * \var IPASessionConfiguration::sensorInfo + * \brief The sensor configuration for the streaming session + */ + /** * \var IPAActiveState::agc * \brief Context for the Automatic Gain Control algorithm diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index c4aa4c3f4f6a..2629d0db9f9a 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -15,6 +15,8 @@ #include #include +#include + #include namespace libcamera { @@ -43,6 +45,10 @@ struct IPASessionConfiguration { int32_t defVBlank; utils::Duration lineDuration; } sensor; + + ControlInfoMap sensorCtrls; + ControlInfoMap lensCtrls; + IPACameraSensorInfo sensorInfo; }; struct IPAActiveState { diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index dd9d21e4df52..6d40f3d0cd9e 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -172,11 +172,6 @@ private: std::map buffers_; - ControlInfoMap sensorCtrls_; - ControlInfoMap lensCtrls_; - - IPACameraSensorInfo sensorInfo_; - /* Interface to the Camera Helper */ std::unique_ptr camHelper_; @@ -209,7 +204,7 @@ int IPAIPU3::init(const IPASettings &settings, return -ENODEV; } - /* Clean context */ + /* Clean context. */ context_.configuration = {}; /* Load the tuning data file. */ @@ -379,7 +374,6 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo, ControlInfoMap *ipaControls) { ControlInfoMap::Map controls{}; - double lineDuration = context_.configuration.sensor.lineDuration.get(); /* * Compute exposure time limits by using line length and pixel rate @@ -388,6 +382,7 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo, * microseconds. */ const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second; + double lineDuration = sensorInfo.lineLength / sensorInfo.pixelRate; int32_t minExposure = v4l2Exposure.min().get() * lineDuration; int32_t maxExposure = v4l2Exposure.max().get() * lineDuration; int32_t defExposure = v4l2Exposure.def().get() * lineDuration; @@ -431,9 +426,22 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo, */ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo) { - const IPACameraSensorInfo &sensorInfo = configInfo.sensorInfo; - const ControlInfoMap &sensorControls = configInfo.sensorControls; + /* Clear and intialize the IPA context before the streaming session. */ + context_.frameContexts.clear(); + context_ = {}; + + context_.configuration.sensorCtrls = configInfo.sensorControls; + context_.configuration.lensCtrls = configInfo.lensControls; + context_.configuration.sensorInfo = configInfo.sensorInfo; + /* + * When the AGC computes the new exposure values for a frame, it needs + * to know the limits for shutter speed and analogue gain. + * As it depends on the sensor, update it with the controls. + * + * \todo take VBLANK into account for maximum shutter speed + */ + const ControlInfoMap &sensorControls = configInfo.sensorControls; const ControlInfo vBlank = sensorControls.find(V4L2_CID_VBLANK)->second; context_.configuration.sensor.defVBlank = vBlank.def().get(); @@ -445,19 +453,8 @@ void IPAIPU3::updateSessionConfiguration(const IPAConfigInfo &configInfo) int32_t minGain = v4l2Gain.min().get(); int32_t maxGain = v4l2Gain.max().get(); - /* Clear the IPA context before the streaming session. */ - context_.frameContexts.clear(); - context_ = {}; - - /* - * When the AGC computes the new exposure values for a frame, it needs - * to know the limits for shutter speed and analogue gain. - * As it depends on the sensor, update it with the controls. - * - * \todo take VBLANK into account for maximum shutter speed - */ - context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s - / sensorInfo.pixelRate; + context_.configuration.sensor.lineDuration = configInfo.sensorInfo.lineLength * 1.0s + / configInfo.sensorInfo.pixelRate; context_.configuration.agc.minShutterSpeed = minExposure * context_.configuration.sensor.lineDuration; context_.configuration.agc.maxShutterSpeed = maxExposure * context_.configuration.sensor.lineDuration; context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain); @@ -487,14 +484,10 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, return -EINVAL; } - sensorCtrls_ = configInfo.sensorControls; - sensorInfo_ = configInfo.sensorInfo; - lensCtrls_ = configInfo.lensControls; - calculateBdsGrid(configInfo.bdsOutputSize); /* Update the camera controls using the new sensor settings. */ - updateControls(sensorInfo_, sensorCtrls_, ipaControls); + updateControls(configInfo.sensorInfo, configInfo.sensorControls, ipaControls); /* Update the IPASessionConfiguration using the sensor settings. */ updateSessionConfiguration(configInfo); @@ -618,7 +611,8 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, setControls(frame); /* \todo Use VBlank value calculated from each frame exposure. */ - int64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration; + const IPACameraSensorInfo &sensorInfo = context_.configuration.sensorInfo; + int64_t frameDuration = (vBlank + sensorInfo.outputSize.height) * lineDuration; ctrls.set(controls::FrameDuration, frameDuration); ctrls.set(controls::AnalogueGain, frameContext.sensor.gain); @@ -667,11 +661,11 @@ void IPAIPU3::setControls(unsigned int frame) int32_t exposure = context_.activeState.agc.exposure; int32_t gain = camHelper_->gainCode(context_.activeState.agc.gain); - ControlList ctrls(sensorCtrls_); + ControlList ctrls(context_.configuration.sensorCtrls); ctrls.set(V4L2_CID_EXPOSURE, exposure); ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain); - ControlList lensCtrls(lensCtrls_); + ControlList lensCtrls(context_.configuration.lensCtrls); lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(context_.activeState.af.focus));