1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
12 VIDIOC_DQEVENT - Dequeue event
18 .. c:function:: int ioctl( int fd, VIDIOC_DQEVENT, struct v4l2_event *argp )
26 File descriptor returned by :ref:`open() <func-open>`.
29 Pointer to struct :c:type:`v4l2_event`.
35 Dequeue an event from a video device. No input is required for this
36 ioctl. All the fields of the struct :c:type:`v4l2_event`
37 structure are filled by the driver. The file handle will also receive
38 exceptions which the application may get by e.g. using the select system
42 .. tabularcolumns:: |p{3.0cm}|p{4.4cm}|p{2.4cm}|p{7.7cm}|
44 .. c:type:: v4l2_event
46 .. cssclass: longtable
48 .. flat-table:: struct v4l2_event
55 - Type of the event, see :ref:`event-type`.
58 * - struct :c:type:`v4l2_event_vsync`
60 - Event data for event ``V4L2_EVENT_VSYNC``.
61 * - struct :c:type:`v4l2_event_ctrl`
63 - Event data for event ``V4L2_EVENT_CTRL``.
64 * - struct :c:type:`v4l2_event_frame_sync`
66 - Event data for event ``V4L2_EVENT_FRAME_SYNC``.
67 * - struct :c:type:`v4l2_event_motion_det`
69 - Event data for event V4L2_EVENT_MOTION_DET.
70 * - struct :c:type:`v4l2_event_src_change`
72 - Event data for event V4L2_EVENT_SOURCE_CHANGE.
75 - Event data. Defined by the event type. The union should be used to
76 define easily accessible type for events.
81 - Number of pending events excluding this one.
84 - Event sequence number. The sequence number is incremented for
85 every subscribed event that takes place. If sequence numbers are
86 not contiguous it means that events have been lost.
89 - Event timestamp. The timestamp has been taken from the
90 ``CLOCK_MONOTONIC`` clock. To access the same clock outside V4L2,
91 use :c:func:`clock_gettime`.
94 - The ID associated with the event source. If the event does not
95 have an associated ID (this depends on the event type), then this
99 - Reserved for future extensions. Drivers must set the array to
104 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
106 .. cssclass:: longtable
110 .. flat-table:: Event Types
115 * - ``V4L2_EVENT_ALL``
117 - All events. V4L2_EVENT_ALL is valid only for
118 VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
119 * - ``V4L2_EVENT_VSYNC``
121 - This event is triggered on the vertical sync. This event has a
122 struct :c:type:`v4l2_event_vsync` associated
124 * - ``V4L2_EVENT_EOS``
126 - This event is triggered when the end of a stream is reached. This
127 is typically used with MPEG decoders to report to the application
128 when the last of the MPEG stream has been decoded.
129 * - ``V4L2_EVENT_CTRL``
131 - This event requires that the ``id`` matches the control ID from
132 which you want to receive events. This event is triggered if the
133 control's value changes, if a button control is pressed or if the
134 control's flags change. This event has a struct
135 :c:type:`v4l2_event_ctrl` associated with it.
136 This struct contains much of the same information as struct
137 :ref:`v4l2_queryctrl <v4l2-queryctrl>` and struct
138 :c:type:`v4l2_control`.
140 If the event is generated due to a call to
141 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` or
142 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then the
143 event will *not* be sent to the file handle that called the ioctl
144 function. This prevents nasty feedback loops. If you *do* want to
145 get the event, then set the ``V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK``
148 This event type will ensure that no information is lost when more
149 events are raised than there is room internally. In that case the
150 struct :c:type:`v4l2_event_ctrl` of the
151 second-oldest event is kept, but the ``changes`` field of the
152 second-oldest event is ORed with the ``changes`` field of the
154 * - ``V4L2_EVENT_FRAME_SYNC``
156 - Triggered immediately when the reception of a frame has begun.
157 This event has a struct
158 :c:type:`v4l2_event_frame_sync`
161 If the hardware needs to be stopped in the case of a buffer
162 underrun it might not be able to generate this event. In such
163 cases the ``frame_sequence`` field in struct
164 :c:type:`v4l2_event_frame_sync` will not
165 be incremented. This causes two consecutive frame sequence numbers
166 to have n times frame interval in between them.
167 * - ``V4L2_EVENT_SOURCE_CHANGE``
169 - This event is triggered when a source parameter change is detected
170 during runtime by the video device. It can be a runtime resolution
171 change triggered by a video decoder or the format change happening
172 on an input connector. This event requires that the ``id`` matches
173 the input index (when used with a video device node) or the pad
174 index (when used with a subdevice node) from which you want to
177 This event has a struct
178 :c:type:`v4l2_event_src_change`
179 associated with it. The ``changes`` bitfield denotes what has
180 changed for the subscribed pad. If multiple events occurred before
181 application could dequeue them, then the changes will have the
182 ORed value of all the events generated.
183 * - ``V4L2_EVENT_MOTION_DET``
185 - Triggered whenever the motion detection state for one or more of
186 the regions changes. This event has a struct
187 :c:type:`v4l2_event_motion_det`
189 * - ``V4L2_EVENT_PRIVATE_START``
191 - Base event number for driver-private events.
195 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
197 .. c:type:: v4l2_event_vsync
199 .. flat-table:: struct v4l2_event_vsync
206 - The upcoming field. See enum :c:type:`v4l2_field`.
210 .. tabularcolumns:: |p{3.5cm}|p{3.0cm}|p{1.8cm}|p{8.5cm}|
212 .. c:type:: v4l2_event_ctrl
214 .. flat-table:: struct v4l2_event_ctrl
221 - A bitmask that tells what has changed. See
222 :ref:`ctrl-changes-flags`.
225 - The type of the control. See enum
226 :c:type:`v4l2_ctrl_type`.
231 - The 32-bit value of the control for 32-bit control types. This is
232 0 for string controls since the value of a string cannot be passed
233 using :ref:`VIDIOC_DQEVENT`.
236 - The 64-bit value of the control for 64-bit control types.
241 - The control flags. See :ref:`control-flags`.
244 - The minimum value of the control. See struct
245 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
248 - The maximum value of the control. See struct
249 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
252 - The step value of the control. See struct
253 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
256 - The default value of the control. See struct
257 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
261 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
263 .. c:type:: v4l2_event_frame_sync
265 .. flat-table:: struct v4l2_event_frame_sync
272 - The sequence number of the frame being received.
276 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
278 .. c:type:: v4l2_event_src_change
280 .. flat-table:: struct v4l2_event_src_change
287 - A bitmask that tells what has changed. See
288 :ref:`src-changes-flags`.
292 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
294 .. c:type:: v4l2_event_motion_det
296 .. flat-table:: struct v4l2_event_motion_det
303 - Currently only one flag is available: if
304 ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` is set, then the
305 ``frame_sequence`` field is valid, otherwise that field should be
309 - The sequence number of the frame being received. Only valid if the
310 ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` flag was set.
313 - The bitmask of the regions that reported motion. There is at least
314 one region. If this field is 0, then no motion was detected at
315 all. If there is no ``V4L2_CID_DETECT_MD_REGION_GRID`` control
316 (see :ref:`detect-controls`) to assign a different region to
317 each cell in the motion detection grid, then that all cells are
318 automatically assigned to the default region 0.
322 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
324 .. _ctrl-changes-flags:
326 .. flat-table:: Control Changes
331 * - ``V4L2_EVENT_CTRL_CH_VALUE``
333 - This control event was triggered because the value of the control
334 changed. Special cases: Volatile controls do no generate this
335 event; If a control has the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
336 flag set, then this event is sent as well, regardless its value.
337 * - ``V4L2_EVENT_CTRL_CH_FLAGS``
339 - This control event was triggered because the control flags
341 * - ``V4L2_EVENT_CTRL_CH_RANGE``
343 - This control event was triggered because the minimum, maximum,
344 step or the default value of the control changed.
348 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
350 .. _src-changes-flags:
352 .. flat-table:: Source Changes
357 * - ``V4L2_EVENT_SRC_CH_RESOLUTION``
359 - This event gets triggered when a resolution change is detected at
360 an input. This can come from an input connector or from a video
361 decoder. Applications will have to query the new resolution (if
362 any, the signal may also have been lost).
364 For stateful decoders follow the guidelines in :ref:`decoder`.
365 Video Capture devices have to query the new timings using
366 :ref:`VIDIOC_QUERY_DV_TIMINGS` or
367 :ref:`VIDIOC_QUERYSTD <VIDIOC_QUERYSTD>`.
369 *Important*: even if the new video timings appear identical to the old
370 ones, receiving this event indicates that there was an issue with the
371 video signal and you must stop and restart streaming
372 (:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
373 followed by :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`). The reason is
374 that many Video Capture devices are not able to recover from a temporary
375 loss of signal and so restarting streaming I/O is required in order for
376 the hardware to synchronize to the video signal.
382 On success 0 is returned, on error -1 and the ``errno`` variable is set
383 appropriately. The generic error codes are described at the
384 :ref:`Generic Error Codes <gen-errors>` chapter.