[v2,1/3] libcamera: v4l2_device: Make supportsFrameStartEvent() generic
diff mbox series

Message ID 20261005-v4l2-events-v2-1-e4883190489d@ideasonboard.com
State New
Headers show
Series
  • Add generic V4L2 Events support
Related show

Commit Message

Daniel Scally Oct. 5, 2026, 3:40 p.m. UTC
Replace the existing V4l2Device::supportsFrameStartEvent() function
with a generic function with a v4l2_event_subscription parameter that
allows users to check whether the V4L2Device supports event
subscriptions for any type.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v2:

	- Use kernel uAPI types directly instead of V4L2Event and
	  V4L2EventSubscription classes
---
 include/libcamera/internal/v4l2_device.h |  2 +-
 src/libcamera/pipeline/simple/simple.cpp |  7 ++++++-
 src/libcamera/v4l2_device.cpp            | 19 ++++++++-----------
 3 files changed, 15 insertions(+), 13 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h
index 1a63fc547eac579fabf50421b719d07ddb2d6639..03e4d3dbb480557de98a5fa16fd41d4f2e7431c5 100644
--- a/include/libcamera/internal/v4l2_device.h
+++ b/include/libcamera/internal/v4l2_device.h
@@ -46,7 +46,7 @@  public:
 	const std::string &deviceNode() const { return deviceNode_; }
 	std::string devicePath() const;
 
-	bool supportsFrameStartEvent();
+	bool supportsEvents(v4l2_event_subscription &sub);
 	int setFrameStartEnabled(bool enable);
 	Signal<uint32_t> frameStart;
 
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 35c29ceca1bb1f9fb09e8c547b603ee8a2b67774..4631d5450b4ac4c47a78a631917d8b226a5269b0 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -22,6 +22,7 @@ 
 #include <vector>
 
 #include <linux/media-bus-format.h>
+#include <linux/videodev2.h>
 
 #include <libcamera/base/log.h>
 
@@ -668,7 +669,11 @@  int SimpleCameraData::init()
 	frameStartEmitter_ = nullptr;
 	for (const Entity &entity : entities_) {
 		V4L2Subdevice *sd = pipe->subdev(entity.entity);
-		if (!sd || !sd->supportsFrameStartEvent())
+
+		v4l2_event_subscription sub{};
+		sub.type = V4L2_EVENT_FRAME_SYNC;
+
+		if (!sd || !sd->supportsEvents(sub))
 			continue;
 
 		LOG(SimplePipeline, Debug)
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 258c82b8d238156038909a4b7b7aa842c99bd677..225b938649dcfe86f5528c3a82ed1b5ca0c94a5a 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -470,24 +470,21 @@  std::string V4L2Device::devicePath() const
 }
 
 /**
- * \brief Check if frame start event is supported
+ * \brief Check if an event subscription is supported
  *
- * Due to limitations in the kernel API, this function may disable the frame
- * start event as a side effect. It should only be called during initialization,
- * before enabling the frame start event with setFrameStartEnabled().
+ * Due to limitations in the kernel API, this function may disable the events as
+ * a side effect. It should only be called during initialization, before
+ * enabling the events explicitly.
  *
- * \return True if frame start event is supported, false otherwise
+ * \return True if the subscription is supported, false otherwise
  */
-bool V4L2Device::supportsFrameStartEvent()
+bool V4L2Device::supportsEvents(v4l2_event_subscription &sub)
 {
-	struct v4l2_event_subscription event{};
-	event.type = V4L2_EVENT_FRAME_SYNC;
-
-	int ret = ioctl(VIDIOC_SUBSCRIBE_EVENT, &event);
+	int ret = ioctl(VIDIOC_SUBSCRIBE_EVENT, &sub);
 	if (ret)
 		return false;
 
-	ioctl(VIDIOC_UNSUBSCRIBE_EVENT, &event);
+	ioctl(VIDIOC_UNSUBSCRIBE_EVENT, &sub);
 	return true;
 }