← Documents Documentation/userspace-api/media/drivers/uvcvideo.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / Drivers

The Linux USB Video Class (UVC) driver

UVC Extension Unit 컨트롤 매핑과 직접 질의, ROI 전용 V4L2 컨트롤을 설명합니다.

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

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

1. 요약·해설

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

요약·해설

uvcvideo.rst:1-321

UVC XU는 일반 V4L2 컨트롤로 매핑하거나 UVCIOC_CTRL_QUERY로 직접 접근할 수 있습니다. 직접 질의에서는 길이·지원 비트·byte order를 애플리케이션이 관리해야 하며, ROI 컨트롤은 전역 센서 좌표의 사각형과 자동 기능 bitmask를 결합합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 The Linux USB Video Class (UVC) driver
4 ======================================
5
6 This file documents some driver-specific aspects of the UVC driver, such as
7 driver-specific ioctls and implementation notes.
8
9 Questions and remarks can be sent to the Linux UVC development mailing list at
10 linux-media@vger.kernel.org.
11
12
13 Extension Unit (XU) support
14 ---------------------------
15
16 Introduction
17 ~~~~~~~~~~~~
18
19 The UVC specification allows for vendor-specific extensions through extension
20 units (XUs). The Linux UVC driver supports extension unit controls (XU controls)
21 through two separate mechanisms:
22
23 - through mappings of XU controls to V4L2 controls
24 - through a driver-specific ioctl interface
25
26 The first one allows generic V4L2 applications to use XU controls by mapping
27 certain XU controls onto V4L2 controls, which then show up during ordinary
28 control enumeration.
29
30 The second mechanism requires uvcvideo-specific knowledge for the application to
31 access XU controls but exposes the entire UVC XU concept to user space for
32 maximum flexibility.
33
34 Both mechanisms complement each other and are described in more detail below.
35
36
37 Control mappings
38 ~~~~~~~~~~~~~~~~
39
40 The UVC driver provides an API for user space applications to define so-called
41 control mappings at runtime. These allow for individual XU controls or byte
42 ranges thereof to be mapped to new V4L2 controls. Such controls appear and
43 function exactly like normal V4L2 controls (i.e. the stock controls, such as
44 brightness, contrast, etc.). However, reading or writing of such a V4L2 controls
45 triggers a read or write of the associated XU control.
46
47 The ioctl used to create these control mappings is called UVCIOC_CTRL_MAP.
48 Previous driver versions (before 0.2.0) required another ioctl to be used
49 beforehand (UVCIOC_CTRL_ADD) to pass XU control information to the UVC driver.
50 This is no longer necessary as newer uvcvideo versions query the information
51 directly from the device.
52
53 For details on the UVCIOC_CTRL_MAP ioctl please refer to the section titled
54 "IOCTL reference" below.
55
56
57 3. Driver specific XU control interface
58
59 For applications that need to access XU controls directly, e.g. for testing
60 purposes, firmware upload, or accessing binary controls, a second mechanism to
61 access XU controls is provided in the form of a driver-specific ioctl, namely
62 UVCIOC_CTRL_QUERY.
63
64 A call to this ioctl allows applications to send queries to the UVC driver that
65 directly map to the low-level UVC control requests.
66
67 In order to make such a request the UVC unit ID of the control's extension unit
68 and the control selector need to be known. This information either needs to be
69 hardcoded in the application or queried using other ways such as by parsing the
70 UVC descriptor or, if available, using the media controller API to enumerate a
71 device's entities.
72
73 Unless the control size is already known it is necessary to first make a
74 UVC_GET_LEN requests in order to be able to allocate a sufficiently large buffer
75 and set the buffer size to the correct value. Similarly, to find out whether
76 UVC_GET_CUR or UVC_SET_CUR are valid requests for a given control, a
77 UVC_GET_INFO request should be made. The bits 0 (GET supported) and 1 (SET
78 supported) of the resulting byte indicate which requests are valid.
79
80 With the addition of the UVCIOC_CTRL_QUERY ioctl the UVCIOC_CTRL_GET and
81 UVCIOC_CTRL_SET ioctls have become obsolete since their functionality is a
82 subset of the former ioctl. For the time being they are still supported but
83 application developers are encouraged to use UVCIOC_CTRL_QUERY instead.
84
85 For details on the UVCIOC_CTRL_QUERY ioctl please refer to the section titled
86 "IOCTL reference" below.
87
88
89 Security
90 ~~~~~~~~
91
92 The API doesn't currently provide a fine-grained access control facility. The
93 UVCIOC_CTRL_ADD and UVCIOC_CTRL_MAP ioctls require super user permissions.
94
95 Suggestions on how to improve this are welcome.
96
97
98 Debugging
99 ~~~~~~~~~
100
101 In order to debug problems related to XU controls or controls in general it is
102 recommended to enable the UVC_TRACE_CONTROL bit in the module parameter 'trace'.
103 This causes extra output to be written into the system log.
104
105
106 IOCTL reference
107 ~~~~~~~~~~~~~~~
108
109 UVCIOC_CTRL_MAP - Map a UVC control to a V4L2 control
110 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111
112 Argument: struct uvc_xu_control_mapping
113
114 **Description**:
115
116 This ioctl creates a mapping between a UVC control or part of a UVC
117 control and a V4L2 control. Once mappings are defined, userspace
118 applications can access vendor-defined UVC control through the V4L2
119 control API.
120
121 To create a mapping, applications fill the uvc_xu_control_mapping
122 structure with information about an existing UVC control defined with
123 UVCIOC_CTRL_ADD and a new V4L2 control.
124
125 A UVC control can be mapped to several V4L2 controls. For instance,
126 a UVC pan/tilt control could be mapped to separate pan and tilt V4L2
127 controls. The UVC control is divided into non overlapping fields using
128 the 'size' and 'offset' fields and are then independently mapped to
129 V4L2 control.
130
131 For signed integer V4L2 controls the data_type field should be set to
132 UVC_CTRL_DATA_TYPE_SIGNED. Other values are currently ignored.
133
134 **Return value**:
135
136 On success 0 is returned. On error -1 is returned and errno is set
137 appropriately.
138
139 ENOMEM
140 Not enough memory to perform the operation.
141 EPERM
142 Insufficient privileges (super user privileges are required).
143 EINVAL
144 No such UVC control.
145 EOVERFLOW
146 The requested offset and size would overflow the UVC control.
147 EEXIST
148 Mapping already exists.
149
150 **Data types**:
151
152 .. code-block:: none
153
154 * struct uvc_xu_control_mapping
155
156 __u32 id V4L2 control identifier
157 __u8 name[32] V4L2 control name
158 __u8 entity[16] UVC extension unit GUID
159 __u8 selector UVC control selector
160 __u8 size V4L2 control size (in bits)
161 __u8 offset V4L2 control offset (in bits)
162 enum v4l2_ctrl_type
163 v4l2_type V4L2 control type
164 enum uvc_control_data_type
165 data_type UVC control data type
166 struct uvc_menu_info
167 *menu_info Array of menu entries (for menu controls only)
168 __u32 menu_count Number of menu entries (for menu controls only)
169
170 * struct uvc_menu_info
171
172 __u32 value Menu entry value used by the device
173 __u8 name[32] Menu entry name
174
175
176 * enum uvc_control_data_type
177
178 UVC_CTRL_DATA_TYPE_RAW Raw control (byte array)
179 UVC_CTRL_DATA_TYPE_SIGNED Signed integer
180 UVC_CTRL_DATA_TYPE_UNSIGNED Unsigned integer
181 UVC_CTRL_DATA_TYPE_BOOLEAN Boolean
182 UVC_CTRL_DATA_TYPE_ENUM Enumeration
183 UVC_CTRL_DATA_TYPE_BITMASK Bitmask
184 UVC_CTRL_DATA_TYPE_RECT Rectangular area
185
186
187 UVCIOC_CTRL_QUERY - Query a UVC XU control
188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189 Argument: struct uvc_xu_control_query
190
191 **Description**:
192
193 This ioctl queries a UVC XU control identified by its extension unit ID
194 and control selector.
195
196 There are a number of different queries available that closely
197 correspond to the low-level control requests described in the UVC
198 specification. These requests are:
199
200 UVC_GET_CUR
201 Obtain the current value of the control.
202 UVC_GET_MIN
203 Obtain the minimum value of the control.
204 UVC_GET_MAX
205 Obtain the maximum value of the control.
206 UVC_GET_DEF
207 Obtain the default value of the control.
208 UVC_GET_RES
209 Query the resolution of the control, i.e. the step size of the
210 allowed control values.
211 UVC_GET_LEN
212 Query the size of the control in bytes.
213 UVC_GET_INFO
214 Query the control information bitmap, which indicates whether
215 get/set requests are supported.
216 UVC_SET_CUR
217 Update the value of the control.
218
219 Applications must set the 'size' field to the correct length for the
220 control. Exceptions are the UVC_GET_LEN and UVC_GET_INFO queries, for
221 which the size must be set to 2 and 1, respectively. The 'data' field
222 must point to a valid writable buffer big enough to hold the indicated
223 number of data bytes.
224
225 Data is copied directly from the device without any driver-side
226 processing. Applications are responsible for data buffer formatting,
227 including little-endian/big-endian conversion. This is particularly
228 important for the result of the UVC_GET_LEN requests, which is always
229 returned as a little-endian 16-bit integer by the device.
230
231 **Return value**:
232
233 On success 0 is returned. On error -1 is returned and errno is set
234 appropriately.
235
236 ENOENT
237 The device does not support the given control or the specified
238 extension unit could not be found.
239 ENOBUFS
240 The specified buffer size is incorrect (too big or too small).
241 EINVAL
242 An invalid request code was passed.
243 EBADRQC
244 The given request is not supported by the given control.
245 EFAULT
246 The data pointer references an inaccessible memory area.
247
248 **Data types**:
249
250 .. code-block:: none
251
252 * struct uvc_xu_control_query
253
254 __u8 unit Extension unit ID
255 __u8 selector Control selector
256 __u8 query Request code to send to the device
257 __u16 size Control data size (in bytes)
258 __u8 *data Control value
259
260
261 Driver-specific V4L2 controls
262 -----------------------------
263
264 The uvcvideo driver implements the following UVC-specific controls:
265
266 ``V4L2_CID_UVC_REGION_OF_INTEREST_RECT (struct)``
267 This control determines the region of interest (ROI). ROI is a
268 rectangular area represented by a struct :c:type:`v4l2_rect`. The
269 rectangle is in global sensor coordinates using pixel units. It is
270 independent of the field of view, not impacted by any cropping or
271 scaling.
272
273 Use ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` to query
274 the range of rectangle sizes.
275
276 Setting a ROI allows the camera to optimize the capture for the region.
277 The value of ``V4L2_CID_REGION_OF_INTEREST_AUTO`` control determines
278 the detailed behavior.
279
280 An example of use of this control, can be found in the:
281 `Chrome OS USB camera HAL.
282 <https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/release-R121-15699.B/camera/hal/usb/>`
283
284
285 ``V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (bitmask)``
286 This determines which, if any, on-board features should track to the
287 Region of Interest specified by the current value of
288 ``V4L2_CID_UVD__REGION_OF_INTEREST_RECT``.
289
290 Max value is a mask indicating all supported Auto Controls.
291
292 .. flat-table::
293 :header-rows: 0
294 :stub-columns: 0
295
296 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE``
297 - Setting this bit causes automatic exposure to track the region of
298 interest instead of the whole image.
299 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS``
300 - Setting this bit causes automatic iris to track the region of interest
301 instead of the whole image.
302 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
303 - Setting this bit causes automatic white balance to track the region
304 of interest instead of the whole image.
305 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS``
306 - Setting this bit causes automatic focus adjustment to track the region
307 of interest instead of the whole image.
308 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT``
309 - Setting this bit causes automatic face detection to track the region of
310 interest instead of the whole image.
311 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
312 - Setting this bit enables automatic face detection and tracking. The
313 current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by
314 the driver.
315 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
316 - Setting this bit enables automatic image stabilization. The
317 current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by
318 the driver.
319 * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
320 - Setting this bit enables automatically capture the specified region
321 with higher quality if possible.
322

3. 한국어 전문 번역

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

문서 범위와 연락처

1-12

이 문서는 GPL-2.0 라이선스를 따르며 Linux USB Video Class(UVC) 드라이버의 전용 IOCTL과 구현 참고 사항을 설명합니다.

질문과 의견은 Linux UVC 개발 메일링 리스트 `linux-media@vger.kernel.org`로 보낼 수 있습니다.

.. SPDX-License-Identifier: GPL-2.0

The Linux USB Video Class (UVC) driver
======================================

This file documents some driver-specific aspects of the UVC driver, such as
driver-specific ioctls and implementation notes.

Questions and remarks can be sent to the Linux UVC development mailing list at
linux-media@vger.kernel.org.

Extension Unit(XU) 지원

13-36

UVC 규격은 Extension Unit(XU)을 통한 벤더별 확장을 허용합니다. Linux UVC 드라이버는 XU 컨트롤을 두 가지 별도 방식으로 지원합니다.

XU 컨트롤 접근 방식
항목설명
XU 컨트롤을 V4L2 컨트롤로 매핑일반 V4L2 애플리케이션이 보통의 컨트롤 열거와 동일하게 사용
드라이버 전용 IOCTL 인터페이스uvcvideo 지식이 필요하지만 UVC XU 개념 전체를 사용자 공간에 노출

일반 V4L2 통합과 UVC 전용 직접 접근을 함께 제공합니다.

첫 번째 방식은 특정 XU 컨트롤을 V4L2 컨트롤에 매핑합니다. 그러면 해당 컨트롤이 일반 컨트롤 열거 과정에 나타나므로 범용 V4L2 애플리케이션에서도 사용할 수 있습니다.

두 번째 방식은 애플리케이션이 uvcvideo 전용 인터페이스를 알아야 하지만, 최대한의 유연성을 위해 UVC XU 전체를 사용자 공간에 노출합니다. 두 방식은 서로 보완적입니다.

Extension Unit (XU) support
---------------------------

Introduction
~~~~~~~~~~~~

The UVC specification allows for vendor-specific extensions through extension
units (XUs). The Linux UVC driver supports extension unit controls (XU controls)
through two separate mechanisms:

  - through mappings of XU controls to V4L2 controls
  - through a driver-specific ioctl interface

The first one allows generic V4L2 applications to use XU controls by mapping
certain XU controls onto V4L2 controls, which then show up during ordinary
control enumeration.

The second mechanism requires uvcvideo-specific knowledge for the application to
access XU controls but exposes the entire UVC XU concept to user space for
maximum flexibility.

Both mechanisms complement each other and are described in more detail below.

런타임 컨트롤 매핑

37-55

UVC 드라이버는 사용자 공간 애플리케이션이 런타임에 컨트롤 매핑을 정의하는 API를 제공합니다. 개별 XU 컨트롤이나 그 일부 바이트 범위를 새 V4L2 컨트롤에 매핑할 수 있습니다.

매핑된 컨트롤은 밝기나 대비 같은 기본 컨트롤과 똑같이 일반 V4L2 컨트롤로 표시되고 동작합니다. 다만 그 V4L2 컨트롤을 읽거나 쓰면 연결된 XU 컨트롤 읽기 또는 쓰기가 실행됩니다.

컨트롤 매핑을 만드는 IOCTL은 `UVCIOC_CTRL_MAP`입니다. 0.2.0 이전 드라이버에서는 먼저 `UVCIOC_CTRL_ADD`로 XU 컨트롤 정보를 전달해야 했지만, 최신 uvcvideo는 장치에서 직접 정보를 질의하므로 더 이상 필요하지 않습니다.

`UVCIOC_CTRL_MAP`의 세부 사항은 아래의 IOCTL 참조 절에서 설명합니다.

XU를 V4L2 컨트롤로 매핑
장치에서 XU 컨트롤 정보 확인UVCIOC_CTRL_MAP 구조체 작성XU 비트 범위를 새 V4L2 컨트롤에 연결일반 V4L2 컨트롤 열거에 노출V4L2 읽기·쓰기를 XU 읽기·쓰기로 전달

런타임 매핑 뒤에는 범용 V4L2 API가 XU 요청으로 이어집니다.

Control mappings
~~~~~~~~~~~~~~~~

The UVC driver provides an API for user space applications to define so-called
control mappings at runtime. These allow for individual XU controls or byte
ranges thereof to be mapped to new V4L2 controls. Such controls appear and
function exactly like normal V4L2 controls (i.e. the stock controls, such as
brightness, contrast, etc.). However, reading or writing of such a V4L2 controls
triggers a read or write of the associated XU control.

The ioctl used to create these control mappings is called UVCIOC_CTRL_MAP.
Previous driver versions (before 0.2.0) required another ioctl to be used
beforehand (UVCIOC_CTRL_ADD) to pass XU control information to the UVC driver.
This is no longer necessary as newer uvcvideo versions query the information
directly from the device.

For details on the UVCIOC_CTRL_MAP ioctl please refer to the section titled
"IOCTL reference" below.

드라이버 전용 XU 컨트롤 인터페이스

56-88

테스트, 펌웨어 업로드, 바이너리 컨트롤처럼 XU 컨트롤에 직접 접근해야 하는 애플리케이션을 위해 `UVCIOC_CTRL_QUERY` 드라이버 전용 IOCTL이 제공됩니다. 이 호출은 저수준 UVC 컨트롤 요청과 직접 대응하는 질의를 UVC 드라이버에 보냅니다.

요청하려면 컨트롤이 속한 Extension Unit의 UVC unit ID와 control selector를 알아야 합니다. 애플리케이션에 값을 하드코딩하거나, UVC descriptor를 파싱하거나, 가능하면 Media Controller API로 장치 entity를 열거해 얻을 수 있습니다.

컨트롤 크기를 모르면 충분한 버퍼를 할당하고 정확한 크기를 설정하기 위해 먼저 `UVC_GET_LEN`을 요청해야 합니다. 특정 컨트롤에서 `UVC_GET_CUR` 또는 `UVC_SET_CUR`이 유효한지 확인하려면 `UVC_GET_INFO`를 요청합니다.

`UVC_GET_INFO` 결과 바이트의 bit 0은 GET 지원, bit 1은 SET 지원을 나타냅니다.

`UVCIOC_CTRL_QUERY`가 추가되면서 `UVCIOC_CTRL_GET`과 `UVCIOC_CTRL_SET`은 기능이 QUERY의 부분집합이므로 폐기 예정이 되었습니다. 당분간은 지원되지만 새 애플리케이션은 `UVCIOC_CTRL_QUERY`를 사용하는 것이 권장됩니다.

직접 XU 질의 준비
Extension Unit ID와 selector 확인UVC_GET_LEN으로 데이터 크기 조회크기에 맞는 버퍼 할당UVC_GET_INFO로 GET·SET 지원 확인UVCIOC_CTRL_QUERY로 실제 요청 전송

크기와 지원 요청을 먼저 확인한 뒤 실제 값을 읽거나 씁니다.


3. Driver specific XU control interface

For applications that need to access XU controls directly, e.g. for testing
purposes, firmware upload, or accessing binary controls, a second mechanism to
access XU controls is provided in the form of a driver-specific ioctl, namely
UVCIOC_CTRL_QUERY.

A call to this ioctl allows applications to send queries to the UVC driver that
directly map to the low-level UVC control requests.

In order to make such a request the UVC unit ID of the control's extension unit
and the control selector need to be known. This information either needs to be
hardcoded in the application or queried using other ways such as by parsing the
UVC descriptor or, if available, using the media controller API to enumerate a
device's entities.

Unless the control size is already known it is necessary to first make a
UVC_GET_LEN requests in order to be able to allocate a sufficiently large buffer
and set the buffer size to the correct value. Similarly, to find out whether
UVC_GET_CUR or UVC_SET_CUR are valid requests for a given control, a
UVC_GET_INFO request should be made. The bits 0 (GET supported) and 1 (SET
supported) of the resulting byte indicate which requests are valid.

With the addition of the UVCIOC_CTRL_QUERY ioctl the UVCIOC_CTRL_GET and
UVCIOC_CTRL_SET ioctls have become obsolete since their functionality is a
subset of the former ioctl. For the time being they are still supported but
application developers are encouraged to use UVCIOC_CTRL_QUERY instead.

For details on the UVCIOC_CTRL_QUERY ioctl please refer to the section titled
"IOCTL reference" below.

보안과 디버깅

89-105

현재 API는 세밀한 접근 제어 기능을 제공하지 않습니다. `UVCIOC_CTRL_ADD`와 `UVCIOC_CTRL_MAP` IOCTL을 사용하려면 super user 권한이 필요합니다. 이 부분을 개선할 제안을 환영합니다.

XU 컨트롤이나 일반 컨트롤 문제를 디버깅할 때는 모듈 매개변수 `trace`에서 `UVC_TRACE_CONTROL` 비트를 활성화하는 것이 권장됩니다. 그러면 추가 진단 출력이 시스템 로그에 기록됩니다.

XU 운영 주의점
항목설명
UVCIOC_CTRL_ADD / UVCIOC_CTRL_MAPsuper user 권한 필요
trace의 UVC_TRACE_CONTROL컨트롤 관련 추가 로그 활성화

매핑 권한과 추적 출력을 구분합니다.

Security
~~~~~~~~

The API doesn't currently provide a fine-grained access control facility. The
UVCIOC_CTRL_ADD and UVCIOC_CTRL_MAP ioctls require super user permissions.

Suggestions on how to improve this are welcome.


Debugging
~~~~~~~~~

In order to debug problems related to XU controls or controls in general it is
recommended to enable the UVC_TRACE_CONTROL bit in the module parameter 'trace'.
This causes extra output to be written into the system log.

UVCIOC_CTRL_MAP

106-149

`UVCIOC_CTRL_MAP`은 UVC 컨트롤 또는 그 일부를 V4L2 컨트롤에 매핑합니다. 인자는 `struct uvc_xu_control_mapping`입니다. 매핑을 정의하면 사용자 공간은 V4L2 컨트롤 API로 벤더 정의 UVC 컨트롤에 접근할 수 있습니다.

애플리케이션은 기존 UVC 컨트롤 정보와 새 V4L2 컨트롤 정보를 `uvc_xu_control_mapping` 구조체에 채웁니다. 원문은 기존 컨트롤이 `UVCIOC_CTRL_ADD`로 정의된다고 설명합니다.

하나의 UVC 컨트롤을 여러 V4L2 컨트롤에 매핑할 수 있습니다. 예를 들어 UVC pan/tilt 컨트롤을 별도의 pan과 tilt V4L2 컨트롤로 나눌 수 있습니다. `size`와 `offset`으로 UVC 컨트롤을 겹치지 않는 필드로 나눈 뒤 각각 독립적으로 매핑합니다.

부호 있는 정수 V4L2 컨트롤은 `data_type`을 `UVC_CTRL_DATA_TYPE_SIGNED`로 설정해야 합니다. 현재 다른 값은 무시됩니다.

성공하면 0을 반환합니다. 오류이면 -1을 반환하고 `errno`를 알맞게 설정합니다.

UVCIOC_CTRL_MAP 오류
항목설명
ENOMEM작업을 수행할 메모리가 부족함
EPERM권한 부족; super user 권한 필요
EINVAL해당 UVC 컨트롤이 없음
EOVERFLOW요청한 offset과 size가 UVC 컨트롤 범위를 넘음
EEXIST매핑이 이미 존재함

매핑 생성이 실패할 때의 errno 의미입니다.

IOCTL reference
~~~~~~~~~~~~~~~

UVCIOC_CTRL_MAP - Map a UVC control to a V4L2 control
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Argument: struct uvc_xu_control_mapping

**Description**:

	This ioctl creates a mapping between a UVC control or part of a UVC
	control and a V4L2 control. Once mappings are defined, userspace
	applications can access vendor-defined UVC control through the V4L2
	control API.

	To create a mapping, applications fill the uvc_xu_control_mapping
	structure with information about an existing UVC control defined with
	UVCIOC_CTRL_ADD and a new V4L2 control.

	A UVC control can be mapped to several V4L2 controls. For instance,
	a UVC pan/tilt control could be mapped to separate pan and tilt V4L2
	controls. The UVC control is divided into non overlapping fields using
	the 'size' and 'offset' fields and are then independently mapped to
	V4L2 control.

	For signed integer V4L2 controls the data_type field should be set to
	UVC_CTRL_DATA_TYPE_SIGNED. Other values are currently ignored.

**Return value**:

	On success 0 is returned. On error -1 is returned and errno is set
	appropriately.

	ENOMEM
		Not enough memory to perform the operation.
	EPERM
		Insufficient privileges (super user privileges are required).
	EINVAL
		No such UVC control.
	EOVERFLOW
		The requested offset and size would overflow the UVC control.
	EEXIST
		Mapping already exists.

매핑 구조체와 데이터 형식

150-186
struct uvc_xu_control_mapping
필드의미
__u32 idV4L2 control identifier
__u8 name[32]V4L2 control name
__u8 entity[16]UVC extension unit GUID
__u8 selectorUVC control selector
__u8 sizeV4L2 control size, bits
__u8 offsetV4L2 control offset, bits
enum v4l2_ctrl_type v4l2_typeV4L2 control type
enum uvc_control_data_type data_typeUVC control data type
struct uvc_menu_info *menu_info메뉴 컨트롤의 menu entry 배열
__u32 menu_count메뉴 컨트롤의 menu entry 수

V4L2 컨트롤과 XU 필드를 연결하는 구조체 필드입니다.

struct uvc_menu_info
필드의미
__u32 value장치가 사용하는 menu entry 값
__u8 name[32]menu entry 이름

메뉴 값과 표시 이름을 보관합니다.

enum uvc_control_data_type
항목설명
UVC_CTRL_DATA_TYPE_RAWRaw control, byte array
UVC_CTRL_DATA_TYPE_SIGNEDSigned integer
UVC_CTRL_DATA_TYPE_UNSIGNEDUnsigned integer
UVC_CTRL_DATA_TYPE_BOOLEANBoolean
UVC_CTRL_DATA_TYPE_ENUMEnumeration
UVC_CTRL_DATA_TYPE_BITMASKBitmask
UVC_CTRL_DATA_TYPE_RECTRectangular area

XU 컨트롤 데이터의 해석 형식입니다.

**Data types**:

.. code-block:: none

	* struct uvc_xu_control_mapping

	__u32	id		V4L2 control identifier
	__u8	name[32]	V4L2 control name
	__u8	entity[16]	UVC extension unit GUID
	__u8	selector	UVC control selector
	__u8	size		V4L2 control size (in bits)
	__u8	offset		V4L2 control offset (in bits)
	enum v4l2_ctrl_type
		v4l2_type	V4L2 control type
	enum uvc_control_data_type
		data_type	UVC control data type
	struct uvc_menu_info
		*menu_info	Array of menu entries (for menu controls only)
	__u32	menu_count	Number of menu entries (for menu controls only)

	* struct uvc_menu_info

	__u32	value		Menu entry value used by the device
	__u8	name[32]	Menu entry name


	* enum uvc_control_data_type

	UVC_CTRL_DATA_TYPE_RAW		Raw control (byte array)
	UVC_CTRL_DATA_TYPE_SIGNED	Signed integer
	UVC_CTRL_DATA_TYPE_UNSIGNED	Unsigned integer
	UVC_CTRL_DATA_TYPE_BOOLEAN	Boolean
	UVC_CTRL_DATA_TYPE_ENUM		Enumeration
	UVC_CTRL_DATA_TYPE_BITMASK	Bitmask
	UVC_CTRL_DATA_TYPE_RECT		Rectangular area

UVCIOC_CTRL_QUERY 요청

187-230

`UVCIOC_CTRL_QUERY`는 Extension Unit ID와 control selector로 식별한 UVC XU 컨트롤을 질의합니다. 인자는 `struct uvc_xu_control_query`입니다.

사용 가능한 질의는 UVC 규격의 저수준 컨트롤 요청과 밀접하게 대응합니다.

UVC XU query code
항목설명
UVC_GET_CUR현재 컨트롤 값 조회
UVC_GET_MIN최솟값 조회
UVC_GET_MAX최댓값 조회
UVC_GET_DEF기본값 조회
UVC_GET_RES허용되는 값의 step size인 resolution 조회
UVC_GET_LEN컨트롤 크기를 byte 단위로 조회
UVC_GET_INFOGET/SET 지원을 나타내는 정보 bitmap 조회
UVC_SET_CUR현재 컨트롤 값 갱신

각 요청 코드의 동작입니다.

애플리케이션은 `size` 필드를 컨트롤의 정확한 길이로 설정해야 합니다. 예외적으로 `UVC_GET_LEN`은 2, `UVC_GET_INFO`는 1로 설정해야 합니다. `data`는 지정한 byte 수를 담을 만큼 큰 유효한 쓰기 가능 버퍼를 가리켜야 합니다.

데이터는 드라이버 측 처리 없이 장치에서 그대로 복사됩니다. little-endian과 big-endian 변환을 포함한 버퍼 형식 처리는 애플리케이션 책임입니다. 특히 `UVC_GET_LEN` 결과는 장치가 항상 little-endian 16-bit 정수로 반환합니다.

UVCIOC_CTRL_QUERY 데이터 처리
요청 코드와 올바른 size 지정충분히 큰 writable data 버퍼 준비UVCIOC_CTRL_QUERY 호출장치 데이터가 그대로 버퍼에 복사애플리케이션이 byte order와 데이터 형식 변환

드라이버가 가공하지 않는 데이터를 애플리케이션이 형식에 맞게 해석합니다.

UVCIOC_CTRL_QUERY - Query a UVC XU control
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Argument: struct uvc_xu_control_query

**Description**:

	This ioctl queries a UVC XU control identified by its extension unit ID
	and control selector.

	There are a number of different queries available that closely
	correspond to the low-level control requests described in the UVC
	specification. These requests are:

	UVC_GET_CUR
		Obtain the current value of the control.
	UVC_GET_MIN
		Obtain the minimum value of the control.
	UVC_GET_MAX
		Obtain the maximum value of the control.
	UVC_GET_DEF
		Obtain the default value of the control.
	UVC_GET_RES
		Query the resolution of the control, i.e. the step size of the
		allowed control values.
	UVC_GET_LEN
		Query the size of the control in bytes.
	UVC_GET_INFO
		Query the control information bitmap, which indicates whether
		get/set requests are supported.
	UVC_SET_CUR
		Update the value of the control.

	Applications must set the 'size' field to the correct length for the
	control. Exceptions are the UVC_GET_LEN and UVC_GET_INFO queries, for
	which the size must be set to 2 and 1, respectively. The 'data' field
	must point to a valid writable buffer big enough to hold the indicated
	number of data bytes.

	Data is copied directly from the device without any driver-side
	processing. Applications are responsible for data buffer formatting,
	including little-endian/big-endian conversion. This is particularly
	important for the result of the UVC_GET_LEN requests, which is always
	returned as a little-endian 16-bit integer by the device.

QUERY 반환값과 구조체

231-259

`UVCIOC_CTRL_QUERY`는 성공 시 0, 오류 시 -1을 반환하고 `errno`를 설정합니다.

UVCIOC_CTRL_QUERY 오류
항목설명
ENOENT장치가 해당 컨트롤을 지원하지 않거나 Extension Unit을 찾지 못함
ENOBUFS지정한 버퍼 크기가 너무 크거나 작음
EINVAL유효하지 않은 request code
EBADRQC해당 컨트롤이 요청을 지원하지 않음
EFAULTdata 포인터가 접근할 수 없는 메모리를 가리킴

직접 XU 질의 실패 원인입니다.

struct uvc_xu_control_query
필드의미
__u8 unitExtension unit ID
__u8 selectorControl selector
__u8 query장치에 보낼 request code
__u16 size컨트롤 데이터 크기, bytes
__u8 *data컨트롤 값 버퍼

직접 XU 요청에 사용하는 필드입니다.

**Return value**:

	On success 0 is returned. On error -1 is returned and errno is set
	appropriately.

	ENOENT
		The device does not support the given control or the specified
		extension unit could not be found.
	ENOBUFS
		The specified buffer size is incorrect (too big or too small).
	EINVAL
		An invalid request code was passed.
	EBADRQC
		The given request is not supported by the given control.
	EFAULT
		The data pointer references an inaccessible memory area.

**Data types**:

.. code-block:: none

	* struct uvc_xu_control_query

	__u8	unit		Extension unit ID
	__u8	selector	Control selector
	__u8	query		Request code to send to the device
	__u16	size		Control data size (in bytes)
	__u8	*data		Control value

V4L2_CID_UVC_REGION_OF_INTEREST_RECT

260-284

uvcvideo 드라이버는 UVC 전용 V4L2 컨트롤을 구현합니다. `V4L2_CID_UVC_REGION_OF_INTEREST_RECT (struct)`는 Region of Interest(ROI)를 결정합니다.

ROI는 `struct v4l2_rect`로 나타내는 사각형입니다. 픽셀 단위의 전역 센서 좌표를 사용하며 field of view와 독립적이고 crop이나 scale의 영향을 받지 않습니다.

`V4L2_CTRL_WHICH_MIN_VAL`과 `V4L2_CTRL_WHICH_MAX_VAL`을 사용해 사각형 크기 범위를 질의할 수 있습니다.

ROI를 설정하면 카메라는 해당 영역에 맞춰 캡처를 최적화할 수 있습니다. 구체적인 동작은 `V4L2_CID_REGION_OF_INTEREST_AUTO` 컨트롤 값이 결정합니다.

이 컨트롤의 사용 예는 원문이 연결한 `Chrome OS USB camera HAL`에서 확인할 수 있습니다: `https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/release-R121-15699.B/camera/hal/usb/`.

UVC ROI 좌표 특성
항목설명
형식struct v4l2_rect
단위pixel
좌표계global sensor coordinates
crop/scale 영향없음
크기 범위V4L2_CTRL_WHICH_MIN_VAL / V4L2_CTRL_WHICH_MAX_VAL로 조회

ROI 사각형은 센서 전체 좌표계에 고정됩니다.


Driver-specific V4L2 controls
-----------------------------

The uvcvideo driver implements the following UVC-specific controls:

``V4L2_CID_UVC_REGION_OF_INTEREST_RECT (struct)``
	This control determines the region of interest (ROI). ROI is a
	rectangular area represented by a struct :c:type:`v4l2_rect`. The
	rectangle is in global sensor coordinates using pixel units. It is
	independent of the field of view, not impacted by any cropping or
	scaling.

	Use ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` to query
	the range of rectangle sizes.

	Setting a ROI allows the camera to optimize the capture for the region.
	The value of ``V4L2_CID_REGION_OF_INTEREST_AUTO`` control determines
	the detailed behavior.

	An example of use of this control, can be found in the:
	`Chrome OS USB camera HAL.
	<https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/release-R121-15699.B/camera/hal/usb/>`

