[libcamera-devel] [PATCH v2] android: camera_capabilities: Adjust minimum frame duration to match FPS

Han-Lin Chen hanlinchen at chromium.org
Tue Apr 26 13:43:30 CEST 2022


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 at 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.
+			 */
+			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



More information about the libcamera-devel mailing list