[v5,16/24] ipa: libipa: agc: Better respect frame duration limits
diff mbox series

Message ID 20261029125844.170324-17-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 Oct. 29, 2026, 12:58 p.m. UTC
Only frame durations that are multiples of the line duration are possible,
and currently it is possible that a smaller frame duration is selected
even if a frame duration satisfying the requested limits is available.

This is caused by the float -> integer truncation during the calculation. For
(an unrealistic) example, if the exposure time is 24ms, the min frame duration
is 33ms, and the line duration is 2ms, then 32ms will be used as the frame
duration even if e.g. 34 would be allowed by the max frame duration.

So round the result to ensure that if not prevented by the max frame duration
then a value that satisfies the limits is selected.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/ipa/libipa/agc.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jacopo Mondi Oct. 29, 2026, 3:51 p.m. UTC | #1
Hi Barnabás

On Thu, Oct 29, 2026 at 01:58:36PM +0100, Barnabás Pőcze wrote:
> Only frame durations that are multiples of the line duration are possible,
> and currently it is possible that a smaller frame duration is selected
> even if a frame duration satisfying the requested limits is available.
>
> This is caused by the float -> integer truncation during the calculation. For
> (an unrealistic) example, if the exposure time is 24ms, the min frame duration
> is 33ms, and the line duration is 2ms, then 32ms will be used as the frame
> duration even if e.g. 34 would be allowed by the max frame duration.
>
> So round the result to ensure that if not prevented by the max frame duration
> then a value that satisfies the limits is selected.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  src/ipa/libipa/agc.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
> index 3090a0073b..05ca0ad2d0 100644
> --- a/src/ipa/libipa/agc.cpp
> +++ b/src/ipa/libipa/agc.cpp
> @@ -1103,7 +1103,8 @@ void AgcAlgorithm::processFrameDuration(const agc::Session &session,
>  	 * the minimum frame duration when we have short exposures.
>  	 */
>  	const auto frameLength = std::max<uint32_t>(
> -		frameContext.minFrameDuration / lineDuration,
> +		std::min(std::ceil(frameContext.minFrameDuration / lineDuration),
> +			 frameContext.maxFrameDuration / lineDuration),

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

>  		frameContext.exposure);
>
>  	frameContext.vblank = frameLength - session.sensor.outputSize.height;
> --
> 2.56.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp
index 3090a0073b..05ca0ad2d0 100644
--- a/src/ipa/libipa/agc.cpp
+++ b/src/ipa/libipa/agc.cpp
@@ -1103,7 +1103,8 @@  void AgcAlgorithm::processFrameDuration(const agc::Session &session,
 	 * the minimum frame duration when we have short exposures.
 	 */
 	const auto frameLength = std::max<uint32_t>(
-		frameContext.minFrameDuration / lineDuration,
+		std::min(std::ceil(frameContext.minFrameDuration / lineDuration),
+			 frameContext.maxFrameDuration / lineDuration),
 		frameContext.exposure);
 
 	frameContext.vblank = frameLength - session.sensor.outputSize.height;