← Documents Documentation/userspace-api/media/v4l/vidioc-dqevent.rst GitHub 원문 ↗

Linux 6.18.37 · 사용자 공간 API

VIDIOC_DQEVENT ioctl

VIDIOC_DQEVENT로 구독 이벤트를 꺼내고 공통 sequence·timestamp·pending 메타데이터와 control, frame, source, motion 이벤트의 병합·유실·재시작 규칙을 해석합니다.

Source pathDocumentation/userspace-api/media/v4l/vidioc-dqevent.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

vidioc-dqevent.rst:1-377

VIDIOC_DQEVENT로 구독 이벤트를 꺼내고 공통 sequence·timestamp·pending 메타데이터와 control, frame, source, motion 이벤트의 병합·유실·재시작 규칙을 해석합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

이름, 호출 형식과 인자

1-30

`VIDIOC_DQEVENT`는 비디오 장치의 이벤트 큐에서 이벤트 하나를 꺼냅니다. 호출 형식은 `int ioctl(int fd, VIDIOC_DQEVENT, struct v4l2_event *argp)`입니다.

`fd`는 `open()`이 반환한 파일 디스크립터이며 `argp`는 드라이버가 채울 `struct v4l2_event`를 가리킵니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L

.. _VIDIOC_DQEVENT:

********************
ioctl VIDIOC_DQEVENT
********************

Name
====

VIDIOC_DQEVENT - Dequeue event

Synopsis
========

.. c:macro:: VIDIOC_DQEVENT

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

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``argp``
    Pointer to struct :c:type:`v4l2_event`.

이벤트 dequeue와 대기

31-39

이 ioctl에는 입력값이 필요하지 않으며 드라이버가 `struct v4l2_event`의 모든 필드를 채웁니다. 파일 핸들은 이벤트가 준비될 때 exception 상태도 받으므로 응용 프로그램은 `select()` 같은 시스템 호출로 대기한 뒤 dequeue할 수 있습니다.

이벤트 수신 흐름
VIDIOC_SUBSCRIBE_EVENTselect/poll로 exception 대기VIDIOC_DQEVENTtype과 union 데이터 처리pending이 남으면 반복

구독한 이벤트가 준비되면 exception 상태를 통해 깨워지고 큐에서 하나씩 꺼냅니다.

Description
===========

