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:
Niklas Söderlund 2019-04-14 01:48:57 +02:00
parent 2e22ee4310
commit d6a8860747
6 changed files with 59 additions and 68 deletions

View file

@ -24,7 +24,6 @@ class PipelineHandlerVimc : public PipelineHandler
{
public:
PipelineHandlerVimc(CameraManager *manager);
~PipelineHandlerVimc();
CameraConfiguration
streamConfiguration(Camera *camera,
@ -69,21 +68,13 @@ private:
return static_cast<VimcCameraData *>(
PipelineHandler::cameraData(camera));
}
std::shared_ptr<MediaDevice> media_;
};
PipelineHandlerVimc::PipelineHandlerVimc(CameraManager *manager)
: PipelineHandler(manager), media_(nullptr)
: PipelineHandler(manager)
{
}
PipelineHandlerVimc::~PipelineHandlerVimc()
{
if (media_)
media_->release();
}
CameraConfiguration
PipelineHandlerVimc::streamConfiguration(Camera *camera,
const std::vector<StreamUsage> &usages)
@ -189,17 +180,14 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
dm.add("RGB/YUV Input");
dm.add("Scaler");
media_ = enumerator->search(dm);
if (!media_)
return false;
if (!media_->acquire())
MediaDevice *media = acquireMediaDevice(enumerator, dm);
if (!media)
return false;
std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);
/* Locate and open the capture video node. */
data->video_ = new V4L2Device(media_->getEntityByName("Raw Capture 1"));
data->video_ = new V4L2Device(media->getEntityByName("Raw Capture 1"));
if (data->video_->open())
return false;