libcamera: v4l2_device: add frame start event helpers

Add helper to check if frame start event are supported by subdevice.
Since kernel does not have interface to query supported events
use subscribe interface.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # v3
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # v5
Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stanislaw Gruszka 2025-04-03 09:45:47 +02:00 committed by Kieran Bingham
parent a2a7f4fc2d
commit b2eccef711
2 changed files with 23 additions and 0 deletions

View file

@ -45,6 +45,7 @@ public:
const std::string &deviceNode() const { return deviceNode_; }
std::string devicePath() const;
bool supportsFrameStartEvent();
int setFrameStartEnabled(bool enable);
Signal<uint32_t> frameStart;

View file

@ -449,6 +449,28 @@ std::string V4L2Device::devicePath() const
return path;
}
/**
* \brief Check if frame start event 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().
*
* \return True if frame start event is supported, false otherwise
*/
bool V4L2Device::supportsFrameStartEvent()
{
struct v4l2_event_subscription event{};
event.type = V4L2_EVENT_FRAME_SYNC;
int ret = ioctl(VIDIOC_SUBSCRIBE_EVENT, &event);
if (ret)
return false;
ioctl(VIDIOC_UNSUBSCRIBE_EVENT, &event);
return true;
}
/**
* \brief Enable or disable frame start event notification
* \param[in] enable True to enable frame start events, false to disable them