Patch Detail
Show a patch.
GET /api/patches/105/?format=api
{ "id": 105, "url": "https://patchwork.libcamera.org/api/patches/105/?format=api", "web_url": "https://patchwork.libcamera.org/patch/105/", "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-11-niklas.soderlund@ragnatech.se>", "date": "2018-12-29T03:28:53", "name": "[libcamera-devel,v2,10/12] libcamera: camera_manager: add CameraManager class", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "47f1cb3d5a7b691e77fee93c950863c7a898c3d0", "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/105/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/105/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/105/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 DC2F760B47\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 fd397e64-0b19-11e9-911a-0050569116f7;\n\tSat, 29 Dec 2018 04:29:46 +0100 (CET)" ], "X-Halon-ID": "fd397e64-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:53 +0100", "Message-Id": "<20181229032855.26249-11-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 10/12] libcamera: camera_manager: 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, 29 Dec 2018 03:29:59 -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/camera_manager.h | 38 +++++++\n include/libcamera/libcamera.h | 1 +\n include/libcamera/meson.build | 1 +\n src/libcamera/camera_manager.cpp | 166 +++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 5 files changed, 207 insertions(+)\n create mode 100644 include/libcamera/camera_manager.h\n create mode 100644 src/libcamera/camera_manager.cpp", "diff": "diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\nnew file mode 100644\nindex 0000000000000000..9d032d71c4c0841a\n--- /dev/null\n+++ b/include/libcamera/camera_manager.h\n@@ -0,0 +1,38 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * camera_manager.h - Camera management\n+ */\n+#ifndef __LIBCAMERA_CAMERA_MANAGER_H__\n+#define __LIBCAMERA_CAMERA_MANAGER_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+\tint 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_CAMERA_MANAGER_H__ */\ndiff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h\nindex 44c094d92feed5ba..32fb1ff741a7b97a 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/camera_manager.h>\n \n namespace libcamera {\n \ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 9b266ad926681db9..3e04557d66b1a8f4 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+ 'camera_manager.h',\n 'libcamera.h',\n ])\n \ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nnew file mode 100644\nindex 0000000000000000..1160381b72a08850\n--- /dev/null\n+++ b/src/libcamera/camera_manager.cpp\n@@ -0,0 +1,166 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * camera_manager.h - Camera management\n+ */\n+\n+#include <libcamera/camera_manager.h>\n+\n+#include \"device_enumerator.h\"\n+#include \"pipeline_handler.h\"\n+\n+/**\n+ * \\file camera_manager.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_(nullptr)\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 start 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+int CameraManager::start()\n+{\n+\tstd::vector<std::string> handlers;\n+\n+\tif (enumerator_)\n+\t\treturn -ENODEV;\n+\n+\tenumerator_ = DeviceEnumerator::create();\n+\n+\tif (enumerator_->enumerate())\n+\t\treturn -ENODEV;\n+\n+\t/*\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+\tPipelineHandlerFactory::handlers(handlers);\n+\n+\tfor (std::string const &handler : handlers) {\n+\t\tPipelineHandler *pipe;\n+\n+\t\t/*\n+\t\t * Try each pipeline handler until it exhaust\n+\t\t * all pipelines it can provide.\n+\t\t */\n+\t\tdo {\n+\t\t\tpipe = PipelineHandlerFactory::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 0;\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 has been stopped no resource provided by 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+\tpipes_.clear();\n+\n+\tif (enumerator_)\n+\t\tdelete enumerator_;\n+\n+\tenumerator_ = nullptr;\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+ * release by the user with the put() method of the Camera object once\n+ * it's done using the camera.\n+ *\n+ * \\return Pointer to Camera object or nullptr 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 nullptr;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 0db648dd3e37156e..a8cb3fdc22784334 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+ 'camera_manager.cpp',\n 'device_enumerator.cpp',\n 'log.cpp',\n 'main.cpp',\n", "prefixes": [ "libcamera-devel", "v2", "10/12" ] }