[libcamera-devel,RFC,v2,6/8] android: camera_device: Only construct required planes

Message ID 20200720224832.154442-1-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • Untitled series #1120
Related show

Commit Message

Kieran Bingham July 20, 2020, 10:48 p.m. UTC
The camera3buffer describes the number of filedescriptors given.
Don't try to construct more planes than that.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
v2:
 - cleanly skip planes with no given file descriptor (set to -1)
 - Clean up the error handling and reporting if the FileDescriptor
   failes to dup.

 src/android/camera_device.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart July 24, 2020, 5:11 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Mon, Jul 20, 2020 at 11:48:32PM +0100, Kieran Bingham wrote:
> The camera3buffer describes the number of filedescriptors given.
> Don't try to construct more planes than that.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
> v2:
>  - cleanly skip planes with no given file descriptor (set to -1)
>  - Clean up the error handling and reporting if the FileDescriptor
>    failes to dup.
> 
>  src/android/camera_device.cpp | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index e5c50084e590..610c54d45eb9 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1033,9 +1033,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)
>  {
>  	std::vector<FrameBuffer::Plane> planes;
> -	for (unsigned int i = 0; i < 3; i++) {
> +	for (int i = 0; i < camera3buffer->numFds; i++) {

I'd have said unsigned int, but numFds is signed.

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

> +		/* Skip unused planes. */
> +		if (camera3buffer->data[i] == -1)
> +			continue;
> +
>  		FrameBuffer::Plane plane;
>  		plane.fd = FileDescriptor(camera3buffer->data[i]);
> +		if (!plane.fd.isValid()) {
> +			LOG(HAL, Error) << "Failed to obtain FileDescriptor ("
> +					<< camera3buffer->data[i] << ") "
> +					<< " on plane " << i;
> +			continue;
> +		}
> +
>  		/*
>  		 * Setting length to zero here is OK as the length is only used
>  		 * to map the memory of the plane. Libcamera do not need to poke

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index e5c50084e590..610c54d45eb9 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1033,9 +1033,20 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)
 {
 	std::vector<FrameBuffer::Plane> planes;
-	for (unsigned int i = 0; i < 3; i++) {
+	for (int i = 0; i < camera3buffer->numFds; i++) {
+		/* Skip unused planes. */
+		if (camera3buffer->data[i] == -1)
+			continue;
+
 		FrameBuffer::Plane plane;
 		plane.fd = FileDescriptor(camera3buffer->data[i]);
+		if (!plane.fd.isValid()) {
+			LOG(HAL, Error) << "Failed to obtain FileDescriptor ("
+					<< camera3buffer->data[i] << ") "
+					<< " on plane " << i;
+			continue;
+		}
+
 		/*
 		 * Setting length to zero here is OK as the length is only used
 		 * to map the memory of the plane. Libcamera do not need to poke