summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2021-08-26 20:25:38 +0900
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-30 18:59:10 +0300
commitdde91916f16e7836d28ad4c394678f82c86dcc4b (patch)
tree63dfb2daa2fcbf874cd8fbfe85bfd2914e7fb01a
parent94fb6b2f4d02707cac2a1c5c1a9d622eeaeb4c04 (diff)
android: camera_device: Fill offset and right length in CreateFrameBuffer()
CameraDevice::CreateFrameBuffer() fills the length of the buffer to each FrameBuffer::Plane::length. It should rather be the length of plane. This also changes CreateFrameBuffer() to fill offset of FrameBuffer::Plane. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--src/android/camera_device.cpp52
-rw-r--r--src/android/camera_device.h6
2 files changed, 37 insertions, 21 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index a69b687a..8ca76719 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>
@@ -744,31 +745,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
return 0;
}
-FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)
+FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,
+ libcamera::PixelFormat pixelFormat,
+ const libcamera::Size &size)
{
- std::vector<FrameBuffer::Plane> planes;
+ FileDescriptor fd;
+ /*
+ * This assumes all the planes are in the same dmabuf.
+ *
+ * \todo Verify that this assumption holds, fstat() can be used to check
+ * if two fds refer to the same dmabuf.
+ */
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, pixelFormat, size, PROT_READ);
+ if (!buf.isValid()) {
+ LOG(HAL, Fatal) << "Failed to create CameraBuffer";
+ 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].offset = buf.offset(i);
+ planes[i].length = buf.size(i);
}
return new FrameBuffer(std::move(planes));
@@ -976,7 +986,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
* associate it with the Camera3RequestDescriptor for
* lifetime management only.
*/
- buffer = createFrameBuffer(*camera3Buffer.buffer);
+ buffer = createFrameBuffer(*camera3Buffer.buffer,
+ cameraStream->configuration().pixelFormat,
+ cameraStream->configuration().size);
descriptor.frameBuffers_.emplace_back(buffer);
LOG(HAL, Debug) << ss.str() << " (direct)";
break;
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index dd9aebba..a5576927 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -21,6 +21,8 @@
#include <libcamera/camera.h>
#include <libcamera/framebuffer.h>
+#include <libcamera/geometry.h>
+#include <libcamera/pixel_format.h>
#include <libcamera/request.h>
#include <libcamera/stream.h>
@@ -91,7 +93,9 @@ private:
void stop();
- libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);
+ libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer,
+ libcamera::PixelFormat pixelFormat,
+ const libcamera::Size &size);
void abortRequest(camera3_capture_request_t *request);
bool isValidRequest(camera3_capture_request_t *request) const;
void notifyShutter(uint32_t frameNumber, uint64_t timestamp);