blob: 4876ff1a1a0496c25b21aec609899983c4820e4d [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;
106<structfield>minimum</structfield> (0) to
107<structfield>maximum</structfield>, inclusive.</para>
108
109 <para>See also the examples in <xref linkend="control" />.</para>
110
111 <table pgwide="1" frame="none" id="v4l2-queryctrl">
112 <title>struct <structname>v4l2_queryctrl</structname></title>
113 <tgroup cols="3">
114 &cs-str;
115 <tbody valign="top">
116 <row>
117 <entry>__u32</entry>
118 <entry><structfield>id</structfield></entry>
119 <entry>Identifies the control, set by the application. See
120<xref linkend="control-id" /> for predefined IDs. When the ID is ORed
121with V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and returns
122the first control with a higher ID. Drivers which do not support this
123flag yet always return an &EINVAL;.</entry>
124 </row>
125 <row>
126 <entry>&v4l2-ctrl-type;</entry>
127 <entry><structfield>type</structfield></entry>
128 <entry>Type of control, see <xref
129 linkend="v4l2-ctrl-type" />.</entry>
130 </row>
131 <row>
132 <entry>__u8</entry>
133 <entry><structfield>name</structfield>[32]</entry>
134 <entry>Name of the control, a NUL-terminated ASCII
135string. This information is intended for the user.</entry>
136 </row>
137 <row>
138 <entry>__s32</entry>
139 <entry><structfield>minimum</structfield></entry>
140 <entry>Minimum value, inclusive. This field gives a lower
141bound for <constant>V4L2_CTRL_TYPE_INTEGER</constant> controls and the
142lowest valid index (always 0) for <constant>V4L2_CTRL_TYPE_MENU</constant> controls.
143For <constant>V4L2_CTRL_TYPE_STRING</constant> controls the minimum value
144gives the minimum length of the string. This length <emphasis>does not include the terminating
145zero</emphasis>. It may not be valid for any other type of control, including
146<constant>V4L2_CTRL_TYPE_INTEGER64</constant> controls. Note that this is a
147signed value.</entry>
148 </row>
149 <row>
150 <entry>__s32</entry>
151 <entry><structfield>maximum</structfield></entry>
152 <entry>Maximum value, inclusive. This field gives an upper
153bound for <constant>V4L2_CTRL_TYPE_INTEGER</constant> controls and the
154highest valid index for <constant>V4L2_CTRL_TYPE_MENU</constant>
155controls.
156For <constant>V4L2_CTRL_TYPE_STRING</constant> controls the maximum value
157gives the maximum length of the string. This length <emphasis>does not include the terminating
158zero</emphasis>. It may not be valid for any other type of control, including
159<constant>V4L2_CTRL_TYPE_INTEGER64</constant> controls. Note that this is a
160signed value.</entry>
161 </row>
162 <row>
163 <entry>__s32</entry>
164 <entry><structfield>step</structfield></entry>
165 <entry><para>This field gives a step size for
166<constant>V4L2_CTRL_TYPE_INTEGER</constant> controls. For
167<constant>V4L2_CTRL_TYPE_STRING</constant> controls this field refers to
168the string length that has to be a multiple of this step size.
169It may not be valid for any other type of control, including
170<constant>V4L2_CTRL_TYPE_INTEGER64</constant>
171controls.</para><para>Generally drivers should not scale hardware
172control values. It may be necessary for example when the
173<structfield>name</structfield> or <structfield>id</structfield> imply
174a particular unit and the hardware actually accepts only multiples of
175said unit. If so, drivers must take care values are properly rounded
176when scaling, such that errors will not accumulate on repeated
177read-write cycles.</para><para>This field gives the smallest change of
178an integer control actually affecting hardware. Often the information
179is needed when the user can change controls by keyboard or GUI
180buttons, rather than a slider. When for example a hardware register
181accepts values 0-511 and the driver reports 0-65535, step should be
182128.</para><para>Note that although signed, the step value is supposed to
183be always positive.</para></entry>
184 </row>
185 <row>
186 <entry>__s32</entry>
187 <entry><structfield>default_value</structfield></entry>
188 <entry>The default value of a
189<constant>V4L2_CTRL_TYPE_INTEGER</constant>,
190<constant>_BOOLEAN</constant> or <constant>_MENU</constant> control.
191Not valid for other types of controls. Drivers reset controls only
192when the driver is loaded, not later, in particular not when the
193func-open; is called.</entry>
194 </row>
195 <row>
196 <entry>__u32</entry>
197 <entry><structfield>flags</structfield></entry>
198 <entry>Control flags, see <xref
199 linkend="control-flags" />.</entry>
200 </row>
201 <row>
202 <entry>__u32</entry>
203 <entry><structfield>reserved</structfield>[2]</entry>
204 <entry>Reserved for future extensions. Drivers must set
205the array to zero.</entry>
206 </row>
207 </tbody>
208 </tgroup>
209 </table>
210
211 <table pgwide="1" frame="none" id="v4l2-querymenu">
212 <title>struct <structname>v4l2_querymenu</structname></title>
213 <tgroup cols="3">
214 &cs-str;
215 <tbody valign="top">
216 <row>
217 <entry>__u32</entry>
218 <entry><structfield>id</structfield></entry>
219 <entry>Identifies the control, set by the application
220from the respective &v4l2-queryctrl;
221<structfield>id</structfield>.</entry>
222 </row>
223 <row>
224 <entry>__u32</entry>
225 <entry><structfield>index</structfield></entry>
226 <entry>Index of the menu item, starting at zero, set by
227 the application.</entry>
228 </row>
229 <row>
230 <entry>__u8</entry>
231 <entry><structfield>name</structfield>[32]</entry>
232 <entry>Name of the menu item, a NUL-terminated ASCII
233string. This information is intended for the user.</entry>
234 </row>
235 <row>
236 <entry>__u32</entry>
237 <entry><structfield>reserved</structfield></entry>
238 <entry>Reserved for future extensions. Drivers must set
239the array to zero.</entry>
240 </row>
241 </tbody>
242 </tgroup>
243 </table>
244
245 <table pgwide="1" frame="none" id="v4l2-ctrl-type">
246 <title>enum v4l2_ctrl_type</title>
247 <tgroup cols="5" align="left">
248 <colspec colwidth="30*" />
249 <colspec colwidth="5*" align="center" />
250 <colspec colwidth="5*" align="center" />
251 <colspec colwidth="5*" align="center" />
252 <colspec colwidth="55*" />
253 <thead>
254 <row>
255 <entry>Type</entry>
256 <entry><structfield>minimum</structfield></entry>
257 <entry><structfield>step</structfield></entry>
258 <entry><structfield>maximum</structfield></entry>
259 <entry>Description</entry>
260 </row>
261 </thead>
262 <tbody valign="top">
263 <row>
264 <entry><constant>V4L2_CTRL_TYPE_INTEGER</constant></entry>
265 <entry>any</entry>
266 <entry>any</entry>
267 <entry>any</entry>
268 <entry>An integer-valued control ranging from minimum to
269maximum inclusive. The step value indicates the increment between
270values which are actually different on the hardware.</entry>
271 </row>
272 <row>
273 <entry><constant>V4L2_CTRL_TYPE_BOOLEAN</constant></entry>
274 <entry>0</entry>
275 <entry>1</entry>
276 <entry>1</entry>
277 <entry>A boolean-valued control. Zero corresponds to
278"disabled", and one means "enabled".</entry>
279 </row>
280 <row>
281 <entry><constant>V4L2_CTRL_TYPE_MENU</constant></entry>
282 <entry>0</entry>
283 <entry>1</entry>
284 <entry>N-1</entry>
285 <entry>The control has a menu of N choices. The names of
286the menu items can be enumerated with the
287<constant>VIDIOC_QUERYMENU</constant> ioctl.</entry>
288 </row>
289 <row>
290 <entry><constant>V4L2_CTRL_TYPE_BUTTON</constant></entry>
291 <entry>0</entry>
292 <entry>0</entry>
293 <entry>0</entry>
294 <entry>A control which performs an action when set.
295Drivers must ignore the value passed with
296<constant>VIDIOC_S_CTRL</constant> and return an &EINVAL; on a
297<constant>VIDIOC_G_CTRL</constant> attempt.</entry>
298 </row>
299 <row>
300 <entry><constant>V4L2_CTRL_TYPE_INTEGER64</constant></entry>
301 <entry>n/a</entry>
302 <entry>n/a</entry>
303 <entry>n/a</entry>
304 <entry>A 64-bit integer valued control. Minimum, maximum
305and step size cannot be queried.</entry>
306 </row>
307 <row>
308 <entry><constant>V4L2_CTRL_TYPE_STRING</constant></entry>
309 <entry>&ge; 0</entry>
310 <entry>&ge; 1</entry>
311 <entry>&ge; 0</entry>
312 <entry>The minimum and maximum string lengths. The step size
313means that the string must be (minimum + N * step) characters long for
314N &ge; 0. These lengths do not include the terminating zero, so in order to
315pass a string of length 8 to &VIDIOC-S-EXT-CTRLS; you need to set the
316<structfield>size</structfield> field of &v4l2-ext-control; to 9. For &VIDIOC-G-EXT-CTRLS; you can
317set the <structfield>size</structfield> field to <structfield>maximum</structfield> + 1.
318Which character encoding is used will depend on the string control itself and
319should be part of the control documentation.</entry>
320 </row>
321 <row>
322 <entry><constant>V4L2_CTRL_TYPE_CTRL_CLASS</constant></entry>
323 <entry>n/a</entry>
324 <entry>n/a</entry>
325 <entry>n/a</entry>
326 <entry>This is not a control. When
327<constant>VIDIOC_QUERYCTRL</constant> is called with a control ID
328equal to a control class code (see <xref linkend="ctrl-class" />), the
329ioctl returns the name of the control class and this control type.
330Older drivers which do not support this feature return an
331&EINVAL;.</entry>
332 </row>
333 </tbody>
334 </tgroup>
335 </table>
336
337 <table pgwide="1" frame="none" id="control-flags">
338 <title>Control Flags</title>
339 <tgroup cols="3">
340 &cs-def;
341 <tbody valign="top">
342 <row>
343 <entry><constant>V4L2_CTRL_FLAG_DISABLED</constant></entry>
344 <entry>0x0001</entry>
345 <entry>This control is permanently disabled and should be
346ignored by the application. Any attempt to change the control will
347result in an &EINVAL;.</entry>
348 </row>
349 <row>
350 <entry><constant>V4L2_CTRL_FLAG_GRABBED</constant></entry>
351 <entry>0x0002</entry>
352 <entry>This control is temporarily unchangeable, for
353example because another application took over control of the
354respective resource. Such controls may be displayed specially in a
355user interface. Attempts to change the control may result in an
356&EBUSY;.</entry>
357 </row>
358 <row>
359 <entry><constant>V4L2_CTRL_FLAG_READ_ONLY</constant></entry>
360 <entry>0x0004</entry>
361 <entry>This control is permanently readable only. Any
362attempt to change the control will result in an &EINVAL;.</entry>
363 </row>
364 <row>
365 <entry><constant>V4L2_CTRL_FLAG_UPDATE</constant></entry>
366 <entry>0x0008</entry>
367 <entry>A hint that changing this control may affect the
368value of other controls within the same control class. Applications
369should update their user interface accordingly.</entry>
370 </row>
371 <row>
372 <entry><constant>V4L2_CTRL_FLAG_INACTIVE</constant></entry>
373 <entry>0x0010</entry>
374 <entry>This control is not applicable to the current
375configuration and should be displayed accordingly in a user interface.
376For example the flag may be set on a MPEG audio level 2 bitrate
377control when MPEG audio encoding level 1 was selected with another
378control.</entry>
379 </row>
380 <row>
381 <entry><constant>V4L2_CTRL_FLAG_SLIDER</constant></entry>
382 <entry>0x0020</entry>
383 <entry>A hint that this control is best represented as a
384slider-like element in a user interface.</entry>
385 </row>
386 <row>
387 <entry><constant>V4L2_CTRL_FLAG_WRITE_ONLY</constant></entry>
388 <entry>0x0040</entry>
389 <entry>This control is permanently writable only. Any
390attempt to read the control will result in an &EACCES; error code. This
391flag is typically present for relative controls or action controls where
392writing a value will cause the device to carry out a given action
393(&eg; motor control) but no meaningful value can be returned.</entry>
394 </row>
395 </tbody>
396 </tgroup>
397 </table>
398 </refsect1>
399
400 <refsect1>
401 &return-value;
402
403 <variablelist>
404 <varlistentry>
405 <term><errorcode>EINVAL</errorcode></term>
406 <listitem>
407 <para>The &v4l2-queryctrl; <structfield>id</structfield>
408is invalid. The &v4l2-querymenu; <structfield>id</structfield> or
409<structfield>index</structfield> is invalid.</para>
410 </listitem>
411 </varlistentry>
412 <varlistentry>
413 <term><errorcode>EACCES</errorcode></term>
414 <listitem>
415 <para>An attempt was made to read a write-only control.</para>
416 </listitem>
417 </varlistentry>
418 </variablelist>
419 </refsect1>
420</refentry>
421
422<!--
423Local Variables:
424mode: sgml
425sgml-parent-document: "v4l2.sgml"
426indent-tabs-mode: nil
427End:
428-->