From patchwork Thu Feb 7 21:21:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 544 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5667A610B3 for ; Thu, 7 Feb 2019 22:21:28 +0100 (CET) Received: from localhost.localdomain (unknown [149.254.234.206]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 76F62567; Thu, 7 Feb 2019 22:21:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549574488; bh=Kx2RrxQC4y3ZhPm8fExrDxplTK4s45n0LOOgSqbgMjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EobfsUHaIdl9dJMxpN9p+buXQBqrw9N7K3M/xv7+H7s1Ffnqt6k5ebOCZvWIE3WTs PJLP5+jM/s7KQvlR2FWXuqjSZmTQ4lGLECRYoBOAhYVz9eAY/lEPV1dIwVz16+1Ve0 BwGj2wDd/boUjWha/Y1EztuYp2+uN7HgheAs7zgg= From: Kieran Bingham To: LibCamera Devel Date: Thu, 7 Feb 2019 21:21:15 +0000 Message-Id: <20190207212119.30299-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190207212119.30299-1-kieran.bingham@ideasonboard.com> References: <20190207212119.30299-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: media_device: Provide the default 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: Thu, 07 Feb 2019 21:21:28 -0000 Add a helper to identify the default entity from a media device. Utilise it in the two places which iterate the entities manually, to allocated a V4L2Device from the default entity. Signed-off-by: Kieran Bingham --- src/libcamera/include/media_device.h | 1 + src/libcamera/media_device.cpp | 15 +++++++++++++++ src/libcamera/pipeline/uvcvideo.cpp | 10 ++++------ test/v4l2_device/v4l2_device_test.cpp | 12 +++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h index 9f038093b2b2..361e8f4a4b86 100644 --- a/src/libcamera/include/media_device.h +++ b/src/libcamera/include/media_device.h @@ -42,6 +42,7 @@ public: const std::vector &entities() const { return entities_; } MediaEntity *getEntityByName(const std::string &name) const; + MediaEntity *defaultEntity() const; MediaLink *link(const std::string &sourceName, unsigned int sourceIdx, const std::string &sinkName, unsigned int sinkIdx); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 800ed330fe6d..4af90e1590a1 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -319,6 +319,21 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const return nullptr; } +/** + * \brief Return the default MediaEntity within a MediaDevice + * \return The default entity if specified, or a nullptr otherwise + */ +MediaEntity *MediaDevice::defaultEntity() const +{ + for (MediaEntity *entity : entities_) { + if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { + return entity; + } + } + + return nullptr; +} + /** * \brief Retrieve the MediaLink connecting two pads, identified by entity * names and pad indexes diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index fc31c52c0ecd..ed8228bb2fc6 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -146,13 +146,11 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) media_->acquire(); - for (MediaEntity *entity : media_->entities()) { - if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { - video_ = new V4L2Device(entity); - break; - } - } + MediaEntity *entity = media_->defaultEntity(); + if (!entity) + return false; + video_ = new V4L2Device(entity); if (!video_ || video_->open()) { if (!video_) LOG(UVC, Error) << "Could not find a default video device"; diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 18d014caf4c8..dd28cccada6b 100644 --- a/test/v4l2_device/v4l2_device_test.cpp +++ b/test/v4l2_device/v4l2_device_test.cpp @@ -46,15 +46,13 @@ int V4L2DeviceTest::init() media_->acquire(); - for (MediaEntity *entity : media_->entities()) { - if (entity->flags() & MEDIA_ENT_FL_DEFAULT) { - dev_ = new V4L2Device(entity); - break; - } - } + MediaEntity *entity = media_->defaultEntity(); + if (!entity) + return TestFail; + dev_ = new V4L2Device(entity); if (!dev_) - return TestSkip; + return TestFail; return dev_->open(); }