1 .. -*- coding: utf-8; mode: rst -*-
3 .. _VIDIOC_G_EXT_CTRLS:
5 ******************************************************************
6 ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
7 ******************************************************************
12 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:function:: int ioctl( int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp )
19 :name: VIDIOC_G_EXT_CTRLS
22 .. c:function:: int ioctl( int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp )
23 :name: VIDIOC_S_EXT_CTRLS
26 .. c:function:: int ioctl( int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp )
27 :name: VIDIOC_TRY_EXT_CTRLS
34 File descriptor returned by :ref:`open() <func-open>`.
37 Pointer to struct :c:type:`v4l2_ext_controls`.
43 These ioctls allow the caller to get or set multiple controls
44 atomically. Control IDs are grouped into control classes (see
45 :ref:`ctrl-class`) and all controls in the control array must belong
46 to the same control class.
48 Applications must always fill in the ``count``, ``which``, ``controls``
49 and ``reserved`` fields of struct
50 :c:type:`v4l2_ext_controls`, and initialize the
51 struct :c:type:`v4l2_ext_control` array pointed to
52 by the ``controls`` fields.
54 To get the current value of a set of controls applications initialize
55 the ``id``, ``size`` and ``reserved2`` fields of each struct
56 :c:type:`v4l2_ext_control` and call the
57 :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. String controls controls must also set the
58 ``string`` field. Controls of compound types
59 (``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set) must set the ``ptr`` field.
61 If the ``size`` is too small to receive the control result (only
62 relevant for pointer-type controls like strings), then the driver will
63 set ``size`` to a valid value and return an ``ENOSPC`` error code. You
64 should re-allocate the memory to this new size and try again. For the
65 string type it is possible that the same issue occurs again if the
66 string has grown in the meantime. It is recommended to call
67 :ref:`VIDIOC_QUERYCTRL` first and use
68 ``maximum``\ +1 as the new ``size`` value. It is guaranteed that that is
71 N-dimensional arrays are set and retrieved row-by-row. You cannot set a
72 partial array, all elements have to be set or retrieved. The total size
73 is calculated as ``elems`` * ``elem_size``. These values can be obtained
74 by calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`.
76 To change the value of a set of controls applications initialize the
77 ``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields
78 of each struct :c:type:`v4l2_ext_control` and call
79 the :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all*
80 control values are valid.
82 To check if a set of controls have correct values applications
83 initialize the ``id``, ``size``, ``reserved2`` and
84 ``value/value64/string/ptr`` fields of each struct
85 :c:type:`v4l2_ext_control` and call the
86 :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. It is up to the driver whether wrong
87 values are automatically adjusted to a valid value or if an error is
90 When the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error
91 code. When the value is out of bounds drivers can choose to take the
92 closest valid value or return an ``ERANGE`` error code, whatever seems more
93 appropriate. In the first case the new value is set in struct
94 :c:type:`v4l2_ext_control`. If the new control value
95 is inappropriate (e.g. the given menu index is not supported by the menu
96 control), then this will also result in an ``EINVAL`` error code error.
98 The driver will only set/get these controls if all control values are
99 correct. This prevents the situation where only some of the controls
100 were set/get. Only low-level errors (e. g. a failed i2c command) can
101 still cause this situation.
104 .. tabularcolumns:: |p{1.2cm}|p{3.0cm}|p{1.5cm}|p{11.8cm}|
106 .. c:type:: v4l2_ext_control
108 .. cssclass: longtable
110 .. flat-table:: struct v4l2_ext_control
118 - Identifies the control, set by the application.
122 - The total size in bytes of the payload of this control. This is
123 normally 0, but for pointer controls this should be set to the
124 size of the memory containing the payload, or that will receive
125 the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is
126 less than is required to store the payload result, then it is set
127 to a value large enough to store the payload result and ``ENOSPC`` is
132 For string controls, this ``size`` field should
133 not be confused with the length of the string. This field refers
134 to the size of the memory that contains the string. The actual
135 *length* of the string may well be much smaller.
139 - Reserved for future extensions. Drivers and applications must set
146 - New value or current value. Valid if this control is not of type
147 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
152 - New value or current value. Valid if this control is of type
153 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
158 - A pointer to a string. Valid if this control is of type
159 ``V4L2_CTRL_TYPE_STRING``.
163 - A pointer to a matrix control of unsigned 8-bit values. Valid if
164 this control is of type ``V4L2_CTRL_TYPE_U8``.
168 - A pointer to a matrix control of unsigned 16-bit values. Valid if
169 this control is of type ``V4L2_CTRL_TYPE_U16``.
173 - A pointer to a matrix control of unsigned 32-bit values. Valid if
174 this control is of type ``V4L2_CTRL_TYPE_U32``.
178 - A pointer to a compound type which can be an N-dimensional array
179 and/or a compound type (the control's type is >=
180 ``V4L2_CTRL_COMPOUND_TYPES``). Valid if
181 ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control.
184 .. tabularcolumns:: |p{4.0cm}|p{2.2cm}|p{2.1cm}|p{8.2cm}|
186 .. c:type:: v4l2_ext_controls
188 .. cssclass:: longtable
190 .. flat-table:: struct v4l2_ext_controls
200 - The control class to which all controls belong, see
201 :ref:`ctrl-class`. Drivers that use a kernel framework for
202 handling controls will also accept a value of 0 here, meaning that
203 the controls can belong to any control class. Whether drivers
204 support this can be tested by setting ``ctrl_class`` to 0 and
205 calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that
206 succeeds, then the driver supports this feature.
210 - Which value of the control to get/set/try.
211 ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the
212 control and ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
213 value of the control.
217 You can only get the default value of the control,
218 you cannot set or try it.
220 For backwards compatibility you can also use a control class here
221 (see :ref:`ctrl-class`). In that case all controls have to
222 belong to that control class. This usage is deprecated, instead
223 just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old
224 drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and
225 that require a control class here. You can test for such drivers
226 by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling
227 VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the
228 driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``.
231 - The number of controls in the controls array. May also be zero.
234 - Set by the driver in case of an error. If the error is associated
235 with a particular control, then ``error_idx`` is set to the index
236 of that control. If the error is not related to a specific
237 control, or the validation step failed (see below), then
238 ``error_idx`` is set to ``count``. The value is undefined if the
239 ioctl returned 0 (success).
241 Before controls are read from/written to hardware a validation
242 step takes place: this checks if all controls in the list are
243 valid controls, if no attempt is made to write to a read-only
244 control or read from a write-only control, and any other up-front
245 checks that can be done without accessing the hardware. The exact
246 validations done during this step are driver dependent since some
247 checks might require hardware access for some devices, thus making
248 it impossible to do those checks up-front. However, drivers should
249 make a best-effort to do as many up-front checks as possible.
251 This check is done to avoid leaving the hardware in an
252 inconsistent state due to easy-to-avoid problems. But it leads to
253 another problem: the application needs to know whether an error
254 came from the validation step (meaning that the hardware was not
255 touched) or from an error during the actual reading from/writing
258 The, in hindsight quite poor, solution for that is to set
259 ``error_idx`` to ``count`` if the validation failed. This has the
260 unfortunate side-effect that it is not possible to see which
261 control failed the validation. If the validation was successful
262 and the error happened while accessing the hardware, then
263 ``error_idx`` is less than ``count`` and only the controls up to
264 ``error_idx-1`` were read or written correctly, and the state of
265 the remaining controls is undefined.
267 Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is
268 also no need to handle the validation step in this special way, so
269 ``error_idx`` will just be set to the control that failed the
270 validation step instead of to ``count``. This means that if
271 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``,
272 then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the
273 actual control that failed the validation step. Unfortunately,
274 there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`.
277 - Reserved for future extensions.
279 Drivers and applications must set the array to zero.
280 * - struct :c:type:`v4l2_ext_control` *
282 - Pointer to an array of ``count`` v4l2_ext_control structures.
284 Ignored if ``count`` equals zero.
287 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
291 .. flat-table:: Control classes
296 * - ``V4L2_CTRL_CLASS_USER``
298 - The class containing user controls. These controls are described
299 in :ref:`control`. All controls that can be set using the
300 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and
301 :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this
303 * - ``V4L2_CTRL_CLASS_MPEG``
305 - The class containing MPEG compression controls. These controls are
306 described in :ref:`mpeg-controls`.
307 * - ``V4L2_CTRL_CLASS_CAMERA``
309 - The class containing camera controls. These controls are described
310 in :ref:`camera-controls`.
311 * - ``V4L2_CTRL_CLASS_FM_TX``
313 - The class containing FM Transmitter (FM TX) controls. These
314 controls are described in :ref:`fm-tx-controls`.
315 * - ``V4L2_CTRL_CLASS_FLASH``
317 - The class containing flash device controls. These controls are
318 described in :ref:`flash-controls`.
319 * - ``V4L2_CTRL_CLASS_JPEG``
321 - The class containing JPEG compression controls. These controls are
322 described in :ref:`jpeg-controls`.
323 * - ``V4L2_CTRL_CLASS_IMAGE_SOURCE``
325 - The class containing image source controls. These controls are
326 described in :ref:`image-source-controls`.
327 * - ``V4L2_CTRL_CLASS_IMAGE_PROC``
329 - The class containing image processing controls. These controls are
330 described in :ref:`image-process-controls`.
331 * - ``V4L2_CTRL_CLASS_FM_RX``
333 - The class containing FM Receiver (FM RX) controls. These controls
334 are described in :ref:`fm-rx-controls`.
335 * - ``V4L2_CTRL_CLASS_RF_TUNER``
337 - The class containing RF tuner controls. These controls are
338 described in :ref:`rf-tuner-controls`.
344 On success 0 is returned, on error -1 and the ``errno`` variable is set
345 appropriately. The generic error codes are described at the
346 :ref:`Generic Error Codes <gen-errors>` chapter.
349 The struct :c:type:`v4l2_ext_control` ``id`` is
350 invalid, the struct :c:type:`v4l2_ext_controls`
351 ``which`` is invalid, or the struct
352 :c:type:`v4l2_ext_control` ``value`` was
353 inappropriate (e.g. the given menu index is not supported by the
354 driver). This error code is also returned by the
355 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or
356 more control values are in conflict.
359 The struct :c:type:`v4l2_ext_control` ``value``
363 The control is temporarily not changeable, possibly because another
364 applications took over control of the device function this control
368 The space reserved for the control's payload is insufficient. The
369 field ``size`` is set to a value that is enough to store the payload
370 and this error code is returned.
373 Attempt to try or set a read-only control or to get a write-only