[libcamera-devel,1/5] android: camera_device: Refuse unsupported formats

Message ID 20200902104730.43451-2-jacopo@jmondi.org
State Accepted
Headers show
Series
  • android: camera_device: List JPEG/RAW correct resolutions
Related show

Commit Message

Jacopo Mondi Sept. 2, 2020, 10:47 a.m. UTC
The current implementation of CameraDevice::initializeStreamConfigurations()
fails if an image format marked as mandatory is not supported by the
libcamera::Camera device, but erroneously accepts non-mandatory
non-supported formats in the list of accepted ones.

Fix this by ignoring non supported image formats which are not marked as
mandatory.

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

Comments

Kieran Bingham Sept. 2, 2020, 12:48 p.m. UTC | #1
Hi Jacopo,

On 02/09/2020 11:47, Jacopo Mondi wrote:
> The current implementation of CameraDevice::initializeStreamConfigurations()
> fails if an image format marked as mandatory is not supported by the
> libcamera::Camera device, but erroneously accepts non-mandatory
> non-supported formats in the list of accepted ones.
> 
> Fix this by ignoring non supported image formats which are not marked as
> mandatory.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/android/camera_device.cpp | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 9605b9e9069e..ad0d7fd15d90 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -392,10 +392,16 @@ int CameraDevice::initializeStreamConfigurations()
>  				break;
>  			}
>  		}
> -		if (camera3Format.mandatory && !mappedFormat.isValid()) {

Eeek, I see it ;-)

> -			LOG(HAL, Error) << "Failed to map Android format "
> -					<< camera3Format.name << " ("
> -					<< utils::hex(androidFormat) << ")";
> +
> +		if (!mappedFormat.isValid()) {
> +			/* If the format is not mandatory, skip it. */
> +			if (!camera3Format.mandatory)
> +				continue;

That's better ;-)

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +
> +			LOG(HAL, Error)
> +				<< "Failed to map mandatory Android format "
> +				<< camera3Format.name << " ("
> +				<< utils::hex(androidFormat) << "): aborting";
>  			return -EINVAL;
>  		}
>  
>

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 9605b9e9069e..ad0d7fd15d90 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -392,10 +392,16 @@  int CameraDevice::initializeStreamConfigurations()
 				break;
 			}
 		}
-		if (camera3Format.mandatory && !mappedFormat.isValid()) {
-			LOG(HAL, Error) << "Failed to map Android format "
-					<< camera3Format.name << " ("
-					<< utils::hex(androidFormat) << ")";
+
+		if (!mappedFormat.isValid()) {
+			/* If the format is not mandatory, skip it. */
+			if (!camera3Format.mandatory)
+				continue;
+
+			LOG(HAL, Error)
+				<< "Failed to map mandatory Android format "
+				<< camera3Format.name << " ("
+				<< utils::hex(androidFormat) << "): aborting";
 			return -EINVAL;
 		}