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