[libcamera-devel,6/8] android: camera_manager: Replace hardcoded stream configuration

Message ID 20200526142237.407557-7-jacopo@jmondi.org
State Superseded, archived
Delegated to: Jacopo Mondi
Headers show
Series
  • android: Implament format translation
Related show

Commit Message

Jacopo Mondi May 26, 2020, 2:22 p.m. UTC
Replace the hardcoded stream configuration map with the information
collected at CameraDevice initialization time.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 38 ++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 18 deletions(-)

Comments

Laurent Pinchart June 4, 2020, 2:18 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Tue, May 26, 2020 at 04:22:35PM +0200, Jacopo Mondi wrote:
> Replace the hardcoded stream configuration map with the information
> collected at CameraDevice initialization time.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/android/camera_device.cpp | 38 ++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 6cc377820210..f8a52342abe5 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -623,23 +623,22 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
>  				  &maxDigitalZoom, 1);
>  
> -	std::vector<uint32_t> availableStreamFormats = {
> -		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED,
> -	};
> +	std::vector<uint32_t> availableStreamFormats;
> +	for (const auto &entry : streamConfigurations_)
> +		availableStreamFormats.push_back(entry.androidScalerCode);

	std::transform(streamConfigurations_.begin(), streamConfigurations_.end(),
		       std::back_inserter(availableStreamFormats),
		       [](const auto &entry) { return entry.androidScalerCode; });

Up to you.

>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_FORMATS,
>  				  availableStreamFormats.data(),
>  				  availableStreamFormats.size());
>  
> -	std::vector<uint32_t> availableStreamConfigurations = {
> -		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920,
> -		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920,
> -		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920,
> -		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
> -	};
> +	std::vector<uint32_t> availableStreamConfigurations;

If you want to make this a bit more efficient, you could call

	availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);

> +	for (const auto &entry : streamConfigurations_) {
> +		availableStreamConfigurations.push_back(entry.androidScalerCode);
> +		availableStreamConfigurations.push_back(entry.resolution.width);
> +		availableStreamConfigurations.push_back(entry.resolution.height);
> +		availableStreamConfigurations.push_back(entry.input ?
> +			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT :
> +			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);

This is where I would hardcode OUTPUT (see review of previous patches).

> +	}
>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
>  				  availableStreamConfigurations.data(),
>  				  availableStreamConfigurations.size());
> @@ -651,11 +650,14 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
>  				  availableStallDurations.data(),
>  				  availableStallDurations.size());
>  
> -	std::vector<int64_t> minFrameDurations = {
> -		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920, 33333333,
> -		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920, 33333333,
> -	};
> +	/* \todo Collect the minimum frame duration from the camera. */
> +	std::vector<int64_t> minFrameDurations;
> +	for (const auto &entry : streamConfigurations_) {
> +		minFrameDurations.push_back(entry.androidScalerCode);
> +		minFrameDurations.push_back(entry.resolution.width);
> +		minFrameDurations.push_back(entry.resolution.height);
> +		minFrameDurations.push_back(33333333);
> +	}
>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
>  				  minFrameDurations.data(),
>  				  minFrameDurations.size());

Very nice :-)

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 6cc377820210..f8a52342abe5 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -623,23 +623,22 @@  const camera_metadata_t *CameraDevice::getStaticMetadata()
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
 				  &maxDigitalZoom, 1);
 
-	std::vector<uint32_t> availableStreamFormats = {
-		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB,
-		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888,
-		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED,
-	};
+	std::vector<uint32_t> availableStreamFormats;
+	for (const auto &entry : streamConfigurations_)
+		availableStreamFormats.push_back(entry.androidScalerCode);
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_FORMATS,
 				  availableStreamFormats.data(),
 				  availableStreamFormats.size());
 
-	std::vector<uint32_t> availableStreamConfigurations = {
-		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920,
-		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
-		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920,
-		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
-		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920,
-		ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
-	};
+	std::vector<uint32_t> availableStreamConfigurations;
+	for (const auto &entry : streamConfigurations_) {
+		availableStreamConfigurations.push_back(entry.androidScalerCode);
+		availableStreamConfigurations.push_back(entry.resolution.width);
+		availableStreamConfigurations.push_back(entry.resolution.height);
+		availableStreamConfigurations.push_back(entry.input ?
+			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT :
+			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
+	}
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
 				  availableStreamConfigurations.data(),
 				  availableStreamConfigurations.size());
@@ -651,11 +650,14 @@  const camera_metadata_t *CameraDevice::getStaticMetadata()
 				  availableStallDurations.data(),
 				  availableStallDurations.size());
 
-	std::vector<int64_t> minFrameDurations = {
-		ANDROID_SCALER_AVAILABLE_FORMATS_BLOB, 2560, 1920, 33333333,
-		ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, 2560, 1920, 33333333,
-		ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, 2560, 1920, 33333333,
-	};
+	/* \todo Collect the minimum frame duration from the camera. */
+	std::vector<int64_t> minFrameDurations;
+	for (const auto &entry : streamConfigurations_) {
+		minFrameDurations.push_back(entry.androidScalerCode);
+		minFrameDurations.push_back(entry.resolution.width);
+		minFrameDurations.push_back(entry.resolution.height);
+		minFrameDurations.push_back(33333333);
+	}
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
 				  minFrameDurations.data(),
 				  minFrameDurations.size());