[libcamera-devel,v3] android: camera_device: Add null check for ScalerCrop control
diff mbox series

Message ID 20210329174046.86591-1-pnguyen@baylibre.com
State Accepted
Headers show
Series
  • [libcamera-devel,v3] android: camera_device: Add null check for ScalerCrop control
Related show

Commit Message

Phi-bang Nguyen March 29, 2021, 5:40 p.m. UTC
The ScalerCrop control does not contain the null check which can
cause the camera HAL crash at boot. Fix it.

Fixes: 31a1a628cd0e ("android: camera_device: Register MAX_DIGITAL_ZOOM")

Signed-off-by: Phi-Bang Nguyen <pnguyen@baylibre.com>
---
 src/android/camera_device.cpp | 40 ++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 19 deletions(-)

Comments

Laurent Pinchart March 30, 2021, 3:25 a.m. UTC | #1
Hi Phi-Bang,

On Mon, Mar 29, 2021 at 07:40:46PM +0200, Phi-Bang Nguyen wrote:
> The ScalerCrop control does not contain the null check which can
> cause the camera HAL crash at boot. Fix it.
> 
> Fixes: 31a1a628cd0e ("android: camera_device: Register MAX_DIGITAL_ZOOM")
> 
> Signed-off-by: Phi-Bang Nguyen <pnguyen@baylibre.com>

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

And pushed. Thank you :-)

> ---
>  src/android/camera_device.cpp | 40 ++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index ae693664..9ec261c3 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1095,26 +1095,28 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
>  	}
>  
>  	/* Scaler static metadata. */
> -	{
> -		/*
> -		 * \todo The digital zoom factor is a property that depends
> -		 * on the desired output configuration and the sensor frame size
> -		 * input to the ISP. This information is not available to the
> -		 * Android HAL, not at initialization time at least.
> -		 *
> -		 * As a workaround rely on pipeline handlers initializing the
> -		 * ScalerCrop control with the camera default configuration and
> -		 * use the maximum and minimum crop rectangles to calculate the
> -		 * digital zoom factor.
> -		 */
> -		const auto info = controlsInfo.find(&controls::ScalerCrop);
> -		Rectangle min = info->second.min().get<Rectangle>();
> -		Rectangle max = info->second.max().get<Rectangle>();
> -		float maxZoom = std::min(1.0f * max.width / min.width,
> -					 1.0f * max.height / min.height);
> -		staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
> -					  &maxZoom, 1);
> +
> +	/*
> +	 * \todo The digital zoom factor is a property that depends
> +	 * on the desired output configuration and the sensor frame size
> +	 * input to the ISP. This information is not available to the
> +	 * Android HAL, not at initialization time at least.
> +	 *
> +	 * As a workaround rely on pipeline handlers initializing the
> +	 * ScalerCrop control with the camera default configuration and
> +	 * use the maximum and minimum crop rectangles to calculate the
> +	 * digital zoom factor.
> +	 */
> +	float maxZoom = 1.0f;
> +	const auto scalerCrop = controlsInfo.find(&controls::ScalerCrop);
> +	if (scalerCrop != controlsInfo.end()) {
> +		Rectangle min = scalerCrop->second.min().get<Rectangle>();
> +		Rectangle max = scalerCrop->second.max().get<Rectangle>();
> +		maxZoom = std::min(1.0f * max.width / min.width,
> +				   1.0f * max.height / min.height);
>  	}
> +	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
> +				  &maxZoom, 1);
>  
>  	std::vector<uint32_t> availableStreamConfigurations;
>  	availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index ae693664..9ec261c3 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1095,26 +1095,28 @@  const camera_metadata_t *CameraDevice::getStaticMetadata()
 	}
 
 	/* Scaler static metadata. */
-	{
-		/*
-		 * \todo The digital zoom factor is a property that depends
-		 * on the desired output configuration and the sensor frame size
-		 * input to the ISP. This information is not available to the
-		 * Android HAL, not at initialization time at least.
-		 *
-		 * As a workaround rely on pipeline handlers initializing the
-		 * ScalerCrop control with the camera default configuration and
-		 * use the maximum and minimum crop rectangles to calculate the
-		 * digital zoom factor.
-		 */
-		const auto info = controlsInfo.find(&controls::ScalerCrop);
-		Rectangle min = info->second.min().get<Rectangle>();
-		Rectangle max = info->second.max().get<Rectangle>();
-		float maxZoom = std::min(1.0f * max.width / min.width,
-					 1.0f * max.height / min.height);
-		staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
-					  &maxZoom, 1);
+
+	/*
+	 * \todo The digital zoom factor is a property that depends
+	 * on the desired output configuration and the sensor frame size
+	 * input to the ISP. This information is not available to the
+	 * Android HAL, not at initialization time at least.
+	 *
+	 * As a workaround rely on pipeline handlers initializing the
+	 * ScalerCrop control with the camera default configuration and
+	 * use the maximum and minimum crop rectangles to calculate the
+	 * digital zoom factor.
+	 */
+	float maxZoom = 1.0f;
+	const auto scalerCrop = controlsInfo.find(&controls::ScalerCrop);
+	if (scalerCrop != controlsInfo.end()) {
+		Rectangle min = scalerCrop->second.min().get<Rectangle>();
+		Rectangle max = scalerCrop->second.max().get<Rectangle>();
+		maxZoom = std::min(1.0f * max.width / min.width,
+				   1.0f * max.height / min.height);
 	}
+	staticMetadata_->addEntry(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
+				  &maxZoom, 1);
 
 	std::vector<uint32_t> availableStreamConfigurations;
 	availableStreamConfigurations.reserve(streamConfigurations_.size() * 4);