summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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() + "'";