summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-03-22 12:21:16 +0100
committerJacopo Mondi <jacopo@jmondi.org>2019-04-02 11:02:38 +0200
commitc5ef6310fd749d4ac4aea62b8eafb46ca778f938 (patch)
tree70601588f850cbd6e1f8814696e50a4476d218bb /src
parent69c97ec0420bc23bfa39297d6bfec6d3f7e48e80 (diff)
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 <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/include/v4l2_subdevice.h5
-rw-r--r--src/libcamera/v4l2_subdevice.cpp22
2 files changed, 27 insertions, 0 deletions
diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
index f42cccab..ee7c7246 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;
@@ -48,6 +50,9 @@ public:
int getFormat(unsigned int pad, V4L2SubdeviceFormat *format);
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format);
+ static V4L2Subdevice *fromEntityName(const MediaDevice *media,
+ const std::string &entity);
+
protected:
std::string logPrefix() const;
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() + "'";