From c5ef6310fd749d4ac4aea62b8eafb46ca778f938 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Fri, 22 Mar 2019 12:21:16 +0100 Subject: libcamera: v4l2_subdevice: Create device from entity name Add a static method to V4L2Subdevice class to create a V4L2Subdevice instance from a media entity name. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/libcamera/v4l2_subdevice.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/libcamera/v4l2_subdevice.cpp') diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 10925f9f..0abeaa20 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" @@ -313,6 +314,27 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format) return 0; } +/** + * \brief Create a new video subdevice instance from \a entity in media device + * \a media + * \param[in] media The media device where the entity is registered + * \param[in] entity 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 &entity) +{ + MediaEntity *mediaEntity = media->getEntityByName(entity); + if (!mediaEntity) + return nullptr; + + return new V4L2Subdevice(mediaEntity); +} + std::string V4L2Subdevice::logPrefix() const { return "'" + entityName() + "'"; -- cgit v1.2.1