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

Message ID 20210702103800.41291-3-paul.elder@ideasonboard.com
State Superseded
Delegated to: Paul Elder
Headers show
Series
  • Preliminary FULL plumbing
Related show

Commit Message

Paul Elder July 2, 2021, 10:37 a.m. UTC
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@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(-)

Comments

Jacopo Mondi July 5, 2021, 1:52 p.m. UTC | #1
Hi Paul,

On Fri, Jul 02, 2021 at 07:37:46PM +0900, Paul Elder wrote:
> 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@ideasonboard.com>
>

Shouldn't it be the other way around ?

We start with an empty set of capabilities and validates them one by
one.

The set of requirements is not trivial and I'm not sure we can express
its negation easily. What I mean is that, copying the examples in my
reply to "[PATCH v2] android: Add infrastructure for determining
capabilities and hardware level":

For MANUAL_SENSOR capability:
  - android.control.aeMode contains OFF
  - android.control.awbMode contains OFF
  - android.control.afMode contains OFF
  - ANDROID_REQUEST_AVAILABLE_RESULT_KEYS contains android.sensor.frameDuration
  - ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS contains
    android.sensor.info.maxFrameDuration
  - ...

We can operates in two ways:
- Start with the capability enabled and verify for each required
  feature if it is present or not while populating the static metadata
  by duplicating a lot of:

        if (!condition)
                capabilities.erase(MANUAL_SENSOR)

  Causing the code that verifies if a capabilitiy is supported to be
  spread in many places and difficult to verify against the
  specification

- Start with an empty set of capabilities. After having populated the
  static metadata as we currently do introduce an
  initializeCapabilties() function that takes the static metadata pack
  and verifies the requirements for each capabilities are supported:

  in PseudoCode:

         bool validateManualSensorCapability(staticMetadata) {
                if (!staticMetadata.get(ANDROID_CONTROL_AE_MODE).contains(OFF)
                        return false;

                if ....

                return true;
       }

       void initializeCapabilities() {
                if (validateManualSensorCapability(staticMetadata))
                        capabilities.push_back(MANUAL_SENSOR);

                ...
       }

I would go for the second option, and after having plumbed most of the
requirements for FULL in.

Thanks
   j

> ---
> 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
>

Patch
diff mbox series

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,