[libcamera-devel,v3,2/4] android: CameraDevice: Validate crop_rotate_scale_degrees in configuration
diff mbox series

Message ID 20210330052521.381550-3-hiroh@chromium.org
State Changes Requested
Headers show
Series
  • Regard crop_rotate_scale_degrees in configuration
Related show

Commit Message

Hirokazu Honda March 30, 2021, 5:25 a.m. UTC
Libcamera doesn't handle |crop_rotate_scale_degrees| in
camera3_stream at all. This adds the validation of the requested
|crop_rotate_scale_degrees| in configuration, but still not
handle the specified values.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_device.cpp | 46 +++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Comments

Laurent Pinchart April 3, 2021, 12:44 a.m. UTC | #1
Hi Hiro,

Thank you for the patch.

On Tue, Mar 30, 2021 at 02:25:19PM +0900, Hirokazu Honda wrote:
> Libcamera doesn't handle |crop_rotate_scale_degrees| in

s/Libcamera/libcamera/

> camera3_stream at all. This adds the validation of the requested
> |crop_rotate_scale_degrees| in configuration, but still not
> handle the specified values.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/android/camera_device.cpp | 46 +++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index ae693664..f88e94bc 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -256,6 +256,44 @@ void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,
>  	unsortedConfigs = sortedConfigs;
>  }
>  
> +#if defined(CHROMEOS)
> +/*
> + * Check whether the crop_rotate_scale_degrees values for all streams in
> + * the list are valid according to the Chrome OS camera HAL API.
> + */
> +bool validateCropRotate(const camera3_stream_configuration_t &streamList)
> +{
> +	ASSERT(streamList.num_streams > 0);
> +	const int cropRotateScaleDegrees =
> +		streamList.streams[0]->crop_rotate_scale_degrees;
> +	for (unsigned int i = 0; i < streamList.num_streams; ++i) {
> +		const camera3_stream_t &stream = *streamList.streams[i];
> +
> +		switch (stream.crop_rotate_scale_degrees) {
> +		case CAMERA3_STREAM_ROTATION_0:
> +		case CAMERA3_STREAM_ROTATION_90:
> +		case CAMERA3_STREAM_ROTATION_270:
> +			break;
> +
> +		/* 180° rotation is specified by Chrome OS as invalid. */
> +		case CAMERA3_STREAM_ROTATION_180:
> +		default:
> +			LOG(HAL, Error) << "Invalid crop_rotate_scale_degrees: "
> +					<< stream.crop_rotate_scale_degrees;
> +			return false;
> +		}
> +
> +		if (cropRotateScaleDegrees != stream.crop_rotate_scale_degrees) {
> +			LOG(HAL, Error) << "crop_rotate_scale_degrees in all "
> +					<< "streams are not identical";
> +			return false;
> +		}
> +	}
> +
> +	return true;
> +}
> +#endif
> +
>  } /* namespace */
>  
>  /*
> @@ -1552,6 +1590,14 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		running_ = false;
>  	}
>  
> +	if (stream_list->num_streams == 0)
> +		return -EINVAL;
> +

This could be split to a different patch, or be at least mentioned in
the commit message.

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

> +#if defined(CHROMEOS)
> +	if (!validateCropRotate(*stream_list))
> +		return -EINVAL;
> +#endif
> +
>  	/*
>  	 * Generate an empty configuration, and construct a StreamConfiguration
>  	 * for each camera3_stream to add to it.

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index ae693664..f88e94bc 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -256,6 +256,44 @@  void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,
 	unsortedConfigs = sortedConfigs;
 }
 
+#if defined(CHROMEOS)
+/*
+ * Check whether the crop_rotate_scale_degrees values for all streams in
+ * the list are valid according to the Chrome OS camera HAL API.
+ */
+bool validateCropRotate(const camera3_stream_configuration_t &streamList)
+{
+	ASSERT(streamList.num_streams > 0);
+	const int cropRotateScaleDegrees =
+		streamList.streams[0]->crop_rotate_scale_degrees;
+	for (unsigned int i = 0; i < streamList.num_streams; ++i) {
+		const camera3_stream_t &stream = *streamList.streams[i];
+
+		switch (stream.crop_rotate_scale_degrees) {
+		case CAMERA3_STREAM_ROTATION_0:
+		case CAMERA3_STREAM_ROTATION_90:
+		case CAMERA3_STREAM_ROTATION_270:
+			break;
+
+		/* 180° rotation is specified by Chrome OS as invalid. */
+		case CAMERA3_STREAM_ROTATION_180:
+		default:
+			LOG(HAL, Error) << "Invalid crop_rotate_scale_degrees: "
+					<< stream.crop_rotate_scale_degrees;
+			return false;
+		}
+
+		if (cropRotateScaleDegrees != stream.crop_rotate_scale_degrees) {
+			LOG(HAL, Error) << "crop_rotate_scale_degrees in all "
+					<< "streams are not identical";
+			return false;
+		}
+	}
+
+	return true;
+}
+#endif
+
 } /* namespace */
 
 /*
@@ -1552,6 +1590,14 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 		running_ = false;
 	}
 
+	if (stream_list->num_streams == 0)
+		return -EINVAL;
+
+#if defined(CHROMEOS)
+	if (!validateCropRotate(*stream_list))
+		return -EINVAL;
+#endif
+
 	/*
 	 * Generate an empty configuration, and construct a StreamConfiguration
 	 * for each camera3_stream to add to it.