From patchwork Tue Mar 26 08:38:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 802 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BE49961111 for ; Tue, 26 Mar 2019 09:38:34 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 392A024000A; Tue, 26 Mar 2019 08:38:34 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Mar 2019 09:38:50 +0100 Message-Id: <20190326083902.26121-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326083902.26121-1-jacopo@jmondi.org> References: <20190326083902.26121-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 07/19] libcamera: v4l2_subdevice: Create device from entity name 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: Tue, 26 Mar 2019 08:38:35 -0000 Add a static method to V4L2Subdevice class to create a V4L2Subdevice instance from a media entity name. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_subdevice.h | 5 +++++ src/libcamera/v4l2_subdevice.cpp | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index f42cccabda94..0067109931d1 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -18,6 +18,8 @@ namespace libcamera { +class MediaDevice; + struct V4L2SubdeviceFormat { uint32_t mbus_code; uint32_t width; @@ -29,6 +31,9 @@ struct V4L2SubdeviceFormat { class V4L2Subdevice : protected Loggable { public: + static V4L2Subdevice *fromEntityName(const MediaDevice *media, + const std::string &name); + explicit V4L2Subdevice(const MediaEntity *entity); V4L2Subdevice(const V4L2Subdevice &) = delete; V4L2Subdevice &operator=(const V4L2Subdevice &) = delete; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 10925f9fe497..e28857c9aeb1 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -16,6 +16,7 @@ #include "geometry.h" #include "log.h" +#include "media_device.h" #include "media_object.h" #include "v4l2_subdevice.h" @@ -101,6 +102,27 @@ const std::string V4L2SubdeviceFormat::toString() const * any device left open will be closed, and any resources released. */ +/** + * \brief Create a new video subdevice instance from entity with \a name in + * media device \a media + * \param[in] media The media device where the entity is registered + * \param[in] name The media entity name + * + * Releasing memory of the newly created instance is responsibility of the + * caller of this function. + * + * \return A newly created V4L2Subdevice on success, nullptr otherwise + */ +V4L2Subdevice *V4L2Subdevice::fromEntityName(const MediaDevice *media, + const std::string &name) +{ + MediaEntity *entity = media->getEntityByName(name); + if (!entity) + return nullptr; + + return new V4L2Subdevice(entity); +} + /** * \brief Create a V4L2 subdevice from a MediaEntity using its device node * path