V4L2_CID_UVC_REGION_OF_INTEREST_AUTO

285-321

`V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (bitmask)`는 현재 ROI 사각형을 추적할 온보드 자동 기능을 결정합니다. 원문 288줄은 사각형 컨트롤을 `V4L2_CID_UVD__REGION_OF_INTEREST_RECT`로 표기하고 있습니다.

최댓값은 지원되는 모든 Auto Control을 나타내는 mask입니다.

UVC ROI 자동 기능 비트
항목설명
V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE전체 이미지 대신 ROI를 따라 자동 노출 조정
V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS전체 이미지 대신 ROI를 따라 자동 iris 조정
V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE전체 이미지 대신 ROI를 따라 자동 white balance 조정
V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS전체 이미지 대신 ROI를 따라 자동 focus 조정
V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT전체 이미지 대신 ROI를 따라 자동 face detection
V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK자동 face detection과 tracking 활성화; 드라이버가 V4L2_CID_REGION_OF_INTEREST_RECT를 갱신할 수 있음
V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION자동 image stabilization 활성화; 드라이버가 V4L2_CID_REGION_OF_INTEREST_RECT를 갱신할 수 있음
V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY가능하면 지정 영역을 더 높은 품질로 자동 캡처

비트를 설정했을 때 ROI를 기준으로 동작하는 기능입니다.

