{"id":85,"url":"https://patchwork.libcamera.org/api/1.1/patches/85/?format=json","web_url":"https://patchwork.libcamera.org/patch/85/","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":"<20181222230041.29999-10-niklas.soderlund@ragnatech.se>","date":"2018-12-22T23:00:38","name":"[libcamera-devel,09/12] libcamera: pipelinehandler: add PipelineHandler class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"926d287eee5052950aa59bc228847ef84d7c3054","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/85/mbox/","series":[{"id":38,"url":"https://patchwork.libcamera.org/api/1.1/series/38/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=38","date":"2018-12-22T23:00:29","name":"Add basic camera enumeration","version":1,"mbox":"https://patchwork.libcamera.org/series/38/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/85/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/85/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 1EF1C60B34\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:33 +0100 (CET)","from wyvern.dyn.berto.se (unknown [217.31.177.236])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 996a0c8f-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:02:06 +0100 (CET)"],"X-Halon-ID":"996a0c8f-063d-11e9-9adf-005056917a89","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":"Sun, 23 Dec 2018 00:00:38 +0100","Message-Id":"<20181222230041.29999-10-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20181222230041.29999-1-niklas.soderlund@ragnatech.se>","References":"<20181222230041.29999-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 09/12] libcamera: pipelinehandler: 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, 22 Dec 2018 23:02:33 -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/pipelinehandler.h |  71 ++++++++++++++\n src/libcamera/meson.build               |   2 +\n src/libcamera/pipelinehandler.cpp       | 122 ++++++++++++++++++++++++\n 3 files changed, 195 insertions(+)\n create mode 100644 src/libcamera/include/pipelinehandler.h\n create mode 100644 src/libcamera/pipelinehandler.cpp","diff":"diff --git a/src/libcamera/include/pipelinehandler.h b/src/libcamera/include/pipelinehandler.h\nnew file mode 100644\nindex 0000000000000000..0e2f497a4fda3caa\n--- /dev/null\n+++ b/src/libcamera/include/pipelinehandler.h\n@@ -0,0 +1,71 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * pipelinehandler.h - Pipeline handler infrastructure\n+ */\n+#ifndef __LIBCAMERA_PIPELINEHANDLER_H__\n+#define __LIBCAMERA_PIPELINEHANDLER_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+\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 *> &registry();\n+};\n+\n+class PipelineHandlerFactory\n+{\n+public:\n+\n+\tvirtual ~PipelineHandlerFactory() { };\n+\n+\tvirtual PipelineHandler *create() = 0;\n+};\n+\n+/**\n+ * \\brief Register a pipeline hander 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+#define REGISTER_PIPELINE(handler) \\\n+\tclass handler##Factory : public PipelineHandlerFactory { \\\n+\tpublic: \\\n+\t\thandler##Factory() \\\n+\t\t{ \\\n+\t\t\tPipelineHandler::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_PIPELINEHANDLER_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 17cdf06dd2bedfb3..0776643d3064129d 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -3,11 +3,13 @@ libcamera_sources = files([\n     'deviceenumerator.cpp',\n     'log.cpp',\n     'main.cpp',\n+    'pipelinehandler.cpp',\n ])\n \n libcamera_headers = files([\n     'include/deviceenumerator.h',\n     'include/log.h',\n+    'include/pipelinehandler.h',\n     'include/utils.h',\n ])\n \ndiff --git a/src/libcamera/pipelinehandler.cpp b/src/libcamera/pipelinehandler.cpp\nnew file mode 100644\nindex 0000000000000000..3c47f1ceb72eb6f6\n--- /dev/null\n+++ b/src/libcamera/pipelinehandler.cpp\n@@ -0,0 +1,122 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * pipelinehandler.cpp - Pipeline handler infrastructure\n+ */\n+\n+#include \"deviceenumerator.h\"\n+#include \"log.h\"\n+#include \"pipelinehandler.h\"\n+\n+/**\n+ * \\file pipelinehandler.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+ * important macro REGISTER_PIPELINE() is provided which allows a pipeline\n+ * hander implementation to register itself with the library with ease.\n+ *\n+ * \\todo Figure out how and if the PipelineHandler should be involved in\n+ *       controlling cameras with resource dependencies and if the handler\n+ *       should provide helpers for cameras to control media graph links.\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+ * \\brief Add a pipeline hander 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 PipelineHandler::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 hander 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 NULL\n+ */\n+PipelineHandler *PipelineHandler::create(const std::string &name, DeviceEnumerator *enumerator)\n+{\n+\tstd::map<std::string, PipelineHandlerFactory *> &factories = registry();\n+\n+\tif (!factories.count(name)) {\n+\t\tLOG(Error) << \"Trying to create non-existing pipeline handler \" << name;\n+\t\treturn NULL;\n+\t}\n+\n+\tPipelineHandler *pipe;\n+\n+\tpipe = factories[name]->create();\n+\n+\tif (pipe->match(enumerator))\n+\t\treturn pipe;\n+\n+\tdelete pipe;\n+\treturn NULL;\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 PipelineHandler::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 *> &PipelineHandler::registry()\n+{\n+\tstatic std::map<std::string, PipelineHandlerFactory *> factories;\n+\treturn factories;\n+}\n+\n+} /* namespace libcamera */\n","prefixes":["libcamera-devel","09/12"]}