{"id":10043,"url":"https://patchwork.libcamera.org/api/1.1/patches/10043/?format=json","web_url":"https://patchwork.libcamera.org/patch/10043/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201010095830.134084-3-jacopo@jmondi.org>","date":"2020-10-10T09:58:29","name":"[libcamera-devel,v2,2/3] android: camera_device: Queue request using Worker","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"91dde325046a2ccd97877f5456533dbbd7c82e3e","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/10043/mbox/","series":[{"id":1372,"url":"https://patchwork.libcamera.org/api/1.1/series/1372/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1372","date":"2020-10-10T09:58:27","name":"android: Introduce CameraWorker","version":2,"mbox":"https://patchwork.libcamera.org/series/1372/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10043/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10043/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 36EE2BEEDF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 10 Oct 2020 09:54:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 05D2B60890;\n\tSat, 10 Oct 2020 11:54:40 +0200 (CEST)","from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64847603C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 10 Oct 2020 11:54:37 +0200 (CEST)","from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 04B0340002;\n\tSat, 10 Oct 2020 09:54:36 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 10 Oct 2020 11:58:29 +0200","Message-Id":"<20201010095830.134084-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20201010095830.134084-1-jacopo@jmondi.org>","References":"<20201010095830.134084-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 2/3] android: camera_device: Queue\n\trequest using Worker","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a CameraWorker class member to the CameraDevice class and\nqueue capture requests to it to delegate its handling. Start and\nstop the CameraWorker when the libcamera::Camera is started or\nstopped.\n\nTie the CaptureRequest lifetime to the Camera3RequestDescriptor's one\nby storing it as unique_ptr<> in the descriptor to simplify handling\nof request creation and deletion.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 42 ++++++++++++++++++-----------------\n src/android/camera_device.h   |  7 +++++-\n 2 files changed, 28 insertions(+), 21 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex c29fcb43fe2d..0036f1140560 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -168,11 +168,24 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,\n  */\n \n CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor(\n-\t\tunsigned int frameNumber, unsigned int numBuffers)\n+\tCamera *camera, unsigned int frameNumber, unsigned int numBuffers)\n \t: frameNumber(frameNumber), numBuffers(numBuffers)\n {\n \tbuffers = new camera3_stream_buffer_t[numBuffers];\n+\n+\t/*\n+\t * FrameBuffer instances created by wrapping a camera3 provided dmabuf\n+\t * are emplaced in this vector of unique_ptr<> for lifetime management.\n+\t */\n \tframeBuffers.reserve(numBuffers);\n+\n+\t/*\n+\t * Create the libcamera::Request unique_ptr<> to tie its lifetime\n+\t * to the descriptor's one. Set the descriptor's address as the\n+\t * request's cookie to retrieve it at completion time.\n+\t */\n+\trequest = std::make_unique<CaptureRequest>(camera,\n+\t\t\t\t\t\t   reinterpret_cast<uint64_t>(this));\n }\n \n CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor()\n@@ -519,6 +532,7 @@ void CameraDevice::close()\n {\n \tstreams_.clear();\n \n+\tworker_.stop();\n \tcamera_->stop();\n \tcamera_->release();\n \n@@ -1350,6 +1364,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \n \t/* Start the camera if that's the first request we handle. */\n \tif (!running_) {\n+\t\tworker_.start();\n+\n \t\tint ret = camera_->start();\n \t\tif (ret) {\n \t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n@@ -1372,16 +1388,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t * at request complete time.\n \t */\n \tCamera3RequestDescriptor *descriptor =\n-\t\tnew Camera3RequestDescriptor(camera3Request->frame_number,\n+\t\tnew Camera3RequestDescriptor(camera_.get(), camera3Request->frame_number,\n \t\t\t\t\t     camera3Request->num_output_buffers);\n \n-\tstd::unique_ptr<Request> request =\n-\t\tcamera_->createRequest(reinterpret_cast<uint64_t>(descriptor));\n-\tif (!request) {\n-\t\tLOG(HAL, Error) << \"Failed to create request\";\n-\t\treturn -ENOMEM;\n-\t}\n-\n \tLOG(HAL, Debug) << \"Queueing Request to libcamera with \"\n \t\t\t<< descriptor->numBuffers << \" HAL streams\";\n \tfor (unsigned int i = 0; i < descriptor->numBuffers; ++i) {\n@@ -1448,18 +1457,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\treturn -ENOMEM;\n \t\t}\n \n-\t\trequest->addBuffer(cameraStream->stream(), buffer);\n-\t}\n-\n-\tint ret = camera_->queueRequest(request.get());\n-\tif (ret) {\n-\t\tLOG(HAL, Error) << \"Failed to queue request\";\n-\t\tdelete descriptor;\n-\t\treturn ret;\n+\t\tdescriptor->request->addBuffer(cameraStream->stream(), buffer,\n+\t\t\t\t\t       camera3Buffers[i].acquire_fence);\n \t}\n \n-\t/* The request will be deleted in the completion handler. */\n-\trequest.release();\n+\t/* Queue the request on the CameraWorker. */\n+\tworker_.queueRequest(descriptor->request.get());\n \n \treturn 0;\n }\n@@ -1564,7 +1567,6 @@ void CameraDevice::requestComplete(Request *request)\n \tcallbacks_->process_capture_result(callbacks_, &captureResult);\n \n \tdelete descriptor;\n-\tdelete request;\n }\n \n std::string CameraDevice::logPrefix() const\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 777d1a35e801..86f2b8974b53 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -25,6 +25,7 @@\n #include \"libcamera/internal/message.h\"\n \n #include \"camera_stream.h\"\n+#include \"camera_worker.h\"\n #include \"jpeg/encoder.h\"\n \n class CameraMetadata;\n@@ -73,7 +74,8 @@ private:\n \tCameraDevice(unsigned int id, const std::shared_ptr<libcamera::Camera> &camera);\n \n \tstruct Camera3RequestDescriptor {\n-\t\tCamera3RequestDescriptor(unsigned int frameNumber,\n+\t\tCamera3RequestDescriptor(libcamera::Camera *camera,\n+\t\t\t\t\t unsigned int frameNumber,\n \t\t\t\t\t unsigned int numBuffers);\n \t\t~Camera3RequestDescriptor();\n \n@@ -81,6 +83,7 @@ private:\n \t\tuint32_t numBuffers;\n \t\tcamera3_stream_buffer_t *buffers;\n \t\tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers;\n+\t\tstd::unique_ptr<CaptureRequest> request;\n \t};\n \n \tstruct Camera3StreamConfiguration {\n@@ -108,6 +111,8 @@ private:\n \tunsigned int id_;\n \tcamera3_device_t camera3Device_;\n \n+\tCameraWorker worker_;\n+\n \tbool running_;\n \tstd::shared_ptr<libcamera::Camera> camera_;\n \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n","prefixes":["libcamera-devel","v2","2/3"]}