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