[libcamera-devel,RFC,3/5] android: camera_device: Fills the size of plane to FrameBuffer::Plane::length
diff mbox series

Message ID 20210811124015.2116188-4-hiroh@chromium.org
State Superseded
Headers show
Series
  • MappedFrameBuffer::maps() returns the plane address
Related show

Commit Message

Hirokazu Honda Aug. 11, 2021, 12:40 p.m. UTC
CameraDevice fills the size of a buffer to FrameBuffer::Plane::length.
It should rather fill the size of a plane to it.

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

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index a69b687a..f10f27b7 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -12,6 +12,7 @@ 
 
 #include <algorithm>
 #include <fstream>
+#include <sys/mman.h>
 #include <unistd.h>
 #include <vector>
 
@@ -746,29 +747,31 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 
 FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)
 {
-	std::vector<FrameBuffer::Plane> planes;
+	FileDescriptor fd;
+	/* This assumes all the planes are in the same buffer. */
 	for (int i = 0; i < camera3buffer->numFds; i++) {
 		/* Skip unused planes. */
-		if (camera3buffer->data[i] == -1)
+		if (camera3buffer->data[i] != -1) {
+			fd = FileDescriptor(camera3buffer->data[i]);
 			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;
 		}
+	}
 
-		off_t length = lseek(plane.fd.fd(), 0, SEEK_END);
-		if (length == -1) {
-			LOG(HAL, Error) << "Failed to query plane length";
-			return nullptr;
-		}
+	if (!fd.isValid()) {
+		LOG(HAL, Fatal) << "No valid fd";
+		return nullptr;
+	}
+
+	CameraBuffer buf(camera3buffer, PROT_READ);
+	if (!buf.isValid()) {
+		LOG(HAL, Fatal) << "Failed mapping buffer";
+		return nullptr;
+	}
 
-		plane.length = length;
-		planes.push_back(std::move(plane));
+	std::vector<FrameBuffer::Plane> planes(buf.numPlanes());
+	for (size_t i = 0; i < buf.numPlanes(); ++i) {
+		planes[i].fd = fd;
+		planes[i].length = buf.plane(i).size();
 	}
 
 	return new FrameBuffer(std::move(planes));