@@ -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));
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(-)