[libcamera-devel,v2] android: camera_capabilities: Adjust minimum frame duration to match FPS
diff mbox series

Message ID 20220426114330.675768-1-hanlinchen@chromium.org
State Superseded
Headers show
Series
  • [libcamera-devel,v2] android: camera_capabilities: Adjust minimum frame duration to match FPS
Related show

Commit Message

Hanlin Chen April 26, 2022, 11:43 a.m. UTC
CTS calculates FPS with a rounding formula: See
Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()

fps = floor(1e9 / minFrameDuration + 0.05f)

The android adapter reports it as the AE target FPS. The patch adjusts the
reported minimum frame duration to match the reported FPS.

The requirement comes from ChromeOS which only allows the stream configuration
with the minimum frame duration achieves the target FPS.

Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
---
 src/android/camera_capabilities.cpp | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

Jacopo Mondi April 26, 2022, 2:35 p.m. UTC | #1
Hi Han-Lin

On Tue, Apr 26, 2022 at 07:43:30PM +0800, Han-Lin Chen via libcamera-devel wrote:
> CTS calculates FPS with a rounding formula: See
> Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
>
> fps = floor(1e9 / minFrameDuration + 0.05f)
>
> The android adapter reports it as the AE target FPS. The patch adjusts the
> reported minimum frame duration to match the reported FPS.
>
> The requirement comes from ChromeOS which only allows the stream configuration
> with the minimum frame duration achieves the target FPS.
>
> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
> ---
>  src/android/camera_capabilities.cpp | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
> index 55d651f3..5242055c 100644
> --- a/src/android/camera_capabilities.cpp
> +++ b/src/android/camera_capabilities.cpp
> @@ -687,6 +687,21 @@ int CameraCapabilities::initializeStreamConfigurations()
>  					minFrameDuration = minFrameDurationCap;
>  			}
>
> +			/*
> +			 * Calculate FPS as CTS does: see
> +			 * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
> +			 */
> +			unsigned int fps =
> +				static_cast<unsigned int>(floor(1e9 / minFrameDuration + 0.05f));
> +
> +			/*
> +			 * Adjust the minimum frame duration to match the
> +			 * calculated FPS.The requirement comes from ChromeOS
                                         ^ space

> +			 * which only allows the stream configuration with the
> +			 * minimum frame duration achieves the target FPS.

To be honest I would drop the last phrase. We adjust the min frame
duration to match the just calculated fps, regardless of the platform
that requires it.

Anyway, can be adjusted when applying eventually

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> +			 */
> +			minFrameDuration = 1e9 / fps;
> +
>  			streamConfigurations_.push_back({
>  				res, androidFormat, minFrameDuration, maxFrameDuration,
>  			});
> @@ -1287,12 +1302,10 @@ int CameraCapabilities::initializeStaticMetadata()
>  		 * recording profile. Inspecting the Intel IPU3 HAL
>  		 * implementation confirms this but no reference has been found
>  		 * in the metadata documentation.
> -		 *
> -		 * Calculate FPS as CTS does: see
> -		 * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
>  		 */
> -		unsigned int fps = static_cast<unsigned int>
> -				   (floor(1e9 / entry.minFrameDurationNsec + 0.05f));
> +		unsigned int fps =
> +			static_cast<unsigned int>(floor(1e9 / entry.minFrameDurationNsec));
> +
>  		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
>  			continue;
>
> --
> 2.36.0.rc2.479.g8af0fa9b8e-goog
>
Kieran Bingham April 27, 2022, 2:26 p.m. UTC | #2
Quoting Han-Lin Chen via libcamera-devel (2022-04-26 12:43:30)
> CTS calculates FPS with a rounding formula: See
> Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
> 
> fps = floor(1e9 / minFrameDuration + 0.05f)
> 
> The android adapter reports it as the AE target FPS. The patch adjusts the
> reported minimum frame duration to match the reported FPS.
> 
> The requirement comes from ChromeOS which only allows the stream configuration
> with the minimum frame duration achieves the target FPS.
> 
> Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
> ---
>  src/android/camera_capabilities.cpp | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
> index 55d651f3..5242055c 100644
> --- a/src/android/camera_capabilities.cpp
> +++ b/src/android/camera_capabilities.cpp
> @@ -687,6 +687,21 @@ int CameraCapabilities::initializeStreamConfigurations()
>                                         minFrameDuration = minFrameDurationCap;
>                         }
>  
> +                       /*
> +                        * Calculate FPS as CTS does: see
> +                        * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
> +                        */
> +                       unsigned int fps =
> +                               static_cast<unsigned int>(floor(1e9 / minFrameDuration + 0.05f));
> +
> +                       /*
> +                        * Adjust the minimum frame duration to match the
> +                        * calculated FPS.The requirement comes from ChromeOS
> +                        * which only allows the stream configuration with the
> +                        * minimum frame duration achieves the target FPS.

This doesn't quite make sense, (perhaps it was supposed to be 'with the
minimum frame duration which achieves the target FPS') but I think Jacopo
said it may be dropped in his review so I won't worry too much about it.


> +                        */
> +                       minFrameDuration = 1e9 / fps;


