vidioc-g-ext-ctrls.rst 14.4 KB
Newer Older
1 2
.. -*- coding: utf-8; mode: rst -*-

3
.. _VIDIOC_G_EXT_CTRLS:
4 5 6 7 8

******************************************************************
ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
******************************************************************

9
Name
10
====
11

12
VIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values
13

14 15

Synopsis
16 17
========

18
.. cpp:function:: int ioctl( int fd, int request, struct v4l2_ext_controls *argp )
19

20

21
Arguments
22 23 24 25 26 27 28 29 30 31 32 33
=========

``fd``
    File descriptor returned by :ref:`open() <func-open>`.

``request``
    VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,
    VIDIOC_TRY_EXT_CTRLS

``argp``


34
Description
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
===========

These ioctls allow the caller to get or set multiple controls
atomically. Control IDs are grouped into control classes (see
:ref:`ctrl-class`) and all controls in the control array must belong
to the same control class.

Applications must always fill in the ``count``, ``which``, ``controls``
and ``reserved`` fields of struct
:ref:`v4l2_ext_controls <v4l2-ext-controls>`, and initialize the
struct :ref:`v4l2_ext_control <v4l2-ext-control>` array pointed to
by the ``controls`` fields.

To get the current value of a set of controls applications initialize
the ``id``, ``size`` and ``reserved2`` fields of each struct
:ref:`v4l2_ext_control <v4l2-ext-control>` and call the
51
:ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. String controls controls must also set the
52 53 54 55 56
``string`` field. Controls of compound types
(``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set) must set the ``ptr`` field.

If the ``size`` is too small to receive the control result (only
relevant for pointer-type controls like strings), then the driver will
57
set ``size`` to a valid value and return an ``ENOSPC`` error code. You
58 59 60
should re-allocate the memory to this new size and try again. For the
string type it is possible that the same issue occurs again if the
string has grown in the meantime. It is recommended to call
61
:ref:`VIDIOC_QUERYCTRL` first and use
62 63 64 65 66 67
``maximum``\ +1 as the new ``size`` value. It is guaranteed that that is
sufficient memory.

N-dimensional arrays are set and retrieved row-by-row. You cannot set a
partial array, all elements have to be set or retrieved. The total size
is calculated as ``elems`` * ``elem_size``. These values can be obtained
68
by calling :ref:`VIDIOC_QUERY_EXT_CTRL <VIDIOC_QUERYCTRL>`.
69 70 71 72

To change the value of a set of controls applications initialize the
``id``, ``size``, ``reserved2`` and ``value/value64/string/ptr`` fields
of each struct :ref:`v4l2_ext_control <v4l2-ext-control>` and call
73
the :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. The controls will only be set if *all*
74 75 76 77 78 79
control values are valid.

To check if a set of controls have correct values applications
initialize the ``id``, ``size``, ``reserved2`` and
``value/value64/string/ptr`` fields of each struct
:ref:`v4l2_ext_control <v4l2-ext-control>` and call the
80
:ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctl. It is up to the driver whether wrong
81 82 83
values are automatically adjusted to a valid value or if an error is
returned.

84
When the ``id`` or ``which`` is invalid drivers return an ``EINVAL`` error
85
code. When the value is out of bounds drivers can choose to take the
86
closest valid value or return an ``ERANGE`` error code, whatever seems more
87 88 89
appropriate. In the first case the new value is set in struct
:ref:`v4l2_ext_control <v4l2-ext-control>`. If the new control value
is inappropriate (e.g. the given menu index is not supported by the menu
90
control), then this will also result in an ``EINVAL`` error code error.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

The driver will only set/get these controls if all control values are
correct. This prevents the situation where only some of the controls
were set/get. Only low-level errors (e. g. a failed i2c command) can
still cause this situation.


.. _v4l2-ext-control:

.. flat-table:: struct v4l2_ext_control
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 1 2


    -  .. row 1

       -  __u32

       -  ``id``

112
       -
113 114 115 116 117 118 119 120
       -  Identifies the control, set by the application.

    -  .. row 2

       -  __u32

       -  ``size``

121
       -
122
       -  The total size in bytes of the payload of this control. This is
