1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
4 .. _VIDIOC_G_EXT_CTRLS:
6 ******************************************************************
7 ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
8 ******************************************************************
13 VIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values
18 .. c:macro:: VIDIOC_G_EXT_CTRLS
20 ``int ioctl(int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp)``
22 .. c:macro:: VIDIOC_S_EXT_CTRLS
24 ``int ioctl(int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp)``
26 .. c:macro:: VIDIOC_TRY_EXT_CTRLS
28 ``int ioctl(int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp)``
34 File descriptor returned by :c:func:`open()`.
37 Pointer to struct :c:type:`v4l2_ext_controls`.
42 These ioctls allow the caller to get or set multiple controls
43 atomically. Control IDs are grouped into control classes (see
44 :ref:`ctrl-class`) and all controls in the control array must belong
45 to the same control class.
47 Applications must always fill in the ``count``, ``which``, ``controls``
48 and ``reserved`` fields of struct
49 :c:type:`v4l2_ext_controls`, and initialize the
50 struct :c:type:`v4l2_ext_control` array pointed to
51 by the ``controls`` fields.
53 To get the current value of a set of controls applications initialize
54 the ``id``, ``size`` and ``reserved2`` fields of each struct
55 :c:type:`v4l2_ext_control` and call the
56 :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. String controls must also set the
57 ``string`` field. Controls of compound types
58 (``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set) must set the ``ptr`` field.
60 If the ``size`` is too small to receive the control result (only
61 relevant for pointer-type controls like strings), then the driver will
62 set ``size`` to a valid value and return an ``ENOSPC`` error code. You
63 should re-allocate the memory to this new size and try again. For the
64 string type it is possible that the same issue occurs again if the
65 string has grown in the meantime. It is recommended to call
66 :ref:`VIDIOC_QUERYCTRL` first and use
67 ``maximum``\ +1 as the new ``size`` value. It is guaranteed that that is
70 N-dimensional arrays are set and retrieved row-by-row. You cannot set a
71 partial array, all elements have to be set or retrieved. The total size
72 is calculated as ``elems`` * ``elem_size``. These values can be obtained
73 by calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`.
75 To change the value of a set of controls applications initialize the
76 ``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields
77 of each struct :c:type:`v4l2_ext_control` and call
78 the :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all*
79 control values are valid.
81 To check if a set of controls have correct values applications
82 initialize the ``id``, ``size``, ``reserved2`` and
83 ``value/value64/string/ptr`` fields of each struct
84 :c:type:`v4l2_ext_control` and call the
85 :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. It is up to the driver whether wrong
86 values are automatically adjusted to a valid value or if an error is
89 When the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error
90 code. When the value is out of bounds drivers can choose to take the
91 closest valid value or return an ``ERANGE`` error code, whatever seems more
92 appropriate. In the first case the new value is set in struct
93 :c:type:`v4l2_ext_control`. If the new control value
94 is inappropriate (e.g. the given menu index is not supported by the menu
95 control), then this will also result in an ``EINVAL`` error code error.
97 If ``request_fd`` is set to a not-yet-queued :ref:`request <media-request-api>`
98 file descriptor and ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``,
99 then the controls are not applied immediately when calling
100 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, but instead are applied by
101 the driver for the buffer associated with the same request.
102 If the device does not support requests, then ``EACCES`` will be returned.
103 If requests are supported but an invalid request file descriptor is given,
104 then ``EINVAL`` will be returned.
106 An attempt to call :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` for a
107 request that has already been queued will result in an ``EBUSY`` error.
109 If ``request_fd`` is specified and ``which`` is set to
110 ``V4L2_CTRL_WHICH_REQUEST_VAL`` during a call to
111 :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then it will return the
112 values of the controls at the time of request completion.
113 If the request is not yet completed, then this will result in an
116 The driver will only set/get these controls if all control values are
117 correct. This prevents the situation where only some of the controls
118 were set/get. Only low-level errors (e. g. a failed i2c command) can
119 still cause this situation.
121 .. tabularcolumns:: |p{1.2cm}|p{3.0cm}|p{1.5cm}|p{11.8cm}|
123 .. c:type:: v4l2_ext_control
125 .. cssclass: longtable
127 .. flat-table:: struct v4l2_ext_control
134 - Identifies the control, set by the application.
137 - The total size in bytes of the payload of this control. This is
138 normally 0, but for pointer controls this should be set to the
139 size of the memory containing the payload, or that will receive
140 the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is
141 less than is required to store the payload result, then it is set
142 to a value large enough to store the payload result and ``ENOSPC`` is
147 For string controls, this ``size`` field should
148 not be confused with the length of the string. This field refers
149 to the size of the memory that contains the string. The actual
150 *length* of the string may well be much smaller.
153 - Reserved for future extensions. Drivers and applications must set
159 - New value or current value. Valid if this control is not of type
160 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
164 - New value or current value. Valid if this control is of type
165 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
169 - A pointer to a string. Valid if this control is of type
170 ``V4L2_CTRL_TYPE_STRING``.
173 - A pointer to a matrix control of unsigned 8-bit values. Valid if
174 this control is of type ``V4L2_CTRL_TYPE_U8``.
177 - A pointer to a matrix control of unsigned 16-bit values. Valid if
178 this control is of type ``V4L2_CTRL_TYPE_U16``.
181 - A pointer to a matrix control of unsigned 32-bit values. Valid if
182 this control is of type ``V4L2_CTRL_TYPE_U32``.
183 * - struct :c:type:`v4l2_area` *
185 - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
186 of type ``V4L2_CTRL_TYPE_AREA``.
187 * - struct :c:type:`v4l2_ctrl_h264_sps` *
189 - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is
190 of type ``V4L2_CTRL_TYPE_H264_SPS``.
191 * - struct :c:type:`v4l2_ctrl_h264_pps` *
193 - A pointer to a struct :c:type:`v4l2_ctrl_h264_pps`. Valid if this control is
194 of type ``V4L2_CTRL_TYPE_H264_PPS``.
195 * - struct :c:type:`v4l2_ctrl_h264_scaling_matrix` *
196 - ``p_h264_scaling_matrix``
197 - A pointer to a struct :c:type:`v4l2_ctrl_h264_scaling_matrix`. Valid if this control is
198 of type ``V4L2_CTRL_TYPE_H264_SCALING_MATRIX``.
199 * - struct :c:type:`v4l2_ctrl_h264_pred_weights` *
200 - ``p_h264_pred_weights``
201 - A pointer to a struct :c:type:`v4l2_ctrl_h264_pred_weights`. Valid if this control is
202 of type ``V4L2_CTRL_TYPE_H264_PRED_WEIGHTS``.
203 * - struct :c:type:`v4l2_ctrl_h264_slice_params` *
204 - ``p_h264_slice_params``
205 - A pointer to a struct :c:type:`v4l2_ctrl_h264_slice_params`. Valid if this control is
206 of type ``V4L2_CTRL_TYPE_H264_SLICE_PARAMS``.
207 * - struct :c:type:`v4l2_ctrl_h264_decode_params` *
208 - ``p_h264_decode_params``
209 - A pointer to a struct :c:type:`v4l2_ctrl_h264_decode_params`. Valid if this control is
210 of type ``V4L2_CTRL_TYPE_H264_DECODE_PARAMS``.
211 * - struct :c:type:`v4l2_ctrl_fwht_params` *
213 - A pointer to a struct :c:type:`v4l2_ctrl_fwht_params`. Valid if this control is
214 of type ``V4L2_CTRL_TYPE_FWHT_PARAMS``.
217 - A pointer to a compound type which can be an N-dimensional array
218 and/or a compound type (the control's type is >=
219 ``V4L2_CTRL_COMPOUND_TYPES``). Valid if
220 ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control.
224 .. tabularcolumns:: |p{4.0cm}|p{2.2cm}|p{2.1cm}|p{8.2cm}|
226 .. c:type:: v4l2_ext_controls
228 .. cssclass:: longtable
230 .. flat-table:: struct v4l2_ext_controls
239 - The control class to which all controls belong, see
240 :ref:`ctrl-class`. Drivers that use a kernel framework for
241 handling controls will also accept a value of 0 here, meaning that
242 the controls can belong to any control class. Whether drivers
243 support this can be tested by setting ``ctrl_class`` to 0 and
244 calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that
245 succeeds, then the driver supports this feature.
248 - Which value of the control to get/set/try.
249 ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the
250 control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
251 value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that
252 these controls have to be retrieved from a request or tried/set for
253 a request. In the latter case the ``request_fd`` field contains the
254 file descriptor of the request that should be used. If the device
255 does not support requests, then ``EACCES`` will be returned.
259 When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only
260 get the default value of the control, you cannot set or try it.
262 For backwards compatibility you can also use a control class here
263 (see :ref:`ctrl-class`). In that case all controls have to
264 belong to that control class. This usage is deprecated, instead
265 just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old
266 drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and
267 that require a control class here. You can test for such drivers
268 by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling
269 VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the
270 driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``.
275 - The number of controls in the controls array. May also be zero.
278 - Set by the driver in case of an error. If the error is associated
279 with a particular control, then ``error_idx`` is set to the index
280 of that control. If the error is not related to a specific
281 control, or the validation step failed (see below), then
282 ``error_idx`` is set to ``count``. The value is undefined if the
283 ioctl returned 0 (success).
285 Before controls are read from/written to hardware a validation
286 step takes place: this checks if all controls in the list are
287 valid controls, if no attempt is made to write to a read-only
288 control or read from a write-only control, and any other up-front
289 checks that can be done without accessing the hardware. The exact
290 validations done during this step are driver dependent since some
291 checks might require hardware access for some devices, thus making
292 it impossible to do those checks up-front. However, drivers should
293 make a best-effort to do as many up-front checks as possible.
295 This check is done to avoid leaving the hardware in an
296 inconsistent state due to easy-to-avoid problems. But it leads to
297 another problem: the application needs to know whether an error
298 came from the validation step (meaning that the hardware was not
299 touched) or from an error during the actual reading from/writing
302 The, in hindsight quite poor, solution for that is to set
303 ``error_idx`` to ``count`` if the validation failed. This has the
304 unfortunate side-effect that it is not possible to see which
305 control failed the validation. If the validation was successful
306 and the error happened while accessing the hardware, then
307 ``error_idx`` is less than ``count`` and only the controls up to
308 ``error_idx-1`` were read or written correctly, and the state of
309 the remaining controls is undefined.
311 Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is
312 also no need to handle the validation step in this special way, so
313 ``error_idx`` will just be set to the control that failed the
314 validation step instead of to ``count``. This means that if
315 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``,
316 then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the
317 actual control that failed the validation step. Unfortunately,
318 there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`.
321 - File descriptor of the request to be used by this operation. Only
322 valid if ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``.
323 If the device does not support requests, then ``EACCES`` will be returned.
324 If requests are supported but an invalid request file descriptor is
325 given, then ``EINVAL`` will be returned.
328 - Reserved for future extensions.
330 Drivers and applications must set the array to zero.
331 * - struct :c:type:`v4l2_ext_control` *
333 - Pointer to an array of ``count`` v4l2_ext_control structures.
335 Ignored if ``count`` equals zero.
337 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
341 .. flat-table:: Control classes
346 * - ``V4L2_CTRL_CLASS_USER``
348 - The class containing user controls. These controls are described
349 in :ref:`control`. All controls that can be set using the
350 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and
351 :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this
353 * - ``V4L2_CTRL_CLASS_CODEC``
355 - The class containing stateful codec controls. These controls are
356 described in :ref:`codec-controls`.
357 * - ``V4L2_CTRL_CLASS_CAMERA``
359 - The class containing camera controls. These controls are described
360 in :ref:`camera-controls`.
361 * - ``V4L2_CTRL_CLASS_FM_TX``
363 - The class containing FM Transmitter (FM TX) controls. These
364 controls are described in :ref:`fm-tx-controls`.
365 * - ``V4L2_CTRL_CLASS_FLASH``
367 - The class containing flash device controls. These controls are
368 described in :ref:`flash-controls`.
369 * - ``V4L2_CTRL_CLASS_JPEG``
371 - The class containing JPEG compression controls. These controls are
372 described in :ref:`jpeg-controls`.
373 * - ``V4L2_CTRL_CLASS_IMAGE_SOURCE``
375 - The class containing image source controls. These controls are
376 described in :ref:`image-source-controls`.
377 * - ``V4L2_CTRL_CLASS_IMAGE_PROC``
379 - The class containing image processing controls. These controls are
380 described in :ref:`image-process-controls`.
381 * - ``V4L2_CTRL_CLASS_FM_RX``
383 - The class containing FM Receiver (FM RX) controls. These controls
384 are described in :ref:`fm-rx-controls`.
385 * - ``V4L2_CTRL_CLASS_RF_TUNER``
387 - The class containing RF tuner controls. These controls are
388 described in :ref:`rf-tuner-controls`.
389 * - ``V4L2_CTRL_CLASS_DETECT``
391 - The class containing motion or object detection controls. These controls
392 are described in :ref:`detect-controls`.
393 * - ``V4L2_CTRL_CLASS_CODEC_STATELESS``
395 - The class containing stateless codec controls. These controls are
396 described in :ref:`codec-stateless-controls`.
401 On success 0 is returned, on error -1 and the ``errno`` variable is set
402 appropriately. The generic error codes are described at the
403 :ref:`Generic Error Codes <gen-errors>` chapter.
406 The struct :c:type:`v4l2_ext_control` ``id`` is
407 invalid, or the struct :c:type:`v4l2_ext_controls`
408 ``which`` is invalid, or the struct
409 :c:type:`v4l2_ext_control` ``value`` was
410 inappropriate (e.g. the given menu index is not supported by the
411 driver), or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL``
412 but the given ``request_fd`` was invalid or ``V4L2_CTRL_WHICH_REQUEST_VAL``
413 is not supported by the kernel.
414 This error code is also returned by the
415 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or
416 more control values are in conflict.
419 The struct :c:type:`v4l2_ext_control` ``value``
423 The control is temporarily not changeable, possibly because another
424 applications took over control of the device function this control
425 belongs to, or (if the ``which`` field was set to
426 ``V4L2_CTRL_WHICH_REQUEST_VAL``) the request was queued but not yet
430 The space reserved for the control's payload is insufficient. The
431 field ``size`` is set to a value that is enough to store the payload
432 and this error code is returned.
435 Attempt to try or set a read-only control, or to get a write-only
436 control, or to get a control from a request that has not yet been
439 Or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` but the
440 device does not support requests.