ROI 자동 제어
전역 센서 좌표로 ROI 사각형 설정지원 mask 최댓값 조회필요한 자동 기능 비트 선택카메라가 ROI를 기준으로 자동 기능 수행tracking 또는 stabilization 시 드라이버가 ROI 사각형 갱신 가능

ROI 사각형과 bitmask가 카메라의 자동 기능을 함께 제어합니다.

``V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (bitmask)``
	This determines which, if any, on-board features should track to the
	Region of Interest specified by the current value of
	``V4L2_CID_UVD__REGION_OF_INTEREST_RECT``.

	Max value is a mask indicating all supported Auto Controls.

.. flat-table::
    :header-rows:  0
    :stub-columns: 0

    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE``
      - Setting this bit causes automatic exposure to track the region of
	interest instead of the whole image.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS``
      - Setting this bit causes automatic iris to track the region of interest
        instead of the whole image.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE``
      - Setting this bit causes automatic white balance to track the region
	of interest instead of the whole image.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS``
      - Setting this bit causes automatic focus adjustment to track the region
        of interest instead of the whole image.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT``
      - Setting this bit causes automatic face detection to track the region of
        interest instead of the whole image.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK``
      - Setting this bit enables automatic face detection and tracking. The
	current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by
	the driver.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION``
      - Setting this bit enables automatic image stabilization. The
	current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by
	the driver.
    * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY``
      - Setting this bit enables automatically capture the specified region
        with higher quality if possible.