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