[v2,06/10] ipa: libipa: agc: Initialize exposure with frame duration
diff mbox series

Message ID 20251028-exposure-limits-v2-6-a8b5a318323e@ideasonboard.com
State New
Headers show
Series
  • libipa: agc: Calculate exposure limits
Related show

Commit Message

Jacopo Mondi Oct. 28, 2025, 9:31 a.m. UTC
The maximum exposure time the AGC algorithm can achieve is, by
definition, limited by the maximum programmed frame duration.

When initializing the AGC algorithm, use the frame duration and the
sensor's exposure margin to calculate the maximum exposure, unless
the IPA has asked for a fixed exposure by setting min == max.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/exposure_mode_helper.cpp | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
index edb8f04b245f01119d0d0b0917d10f98c7172dc0..8f40290959e24294ead008c7228e2f67ffc5adf8 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -106,12 +106,33 @@  void ExposureModeHelper::configure(utils::Duration lineDuration,
 				   const CameraSensorHelper *sensorHelper)
 {
 	lineDuration_ = lineDuration;
-	minExposureTime_ = minExposureTime;
-	maxExposureTime_ = maxExposureTime;
 	maxFrameDuration_ = maxFrameDuration;
 	minGain_ = minGain;
 	maxGain_ = maxGain;
 	sensorHelper_ = sensorHelper;
+
+	minExposureTime_ = minExposureTime;
+
+	/*
+	 * Compute the maximum exposure time.
+	 *
+	 * If maxExposureTime is equal to minExposureTime then we use them
+	 * to fix the exposure time.
+	 *
+	 * Otherwise, if the exposure can range between a min and max, use the
+	 * maxFrameDuration minus the margin as upper limit for exposure
+	 * (capped to the provided max exposure).
+	 */
+	auto margin = sensorHelper_->exposureMargin();
+	if (!margin.has_value()) {
+		LOG(ExposureModeHelper, Warning)
+			<< "Exposure margin not known. Default to 4";
+		margin = { 4 };
+	}
+
+	maxExposureTime_ = minExposureTime != maxExposureTime
+			 ? maxFrameDuration - margin.value() * lineDuration
+			 : minExposureTime;
 }
 
 /**