Patch Detail
Show a patch.
GET /api/1.1/patches/10570/?format=api
{ "id": 10570, "url": "https://patchwork.libcamera.org/api/1.1/patches/10570/?format=api", "web_url": "https://patchwork.libcamera.org/patch/10570/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20201205103106.242080-8-paul.elder@ideasonboard.com>", "date": "2020-12-05T10:30:50", "name": "[libcamera-devel,v5,07/23] libcamera: Add IPCPipe implementation based on unix socket", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b3a95c44577160d5a72df88e2f82fbd69dcc7dc1", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/users/17/?format=api", "username": "epaul", "first_name": "Paul", "last_name": "Elder", "email": "paul.elder@ideasonboard.com" }, "mbox": "https://patchwork.libcamera.org/patch/10570/mbox/", "series": [ { "id": 1506, "url": "https://patchwork.libcamera.org/api/1.1/series/1506/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1506", "date": "2020-12-05T10:30:43", "name": "IPA isolation implementation", "version": 5, "mbox": "https://patchwork.libcamera.org/series/1506/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/10570/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/10570/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 4FF7CBDB20\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 5 Dec 2020 10:31:33 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B60C63601;\n\tSat, 5 Dec 2020 11:31:33 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B333635FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 5 Dec 2020 11:31:31 +0100 (CET)", "from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C7F599A;\n\tSat, 5 Dec 2020 11:31:29 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IfbkMFMt\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607164291;\n\tbh=SIJJdC3IOY5oADIaogTBIbubGZfPbbhuu84ht8RqGKo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IfbkMFMtNDXqusAhFEdWtE+SM0iTlyFlvgbm9pkMzS5Py35eOsA1vTiueAXbyvul9\n\tnZPk8mVLHxY093g/wcDrXTZWCC8awALl39rLjoThQYbdDRhCnZhY9UXyBSK8AmNvYa\n\th3eVWMXtfK5SmTgefaheFT7DKeutgKQ920ON+6EI=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 5 Dec 2020 19:30:50 +0900", "Message-Id": "<20201205103106.242080-8-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20201205103106.242080-1-paul.elder@ideasonboard.com>", "References": "<20201205103106.242080-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v5 07/23] libcamera: Add IPCPipe\n\timplementation based on unix socket", "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 an implementation of IPCPipe using unix socket.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v5:\n- rename IPAIPCUnixSocket to IPCPipeUnixSocket\n- rename ipa_ipc_unisocket.[(cpp),h] ipc_pipe_unixsocket.[(cpp),h]\n\nChanges in v4:\n- change snake_case to camelCase\n- change proc_ and socket_ to unique pointers\n- move inclusion of corresponding header to first in the include list\n- reserve message data and fds size (for sending)\n\nChanges in v3:\n- remove unused writeUInt32() and readUInt32()\n- remove redundant definition of IPAIPCUnixSocket::isValid()\n- remove & 0xff in writeHeader()\n- make readHeader, writeHeader, and eraseHeader static class functions\n of IPAIPCUnixSocket instead of globals\n\nChanges in v2:\n- specify in doxygen to skip generating documentation for\n IPAIPCUnixSocket\n---\n Documentation/Doxyfile.in | 2 +\n .../libcamera/internal/ipc_pipe_unixsocket.h | 50 ++++++\n src/libcamera/ipc_pipe_unixsocket.cpp | 147 ++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 200 insertions(+)\n create mode 100644 include/libcamera/internal/ipc_pipe_unixsocket.h\n create mode 100644 src/libcamera/ipc_pipe_unixsocket.cpp", "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex b18b8e9c..36a0cef3 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -837,8 +837,10 @@ RECURSIVE = YES\n EXCLUDE = @TOP_SRCDIR@/include/libcamera/span.h \\\n \t\t\t @TOP_SRCDIR@/include/libcamera/internal/device_enumerator_sysfs.h \\\n \t\t\t @TOP_SRCDIR@/include/libcamera/internal/device_enumerator_udev.h \\\n+\t\t\t @TOP_SRCDIR@/include/libcamera/internal/ipc_pipe_unixsocket.h \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_sysfs.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/device_enumerator_udev.cpp \\\n+\t\t\t @TOP_SRCDIR@/src/libcamera/ipc_pipe_unixsocket.cpp \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/proxy/ \\\n \t\t\t @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\ndiff --git a/include/libcamera/internal/ipc_pipe_unixsocket.h b/include/libcamera/internal/ipc_pipe_unixsocket.h\nnew file mode 100644\nindex 00000000..fea3179c\n--- /dev/null\n+++ b/include/libcamera/internal/ipc_pipe_unixsocket.h\n@@ -0,0 +1,50 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe_unixsocket.h - Image Processing Algorithm IPC module using unix socket\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__\n+#define __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__\n+\n+#include <map>\n+#include <memory>\n+#include <vector>\n+\n+#include \"libcamera/internal/ipc_pipe.h\"\n+#include \"libcamera/internal/ipc_unixsocket.h\"\n+\n+namespace libcamera {\n+\n+class Process;\n+\n+class IPCPipeUnixSocket : public IPCPipe\n+{\n+public:\n+\tIPCPipeUnixSocket(const char *ipaModulePath, const char *ipaProxyWorkerPath);\n+\t~IPCPipeUnixSocket();\n+\n+\tint sendSync(uint32_t cmd,\n+\t\t const IPCMessage &in,\n+\t\t IPCMessage *out = nullptr) override;\n+\n+\tint sendAsync(uint32_t cmd, const IPCMessage &data) override;\n+\n+private:\n+\tstruct CallData {\n+\t\tIPCUnixSocket::Payload *response;\n+\t\tbool done;\n+\t};\n+\n+\tvoid readyRead(IPCUnixSocket *socket);\n+\tint call(const IPCUnixSocket::Payload &message, IPCUnixSocket::Payload *response, uint32_t seq);\n+\n+\tuint32_t seq_;\n+\tstd::unique_ptr<Process> proc_;\n+\tstd::unique_ptr<IPCUnixSocket> socket_;\n+\tstd::map<uint32_t, CallData> callData_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_IPA_IPC_UNIXSOCKET_H__ */\ndiff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp\nnew file mode 100644\nindex 00000000..b47c47d2\n--- /dev/null\n+++ b/src/libcamera/ipc_pipe_unixsocket.cpp\n@@ -0,0 +1,147 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * ipc_pipe_unixsocket.cpp - Image Processing Algorithm IPC module using unix socket\n+ */\n+\n+#include \"libcamera/internal/ipc_pipe_unixsocket.h\"\n+\n+#include <vector>\n+\n+#include \"libcamera/internal/event_dispatcher.h\"\n+#include \"libcamera/internal/ipc_pipe.h\"\n+#include \"libcamera/internal/ipc_unixsocket.h\"\n+#include \"libcamera/internal/log.h\"\n+#include \"libcamera/internal/process.h\"\n+#include \"libcamera/internal/thread.h\"\n+#include \"libcamera/internal/timer.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(IPCPipe)\n+\n+IPCPipeUnixSocket::IPCPipeUnixSocket(const char *ipaModulePath,\n+\t\t\t\t const char *ipaProxyWorkerPath)\n+\t: IPCPipe(), seq_(0),\n+\t proc_(nullptr), socket_(nullptr)\n+{\n+\tstd::vector<int> fds;\n+\tstd::vector<std::string> args;\n+\targs.push_back(ipaModulePath);\n+\n+\tsocket_ = std::make_unique<IPCUnixSocket>();\n+\tint fd = socket_->create();\n+\tif (fd < 0) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to create socket\";\n+\t\treturn;\n+\t}\n+\tsocket_->readyRead.connect(this, &IPCPipeUnixSocket::readyRead);\n+\targs.push_back(std::to_string(fd));\n+\tfds.push_back(fd);\n+\n+\tproc_ = std::make_unique<Process>();\n+\tint ret = proc_->start(ipaProxyWorkerPath, args, fds);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error)\n+\t\t\t<< \"Failed to start proxy worker process\";\n+\t\treturn;\n+\t}\n+\n+\tconnected_ = true;\n+}\n+\n+IPCPipeUnixSocket::~IPCPipeUnixSocket()\n+{\n+}\n+\n+int IPCPipeUnixSocket::sendSync(uint32_t cmd,\n+\t\t\t\tconst IPCMessage &in, IPCMessage *out)\n+{\n+\tIPCUnixSocket::Payload message, response;\n+\n+\tconst IPCMessage::Header header{ cmd, ++seq_ };\n+\tmessage = in.payload(&header);\n+\n+\tint ret = call(message, &response, seq_);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to call sync\";\n+\t\tcallData_.erase(seq_);\n+\t\treturn ret;\n+\t}\n+\n+\tif (out)\n+\t\t*out = IPCMessage(response);\n+\n+\treturn 0;\n+}\n+\n+int IPCPipeUnixSocket::sendAsync(uint32_t cmd, const IPCMessage &data)\n+{\n+\tconst IPCMessage::Header header{ cmd, 0 };\n+\tIPCUnixSocket::Payload message = data.payload(&header);\n+\n+\tint ret = socket_->send(message);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Failed to call async\";\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void IPCPipeUnixSocket::readyRead(IPCUnixSocket *socket)\n+{\n+\tIPCUnixSocket::Payload message;\n+\tint ret = socket->receive(&message);\n+\tif (ret) {\n+\t\tLOG(IPCPipe, Error) << \"Receive message failed\" << ret;\n+\t\treturn;\n+\t}\n+\n+\t/* \\todo Use span to avoid the double copy when callData is found. */\n+\tIPCMessage ipcMessage(message);\n+\n+\tauto callData = callData_.find(ipcMessage.header().cookie);\n+\tif (callData != callData_.end()) {\n+\t\t*callData->second.response = std::move(message);\n+\t\tcallData->second.done = true;\n+\t\treturn;\n+\t}\n+\n+\t/* Received unexpected data, this means it's a call from the IPA. */\n+\trecv.emit(ipcMessage.header().cmd, ipcMessage);\n+\n+\treturn;\n+}\n+\n+int IPCPipeUnixSocket::call(const IPCUnixSocket::Payload &message,\n+\t\t\t IPCUnixSocket::Payload *response, uint32_t cookie)\n+{\n+\tTimer timeout;\n+\tint ret;\n+\n+\tcallData_[cookie].response = response;\n+\tcallData_[cookie].done = false;\n+\n+\tret = socket_->send(message);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\ttimeout.start(2000);\n+\twhile (!callData_[cookie].done) {\n+\t\tif (!timeout.isRunning()) {\n+\t\t\tLOG(IPCPipe, Error) << \"Call timeout!\";\n+\t\t\tcallData_.erase(cookie);\n+\t\t\treturn -ETIMEDOUT;\n+\t\t}\n+\n+\t\tThread::current()->eventDispatcher()->processEvents();\n+\t}\n+\n+\tcallData_.erase(cookie);\n+\n+\treturn 0;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex b7cfe0c2..cd3cf9e3 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -31,6 +31,7 @@ libcamera_sources = files([\n 'ipa_module.cpp',\n 'ipa_proxy.cpp',\n 'ipc_pipe.cpp',\n+ 'ipc_pipe_unixsocket.cpp',\n 'ipc_unixsocket.cpp',\n 'log.cpp',\n 'media_device.cpp',\n", "prefixes": [ "libcamera-devel", "v5", "07/23" ] }