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>
This commit is contained in:
Hirokazu Honda 2021-08-26 20:25:38 +09:00 committed by Laurent Pinchart
parent 94fb6b2f4d
commit dde91916f1
2 changed files with 37 additions and 21 deletions

View file

@ -12,6 +12,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
@ -744,31 +745,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
return 0; 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++) { 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; break;
}
}
FrameBuffer::Plane plane; if (!fd.isValid()) {
plane.fd = FileDescriptor(camera3buffer->data[i]); LOG(HAL, Fatal) << "No valid fd";
if (!plane.fd.isValid()) {
LOG(HAL, Error) << "Failed to obtain FileDescriptor ("
<< camera3buffer->data[i] << ") "
<< " on plane " << i;
return nullptr; return nullptr;
} }
off_t length = lseek(plane.fd.fd(), 0, SEEK_END); CameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ);
if (length == -1) { if (!buf.isValid()) {
LOG(HAL, Error) << "Failed to query plane length"; LOG(HAL, Fatal) << "Failed to create CameraBuffer";
return nullptr; return nullptr;
} }
plane.length = length; std::vector<FrameBuffer::Plane> planes(buf.numPlanes());
planes.push_back(std::move(plane)); 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)); return new FrameBuffer(std::move(planes));
@ -976,7 +986,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
* associate it with the Camera3RequestDescriptor for * associate it with the Camera3RequestDescriptor for
* lifetime management only. * lifetime management only.
*/ */
buffer = createFrameBuffer(*camera3Buffer.buffer); buffer = createFrameBuffer(*camera3Buffer.buffer,
cameraStream->configuration().pixelFormat,
cameraStream->configuration().size);
descriptor.frameBuffers_.emplace_back(buffer); descriptor.frameBuffers_.emplace_back(buffer);
LOG(HAL, Debug) << ss.str() << " (direct)"; LOG(HAL, Debug) << ss.str() << " (direct)";
break; break;

View file

@ -21,6 +21,8 @@
#include <libcamera/camera.h> #include <libcamera/camera.h>
#include <libcamera/framebuffer.h> #include <libcamera/framebuffer.h>
#include <libcamera/geometry.h>
#include <libcamera/pixel_format.h>
#include <libcamera/request.h> #include <libcamera/request.h>
#include <libcamera/stream.h> #include <libcamera/stream.h>
@ -91,7 +93,9 @@ private:
void stop(); 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); void abortRequest(camera3_capture_request_t *request);
bool isValidRequest(camera3_capture_request_t *request) const; bool isValidRequest(camera3_capture_request_t *request) const;
void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyShutter(uint32_t frameNumber, uint64_t timestamp);