[media] docs-rst: add tabularcolumns to all tables
[cascardo/linux.git] / Documentation / media / uapi / v4l / vidioc-queryctrl.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _VIDIOC_QUERYCTRL:
4
5 *******************************************************************
6 ioctls VIDIOC_QUERYCTRL, VIDIOC_QUERY_EXT_CTRL and VIDIOC_QUERYMENU
7 *******************************************************************
8
9 Name
10 ====
11
12 VIDIOC_QUERYCTRL - VIDIOC_QUERY_EXT_CTRL - VIDIOC_QUERYMENU - Enumerate controls and menu control items
13
14
15 Synopsis
16 ========
17
18 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_queryctrl *argp )
19
20 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_query_ext_ctrl *argp )
21
22 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_querymenu *argp )
23
24
25 Arguments
26 =========
27
28 ``fd``
29     File descriptor returned by :ref:`open() <func-open>`.
30
31 ``request``
32     VIDIOC_QUERYCTRL, VIDIOC_QUERY_EXT_CTRL, VIDIOC_QUERYMENU
33
34 ``argp``
35
36
37 Description
38 ===========
39
40 To query the attributes of a control applications set the ``id`` field
41 of a struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` and call the
42 ``VIDIOC_QUERYCTRL`` ioctl with a pointer to this structure. The driver
43 fills the rest of the structure or returns an ``EINVAL`` error code when the
44 ``id`` is invalid.
45
46 It is possible to enumerate controls by calling ``VIDIOC_QUERYCTRL``
47 with successive ``id`` values starting from ``V4L2_CID_BASE`` up to and
48 exclusive ``V4L2_CID_LASTP1``. Drivers may return ``EINVAL`` if a control in
49 this range is not supported. Further applications can enumerate private
50 controls, which are not defined in this specification, by starting at
51 ``V4L2_CID_PRIVATE_BASE`` and incrementing ``id`` until the driver
52 returns ``EINVAL``.
53
54 In both cases, when the driver sets the ``V4L2_CTRL_FLAG_DISABLED`` flag
55 in the ``flags`` field this control is permanently disabled and should
56 be ignored by the application. [#f1]_
57
58 When the application ORs ``id`` with ``V4L2_CTRL_FLAG_NEXT_CTRL`` the
59 driver returns the next supported non-compound control, or ``EINVAL`` if
60 there is none. In addition, the ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` flag
61 can be specified to enumerate all compound controls (i.e. controls with
62 type ≥ ``V4L2_CTRL_COMPOUND_TYPES`` and/or array control, in other words
63 controls that contain more than one value). Specify both
64 ``V4L2_CTRL_FLAG_NEXT_CTRL`` and ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` in
65 order to enumerate all controls, compound or not. Drivers which do not
66 support these flags yet always return ``EINVAL``.
67
68 The ``VIDIOC_QUERY_EXT_CTRL`` ioctl was introduced in order to better
69 support controls that can use compound types, and to expose additional
70 control information that cannot be returned in struct
71 :ref:`v4l2_queryctrl <v4l2-queryctrl>` since that structure is full.
72
73 ``VIDIOC_QUERY_EXT_CTRL`` is used in the same way as
74 ``VIDIOC_QUERYCTRL``, except that the ``reserved`` array must be zeroed
75 as well.
76
77 Additional information is required for menu controls: the names of the
78 menu items. To query them applications set the ``id`` and ``index``
79 fields of struct :ref:`v4l2_querymenu <v4l2-querymenu>` and call the
80 ``VIDIOC_QUERYMENU`` ioctl with a pointer to this structure. The driver
81 fills the rest of the structure or returns an ``EINVAL`` error code when the
82 ``id`` or ``index`` is invalid. Menu items are enumerated by calling
83 ``VIDIOC_QUERYMENU`` with successive ``index`` values from struct
84 :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``minimum`` to ``maximum``,
85 inclusive.
86
87 .. note::
88
89    It is possible for ``VIDIOC_QUERYMENU`` to return
90    an ``EINVAL`` error code for some indices between ``minimum`` and
91    ``maximum``. In that case that particular menu item is not supported by
92    this driver. Also note that the ``minimum`` value is not necessarily 0.
93
94 See also the examples in :ref:`control`.
95
96
97 .. _v4l2-queryctrl:
98
99 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
100
101 .. flat-table:: struct v4l2_queryctrl
102     :header-rows:  0
103     :stub-columns: 0
104     :widths:       1 1 2
105
106
107     -  .. row 1
108
109        -  __u32
110
111        -  ``id``
112
113        -  Identifies the control, set by the application. See
114           :ref:`control-id` for predefined IDs. When the ID is ORed with
115           V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and
116           returns the first control with a higher ID. Drivers which do not
117           support this flag yet always return an ``EINVAL`` error code.
118
119     -  .. row 2
120
121        -  __u32
122
123        -  ``type``
124
125        -  Type of control, see :ref:`v4l2-ctrl-type`.
126
127     -  .. row 3
128
129        -  __u8
130
131        -  ``name``\ [32]
132
133        -  Name of the control, a NUL-terminated ASCII string. This
134           information is intended for the user.
135
136     -  .. row 4
137
138        -  __s32
139
140        -  ``minimum``
141
142        -  Minimum value, inclusive. This field gives a lower bound for the
143           control. See enum :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how
144           the minimum value is to be used for each possible control type.
145           Note that this a signed 32-bit value.
146
147     -  .. row 5
148
149        -  __s32
150
151        -  ``maximum``
152
153        -  Maximum value, inclusive. This field gives an upper bound for the
154           control. See enum :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how
155           the maximum value is to be used for each possible control type.
156           Note that this a signed 32-bit value.
157
158     -  .. row 6
159
160        -  __s32
161
162        -  ``step``
163
164        -  This field gives a step size for the control. See enum
165           :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how the step value is
166           to be used for each possible control type. Note that this an
167           unsigned 32-bit value.
168
169           Generally drivers should not scale hardware control values. It may
170           be necessary for example when the ``name`` or ``id`` imply a
171           particular unit and the hardware actually accepts only multiples
172           of said unit. If so, drivers must take care values are properly
173           rounded when scaling, such that errors will not accumulate on
174           repeated read-write cycles.
175
176           This field gives the smallest change of an integer control
177           actually affecting hardware. Often the information is needed when
178           the user can change controls by keyboard or GUI buttons, rather
179           than a slider. When for example a hardware register accepts values
180           0-511 and the driver reports 0-65535, step should be 128.
181
182           Note that although signed, the step value is supposed to be always
183           positive.
184
185     -  .. row 7
186
187        -  __s32
188
189        -  ``default_value``
190
191        -  The default value of a ``V4L2_CTRL_TYPE_INTEGER``, ``_BOOLEAN``,
192           ``_BITMASK``, ``_MENU`` or ``_INTEGER_MENU`` control. Not valid
193           for other types of controls.
194
195           .. note::
196
197              Drivers reset controls to their default value only when
198              the driver is first loaded, never afterwards.
199
200     -  .. row 8
201
202        -  __u32
203
204        -  ``flags``
205
206        -  Control flags, see :ref:`control-flags`.
207
208     -  .. row 9
209
210        -  __u32
211
212        -  ``reserved``\ [2]
213
214        -  Reserved for future extensions. Drivers must set the array to
215           zero.
216
217
218
219 .. _v4l2-query-ext-ctrl:
220
221 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
222
223 .. flat-table:: struct v4l2_query_ext_ctrl
224     :header-rows:  0
225     :stub-columns: 0
226     :widths:       1 1 2
227
228
229     -  .. row 1
230
231        -  __u32
232
233        -  ``id``
234
235        -  Identifies the control, set by the application. See
236           :ref:`control-id` for predefined IDs. When the ID is ORed with
237           ``V4L2_CTRL_FLAG_NEXT_CTRL`` the driver clears the flag and
238           returns the first non-compound control with a higher ID. When the
239           ID is ORed with ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` the driver clears
240           the flag and returns the first compound control with a higher ID.
241           Set both to get the first control (compound or not) with a higher
242           ID.
243
244     -  .. row 2
245
246        -  __u32
247
248        -  ``type``
249
250        -  Type of control, see :ref:`v4l2-ctrl-type`.
251
252     -  .. row 3
253
254        -  char
255
256        -  ``name``\ [32]
257
258        -  Name of the control, a NUL-terminated ASCII string. This
259           information is intended for the user.
260
261     -  .. row 4
262
263        -  __s64
264
265        -  ``minimum``
266
267        -  Minimum value, inclusive. This field gives a lower bound for the
268           control. See enum :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how
269           the minimum value is to be used for each possible control type.
270           Note that this a signed 64-bit value.
271
272     -  .. row 5
273
274        -  __s64
275
276        -  ``maximum``
277
278        -  Maximum value, inclusive. This field gives an upper bound for the
279           control. See enum :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how
280           the maximum value is to be used for each possible control type.
281           Note that this a signed 64-bit value.
282
283     -  .. row 6
284
285        -  __u64
286
287        -  ``step``
288
289        -  This field gives a step size for the control. See enum
290           :ref:`v4l2_ctrl_type <v4l2-ctrl-type>` how the step value is
291           to be used for each possible control type. Note that this an
292           unsigned 64-bit value.
293
294           Generally drivers should not scale hardware control values. It may
295           be necessary for example when the ``name`` or ``id`` imply a
296           particular unit and the hardware actually accepts only multiples
297           of said unit. If so, drivers must take care values are properly
298           rounded when scaling, such that errors will not accumulate on
299           repeated read-write cycles.
300
301           This field gives the smallest change of an integer control
302           actually affecting hardware. Often the information is needed when
303           the user can change controls by keyboard or GUI buttons, rather
304           than a slider. When for example a hardware register accepts values
305           0-511 and the driver reports 0-65535, step should be 128.
306
307     -  .. row 7
308
309        -  __s64
310
311        -  ``default_value``
312
313        -  The default value of a ``V4L2_CTRL_TYPE_INTEGER``, ``_INTEGER64``,
314           ``_BOOLEAN``, ``_BITMASK``, ``_MENU``, ``_INTEGER_MENU``, ``_U8``
315           or ``_U16`` control. Not valid for other types of controls.
316
317           .. note::
318
319              Drivers reset controls to their default value only when
320              the driver is first loaded, never afterwards.
321
322     -  .. row 8
323
324        -  __u32
325
326        -  ``flags``
327
328        -  Control flags, see :ref:`control-flags`.
329
330     -  .. row 9
331
332        -  __u32
333
334        -  ``elem_size``
335
336        -  The size in bytes of a single element of the array. Given a char
337           pointer ``p`` to a 3-dimensional array you can find the position
338           of cell ``(z, y, x)`` as follows:
339           ``p + ((z * dims[1] + y) * dims[0] + x) * elem_size``.
340           ``elem_size`` is always valid, also when the control isn't an
341           array. For string controls ``elem_size`` is equal to
342           ``maximum + 1``.
343
344     -  .. row 10
345
346        -  __u32
347
348        -  ``elems``
349
350        -  The number of elements in the N-dimensional array. If this control
351           is not an array, then ``elems`` is 1. The ``elems`` field can
352           never be 0.
353
354     -  .. row 11
355
356        -  __u32
357
358        -  ``nr_of_dims``
359
360        -  The number of dimension in the N-dimensional array. If this
361           control is not an array, then this field is 0.
362
363     -  .. row 12
364
365        -  __u32
366
367        -  ``dims[V4L2_CTRL_MAX_DIMS]``
368
369        -  The size of each dimension. The first ``nr_of_dims`` elements of
370           this array must be non-zero, all remaining elements must be zero.
371
372     -  .. row 13
373
374        -  __u32
375
376        -  ``reserved``\ [32]
377
378        -  Reserved for future extensions. Applications and drivers must set
379           the array to zero.
380
381
382
383 .. _v4l2-querymenu:
384
385 .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{7.0cm}|p{3.5cm}|
386
387 .. flat-table:: struct v4l2_querymenu
388     :header-rows:  0
389     :stub-columns: 0
390     :widths:       1 1 2 1
391
392
393     -  .. row 1
394
395        -  __u32
396
397        -
398        -  ``id``
399
400        -  Identifies the control, set by the application from the respective
401           struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``id``.
402
403     -  .. row 2
404
405        -  __u32
406
407        -
408        -  ``index``
409
410        -  Index of the menu item, starting at zero, set by the application.
411
412     -  .. row 3
413
414        -  union
415
416        -
417        -
418        -
419
420     -  .. row 4
421
422        -
423        -  __u8
424
425        -  ``name``\ [32]
426
427        -  Name of the menu item, a NUL-terminated ASCII string. This
428           information is intended for the user. This field is valid for
429           ``V4L2_CTRL_FLAG_MENU`` type controls.
430
431     -  .. row 5
432
433        -
434        -  __s64
435
436        -  ``value``
437
438        -  Value of the integer menu item. This field is valid for
439           ``V4L2_CTRL_FLAG_INTEGER_MENU`` type controls.
440
441     -  .. row 6
442
443        -  __u32
444
445        -
446        -  ``reserved``
447
448        -  Reserved for future extensions. Drivers must set the array to
449           zero.
450
451
452
453 .. _v4l2-ctrl-type:
454
455 .. tabularcolumns:: |p{5.3cm}|p{0.9cm}|p{0.9cm}|p{0.9cm}|p{9.5cm}|
456
457 .. flat-table:: enum v4l2_ctrl_type
458     :header-rows:  1
459     :stub-columns: 0
460     :widths:       30 5 5 5 55
461
462
463     -  .. row 1
464
465        -  Type
466
467        -  ``minimum``
468
469        -  ``step``
470
471        -  ``maximum``
472
473        -  Description
474
475     -  .. row 2
476
477        -  ``V4L2_CTRL_TYPE_INTEGER``
478
479        -  any
480
481        -  any
482
483        -  any
484
485        -  An integer-valued control ranging from minimum to maximum
486           inclusive. The step value indicates the increment between values.
487
488     -  .. row 3
489
490        -  ``V4L2_CTRL_TYPE_BOOLEAN``
491
492        -  0
493
494        -  1
495
496        -  1
497
498        -  A boolean-valued control. Zero corresponds to "disabled", and one
499           means "enabled".
500
501     -  .. row 4
502
503        -  ``V4L2_CTRL_TYPE_MENU``
504
505        -  ≥ 0
506
507        -  1
508
509        -  N-1
510
511        -  The control has a menu of N choices. The names of the menu items
512           can be enumerated with the ``VIDIOC_QUERYMENU`` ioctl.
513
514     -  .. row 5
515
516        -  ``V4L2_CTRL_TYPE_INTEGER_MENU``
517
518        -  ≥ 0
519
520        -  1
521
522        -  N-1
523
524        -  The control has a menu of N choices. The values of the menu items
525           can be enumerated with the ``VIDIOC_QUERYMENU`` ioctl. This is
526           similar to ``V4L2_CTRL_TYPE_MENU`` except that instead of strings,
527           the menu items are signed 64-bit integers.
528
529     -  .. row 6
530
531        -  ``V4L2_CTRL_TYPE_BITMASK``
532
533        -  0
534
535        -  n/a
536
537        -  any
538
539        -  A bitmask field. The maximum value is the set of bits that can be
540           used, all other bits are to be 0. The maximum value is interpreted
541           as a __u32, allowing the use of bit 31 in the bitmask.
542
543     -  .. row 7
544
545        -  ``V4L2_CTRL_TYPE_BUTTON``
546
547        -  0
548
549        -  0
550
551        -  0
552
553        -  A control which performs an action when set. Drivers must ignore
554           the value passed with ``VIDIOC_S_CTRL`` and return an ``EINVAL`` error
555           code on a ``VIDIOC_G_CTRL`` attempt.
556
557     -  .. row 8
558
559        -  ``V4L2_CTRL_TYPE_INTEGER64``
560
561        -  any
562
563        -  any
564
565        -  any
566
567        -  A 64-bit integer valued control. Minimum, maximum and step size
568           cannot be queried using ``VIDIOC_QUERYCTRL``. Only
569           ``VIDIOC_QUERY_EXT_CTRL`` can retrieve the 64-bit min/max/step
570           values, they should be interpreted as n/a when using
571           ``VIDIOC_QUERYCTRL``.
572
573     -  .. row 9
574
575        -  ``V4L2_CTRL_TYPE_STRING``
576
577        -  ≥ 0
578
579        -  ≥ 1
580
581        -  ≥ 0
582
583        -  The minimum and maximum string lengths. The step size means that
584           the string must be (minimum + N * step) characters long for N ≥ 0.
585           These lengths do not include the terminating zero, so in order to
586           pass a string of length 8 to
587           :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` you need to
588           set the ``size`` field of struct
589           :ref:`v4l2_ext_control <v4l2-ext-control>` to 9. For
590           :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` you can set
591           the ``size`` field to ``maximum`` + 1. Which character encoding is
592           used will depend on the string control itself and should be part
593           of the control documentation.
594
595     -  .. row 10
596
597        -  ``V4L2_CTRL_TYPE_CTRL_CLASS``
598
599        -  n/a
600
601        -  n/a
602
603        -  n/a
604
605        -  This is not a control. When ``VIDIOC_QUERYCTRL`` is called with a
606           control ID equal to a control class code (see :ref:`ctrl-class`)
607           + 1, the ioctl returns the name of the control class and this
608           control type. Older drivers which do not support this feature
609           return an ``EINVAL`` error code.
610
611     -  .. row 11
612
613        -  ``V4L2_CTRL_TYPE_U8``
614
615        -  any
616
617        -  any
618
619        -  any
620
621        -  An unsigned 8-bit valued control ranging from minimum to maximum
622           inclusive. The step value indicates the increment between values.
623
624     -  .. row 12
625
626        -  ``V4L2_CTRL_TYPE_U16``
627
628        -  any
629
630        -  any
631
632        -  any
633
634        -  An unsigned 16-bit valued control ranging from minimum to maximum
635           inclusive. The step value indicates the increment between values.
636
637     -  .. row 13
638
639        -  ``V4L2_CTRL_TYPE_U32``
640
641        -  any
642
643        -  any
644
645        -  any
646
647        -  An unsigned 32-bit valued control ranging from minimum to maximum
648           inclusive. The step value indicates the increment between values.
649
650
651
652 .. _control-flags:
653
654 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
655
656 .. flat-table:: Control Flags
657     :header-rows:  0
658     :stub-columns: 0
659     :widths:       3 1 4
660
661
662     -  .. row 1
663
664        -  ``V4L2_CTRL_FLAG_DISABLED``
665
666        -  0x0001
667
668        -  This control is permanently disabled and should be ignored by the
669           application. Any attempt to change the control will result in an
670           ``EINVAL`` error code.
671
672     -  .. row 2
673
674        -  ``V4L2_CTRL_FLAG_GRABBED``
675
676        -  0x0002
677
678        -  This control is temporarily unchangeable, for example because
679           another application took over control of the respective resource.
680           Such controls may be displayed specially in a user interface.
681           Attempts to change the control may result in an ``EBUSY`` error code.
682
683     -  .. row 3
684
685        -  ``V4L2_CTRL_FLAG_READ_ONLY``
686
687        -  0x0004
688
689        -  This control is permanently readable only. Any attempt to change
690           the control will result in an ``EINVAL`` error code.
691
692     -  .. row 4
693
694        -  ``V4L2_CTRL_FLAG_UPDATE``
695
696        -  0x0008
697
698        -  A hint that changing this control may affect the value of other
699           controls within the same control class. Applications should update
700           their user interface accordingly.
701
702     -  .. row 5
703
704        -  ``V4L2_CTRL_FLAG_INACTIVE``
705
706        -  0x0010
707
708        -  This control is not applicable to the current configuration and
709           should be displayed accordingly in a user interface. For example
710           the flag may be set on a MPEG audio level 2 bitrate control when
711           MPEG audio encoding level 1 was selected with another control.
712
713     -  .. row 6
714
715        -  ``V4L2_CTRL_FLAG_SLIDER``
716
717        -  0x0020
718
719        -  A hint that this control is best represented as a slider-like
720           element in a user interface.
721
722     -  .. row 7
723
724        -  ``V4L2_CTRL_FLAG_WRITE_ONLY``
725
726        -  0x0040
727
728        -  This control is permanently writable only. Any attempt to read the
729           control will result in an ``EACCES`` error code error code. This flag
730           is typically present for relative controls or action controls
731           where writing a value will cause the device to carry out a given
732           action (e. g. motor control) but no meaningful value can be
733           returned.
734
735     -  .. row 8
736
737        -  ``V4L2_CTRL_FLAG_VOLATILE``
738
739        -  0x0080
740
741        -  This control is volatile, which means that the value of the
742           control changes continuously. A typical example would be the
743           current gain value if the device is in auto-gain mode. In such a
744           case the hardware calculates the gain value based on the lighting
745           conditions which can change over time.
746
747           .. note::
748
749              Setting a new value for a volatile control will have no
750              effect and no ``V4L2_EVENT_CTRL_CH_VALUE`` will be sent, unless
751              the ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`` flag (see below) is
752              also set. Otherwise the new value will just be ignored.
753
754     -  .. row 9
755
756        -  ``V4L2_CTRL_FLAG_HAS_PAYLOAD``
757
758        -  0x0100
759
760        -  This control has a pointer type, so its value has to be accessed
761           using one of the pointer fields of struct
762           :ref:`v4l2_ext_control <v4l2-ext-control>`. This flag is set
763           for controls that are an array, string, or have a compound type.
764           In all cases you have to set a pointer to memory containing the
765           payload of the control.
766
767     -  .. row 10
768
769        -  ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
770
771        -  0x0200
772
773        -  The value provided to the control will be propagated to the driver
774           even if it remains constant. This is required when the control
775           represents an action on the hardware. For example: clearing an
776           error flag or triggering the flash. All the controls of the type
777           ``V4L2_CTRL_TYPE_BUTTON`` have this flag set.
778
779
780 Return Value
781 ============
782
783 On success 0 is returned, on error -1 and the ``errno`` variable is set
784 appropriately. The generic error codes are described at the
785 :ref:`Generic Error Codes <gen-errors>` chapter.
786
787 EINVAL
788     The struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``id`` is
789     invalid. The struct :ref:`v4l2_querymenu <v4l2-querymenu>` ``id``
790     is invalid or ``index`` is out of range (less than ``minimum`` or
791     greater than ``maximum``) or this particular menu item is not
792     supported by the driver.
793
794 EACCES
795     An attempt was made to read a write-only control.
796
797 .. [#f1]
798    ``V4L2_CTRL_FLAG_DISABLED`` was intended for two purposes: Drivers
799    can skip predefined controls not supported by the hardware (although
800    returning ``EINVAL`` would do as well), or disable predefined and private
801    controls after hardware detection without the trouble of reordering
802    control arrays and indices (``EINVAL`` cannot be used to skip private
803    controls because it would prematurely end the enumeration).