summaryrefslogtreecommitdiff
path: root/src/android/camera_device.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-11-22 16:22:56 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-12 16:10:38 +0100
commit9217f274f64f690b768d332663e1731a3ee5ef15 (patch)
treeee152928be1eaea656c929e56e27e97b175de435 /src/android/camera_device.cpp
parenteb4030f6c07174a520be1ebd73628e9ae4789569 (diff)
libcamera: Switch to FrameBuffer interface
Switch to the FrameBuffer interface where all buffers are treated as external buffers and are allocated outside the camera. Applications allocating buffers using libcamera are switched to use the FrameBufferAllocator helper. Follow-up changes to this one will finalize the transition to the new FrameBuffer interface by removing code that is left unused after this change. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/android/camera_device.cpp')
-rw-r--r--src/android/camera_device.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index ebe91ea8..ab3e4488 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -739,13 +739,21 @@ void CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reque
* and (currently) only supported request buffer.
*/
const buffer_handle_t camera3Handle = *camera3Buffers[0].buffer;
- std::array<int, 3> fds = {
- camera3Handle->data[0],
- camera3Handle->data[1],
- camera3Handle->data[2],
- };
- std::unique_ptr<Buffer> buffer = stream->createBuffer(fds);
+ std::vector<FrameBuffer::Plane> planes;
+ for (int i = 0; i < 3; i++) {
+ FrameBuffer::Plane plane;
+ plane.fd = FileDescriptor(camera3Handle->data[i]);
+ /*
+ * Setting length to zero here is OK as the length is only used
+ * to map the memory of the plane. Libcamera do not need to poke
+ * at the memory content queued by the HAL.
+ */
+ plane.length = 0;
+ planes.push_back(std::move(plane));
+ }
+
+ FrameBuffer *buffer = new FrameBuffer(std::move(planes));
if (!buffer) {
LOG(HAL, Error) << "Failed to create buffer";
delete descriptor;
@@ -754,7 +762,7 @@ void CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reque
Request *request =
camera_->createRequest(reinterpret_cast<uint64_t>(descriptor));
- request->addBuffer(stream, std::move(buffer));
+ request->addBuffer(stream, buffer);
int ret = camera_->queueRequest(request);
if (ret) {
@@ -771,8 +779,8 @@ error:
void CameraDevice::requestComplete(Request *request)
{
- const std::map<Stream *, Buffer *> &buffers = request->buffers();
- Buffer *libcameraBuffer = buffers.begin()->second;
+ const std::map<Stream *, FrameBuffer *> &buffers = request->buffers();
+ FrameBuffer *buffer = buffers.begin()->second;
camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK;
std::unique_ptr<CameraMetadata> resultMetadata;
@@ -803,11 +811,11 @@ void CameraDevice::requestComplete(Request *request)
if (status == CAMERA3_BUFFER_STATUS_OK) {
notifyShutter(descriptor->frameNumber,
- libcameraBuffer->metadata().timestamp);
+ buffer->metadata().timestamp);
captureResult.partial_result = 1;
resultMetadata = getResultMetadata(descriptor->frameNumber,
- libcameraBuffer->metadata().timestamp);
+ buffer->metadata().timestamp);
captureResult.result = resultMetadata->get();
}
@@ -825,6 +833,7 @@ void CameraDevice::requestComplete(Request *request)
callbacks_->process_capture_result(callbacks_, &captureResult);
delete descriptor;
+ delete buffer;
}
void CameraDevice::notifyShutter(uint32_t frameNumber, uint64_t timestamp)