1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2 3.. _VIDIOC_G_EXT_CTRLS: 4 5****************************************************************** 6ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS 7****************************************************************** 8 9Name 10==== 11 12VIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values 13 14 15Synopsis 16======== 17 18.. c:function:: int ioctl( int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp ) 19 :name: VIDIOC_G_EXT_CTRLS 20 21 22.. c:function:: int ioctl( int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp ) 23 :name: VIDIOC_S_EXT_CTRLS 24 25 26.. c:function:: int ioctl( int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp ) 27 :name: VIDIOC_TRY_EXT_CTRLS 28 29 30Arguments 31========= 32 33``fd`` 34 File descriptor returned by :ref:`open() <func-open>`. 35 36``argp`` 37 Pointer to struct :c:type:`v4l2_ext_controls`. 38 39 40Description 41=========== 42 43These ioctls allow the caller to get or set multiple controls 44atomically. Control IDs are grouped into control classes (see 45:ref:`ctrl-class`) and all controls in the control array must belong 46to the same control class. 47 48Applications must always fill in the ``count``, ``which``, ``controls`` 49and ``reserved`` fields of struct 50:c:type:`v4l2_ext_controls`, and initialize the 51struct :c:type:`v4l2_ext_control` array pointed to 52by the ``controls`` fields. 53 54To get the current value of a set of controls applications initialize 55the ``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. 60 61If the ``size`` is too small to receive the control result (only 62relevant for pointer-type controls like strings), then the driver will 63set ``size`` to a valid value and return an ``ENOSPC`` error code. You 64should re-allocate the memory to this new size and try again. For the 65string type it is possible that the same issue occurs again if the 66string 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 69sufficient memory. 70 71N-dimensional arrays are set and retrieved row-by-row. You cannot set a 72partial array, all elements have to be set or retrieved. The total size 73is calculated as ``elems`` * ``elem_size``. These values can be obtained 74by calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`. 75 76To change the value of a set of controls applications initialize the 77``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields 78of each struct :c:type:`v4l2_ext_control` and call 79the :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all* 80control values are valid. 81 82To check if a set of controls have correct values applications 83initialize 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 87values are automatically adjusted to a valid value or if an error is 88returned. 89 90When the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error 91code. When the value is out of bounds drivers can choose to take the 92closest valid value or return an ``ERANGE`` error code, whatever seems more 93appropriate. In the first case the new value is set in struct 94:c:type:`v4l2_ext_control`. If the new control value 95is inappropriate (e.g. the given menu index is not supported by the menu 96control), then this will also result in an ``EINVAL`` error code error. 97 98If ``request_fd`` is set to a not-yet-queued :ref:`request <media-request-api>` 99file descriptor and ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``, 100then the controls are not applied immediately when calling 101:ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, but instead are applied by 102the driver for the buffer associated with the same request. 103If the device does not support requests, then ``EACCES`` will be returned. 104If requests are supported but an invalid request file descriptor is given, 105then ``EINVAL`` will be returned. 106 107An attempt to call :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` for a 108request that has already been queued will result in an ``EBUSY`` error. 109 110If ``request_fd`` is specified and ``which`` is set to 111``V4L2_CTRL_WHICH_REQUEST_VAL`` during a call to 112:ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`, then it will return the 113values of the controls at the time of request completion. 114If the request is not yet completed, then this will result in an 115``EACCES`` error. 116 117The driver will only set/get these controls if all control values are 118correct. This prevents the situation where only some of the controls 119were set/get. Only low-level errors (e. g. a failed i2c command) can 120still cause this situation. 121 122 123.. tabularcolumns:: |p{1.2cm}|p{3.0cm}|p{1.5cm}|p{11.8cm}| 124 125.. c:type:: v4l2_ext_control 126 127.. cssclass: longtable 128 129.. flat-table:: struct v4l2_ext_control 130 :header-rows: 0 131 :stub-columns: 0 132 :widths: 1 1 2 133 134 * - __u32 135 - ``id`` 136 - Identifies the control, set by the application. 137 * - __u32 138 - ``size`` 139 - The total size in bytes of the payload of this control. This is 140 normally 0, but for pointer controls this should be set to the 141 size of the memory containing the payload, or that will receive 142 the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is 143 less than is required to store the payload result, then it is set 144 to a value large enough to store the payload result and ``ENOSPC`` is 145 returned. 146 147 .. note:: 148 149 For string controls, this ``size`` field should 150 not be confused with the length of the string. This field refers 151 to the size of the memory that contains the string. The actual 152 *length* of the string may well be much smaller. 153 * - __u32 154 - ``reserved2``\ [1] 155 - Reserved for future extensions. Drivers and applications must set 156 the array to zero. 157 * - union { 158 - (anonymous) 159 * - __s32 160 - ``value`` 161 - New value or current value. Valid if this control is not of type 162 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is 163 not set. 164 * - __s64 165 - ``value64`` 166 - New value or current value. Valid if this control is of type 167 ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is 168 not set. 169 * - char * 170 - ``string`` 171 - A pointer to a string. Valid if this control is of type 172 ``V4L2_CTRL_TYPE_STRING``. 173 * - __u8 * 174 - ``p_u8`` 175 - A pointer to a matrix control of unsigned 8-bit values. Valid if 176 this control is of type ``V4L2_CTRL_TYPE_U8``. 177 * - __u16 * 178 - ``p_u16`` 179 - A pointer to a matrix control of unsigned 16-bit values. Valid if 180 this control is of type ``V4L2_CTRL_TYPE_U16``. 181 * - __u32 * 182 - ``p_u32`` 183 - A pointer to a matrix control of unsigned 32-bit values. Valid if 184 this control is of type ``V4L2_CTRL_TYPE_U32``. 185 * - :c:type:`v4l2_area` * 186 - ``p_area`` 187 - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is 188 of type ``V4L2_CTRL_TYPE_AREA``. 189 * - void * 190 - ``ptr`` 191 - A pointer to a compound type which can be an N-dimensional array 192 and/or a compound type (the control's type is >= 193 ``V4L2_CTRL_COMPOUND_TYPES``). Valid if 194 ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control. 195 * - } 196 - 197 198 199.. tabularcolumns:: |p{4.0cm}|p{2.2cm}|p{2.1cm}|p{8.2cm}| 200 201.. c:type:: v4l2_ext_controls 202 203.. cssclass:: longtable 204 205.. flat-table:: struct v4l2_ext_controls 206 :header-rows: 0 207 :stub-columns: 0 208 :widths: 1 1 2 209 210 * - union { 211 - (anonymous) 212 * - __u32 213 - ``ctrl_class`` 214 - The control class to which all controls belong, see 215 :ref:`ctrl-class`. Drivers that use a kernel framework for 216 handling controls will also accept a value of 0 here, meaning that 217 the controls can belong to any control class. Whether drivers 218 support this can be tested by setting ``ctrl_class`` to 0 and 219 calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that 220 succeeds, then the driver supports this feature. 221 * - __u32 222 - ``which`` 223 - Which value of the control to get/set/try. 224 ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the 225 control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default 226 value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that 227 these controls have to be retrieved from a request or tried/set for 228 a request. In the latter case the ``request_fd`` field contains the 229 file descriptor of the request that should be used. If the device 230 does not support requests, then ``EACCES`` will be returned. 231 232 .. note:: 233 234 When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only 235 get the default value of the control, you cannot set or try it. 236 237 For backwards compatibility you can also use a control class here 238 (see :ref:`ctrl-class`). In that case all controls have to 239 belong to that control class. This usage is deprecated, instead 240 just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old 241 drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and 242 that require a control class here. You can test for such drivers 243 by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling 244 VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the 245 driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``. 246 * - } 247 - 248 * - __u32 249 - ``count`` 250 - The number of controls in the controls array. May also be zero. 251 * - __u32 252 - ``error_idx`` 253 - Set by the driver in case of an error. If the error is associated 254 with a particular control, then ``error_idx`` is set to the index 255 of that control. If the error is not related to a specific 256 control, or the validation step failed (see below), then 257 ``error_idx`` is set to ``count``. The value is undefined if the 258 ioctl returned 0 (success). 259 260 Before controls are read from/written to hardware a validation 261 step takes place: this checks if all controls in the list are 262 valid controls, if no attempt is made to write to a read-only 263 control or read from a write-only control, and any other up-front 264 checks that can be done without accessing the hardware. The exact 265 validations done during this step are driver dependent since some 266 checks might require hardware access for some devices, thus making 267 it impossible to do those checks up-front. However, drivers should 268 make a best-effort to do as many up-front checks as possible. 269 270 This check is done to avoid leaving the hardware in an 271 inconsistent state due to easy-to-avoid problems. But it leads to 272 another problem: the application needs to know whether an error 273 came from the validation step (meaning that the hardware was not 274 touched) or from an error during the actual reading from/writing 275 to hardware. 276 277 The, in hindsight quite poor, solution for that is to set 278 ``error_idx`` to ``count`` if the validation failed. This has the 279 unfortunate side-effect that it is not possible to see which 280 control failed the validation. If the validation was successful 281 and the error happened while accessing the hardware, then 282 ``error_idx`` is less than ``count`` and only the controls up to 283 ``error_idx-1`` were read or written correctly, and the state of 284 the remaining controls is undefined. 285 286 Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is 287 also no need to handle the validation step in this special way, so 288 ``error_idx`` will just be set to the control that failed the 289 validation step instead of to ``count``. This means that if 290 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``, 291 then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the 292 actual control that failed the validation step. Unfortunately, 293 there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`. 294 * - __s32 295 - ``request_fd`` 296 - File descriptor of the request to be used by this operation. Only 297 valid if ``which`` is set to ``V4L2_CTRL_WHICH_REQUEST_VAL``. 298 If the device does not support requests, then ``EACCES`` will be returned. 299 If requests are supported but an invalid request file descriptor is 300 given, then ``EINVAL`` will be returned. 301 * - __u32 302 - ``reserved``\ [1] 303 - Reserved for future extensions. 304 305 Drivers and applications must set the array to zero. 306 * - struct :c:type:`v4l2_ext_control` * 307 - ``controls`` 308 - Pointer to an array of ``count`` v4l2_ext_control structures. 309 310 Ignored if ``count`` equals zero. 311 312 313.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}| 314 315.. _ctrl-class: 316 317.. flat-table:: Control classes 318 :header-rows: 0 319 :stub-columns: 0 320 :widths: 3 1 4 321 322 * - ``V4L2_CTRL_CLASS_USER`` 323 - 0x980000 324 - The class containing user controls. These controls are described 325 in :ref:`control`. All controls that can be set using the 326 :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and 327 :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this 328 class. 329 * - ``V4L2_CTRL_CLASS_MPEG`` 330 - 0x990000 331 - The class containing MPEG compression controls. These controls are 332 described in :ref:`mpeg-controls`. 333 * - ``V4L2_CTRL_CLASS_CAMERA`` 334 - 0x9a0000 335 - The class containing camera controls. These controls are described 336 in :ref:`camera-controls`. 337 * - ``V4L2_CTRL_CLASS_FM_TX`` 338 - 0x9b0000 339 - The class containing FM Transmitter (FM TX) controls. These 340 controls are described in :ref:`fm-tx-controls`. 341 * - ``V4L2_CTRL_CLASS_FLASH`` 342 - 0x9c0000 343 - The class containing flash device controls. These controls are 344 described in :ref:`flash-controls`. 345 * - ``V4L2_CTRL_CLASS_JPEG`` 346 - 0x9d0000 347 - The class containing JPEG compression controls. These controls are 348 described in :ref:`jpeg-controls`. 349 * - ``V4L2_CTRL_CLASS_IMAGE_SOURCE`` 350 - 0x9e0000 351 - The class containing image source controls. These controls are 352 described in :ref:`image-source-controls`. 353 * - ``V4L2_CTRL_CLASS_IMAGE_PROC`` 354 - 0x9f0000 355 - The class containing image processing controls. These controls are 356 described in :ref:`image-process-controls`. 357 * - ``V4L2_CTRL_CLASS_FM_RX`` 358 - 0xa10000 359 - The class containing FM Receiver (FM RX) controls. These controls 360 are described in :ref:`fm-rx-controls`. 361 * - ``V4L2_CTRL_CLASS_RF_TUNER`` 362 - 0xa20000 363 - The class containing RF tuner controls. These controls are 364 described in :ref:`rf-tuner-controls`. 365 366 367Return Value 368============ 369 370On success 0 is returned, on error -1 and the ``errno`` variable is set 371appropriately. The generic error codes are described at the 372:ref:`Generic Error Codes <gen-errors>` chapter. 373 374EINVAL 375 The struct :c:type:`v4l2_ext_control` ``id`` is 376 invalid, or the struct :c:type:`v4l2_ext_controls` 377 ``which`` is invalid, or the struct 378 :c:type:`v4l2_ext_control` ``value`` was 379 inappropriate (e.g. the given menu index is not supported by the 380 driver), or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` 381 but the given ``request_fd`` was invalid or ``V4L2_CTRL_WHICH_REQUEST_VAL`` 382 is not supported by the kernel. 383 This error code is also returned by the 384 :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or 385 more control values are in conflict. 386 387ERANGE 388 The struct :c:type:`v4l2_ext_control` ``value`` 389 is out of bounds. 390 391EBUSY 392 The control is temporarily not changeable, possibly because another 393 applications took over control of the device function this control 394 belongs to, or (if the ``which`` field was set to 395 ``V4L2_CTRL_WHICH_REQUEST_VAL``) the request was queued but not yet 396 completed. 397 398ENOSPC 399 The space reserved for the control's payload is insufficient. The 400 field ``size`` is set to a value that is enough to store the payload 401 and this error code is returned. 402 403EACCES 404 Attempt to try or set a read-only control, or to get a write-only 405 control, or to get a control from a request that has not yet been 406 completed. 407 408 Or the ``which`` field was set to ``V4L2_CTRL_WHICH_REQUEST_VAL`` but the 409 device does not support requests. 410