[libcamera-devel] [RFC PATCH 8/8] RFC-Only: android: camera_device: Provide a MappedCamera3Buffer
Kieran Bingham
kieran.bingham at ideasonboard.com
Tue Jul 21 00:42:32 CEST 2020
Utilise the MappedBuffer interface to map each of the planes provided
in the Camera3 buffer to facilitate use in software streams.
The buffers will be automatically unmapped when the object goes out of
scope or is deleted.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
This patch shows an addition of a new MappedBuffer type constructed from
a camera3buffer. The base class deals with the move-constructors and
destructor, and gives us a common interface to pass a set of mapped
dmabufs around.
I had hoped to use this to pass in the camera3buffer for writing jpeg
buffers to, giving the same interface for both the source and
destination buffer - but for JPEG, I do also need to return the number
of bytes actually consumed, so this ended up potentially not adding the
benefits I hoped for.
Still, it might still provide some benefits, so I've included it here as
something to talk about.
--
Kieran
src/android/camera_device.cpp | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 6212ccdd61ec..f78486117e9f 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -86,6 +86,39 @@ const std::map<int, const Camera3Format> camera3FormatsMap = {
LOG_DECLARE_CATEGORY(HAL);
+class MappedCamera3Buffer : public MappedBuffer {
+public:
+ MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags)
+ {
+ maps_.reserve(camera3buffer->numFds);
+ error_ = 0;
+
+ for (int i = 0; i < camera3buffer->numFds; i++) {
+ if (camera3buffer->data[i] == -1)
+ continue;
+
+ off_t length = lseek(camera3buffer->data[i], 0, SEEK_END);
+ if (length < 0) {
+ error_ = errno;
+ LOG(HAL, Error) << "Failed to query plane length";
+ break;
+ }
+
+ void *address = mmap(nullptr, length, flags, MAP_SHARED,
+ camera3buffer->data[i], 0);
+ if (address == MAP_FAILED) {
+ error_ = errno;
+ LOG(HAL, Error) << "Failed to mmap plane";
+ break;
+ }
+
+ maps_.push_back({address, static_cast<size_t>(length)});
+ }
+
+ valid_ = error_ == 0;
+ }
+};
+
/*
* \struct Camera3RequestDescriptor
*
--
2.25.1
More information about the libcamera-devel
mailing list