[libcamera-devel] [PATCH v3 20/23] ipa: ipu3: Make algorithms use libcamera controls
Jacopo Mondi
jacopo at jmondi.org
Thu Jun 30 15:38:59 CEST 2022
Move the IPU3 IPA module and the AGC algorithm to use libcamera controls
instead of computing V4L2 control values.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
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<std::micro>();
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<int32_t>();
- frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>());
+ 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<uint8_t> 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<float>(state.agc.gain));
ControlList lensCtrls(controls::controls);
lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,
--
2.36.1
More information about the libcamera-devel
mailing list