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/media/uapi/fdl-appendix.rst.
8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
10 .. _VIDIOC_G_EXT_CTRLS:
12 ******************************************************************
13 ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
14 ******************************************************************
19 VIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values
25 .. c:function:: int ioctl( int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp )
26 :name: VIDIOC_G_EXT_CTRLS
29 .. c:function:: int ioctl( int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp )
30 :name: VIDIOC_S_EXT_CTRLS
33 .. c:function:: int ioctl( int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp )
34 :name: VIDIOC_TRY_EXT_CTRLS
41 File descriptor returned by :ref:`open() <func-open>`.
44 Pointer to struct :c:type:`v4l2_ext_controls`.
50 These ioctls allow the caller to get or set multiple controls
51 atomically. Control IDs are grouped into control classes (see
52 :ref:`ctrl-class`) and all controls in the control array must belong
53 to the same control class.
55 Applications must always fill in the ``count``, ``which``, ``controls``
56 and ``reserved`` fields of struct
57 :c:type:`v4l2_ext_controls`, and initialize the
58 struct :c:type:`v4l2_ext_control` array pointed to
59 by the ``controls`` fields.
61 To get the current value of a set of controls applications initialize
62 the ``id``, ``size`` and ``reserved2`` fields of each struct
63 :c:type:`v4l2_ext_control` and call the
64 :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. String controls controls must also set the
65 ``string`` field. Controls of compound types
66 (``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set) must set the ``ptr`` field.
68 If the ``size`` is too small to receive the control result (only
69 relevant for pointer-type controls like strings), then the driver will
70 set ``size`` to a valid value and return an ``ENOSPC`` error code. You
71 should re-allocate the memory to this new size and try again. For the
72 string type it is possible that the same issue occurs again if the
73 string has grown in the meantime. It is recommended to call
74 :ref:`VIDIOC_QUERYCTRL` first and use
75 ``maximum``\ +1 as the new ``size`` value. It is guaranteed that that is
78 N-dimensional arrays are set and retrieved row-by-row. You cannot set a
79 partial array, all elements have to be set or retrieved. The total size
80 is calculated as ``elems`` * ``elem_size``. These values can be obtained
81 by calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`.
83 To change the value of a set of controls applications initialize the
84 ``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields
85 of each struct :c:type:`v4l2_ext_control` and call
86 the :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all*
87 control values are valid.
89 To check if a set of controls have correct values applications
90 initialize the ``id``, ``size``, ``reserved2`` and
91 ``value/value64/string/ptr`` fields of each struct
92 :c:type:`v4l2_ext_control` and call the
93 :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. It is up to the driver whether wrong
94 values are automatically adjusted to a valid value or if an error is
97 When the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error
98 code. When the value is out of bounds drivers can choose to take the
99 closest valid value or return an ``ERANGE`` error code, whatever seems more
100 appropriate. In the first case the new value is set in struct
101 :c:type:`v4l2_ext_control`. If the new control value
102 is inappropriate (e.g. the given menu index is not supported by the menu
103 control), then this will also result in an ``EINVAL`` error code error.
105 If ``request_fd`` is set to a not-yet-queued :ref:`request <media-request-api>`
106 file descriptor and ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``,
107 then the controls are not applied immediately when calling
108 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, but instead are applied by
109 the driver for the buffer associated with the same request.
110 If the device does not support requests, then ``EACCES`` will be returned.
111 If requests are supported but an invalid request file descriptor is given,
112 then ``EINVAL`` will be returned.
114 An attempt to call :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` for a
115 request that has already been queued will result in an ``EBUSY`` error.
117 If ``request_fd`` is specified and ``which`` is set to
118 ``V4L2_CTRL_WHICH_REQUEST_VAL`` during a call to
119 :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then it will return the
120 values of the controls at the time of request completion.
121 If the request is not yet completed, then this will result in an
124 The driver will only set/get these controls if all control values are
125 correct. This prevents the situation where only some of the controls
126 were set/get. Only low-level errors (e. g. a failed i2c command) can
127 still cause this situation.
130 .. tabularcolumns:: |p{1.2cm}|p{3.0cm}|p{1.5cm}|p{11.8cm}|
132 .. c:type:: v4l2_ext_control
134 .. cssclass: longtable
136 .. flat-table:: struct v4l2_ext_control
144 - Identifies the control, set by the application.
148 - The total size in bytes of the payload of this control. This is
149 normally 0, but for pointer controls this should be set to the
150 size of the memory containing the payload, or that will receive
151 the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is
152 less than is required to store the payload result, then it is set
153 to a value large enough to store the payload result and ``ENOSPC`` is
158 For string controls, this ``size`` field should
159 not be confused with the length of the string. This field refers
160 to the size of the memory that contains the string. The actual
161 *length* of the string may well be much smaller.
165 - Reserved for future extensions. Drivers and applications must set
172 - New value or current value. Valid if this control is not of type
173 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
178 - New value or current value. Valid if this control is of type
179 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
184 - A pointer to a string. Valid if this control is of type
185 ``V4L2_CTRL_TYPE_STRING``.
189 - A pointer to a matrix control of unsigned 8-bit values. Valid if
190 this control is of type ``V4L2_CTRL_TYPE_U8``.
194 - A pointer to a matrix control of unsigned 16-bit values. Valid if
195 this control is of type ``V4L2_CTRL_TYPE_U16``.
199 - A pointer to a matrix control of unsigned 32-bit values. Valid if
200 this control is of type ``V4L2_CTRL_TYPE_U32``.
202 - :c:type:`v4l2_area` *
204 - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
205 of type ``V4L2_CTRL_TYPE_AREA``.
209 - A pointer to a compound type which can be an N-dimensional array
210 and/or a compound type (the control's type is >=
211 ``V4L2_CTRL_COMPOUND_TYPES``). Valid if
212 ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control.
215 .. tabularcolumns:: |p{4.0cm}|p{2.2cm}|p{2.1cm}|p{8.2cm}|
217 .. c:type:: v4l2_ext_controls
219 .. cssclass:: longtable
221 .. flat-table:: struct v4l2_ext_controls
231 - The control class to which all controls belong, see
232 :ref:`ctrl-class`. Drivers that use a kernel framework for
233 handling controls will also accept a value of 0 here, meaning that
234 the controls can belong to any control class. Whether drivers
235 support this can be tested by setting ``ctrl_class`` to 0 and
236 calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that
237 succeeds, then the driver supports this feature.
241 - Which value of the control to get/set/try.
242 ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the
243 control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
244 value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that
245 these controls have to be retrieved from a request or tried/set for
246 a request. In the latter case the ``request_fd`` field contains the
247 file descriptor of the request that should be used. If the device
248 does not support requests, then ``EACCES`` will be returned.
252 When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only
253 get the default value of the control, you cannot set or try it.
255 For backwards compatibility you can also use a control class here
256 (see :ref:`ctrl-class`). In that case all controls have to
257 belong to that control class. This usage is deprecated, instead
258 just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old
259 drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and
260 that require a control class here. You can test for such drivers
261 by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling
262 VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the
263 driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``.
266 - The number of controls in the controls array. May also be zero.
269 - Set by the driver in case of an error. If the error is associated
270 with a particular control, then ``error_idx`` is set to the index
271 of that control. If the error is not related to a specific
272 control, or the validation step failed (see below), then
273 ``error_idx`` is set to ``count``. The value is undefined if the
274 ioctl returned 0 (success).
276 Before controls are read from/written to hardware a validation
277 step takes place: this checks if all controls in the list are
278 valid controls, if no attempt is made to write to a read-only
279 control or read from a write-only control, and any other up-front
280 checks that can be done without accessing the hardware. The exact
281 validations done during this step are driver dependent since some
282 checks might require hardware access for some devices, thus making
283 it impossible to do those checks up-front. However, drivers should
284 make a best-effort to do as many up-front checks as possible.
286 This check is done to avoid leaving the hardware in an
287 inconsistent state due to easy-to-avoid problems. But it leads to
288 another problem: the application needs to know whether an error
289 came from the validation step (meaning that the hardware was not
290 touched) or from an error during the actual reading from/writing
293 The, in hindsight quite poor, solution for that is to set
294 ``error_idx`` to ``count`` if the validation failed. This has the
295 unfortunate side-effect that it is not possible to see which
296 control failed the validation. If the validation was successful
297 and the error happened while accessing the hardware, then
298 ``error_idx`` is less than ``count`` and only the controls up to
299 ``error_idx-1`` were read or written correctly, and the state of
300 the remaining controls is undefined.
302 Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is
303 also no need to handle the validation step in this special way, so
304 ``error_idx`` will just be set to the control that failed the
305 validation step instead of to ``count``. This means that if
306 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``,
307 then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the
308 actual control that failed the validation step. Unfortunately,
309 there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`.
312 - File descriptor of the request to be used by this operation. Only
313 valid if ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``.
314 If the device does not support requests, then ``EACCES`` will be returned.
315 If requests are supported but an invalid request file descriptor is
316 given, then ``EINVAL`` will be returned.
319 - Reserved for future extensions.
321 Drivers and applications must set the array to zero.
322 * - struct :c:type:`v4l2_ext_control` *
324 - Pointer to an array of ``count`` v4l2_ext_control structures.
326 Ignored if ``count`` equals zero.
329 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
333 .. flat-table:: Control classes
338 * - ``V4L2_CTRL_CLASS_USER``
340 - The class containing user controls. These controls are described
341 in :ref:`control`. All controls that can be set using the
342 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and
343 :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this
345 * - ``V4L2_CTRL_CLASS_MPEG``
347 - The class containing MPEG compression controls. These controls are
348 described in :ref:`mpeg-controls`.
349 * - ``V4L2_CTRL_CLASS_CAMERA``
351 - The class containing camera controls. These controls are described
352 in :ref:`camera-controls`.
353 * - ``V4L2_CTRL_CLASS_FM_TX``
355 - The class containing FM Transmitter (FM TX) controls. These
356 controls are described in :ref:`fm-tx-controls`.
357 * - ``V4L2_CTRL_CLASS_FLASH``
359 - The class containing flash device controls. These controls are
360 described in :ref:`flash-controls`.
361 * - ``V4L2_CTRL_CLASS_JPEG``
363 - The class containing JPEG compression controls. These controls are
364 described in :ref:`jpeg-controls`.
365 * - ``V4L2_CTRL_CLASS_IMAGE_SOURCE``
367 - The class containing image source controls. These controls are
368 described in :ref:`image-source-controls`.
369 * - ``V4L2_CTRL_CLASS_IMAGE_PROC``
371 - The class containing image processing controls. These controls are
372 described in :ref:`image-process-controls`.
373 * - ``V4L2_CTRL_CLASS_FM_RX``
375 - The class containing FM Receiver (FM RX) controls. These controls
376 are described in :ref:`fm-rx-controls`.
377 * - ``V4L2_CTRL_CLASS_RF_TUNER``
379 - The class containing RF tuner controls. These controls are
380 described in :ref:`rf-tuner-controls`.
386 On success 0 is returned, on error -1 and the ``errno`` variable is set
387 appropriately. The generic error codes are described at the
388 :ref:`Generic Error Codes <gen-errors>` chapter.
391 The struct :c:type:`v4l2_ext_control` ``id`` is
392 invalid, or the struct :c:type:`v4l2_ext_controls`
393 ``which`` is invalid, or the struct
394 :c:type:`v4l2_ext_control` ``value`` was
395 inappropriate (e.g. the given menu index is not supported by the
396 driver), or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL``
397 but the given ``request_fd`` was invalid or ``V4L2_CTRL_WHICH_REQUEST_VAL``
398 is not supported by the kernel.
399 This error code is also returned by the
400 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or
401 more control values are in conflict.
404 The struct :c:type:`v4l2_ext_control` ``value``
408 The control is temporarily not changeable, possibly because another
409 applications took over control of the device function this control
410 belongs to, or (if the ``which`` field was set to
411 ``V4L2_CTRL_WHICH_REQUEST_VAL``) the request was queued but not yet
415 The space reserved for the control's payload is insufficient. The
416 field ``size`` is set to a value that is enough to store the payload
417 and this error code is returned.
420 Attempt to try or set a read-only control, or to get a write-only
421 control, or to get a control from a request that has not yet been
424 Or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` but the
425 device does not support requests.