From 5801dedd2a30e7123a0f78e6140c409c7c35988c Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Fri, 5 Jun 2020 20:36:32 +0900 Subject: libcamera: CameraManager, PipelineHandler: Automatically map devnums to Camera MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The V4L2 compatibility layer uses devnum to match video device nodes to libcamera Cameras. Some pipeline handlers don't report a devnum for their camera, which prevents the V4L2 compatibility layer from matching video device nodes to these cameras. To fix this, we first allow the camera manager to map multiple devnums to a camera. Next, we walk the media device and entity list and tell the camera manager to map every one of these devnums that is a video capture node to the camera. Since we decided that all video capture nodes that belong to a camera can be opened via the V4L2 compatibility layer to map to that camera, it would cause confusion for users if some pipeline handlers decided that only specific device nodes would map to the camera. To prevent this confusion, remove the ability for pipeline handlers to declare their own devnum-to-camera mapping. The only pipeline handler that declares the devnum mapping is the UVC pipeline handler, so remove the devnum there. We considered walking the media entity list and taking the devnum from just the one with the default flag set, but we found that some drivers (eg. vimc) don't set this flag for any entity. Instead, we take all the video capture nodes (entities with the sink pad flag set). Signed-off-by: Paul Elder Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/camera_manager.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/libcamera/camera_manager.cpp') diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index da806fa7..576856ab 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -36,7 +36,8 @@ public: Private(CameraManager *cm); int start(); - void addCamera(std::shared_ptr &camera, dev_t devnum); + void addCamera(std::shared_ptr &camera, + const std::vector &devnums); void removeCamera(Camera *camera); /* @@ -168,7 +169,7 @@ void CameraManager::Private::cleanup() } void CameraManager::Private::addCamera(std::shared_ptr &camera, - dev_t devnum) + const std::vector &devnums) { MutexLocker locker(mutex_); @@ -183,10 +184,9 @@ void CameraManager::Private::addCamera(std::shared_ptr &camera, cameras_.push_back(std::move(camera)); - if (devnum) { - unsigned int index = cameras_.size() - 1; + unsigned int index = cameras_.size() - 1; + for (dev_t devnum : devnums) camerasByDevnum_[devnum] = cameras_[index]; - } } void CameraManager::Private::removeCamera(Camera *camera) @@ -374,22 +374,23 @@ std::shared_ptr CameraManager::get(dev_t devnum) /** * \brief Add a camera to the camera manager * \param[in] camera The camera to be added - * \param[in] devnum The device number to associate with \a camera + * \param[in] devnums The device numbers to associate with \a camera * * 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. * - * \a devnum is used by the V4L2 compatibility layer to map V4L2 device nodes + * \a devnums are used by the V4L2 compatibility layer to map V4L2 device nodes * to Camera instances. * * \context This function shall be called from the CameraManager thread. */ -void CameraManager::addCamera(std::shared_ptr camera, dev_t devnum) +void CameraManager::addCamera(std::shared_ptr camera, + const std::vector &devnums) { ASSERT(Thread::current() == p_.get()); - p_->addCamera(camera, devnum); + p_->addCamera(camera, devnums); } /** -- cgit v1.2.1