summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-03-22 12:19:33 +0100
committerJacopo Mondi <jacopo@jmondi.org>2019-04-02 11:02:38 +0200
commit69c97ec0420bc23bfa39297d6bfec6d3f7e48e80 (patch)
tree45ee78ecb266a001dd67d57e4e1b4c4df857a2b3
parent5b9b3c38a11845da9d9ee3549a3c3866c0eb3e29 (diff)
libcamera: v4l2_device: Create device from entity name
Add a static method to V4L2Device class to create a V4L2Device instance from a media entity name. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r--src/libcamera/include/v4l2_device.h4
-rw-r--r--src/libcamera/v4l2_device.cpp22
2 files changed, 26 insertions, 0 deletions
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index 258deee8..b4b3cd5c 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 {
@@ -136,6 +137,9 @@ public:
int streamOn();
int streamOff();
+ static V4L2Device *fromEntityName(const MediaDevice *media,
+ const std::string &entity);
+
protected:
std::string logPrefix() const;
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 93d81517..4cc4a6d6 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -19,6 +19,7 @@
#include <libcamera/event_notifier.h>
#include "log.h"
+#include "media_device.h"
#include "media_object.h"
#include "v4l2_device.h"
@@ -928,4 +929,25 @@ int V4L2Device::streamOff()
return 0;
}
+/**
+ * \brief Create a new video device 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 V4L2Device on success, nullptr otherwise
+ */
+V4L2Device *V4L2Device::fromEntityName(const MediaDevice *media,
+ const std::string &entity)
+{
+ MediaEntity *mediaEntity = media->getEntityByName(entity);
+ if (!mediaEntity)
+ return nullptr;
+
+ return new V4L2Device(mediaEntity);
+}
+
} /* namespace libcamera */