[media] doc: v4l: add documentation for selection API
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / Documentation / DocBook / media / v4l / vidioc-g-selection.xml
bloba9d36e0c090e4a74b89ffde495eb82fb5cc5e92f
1 <refentry id="vidioc-g-selection">
3   <refmeta>
4     <refentrytitle>ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</refentrytitle>
5     &manvol;
6   </refmeta>
8   <refnamediv>
9     <refname>VIDIOC_G_SELECTION</refname>
10     <refname>VIDIOC_S_SELECTION</refname>
11     <refpurpose>Get or set one of the selection rectangles</refpurpose>
12   </refnamediv>
14   <refsynopsisdiv>
15     <funcsynopsis>
16       <funcprototype>
17         <funcdef>int <function>ioctl</function></funcdef>
18         <paramdef>int <parameter>fd</parameter></paramdef>
19         <paramdef>int <parameter>request</parameter></paramdef>
20         <paramdef>struct v4l2_selection *<parameter>argp</parameter></paramdef>
21       </funcprototype>
22     </funcsynopsis>
23   </refsynopsisdiv>
25   <refsect1>
26     <title>Arguments</title>
28     <variablelist>
29       <varlistentry>
30         <term><parameter>fd</parameter></term>
31         <listitem>
32           <para>&fd;</para>
33         </listitem>
34       </varlistentry>
35       <varlistentry>
36         <term><parameter>request</parameter></term>
37         <listitem>
38           <para>VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</para>
39         </listitem>
40       </varlistentry>
41       <varlistentry>
42         <term><parameter>argp</parameter></term>
43         <listitem>
44           <para></para>
45         </listitem>
46       </varlistentry>
47     </variablelist>
48   </refsect1>
50   <refsect1>
51     <title>Description</title>
53     <note>
54       <title>Experimental</title>
55       <para>This is an <link linkend="experimental"> experimental </link>
56       interface and may change in the future.</para>
57     </note>
59     <para>The ioctls are used to query and configure selection rectangles.</para>
61 <para> To query the cropping (composing) rectangle set <structfield>
62 &v4l2-selection;::type </structfield> to the respective buffer type.  Do not
63 use multiplanar buffers.  Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
64 </constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
65 </constant>.  Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
66 <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>.  The next step is
67 setting <structfield> &v4l2-selection;::target </structfield> to value
68 <constant> V4L2_SEL_TGT_CROP_ACTIVE </constant> (<constant>
69 V4L2_SEL_TGT_COMPOSE_ACTIVE </constant>).  Please refer to table <xref
70 linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
71 targets.  Fields <structfield> &v4l2-selection;::flags </structfield> and
72 <structfield> &v4l2-selection;::reserved </structfield> are ignored and they
73 must be filled with zeros.  The driver fills the rest of the structure or
74 returns &EINVAL; if incorrect buffer type or target was used. If cropping
75 (composing) is not supported then the active rectangle is not mutable and it is
76 always equal to the bounds rectangle.  Finally, structure <structfield>
77 &v4l2-selection;::r </structfield> is filled with the current cropping
78 (composing) coordinates. The coordinates are expressed in driver-dependent
79 units. The only exception are rectangles for images in raw formats, whose
80 coordinates are always expressed in pixels.  </para>
82 <para> To change the cropping (composing) rectangle set <structfield>
83 &v4l2-selection;::type </structfield> to the respective buffer type.  Do not
84 use multiplanar buffers.  Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
85 </constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
86 </constant>.  Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
87 <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>.  The next step is
88 setting <structfield> &v4l2-selection;::target </structfield> to value
89 <constant> V4L2_SEL_TGT_CROP_ACTIVE </constant> (<constant>
90 V4L2_SEL_TGT_COMPOSE_ACTIVE </constant>). Please refer to table <xref
91 linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
92 targets.  Set desired active area into the field <structfield>
93 &v4l2-selection;::r </structfield>.  Field <structfield>
94 &v4l2-selection;::reserved </structfield> is ignored and must be filled with
95 zeros.  The driver may adjust the rectangle coordinates. An application may
96 introduce constraints to control rounding behaviour. Set the field
97 <structfield> &v4l2-selection;::flags </structfield> to one of values:
99 <itemizedlist>
100   <listitem>
101 <para><constant>0</constant> - The driver can adjust the rectangle size freely
102 and shall choose a crop/compose rectangle as close as possible to the requested
103 one.</para>
104   </listitem>
105   <listitem>
106 <para><constant>V4L2_SEL_FLAG_GE</constant> - The driver is not allowed to
107 shrink the rectangle.  The original rectangle must lay inside the adjusted
108 one.</para>
109   </listitem>
110   <listitem>
111 <para><constant>V4L2_SEL_FLAG_LE</constant> - The driver is not allowed to
112 enlarge the rectangle.  The adjusted rectangle must lay inside the original
113 one.</para>
114   </listitem>
115   <listitem>
116 <para><constant>V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</constant> - The driver
117 must choose the size exactly the same as in the requested rectangle.</para>
118   </listitem>
119 </itemizedlist>
121 Please refer to <xref linkend="sel-const-adjust" />.
123 </para>
125 <para> The driver may have to adjusts the requested dimensions against hardware
126 limits and other parts as the pipeline, i.e. the bounds given by the
127 capture/output window or TV display. The closest possible values of horizontal
128 and vertical offset and sizes are chosen according to following priority:
130 <orderedlist>
131   <listitem>
132     <para>Satisfy constraints from <structfield>&v4l2-selection;::flags</structfield>.</para>
133   </listitem>
134   <listitem>
135     <para>Adjust width, height, left, and top to hardware limits and alignments.</para>
136   </listitem>
137   <listitem>
138     <para>Keep center of adjusted rectangle as close as possible to the original one.</para>
139   </listitem>
140   <listitem>
141     <para>Keep width and height as close as possible to original ones.</para>
142   </listitem>
143   <listitem>
144     <para>Keep horizontal and vertical offset as close as possible to original ones.</para>
145   </listitem>
146 </orderedlist>
148 On success the field <structfield> &v4l2-selection;::r </structfield> contains
149 the adjusted rectangle. When the parameters are unsuitable the application may
150 modify the cropping (composing) or image parameters and repeat the cycle until
151 satisfactory parameters have been negotiated. If constraints flags have to be
152 violated at then ERANGE is returned. The error indicates that <emphasis> there
153 exist no rectangle </emphasis> that satisfies the constraints.</para>
155   </refsect1>
157   <refsect1>
158     <table frame="none" pgwide="1" id="v4l2-sel-target">
159       <title>Selection targets.</title>
160       <tgroup cols="3">
161         &cs-def;
162         <tbody valign="top">
163           <row>
164             <entry><constant>V4L2_SEL_TGT_CROP_ACTIVE</constant></entry>
165             <entry>0</entry>
166             <entry>area that is currently cropped by hardware</entry>
167           </row>
168           <row>
169             <entry><constant>V4L2_SEL_TGT_CROP_DEFAULT</constant></entry>
170             <entry>1</entry>
171             <entry>suggested cropping rectangle that covers the "whole picture"</entry>
172           </row>
173           <row>
174             <entry><constant>V4L2_SEL_TGT_CROP_BOUNDS</constant></entry>
175             <entry>2</entry>
176             <entry>limits for the cropping rectangle</entry>
177           </row>
178           <row>
179             <entry><constant>V4L2_SEL_TGT_COMPOSE_ACTIVE</constant></entry>
180             <entry>256</entry>
181             <entry>area to which data are composed by hardware</entry>
182           </row>
183           <row>
184             <entry><constant>V4L2_SEL_TGT_COMPOSE_DEFAULT</constant></entry>
185             <entry>257</entry>
186             <entry>suggested composing rectangle that covers the "whole picture"</entry>
187           </row>
188           <row>
189             <entry><constant>V4L2_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
190             <entry>258</entry>
191             <entry>limits for the composing rectangle</entry>
192           </row>
193           <row>
194             <entry><constant>V4L2_SEL_TGT_COMPOSE_PADDED</constant></entry>
195             <entry>259</entry>
196             <entry>the active area and all padding pixels that are inserted or modified by the hardware</entry>
197           </row>
198         </tbody>
199       </tgroup>
200     </table>
201   </refsect1>
203   <refsect1>
204     <table frame="none" pgwide="1" id="v4l2-sel-flags">
205       <title>Selection constraint flags</title>
206       <tgroup cols="3">
207         &cs-def;
208         <tbody valign="top">
209           <row>
210             <entry><constant>V4L2_SEL_FLAG_GE</constant></entry>
211             <entry>0x00000001</entry>
212             <entry>indicate that adjusted rectangle must contain a rectangle from <structfield>&v4l2-selection;::r</structfield></entry>
213           </row>
214           <row>
215             <entry><constant>V4L2_SEL_FLAG_LE</constant></entry>
216             <entry>0x00000002</entry>
217             <entry>indicate that adjusted rectangle must be inside a rectangle from <structfield>&v4l2-selection;::r</structfield></entry>
218           </row>
219         </tbody>
220       </tgroup>
221     </table>
222   </refsect1>
224     <section>
225       <figure id="sel-const-adjust">
226         <title>Size adjustments with constraint flags.</title>
227         <mediaobject>
228           <imageobject>
229             <imagedata fileref="constraints.png" format="PNG" />
230           </imageobject>
231           <textobject>
232             <phrase>Behaviour of rectangle adjustment for different constraint
233             flags.</phrase>
234           </textobject>
235         </mediaobject>
236       </figure>
237     </section>
239   <refsect1>
240     <table pgwide="1" frame="none" id="v4l2-selection">
241       <title>struct <structname>v4l2_selection</structname></title>
242       <tgroup cols="3">
243         &cs-str;
244         <tbody valign="top">
245           <row>
246             <entry>__u32</entry>
247             <entry><structfield>type</structfield></entry>
248             <entry>Type of the buffer (from &v4l2-buf-type;)</entry>
249           </row>
250           <row>
251             <entry>__u32</entry>
252             <entry><structfield>target</structfield></entry>
253             <entry>used to select between <link linkend="v4l2-sel-target"> cropping and composing rectangles </link></entry>
254           </row>
255           <row>
256             <entry>__u32</entry>
257             <entry><structfield>flags</structfield></entry>
258             <entry>control over coordinates adjustments, refer to <link linkend="v4l2-sel-flags">selection flags</link></entry>
259           </row>
260           <row>
261             <entry>&v4l2-rect;</entry>
262             <entry><structfield>r</structfield></entry>
263             <entry>selection rectangle</entry>
264           </row>
265           <row>
266             <entry>__u32</entry>
267             <entry><structfield>reserved[9]</structfield></entry>
268             <entry>Reserved fields for future use</entry>
269           </row>
270         </tbody>
271       </tgroup>
272     </table>
273   </refsect1>
275   <refsect1>
276     &return-value;
277     <variablelist>
278       <varlistentry>
279         <term><errorcode>EINVAL</errorcode></term>
280         <listitem>
281           <para>The buffer <structfield> &v4l2-selection;::type </structfield>
282 or <structfield> &v4l2-selection;::target </structfield> is not supported, or
283 the <structfield> &v4l2-selection;::flags </structfield> are invalid.</para>
284         </listitem>
285       </varlistentry>
286       <varlistentry>
287         <term><errorcode>ERANGE</errorcode></term>
288         <listitem>
289           <para>it is not possible to adjust a rectangle <structfield>
290 &v4l2-selection;::r </structfield> that satisfies all contraints from
291 <structfield> &v4l2-selection;::flags </structfield>.</para>
292         </listitem>
293       </varlistentry>
294       <varlistentry>
295         <term><errorcode>EBUSY</errorcode></term>
296         <listitem>
297           <para>it is not possible to apply change of selection rectangle at the moment.
298 Usually because streaming is in progress.</para>
299         </listitem>
300       </varlistentry>
301     </variablelist>
302   </refsect1>
304 </refentry>