| Message ID | 20261026132045.269007-16-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
Hi Barnabás On Mon, Oct 26, 2026 at 02:20:37PM +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 40cc4e26d0..af5c179db6 100644 > --- a/src/ipa/libipa/agc.cpp > +++ b/src/ipa/libipa/agc.cpp > @@ -1107,7 +1107,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), Two questions: 1) do not we guarantee already that frameContext.maxFrameDuration > frameContext.minFrameDuration ? IOW: do you need to std::min() 2) Doesn't frameContext.maxFrameDuration / lineDuration), suffer from the same rounding error of frameContext.minFrameDuration / lineDuration), IOW: should you ceil() this one as well ? Also, should we std::ceil() or std::round() ? Thanks j > frameContext.exposure); > > frameContext.vblank = frameLength - session.sensor.outputSize.height; > -- > 2.56.0 >
2026. 10. 27. 9:35 keltezéssel, Jacopo Mondi írta: > Hi Barnabás > > On Mon, Oct 26, 2026 at 02:20:37PM +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 40cc4e26d0..af5c179db6 100644 >> --- a/src/ipa/libipa/agc.cpp >> +++ b/src/ipa/libipa/agc.cpp >> @@ -1107,7 +1107,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), > > Two questions: > 1) do not we guarantee already that frameContext.maxFrameDuration > > frameContext.minFrameDuration ? IOW: do you need to std::min() The `std::min()` is needed because of the `std::ceil()`, it is guaranteed that maxFrameDuration >= minFrameDuration but even in that case ceil(minFrameDuration / lineDuration) > (maxFrameDuration / lineDuration) is entirely possible. > > 2) Doesn't > > frameContext.maxFrameDuration / lineDuration), > > suffer from the same rounding error of > > frameContext.minFrameDuration / lineDuration), > > IOW: should you ceil() this one as well ? > > Also, should we std::ceil() or std::round() ? Yes, but that's fine. Technically one would want to select the smallest possible duration between ceil(minFrameDuration / lineDuration) # no. of lines and floor(maxFrameDuration / lineDuration) # no. of lines (this is effectively the same as `(maxFrameDuration / lineDuration` truncated to an integer) but this is not always possible, for example, if the `FrameDurationLimits` designates a range that contains no multiples of `lineDuration`. So the logic is: * try to use `ceil(minFrameDuration / lineDuration)`, which is the smallest value no lower than the lower bound, (1st arg of min) * but do not go above `maxFrameDuration / lineDuration` in any case. (2nd arg of min) Does this make it clearer? > > Thanks > j > > >> frameContext.exposure); >> >> frameContext.vblank = frameLength - session.sensor.outputSize.height; >> -- >> 2.56.0 >>
Hi Barnabás On Tue, Oct 27, 2026 at 09:43:55AM +0100, Barnabás Pőcze wrote: > 2026. 10. 27. 9:35 keltezéssel, Jacopo Mondi írta: > > Hi Barnabás > > > > On Mon, Oct 26, 2026 at 02:20:37PM +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 40cc4e26d0..af5c179db6 100644 > > > --- a/src/ipa/libipa/agc.cpp > > > +++ b/src/ipa/libipa/agc.cpp > > > @@ -1107,7 +1107,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), > > > > Two questions: > > 1) do not we guarantee already that frameContext.maxFrameDuration > > > frameContext.minFrameDuration ? IOW: do you need to std::min() > > The `std::min()` is needed because of the `std::ceil()`, it is guaranteed that > > maxFrameDuration >= minFrameDuration > > but even in that case > > ceil(minFrameDuration / lineDuration) > (maxFrameDuration / lineDuration) > > is entirely possible. > especially if minFrameDuration == maxFrameDuration > > > > 2) Doesn't > > > > frameContext.maxFrameDuration / lineDuration), > > > > suffer from the same rounding error of > > > > frameContext.minFrameDuration / lineDuration), > > > > IOW: should you ceil() this one as well ? > > > > Also, should we std::ceil() or std::round() ? > > Yes, but that's fine. Technically one would want to select the smallest possible duration between > > ceil(minFrameDuration / lineDuration) # no. of lines > > and > > floor(maxFrameDuration / lineDuration) # no. of lines > (this is effectively the same as `(maxFrameDuration / lineDuration` truncated to an integer) > > but this is not always possible, for example, if the `FrameDurationLimits` designates a > range that contains no multiples of `lineDuration`. > > So the logic is: > > * try to use `ceil(minFrameDuration / lineDuration)`, which is the smallest value no lower than the lower bound, (1st arg of min) > * but do not go above `maxFrameDuration / lineDuration` in any case. (2nd arg of min) > > Does this make it clearer? > Yes thanks. Maybe record it with a few lines in the comment above the hunk you modified With that, if you consider it appropriate Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Thanks j > > > > > Thanks > > j > > > > > > > frameContext.exposure); > > > > > > frameContext.vblank = frameLength - session.sensor.outputSize.height; > > > -- > > > 2.56.0 > > > >
diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp index 40cc4e26d0..af5c179db6 100644 --- a/src/ipa/libipa/agc.cpp +++ b/src/ipa/libipa/agc.cpp @@ -1107,7 +1107,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;
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(-)