[libcamera-devel] android: CameraDevice: Report proper min and max frame durations
diff mbox series

Message ID 20210330094941.127664-1-paul.elder@ideasonboard.com
State Accepted
Delegated to: Paul Elder
Headers show
Series
  • [libcamera-devel] android: CameraDevice: Report proper min and max frame durations
Related show

Commit Message

Paul Elder March 30, 2021, 9:49 a.m. UTC
The HAL layer was getting the min and max frame durations from from the
camera, then rounding it to fps to report as available fps ranges. The
same min and max frame durations were then being reported as min and max
frame durations. Since the fps are integer values while the frame
durations are in ns, this caused a rounding error making it seem like we
were reporting an available max fps that was higher than was was allowed
by the minimum frame duration.

Fix this by recalculating the frame durations based on the rounded fps
values.

This allows the following CTS test to pass:
- android.hardware.camera2.cts.SurfaceViewPreviewTest#testPreviewFpsRange

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/android/camera_device.cpp | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Hirokazu Honda March 31, 2021, 6:55 a.m. UTC | #1
Hi Paul, thanks for the patch.

On Tue, Mar 30, 2021 at 6:50 PM Paul Elder <paul.elder@ideasonboard.com> wrote:
>
> The HAL layer was getting the min and max frame durations from from the

nit: durations from the

> camera, then rounding it to fps to report as available fps ranges. The
> same min and max frame durations were then being reported as min and max
> frame durations. Since the fps are integer values while the frame
> durations are in ns, this caused a rounding error making it seem like we
> were reporting an available max fps that was higher than was was allowed
> by the minimum frame duration.
>

It might be nice to have one example of the case.

> Fix this by recalculating the frame durations based on the rounded fps
> values.
>
> This allows the following CTS test to pass:
> - android.hardware.camera2.cts.SurfaceViewPreviewTest#testPreviewFpsRange
>
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  src/android/camera_device.cpp | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 931e9f37..91d4e8d4 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -799,6 +799,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
>                 int32_t minFps = std::round(1e9 / maxFrameDurationNsec);
>                 minFps = std::max(1, minFps);
>
> +               /* Avoid rounding errors when we reuse these variables later */
> +               minFrameDurationNsec = 1e9 / maxFps;
> +               maxFrameDurationNsec = 1e9 / minFps;
> +
>                 /*
>                  * Register to the camera service {min, max} and {max, max}
>                  * intervals as requested by the metadata documentation.
> --
> 2.27.0
>

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 931e9f37..91d4e8d4 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -799,6 +799,10 @@  const camera_metadata_t *CameraDevice::getStaticMetadata()
 		int32_t minFps = std::round(1e9 / maxFrameDurationNsec);
 		minFps = std::max(1, minFps);
 
+		/* Avoid rounding errors when we reuse these variables later */
+		minFrameDurationNsec = 1e9 / maxFps;
+		maxFrameDurationNsec = 1e9 / minFps;
+
 		/*
 		 * Register to the camera service {min, max} and {max, max}
 		 * intervals as requested by the metadata documentation.