diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-04-14 01:48:57 +0200 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-05-17 20:35:27 +0200 |
commit | d6a88607479937a9941f1ea2c82a7e5c66b20647 (patch) | |
tree | eff0e2193ef12e2b1e058943fb10d8a171c70e56 /src/libcamera/pipeline/uvcvideo.cpp | |
parent | 2e22ee4310d47bc76c9db0da1b6b48f12f032743 (diff) |
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>
Diffstat (limited to 'src/libcamera/pipeline/uvcvideo.cpp')
-rw-r--r-- | src/libcamera/pipeline/uvcvideo.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index e40b052f..351712cf 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -24,7 +24,6 @@ class PipelineHandlerUVC : public PipelineHandler { public: PipelineHandlerUVC(CameraManager *manager); - ~PipelineHandlerUVC(); CameraConfiguration streamConfiguration(Camera *camera, @@ -69,19 +68,11 @@ private: return static_cast<UVCCameraData *>( PipelineHandler::cameraData(camera)); } - - std::shared_ptr<MediaDevice> media_; }; PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) - : PipelineHandler(manager), media_(nullptr) -{ -} - -PipelineHandlerUVC::~PipelineHandlerUVC() + : PipelineHandler(manager) { - if (media_) - media_->release(); } CameraConfiguration @@ -177,19 +168,17 @@ int PipelineHandlerUVC::queueRequest(Camera *camera, Request *request) bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) { + MediaDevice *media; DeviceMatch dm("uvcvideo"); - media_ = enumerator->search(dm); - if (!media_) - return false; - - if (!media_->acquire()) + media = acquireMediaDevice(enumerator, dm); + if (!media) return false; std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this); /* Locate and open the default video node. */ - for (MediaEntity *entity : media_->entities()) { + for (MediaEntity *entity : media->entities()) { if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { data->video_ = new V4L2Device(entity); break; @@ -208,11 +197,11 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) /* Create and register the camera. */ 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)); /* Enable hot-unplug notifications. */ - hotplugMediaDevice(media_.get()); + hotplugMediaDevice(media); return true; } |