summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-10-06 17:56:50 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-10-14 20:11:26 +0200
commit4b1aa21db09df16d1a23d074e1b1c915b1b36ae4 (patch)
tree5f5126b6ca339bb27171034f1787c1ac96d356bf
parent8806863b0bc4498d098e16dda657ab6f8293d208 (diff)
android: camera_device: Queue request using Worker
Add a CameraWorker class member to the CameraDevice class and queue capture requests to it to delegate its handling. Start and stop the CameraWorker when the libcamera::Camera is started or stopped. Tie the CaptureRequest lifetime to the Camera3RequestDescriptor's one by storing it as unique_ptr<> in the descriptor to simplify handling of request creation and deletion. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r--src/android/camera_device.cpp42
-rw-r--r--src/android/camera_device.h7
2 files changed, 28 insertions, 21 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index c29fcb43..09832329 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -168,11 +168,24 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,
*/
CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor(
- unsigned int frameNumber, unsigned int numBuffers)
+ Camera *camera, unsigned int frameNumber, unsigned int numBuffers)
: frameNumber(frameNumber), numBuffers(numBuffers)
{
buffers = new camera3_stream_buffer_t[numBuffers];
+
+ /*
+ * FrameBuffer instances created by wrapping a camera3 provided dmabuf
+ * are emplaced in this vector of unique_ptr<> for lifetime management.
+ */
frameBuffers.reserve(numBuffers);
+
+ /*
+ * Create the libcamera::Request unique_ptr<> to tie its lifetime
+ * to the descriptor's one. Set the descriptor's address as the
+ * request's cookie to retrieve it at completion time.
+ */
+ request = std::make_unique<CaptureRequest>(camera,
+ reinterpret_cast<uint64_t>(this));
}
CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor()
@@ -519,6 +532,7 @@ void CameraDevice::close()
{
streams_.clear();
+ worker_.stop();
camera_->stop();
camera_->release();
@@ -1350,6 +1364,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
/* Start the camera if that's the first request we handle. */
if (!running_) {
+ worker_.start();
+
int ret = camera_->start();
if (ret) {
LOG(HAL, Error) << "Failed to start camera";
@@ -1372,16 +1388,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
* at request complete time.
*/
Camera3RequestDescriptor *descriptor =
- new Camera3RequestDescriptor(camera3Request->frame_number,
+ new Camera3RequestDescriptor(camera_.get(), camera3Request->frame_number,
camera3Request->num_output_buffers);
- std::unique_ptr<Request> request =
- camera_->createRequest(reinterpret_cast<uint64_t>(descriptor));
- if (!request) {
- LOG(HAL, Error) << "Failed to create request";
- return -ENOMEM;
- }
-
LOG(HAL, Debug) << "Queueing Request to libcamera with "
<< descriptor->numBuffers << " HAL streams";
for (unsigned int i = 0; i < descriptor->numBuffers; ++i) {
@@ -1448,18 +1457,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
return -ENOMEM;
}
- request->addBuffer(cameraStream->stream(), buffer);
- }
-
- int ret = camera_->queueRequest(request.get());
- if (ret) {
- LOG(HAL, Error) << "Failed to queue request";
- delete descriptor;
- return ret;
+ descriptor->request->addBuffer(cameraStream->stream(), buffer,
+ camera3Buffers[i].acquire_fence);
}
- /* The request will be deleted in the completion handler. */
- request.release();
+ /* Queue the request to the CameraWorker. */
+ worker_.queueRequest(descriptor->request.get());
return 0;
}
@@ -1564,7 +1567,6 @@ void CameraDevice::requestComplete(Request *request)
callbacks_->process_capture_result(callbacks_, &captureResult);
delete descriptor;
- delete request;
}
std::string CameraDevice::logPrefix() const
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 777d1a35..86f2b897 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -25,6 +25,7 @@
#include "libcamera/internal/message.h"
#include "camera_stream.h"
+#include "camera_worker.h"
#include "jpeg/encoder.h"
class CameraMetadata;
@@ -73,7 +74,8 @@ private:
CameraDevice(unsigned int id, const std::shared_ptr<libcamera::Camera> &camera);
struct Camera3RequestDescriptor {
- Camera3RequestDescriptor(unsigned int frameNumber,
+ Camera3RequestDescriptor(libcamera::Camera *camera,
+ unsigned int frameNumber,
unsigned int numBuffers);
~Camera3RequestDescriptor();
@@ -81,6 +83,7 @@ private:
uint32_t numBuffers;
camera3_stream_buffer_t *buffers;
std::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers;
+ std::unique_ptr<CaptureRequest> request;
};
struct Camera3StreamConfiguration {
@@ -108,6 +111,8 @@ private:
unsigned int id_;
camera3_device_t camera3Device_;
+ CameraWorker worker_;
+
bool running_;
std::shared_ptr<libcamera::Camera> camera_;
std::unique_ptr<libcamera::CameraConfiguration> config_;