[libcamera-devel] [PATCH 3/5] android: camera_device: Compute AE frame limits

Jacopo Mondi jacopo at jmondi.org
Thu Jan 21 18:46:31 CET 2021


Compute the Auto-Exposure routine FPS limits using the FrameDurations
control as libcamera clips the AE routine calculations in the frame
durations limits.

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/android/camera_device.cpp | 75 +++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 26 deletions(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index f9af038412b1..aa50a151668d 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -9,6 +9,7 @@
 #include "camera_ops.h"
 #include "post_processor.h"
 
+#include <math.h>
 #include <sys/mman.h>
 #include <tuple>
 #include <vector>
@@ -682,10 +683,10 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()
 {
 	/*
 	 * \todo Keep this in sync with the actual number of entries.
-	 * Currently: 54 entries, 794 bytes of static metadata
+	 * Currently: 54 entries, 802 bytes of static metadata
 	 */
 	uint32_t numEntries = 54;
-	uint32_t byteSize = 794;
+	uint32_t byteSize = 802;
 
 	/*
 	 * Calculate space occupation in bytes for dynamically built metadata
@@ -760,12 +761,34 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
 				  aeAvailableModes.data(),
 				  aeAvailableModes.size());
 
-	std::vector<int32_t> availableAeFpsTarget = {
-		15, 30,
-	};
-	staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
-				  availableAeFpsTarget.data(),
-				  availableAeFpsTarget.size());
+	int64_t minFrameDurationUsec = -1;
+	int64_t maxFrameDurationUsec = -1;
+	const auto frameDurationsInfo = controlsInfo.find(&controls::FrameDurations);
+	if (frameDurationsInfo != controlsInfo.end()) {
+		minFrameDurationUsec = frameDurationsInfo->second.min().get<int64_t>();
+		maxFrameDurationUsec = frameDurationsInfo->second.max().get<int64_t>();
+
+		/*
+		 * The AE routine frame rate limits are computed using the frame
+		 * duration limits, as libcamera clips the AE routine to the
+		 * frame durations.
+		 */
+		int32_t minFps = static_cast<int32_t>(::round(1000000.0f /
+							      maxFrameDurationUsec));
+		minFps = std::max(1, minFps);
+		int maxFps = static_cast<int32_t>(::round(1000000.0f /
+							  minFrameDurationUsec));
+
+		/*
+		 * Register to the camera service {min, max} and {max, max}
+		 * intervals as requested by the metadata documentation.
+		 */
+		int32_t availableAeFpsTarget[] = {
+			minFps, maxFps, maxFps, maxFps
+		};
+		staticMetadata_->addEntry(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
+					  availableAeFpsTarget, 4);
+	}
 
 	std::vector<int32_t> aeCompensationRange = {
 		0, 0,
@@ -929,13 +952,11 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
 	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,
 				  &timestampSource, 1);
 
-	/*
-	 * 66,67 milliseconds to accomodate the 15 FPS limit reported in
-	 * AE_AVAILABLE_TARGET_FPS_RANGE.
-	 */
-	int64_t maxFrameDuration = 66666667;
-	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
-				  &maxFrameDuration, 1);
+	if (maxFrameDurationUsec > 0) {
+		int64_t maxFrameDuration = maxFrameDurationUsec * 1000;
+		staticMetadata_->addEntry(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
+					  &maxFrameDuration, 1);
+	}
 
 	/* Statistics static metadata. */
 	uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
@@ -1071,18 +1092,20 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
 				  availableStallDurations.data(),
 				  availableStallDurations.size());
 
-	/* \todo Collect the minimum frame duration from the camera. */
-	std::vector<int64_t> minFrameDurations;
-	minFrameDurations.reserve(streamConfigurations_.size() * 4);
-	for (const auto &entry : streamConfigurations_) {
-		minFrameDurations.push_back(entry.androidFormat);
-		minFrameDurations.push_back(entry.resolution.width);
-		minFrameDurations.push_back(entry.resolution.height);
-		minFrameDurations.push_back(33333333);
+	/* Use the minimum frame duration for all the YUV/RGB formats. */
+	if (minFrameDurationUsec > 0) {
+		std::vector<int64_t> minFrameDurations;
+		minFrameDurations.reserve(streamConfigurations_.size() * 4);
+		for (const auto &entry : streamConfigurations_) {
+			minFrameDurations.push_back(entry.androidFormat);
+			minFrameDurations.push_back(entry.resolution.width);
+			minFrameDurations.push_back(entry.resolution.height);
+			minFrameDurations.push_back(minFrameDurationUsec * 1000);
+		}
+		staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
+					  minFrameDurations.data(),
+					  minFrameDurations.size());
 	}
-	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
-				  minFrameDurations.data(),
-				  minFrameDurations.size());
 
 	uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY;
 	staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, &croppingType, 1);
-- 
2.29.2



More information about the libcamera-devel mailing list