From patchwork Wed Jan 23 15:03:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 353 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C26460C7F for ; Wed, 23 Jan 2019 16:04:00 +0100 (CET) X-Halon-ID: 100da7ca-1f20-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 100da7ca-1f20-11e9-911a-0050569116f7; Wed, 23 Jan 2019 16:03:38 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 16:03:50 +0100 Message-Id: <20190123150351.8307-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123150351.8307-1-niklas.soderlund@ragnatech.se> References: <20190123150351.8307-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: MediaEntity: expose the entity flags X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 15:04:00 -0000 The media entity flags can be useful for pipeline handlers to find the default device in a media graph which is marked with the MEDIA_ENT_FL_DEFAULT flag. This will be especially useful for the UVC pipeline handler where the entity names differ per device. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/include/media_object.h | 2 ++ src/libcamera/media_object.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h index 64095bec8606bd32..2a3ffc06c876d792 100644 --- a/src/libcamera/include/media_object.h +++ b/src/libcamera/include/media_object.h @@ -85,6 +85,7 @@ class MediaEntity : public MediaObject public: const std::string &name() const { return name_; } unsigned int function() const { return function_; } + unsigned int flags() const { return flags_; } const std::string &deviceNode() const { return deviceNode_; } unsigned int deviceMajor() const { return major_; } unsigned int deviceMinor() const { return minor_; } @@ -106,6 +107,7 @@ private: std::string name_; unsigned int function_; + unsigned int flags_; std::string deviceNode_; unsigned int major_; unsigned int minor_; diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index baf9aeaa8fffe1a6..f6abcd8676a3866d 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -265,6 +265,16 @@ void MediaPad::addLink(MediaLink *link) * \return The entity's function */ +/** + * \fn MediaEntity::flags() + * \brief Retrieve the entity's flags + * + * Media entity flags are expressed using the MEDIA_ENT_FL_* macros + * defined by the Media Controller API. + * + * \return The entity's flags + */ + /** * \fn MediaEntity::deviceNode() * \brief Retrieve the entity's device node path, if any @@ -358,7 +368,8 @@ MediaEntity::MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity, unsigned int major, unsigned int minor) : MediaObject(dev, entity->id), name_(entity->name), - function_(entity->function), major_(major), minor_(minor) + function_(entity->function), flags_(entity->flags), + major_(major), minor_(minor) { } From patchwork Wed Jan 23 15:03:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 354 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B964560B2D for ; Wed, 23 Jan 2019 16:04:01 +0100 (CET) X-Halon-ID: 10805d3c-1f20-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 10805d3c-1f20-11e9-911a-0050569116f7; Wed, 23 Jan 2019 16:03:38 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 16:03:51 +0100 Message-Id: <20190123150351.8307-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123150351.8307-1-niklas.soderlund@ragnatech.se> References: <20190123150351.8307-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: pipeline: uvcvideo: create a V4L2Device for the default video entity X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 15:04:02 -0000 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 | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b56ee9881239abdc..f853105f50a958a3 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -12,6 +12,7 @@ #include "log.h" #include "media_device.h" #include "pipeline_handler.h" +#include "v4l2_device.h" namespace libcamera { @@ -31,15 +32,21 @@ public: private: MediaDevice *dev_; + V4L2Device *v4l2dev_; }; PipelineHandlerUVC::PipelineHandlerUVC() - : dev_(nullptr) + : dev_(nullptr), v4l2dev_(nullptr) { } PipelineHandlerUVC::~PipelineHandlerUVC() { + if (v4l2dev_) { + v4l2dev_->close(); + delete v4l2dev_; + } + if (dev_) dev_->release(); } @@ -83,6 +90,23 @@ bool PipelineHandlerUVC::match(CameraManager *manager, DeviceEnumerator *enumera dev_->acquire(); + for (MediaEntity *entity : dev_->entities()) { + if (!(entity->flags() & MEDIA_ENT_FL_DEFAULT)) + continue; + + v4l2dev_ = new V4L2Device(*entity); + + if (v4l2dev_->open()) + delete v4l2dev_; + + break; + } + + if (!v4l2dev_) { + dev_->release(); + return false; + } + std::shared_ptr camera = Camera::create(this, dev_->model()); registerCamera(manager, std::move(camera));