1.. Permission is granted to copy, distribute and/or modify this
2.. document under the terms of the GNU Free Documentation License,
3.. Version 1.1 or any later version published by the Free Software
4.. Foundation, with no Invariant Sections, no Front-Cover Texts
5.. and no Back-Cover Texts. A copy of the license is included at
6.. Documentation/userspace-api/media/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
10.. _VIDIOC_DQEVENT:
11
12********************
13ioctl VIDIOC_DQEVENT
14********************
15
16Name
17====
18
19VIDIOC_DQEVENT - Dequeue event
20
21
22Synopsis
23========
24
25.. c:function:: int ioctl( int fd, VIDIOC_DQEVENT, struct v4l2_event *argp )
26    :name: VIDIOC_DQEVENT
27
28
29Arguments
30=========
31
32``fd``
33    File descriptor returned by :ref:`open() <func-open>`.
34
35``argp``
36    Pointer to struct :c:type:`v4l2_event`.
37
38
39Description
40===========
41
42Dequeue an event from a video device. No input is required for this
43ioctl. All the fields of the struct :c:type:`v4l2_event`
44structure are filled by the driver. The file handle will also receive
45exceptions which the application may get by e.g. using the select system
46call.
47
48
49.. tabularcolumns:: |p{3.0cm}|p{4.4cm}|p{2.4cm}|p{7.7cm}|
50
51.. c:type:: v4l2_event
52
53.. cssclass: longtable
54
55.. flat-table:: struct v4l2_event
56    :header-rows:  0
57    :stub-columns: 0
58    :widths:       1 1 2
59
60    * - __u32
61      - ``type``
62      - Type of the event, see :ref:`event-type`.
63    * - union {
64      - ``u``
65    * - struct :c:type:`v4l2_event_vsync`
66      - ``vsync``
67      - Event data for event ``V4L2_EVENT_VSYNC``.
68    * - struct :c:type:`v4l2_event_ctrl`
69      - ``ctrl``
70      - Event data for event ``V4L2_EVENT_CTRL``.
71    * - struct :c:type:`v4l2_event_frame_sync`
72      - ``frame_sync``
73      - Event data for event ``V4L2_EVENT_FRAME_SYNC``.
74    * - struct :c:type:`v4l2_event_motion_det`
75      - ``motion_det``
76      - Event data for event V4L2_EVENT_MOTION_DET.
77    * - struct :c:type:`v4l2_event_src_change`
78      - ``src_change``
79      - Event data for event V4L2_EVENT_SOURCE_CHANGE.
80    * - __u8
81      - ``data``\ [64]
82      - Event data. Defined by the event type. The union should be used to
83	define easily accessible type for events.
84    * - }
85      -
86    * - __u32
87      - ``pending``
88      - Number of pending events excluding this one.
89    * - __u32
90      - ``sequence``
91      - Event sequence number. The sequence number is incremented for
92	every subscribed event that takes place. If sequence numbers are
93	not contiguous it means that events have been lost.
94    * - struct timespec
95      - ``timestamp``
96      - Event timestamp. The timestamp has been taken from the
97	``CLOCK_MONOTONIC`` clock. To access the same clock outside V4L2,
98	use :c:func:`clock_gettime`.
99    * - u32
100      - ``id``
101      - The ID associated with the event source. If the event does not
102	have an associated ID (this depends on the event type), then this
103	is 0.
104    * - __u32
105      - ``reserved``\ [8]
106      - Reserved for future extensions. Drivers must set the array to
107	zero.
108
109
110
111.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
112
113.. cssclass:: longtable
114
115.. _event-type:
116
117.. flat-table:: Event Types
118    :header-rows:  0
119    :stub-columns: 0
120    :widths:       3 1 4
121
122    * - ``V4L2_EVENT_ALL``
123      - 0
124      - All events. V4L2_EVENT_ALL is valid only for
125	VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
126    * - ``V4L2_EVENT_VSYNC``
127      - 1
128      - This event is triggered on the vertical sync. This event has a
129	struct :c:type:`v4l2_event_vsync` associated
130	with it.
131    * - ``V4L2_EVENT_EOS``
132      - 2
133      - This event is triggered when the end of a stream is reached. This
134	is typically used with MPEG decoders to report to the application
135	when the last of the MPEG stream has been decoded.
136    * - ``V4L2_EVENT_CTRL``
137      - 3
138      - This event requires that the ``id`` matches the control ID from
139	which you want to receive events. This event is triggered if the
140	control's value changes, if a button control is pressed or if the
141	control's flags change. This event has a struct
142	:c:type:`v4l2_event_ctrl` associated with it.
143	This struct contains much of the same information as struct
144	:ref:`v4l2_queryctrl <v4l2-queryctrl>` and struct
145	:c:type:`v4l2_control`.
146
147	If the event is generated due to a call to
148	:ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` or
149	:ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then the
150	event will *not* be sent to the file handle that called the ioctl
151	function. This prevents nasty feedback loops. If you *do* want to
152	get the event, then set the ``V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK``
153	flag.
154
155	This event type will ensure that no information is lost when more
156	events are raised than there is room internally. In that case the
157	struct :c:type:`v4l2_event_ctrl` of the
158	second-oldest event is kept, but the ``changes`` field of the
159	second-oldest event is ORed with the ``changes`` field of the
160	oldest event.
161    * - ``V4L2_EVENT_FRAME_SYNC``
162      - 4
163      - Triggered immediately when the reception of a frame has begun.
164	This event has a struct
165	:c:type:`v4l2_event_frame_sync`
166	associated with it.
167
168	If the hardware needs to be stopped in the case of a buffer
169	underrun it might not be able to generate this event. In such
170	cases the ``frame_sequence`` field in struct
171	:c:type:`v4l2_event_frame_sync` will not
172	be incremented. This causes two consecutive frame sequence numbers
173	to have n times frame interval in between them.
174    * - ``V4L2_EVENT_SOURCE_CHANGE``
175      - 5
176      - This event is triggered when a source parameter change is detected
177	during runtime by the video device. It can be a runtime resolution
178	change triggered by a video decoder or the format change happening
179	on an input connector. This event requires that the ``id`` matches
180	the input index (when used with a video device node) or the pad
181	index (when used with a subdevice node) from which you want to
182	receive events.
183
184	This event has a struct
185	:c:type:`v4l2_event_src_change`
186	associated with it. The ``changes`` bitfield denotes what has
187	changed for the subscribed pad. If multiple events occurred before
188	application could dequeue them, then the changes will have the
189	ORed value of all the events generated.
190    * - ``V4L2_EVENT_MOTION_DET``
191      - 6
192      - Triggered whenever the motion detection state for one or more of
193	the regions changes. This event has a struct
194	:c:type:`v4l2_event_motion_det`
195	associated with it.
196    * - ``V4L2_EVENT_PRIVATE_START``
197      - 0x08000000
198      - Base event number for driver-private events.
199
200
201
202.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
203
204.. c:type:: v4l2_event_vsync
205
206.. flat-table:: struct v4l2_event_vsync
207    :header-rows:  0
208    :stub-columns: 0
209    :widths:       1 1 2
210
211    * - __u8
212      - ``field``
213      - The upcoming field. See enum :c:type:`v4l2_field`.
214
215
216
217.. tabularcolumns:: |p{3.5cm}|p{3.0cm}|p{1.8cm}|p{8.5cm}|
218
219.. c:type:: v4l2_event_ctrl
220
221.. flat-table:: struct v4l2_event_ctrl
222    :header-rows:  0
223    :stub-columns: 0
224    :widths:       1 1 2
225
226    * - __u32
227      - ``changes``
228      - A bitmask that tells what has changed. See
229	:ref:`ctrl-changes-flags`.
230    * - __u32
231      - ``type``
232      - The type of the control. See enum
233	:c:type:`v4l2_ctrl_type`.
234    * - union {
235      - (anonymous)
236    * - __s32
237      - ``value``
238      - The 32-bit value of the control for 32-bit control types. This is
239	0 for string controls since the value of a string cannot be passed
240	using :ref:`VIDIOC_DQEVENT`.
241    * - __s64
242      - ``value64``
243      - The 64-bit value of the control for 64-bit control types.
244    * - }
245      -
246    * - __u32
247      - ``flags``
248      - The control flags. See :ref:`control-flags`.
249    * - __s32
250      - ``minimum``
251      - The minimum value of the control. See struct
252	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
253    * - __s32
254      - ``maximum``
255      - The maximum value of the control. See struct
256	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
257    * - __s32
258      - ``step``
259      - The step value of the control. See struct
260	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
261    * - __s32
262      - ``default_value``
263      - The default value value of the control. See struct
264	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
265
266
267
268.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
269
270.. c:type:: v4l2_event_frame_sync
271
272.. flat-table:: struct v4l2_event_frame_sync
273    :header-rows:  0
274    :stub-columns: 0
275    :widths:       1 1 2
276
277    * - __u32
278      - ``frame_sequence``
279      - The sequence number of the frame being received.
280
281
282
283.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
284
285.. c:type:: v4l2_event_src_change
286
287.. flat-table:: struct v4l2_event_src_change
288    :header-rows:  0
289    :stub-columns: 0
290    :widths:       1 1 2
291
292    * - __u32
293      - ``changes``
294      - A bitmask that tells what has changed. See
295	:ref:`src-changes-flags`.
296
297
298
299.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
300
301.. c:type:: v4l2_event_motion_det
302
303.. flat-table:: struct v4l2_event_motion_det
304    :header-rows:  0
305    :stub-columns: 0
306    :widths:       1 1 2
307
308    * - __u32
309      - ``flags``
310      - Currently only one flag is available: if
311	``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` is set, then the
312	``frame_sequence`` field is valid, otherwise that field should be
313	ignored.
314    * - __u32
315      - ``frame_sequence``
316      - The sequence number of the frame being received. Only valid if the
317	``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` flag was set.
318    * - __u32
319      - ``region_mask``
320      - The bitmask of the regions that reported motion. There is at least
321	one region. If this field is 0, then no motion was detected at
322	all. If there is no ``V4L2_CID_DETECT_MD_REGION_GRID`` control
323	(see :ref:`detect-controls`) to assign a different region to
324	each cell in the motion detection grid, then that all cells are
325	automatically assigned to the default region 0.
326
327
328
329.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
330
331.. _ctrl-changes-flags:
332
333.. flat-table:: Control Changes
334    :header-rows:  0
335    :stub-columns: 0
336    :widths:       3 1 4
337
338    * - ``V4L2_EVENT_CTRL_CH_VALUE``
339      - 0x0001
340      - This control event was triggered because the value of the control
341	changed. Special cases: Volatile controls do no generate this
342	event; If a control has the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
343	flag set, then this event is sent as well, regardless its value.
344    * - ``V4L2_EVENT_CTRL_CH_FLAGS``
345      - 0x0002
346      - This control event was triggered because the control flags
347	changed.
348    * - ``V4L2_EVENT_CTRL_CH_RANGE``
349      - 0x0004
350      - This control event was triggered because the minimum, maximum,
351	step or the default value of the control changed.
352
353
354
355.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
356
357.. _src-changes-flags:
358
359.. flat-table:: Source Changes
360    :header-rows:  0
361    :stub-columns: 0
362    :widths:       3 1 4
363
364    * - ``V4L2_EVENT_SRC_CH_RESOLUTION``
365      - 0x0001
366      - This event gets triggered when a resolution change is detected at
367	an input. This can come from an input connector or from a video
368	decoder. Applications will have to query the new resolution (if
369	any, the signal may also have been lost).
370
371	For stateful decoders follow the guidelines in :ref:`decoder`.
372	Video Capture devices have to query the new timings using
373	:ref:`VIDIOC_QUERY_DV_TIMINGS` or
374	:ref:`VIDIOC_QUERYSTD <VIDIOC_QUERYSTD>`.
375
376	*Important*: even if the new video timings appear identical to the old
377	ones, receiving this event indicates that there was an issue with the
378	video signal and you must stop and restart streaming
379	(:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
380	followed by :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`). The reason is
381	that many Video Capture devices are not able to recover from a temporary
382	loss of signal and so restarting streaming I/O is required in order for
383	the hardware to synchronize to the video signal.
384
385
386Return Value
387============
388
389On success 0 is returned, on error -1 and the ``errno`` variable is set
390appropriately. The generic error codes are described at the
391:ref:`Generic Error Codes <gen-errors>` chapter.
392