libcamera: CameraManager, PipelineHandler: Automatically map devnums to Camera
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 <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
82d9331efd
commit
5801dedd2a
5 changed files with 33 additions and 24 deletions
|
@ -34,7 +34,8 @@ public:
|
||||||
std::shared_ptr<Camera> get(const std::string &name);
|
std::shared_ptr<Camera> get(const std::string &name);
|
||||||
std::shared_ptr<Camera> get(dev_t devnum);
|
std::shared_ptr<Camera> get(dev_t devnum);
|
||||||
|
|
||||||
void addCamera(std::shared_ptr<Camera> camera, dev_t devnum);
|
void addCamera(std::shared_ptr<Camera> camera,
|
||||||
|
const std::vector<dev_t> &devnums);
|
||||||
void removeCamera(Camera *camera);
|
void removeCamera(Camera *camera);
|
||||||
|
|
||||||
static const std::string &version() { return version_; }
|
static const std::string &version() { return version_; }
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void registerCamera(std::shared_ptr<Camera> camera,
|
void registerCamera(std::shared_ptr<Camera> camera,
|
||||||
std::unique_ptr<CameraData> data, dev_t devnum = 0);
|
std::unique_ptr<CameraData> data);
|
||||||
void hotplugMediaDevice(MediaDevice *media);
|
void hotplugMediaDevice(MediaDevice *media);
|
||||||
|
|
||||||
virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
|
virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
|
||||||
|
|
|
@ -36,7 +36,8 @@ public:
|
||||||
Private(CameraManager *cm);
|
Private(CameraManager *cm);
|
||||||
|
|
||||||
int start();
|
int start();
|
||||||
void addCamera(std::shared_ptr<Camera> &camera, dev_t devnum);
|
void addCamera(std::shared_ptr<Camera> &camera,
|
||||||
|
const std::vector<dev_t> &devnums);
|
||||||
void removeCamera(Camera *camera);
|
void removeCamera(Camera *camera);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -168,7 +169,7 @@ void CameraManager::Private::cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::Private::addCamera(std::shared_ptr<Camera> &camera,
|
void CameraManager::Private::addCamera(std::shared_ptr<Camera> &camera,
|
||||||
dev_t devnum)
|
const std::vector<dev_t> &devnums)
|
||||||
{
|
{
|
||||||
MutexLocker locker(mutex_);
|
MutexLocker locker(mutex_);
|
||||||
|
|
||||||
|
@ -183,10 +184,9 @@ void CameraManager::Private::addCamera(std::shared_ptr<Camera> &camera,
|
||||||
|
|
||||||
cameras_.push_back(std::move(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];
|
camerasByDevnum_[devnum] = cameras_[index];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::Private::removeCamera(Camera *camera)
|
void CameraManager::Private::removeCamera(Camera *camera)
|
||||||
|
@ -374,22 +374,23 @@ std::shared_ptr<Camera> CameraManager::get(dev_t devnum)
|
||||||
/**
|
/**
|
||||||
* \brief Add a camera to the camera manager
|
* \brief Add a camera to the camera manager
|
||||||
* \param[in] camera The camera to be added
|
* \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
|
* This function is called by pipeline handlers to register the cameras they
|
||||||
* handle with the camera manager. Registered cameras are immediately made
|
* handle with the camera manager. Registered cameras are immediately made
|
||||||
* available to the system.
|
* 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.
|
* to Camera instances.
|
||||||
*
|
*
|
||||||
* \context This function shall be called from the CameraManager thread.
|
* \context This function shall be called from the CameraManager thread.
|
||||||
*/
|
*/
|
||||||
void CameraManager::addCamera(std::shared_ptr<Camera> camera, dev_t devnum)
|
void CameraManager::addCamera(std::shared_ptr<Camera> camera,
|
||||||
|
const std::vector<dev_t> &devnums)
|
||||||
{
|
{
|
||||||
ASSERT(Thread::current() == p_.get());
|
ASSERT(Thread::current() == p_.get());
|
||||||
|
|
||||||
p_->addCamera(camera, devnum);
|
p_->addCamera(camera, devnums);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/sysmacros.h>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <libcamera/camera.h>
|
#include <libcamera/camera.h>
|
||||||
|
@ -396,12 +395,10 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
|
||||||
if (data->init(*entity))
|
if (data->init(*entity))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dev_t devnum = makedev((*entity)->deviceMajor(), (*entity)->deviceMinor());
|
|
||||||
|
|
||||||
/* Create and register the camera. */
|
/* Create and register the camera. */
|
||||||
std::set<Stream *> streams{ &data->stream_ };
|
std::set<Stream *> streams{ &data->stream_ };
|
||||||
std::shared_ptr<Camera> camera = Camera::create(this, media->model(), streams);
|
std::shared_ptr<Camera> camera = Camera::create(this, media->model(), streams);
|
||||||
registerCamera(std::move(camera), std::move(data), devnum);
|
registerCamera(std::move(camera), std::move(data));
|
||||||
|
|
||||||
/* Enable hot-unplug notifications. */
|
/* Enable hot-unplug notifications. */
|
||||||
hotplugMediaDevice(media);
|
hotplugMediaDevice(media);
|
||||||
|
|
|
@ -481,28 +481,38 @@ void PipelineHandler::completeRequest(Camera *camera, Request *request)
|
||||||
* \brief Register a camera to the camera manager and pipeline handler
|
* \brief Register a camera to the camera manager and pipeline handler
|
||||||
* \param[in] camera The camera to be added
|
* \param[in] camera The camera to be added
|
||||||
* \param[in] data Pipeline-specific data for the camera
|
* \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
|
* This method is called by pipeline handlers to register the cameras they
|
||||||
* handle with the camera manager. It associates the pipeline-specific \a data
|
* handle with the camera manager. It associates the pipeline-specific \a data
|
||||||
* with the camera, for later retrieval with cameraData(). Ownership of \a data
|
* with the camera, for later retrieval with cameraData(). Ownership of \a data
|
||||||
* is transferred to the PipelineHandler.
|
* 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.
|
* \context This function shall be called from the CameraManager thread.
|
||||||
*/
|
*/
|
||||||
void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera,
|
void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera,
|
||||||
std::unique_ptr<CameraData> data,
|
std::unique_ptr<CameraData> data)
|
||||||
dev_t devnum)
|
|
||||||
{
|
{
|
||||||
data->camera_ = camera.get();
|
data->camera_ = camera.get();
|
||||||
cameraData_[camera.get()] = std::move(data);
|
cameraData_[camera.get()] = std::move(data);
|
||||||
cameras_.push_back(camera);
|
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<dev_t> devnums;
|
||||||
|
for (const std::shared_ptr<MediaDevice> &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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue