blob: 42659a3d170585d3b5006333a25ad6c36783a136 [file] [log] [blame]
Mauro Carvalho Chehab82559ac2018-08-30 10:15:26 -04001.. 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/media/uapi/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030010.. _VIDIOC_DQEVENT:
Markus Heiser5377d912016-06-30 15:18:56 +020011
12********************
13ioctl VIDIOC_DQEVENT
14********************
15
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030016Name
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030017====
Markus Heiser5377d912016-06-30 15:18:56 +020018
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030019VIDIOC_DQEVENT - Dequeue event
Markus Heiser5377d912016-06-30 15:18:56 +020020
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030021
22Synopsis
Markus Heiser5377d912016-06-30 15:18:56 +020023========
24
Mauro Carvalho Chehab41d80462016-08-19 16:53:38 -030025.. c:function:: int ioctl( int fd, VIDIOC_DQEVENT, struct v4l2_event *argp )
26 :name: VIDIOC_DQEVENT
Markus Heiser5377d912016-06-30 15:18:56 +020027
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030028
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030029Arguments
Markus Heiser5377d912016-06-30 15:18:56 +020030=========
31
32``fd``
33 File descriptor returned by :ref:`open() <func-open>`.
34
Markus Heiser5377d912016-06-30 15:18:56 +020035``argp``
Mauro Carvalho Chehab1473c752017-09-02 09:54:48 -040036 Pointer to struct :c:type:`v4l2_event`.
Markus Heiser5377d912016-06-30 15:18:56 +020037
38
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030039Description
Markus Heiser5377d912016-06-30 15:18:56 +020040===========
41
42Dequeue an event from a video device. No input is required for this
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030043ioctl. All the fields of the struct :c:type:`v4l2_event`
Markus Heiser5377d912016-06-30 15:18:56 +020044structure 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
Mauro Carvalho Chehab70b074d2017-08-26 05:28:26 -040049.. tabularcolumns:: |p{3.0cm}|p{4.4cm}|p{2.4cm}|p{7.7cm}|
Mauro Carvalho Chehab0e9411a2016-08-18 13:46:03 -030050
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030051.. c:type:: v4l2_event
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -030052
Mauro Carvalho Chehab0e9411a2016-08-18 13:46:03 -030053.. cssclass: longtable
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -030054
Markus Heiser5377d912016-06-30 15:18:56 +020055.. flat-table:: struct v4l2_event
56 :header-rows: 0
57 :stub-columns: 0
58 :widths: 1 1 2 1
59
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -030060 * - __u32
61 - ``type``
62 -
63 - Type of the event, see :ref:`event-type`.
64 * - union
65 - ``u``
66 -
67 -
68 * -
69 - struct :c:type:`v4l2_event_vsync`
70 - ``vsync``
71 - Event data for event ``V4L2_EVENT_VSYNC``.
72 * -
73 - struct :c:type:`v4l2_event_ctrl`
74 - ``ctrl``
75 - Event data for event ``V4L2_EVENT_CTRL``.
76 * -
77 - struct :c:type:`v4l2_event_frame_sync`
78 - ``frame_sync``
79 - Event data for event ``V4L2_EVENT_FRAME_SYNC``.
80 * -
81 - struct :c:type:`v4l2_event_motion_det`
82 - ``motion_det``
83 - Event data for event V4L2_EVENT_MOTION_DET.
84 * -
85 - struct :c:type:`v4l2_event_src_change`
86 - ``src_change``
87 - Event data for event V4L2_EVENT_SOURCE_CHANGE.
88 * -
89 - __u8
90 - ``data``\ [64]
91 - Event data. Defined by the event type. The union should be used to
92 define easily accessible type for events.
93 * - __u32
94 - ``pending``
95 -
96 - Number of pending events excluding this one.
97 * - __u32
98 - ``sequence``
99 -
100 - Event sequence number. The sequence number is incremented for
101 every subscribed event that takes place. If sequence numbers are
102 not contiguous it means that events have been lost.
103 * - struct timespec
104 - ``timestamp``
105 -
106 - Event timestamp. The timestamp has been taken from the
107 ``CLOCK_MONOTONIC`` clock. To access the same clock outside V4L2,
108 use :c:func:`clock_gettime`.
109 * - u32
110 - ``id``
111 -
112 - The ID associated with the event source. If the event does not
113 have an associated ID (this depends on the event type), then this
114 is 0.
115 * - __u32
116 - ``reserved``\ [8]
117 -
118 - Reserved for future extensions. Drivers must set the array to
119 zero.
Markus Heiser5377d912016-06-30 15:18:56 +0200120
121
122
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300123.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
124
Mauro Carvalho Chehabef76c062016-08-18 14:31:47 -0300125.. cssclass:: longtable
126
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300127.. _event-type:
128
Markus Heiser5377d912016-06-30 15:18:56 +0200129.. flat-table:: Event Types
130 :header-rows: 0
131 :stub-columns: 0
132 :widths: 3 1 4
133
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300134 * - ``V4L2_EVENT_ALL``
135 - 0
136 - All events. V4L2_EVENT_ALL is valid only for
137 VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
138 * - ``V4L2_EVENT_VSYNC``
139 - 1
140 - This event is triggered on the vertical sync. This event has a
141 struct :c:type:`v4l2_event_vsync` associated
142 with it.
143 * - ``V4L2_EVENT_EOS``
144 - 2
145 - This event is triggered when the end of a stream is reached. This
146 is typically used with MPEG decoders to report to the application
147 when the last of the MPEG stream has been decoded.
148 * - ``V4L2_EVENT_CTRL``
149 - 3
150 - This event requires that the ``id`` matches the control ID from
151 which you want to receive events. This event is triggered if the
152 control's value changes, if a button control is pressed or if the
153 control's flags change. This event has a struct
154 :c:type:`v4l2_event_ctrl` associated with it.
155 This struct contains much of the same information as struct
156 :ref:`v4l2_queryctrl <v4l2-queryctrl>` and struct
157 :c:type:`v4l2_control`.
Markus Heiser5377d912016-06-30 15:18:56 +0200158
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300159 If the event is generated due to a call to
160 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` or
161 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then the
162 event will *not* be sent to the file handle that called the ioctl
163 function. This prevents nasty feedback loops. If you *do* want to
164 get the event, then set the ``V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK``
165 flag.
Markus Heiser5377d912016-06-30 15:18:56 +0200166
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300167 This event type will ensure that no information is lost when more
168 events are raised than there is room internally. In that case the
169 struct :c:type:`v4l2_event_ctrl` of the
170 second-oldest event is kept, but the ``changes`` field of the
171 second-oldest event is ORed with the ``changes`` field of the
172 oldest event.
173 * - ``V4L2_EVENT_FRAME_SYNC``
174 - 4
175 - Triggered immediately when the reception of a frame has begun.
176 This event has a struct
177 :c:type:`v4l2_event_frame_sync`
178 associated with it.
Markus Heiser5377d912016-06-30 15:18:56 +0200179
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300180 If the hardware needs to be stopped in the case of a buffer
181 underrun it might not be able to generate this event. In such
182 cases the ``frame_sequence`` field in struct
183 :c:type:`v4l2_event_frame_sync` will not
184 be incremented. This causes two consecutive frame sequence numbers
185 to have n times frame interval in between them.
186 * - ``V4L2_EVENT_SOURCE_CHANGE``
187 - 5
188 - This event is triggered when a source parameter change is detected
189 during runtime by the video device. It can be a runtime resolution
190 change triggered by a video decoder or the format change happening
191 on an input connector. This event requires that the ``id`` matches
192 the input index (when used with a video device node) or the pad
193 index (when used with a subdevice node) from which you want to
194 receive events.
Markus Heiser5377d912016-06-30 15:18:56 +0200195
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300196 This event has a struct
197 :c:type:`v4l2_event_src_change`
198 associated with it. The ``changes`` bitfield denotes what has
199 changed for the subscribed pad. If multiple events occurred before
200 application could dequeue them, then the changes will have the
201 ORed value of all the events generated.
202 * - ``V4L2_EVENT_MOTION_DET``
203 - 6
204 - Triggered whenever the motion detection state for one or more of
205 the regions changes. This event has a struct
206 :c:type:`v4l2_event_motion_det`
207 associated with it.
208 * - ``V4L2_EVENT_PRIVATE_START``
209 - 0x08000000
210 - Base event number for driver-private events.
Markus Heiser5377d912016-06-30 15:18:56 +0200211
212
213
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300214.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
215
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300216.. c:type:: v4l2_event_vsync
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300217
Markus Heiser5377d912016-06-30 15:18:56 +0200218.. flat-table:: struct v4l2_event_vsync
219 :header-rows: 0
220 :stub-columns: 0
221 :widths: 1 1 2
222
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300223 * - __u8
224 - ``field``
225 - The upcoming field. See enum :c:type:`v4l2_field`.
Markus Heiser5377d912016-06-30 15:18:56 +0200226
227
228
Mauro Carvalho Chehab0e9411a2016-08-18 13:46:03 -0300229.. tabularcolumns:: |p{3.5cm}|p{3.0cm}|p{1.8cm}|p{8.5cm}|
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300230
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300231.. c:type:: v4l2_event_ctrl
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300232
Markus Heiser5377d912016-06-30 15:18:56 +0200233.. flat-table:: struct v4l2_event_ctrl
234 :header-rows: 0
235 :stub-columns: 0
236 :widths: 1 1 2 1
237
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300238 * - __u32
239 - ``changes``
240 -
241 - A bitmask that tells what has changed. See
242 :ref:`ctrl-changes-flags`.
243 * - __u32
244 - ``type``
245 -
246 - The type of the control. See enum
247 :c:type:`v4l2_ctrl_type`.
248 * - union (anonymous)
249 -
250 -
251 -
252 * -
253 - __s32
254 - ``value``
255 - The 32-bit value of the control for 32-bit control types. This is
256 0 for string controls since the value of a string cannot be passed
257 using :ref:`VIDIOC_DQEVENT`.
258 * -
259 - __s64
260 - ``value64``
261 - The 64-bit value of the control for 64-bit control types.
262 * - __u32
263 - ``flags``
264 -
265 - The control flags. See :ref:`control-flags`.
266 * - __s32
267 - ``minimum``
268 -
269 - The minimum value of the control. See struct
270 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
271 * - __s32
272 - ``maximum``
273 -
274 - The maximum value of the control. See struct
275 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
276 * - __s32
277 - ``step``
278 -
279 - The step value of the control. See struct
280 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
281 * - __s32
282 - ``default_value``
283 -
284 - The default value value of the control. See struct
285 :ref:`v4l2_queryctrl <v4l2-queryctrl>`.
Markus Heiser5377d912016-06-30 15:18:56 +0200286
287
288
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300289.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
290
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300291.. c:type:: v4l2_event_frame_sync
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300292
Markus Heiser5377d912016-06-30 15:18:56 +0200293.. flat-table:: struct v4l2_event_frame_sync
294 :header-rows: 0
295 :stub-columns: 0
296 :widths: 1 1 2
297
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300298 * - __u32
299 - ``frame_sequence``
300 - The sequence number of the frame being received.
Markus Heiser5377d912016-06-30 15:18:56 +0200301
302
303
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300304.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
305
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300306.. c:type:: v4l2_event_src_change
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300307
Markus Heiser5377d912016-06-30 15:18:56 +0200308.. flat-table:: struct v4l2_event_src_change
309 :header-rows: 0
310 :stub-columns: 0
311 :widths: 1 1 2
312
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300313 * - __u32
314 - ``changes``
315 - A bitmask that tells what has changed. See
316 :ref:`src-changes-flags`.
Markus Heiser5377d912016-06-30 15:18:56 +0200317
318
319
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300320.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
321
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300322.. c:type:: v4l2_event_motion_det
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300323
Markus Heiser5377d912016-06-30 15:18:56 +0200324.. flat-table:: struct v4l2_event_motion_det
325 :header-rows: 0
326 :stub-columns: 0
327 :widths: 1 1 2
328
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300329 * - __u32
330 - ``flags``
331 - Currently only one flag is available: if
332 ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` is set, then the
333 ``frame_sequence`` field is valid, otherwise that field should be
334 ignored.
335 * - __u32
336 - ``frame_sequence``
337 - The sequence number of the frame being received. Only valid if the
338 ``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` flag was set.
339 * - __u32
340 - ``region_mask``
341 - The bitmask of the regions that reported motion. There is at least
342 one region. If this field is 0, then no motion was detected at
343 all. If there is no ``V4L2_CID_DETECT_MD_REGION_GRID`` control
344 (see :ref:`detect-controls`) to assign a different region to
345 each cell in the motion detection grid, then that all cells are
346 automatically assigned to the default region 0.
Markus Heiser5377d912016-06-30 15:18:56 +0200347
348
349
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300350.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
351
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300352.. _ctrl-changes-flags:
353
Markus Heiser5377d912016-06-30 15:18:56 +0200354.. flat-table:: Control Changes
355 :header-rows: 0
356 :stub-columns: 0
357 :widths: 3 1 4
358
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300359 * - ``V4L2_EVENT_CTRL_CH_VALUE``
360 - 0x0001
361 - This control event was triggered because the value of the control
362 changed. Special cases: Volatile controls do no generate this
363 event; If a control has the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
364 flag set, then this event is sent as well, regardless its value.
365 * - ``V4L2_EVENT_CTRL_CH_FLAGS``
366 - 0x0002
367 - This control event was triggered because the control flags
368 changed.
369 * - ``V4L2_EVENT_CTRL_CH_RANGE``
370 - 0x0004
371 - This control event was triggered because the minimum, maximum,
372 step or the default value of the control changed.
Markus Heiser5377d912016-06-30 15:18:56 +0200373
374
375
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -0300376.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
377
Mauro Carvalho Chehabfa92b04d2016-08-19 11:14:23 -0300378.. _src-changes-flags:
379
Markus Heiser5377d912016-06-30 15:18:56 +0200380.. flat-table:: Source Changes
381 :header-rows: 0
382 :stub-columns: 0
383 :widths: 3 1 4
384
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -0300385 * - ``V4L2_EVENT_SRC_CH_RESOLUTION``
386 - 0x0001
387 - This event gets triggered when a resolution change is detected at
388 an input. This can come from an input connector or from a video
Hans Verkuil1611c682018-09-17 07:37:18 -0400389 decoder. Applications will have to query the new resolution (if
390 any, the signal may also have been lost).
391
Tomasz Figa051f8d22019-08-15 11:44:51 -0300392 For stateful decoders follow the guidelines in :ref:`decoder`.
393 Video Capture devices have to query the new timings using
394 :ref:`VIDIOC_QUERY_DV_TIMINGS` or
395 :ref:`VIDIOC_QUERYSTD <VIDIOC_QUERYSTD>`.
396
Hans Verkuil1611c682018-09-17 07:37:18 -0400397 *Important*: even if the new video timings appear identical to the old
398 ones, receiving this event indicates that there was an issue with the
399 video signal and you must stop and restart streaming
400 (:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
401 followed by :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`). The reason is
Tomasz Figa051f8d22019-08-15 11:44:51 -0300402 that many Video Capture devices are not able to recover from a temporary
403 loss of signal and so restarting streaming I/O is required in order for
404 the hardware to synchronize to the video signal.
Markus Heiser5377d912016-06-30 15:18:56 +0200405
406
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -0300407Return Value
Markus Heiser5377d912016-06-30 15:18:56 +0200408============
409
410On success 0 is returned, on error -1 and the ``errno`` variable is set
411appropriately. The generic error codes are described at the
412:ref:`Generic Error Codes <gen-errors>` chapter.