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/pipeline_handler.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/libcamera/pipeline_handler.cpp') diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 53aeebdc..a0f6b0f1 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -481,28 +481,38 @@ void PipelineHandler::completeRequest(Camera *camera, Request *request) * \brief Register a camera to the camera manager and pipeline handler * \param[in] camera The camera to be added * \param[in] data Pipeline-specific data for the camera - * \param[in] devnum Device number of the camera (optional) * * This method is called by pipeline handlers to register the cameras they * handle with the camera manager. It associates the pipeline-specific \a data * with the camera, for later retrieval with cameraData(). Ownership of \a data * is transferred to the PipelineHandler. * - * \a devnum is the device number (as returned by makedev) that the \a camera - * is to be associated with. This is for the V4L2 compatibility layer to map - * device nodes to Camera instances based on the device number - * registered by this method in \a devnum. - * * \context This function shall be called from the CameraManager thread. */ void PipelineHandler::registerCamera(std::shared_ptr camera, - std::unique_ptr data, - dev_t devnum) + std::unique_ptr data) { data->camera_ = camera.get(); cameraData_[camera.get()] = std::move(data); cameras_.push_back(camera); - manager_->addCamera(std::move(camera), devnum); + + /* + * Walk the entity list and map the devnums of all capture video nodes + * to the camera. + */ + std::vector devnums; + for (const std::shared_ptr &media : mediaDevices_) { + for (const MediaEntity *entity : media->entities()) { + if (entity->pads().size() == 1 && + (entity->pads()[0]->flags() & MEDIA_PAD_FL_SINK) && + entity->function() == MEDIA_ENT_F_IO_V4L) { + devnums.push_back(makedev(entity->deviceMajor(), + entity->deviceMinor())); + } + } + } + + manager_->addCamera(std::move(camera), devnums); } /** -- cgit v1.2.1