From patchwork Tue Sep 7 19:41:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13748 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 7CF18BDB1D for ; Tue, 7 Sep 2021 19:40:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E9B169184; Tue, 7 Sep 2021 21:40:45 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A5806917F for ; Tue, 7 Sep 2021 21:40:42 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id D76E9240002; Tue, 7 Sep 2021 19:40:41 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 21:41:07 +0200 Message-Id: <20210907194107.803730-18-jacopo@jmondi.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907194107.803730-1-jacopo@jmondi.org> References: <20210907194107.803730-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 17/17] ipa: ipu3: Cap frame duration to 30 FPS 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" Limit the IPU3 frame rate to 30 FPS. The reason to do is to bring the IPU3 IPA in par with the Intel HAL implementation on IPU3 platform, where 30FPS is the frame rate used to perform quality tuning in the closed-source IPA module and has been validated as the most efficient rate for the power/performace budget. Compute the vertical blanking to maintain such frame rate and configure the sensor with that. Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/ipa/ipu3/ipu3.cpp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index ec75b3ffa305..3480c828ea62 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -183,7 +183,7 @@ private: IPACameraSensorInfo sensorInfo_; /* Camera sensor controls. */ - uint32_t defVBlank_; + uint32_t vBlank_; uint32_t exposure_; uint32_t minExposure_; uint32_t maxExposure_; @@ -257,10 +257,39 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo, frameDurations[i] = frameSize / (sensorInfo.pixelRate / 1000000U); } + /* + * Cap minimum frame duration to 30FPS. + * + * 30 FPS has been validated in the closed source Intel 3A module as the + * most opportune frame rate for quality tuning, and power + * vs performances budget on Intel IPU3. + * + * Reduce the maximum achievable frame rate to 30 FPS and compute the + * vertical blanking to maintain that rate. + */ + int64_t *minFrameDuration = &frameDurations[0]; + if (*minFrameDuration < 1e6 / 30.0) + *minFrameDuration = 1e6 / 30.0; + controls[&controls::FrameDurationLimits] = ControlInfo(frameDurations[0], frameDurations[1], frameDurations[2]); + /* + * Adjust the vertical blanking to obtain the desired frame duration. + * + * Assume a fixed line length as horizontal blanking is seldom + * controllable. + * + * \todo Support making this overridable by the application through + * controls::FrameDuration. + * + * \todo Clamp exposure to frame duration. + */ + vBlank_ = *minFrameDuration * (sensorInfo.pixelRate / 1000000U); + vBlank_ /= lineLength; + vBlank_ -= sensorInfo.outputSize.height; + *ipaControls = ControlInfoMap(std::move(controls), controls::controls); } @@ -399,8 +428,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, maxGain_ = itGain->second.max().get(); gain_ = minGain_; - defVBlank_ = itVBlank->second.def().get(); - /* Clean context at configuration */ context_ = {}; @@ -511,8 +538,7 @@ void IPAIPU3::parseStatistics(unsigned int frame, setControls(frame); - /* \todo Use VBlank value calculated from each frame exposure. */ - int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) / + int64_t frameDuration = sensorInfo_.lineLength * (vBlank_ + sensorInfo_.outputSize.height) / (sensorInfo_.pixelRate / 1e6); ctrls.set(controls::FrameDuration, frameDuration); @@ -534,6 +560,7 @@ void IPAIPU3::setControls(unsigned int frame) ControlList ctrls(ctrls_); ctrls.set(V4L2_CID_EXPOSURE, static_cast(exposure_)); ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain_)); + ctrls.set(V4L2_CID_VBLANK, static_cast(vBlank_)); op.controls = ctrls; queueFrameAction.emit(frame, op);