123 124 125 126 127
	  normally 0, but for pointer controls this should be set to the
	  size of the memory containing the payload, or that will receive
	  the payload. If :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` finds that this value is
	  less than is required to store the payload result, then it is set
	  to a value large enough to store the payload result and ``ENOSPC`` is
128 129 130 131 132 133
	  returned.

	  .. note:: For string controls, this ``size`` field should
	     not be confused with the length of the string. This field refers
	     to the size of the memory that contains the string. The actual
	     *length* of the string may well be much smaller.
134 135 136 137 138

    -  .. row 3

       -  __u32

139
       -  ``reserved2``\ \[1\]
140

141
       -
142
       -  Reserved for future extensions. Drivers and applications must set
143
	  the array to zero.
144 145 146 147 148 149 150 151 152

    -  .. row 4

       -  union

       -  (anonymous)

    -  .. row 5

153
       -
154 155 156 157 158
       -  __s32

       -  ``value``

       -  New value or current value. Valid if this control is not of type
159 160
	  ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
	  not set.
161 162 163

    -  .. row 6

164
       -
165 166 167 168 169
       -  __s64

       -  ``value64``

       -  New value or current value. Valid if this control is of type
170 171
	  ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
	  not set.
172 173 174

    -  .. row 7

175
       -
176 177 178 179 180
       -  char *

       -  ``string``

       -  A pointer to a string. Valid if this control is of type
181
	  ``V4L2_CTRL_TYPE_STRING``.
182 183 184

    -  .. row 8

185
       -
186 187 188 189 190
       -  __u8 *

       -  ``p_u8``

       -  A pointer to a matrix control of unsigned 8-bit values. Valid if
191
	  this control is of type ``V4L2_CTRL_TYPE_U8``.
192 193 194

    -  .. row 9

195
       -
196 197 198 199 200
       -  __u16 *

       -  ``p_u16``

       -  A pointer to a matrix control of unsigned 16-bit values. Valid if
201
	  this control is of type ``V4L2_CTRL_TYPE_U16``.
202 203 204

    -  .. row 10

205
       -
206 207 208 209 210
       -  __u32 *

       -  ``p_u32``

       -  A pointer to a matrix control of unsigned 32-bit values. Valid if
211
	  this control is of type ``V4L2_CTRL_TYPE_U32``.
212 213 214

    -  .. row 11

215
       -
216 217 218 219 220
       -  void *

       -  ``ptr``

       -  A pointer to a compound type which can be an N-dimensional array
221 222 223
	  and/or a compound type (the control's type is >=
	  ``V4L2_CTRL_COMPOUND_TYPES``). Valid if
	  ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set for this control.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242



.. _v4l2-ext-controls:

.. flat-table:: struct v4l2_ext_controls
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2 1


    -  .. row 1

       -  union

       -  (anonymous)

    -  .. row 2

243
       -
244 245 246 247 248
       -  __u32

       -  ``ctrl_class``

       -  The control class to which all controls belong, see
249 250 251 252 253 254
	  :ref:`ctrl-class`. Drivers that use a kernel framework for
	  handling controls will also accept a value of 0 here, meaning that
	  the controls can belong to any control class. Whether drivers
	  support this can be tested by setting ``ctrl_class`` to 0 and
	  calling :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` with a ``count`` of 0. If that
	  succeeds, then the driver supports this feature.
255 256 257

    -  .. row 3

258
       -
259 260 261 262 263
       -  __u32

       -  ``which``

       -  Which value of the control to get/set/try.
264 265
	  ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the
	  control and ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default
266 267 268 269
	  value of the control.

	  .. note:: You can only get the default value of the control,
	     you cannot set or try it.
270 271 272 273 274 275 276 277 278 279

	  For backwards compatibility you can also use a control class here
	  (see :ref:`ctrl-class`). In that case all controls have to
	  belong to that control class. This usage is deprecated, instead
	  just use ``V4L2_CTRL_WHICH_CUR_VAL``. There are some very old
	  drivers that do not yet support ``V4L2_CTRL_WHICH_CUR_VAL`` and
	  that require a control class here. You can test for such drivers
	  by setting ctrl_class to ``V4L2_CTRL_WHICH_CUR_VAL`` and calling
	  VIDIOC_TRY_EXT_CTRLS with a count of 0. If that fails, then the
	  driver does not support ``V4L2_CTRL_WHICH_CUR_VAL``.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295

    -  .. row 4

       -  __u32

       -  ``count``

       -  The number of controls in the controls array. May also be zero.

    -  .. row 5

       -  __u32

       -  ``error_idx``

       -  Set by the driver in case of an error. If the error is associated
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
	  with a particular control, then ``error_idx`` is set to the index
	  of that control. If the error is not related to a specific
	  control, or the validation step failed (see below), then
	  ``error_idx`` is set to ``count``. The value is undefined if the
	  ioctl returned 0 (success).

	  Before controls are read from/written to hardware a validation
	  step takes place: this checks if all controls in the list are
	  valid controls, if no attempt is made to write to a read-only
	  control or read from a write-only control, and any other up-front
	  checks that can be done without accessing the hardware. The exact
	  validations done during this step are driver dependent since some
	  checks might require hardware access for some devices, thus making
	  it impossible to do those checks up-front. However, drivers should
	  make a best-effort to do as many up-front checks as possible.

	  This check is done to avoid leaving the hardware in an
	  inconsistent state due to easy-to-avoid problems. But it leads to
	  another problem: the application needs to know whether an error
	  came from the validation step (meaning that the hardware was not
	  touched) or from an error during the actual reading from/writing
	  to hardware.

	  The, in hindsight quite poor, solution for that is to set
	  ``error_idx`` to ``count`` if the validation failed. This has the
	  unfortunate side-effect that it is not possible to see which
	  control failed the validation. If the validation was successful
	  and the error happened while accessing the hardware, then
	  ``error_idx`` is less than ``count`` and only the controls up to
	  ``error_idx-1`` were read or written correctly, and the state of
	  the remaining controls is undefined.

	  Since :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` does not access hardware there is
	  also no need to handle the validation step in this special way, so
	  ``error_idx`` will just be set to the control that failed the
	  validation step instead of to ``count``. This means that if
	  :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` fails with ``error_idx`` set to ``count``,
	  then you can call :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` to try to discover the
	  actual control that failed the validation step. Unfortunately,
	  there is no ``TRY`` equivalent for :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>`.
