libcamera: device_enumerator: Convey device ownership through unique_ptr
Replace usage of shared_ptr with unique_ptr to convey media device ownership internally in the enumerators when creating the media device. Once a media device has all its dependencies met, it is converted to a shared_ptr to keep the external API unchanged. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
@@ -208,9 +208,9 @@ DeviceEnumerator::~DeviceEnumerator()
|
||||
*
|
||||
* \return Created media device instance on success, or nullptr otherwise
|
||||
*/
|
||||
std::shared_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &deviceNode)
|
||||
std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &deviceNode)
|
||||
{
|
||||
std::shared_ptr<MediaDevice> media = std::make_shared<MediaDevice>(deviceNode);
|
||||
std::unique_ptr<MediaDevice> media = std::make_unique<MediaDevice>(deviceNode);
|
||||
|
||||
int ret = media->populate();
|
||||
if (ret < 0) {
|
||||
@@ -236,12 +236,12 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::createDevice(const std::string &d
|
||||
* This method shall be called after all members of the entities of the
|
||||
* media graph have been confirmed to be initialized.
|
||||
*/
|
||||
void DeviceEnumerator::addDevice(const std::shared_ptr<MediaDevice> &media)
|
||||
void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> &&media)
|
||||
{
|
||||
LOG(DeviceEnumerator, Debug)
|
||||
<< "Added device " << media->deviceNode() << ": " << media->driver();
|
||||
|
||||
devices_.push_back(media);
|
||||
devices_.push_back(std::move(media));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +290,7 @@ void DeviceEnumerator::removeDevice(const std::string &deviceNode)
|
||||
*/
|
||||
std::shared_ptr<MediaDevice> DeviceEnumerator::search(const DeviceMatch &dm)
|
||||
{
|
||||
for (std::shared_ptr<MediaDevice> media : devices_) {
|
||||
for (std::shared_ptr<MediaDevice> &media : devices_) {
|
||||
if (media->busy())
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user