summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-07-03 21:37:44 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-31 22:44:10 +0300
commita376aa331ae9308f55baa9bb50680c35dc032058 (patch)
treedd3d6badc55a1932af86ed54c01b8e879ab971b1 /src
parent2e4fc65f77309fd99225ab0b40c123f92eba13a8 (diff)
libcamera: media_object: Expose entity type
Add a new field to the MediaEntity class to identify the type of interface it exposes to userspace. The MediaEntity constructor is changed to take a media_v2_interface pointer instead of just the device node major and minor to have access to the interface type. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Martin Kepplinger <martin.kepplinger@puri.sm>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/media_device.cpp9
-rw-r--r--src/libcamera/media_object.cpp50
2 files changed, 47 insertions, 12 deletions
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index 2d519126..ccaf039b 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -652,14 +652,7 @@ bool MediaDevice::populateEntities(const struct media_v2_topology &topology)
*/
struct media_v2_interface *iface =
findInterface(topology, ent->id);
-
- MediaEntity *entity;
- if (iface)
- entity = new MediaEntity(this, ent,
- iface->devnode.major,
- iface->devnode.minor);
- else
- entity = new MediaEntity(this, ent);
+ MediaEntity *entity = new MediaEntity(this, ent, iface);
if (!addObject(entity)) {
delete entity;
diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp
index 815edc8e..f425d044 100644
--- a/src/libcamera/media_object.cpp
+++ b/src/libcamera/media_object.cpp
@@ -248,6 +248,23 @@ void MediaPad::addLink(MediaLink *link)
*/
/**
+ * \enum MediaEntity::Type
+ * \brief The type of the interface exposed by the entity to userspace
+ *
+ * \var MediaEntity::Type::Invalid
+ * \brief Invalid or unsupported entity type
+ *
+ * \var MediaEntity::Type::MediaEntity
+ * \brief Plain media entity with no userspace interface
+ *
+ * \var MediaEntity::Type::V4L2VideoDevice
+ * \brief V4L2 video device with a V4L2 video device node
+ *
+ * \var MediaEntity::Type::V4L2Subdevice
+ * \brief V4L2 subdevice with a V4L2 subdev device node
+ */
+
+/**
* \fn MediaEntity::name()
* \brief Retrieve the entity name
* \return The entity name
@@ -274,6 +291,15 @@ void MediaPad::addLink(MediaLink *link)
*/
/**
+ * \fn MediaEntity::type()
+ * \brief Retrieve the entity's type
+ *
+ * The entity type identifies the type of interface exposed to userspace.
+ *
+ * \return The entity's type
+ */
+
+/**
* \fn MediaEntity::deviceNode()
* \brief Retrieve the entity's device node path, if any
* \return The entity's device node path, or an empty string if it is not set
@@ -356,16 +382,32 @@ int MediaEntity::setDeviceNode(const std::string &deviceNode)
* \brief Construct a MediaEntity
* \param[in] dev The media device this entity belongs to
* \param[in] entity The media entity kernel data
- * \param[in] major The major number of the entity associated interface
- * \param[in] minor The minor number of the entity associated interface
+ * \param[in] iface The entity interface data (may be null)
*/
MediaEntity::MediaEntity(MediaDevice *dev,
const struct media_v2_entity *entity,
- unsigned int major, unsigned int minor)
+ const struct media_v2_interface *iface)
: MediaObject(dev, entity->id), name_(entity->name),
function_(entity->function), flags_(entity->flags),
- major_(major), minor_(minor)
+ type_(Type::MediaEntity), major_(0), minor_(0)
{
+ if (!iface)
+ return;
+
+ switch (iface->intf_type) {
+ case MEDIA_INTF_T_V4L_VIDEO:
+ type_ = Type::V4L2VideoDevice;
+ break;
+ case MEDIA_INTF_T_V4L_SUBDEV:
+ type_ = Type::V4L2Subdevice;
+ break;
+ default:
+ type_ = Type::Invalid;
+ return;
+ }
+
+ major_ = iface->devnode.major;
+ minor_ = iface->devnode.minor;
}
/**