blob: 36660d311b5129d21f3690cbe292394bb457c38d [file] [log] [blame]
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001<refentry id="vidioc-queryctrl">
2 <refmeta>
3 <refentrytitle>ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>VIDIOC_QUERYCTRL</refname>
9 <refname>VIDIOC_QUERYMENU</refname>
10 <refpurpose>Enumerate controls and menu control items</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>struct v4l2_queryctrl *<parameter>argp</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 <funcsynopsis>
23 <funcprototype>
24 <funcdef>int <function>ioctl</function></funcdef>
25 <paramdef>int <parameter>fd</parameter></paramdef>
26 <paramdef>int <parameter>request</parameter></paramdef>
27 <paramdef>struct v4l2_querymenu *<parameter>argp</parameter></paramdef>
28 </funcprototype>
29 </funcsynopsis>
30 </refsynopsisdiv>
31
32 <refsect1>
33 <title>Arguments</title>
34
35 <variablelist>
36 <varlistentry>
37 <term><parameter>fd</parameter></term>
38 <listitem>
39 <para>&fd;</para>
40 </listitem>
41 </varlistentry>
42 <varlistentry>
43 <term><parameter>request</parameter></term>
44 <listitem>
45 <para>VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</para>
46 </listitem>
47 </varlistentry>
48 <varlistentry>
49 <term><parameter>argp</parameter></term>
50 <listitem>
51 <para></para>
52 </listitem>
53 </varlistentry>
54 </variablelist>
55 </refsect1>
56
57 <refsect1>
58 <title>Description</title>
59
60 <para>To query the attributes of a control applications set the
61<structfield>id</structfield> field of a &v4l2-queryctrl; and call the
62<constant>VIDIOC_QUERYCTRL</constant> ioctl with a pointer to this
63structure. The driver fills the rest of the structure or returns an
64&EINVAL; when the <structfield>id</structfield> is invalid.</para>
65
66 <para>It is possible to enumerate controls by calling
67<constant>VIDIOC_QUERYCTRL</constant> with successive
68<structfield>id</structfield> values starting from
69<constant>V4L2_CID_BASE</constant> up to and exclusive
70<constant>V4L2_CID_BASE_LASTP1</constant>. Drivers may return
71<errorcode>EINVAL</errorcode> if a control in this range is not
72supported. Further applications can enumerate private controls, which
73are not defined in this specification, by starting at
74<constant>V4L2_CID_PRIVATE_BASE</constant> and incrementing
75<structfield>id</structfield> until the driver returns
76<errorcode>EINVAL</errorcode>.</para>
77
78 <para>In both cases, when the driver sets the
79<constant>V4L2_CTRL_FLAG_DISABLED</constant> flag in the
80<structfield>flags</structfield> field this control is permanently
81disabled and should be ignored by the application.<footnote>
82 <para><constant>V4L2_CTRL_FLAG_DISABLED</constant> was
83intended for two purposes: Drivers can skip predefined controls not
84supported by the hardware (although returning EINVAL would do as
85well), or disable predefined and private controls after hardware
86detection without the trouble of reordering control arrays and indices
87(EINVAL cannot be used to skip private controls because it would
88prematurely end the enumeration).</para></footnote></para>
89
90 <para>When the application ORs <structfield>id</structfield> with
91<constant>V4L2_CTRL_FLAG_NEXT_CTRL</constant> the driver returns the
92next supported control, or <errorcode>EINVAL</errorcode> if there is
93none. Drivers which do not support this flag yet always return
94<errorcode>EINVAL</errorcode>.</para>
95
96 <para>Additional information is required for menu controls: the
97names of the menu items. To query them applications set the
98<structfield>id</structfield> and <structfield>index</structfield>
99fields of &v4l2-querymenu; and call the
100<constant>VIDIOC_QUERYMENU</constant> ioctl with a pointer to this
101structure. The driver fills the rest of the structure or returns an
102&EINVAL; when the <structfield>id</structfield> or
103<structfield>index</structfield> is invalid. Menu items are enumerated
104by calling <constant>VIDIOC_QUERYMENU</constant> with successive
105<structfield>index</structfield> values from &v4l2-queryctrl;
Hans Verkuil67562072010-09-11 11:38:51 -0300106<structfield>minimum</structfield> to
107<structfield>maximum</structfield>, inclusive. Note that it is possible
108for <constant>VIDIOC_QUERYMENU</constant> to return an &EINVAL; for some
109indices between <structfield>minimum</structfield> and <structfield>maximum</structfield>.
110In that case that particular menu item is not supported by this driver. Also note that
111the <structfield>minimum</structfield> value is not necessarily 0.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300112
113 <para>See also the examples in <xref linkend="control" />.</para>
114
115 <table pgwide="1" frame="none" id="v4l2-queryctrl">
116 <title>struct <structname>v4l2_queryctrl</structname></title>
117 <tgroup cols="3">
118 &cs-str;
119 <tbody valign="top">
120 <row>
121 <entry>__u32</entry>
122 <entry><structfield>id</structfield></entry>
123 <entry>Identifies the control, set by the application. See
124<xref linkend="control-id" /> for predefined IDs. When the ID is ORed
125with V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and returns
126the first control with a higher ID. Drivers which do not support this
127flag yet always return an &EINVAL;.</entry>
128 </row>
129 <row>
130 <entry>&v4l2-ctrl-type;</entry>
131 <entry><structfield>type</structfield></entry>
132 <entry>Type of control, see <xref
133 linkend="v4l2-ctrl-type" />.</entry>
134 </row>
135 <row>
136 <entry>__u8</entry>
137 <entry><structfield>name</structfield>[32]</entry>
138 <entry>Name of the control, a NUL-terminated ASCII
139string. This information is intended for the user.</entry>
140 </row>
141 <row>
142 <entry>__s32</entry>
143 <entry><structfield>minimum</structfield></entry>
144 <entry>Minimum value, inclusive. This field gives a lower
145bound for <constant>V4L2_CTRL_TYPE_INTEGER</constant> controls and the
Hans Verkuil67562072010-09-11 11:38:51 -0300146lowest valid index for <constant>V4L2_CTRL_TYPE_MENU</constant> controls.
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300147For <constant>V4L2_CTRL_TYPE_STRING</constant> controls the minimum value
148gives the minimum length of the string. This length <emphasis>does not include the terminating
149zero</emphasis>. It may not be valid for any other type of control, including
150<constant>V4L2_CTRL_TYPE_INTEGER64</constant> controls. Note that this is a
151signed value.</entry>
152 </row>
153 <row>
154 <entry>__s32</entry>
155 <entry><structfield>maximum</structfield></entry>
156 <entry>Maximum value, inclusive. This field gives an upper
157bound for <constant>V4L2_CTRL_TYPE_INTEGER</constant> controls and the
158highest valid index for <constant>V4L2_CTRL_TYPE_MENU</constant>
Hans Verkuilaec67f02011-05-23 07:36:55 -0300159controls. For <constant>V4L2_CTRL_TYPE_BITMASK</constant> controls it is the
160set of usable bits.
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300161For <constant>V4L2_CTRL_TYPE_STRING</constant> controls the maximum value
162gives the maximum length of the string. This length <emphasis>does not include the terminating
163zero</emphasis>. It may not be valid for any other type of control, including
164<constant>V4L2_CTRL_TYPE_INTEGER64</constant> controls. Note that this is a
165signed value.</entry>
166 </row>
167 <row>
168 <entry>__s32</entry>
169 <entry><structfield>step</structfield></entry>
170 <entry><para>This field gives a step size for
171<constant>V4L2_CTRL_TYPE_INTEGER</constant> controls. For
172<constant>V4L2_CTRL_TYPE_STRING</constant> controls this field refers to
173the string length that has to be a multiple of this step size.
174It may not be valid for any other type of control, including
175<constant>V4L2_CTRL_TYPE_INTEGER64</constant>
176controls.</para><para>Generally drivers should not scale hardware
177control values. It may be necessary for example when the
178<structfield>name</structfield> or <structfield>id</structfield> imply
179a particular unit and the hardware actually accepts only multiples of
180said unit. If so, drivers must take care values are properly rounded
181when scaling, such that errors will not accumulate on repeated
182read-write cycles.</para><para>This field gives the smallest change of
183an integer control actually affecting hardware. Often the information
184is needed when the user can change controls by keyboard or GUI
185buttons, rather than a slider. When for example a hardware register
186accepts values 0-511 and the driver reports 0-65535, step should be
187128.</para><para>Note that although signed, the step value is supposed to
188be always positive.</para></entry>
189 </row>
190 <row>
191 <entry>__s32</entry>
192 <entry><structfield>default_value</structfield></entry>
193 <entry>The default value of a
194<constant>V4L2_CTRL_TYPE_INTEGER</constant>,
195<constant>_BOOLEAN</constant> or <constant>_MENU</constant> control.
196Not valid for other types of controls. Drivers reset controls only
197when the driver is loaded, not later, in particular not when the
198func-open; is called.</entry>
199 </row>
200 <row>
201 <entry>__u32</entry>
202 <entry><structfield>flags</structfield></entry>
203 <entry>Control flags, see <xref
204 linkend="control-flags" />.</entry>
205 </row>
206 <row>
207 <entry>__u32</entry>
208 <entry><structfield>reserved</structfield>[2]</entry>
209 <entry>Reserved for future extensions. Drivers must set
210the array to zero.</entry>
211 </row>
212 </tbody>
213 </tgroup>
214 </table>
215
216 <table pgwide="1" frame="none" id="v4l2-querymenu">
217 <title>struct <structname>v4l2_querymenu</structname></title>
218 <tgroup cols="3">
219 &cs-str;
220 <tbody valign="top">
221 <row>
222 <entry>__u32</entry>
223 <entry><structfield>id</structfield></entry>
224 <entry>Identifies the control, set by the application
225from the respective &v4l2-queryctrl;
226<structfield>id</structfield>.</entry>
227 </row>
228 <row>
229 <entry>__u32</entry>
230 <entry><structfield>index</structfield></entry>
231 <entry>Index of the menu item, starting at zero, set by
232 the application.</entry>
233 </row>
234 <row>
235 <entry>__u8</entry>
236 <entry><structfield>name</structfield>[32]</entry>
237 <entry>Name of the menu item, a NUL-terminated ASCII
238string. This information is intended for the user.</entry>
239 </row>
240 <row>
241 <entry>__u32</entry>
242 <entry><structfield>reserved</structfield></entry>
243 <entry>Reserved for future extensions. Drivers must set
244the array to zero.</entry>
245 </row>
246 </tbody>
247 </tgroup>
248 </table>
249
250 <table pgwide="1" frame="none" id="v4l2-ctrl-type">
251 <title>enum v4l2_ctrl_type</title>
252 <tgroup cols="5" align="left">
253 <colspec colwidth="30*" />
254 <colspec colwidth="5*" align="center" />
255 <colspec colwidth="5*" align="center" />
256 <colspec colwidth="5*" align="center" />
257 <colspec colwidth="55*" />
258 <thead>
259 <row>
260 <entry>Type</entry>
261 <entry><structfield>minimum</structfield></entry>
262 <entry><structfield>step</structfield></entry>
263 <entry><structfield>maximum</structfield></entry>
264 <entry>Description</entry>
265 </row>
266 </thead>
267 <tbody valign="top">
268 <row>
269 <entry><constant>V4L2_CTRL_TYPE_INTEGER</constant></entry>
270 <entry>any</entry>
271 <entry>any</entry>
272 <entry>any</entry>
273 <entry>An integer-valued control ranging from minimum to
274maximum inclusive. The step value indicates the increment between
275values which are actually different on the hardware.</entry>
276 </row>
277 <row>
278 <entry><constant>V4L2_CTRL_TYPE_BOOLEAN</constant></entry>
279 <entry>0</entry>
280 <entry>1</entry>
281 <entry>1</entry>
282 <entry>A boolean-valued control. Zero corresponds to
283"disabled", and one means "enabled".</entry>
284 </row>
285 <row>
286 <entry><constant>V4L2_CTRL_TYPE_MENU</constant></entry>
Hans Verkuil67562072010-09-11 11:38:51 -0300287 <entry>&ge; 0</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300288 <entry>1</entry>
289 <entry>N-1</entry>
290 <entry>The control has a menu of N choices. The names of
291the menu items can be enumerated with the
292<constant>VIDIOC_QUERYMENU</constant> ioctl.</entry>
293 </row>
294 <row>
Hans Verkuilaec67f02011-05-23 07:36:55 -0300295 <entry><constant>V4L2_CTRL_TYPE_BITMASK</constant></entry>
296 <entry>0</entry>
297 <entry>n/a</entry>
298 <entry>any</entry>
299 <entry>A bitmask field. The maximum value is the set of bits that can
300be used, all other bits are to be 0. The maximum value is interpreted as a __u32,
301allowing the use of bit 31 in the bitmask.</entry>
302 </row>
303 <row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300304 <entry><constant>V4L2_CTRL_TYPE_BUTTON</constant></entry>
305 <entry>0</entry>
306 <entry>0</entry>
307 <entry>0</entry>
308 <entry>A control which performs an action when set.
309Drivers must ignore the value passed with
310<constant>VIDIOC_S_CTRL</constant> and return an &EINVAL; on a
311<constant>VIDIOC_G_CTRL</constant> attempt.</entry>
312 </row>
313 <row>
314 <entry><constant>V4L2_CTRL_TYPE_INTEGER64</constant></entry>
315 <entry>n/a</entry>
316 <entry>n/a</entry>
317 <entry>n/a</entry>
318 <entry>A 64-bit integer valued control. Minimum, maximum
319and step size cannot be queried.</entry>
320 </row>
321 <row>
322 <entry><constant>V4L2_CTRL_TYPE_STRING</constant></entry>
323 <entry>&ge; 0</entry>
324 <entry>&ge; 1</entry>
325 <entry>&ge; 0</entry>
326 <entry>The minimum and maximum string lengths. The step size
327means that the string must be (minimum + N * step) characters long for
328N &ge; 0. These lengths do not include the terminating zero, so in order to
329pass a string of length 8 to &VIDIOC-S-EXT-CTRLS; you need to set the
330<structfield>size</structfield> field of &v4l2-ext-control; to 9. For &VIDIOC-G-EXT-CTRLS; you can
331set the <structfield>size</structfield> field to <structfield>maximum</structfield> + 1.
332Which character encoding is used will depend on the string control itself and
333should be part of the control documentation.</entry>
334 </row>
335 <row>
336 <entry><constant>V4L2_CTRL_TYPE_CTRL_CLASS</constant></entry>
337 <entry>n/a</entry>
338 <entry>n/a</entry>
339 <entry>n/a</entry>
340 <entry>This is not a control. When
341<constant>VIDIOC_QUERYCTRL</constant> is called with a control ID
Hans Verkuil86055302010-04-06 06:41:28 -0300342equal to a control class code (see <xref linkend="ctrl-class" />) + 1, the
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300343ioctl returns the name of the control class and this control type.
344Older drivers which do not support this feature return an
345&EINVAL;.</entry>
346 </row>
347 </tbody>
348 </tgroup>
349 </table>
350
351 <table pgwide="1" frame="none" id="control-flags">
352 <title>Control Flags</title>
353 <tgroup cols="3">
354 &cs-def;
355 <tbody valign="top">
356 <row>
357 <entry><constant>V4L2_CTRL_FLAG_DISABLED</constant></entry>
358 <entry>0x0001</entry>
359 <entry>This control is permanently disabled and should be
360ignored by the application. Any attempt to change the control will
361result in an &EINVAL;.</entry>
362 </row>
363 <row>
364 <entry><constant>V4L2_CTRL_FLAG_GRABBED</constant></entry>
365 <entry>0x0002</entry>
366 <entry>This control is temporarily unchangeable, for
367example because another application took over control of the
368respective resource. Such controls may be displayed specially in a
369user interface. Attempts to change the control may result in an
370&EBUSY;.</entry>
371 </row>
372 <row>
373 <entry><constant>V4L2_CTRL_FLAG_READ_ONLY</constant></entry>
374 <entry>0x0004</entry>
375 <entry>This control is permanently readable only. Any
376attempt to change the control will result in an &EINVAL;.</entry>
377 </row>
378 <row>
379 <entry><constant>V4L2_CTRL_FLAG_UPDATE</constant></entry>
380 <entry>0x0008</entry>
381 <entry>A hint that changing this control may affect the
382value of other controls within the same control class. Applications
383should update their user interface accordingly.</entry>
384 </row>
385 <row>
386 <entry><constant>V4L2_CTRL_FLAG_INACTIVE</constant></entry>
387 <entry>0x0010</entry>
388 <entry>This control is not applicable to the current
389configuration and should be displayed accordingly in a user interface.
390For example the flag may be set on a MPEG audio level 2 bitrate
391control when MPEG audio encoding level 1 was selected with another
392control.</entry>
393 </row>
394 <row>
395 <entry><constant>V4L2_CTRL_FLAG_SLIDER</constant></entry>
396 <entry>0x0020</entry>
397 <entry>A hint that this control is best represented as a
398slider-like element in a user interface.</entry>
399 </row>
400 <row>
401 <entry><constant>V4L2_CTRL_FLAG_WRITE_ONLY</constant></entry>
402 <entry>0x0040</entry>
403 <entry>This control is permanently writable only. Any
404attempt to read the control will result in an &EACCES; error code. This
405flag is typically present for relative controls or action controls where
406writing a value will cause the device to carry out a given action
407(&eg; motor control) but no meaningful value can be returned.</entry>
408 </row>
Hans Verkuil74a45792011-08-26 07:31:13 -0300409 <row>
410 <entry><constant>V4L2_CTRL_FLAG_VOLATILE</constant></entry>
411 <entry>0x0080</entry>
412 <entry>This control is volatile, which means that the value of the control
413changes continuously. A typical example would be the current gain value if the device
414is in auto-gain mode. In such a case the hardware calculates the gain value based on
415the lighting conditions which can change over time. Note that setting a new value for
416a volatile control will have no effect. The new value will just be ignored.</entry>
417 </row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300418 </tbody>
419 </tgroup>
420 </table>
421 </refsect1>
422
423 <refsect1>
424 &return-value;
425
426 <variablelist>
427 <varlistentry>
428 <term><errorcode>EINVAL</errorcode></term>
429 <listitem>
430 <para>The &v4l2-queryctrl; <structfield>id</structfield>
Hans Verkuil67562072010-09-11 11:38:51 -0300431is invalid. The &v4l2-querymenu; <structfield>id</structfield> is
432invalid or <structfield>index</structfield> is out of range (less than
433<structfield>minimum</structfield> or greater than <structfield>maximum</structfield>)
434or this particular menu item is not supported by the driver.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300435 </listitem>
436 </varlistentry>
437 <varlistentry>
438 <term><errorcode>EACCES</errorcode></term>
439 <listitem>
440 <para>An attempt was made to read a write-only control.</para>
441 </listitem>
442 </varlistentry>
443 </variablelist>
444 </refsect1>
445</refentry>