From patchwork Tue Mar 26 08:38:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 801 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FF6961111 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 770CC24000A; Tue, 26 Mar 2019 08:38:33 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Mar 2019 09:38:49 +0100 Message-Id: <20190326083902.26121-7-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 06/19] libcamera: v4l2_device: 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:34 -0000 Add a static method to V4L2Device class to create a V4L2Device instance from a media entity name. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/include/v4l2_device.h | 4 ++++ src/libcamera/v4l2_device.cpp | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 258deee8d461..482d7891dd49 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -22,6 +22,7 @@ namespace libcamera { class Buffer; class BufferPool; class EventNotifier; +class MediaDevice; class MediaEntity; struct V4L2Capability final : v4l2_capability { @@ -107,6 +108,9 @@ public: class V4L2Device : protected Loggable { public: + static V4L2Device *fromEntityName(const MediaDevice *media, + const std::string &name); + explicit V4L2Device(const std::string &deviceNode); explicit V4L2Device(const MediaEntity *entity); V4L2Device(const V4L2Device &) = delete; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 93d81517fedb..68be5a064258 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -19,6 +19,7 @@ #include #include "log.h" +#include "media_device.h" #include "media_object.h" #include "v4l2_device.h" @@ -264,6 +265,27 @@ const std::string V4L2DeviceFormat::toString() const * released. */ +/** + * \brief Create a new video device 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 V4L2Device on success, nullptr otherwise + */ +V4L2Device *V4L2Device::fromEntityName(const MediaDevice *media, + const std::string &name) +{ + MediaEntity *entity = media->getEntityByName(name); + if (!entity) + return nullptr; + + return new V4L2Device(entity); +} + /** * \brief Construct a V4L2Device * \param deviceNode The file-system path to the video device node