Patch Detail
Show a patch.
GET /api/patches/9984/?format=api
{ "id": 9984, "url": "https://patchwork.libcamera.org/api/patches/9984/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9984/", "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": "<20201006160637.29841-2-jacopo@jmondi.org>", "date": "2020-10-06T16:06:36", "name": "[libcamera-devel,RFC,1/2] android: camera_worker: Introduce CameraWorker", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "d76126f8621fbbe824783382a19154402f91a121", "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/9984/mbox/", "series": [ { "id": 1357, "url": "https://patchwork.libcamera.org/api/series/1357/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1357", "date": "2020-10-06T16:06:35", "name": "android: Introduce CameraWorker", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1357/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9984/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9984/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 8501ABEEE0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 6 Oct 2020 16:02:46 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6949263C85;\n\tTue, 6 Oct 2020 18:02:45 +0200 (CEST)", "from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 434B560363\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 6 Oct 2020 18:02:44 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id D766F1BF207;\n\tTue, 6 Oct 2020 16:02:43 +0000 (UTC)" ], "X-Originating-IP": "93.34.118.233", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 6 Oct 2020 18:06:36 +0200", "Message-Id": "<20201006160637.29841-2-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.28.0", "In-Reply-To": "<20201006160637.29841-1-jacopo@jmondi.org>", "References": "<20201006160637.29841-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [RFC 1/2] android: camera_worker: Introduce\n\tCameraWorker", "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": "The CameraWork class creates a Worker instance and runs on an internal\nthread. The worker waits on a set of fences before queueing a capture\nrequests to the the libcamera::Camera.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_worker.cpp | 67 +++++++++++++++++++++++++++++++\n src/android/camera_worker.h | 75 +++++++++++++++++++++++++++++++++++\n src/android/meson.build | 1 +\n 3 files changed, 143 insertions(+)\n create mode 100644 src/android/camera_worker.cpp\n create mode 100644 src/android/camera_worker.h", "diff": "diff --git a/src/android/camera_worker.cpp b/src/android/camera_worker.cpp\nnew file mode 100644\nindex 000000000000..2bb94775a195\n--- /dev/null\n+++ b/src/android/camera_worker.cpp\n@@ -0,0 +1,67 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * camera_worker.cpp - Process capture request on behalf of the Camera HAL\n+ */\n+\n+#include \"camera_worker.h\"\n+\n+#include <errno.h>\n+#include <sys/poll.h>\n+\n+#include \"camera_device.h\"\n+\n+using namespace libcamera;\n+\n+CameraWorker::CameraWorker(const std::shared_ptr<Camera> &camera)\n+\t: camera_(camera), worker_(camera_.get())\n+{\n+\tworker_.moveToThread(&thread_);\n+\tthread_.start();\n+}\n+\n+void CameraWorker::queueRequest(std::unique_ptr<CaptureRequest> request)\n+{\n+\tCaptureRequest *req = request.release();\n+\tworker_.invokeMethod(&Worker::processRequest, ConnectionTypeQueued, req);\n+}\n+\n+int CameraWorker::Worker::waitFence(int fence)\n+{\n+\tstruct pollfd fds = { fence, POLLIN, 0 };\n+\tconstexpr unsigned int timeoutMs = 300;\n+\tint ret;\n+\n+\tdo {\n+\t\tret = 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 (ret == -1 && (errno == EINTR || errno == EAGAIN));\n+\n+\treturn ret;\n+}\n+\n+void CameraWorker::Worker::processRequest(CaptureRequest *request)\n+{\n+\tfor (int fence : request->acquireFences_) {\n+\t\tif (fence == -1)\n+\t\t\tcontinue;\n+\n+\t\tint ret = waitFence(fence);\n+\t\tif (ret < 0)\n+\t\t\treturn;\n+\n+\t\tclose(fence);\n+\t}\n+\n+\tcamera_->queueRequest(request->request_);\n+\tdelete request;\n+}\ndiff --git a/src/android/camera_worker.h b/src/android/camera_worker.h\nnew file mode 100644\nindex 000000000000..24b176d6269c\n--- /dev/null\n+++ b/src/android/camera_worker.h\n@@ -0,0 +1,75 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * camera_worker.h - Process capture request on behalf of the Camera HAL\n+ */\n+#ifndef __ANDROID_CAMERA_WORKER_H__\n+#define __ANDROID_CAMERA_WORKER_H__\n+\n+#include <memory>\n+\n+#include <libcamera/buffer.h>\n+#include <libcamera/camera.h>\n+#include <libcamera/object.h>\n+#include <libcamera/request.h>\n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/thread.h\"\n+\n+class CameraDevice;\n+\n+struct CaptureRequest {\n+\tCaptureRequest(libcamera::Request *request)\n+\t\t: request_(request)\n+\t{\n+\t}\n+\n+\tvoid addBuffer(libcamera::Stream *stream,\n+\t\t libcamera::FrameBuffer *buffer, int fence)\n+\t{\n+\t\trequest_->addBuffer(stream, buffer);\n+\t\tacquireFences_.push_back(fence);\n+\t}\n+\n+private:\n+\tfriend class CameraWorker;\n+\n+\tstd::vector<int> acquireFences_;\n+\tlibcamera::Request *request_;\n+};\n+\n+class CameraWorker\n+{\n+public:\n+\tCameraWorker(const std::shared_ptr<libcamera::Camera> &camera);\n+\n+\tvoid queueRequest(std::unique_ptr<CaptureRequest> request);\n+\n+private:\n+\tclass Worker : public libcamera::Object\n+\t{\n+\tpublic:\n+\t\tWorker(libcamera::Camera *camera)\n+\t\t\t: camera_(camera)\n+\t\t{\n+\t\t}\n+\t\t~Worker()\n+\t\t{\n+\t\t}\n+\n+\t\tvoid processRequest(CaptureRequest *request);\n+\n+\tprivate:\n+\t\tint waitFence(int fence);\n+\n+\t\tlibcamera::Camera *camera_;\n+\t};\n+\n+\tstd::shared_ptr<libcamera::Camera> camera_;\n+\n+\tWorker worker_;\n+\tlibcamera::Thread thread_;\n+};\n+\n+#endif /* __ANDROID_CAMERA_WORKER_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 802bb89afe57..b2b2293cf62d 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -21,6 +21,7 @@ android_hal_sources = files([\n 'camera_metadata.cpp',\n 'camera_ops.cpp',\n 'camera_stream.cpp',\n+ 'camera_worker.cpp',\n 'jpeg/encoder_libjpeg.cpp',\n 'jpeg/exif.cpp',\n ])\n", "prefixes": [ "libcamera-devel", "RFC", "1/2" ] }