Patch Detail
Show a patch.
GET /api/1.1/patches/86/?format=api
{ "id": 86, "url": "https://patchwork.libcamera.org/api/1.1/patches/86/?format=api", "web_url": "https://patchwork.libcamera.org/patch/86/", "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": "<20181222230041.29999-11-niklas.soderlund@ragnatech.se>", "date": "2018-12-22T23:00:39", "name": "[libcamera-devel,10/12] libcamera: cameramanager: add CameraManager class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "c7ec492195083ee9c1e8d4fea8bd29318ab8e057", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/86/mbox/", "series": [ { "id": 38, "url": "https://patchwork.libcamera.org/api/1.1/series/38/?format=api", "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/86/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/86/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5231060B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Dec 2018 00:02:35 +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 9ae16192-063d-11e9-9adf-005056917a89;\n\tSun, 23 Dec 2018 00:02:08 +0100 (CET)" ], "X-Halon-ID": "9ae16192-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:39 +0100", "Message-Id": "<20181222230041.29999-11-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 10/12] libcamera: cameramanager: add\n\tCameraManager 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:35 -0000" }, "content": "Provide a CameraManager class which will handle listing, instancing,\ndestruction and lifetime management of cameras.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/cameramanager.h | 38 +++++++\n include/libcamera/libcamera.h | 1 +\n include/libcamera/meson.build | 1 +\n src/libcamera/cameramanager.cpp | 173 ++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 5 files changed, 214 insertions(+)\n create mode 100644 include/libcamera/cameramanager.h\n create mode 100644 src/libcamera/cameramanager.cpp", "diff": "diff --git a/include/libcamera/cameramanager.h b/include/libcamera/cameramanager.h\nnew file mode 100644\nindex 0000000000000000..be078a75f9e5aefc\n--- /dev/null\n+++ b/include/libcamera/cameramanager.h\n@@ -0,0 +1,38 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * cameramanager.h - Camera management\n+ */\n+#ifndef __LIBCAMERA_CAMERAMANAGER_H__\n+#define __LIBCAMERA_CAMERAMANAGER_H__\n+\n+#include <vector>\n+#include <string>\n+\n+namespace libcamera {\n+\n+class Camera;\n+class DeviceEnumerator;\n+class PipelineHandler;\n+\n+class CameraManager\n+{\n+public:\n+\tCameraManager();\n+\n+\tbool start();\n+\tvoid stop();\n+\n+\tstd::vector<std::string> list() const;\n+\tCamera *get(const std::string &name);\n+\tvoid put(Camera *camera);\n+\n+private:\n+\tDeviceEnumerator *enumerator_;\n+\tstd::vector<PipelineHandler *> pipes_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_CAMERAMANAGER_H__ */\ndiff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h\nindex 44c094d92feed5ba..286b3d4d28083b01 100644\n--- a/include/libcamera/libcamera.h\n+++ b/include/libcamera/libcamera.h\n@@ -8,6 +8,7 @@\n #define __LIBCAMERA_LIBCAMERA_H__\n \n #include <libcamera/camera.h>\n+#include <libcamera/cameramanager.h>\n \n namespace libcamera {\n \ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 9b266ad926681db9..b7ba1f124aada003 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -1,5 +1,6 @@\n libcamera_api = files([\n 'camera.h',\n+ 'cameramanager.h',\n 'libcamera.h',\n ])\n \ndiff --git a/src/libcamera/cameramanager.cpp b/src/libcamera/cameramanager.cpp\nnew file mode 100644\nindex 0000000000000000..53209e32d88e3ed3\n--- /dev/null\n+++ b/src/libcamera/cameramanager.cpp\n@@ -0,0 +1,173 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * cameramanager.h - Camera management\n+ */\n+\n+#include <libcamera/cameramanager.h>\n+\n+#include \"deviceenumerator.h\"\n+#include \"pipelinehandler.h\"\n+\n+/**\n+ * \\file cameramanager.h\n+ * \\brief Manage all cameras handled by libcamera\n+ *\n+ * The responsibility of the camera manager is to control the lifetime\n+ * management of objects provided by libcamera.\n+ *\n+ * When a user wish to interact with libcamera it creates and starts a\n+ * CameraManager object. Once confirmed the camera manager is running\n+ * the application can list all cameras detected by the library, get\n+ * one or more of the cameras and interact with them.\n+ *\n+ * When the user is done with the camera it should be returned to the\n+ * camera manager. Once all cameras are returned to the camera manager\n+ * the user is free to stop the manager.\n+ *\n+ * \\todo Add ability to add and remove media devices based on\n+ * hot-(un)plug events coming from the device enumerator.\n+ *\n+ * \\todo Add interface to register a notification callback to the user\n+ * to be able to inform it new cameras have been hot-plugged or\n+ * cameras have been removed due to hot-unplug.\n+ */\n+\n+namespace libcamera {\n+\n+CameraManager::CameraManager()\n+\t: enumerator_(NULL)\n+{\n+}\n+\n+/**\n+ * \\brief Start the camera manager\n+ *\n+ * Start the camera manager and enumerate all devices in the system. Once\n+ * the stat have been confirmed the user is free to list and otherwise\n+ * interact with cameras in the system until either the camera manager\n+ * is stopped or the camera is unplugged from the system.\n+ *\n+ * \\return true on successful start false otherwise\n+ */\n+bool CameraManager::start()\n+{\n+\tstd::vector<std::string> handlers;\n+\n+\tif (enumerator_)\n+\t\treturn false;\n+\n+\tenumerator_ = DeviceEnumerator::create();\n+\n+\tif (enumerator_->enumerate())\n+\t\treturn false;\n+\n+\t/* TODO: Try to read handlers and order from configuration\n+\t * file and only fallback on all handlers if there is no\n+\t * configuration file.\n+\t */\n+\tPipelineHandler::handlers(handlers);\n+\n+\tfor (std::string const &handler : handlers) {\n+\t\tPipelineHandler *pipe;\n+\n+\t\t/* Try each pipeline handler until it exhaust\n+\t\t * all pipelines it can provide. */\n+\t\tdo {\n+\t\t\tpipe = PipelineHandler::create(handler, enumerator_);\n+\t\t\tif (pipe)\n+\t\t\t\tpipes_.push_back(pipe);\n+\t\t} while (pipe);\n+\t}\n+\n+\t/* TODO: register hot-plug callback here */\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Stop the camera manager\n+ *\n+ * Before stopping the camera manger the caller is responsible for making\n+ * sure all cameras provided by the manager are returned to the manager.\n+ *\n+ * After the manager have been stopped no resource provided my the camera\n+ * manager should be consider valid or functional even if they for one\n+ * reason or another have yet to be deleted.\n+ */\n+void CameraManager::stop()\n+{\n+\t/* TODO: unregister hot-plug callback here */\n+\n+\tfor (PipelineHandler *pipe : pipes_)\n+\t\tdelete pipe;\n+\n+\tif (enumerator_)\n+\t\tdelete enumerator_;\n+\n+\tenumerator_ = NULL;\n+}\n+\n+/**\n+ * \\brief List all detected cameras\n+ *\n+ * Before calling this function the caller is responsible to make sure\n+ * the camera manger is running.\n+ *\n+ * \\return List of names for all detected cameras\n+ */\n+std::vector<std::string> CameraManager::list() const\n+{\n+\tstd::vector<std::string> list;\n+\n+\tfor (PipelineHandler *pipe : pipes_) {\n+\t\tfor (unsigned int i = 0; i < pipe->count(); i++) {\n+\t\t\tCamera *cam = pipe->camera(i);\n+\t\t\tlist.push_back(cam->name());\n+\t\t}\n+\t}\n+\n+\treturn list;\n+}\n+\n+/**\n+ * \\brief Get a camera based on name\n+ *\n+ * \\param[in] name Name of camera to get\n+ *\n+ * Before calling this function the caller is responsible to make sure\n+ * the camera manger is running. A camera fetched this way should be\n+ * returned to the camera manger once the caller is done with it.\n+ *\n+ * \\return Pointer to Camera object or NULL if camera not found\n+ */\n+Camera *CameraManager::get(const std::string &name)\n+{\n+\tfor (PipelineHandler *pipe : pipes_) {\n+\t\tfor (unsigned int i = 0; i < pipe->count(); i++) {\n+\t\t\tCamera *cam = pipe->camera(i);\n+\t\t\tif (cam->name() == name) {\n+\t\t\t\tcam->get();\n+\t\t\t\treturn cam;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+/**\n+ * \\brief Return camera to the camera manager\n+ *\n+ * \\param[in] camera Camera to return to the manager\n+ *\n+ * After the camera have been returned to the camera manager the caller\n+ * should not use the pointer to the camera object it has returned.\n+ */\n+void CameraManager::put(Camera *camera)\n+{\n+\tcamera->put();\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 0776643d3064129d..8457e57939b862ed 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -1,5 +1,6 @@\n libcamera_sources = files([\n 'camera.cpp',\n+ 'cameramanager.cpp',\n 'deviceenumerator.cpp',\n 'log.cpp',\n 'main.cpp',\n", "prefixes": [ "libcamera-devel", "10/12" ] }