From patchwork Thu Jun 30 13:38:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 16478 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 B17C8BE173 for ; Thu, 30 Jun 2022 13:39:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DE2F656B5; Thu, 30 Jun 2022 15:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656596395; bh=McMzxIfktJ6BpbvEaIQ6eK0gr6MearwMemeQxYmrzYk=; 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=jAGIT4XFkICFJPSpSp+439Nn0ddHJUAgOG/jUYn2atGeOmC5hWL4lWzmO+ecClHEd qcm4UQwzok7Iua/AFqRwzs+PHoaO29lCCdDAzGl9HDG/SFlI0RmN55Hf5NihZALIp5 ZJoZ9WUNA4GiAlrQH0vwoADiOdN+4zkNepExMxdrZf6KqHp9pFIUAPBneub8zHzqje CctLrwyLyx7NBAxxDIXQYFa5o91Xkxzc2zhZ+TZHYf/EHKr0eYofdkPD9qlrS0hzKz TnZKf3ihkNQLSiRyXuNFPJiSbvAKnKPqfB5h9muW5uK0bCu1Zzt8npa4MAXLXHNrjK DYusbTSKOEThA== Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 72B75656B1 for ; Thu, 30 Jun 2022 15:39:48 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 412D3240003; Thu, 30 Jun 2022 13:39:45 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 15:38:59 +0200 Message-Id: <20220630133902.321099-21-jacopo@jmondi.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220630133902.321099-1-jacopo@jmondi.org> References: <20220630133902.321099-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 20/23] ipa: ipu3: Make algorithms use 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" Move the IPU3 IPA module and the AGC algorithm to use libcamera controls instead of computing V4L2 control values. Signed-off-by: Jacopo Mondi --- src/ipa/ipu3/algorithms/agc.cpp | 12 +++--------- src/ipa/ipu3/ipu3.cpp | 15 ++++++--------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index f16be534dd71..d1bbf2a753e9 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -186,11 +186,6 @@ utils::Duration Agc::filterExposure(utils::Duration exposureValue) void Agc::computeExposure(IPAContext &context, IPAFrameContext *frameContext, double yGain, double iqMeanGain) { - const IPASessionConfiguration &configuration = context.configuration; - /* Get the effective exposure and gain applied on the sensor. */ - uint32_t exposure = frameContext->sensor.exposure; - double analogueGain = frameContext->sensor.gain; - /* Use the highest of the two gain estimates. */ double evGain = std::max(yGain, iqMeanGain); @@ -201,13 +196,12 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext *frameContext, /* extracted from Rpi::Agc::computeTargetExposure */ - /* Calculate the shutter time in seconds */ - utils::Duration currentShutter = exposure * configuration.sensor.lineDuration; - /* * Update the exposure value for the next computation using the values * of exposure and gain really used by the sensor. */ + double analogueGain = frameContext->sensor.gain; + utils::Duration currentShutter = frameContext->sensor.exposure * 1.0us; utils::Duration effectiveExposureValue = currentShutter * analogueGain; LOG(IPU3Agc, Debug) << "Actual total exposure " << currentShutter * analogueGain @@ -250,7 +244,7 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext *frameContext, IPAActiveState &activeState = context.activeState; /* Update the estimated exposure and gain. */ - activeState.agc.exposure = shutterTime / configuration.sensor.lineDuration; + activeState.agc.exposure = shutterTime.get(); activeState.agc.gain = stepGain; } diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index f2e28c06a2c2..6d622b4c290b 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -476,8 +476,8 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, if (frameContext.frame != frame) LOG(IPAIPU3, Warning) << "Frame " << frame << " does not match its frame context"; - frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); - frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); + frameContext.sensor.exposure = sensorControls.get(controls::internal::ExposureTime); + frameContext.sensor.gain = sensorControls.get(controls::internal::AnalogueGain); /* Run algorithms on the statistics and per-frame context. */ Span mem = it->second.planes()[0]; @@ -500,7 +500,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, metadata.set(controls::FrameDuration, frameDuration); metadata.set(controls::AnalogueGain, frameContext.sensor.gain); metadata.set(controls::ColourTemperature, context_.activeState.awb.temperatureK); - metadata.set(controls::ExposureTime, frameContext.sensor.exposure * lineDuration); + metadata.set(controls::ExposureTime, frameContext.sensor.exposure); /* * \todo The Metadata provides a path to getting extended data @@ -538,12 +538,9 @@ void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls) */ void IPAIPU3::setControls(unsigned int frame, const IPAActiveState &state) { - int32_t exposure = state.agc.exposure; - int32_t gain = camHelper_->gainCode(state.agc.gain); - - ControlList ctrls(controls::controls); - ctrls.set(V4L2_CID_EXPOSURE, exposure); - ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain); + ControlList ctrls(controls::internal::controls); + ctrls.set(controls::internal::ExposureTime, state.agc.exposure); + ctrls.set(controls::internal::AnalogueGain, static_cast(state.agc.gain)); ControlList lensCtrls(controls::controls); lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,