[RFC,v4,18/23] ipa: libipa: agc: Rework frame duration limit calculation
diff mbox series

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

Commit Message

Barnabás Pőcze Oct. 26, 2026, 1:20 p.m. UTC
The frame duration is calculated as `frameHeight * lineDuration`, but
it was effectively repeating the line duration calculation, but with
microsecond precision. Instead, simply reuse the already calculated
line duration, and use the already calculated min/max values in the
provided `IPACameraSensorInfo`.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/agc.cpp | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

Comments

Kieran Bingham Oct. 27, 2026, 11:54 a.m. UTC | #1
Quoting Barnabás Pőcze (2026-10-26 13:20:40)
> The frame duration is calculated as `frameHeight * lineDuration`, but
> it was effectively repeating the line duration calculation, but with
> microsecond precision. Instead, simply reuse the already calculated
> line duration, and use the already calculated min/max values in the
> provided `IPACameraSensorInfo`.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/ipa/libipa/agc.cpp | 31 ++++++++-----------------------
>  1 file changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
> index c68b751ec1..d52d798f8f 100644
> --- a/src/ipa/libipa/agc.cpp
> +++ b/src/ipa/libipa/agc.cpp
> @@ -646,25 +646,6 @@ int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
>                 << "line-duration: " << session.lineDuration << ", "
>                 << "sensor-output: " << session.sensor.outputSize;
>  
> -       /*
> -        * Compute the frame duration limits.
> -        *
> -        * The frame length is computed assuming a fixed line length combined
> -        * with the vertical frame sizes.
> -        */
> -
> -       const ControlInfo &v4l2VBlank = config.sensorControls.find(V4L2_CID_VBLANK)->second;
> -       std::array<uint32_t, 3> frameHeights{
> -               v4l2VBlank.min().get<int32_t>() + config.sensorInfo.outputSize.height,
> -               v4l2VBlank.max().get<int32_t>() + config.sensorInfo.outputSize.height,
> -               v4l2VBlank.def().get<int32_t>() + config.sensorInfo.outputSize.height,
> -       };
> -
> -       std::array<int64_t, 3> frameDurations;
> -       for (unsigned int i = 0; i < frameHeights.size(); ++i) {
> -               uint64_t frameSize = static_cast<uint64_t>(lineLength) * frameHeights[i];
> -               frameDurations[i] = frameSize * 1000000U / config.sensorInfo.pixelRate;
> -       }
>  
>         /*
>          * When the AGC computes the new exposure values for a frame, it needs
> @@ -678,8 +659,8 @@ int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
>         session.minAnalogueGain = minGain;
>         session.maxAnalogueGain = maxGain;
>         session.defAnalogueGain = defGain;
> -       session.minFrameDuration = std::chrono::microseconds(frameDurations[0]);
> -       session.maxFrameDuration = std::chrono::microseconds(frameDurations[1]);
> +       session.minFrameDuration = config.sensorInfo.minFrameLength * session.lineDuration;
> +       session.maxFrameDuration = config.sensorInfo.maxFrameLength * session.lineDuration;
>  
>         /* Configure the default exposure and gain. */
>         state = {};
> @@ -718,8 +699,12 @@ int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
>                 static_cast<int32_t>(defExposure * lineDurationUs),
>         };
>         config.ctrlMap[&controls::FrameDurationLimits] = ControlInfo{
> -               frameDurations[0], frameDurations[1],
> -               std::span<const int64_t, 2>{ { frameDurations[0], frameDurations[1] } },
> +               static_cast<int64_t>(session.minFrameDuration.get<std::micro>()),
> +               static_cast<int64_t>(session.maxFrameDuration.get<std::micro>()),
> +               std::span<const int64_t, 2>{ {
> +                       static_cast<int64_t>(state.minFrameDuration.get<std::micro>()),
> +                       static_cast<int64_t>(state.maxFrameDuration.get<std::micro>()),
> +               } },
>         };
>  
>         const auto add = [&](const ControlId &cid, const auto &automatic, const auto &manual) {
> -- 
> 2.56.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
index c68b751ec1..d52d798f8f 100644
--- a/src/ipa/libipa/agc.cpp
+++ b/src/ipa/libipa/agc.cpp
@@ -646,25 +646,6 @@  int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
 		<< "line-duration: " << session.lineDuration << ", "
 		<< "sensor-output: " << session.sensor.outputSize;
 
-	/*
-	 * Compute the frame duration limits.
-	 *
-	 * The frame length is computed assuming a fixed line length combined
-	 * with the vertical frame sizes.
-	 */
-
-	const ControlInfo &v4l2VBlank = config.sensorControls.find(V4L2_CID_VBLANK)->second;
-	std::array<uint32_t, 3> frameHeights{
-		v4l2VBlank.min().get<int32_t>() + config.sensorInfo.outputSize.height,
-		v4l2VBlank.max().get<int32_t>() + config.sensorInfo.outputSize.height,
-		v4l2VBlank.def().get<int32_t>() + config.sensorInfo.outputSize.height,
-	};
-
-	std::array<int64_t, 3> frameDurations;
-	for (unsigned int i = 0; i < frameHeights.size(); ++i) {
-		uint64_t frameSize = static_cast<uint64_t>(lineLength) * frameHeights[i];
-		frameDurations[i] = frameSize * 1000000U / config.sensorInfo.pixelRate;
-	}
 
 	/*
 	 * When the AGC computes the new exposure values for a frame, it needs
@@ -678,8 +659,8 @@  int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
 	session.minAnalogueGain = minGain;
 	session.maxAnalogueGain = maxGain;
 	session.defAnalogueGain = defGain;
-	session.minFrameDuration = std::chrono::microseconds(frameDurations[0]);
-	session.maxFrameDuration = std::chrono::microseconds(frameDurations[1]);
+	session.minFrameDuration = config.sensorInfo.minFrameLength * session.lineDuration;
+	session.maxFrameDuration = config.sensorInfo.maxFrameLength * session.lineDuration;
 
 	/* Configure the default exposure and gain. */
 	state = {};
@@ -718,8 +699,12 @@  int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state,
 		static_cast<int32_t>(defExposure * lineDurationUs),
 	};
 	config.ctrlMap[&controls::FrameDurationLimits] = ControlInfo{
-		frameDurations[0], frameDurations[1],
-		std::span<const int64_t, 2>{ { frameDurations[0], frameDurations[1] } },
+		static_cast<int64_t>(session.minFrameDuration.get<std::micro>()),
+		static_cast<int64_t>(session.maxFrameDuration.get<std::micro>()),
+		std::span<const int64_t, 2>{ {
+			static_cast<int64_t>(state.minFrameDuration.get<std::micro>()),
+			static_cast<int64_t>(state.maxFrameDuration.get<std::micro>()),
+		} },
 	};
 
 	const auto add = [&](const ControlId &cid, const auto &automatic, const auto &manual) {