From f4c65be7b3db0c70e5194614817e7e76b8901c88 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Mon, 6 Jul 2020 16:12:03 +0100 Subject: android: camera_device: Only construct required planes The camera3buffer describes the number of filedescriptors given. Don't try to construct more planes than that. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/android/camera_device.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 0a0bcedb..e609ed76 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1118,9 +1118,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) { std::vector 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) + break; + 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; + return nullptr; + } + /* * 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 -- cgit v1.2.1