From 67d313240c9ba5159b7600eae6a3c843fea849a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Fri, 25 Jan 2019 15:21:05 +0100 Subject: libcamera: pipeline: uvcvideo: create a V4L2Device for the default video entity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a V4L2Device for the default video entity in the media graph. The UVC pipeline needs to search for the entity marked with the MEDIA_ENT_FL_DEFAULT flag as the entity names in the media graph varies depending on which device is used. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/uvcvideo.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 5de8a0cb..c51e8bc1 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -10,6 +10,7 @@ #include "device_enumerator.h" #include "media_device.h" #include "pipeline_handler.h" +#include "v4l2_device.h" namespace libcamera { @@ -23,15 +24,19 @@ public: private: std::shared_ptr media_; + V4L2Device *video_; }; PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager) - : PipelineHandler(manager), media_(nullptr) + : PipelineHandler(manager), media_(nullptr), video_(nullptr) { } PipelineHandlerUVC::~PipelineHandlerUVC() { + if (video_) + delete video_; + if (media_) media_->release(); } @@ -47,6 +52,18 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) media_->acquire(); + for (MediaEntity *entity : media_->entities()) { + if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { + video_ = new V4L2Device(*entity); + break; + } + } + + if (!video_ || video_->open()) { + media_->release(); + return false; + } + std::shared_ptr camera = Camera::create(this, media_->model()); registerCamera(std::move(camera)); hotplugMediaDevice(media_.get()); -- cgit v1.2.1