libcamera: pipeline_handler: Keep track of MediaDevice
Instead of requiring each pipeline handle implementation to keep track of calling release() on its media devices upon deletion, keep track of them in the base class. Add a helper that pipeline handlers shall use to acquire a media device instead of directly interacting with the DeviceEnumerator. This also means that pipeline handler implementations do no need to keep a shared_ptr<> reference to the media devices they store locally as the PipelineHandler base class will keep a shared_ptr<> reference to all media devices consumed for the entire lifetime of the pipeline handler implementation. Centrally keeping track of media devices will also be beneficial to implement exclusive access to pipelines across processes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <libcamera/camera.h>
|
||||
#include <libcamera/camera_manager.h>
|
||||
|
||||
#include "device_enumerator.h"
|
||||
#include "log.h"
|
||||
#include "media_device.h"
|
||||
#include "utils.h"
|
||||
@@ -116,6 +117,8 @@ PipelineHandler::PipelineHandler(CameraManager *manager)
|
||||
|
||||
PipelineHandler::~PipelineHandler()
|
||||
{
|
||||
for (std::shared_ptr<MediaDevice> media : mediaDevices_)
|
||||
media->release();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -149,6 +152,35 @@ PipelineHandler::~PipelineHandler()
|
||||
* created, or false otherwise
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Search and acquire a MediDevice matching a device pattern
|
||||
* \param[in] enumerator Enumerator containing all media devices in the system
|
||||
* \param[in] dm Device match pattern
|
||||
*
|
||||
* Search the device \a enumerator for an available media device matching the
|
||||
* device match pattern \a dm. Matching media device that have previously been
|
||||
* acquired by MediaDevice::acquire() are not considered. If a match is found,
|
||||
* the media device is acquired and returned. The caller shall not release the
|
||||
* device explicitly, it will be automatically released when the pipeline
|
||||
* handler is destroyed.
|
||||
*
|
||||
* \return A pointer to the matching MediaDevice, or nullptr if no match is found
|
||||
*/
|
||||
MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,
|
||||
const DeviceMatch &dm)
|
||||
{
|
||||
std::shared_ptr<MediaDevice> media = enumerator->search(dm);
|
||||
if (!media)
|
||||
return nullptr;
|
||||
|
||||
if (!media->acquire())
|
||||
return nullptr;
|
||||
|
||||
mediaDevices_.push_back(media);
|
||||
|
||||
return media.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn PipelineHandler::streamConfiguration()
|
||||
* \brief Retrieve a group of stream configurations for a specified camera
|
||||
|
||||
Reference in New Issue
Block a user