diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-01-03 13:10:37 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-01-21 11:13:49 +0200 |
commit | f3695e9b09ce4a88d6e0480d9e5058673af34a49 (patch) | |
tree | 804d52f7b54c2add621f317fd13529d1d27bb17b /src/libcamera/camera_manager.cpp | |
parent | 32bf7ef239c1310fba638f35046b0f7eb13b32bf (diff) |
libcamera: camera_manager: Register cameras with the camera manager
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/camera_manager.cpp')
-rw-r--r-- | src/libcamera/camera_manager.cpp | 52 |
1 files changed, 28 insertions, 24 deletions
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<std::string> CameraManager::list() const -{ - std::vector<std::string> 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,20 +156,36 @@ std::vector<std::string> 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 * * The CameraManager is a singleton and can't be constructed manually. This |