7.8.1. Name

VIDIOC_DQEVENT - Dequeue event

7.8.2. Synopsis


int ioctl(int fd, VIDIOC_DQEVENT, struct v4l2_event *argp)

7.8.3. Arguments


File descriptor returned by open().


Pointer to struct v4l2_event.

7.8.4. Description

Dequeue an event from a video device. No input is required for this ioctl. All the fields of the struct v4l2_event structure are filled by the driver. The file handle will also receive exceptions which the application may get by e.g. using the select system call.

type v4l2_event
struct v4l2_event



Type of the event, see Event Types.

union {


struct v4l2_event_vsync


Event data for event V4L2_EVENT_VSYNC.

struct v4l2_event_ctrl


Event data for event V4L2_EVENT_CTRL.

struct v4l2_event_frame_sync


Event data for event V4L2_EVENT_FRAME_SYNC.

struct v4l2_event_motion_det


Event data for event V4L2_EVENT_MOTION_DET.

struct v4l2_event_src_change


Event data for event V4L2_EVENT_SOURCE_CHANGE.



Event data. Defined by the event type. The union should be used to define easily accessible type for events.




Number of pending events excluding this one.



Event sequence number. The sequence number is incremented for every subscribed event that takes place. If sequence numbers are not contiguous it means that events have been lost.

struct timespec


Event timestamp. The timestamp has been taken from the CLOCK_MONOTONIC clock. To access the same clock outside V4L2, use clock_gettime().



The ID associated with the event source. If the event does not have an associated ID (this depends on the event type), then this is 0.



Reserved for future extensions. Drivers must set the array to zero.

Event Types



All events. V4L2_EVENT_ALL is valid only for VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.



This event is triggered on the vertical sync. This event has a struct v4l2_event_vsync associated with it.



This event is triggered when the end of a stream is reached. This is typically used with MPEG decoders to report to the application when the last of the MPEG stream has been decoded.



This event requires that the id matches the control ID from which you want to receive events. This event is triggered if the control’s value changes, if a button control is pressed or if the control’s flags change. This event has a struct v4l2_event_ctrl associated with it. This struct contains much of the same information as struct v4l2_queryctrl and struct v4l2_control.

If the event is generated due to a call to VIDIOC_S_CTRL or VIDIOC_S_EXT_CTRLS, then the event will not be sent to the file handle that called the ioctl function. This prevents nasty feedback loops. If you do want to get the event, then set the V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK flag.

This event type will ensure that no information is lost when more events are raised than there is room internally. In that case the struct v4l2_event_ctrl of the second-oldest event is kept, but the changes field of the second-oldest event is ORed with the changes field of the oldest event.



Triggered immediately when the reception of a frame has begun. This event has a struct v4l2_event_frame_sync associated with it.

If the hardware needs to be stopped in the case of a buffer underrun it might not be able to generate this event. In such cases the frame_sequence field in struct v4l2_event_frame_sync will not be incremented. This causes two consecutive frame sequence numbers to have n times frame interval in between them.



This event is triggered when a source parameter change is detected during runtime by the video device. It can be a runtime resolution change triggered by a video decoder or the format change happening on an input connector. This event requires that the id matches the input index (when used with a video device node) or the pad index (when used with a subdevice node) from which you want to receive events.

This event has a struct v4l2_event_src_change associated with it. The changes bitfield denotes what has changed for the subscribed pad. If multiple events occurred before application could dequeue them, then the changes will have the ORed value of all the events generated.



Triggered whenever the motion detection state for one or more of the regions changes. This event has a struct v4l2_event_motion_det associated with it.



Base event number for driver-private events.

type v4l2_event_vsync
struct v4l2_event_vsync



The upcoming field. See enum v4l2_field.

type v4l2_event_ctrl
struct v4l2_event_ctrl



A bitmask that tells what has changed. See Control Changes.



The type of the control. See enum v4l2_ctrl_type.

union {




The 32-bit value of the control for 32-bit control types. This is 0 for string controls since the value of a string cannot be passed using ioctl VIDIOC_DQEVENT.



The 64-bit value of the control for 64-bit control types.




The control flags. See Control Flags.



The minimum value of the control. See struct v4l2_queryctrl.



The maximum value of the control. See struct v4l2_queryctrl.



The step value of the control. See struct v4l2_queryctrl.



The default value of the control. See struct v4l2_queryctrl.

type v4l2_event_frame_sync
struct v4l2_event_frame_sync



The sequence number of the frame being received.

type v4l2_event_src_change
struct v4l2_event_src_change



A bitmask that tells what has changed. See Source Changes.

type v4l2_event_motion_det
struct v4l2_event_motion_det



Currently only one flag is available: if V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ is set, then the frame_sequence field is valid, otherwise that field should be ignored.



The sequence number of the frame being received. Only valid if the V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ flag was set.



The bitmask of the regions that reported motion. There is at least one region. If this field is 0, then no motion was detected at all. If there is no V4L2_CID_DETECT_MD_REGION_GRID control (see Detect Control Reference) to assign a different region to each cell in the motion detection grid, then that all cells are automatically assigned to the default region 0.

Control Changes



This control event was triggered because the value of the control changed. Special cases: Volatile controls do no generate this event; If a control has the V4L2_CTRL_FLAG_EXECUTE_ON_WRITE flag set, then this event is sent as well, regardless its value.



This control event was triggered because the control flags changed.



This control event was triggered because the minimum, maximum, step or the default value of the control changed.

Source Changes



This event gets triggered when a resolution change is detected at an input. This can come from an input connector or from a video decoder. Applications will have to query the new resolution (if any, the signal may also have been lost).

For stateful decoders follow the guidelines in Memory-to-Memory Stateful Video Decoder Interface. Video Capture devices have to query the new timings using ioctl VIDIOC_QUERY_DV_TIMINGS or VIDIOC_QUERYSTD.

Important: even if the new video timings appear identical to the old ones, receiving this event indicates that there was an issue with the video signal and you must stop and restart streaming (VIDIOC_STREAMOFF followed by VIDIOC_STREAMON). The reason is that many Video Capture devices are not able to recover from a temporary loss of signal and so restarting streaming I/O is required in order for the hardware to synchronize to the video signal.

7.8.5. Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.