Patch Detail
Show a patch.
GET /api/patches/103/?format=api
{ "id": 103, "url": "https://patchwork.libcamera.org/api/patches/103/?format=api", "web_url": "https://patchwork.libcamera.org/patch/103/", "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": "<20181229032855.26249-10-niklas.soderlund@ragnatech.se>", "date": "2018-12-29T03:28:52", "name": "[libcamera-devel,v2,09/12] libcamera: pipeline_handler: add PipelineHandler class", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "817fbebeccd13b45ecfe363bab9fce9e88e981e6", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/103/mbox/", "series": [ { "id": 41, "url": "https://patchwork.libcamera.org/api/series/41/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=41", "date": "2018-12-29T03:28:43", "name": "Add basic camera enumeration", "version": 2, "mbox": "https://patchwork.libcamera.org/series/41/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/103/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/103/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4970860B49\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Dec 2018 04:29:58 +0100 (CET)", "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid fcb5f40b-0b19-11e9-911a-0050569116f7;\n\tSat, 29 Dec 2018 04:29:45 +0100 (CET)" ], "X-Halon-ID": "fcb5f40b-0b19-11e9-911a-0050569116f7", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 29 Dec 2018 04:28:52 +0100", "Message-Id": "<20181229032855.26249-10-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20181229032855.26249-1-niklas.soderlund@ragnatech.se>", "References": "<20181229032855.26249-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 09/12] libcamera: pipeline_handler: add\n\tPipelineHandler class", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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>", "X-List-Received-Date": "Sat, 29 Dec 2018 03:29:58 -0000" }, "content": "Provide a PipelineHandler which represents a handler for one or more\nmedia devices and provider of one or more cameras.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/pipeline_handler.h | 62 ++++++++++\n src/libcamera/meson.build | 2 +\n src/libcamera/pipeline_handler.cpp | 138 +++++++++++++++++++++++\n 3 files changed, 202 insertions(+)\n create mode 100644 src/libcamera/include/pipeline_handler.h\n create mode 100644 src/libcamera/pipeline_handler.cpp", "diff": "diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h\nnew file mode 100644\nindex 0000000000000000..a7805a01e1c779bd\n--- /dev/null\n+++ b/src/libcamera/include/pipeline_handler.h\n@@ -0,0 +1,62 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * pipeline_handler.h - Pipeline handler infrastructure\n+ */\n+#ifndef __LIBCAMERA_PIPELINE_HANDLER_H__\n+#define __LIBCAMERA_PIPELINE_HANDLER_H__\n+\n+#include <map>\n+#include <string>\n+#include <vector>\n+\n+#include <libcamera/camera.h>\n+\n+namespace libcamera {\n+\n+class DeviceEnumerator;\n+class PipelineHandlerFactory;\n+\n+class PipelineHandler\n+{\n+public:\n+\tvirtual ~PipelineHandler() { };\n+\n+\tvirtual bool match(DeviceEnumerator *enumerator) = 0;\n+\n+\tvirtual unsigned int count() = 0;\n+\tvirtual Camera *camera(unsigned int id) = 0;\n+};\n+\n+class PipelineHandlerFactory\n+{\n+public:\n+\tvirtual ~PipelineHandlerFactory() { };\n+\n+\tvirtual PipelineHandler *create() = 0;\n+\n+\tstatic void registerType(const std::string &name, PipelineHandlerFactory *factory);\n+\tstatic PipelineHandler *create(const std::string &name, DeviceEnumerator *enumerator);\n+\tstatic void handlers(std::vector<std::string> &handlers);\n+\n+private:\n+\tstatic std::map<std::string, PipelineHandlerFactory *> ®istry();\n+};\n+\n+#define REGISTER_PIPELINE_HANDLER(handler) \\\n+\tclass handler##Factory : public PipelineHandlerFactory { \\\n+\tpublic: \\\n+\t\thandler##Factory() \\\n+\t\t{ \\\n+\t\t\tPipelineHandlerFactory::registerType(#handler, this); \\\n+\t\t} \\\n+\t\tvirtual PipelineHandler *create() { \\\n+\t\t\treturn new handler(); \\\n+\t\t} \\\n+\t}; \\\n+\tstatic handler##Factory global_##handler##Factory;\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_PIPELINE_HANDLER_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 581da1aa78ebb3ba..0db648dd3e37156e 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -3,11 +3,13 @@ libcamera_sources = files([\n 'device_enumerator.cpp',\n 'log.cpp',\n 'main.cpp',\n+ 'pipeline_handler.cpp',\n ])\n \n libcamera_headers = files([\n 'include/device_enumerator.h',\n 'include/log.h',\n+ 'include/pipeline_handler.h',\n 'include/utils.h',\n ])\n \ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nnew file mode 100644\nindex 0000000000000000..b6e28216a6636faf\n--- /dev/null\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -0,0 +1,138 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * pipeline_handler.cpp - Pipeline handler infrastructure\n+ */\n+\n+#include \"device_enumerator.h\"\n+#include \"log.h\"\n+#include \"pipeline_handler.h\"\n+\n+/**\n+ * \\file pipeline_handler.h\n+ * \\brief Create pipelines and cameras from one or more media device\n+ *\n+ * Each pipeline supported by libcamera needs to be backed by a pipeline\n+ * handler implementation which describes the one or many media devices\n+ * needed for a pipeline to function properly.\n+ *\n+ * The pipeline handler is responsible to find all media devices it requires\n+ * to operate and once it retrieves them create all the camera devices\n+ * it is able to support with the that set of devices.\n+ *\n+ * To make it a bit less bit complicated to write pipe line handlers a\n+ * macro REGISTER_PIPELINE_HANDLER() is provided which allows a pipeline\n+ * handler implementation to register itself with the library with ease.\n+ */\n+\n+namespace libcamera {\n+\n+\n+/**\n+ * \\class PipelineHandler\n+ * \\brief Find a set of media devices and provide cameras\n+ *\n+ * The responsibility of a PipelineHandler is to describe all media\n+ * devices it would need in order to provide cameras to the system.\n+ */\n+\n+/**\n+ * \\class PipelineHandlerFactory\n+ * \\brief Keep a registry and create instances of available pipeline handlers\n+ *\n+ * The responsibility of the PipelineHandlerFactory is to keep a list\n+ * of all pipelines in the system. Each pipeline handler should register\n+ * it self with the factory using the REGISTER_PIPELINE_HANDLER() macro.\n+ */\n+\n+/**\n+ * \\brief Add a pipeline handler to the global list\n+ *\n+ * \\param[in] name Name of the pipeline handler to add\n+ * \\param[in] factory Factory to use to construct the pipeline\n+ *\n+ * The caller is responsible to guarantee the uniqueness of the pipeline name.\n+ */\n+void PipelineHandlerFactory::registerType(const std::string &name, PipelineHandlerFactory *factory)\n+{\n+\tstd::map<std::string, PipelineHandlerFactory *> &factories = registry();\n+\n+\tif (factories.count(name)) {\n+\t\tLOG(Error) << \"Registering '\" << name << \"' pipeline twice\";\n+\t\treturn;\n+\t}\n+\n+\tfactories[name] = factory;\n+}\n+\n+/**\n+ * \\brief Create a new pipeline handler and try to match it\n+ *\n+ * \\param[in] name Name of the pipeline handler to try\n+ * \\param[in] enumerator Numerator to to search for a match for the handler\n+ *\n+ * Search \\a enumerator for a match for a pipeline handler named \\a name.\n+ *\n+ * \\return Pipeline handler if a match was found else nullptr\n+ */\n+PipelineHandler *PipelineHandlerFactory::create(const std::string &name, DeviceEnumerator *enumerator)\n+{\n+\tstd::map<std::string, PipelineHandlerFactory *> &factories = registry();\n+\n+\tauto it = factories.find(name);\n+\tif (it == factories.end()) {\n+\t\tLOG(Error) << \"Trying to create non-existing pipeline handler \" << name;\n+\t\treturn nullptr;\n+\t}\n+\n+\tPipelineHandler *pipe;\n+\n+\tpipe = it->second->create();\n+\n+\tif (pipe->match(enumerator))\n+\t\treturn pipe;\n+\n+\tdelete pipe;\n+\treturn nullptr;\n+}\n+\n+/**\n+ * \\brief List all names of handlers from the global list\n+ *\n+ * \\param[out] handlers Names of all handlers registered with the global list\n+ */\n+void PipelineHandlerFactory::handlers(std::vector<std::string> &handlers)\n+{\n+\tstd::map<std::string, PipelineHandlerFactory *> &factories = registry();\n+\n+\tfor (auto const &handler : factories)\n+\t\thandlers.push_back(handler.first);\n+}\n+\n+/**\n+ * \\brief Static global list of pipeline handlers\n+ *\n+ * It might seem odd to hide the static map inside a function.\n+ * This is needed to make sure the list is created before anyone\n+ * tries to access it and creating problems at link time.\n+ *\n+ * \\return Global list of pipeline handlers\n+ */\n+std::map<std::string, PipelineHandlerFactory *> &PipelineHandlerFactory::registry()\n+{\n+\tstatic std::map<std::string, PipelineHandlerFactory *> factories;\n+\treturn factories;\n+}\n+\n+/**\n+ * \\def REGISTER_PIPELINE_HANDLER\n+ * \\brief Register a pipeline handler with the global list\n+ *\n+ * \\param[in] handler Class name of PipelineHandler subclass to register\n+ *\n+ * Register a specifc pipline handler with the global list and make it\n+ * avaiable to try and match devices for libcamera.\n+ */\n+\n+} /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v2", "09/12" ] }