Can this calculation be simplified so that we operate only on the
minFrameDuration, and not calculate the FPS from the minFrameDuration,
only to then convert the FPS back to a minFrameDuration?


> +
>                         streamConfigurations_.push_back({
>                                 res, androidFormat, minFrameDuration, maxFrameDuration,
>                         });
> @@ -1287,12 +1302,10 @@ int CameraCapabilities::initializeStaticMetadata()
>                  * recording profile. Inspecting the Intel IPU3 HAL
>                  * implementation confirms this but no reference has been found
>                  * in the metadata documentation.
> -                *
> -                * Calculate FPS as CTS does: see
> -                * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
>                  */
> -               unsigned int fps = static_cast<unsigned int>
> -                                  (floor(1e9 / entry.minFrameDurationNsec + 0.05f));
> +               unsigned int fps =
> +                       static_cast<unsigned int>(floor(1e9 / entry.minFrameDurationNsec));
> +
>                 if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
>                         continue;
>  
> -- 
> 2.36.0.rc2.479.g8af0fa9b8e-goog
>

Patch
diff mbox series

diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
index 55d651f3..5242055c 100644
--- a/src/android/camera_capabilities.cpp
+++ b/src/android/camera_capabilities.cpp
@@ -687,6 +687,21 @@  int CameraCapabilities::initializeStreamConfigurations()
 					minFrameDuration = minFrameDurationCap;
 			}
 
+			/*
+			 * Calculate FPS as CTS does: see
+			 * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
+			 */
+			unsigned int fps =
+				static_cast<unsigned int>(floor(1e9 / minFrameDuration + 0.05f));
+
+			/*
+			 * Adjust the minimum frame duration to match the
+			 * calculated FPS.The requirement comes from ChromeOS
+			 * which only allows the stream configuration with the
+			 * minimum frame duration achieves the target FPS.
+			 */
+			minFrameDuration = 1e9 / fps;
+
 			streamConfigurations_.push_back({
 				res, androidFormat, minFrameDuration, maxFrameDuration,
 			});
@@ -1287,12 +1302,10 @@  int CameraCapabilities::initializeStaticMetadata()
 		 * recording profile. Inspecting the Intel IPU3 HAL
 		 * implementation confirms this but no reference has been found
 		 * in the metadata documentation.
-		 *
-		 * Calculate FPS as CTS does: see
-		 * Camera2SurfaceViewTestCase.java:getSuitableFpsRangeForDuration()
 		 */
-		unsigned int fps = static_cast<unsigned int>
-				   (floor(1e9 / entry.minFrameDurationNsec + 0.05f));
+		unsigned int fps =
+			static_cast<unsigned int>(floor(1e9 / entry.minFrameDurationNsec));
+
 		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
 			continue;