From f3695e9b09ce4a88d6e0480d9e5058673af34a49 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 3 Jan 2019 13:10:37 +0200 Subject: libcamera: camera_manager: Register cameras with the camera manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cameras are listed through a double indirection, first iterating over all available pipeline handlers, and then listing the cameras they each support. To simplify the API make the pipeline handlers register the cameras with the camera manager directly, which lets the camera manager easily expose the list of all available cameras. The PipelineHandler API gets simplified as the handlers don't need to expose the list of cameras they have created. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/camera_manager.cpp | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'src/libcamera/camera_manager.cpp') diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 1430bb0d..3fa9f23c 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -94,7 +94,7 @@ int CameraManager::start() */ while (1) { PipelineHandler *pipe = factory->create(); - if (!pipe->match(enumerator_.get())) { + if (!pipe->match(this, enumerator_.get())) { delete pipe; break; } @@ -133,26 +133,14 @@ void CameraManager::stop() } /** - * \brief List all detected cameras + * \fn CameraManager::cameras() + * \brief Retrieve all available cameras * * Before calling this function the caller is responsible for ensuring that * the camera manger is running. * - * \return List of names for all detected cameras + * \return List of all available cameras */ -std::vector CameraManager::list() const -{ - std::vector list; - - for (PipelineHandler *pipe : pipes_) { - for (unsigned int i = 0; i < pipe->count(); i++) { - Camera *cam = pipe->camera(i); - list.push_back(cam->name()); - } - } - - return list; -} /** * \brief Get a camera based on name @@ -168,19 +156,35 @@ std::vector CameraManager::list() const */ Camera *CameraManager::get(const std::string &name) { - for (PipelineHandler *pipe : pipes_) { - for (unsigned int i = 0; i < pipe->count(); i++) { - Camera *cam = pipe->camera(i); - if (cam->name() == name) { - cam->get(); - return cam; - } - } + for (Camera *camera : cameras_) { + if (camera->name() == name) + return camera; } return nullptr; } +/** + * \brief Add a camera to the camera manager + * \param[in] camera The camera to be added + * + * This function is called by pipeline handlers to register the cameras they + * handle with the camera manager. Registered cameras are immediately made + * available to the system. + */ +void CameraManager::addCamera(Camera *camera) +{ + for (Camera *c : cameras_) { + if (c->name() == camera->name()) { + LOG(Warning) << "Registering camera with duplicate name '" + << camera->name() << "'"; + break; + } + } + + cameras_.push_back(camera); +} + /** * \brief Retrieve the camera manager instance * -- cgit v1.2.1