[libcamera-devel] [RFC PATCH 09/10] android: camera_device: Fill offset and right length in CreateFrameBuffer()
Hirokazu Honda
hiroh at chromium.org
Mon Aug 16 06:31:37 CEST 2021
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 at chromium.org>
---
src/android/camera_device.cpp | 38 ++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index a69b687a..1ded5cb1 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,30 @@ 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;
}
+ }
+ if (!fd.isValid()) {
+ LOG(HAL, Fatal) << "No valid fd";
+ 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;
- }
+ 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].offset = buf.plane(i).data() - buf.plane(0).data();
+ planes[i].length = buf.plane(i).size();
}
return new FrameBuffer(std::move(planes));
--
2.33.0.rc1.237.g0d66db33f3-goog
More information about the libcamera-devel
mailing list