libcamera: device_enumerator: Emit a signal when new devices are added
Emit a signal whenever new MediaDevices are added to the DeviceEnumerator. This will allow CameraManager to be notified about the new devices and it can re-emumerate all the devices currently present on the system. Device enumeration by the CameraManger is an expensive operation hence, we want one signal emission per 'x' milliseconds to notify multiple devices additions as a single batch, by the DeviceEnumerator. Add a \todo to investigate the support for that. Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
c6f8ec7d8a
commit
dd21ededd0
3 changed files with 19 additions and 2 deletions
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <linux/media.h>
|
#include <linux/media.h>
|
||||||
|
|
||||||
|
#include <libcamera/signal.h>
|
||||||
|
|
||||||
namespace libcamera {
|
namespace libcamera {
|
||||||
|
|
||||||
class MediaDevice;
|
class MediaDevice;
|
||||||
|
@ -43,6 +45,8 @@ public:
|
||||||
|
|
||||||
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
|
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
|
||||||
|
|
||||||
|
Signal<> devicesAdded;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
||||||
void addDevice(std::unique_ptr<MediaDevice> &&media);
|
void addDevice(std::unique_ptr<MediaDevice> &&media);
|
||||||
|
|
|
@ -155,12 +155,12 @@ void CameraManager::Private::createPipelineHandlers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \todo Register hot-plug callback here */
|
enumerator_->devicesAdded.connect(this, &Private::createPipelineHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraManager::Private::cleanup()
|
void CameraManager::Private::cleanup()
|
||||||
{
|
{
|
||||||
/* \todo Unregister hot-plug callback here */
|
enumerator_->devicesAdded.disconnect(this, &Private::createPipelineHandlers);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Release all references to cameras to ensure they all get destroyed
|
* Release all references to cameras to ensure they all get destroyed
|
||||||
|
|
|
@ -227,6 +227,16 @@ std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &d
|
||||||
return media;
|
return media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \var DeviceEnumerator::devicesAdded
|
||||||
|
* \brief Notify of new media devices being found
|
||||||
|
*
|
||||||
|
* This signal is emitted when the device enumerator finds new media devices in
|
||||||
|
* the system. It may be emitted for every newly detected device, or once for
|
||||||
|
* multiple devices, at the discretion of the device enumerator. Not all device
|
||||||
|
* enumerator types may support dynamic detection of new devices.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Add a media device to the enumerator
|
* \brief Add a media device to the enumerator
|
||||||
* \param[in] media media device instance to add
|
* \param[in] media media device instance to add
|
||||||
|
@ -242,6 +252,9 @@ void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> &&media)
|
||||||
<< "Added device " << media->deviceNode() << ": " << media->driver();
|
<< "Added device " << media->deviceNode() << ": " << media->driver();
|
||||||
|
|
||||||
devices_.push_back(std::move(media));
|
devices_.push_back(std::move(media));
|
||||||
|
|
||||||
|
/* \todo To batch multiple additions, emit with a small delay here. */
|
||||||
|
devicesAdded.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue