[v9,10/18] ipa: libipa: agc: Calculate vblank for correct exposure time
diff mbox series

Message ID 20261111115600.1097488-11-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • ipa: libipa: agc: Take exposure margin into account
Related show

Commit Message

Barnabás Pőcze Nov. 11, 2026, 11:55 a.m. UTC
Adjust `processFrameDuration()` to calculate the vblank and frame duration
based on the exposure time of the frame. This ensures that the gain, exposure
time, and vblank in a frame context are all in sync.

Note, that this still happens too late, but fixing that is postponed to a
later time.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/ipa/libipa/agc.cpp | 27 +++++++++++++--------------
 src/ipa/libipa/agc.h   |  3 +--
 2 files changed, 14 insertions(+), 16 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
index 095d5c8c24..9128aa037f 100644
--- a/src/ipa/libipa/agc.cpp
+++ b/src/ipa/libipa/agc.cpp
@@ -725,7 +725,7 @@  void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state,
 			   ControlList &metadata)
 {
 	if (!params) {
-		processFrameDuration(session, frameContext, frameContext.minFrameDuration);
+		processFrameDuration(session, frameContext);
 		fillMetadata(session, frameContext, metadata);
 		return;
 	}
@@ -829,12 +829,7 @@  void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state,
 		<< "quantization-gain: " << state.automatic.quantizationGain << ", "
 		<< "digital-gain: " << state.automatic.digitalGain;
 
-	/*
-	 * Expand the target frame duration so that we do not run faster than
-	 * the minimum frame duration when we have short exposures.
-	 */
-	processFrameDuration(session, frameContext,
-			     std::max(frameContext.minFrameDuration, newExposureTime));
+	processFrameDuration(session, frameContext);
 
 	fillMetadata(session, frameContext, metadata);
 }
@@ -843,22 +838,26 @@  void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state,
  * \brief Process frame duration and compute vblank
  * \param[in] session The session parameters
  * \param[in] frameContext The current frame context
- * \param[in] frameDuration The target frame duration
  *
  * Compute and populate vblank from the target frame duration.
  */
 void AgcAlgorithm::processFrameDuration(const agc::Session &session,
-					agc::FrameContext &frameContext,
-					utils::Duration frameDuration)
+					agc::FrameContext &frameContext)
 {
 	const utils::Duration &lineDuration = session.lineDuration;
 
-	frameContext.vblank =
-		(frameDuration / lineDuration) - session.sensor.outputSize.height;
+	/*
+	 * Expand the target frame duration so that we do not run faster than
+	 * the minimum frame duration when we have short exposures.
+	 */
+	const auto frameLength = std::max<uint32_t>(
+		frameContext.minFrameDuration / lineDuration,
+		frameContext.exposure);
+
+	frameContext.vblank = frameLength - session.sensor.outputSize.height;
 
 	/* Update frame duration accounting for line length quantization. */
-	frameContext.frameDuration =
-		(session.sensor.outputSize.height + frameContext.vblank) * lineDuration;
+	frameContext.frameDuration = frameLength * lineDuration;
 }
 
 void AgcAlgorithm::fillMetadata(const agc::Session &session,
diff --git a/src/ipa/libipa/agc.h b/src/ipa/libipa/agc.h
index a5700d2625..21b100267f 100644
--- a/src/ipa/libipa/agc.h
+++ b/src/ipa/libipa/agc.h
@@ -154,8 +154,7 @@  public:
 
 private:
 	void processFrameDuration(const agc::Session &session,
-				  agc::FrameContext &frameContext,
-				  utils::Duration frameDuration);
+				  agc::FrameContext &frameContext);
 	void fillMetadata(const agc::Session &session,
 			  const agc::FrameContext &frameContext,
 			  ControlList &metadata);