336 337 338 339 340

    -  .. row 6

       -  __u32

341
       -  ``reserved``\ \[2\]
342 343

       -  Reserved for future extensions. Drivers and applications must set
344
	  the array to zero.
345 346 347 348 349 350 351 352

    -  .. row 7

       -  struct :ref:`v4l2_ext_control <v4l2-ext-control>` *

       -  ``controls``

       -  Pointer to an array of ``count`` v4l2_ext_control structures.
353
	  Ignored if ``count`` equals zero.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371



.. _ctrl-class:

.. flat-table:: Control classes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_CTRL_CLASS_USER``

       -  0x980000

       -  The class containing user controls. These controls are described
372 373 374 375
	  in :ref:`control`. All controls that can be set using the
	  :ref:`VIDIOC_S_CTRL <VIDIOC_G_CTRL>` and
	  :ref:`VIDIOC_G_CTRL <VIDIOC_G_CTRL>` ioctl belong to this
	  class.
376 377 378 379 380 381 382 383

    -  .. row 2

       -  ``V4L2_CTRL_CLASS_MPEG``

       -  0x990000

       -  The class containing MPEG compression controls. These controls are
384
	  described in :ref:`mpeg-controls`.
385 386 387 388 389 390 391 392

    -  .. row 3

       -  ``V4L2_CTRL_CLASS_CAMERA``

       -  0x9a0000

       -  The class containing camera controls. These controls are described
393
	  in :ref:`camera-controls`.
394 395 396 397 398 399 400 401

    -  .. row 4

       -  ``V4L2_CTRL_CLASS_FM_TX``

       -  0x9b0000

       -  The class containing FM Transmitter (FM TX) controls. These
402
	  controls are described in :ref:`fm-tx-controls`.
403 404 405 406 407 408 409 410

    -  .. row 5

       -  ``V4L2_CTRL_CLASS_FLASH``

       -  0x9c0000

       -  The class containing flash device controls. These controls are
411
	  described in :ref:`flash-controls`.
412 413 414 415 416 417 418 419

    -  .. row 6

       -  ``V4L2_CTRL_CLASS_JPEG``

       -  0x9d0000

       -  The class containing JPEG compression controls. These controls are
420
	  described in :ref:`jpeg-controls`.
421 422 423 424 425 426 427 428

    -  .. row 7

       -  ``V4L2_CTRL_CLASS_IMAGE_SOURCE``

       -  0x9e0000

       -  The class containing image source controls. These controls are
429
	  described in :ref:`image-source-controls`.
430 431 432 433 434 435 436 437

    -  .. row 8

       -  ``V4L2_CTRL_CLASS_IMAGE_PROC``

       -  0x9f0000

       -  The class containing image processing controls. These controls are
438
	  described in :ref:`image-process-controls`.
439 440 441 442 443 444 445 446

    -  .. row 9

       -  ``V4L2_CTRL_CLASS_FM_RX``

       -  0xa10000

       -  The class containing FM Receiver (FM RX) controls. These controls
447
	  are described in :ref:`fm-rx-controls`.
448 449 450 451 452 453 454 455

    -  .. row 10

       -  ``V4L2_CTRL_CLASS_RF_TUNER``

       -  0xa20000

       -  The class containing RF tuner controls. These controls are
456
	  described in :ref:`rf-tuner-controls`.
457 458


459
Return Value
460 461 462 463 464 465 466 467 468 469 470 471 472
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.

EINVAL
    The struct :ref:`v4l2_ext_control <v4l2-ext-control>` ``id`` is
    invalid, the struct :ref:`v4l2_ext_controls <v4l2-ext-controls>`
    ``which`` is invalid, or the struct
    :ref:`v4l2_ext_control <v4l2-ext-control>` ``value`` was
    inappropriate (e.g. the given menu index is not supported by the
    driver). This error code is also returned by the
473
    :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` and :ref:`VIDIOC_TRY_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` ioctls if two or
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
    more control values are in conflict.

ERANGE
    The struct :ref:`v4l2_ext_control <v4l2-ext-control>` ``value``
    is out of bounds.

EBUSY
    The control is temporarily not changeable, possibly because another
    applications took over control of the device function this control
    belongs to.

ENOSPC
    The space reserved for the control's payload is insufficient. The
    field ``size`` is set to a value that is enough to store the payload
    and this error code is returned.

EACCES
    Attempt to try or set a read-only control or to get a write-only
    control.