[libcamera-devel] [RFC PATCH v4 02/16] android: Add infrastructure for determining capabilities and hardware level

Paul Elder paul.elder at ideasonboard.com
Fri Jul 2 12:37:46 CEST 2021


Add the infrastructure for checking and reporting capabilities. Use
these capabilities to determine the hardware level as well.

Since the raw capability is set to true when support is determined to be
available, leave that as default false and set to true, since copying
the pattern of the other capabilities would cause redundant code.

Note that this will cause CTS to fail, as we don't yet declare the lack
of support for FULL based on the available controls.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=55
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>

---
Changes in v4:
- rebase on camera capabilities refactoring
- switch to std::set from std::map
- make hwlevel similar to capabilities

Changes in v3:
- fix some compiler errors
- go ahead and initialize the capabilities to true, update the commit
  message accordingly

Changes in v2:
- add a flag for FULL, since there are a few requirements that are not
  obtained from capabilities alone
- add burst capture capability, since that is required for FULL as well

This is my vision of how we would support the various capabilities.
Although we don't have anything for FULL yet; I imagine that we would
start the flags for manual sensor and manual post processing with true,
and then if a required control is unavailable, then we would set the
flag to false.

I considered declaring an enum in CameraDevice to mirror the android
ones, just for shorthand, but it seemed like a lot of code for not much
gain. Unless the shorthand would be valuable because these constant
names are so long?

I think the available keys lists will have to be moved to the head of
the function, and then as available controls are discovered add them to
that list.
---
 src/android/camera_capabilities.cpp | 50 +++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
index 6b5edb66..54bd71da 100644
--- a/src/android/camera_capabilities.cpp
+++ b/src/android/camera_capabilities.cpp
@@ -9,6 +9,7 @@
 
 #include <array>
 #include <cmath>
+#include <map>
 
 #include <hardware/camera3.h>
 
@@ -114,6 +115,15 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {
 	},
 };
 
+const std::map<camera_metadata_enum_android_info_supported_hardware_level, std::string>
+hwLevelStrings = {
+	{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED,  "LIMITED" },
+	{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL,     "FULL" },
+	{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY,   "LEGACY" },
+	{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_3,        "LEVEL_3" },
+	{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, "EXTERNAL" },
+};
+
 } /* namespace */
 
 int CameraCapabilities::initialize(std::shared_ptr<libcamera::Camera> camera,
@@ -376,6 +386,19 @@ int CameraCapabilities::initializeStaticMetadata()
 	const ControlInfoMap &controlsInfo = camera_->controls();
 	const ControlList &properties = camera_->properties();
 
+	std::set<camera_metadata_enum_android_request_available_capabilities>
+	capabilities = {
+		ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE,
+		ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR,
+		ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING,
+		ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE,
+	};
+
+	std::set<camera_metadata_enum_android_info_supported_hardware_level>
+	hwLevels = {
+		ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL,
+	};
+
 	/* Color correction static metadata. */
 	{
 		std::vector<uint8_t> data;
@@ -834,11 +857,6 @@ int CameraCapabilities::initializeStaticMetadata()
 	uint8_t croppingType = ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY;
 	staticMetadata_->addEntry(ANDROID_SCALER_CROPPING_TYPE, croppingType);
 
-	/* Info static metadata. */
-	uint8_t supportedHWLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED;
-	staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL,
-				  supportedHWLevel);
-
 	/* Request static metadata. */
 	int32_t partialResultCount = 1;
 	staticMetadata_->addEntry(ANDROID_REQUEST_PARTIAL_RESULT_COUNT,
@@ -859,10 +877,6 @@ int CameraCapabilities::initializeStaticMetadata()
 	staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS,
 				  maxNumInputStreams);
 
-	std::vector<uint8_t> availableCapabilities = {
-		ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE,
-	};
-
 	/* Report if camera supports RAW. */
 	bool rawStreamAvailable = false;
 	std::unique_ptr<CameraConfiguration> cameraConfig =
@@ -874,7 +888,7 @@ int CameraCapabilities::initializeStaticMetadata()
 		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW &&
 		    info.bitsPerPixel == 16) {
 			rawStreamAvailable = true;
-			availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW);
+			capabilities.insert(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW);
 		}
 	}
 
@@ -883,9 +897,25 @@ int CameraCapabilities::initializeStaticMetadata()
 	staticMetadata_->addEntry(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS,
 				  numOutStreams);
 
+	/* Check capabilities */
+	std::vector<uint8_t> availableCapabilities(capabilities.begin(),
+						   capabilities.end());
 	staticMetadata_->addEntry(ANDROID_REQUEST_AVAILABLE_CAPABILITIES,
 				  availableCapabilities);
 
+	uint8_t hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED;
+	if (capabilities.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR) &&
+	    capabilities.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING) &&
+	    capabilities.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE) &&
+	    hwLevels.count(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL))
+		hwLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL;
+	staticMetadata_->addEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL,
+				  hwLevel);
+
+	LOG(HAL, Info)
+		<< "Hardware level: "
+		<< hwLevelStrings.find((camera_metadata_enum_android_info_supported_hardware_level)hwLevel)->second;
+
 	std::vector<int32_t> availableCharacteristicsKeys = {
 		ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES,
 		ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES,
-- 
2.27.0



More information about the libcamera-devel mailing list