Patch Detail
Show a patch.
GET /api/patches/14678/?format=api
{ "id": 14678, "url": "https://patchwork.libcamera.org/api/patches/14678/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14678/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20211120111313.106621-11-jacopo@jmondi.org>", "date": "2021-11-20T11:13:11", "name": "[libcamera-devel,v2,10/12] android: Remove CameraWorker", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "518de6cc99522637ef2ce9dbb1bce4eacfd638eb", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14678/mbox/", "series": [ { "id": 2739, "url": "https://patchwork.libcamera.org/api/series/2739/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2739", "date": "2021-11-20T11:13:01", "name": "libcamera: Add support for Fence", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2739/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14678/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14678/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 517EBBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 20 Nov 2021 11:12:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 181C36038C;\n\tSat, 20 Nov 2021 12:12:35 +0100 (CET)", "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CB85E60490\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 20 Nov 2021 12:12:28 +0100 (CET)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 56F57100002;\n\tSat, 20 Nov 2021 11:12:28 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 20 Nov 2021 12:13:11 +0100", "Message-Id": "<20211120111313.106621-11-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.33.1", "In-Reply-To": "<20211120111313.106621-1-jacopo@jmondi.org>", "References": "<20211120111313.106621-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 10/12] android: Remove CameraWorker", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The CameraWorker class purpose was to handle acquire fences for incoming\ncapture requests directed to libcamera.\n\nNow that fences are handled by the core library, it is not required to\nhandle them in the HAL and the CameraWorker and CaptureRequest classes\ncan be dropped.\n\nUpdate the core in CameraDevice class accordingly to queue Requests\ndirectly to the libcamera::Camera and set the release_fence to the\nvalue of the FrameBuffer::fence() for streams of type ::Direct.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 43 +++++------\n src/android/camera_device.h | 3 -\n src/android/camera_request.cpp | 3 +-\n src/android/camera_request.h | 3 +-\n src/android/camera_worker.cpp | 129 ---------------------------------\n src/android/camera_worker.h | 72 ------------------\n src/android/meson.build | 1 -\n 7 files changed, 24 insertions(+), 230 deletions(-)\n delete mode 100644 src/android/camera_worker.cpp\n delete mode 100644 src/android/camera_worker.h", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex f2e0bdbdbbf6..29f0abd96ba9 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -19,6 +19,7 @@\n \n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n+#include <libcamera/fence.h>\n #include <libcamera/formats.h>\n #include <libcamera/property_ids.h>\n \n@@ -406,7 +407,6 @@ void CameraDevice::flush()\n \t\tstate_ = State::Flushing;\n \t}\n \n-\tworker_.stop();\n \tcamera_->stop();\n \n \tMutexLocker stateLock(stateMutex_);\n@@ -419,7 +419,6 @@ void CameraDevice::stop()\n \tif (state_ == State::Stopped)\n \t\treturn;\n \n-\tworker_.stop();\n \tcamera_->stop();\n \n \tdescriptors_ = {};\n@@ -912,13 +911,10 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \n \t\t/*\n \t\t * Inspect the camera stream type, create buffers opportunely\n-\t\t * and add them to the Request if required. Only acquire fences\n-\t\t * for streams of type Direct are handled by the CameraWorker,\n-\t\t * while fences for streams of type Internal and Mapped are\n-\t\t * handled at post-processing time.\n+\t\t * and add them to the Request if required.\n \t\t */\n+\t\tFileDescriptor fenceFd;\n \t\tFrameBuffer *frameBuffer = nullptr;\n-\t\tint acquireFence = -1;\n \t\tswitch (cameraStream->type()) {\n \t\tcase CameraStream::Type::Mapped:\n \t\t\t/*\n@@ -943,7 +939,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\t\t\t\t cameraStream->configuration().pixelFormat,\n \t\t\t\t\t\t cameraStream->configuration().size);\n \t\t\tframeBuffer = buffer.frameBuffer.get();\n-\t\t\tacquireFence = buffer.fence;\n+\t\t\tfenceFd = FileDescriptor(std::move(buffer.fence));\n \t\t\tLOG(HAL, Debug) << ss.str() << \" (direct)\";\n \t\t\tbreak;\n \n@@ -969,13 +965,14 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\treturn -ENOMEM;\n \t\t}\n \n+\t\tstd::unique_ptr<Fence> fence = std::make_unique<Fence>(fenceFd);\n \t\tdescriptor->request_->addBuffer(cameraStream->stream(),\n-\t\t\t\t\t\tframeBuffer, acquireFence);\n+\t\t\t\t\t\tframeBuffer, std::move(fence));\n \t}\n \n \t/*\n \t * Translate controls from Android to libcamera and queue the request\n-\t * to the CameraWorker thread.\n+\t * to the camera.\n \t */\n \tint ret = processControls(descriptor.get());\n \tif (ret)\n@@ -1001,26 +998,23 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t}\n \n \tif (state_ == State::Stopped) {\n-\t\tworker_.start();\n-\n \t\tret = camera_->start();\n \t\tif (ret) {\n \t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n-\t\t\tworker_.stop();\n \t\t\treturn ret;\n \t\t}\n \n \t\tstate_ = State::Running;\n \t}\n \n-\tCaptureRequest *request = descriptor->request_.get();\n+\tRequest *request = descriptor->request_.get();\n \n \t{\n \t\tMutexLocker descriptorsLock(descriptorsMutex_);\n \t\tdescriptors_.push(std::move(descriptor));\n \t}\n \n-\tworker_.queueRequest(request);\n+\tcamera_->queueRequest(request);\n \n \treturn 0;\n }\n@@ -1042,16 +1036,23 @@ void CameraDevice::requestComplete(Request *request)\n \t\t/*\n \t\t * Streams of type Direct have been queued to the\n \t\t * libcamera::Camera and their acquire fences have\n-\t\t * already been waited on by the CameraWorker.\n+\t\t * been handled by the library.\n+\t\t *\n+\t\t * If the fence has been signalled correctly it will be -1 and\n+\t\t * closed, otherwise it is set to the 'acquire_fence' value and\n+\t\t * the framework will have to close it.\n \t\t *\n \t\t * Acquire fences of streams of type Internal and Mapped\n \t\t * will be handled during post-processing.\n-\t\t *\n-\t\t * \\todo Instrument the CameraWorker to set the acquire\n-\t\t * fence to -1 once it has handled it and remove this check.\n \t\t */\n-\t\tif (stream->type() == CameraStream::Type::Direct)\n-\t\t\tbuffer.fence = -1;\n+\t\tif (stream->type() == CameraStream::Type::Direct) {\n+\t\t\tFence *fence = buffer.frameBuffer->fence();\n+\t\t\tif (!fence)\n+\t\t\t\tbreak;\n+\n+\t\t\tFileDescriptor fenceFd = std::move(fence->fd());\n+\t\t\tbuffer.fence = fenceFd.fd();\n+\t\t}\n \t\tbuffer.status = Camera3RequestDescriptor::Status::Success;\n \t}\n \ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 2a414020f1ad..c8cc78688bec 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -30,7 +30,6 @@\n #include \"camera_capabilities.h\"\n #include \"camera_metadata.h\"\n #include \"camera_stream.h\"\n-#include \"camera_worker.h\"\n #include \"jpeg/encoder.h\"\n \n class Camera3RequestDescriptor;\n@@ -105,8 +104,6 @@ private:\n \tunsigned int id_;\n \tcamera3_device_t camera3Device_;\n \n-\tCameraWorker worker_;\n-\n \tlibcamera::Mutex stateMutex_; /* Protects access to the camera state. */\n \tState state_;\n \ndiff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp\nindex 8162aa78e953..917769070cd9 100644\n--- a/src/android/camera_request.cpp\n+++ b/src/android/camera_request.cpp\n@@ -47,8 +47,7 @@ Camera3RequestDescriptor::Camera3RequestDescriptor(\n \t * Create the CaptureRequest, stored as a unique_ptr<> to tie its\n \t * lifetime to the descriptor.\n \t */\n-\trequest_ = std::make_unique<CaptureRequest>(camera,\n-\t\t\t\t\t\t reinterpret_cast<uint64_t>(this));\n+\trequest_ = camera->createRequest(reinterpret_cast<uint64_t>(this));\n }\n \n Camera3RequestDescriptor::~Camera3RequestDescriptor() = default;\ndiff --git a/src/android/camera_request.h b/src/android/camera_request.h\nindex 8d1204e5590b..69e1fe9fc379 100644\n--- a/src/android/camera_request.h\n+++ b/src/android/camera_request.h\n@@ -20,7 +20,6 @@\n #include <hardware/camera3.h>\n \n #include \"camera_metadata.h\"\n-#include \"camera_worker.h\"\n \n class CameraBuffer;\n class CameraStream;\n@@ -71,7 +70,7 @@ public:\n \tstd::vector<StreamBuffer> buffers_;\n \n \tCameraMetadata settings_;\n-\tstd::unique_ptr<CaptureRequest> request_;\n+\tstd::unique_ptr<libcamera::Request> request_;\n \tstd::unique_ptr<CameraMetadata> resultMetadata_;\n \n \tbool complete_ = false;\ndiff --git a/src/android/camera_worker.cpp b/src/android/camera_worker.cpp\ndeleted file mode 100644\nindex dabb305407a2..000000000000\n--- a/src/android/camera_worker.cpp\n+++ /dev/null\n@@ -1,129 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2020, Google Inc.\n- *\n- * camera_worker.cpp - Process capture requests on behalf of the Camera HAL\n- */\n-\n-#include \"camera_worker.h\"\n-\n-#include <errno.h>\n-#include <string.h>\n-#include <sys/poll.h>\n-#include <unistd.h>\n-\n-#include \"camera_device.h\"\n-\n-using namespace libcamera;\n-\n-LOG_DECLARE_CATEGORY(HAL)\n-\n-/*\n- * \\class CaptureRequest\n- * \\brief Wrap a libcamera::Request associated with buffers and fences\n- *\n- * A CaptureRequest is constructed by the CameraDevice, filled with\n- * buffers and fences provided by the camera3 framework and then processed\n- * by the CameraWorker which queues it to the libcamera::Camera after handling\n- * fences.\n- */\n-CaptureRequest::CaptureRequest(Camera *camera, uint64_t cookie)\n-\t: camera_(camera)\n-{\n-\trequest_ = camera_->createRequest(cookie);\n-}\n-\n-void CaptureRequest::addBuffer(Stream *stream, FrameBuffer *buffer, int fence)\n-{\n-\trequest_->addBuffer(stream, buffer);\n-\tacquireFences_.push_back(fence);\n-}\n-\n-void CaptureRequest::queue()\n-{\n-\tcamera_->queueRequest(request_.get());\n-}\n-\n-/*\n- * \\class CameraWorker\n- * \\brief Process a CaptureRequest on an internal thread\n- *\n- * The CameraWorker class wraps a Worker that runs on an internal thread\n- * and schedules processing of CaptureRequest through it.\n- */\n-CameraWorker::CameraWorker()\n-{\n-\tworker_.moveToThread(this);\n-}\n-\n-void CameraWorker::start()\n-{\n-\tThread::start();\n-}\n-\n-void CameraWorker::stop()\n-{\n-\texit();\n-\twait();\n-}\n-\n-void CameraWorker::run()\n-{\n-\texec();\n-\tdispatchMessages(Message::Type::InvokeMessage);\n-}\n-\n-void CameraWorker::queueRequest(CaptureRequest *request)\n-{\n-\t/* Async process the request on the worker which runs its own thread. */\n-\tworker_.invokeMethod(&Worker::processRequest, ConnectionTypeQueued,\n-\t\t\t request);\n-}\n-\n-/*\n- * \\class CameraWorker::Worker\n- * \\brief Process a CaptureRequest handling acquisition fences\n- */\n-int CameraWorker::Worker::waitFence(int fence)\n-{\n-\t/*\n-\t * \\todo Better characterize the timeout. Currently equal to the one\n-\t * used by the Rockchip Camera HAL on ChromeOS.\n-\t */\n-\tconstexpr unsigned int timeoutMs = 300;\n-\tstruct pollfd fds = { fence, POLLIN, 0 };\n-\n-\tdo {\n-\t\tint ret = poll(&fds, 1, timeoutMs);\n-\t\tif (ret == 0)\n-\t\t\treturn -ETIME;\n-\n-\t\tif (ret > 0) {\n-\t\t\tif (fds.revents & (POLLERR | POLLNVAL))\n-\t\t\t\treturn -EINVAL;\n-\n-\t\t\treturn 0;\n-\t\t}\n-\t} while (errno == EINTR || errno == EAGAIN);\n-\n-\treturn -errno;\n-}\n-\n-void CameraWorker::Worker::processRequest(CaptureRequest *request)\n-{\n-\t/* Wait on all fences before queuing the Request. */\n-\tfor (int fence : request->fences()) {\n-\t\tif (fence == -1)\n-\t\t\tcontinue;\n-\n-\t\tint ret = waitFence(fence);\n-\t\tclose(fence);\n-\t\tif (ret < 0) {\n-\t\t\tLOG(HAL, Error) << \"Failed waiting for fence: \"\n-\t\t\t\t\t<< fence << \": \" << strerror(-ret);\n-\t\t\treturn;\n-\t\t}\n-\t}\n-\n-\trequest->queue();\n-}\ndiff --git a/src/android/camera_worker.h b/src/android/camera_worker.h\ndeleted file mode 100644\nindex c94f16325925..000000000000\n--- a/src/android/camera_worker.h\n+++ /dev/null\n@@ -1,72 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2020, Google Inc.\n- *\n- * camera_worker.h - Process capture requests on behalf of the Camera HAL\n- */\n-#ifndef __ANDROID_CAMERA_WORKER_H__\n-#define __ANDROID_CAMERA_WORKER_H__\n-\n-#include <memory>\n-#include <stdint.h>\n-\n-#include <libcamera/base/object.h>\n-#include <libcamera/base/thread.h>\n-\n-#include <libcamera/camera.h>\n-#include <libcamera/framebuffer.h>\n-#include <libcamera/request.h>\n-#include <libcamera/stream.h>\n-\n-class CameraDevice;\n-\n-class CaptureRequest\n-{\n-public:\n-\tCaptureRequest(libcamera::Camera *camera, uint64_t cookie);\n-\n-\tconst std::vector<int> &fences() const { return acquireFences_; }\n-\tlibcamera::ControlList &controls() { return request_->controls(); }\n-\tconst libcamera::ControlList &metadata() const\n-\t{\n-\t\treturn request_->metadata();\n-\t}\n-\tunsigned long cookie() const { return request_->cookie(); }\n-\n-\tvoid addBuffer(libcamera::Stream *stream,\n-\t\t libcamera::FrameBuffer *buffer, int fence);\n-\tvoid queue();\n-\n-private:\n-\tlibcamera::Camera *camera_;\n-\tstd::vector<int> acquireFences_;\n-\tstd::unique_ptr<libcamera::Request> request_;\n-};\n-\n-class CameraWorker : private libcamera::Thread\n-{\n-public:\n-\tCameraWorker();\n-\n-\tvoid start();\n-\tvoid stop();\n-\n-\tvoid queueRequest(CaptureRequest *request);\n-\n-protected:\n-\tvoid run() override;\n-\n-private:\n-\tclass Worker : public libcamera::Object\n-\t{\n-\tpublic:\n-\t\tvoid processRequest(CaptureRequest *request);\n-\n-\tprivate:\n-\t\tint waitFence(int fence);\n-\t};\n-\n-\tWorker worker_;\n-};\n-\n-#endif /* __ANDROID_CAMERA_WORKER_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 332b177ca805..75b4bf207085 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -47,7 +47,6 @@ android_hal_sources = files([\n 'camera_ops.cpp',\n 'camera_request.cpp',\n 'camera_stream.cpp',\n- 'camera_worker.cpp',\n 'jpeg/encoder_libjpeg.cpp',\n 'jpeg/exif.cpp',\n 'jpeg/post_processor_jpeg.cpp',\n", "prefixes": [ "libcamera-devel", "v2", "10/12" ] }