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