[libcamera-devel,v2,13/17] android: Populate streams and duration in the same loop
diff mbox series

Message ID 20210907194107.803730-14-jacopo@jmondi.org
State Superseded
Headers show
Series
  • IPU3 control info update and HAL frame durations
Related show

Commit Message

Jacopo Mondi Sept. 7, 2021, 7:41 p.m. UTC
The ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS and
ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS  static metadata are
populated by looping on the streamConfigurations_ vector.

Unify them in a single loop to avoid repeating it.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/android/camera_capabilities.cpp | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

Comments

Laurent Pinchart Oct. 6, 2021, 1:48 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Tue, Sep 07, 2021 at 09:41:03PM +0200, Jacopo Mondi wrote:
> The ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS and
> ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS  static metadata are

s/  / /

> populated by looping on the streamConfigurations_ vector.
> 
> Unify them in a single loop to avoid repeating it.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  src/android/camera_capabilities.cpp | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
> index ba800b545b9d..194ede866806 100644
> --- a/src/android/camera_capabilities.cpp
> +++ b/src/android/camera_capabilities.cpp
> @@ -1257,7 +1257,9 @@ int CameraCapabilities::initializeStaticMetadata()
>  				  maxZoom);
>  
>  	std::vector<uint32_t> availableStreamConfigurations;
> +	std::vector<int64_t> minFrameDurations;
>  	availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);
> +	minFrameDurations.reserve(streamConfigurations_.size() * 4);
>  	for (const auto &entry : streamConfigurations_) {
>  		/*
>  		 * Filter out YUV streams not capable of running at 30 FPS.
> @@ -1274,12 +1276,19 @@ int CameraCapabilities::initializeStaticMetadata()
>  		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
>  			continue;
>  
> +		/* Stream configuration map. */
>  		availableStreamConfigurations.push_back(entry.androidFormat);
>  		availableStreamConfigurations.push_back(entry.resolution.width);
>  		availableStreamConfigurations.push_back(entry.resolution.height);
>  		availableStreamConfigurations.push_back(
>  			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
>  
> +		/* Per-stream durations. */
> +		minFrameDurations.push_back(entry.androidFormat);
> +		minFrameDurations.push_back(entry.resolution.width);
> +		minFrameDurations.push_back(entry.resolution.height);
> +		minFrameDurations.push_back(entry.minFrameDurationNsec);
> +
>  		LOG(HAL, Debug)
>  			<< "Output Stream: " << utils::hex(entry.androidFormat)
>  			<< " (" << entry.resolution.width << "x"
> @@ -1287,22 +1296,10 @@ int CameraCapabilities::initializeStaticMetadata()
>  			<< entry.minFrameDurationNsec << "]"
>  			<< "@" << fps;
>  	}
> +
>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
>  				  availableStreamConfigurations);
>  

I would have dropped this blank line.

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

> -	std::vector<int64_t> minFrameDurations;
> -	minFrameDurations.reserve(streamConfigurations_.size() * 4);
> -	for (const auto &entry : streamConfigurations_) {
> -		unsigned int fps = static_cast<unsigned int>
> -				   (floor(1e9 / entry.minFrameDurationNsec + 0.05f));
> -		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
> -			continue;
> -
> -		minFrameDurations.push_back(entry.androidFormat);
> -		minFrameDurations.push_back(entry.resolution.width);
> -		minFrameDurations.push_back(entry.resolution.height);
> -		minFrameDurations.push_back(entry.minFrameDurationNsec);
> -	}
>  	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
>  				  minFrameDurations);
>

Patch
diff mbox series

diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
index ba800b545b9d..194ede866806 100644
--- a/src/android/camera_capabilities.cpp
+++ b/src/android/camera_capabilities.cpp
@@ -1257,7 +1257,9 @@  int CameraCapabilities::initializeStaticMetadata()
 				  maxZoom);
 
 	std::vector<uint32_t> availableStreamConfigurations;
+	std::vector<int64_t> minFrameDurations;
 	availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);
+	minFrameDurations.reserve(streamConfigurations_.size() * 4);
 	for (const auto &entry : streamConfigurations_) {
 		/*
 		 * Filter out YUV streams not capable of running at 30 FPS.
@@ -1274,12 +1276,19 @@  int CameraCapabilities::initializeStaticMetadata()
 		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
 			continue;
 
+		/* Stream configuration map. */
 		availableStreamConfigurations.push_back(entry.androidFormat);
 		availableStreamConfigurations.push_back(entry.resolution.width);
 		availableStreamConfigurations.push_back(entry.resolution.height);
 		availableStreamConfigurations.push_back(
 			ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
 
+		/* Per-stream durations. */
+		minFrameDurations.push_back(entry.androidFormat);
+		minFrameDurations.push_back(entry.resolution.width);
+		minFrameDurations.push_back(entry.resolution.height);
+		minFrameDurations.push_back(entry.minFrameDurationNsec);
+
 		LOG(HAL, Debug)
 			<< "Output Stream: " << utils::hex(entry.androidFormat)
 			<< " (" << entry.resolution.width << "x"
@@ -1287,22 +1296,10 @@  int CameraCapabilities::initializeStaticMetadata()
 			<< entry.minFrameDurationNsec << "]"
 			<< "@" << fps;
 	}
+
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
 				  availableStreamConfigurations);
 
-	std::vector<int64_t> minFrameDurations;
-	minFrameDurations.reserve(streamConfigurations_.size() * 4);
-	for (const auto &entry : streamConfigurations_) {
-		unsigned int fps = static_cast<unsigned int>
-				   (floor(1e9 / entry.minFrameDurationNsec + 0.05f));
-		if (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB && fps < 30)
-			continue;
-
-		minFrameDurations.push_back(entry.androidFormat);
-		minFrameDurations.push_back(entry.resolution.width);
-		minFrameDurations.push_back(entry.resolution.height);
-		minFrameDurations.push_back(entry.minFrameDurationNsec);
-	}
 	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
 				  minFrameDurations);