Dequeue an event from a video device. No input is required for this
ioctl. All the fields of the struct :c:type:`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.

v4l2_event 공통 구조체

40-99

`type`은 이벤트 종류를 식별하고 union `u`는 종류별 데이터를 제공합니다. 알려지지 않았거나 드라이버 전용 이벤트는 64바이트 `data` 배열로 접근할 수 있습니다.

`pending`은 현재 꺼낸 이벤트를 제외하고 큐에 남은 수입니다. `sequence`는 구독한 이벤트가 발생할 때마다 증가하므로 연속되지 않으면 중간 이벤트가 유실됐음을 뜻합니다. `timestamp`는 `CLOCK_MONOTONIC` 기준이며 V4L2 밖에서는 `clock_gettime()`으로 같은 시계를 읽을 수 있습니다.

`id`는 control ID, 입력 인덱스, pad 인덱스처럼 이벤트 원천과 연결된 ID이며 연결된 ID가 없는 유형은 0입니다. `reserved[8]`은 드라이버가 0으로 설정해야 합니다.

struct v4l2_event
형식필드의미
`__u32``type`이벤트 유형
union`u.vsync``V4L2_EVENT_VSYNC` 데이터
union`u.ctrl``V4L2_EVENT_CTRL` 데이터
union`u.frame_sync``V4L2_EVENT_FRAME_SYNC` 데이터
union`u.motion_det``V4L2_EVENT_MOTION_DET` 데이터
union`u.src_change``V4L2_EVENT_SOURCE_CHANGE` 데이터
`__u8[64]``u.data`유형이 정의하는 원시 이벤트 데이터
`__u32``pending`현재 이벤트를 제외한 보류 이벤트 수
`__u32``sequence`구독 이벤트 발생 순번; 불연속이면 유실
`struct timespec``timestamp``CLOCK_MONOTONIC` 이벤트 시각
`u32``id`이벤트 원천 ID 또는 0
`__u32[8]``reserved`미래 확장용이며 0

공통 메타데이터와 이벤트별 union 멤버입니다.

.. c:type:: v4l2_event

.. tabularcolumns:: |p{3.0cm}|p{3.4cm}|p{10.9cm}|


.. flat-table:: struct v4l2_event
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``type``
      - Type of the event, see :ref:`event-type`.
    * - union {
      - ``u``
    * - struct :c:type:`v4l2_event_vsync`
      - ``vsync``
      - Event data for event ``V4L2_EVENT_VSYNC``.
    * - struct :c:type:`v4l2_event_ctrl`
      - ``ctrl``
      - Event data for event ``V4L2_EVENT_CTRL``.
    * - struct :c:type:`v4l2_event_frame_sync`
      - ``frame_sync``
      - Event data for event ``V4L2_EVENT_FRAME_SYNC``.
    * - struct :c:type:`v4l2_event_motion_det`
      - ``motion_det``
      - Event data for event V4L2_EVENT_MOTION_DET.
    * - struct :c:type:`v4l2_event_src_change`
      - ``src_change``
      - Event data for event V4L2_EVENT_SOURCE_CHANGE.
    * - __u8
      - ``data``\ [64]
      - Event data. Defined by the event type. The union should be used to
	define easily accessible type for events.
    * - }
      -
    * - __u32
      - ``pending``
      - Number of pending events excluding this one.
    * - __u32
      - ``sequence``
      - 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
      - ``timestamp``
      - Event timestamp. The timestamp has been taken from the
	``CLOCK_MONOTONIC`` clock. To access the same clock outside V4L2,
	use :c:func:`clock_gettime`.
    * - u32
      - ``id``
      - 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.
    * - __u32
      - ``reserved``\ [8]
      - Reserved for future extensions. Drivers must set the array to
	zero.

이벤트 유형

100-189

`V4L2_EVENT_ALL`은 모든 이벤트를 한꺼번에 구독 해제할 때만 유효합니다. VSYNC는 수직 동기, EOS는 스트림 끝, CTRL은 control 상태, FRAME_SYNC는 프레임 수신 시작, SOURCE_CHANGE는 실행 중 원천 파라미터 변화, MOTION_DET는 움직임 감지 영역 상태 변화를 알립니다.

CTRL 이벤트를 받으려면 `id`가 대상 control ID와 일치해야 합니다. `VIDIOC_S_CTRL` 또는 `VIDIOC_S_EXT_CTRLS`를 호출해 값을 바꾼 파일 핸들에는 feedback loop 방지를 위해 기본적으로 같은 이벤트를 보내지 않습니다. 호출자도 받아야 한다면 구독 시 `V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK`을 설정합니다.

CTRL 이벤트 큐가 가득 차면 정보 손실을 막기 위해 두 번째로 오래된 이벤트 구조체를 유지하면서 그 `changes`에 가장 오래된 이벤트의 `changes`를 OR합니다. SOURCE_CHANGE도 dequeue 전에 여러 변화가 발생하면 모든 `changes` 비트를 OR해 전달합니다.

FRAME_SYNC는 프레임 수신이 시작되는 즉시 발생합니다. 버퍼 underrun으로 하드웨어를 멈춰야 하는 장치는 이벤트를 만들지 못할 수 있으며 그때 `frame_sequence`가 증가하지 않습니다. 인접 sequence 사이의 시간이 프레임 간격의 n배가 될 수 있습니다.

SOURCE_CHANGE의 `id`는 비디오 장치 노드에서는 입력 인덱스, sub-device 노드에서는 pad 인덱스입니다. MOTION_DET는 하나 이상의 영역 상태가 바뀔 때 발생합니다. `V4L2_EVENT_PRIVATE_START`는 드라이버 전용 이벤트 번호 공간의 시작값입니다.

Event Types
상수발생 조건·데이터
`V4L2_EVENT_ALL`0모든 이벤트; 전체 구독 해제 전용
`V4L2_EVENT_VSYNC`1수직 동기; `v4l2_event_vsync`
`V4L2_EVENT_EOS`2스트림 끝, 보통 MPEG 최종 디코딩 완료
`V4L2_EVENT_CTRL`3control 값·버튼·플래그 변화; `v4l2_event_ctrl`
`V4L2_EVENT_FRAME_SYNC`4프레임 수신 시작; `v4l2_event_frame_sync`
`V4L2_EVENT_SOURCE_CHANGE`5해상도·입력 형식 등 원천 변화; `v4l2_event_src_change`
`V4L2_EVENT_MOTION_DET`6움직임 감지 영역 상태 변화; `v4l2_event_motion_det`
`V4L2_EVENT_PRIVATE_START``0x08000000`드라이버 전용 이벤트 기준 번호

원문 상수값과 연결 구조체를 보존합니다.

.. tabularcolumns:: |p{6.2cm}|p{2.6cm}|p{8.5cm}|

.. cssclass:: longtable

.. _event-type:

.. flat-table:: Event Types
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_EVENT_ALL``
      - 0
      - All events. V4L2_EVENT_ALL is valid only for
	VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
    * - ``V4L2_EVENT_VSYNC``
      - 1
      - This event is triggered on the vertical sync. This event has a
	struct :c:type:`v4l2_event_vsync` associated
	with it.
    * - ``V4L2_EVENT_EOS``
      - 2
      - 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.
    * - ``V4L2_EVENT_CTRL``
      - 3
      - 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
	:c:type:`v4l2_event_ctrl` associated with it.
	This struct contains much of the same information as struct
	:ref:`v4l2_queryctrl <v4l2-queryctrl>` and struct
	:c:type:`v4l2_control`.

	If the event is generated due to a call to
	:ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` or
	:ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_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 :c:type:`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.
    * - ``V4L2_EVENT_FRAME_SYNC``
      - 4
      - Triggered immediately when the reception of a frame has begun.
	This event has a struct
	:c:type:`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
	:c:type:`v4l2_event_frame_sync` will not
	be incremented. This causes two consecutive frame sequence numbers
	to have n times frame interval in between them.
    * - ``V4L2_EVENT_SOURCE_CHANGE``
      - 5
      - 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
	:c:type:`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.
    * - ``V4L2_EVENT_MOTION_DET``
      - 6
      - Triggered whenever the motion detection state for one or more of
	the regions changes. This event has a struct
	:c:type:`v4l2_event_motion_det`
	associated with it.
    * - ``V4L2_EVENT_PRIVATE_START``
      - 0x08000000
      - Base event number for driver-private events.

VSYNC와 control 이벤트 데이터

190-253

`v4l2_event_vsync.field`는 다음에 올 field를 나타내며 `enum v4l2_field` 값을 사용합니다.

`v4l2_event_ctrl.changes`는 무엇이 바뀌었는지 나타내는 비트마스크이고 `type`은 control 유형입니다. 32비트 유형은 `value`, 64비트 유형은 `value64`를 사용합니다. 문자열 값은 이벤트로 전달할 수 없으므로 문자열 control의 `value`는 0입니다.

`flags`, `minimum`, `maximum`, `step`, `default_value`는 현재 control의 플래그와 범위를 전달하며 `v4l2_queryctrl` 및 `v4l2_control` 정보와 대응합니다.

VSYNC·control 이벤트 구조체
구조체필드의미
`v4l2_event_vsync``field`다음에 올 `v4l2_field`
`v4l2_event_ctrl``changes`변화 종류 비트마스크
`v4l2_event_ctrl``type``v4l2_ctrl_type`
`v4l2_event_ctrl``value`32비트 control 값; 문자열은 0
`v4l2_event_ctrl``value64`64비트 control 값
`v4l2_event_ctrl``flags`control 플래그
`v4l2_event_ctrl``minimum`최솟값
`v4l2_event_ctrl``maximum`최댓값
`v4l2_event_ctrl``step`증감 간격
`v4l2_event_ctrl``default_value`기본값

두 이벤트 union 멤버의 필드를 정리합니다.

.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. c:type:: v4l2_event_vsync

.. flat-table:: struct v4l2_event_vsync
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u8
      - ``field``
      - The upcoming field. See enum :c:type:`v4l2_field`.


.. tabularcolumns:: |p{3.5cm}|p{3.0cm}|p{10.8cm}|

.. c:type:: v4l2_event_ctrl

.. flat-table:: struct v4l2_event_ctrl
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``changes``
      - A bitmask that tells what has changed. See
	:ref:`ctrl-changes-flags`.
    * - __u32
      - ``type``
      - The type of the control. See enum
	:c:type:`v4l2_ctrl_type`.
    * - union {
      - (anonymous)
    * - __s32
      - ``value``
      - 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 :ref:`VIDIOC_DQEVENT`.
    * - __s64
      - ``value64``
      - The 64-bit value of the control for 64-bit control types.
    * - }
      -
    * - __u32
      - ``flags``
      - The control flags. See :ref:`control-flags`.
    * - __s32
      - ``minimum``
      - The minimum value of the control. See struct
	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
    * - __s32
      - ``maximum``
      - The maximum value of the control. See struct
	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
    * - __s32
      - ``step``
      - The step value of the control. See struct
	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.
    * - __s32
      - ``default_value``
      - The default value of the control. See struct
	:ref:`v4l2_queryctrl <v4l2-queryctrl>`.

프레임 동기·원천 변화·움직임 감지 데이터

254-311

`v4l2_event_frame_sync.frame_sequence`는 현재 수신 중인 프레임의 sequence 번호입니다. `v4l2_event_src_change.changes`는 원천에서 바뀐 항목을 나타내는 비트마스크입니다.

움직임 감지 이벤트의 `V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ` 플래그가 설정돼야 `frame_sequence`가 유효합니다. 플래그가 없으면 해당 필드를 무시해야 합니다.

`region_mask`는 움직임을 보고한 영역들의 비트마스크입니다. 0이면 움직임이 전혀 감지되지 않았습니다. `V4L2_CID_DETECT_MD_REGION_GRID` control이 없어 grid의 각 cell에 별도 영역을 배정할 수 없으면 모든 cell은 기본 영역 0에 자동 배정됩니다.

Frame·source·motion 이벤트 구조체
구조체필드의미
`v4l2_event_frame_sync``frame_sequence`수신 중인 프레임 sequence
`v4l2_event_src_change``changes`원천 변화 비트마스크
`v4l2_event_motion_det``flags`현재 `HAVE_FRAME_SEQ` 지원
`v4l2_event_motion_det``frame_sequence`플래그가 있을 때만 유효한 프레임 sequence
`v4l2_event_motion_det``region_mask`움직임을 보고한 영역 비트

프레임 번호와 변화 비트의 유효 조건을 포함합니다.

.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. c:type:: v4l2_event_frame_sync

.. flat-table:: struct v4l2_event_frame_sync
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``frame_sequence``
      - The sequence number of the frame being received.


.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. c:type:: v4l2_event_src_change

.. flat-table:: struct v4l2_event_src_change
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``changes``
      - A bitmask that tells what has changed. See
	:ref:`src-changes-flags`.


.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. c:type:: v4l2_event_motion_det

.. flat-table:: struct v4l2_event_motion_det
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``flags``
      - 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.
    * - __u32
      - ``frame_sequence``
      - The sequence number of the frame being received. Only valid if the
	``V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`` flag was set.
    * - __u32
      - ``region_mask``
      - 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 :ref:`detect-controls`) 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 비트

312-341

control 이벤트의 `changes`는 값, 플래그, 범위 또는 차원 중 무엇이 바뀌었는지 표시합니다. 여러 이벤트가 병합되면 해당 비트들이 OR됩니다.

Control Changes
상수의미
`V4L2_EVENT_CTRL_CH_VALUE``0x0001`control 값 변화; volatile control은 생성하지 않으며 EXECUTE_ON_WRITE는 값과 무관하게 생성
`V4L2_EVENT_CTRL_CH_FLAGS``0x0002`control 플래그 변화
`V4L2_EVENT_CTRL_CH_RANGE``0x0004`minimum, maximum, step 또는 default 변화
`V4L2_EVENT_CTRL_CH_DIMENSIONS``0x0008`차원 크기 변화; 차원 개수는 동일

각 변화 비트의 값과 예외입니다.

.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|

.. _ctrl-changes-flags:

.. flat-table:: Control Changes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_EVENT_CTRL_CH_VALUE``
      - 0x0001
      - 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.
    * - ``V4L2_EVENT_CTRL_CH_FLAGS``
      - 0x0002
      - This control event was triggered because the control flags
	changed.
    * - ``V4L2_EVENT_CTRL_CH_RANGE``
      - 0x0004
      - This control event was triggered because the minimum, maximum,
	step or the default value of the control changed.
    * - ``V4L2_EVENT_CTRL_CH_DIMENSIONS``
      - 0x0008
      - This control event was triggered because the dimensions of the
	control changed. Note that the number of dimensions remains the
	same.

Source Changes 비트와 스트리밍 재시작

342-371

`V4L2_EVENT_SRC_CH_RESOLUTION` 값은 `0x0001`이며 입력 커넥터나 비디오 디코더에서 해상도 변화가 감지될 때 발생합니다. 신호가 사라졌을 수도 있으므로 응용 프로그램은 새 해상도를 다시 조회해야 합니다.

stateful 디코더는 decoder 문서의 절차를 따릅니다. 비디오 캡처 장치는 `VIDIOC_QUERY_DV_TIMINGS` 또는 `VIDIOC_QUERYSTD`로 새 타이밍을 조회합니다.

새 타이밍이 이전과 같아 보여도 이 이벤트는 영상 신호에 문제가 있었다는 뜻입니다. 많은 캡처 장치는 일시적 신호 손실에서 자동 복구하지 못하므로 `VIDIOC_STREAMOFF` 뒤 `VIDIOC_STREAMON`으로 스트리밍을 재시작해 하드웨어를 신호에 다시 동기화해야 합니다.

Source Changes
상수대응 조치
`V4L2_EVENT_SRC_CH_RESOLUTION``0x0001`새 타이밍·표준 조회 후 스트리밍 중지와 재시작

현재 정의된 source 변화 비트입니다.

.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|

.. _src-changes-flags:

.. flat-table:: Source Changes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_EVENT_SRC_CH_RESOLUTION``
      - 0x0001
      - 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 :ref:`decoder`.
	Video Capture devices have to query the new timings using
	:ref:`VIDIOC_QUERY_DV_TIMINGS` or
	:ref:`VIDIOC_QUERYSTD <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
	(:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
	followed by :ref:`VIDIOC_STREAMON <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.

반환값

372-377

성공하면 0을 반환하고 실패하면 -1과 적절한 `errno`를 반환합니다. 공통 오류는 Generic Error Codes 절을 따릅니다.

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
:ref:`Generic Error Codes <gen-errors>` chapter.