Merge branch 'x86-x32-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / Documentation / DocBook / media / v4l / vidioc-g-selection.xml
1 <refentry id="vidioc-g-selection">
2
3   <refmeta>
4     <refentrytitle>ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</refentrytitle>
5     &manvol;
6   </refmeta>
7
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>
13
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>
24
25   <refsect1>
26     <title>Arguments</title>
27
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>
49
50   <refsect1>
51     <title>Description</title>
52
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>
58
59     <para>The ioctls are used to query and configure selection rectangles.</para>
60
61 <para> To query the cropping (composing) rectangle set &v4l2-selection;
62 <structfield> type </structfield> field to the respective buffer type.
63 Do not 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 the value of &v4l2-selection; <structfield>target</structfield> field
68 to <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.  The <structfield>flags</structfield> and <structfield>reserved
72 </structfield> fields of &v4l2-selection; are ignored and they must be filled
73 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, the &v4l2-rect;
77 <structfield>r</structfield> rectangle 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>
81
82 <para> To change the cropping (composing) rectangle set the &v4l2-selection;
83 <structfield>type</structfield> field 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 the value of &v4l2-selection; <structfield>target</structfield> to
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.  The &v4l2-rect; <structfield>r</structfield> rectangle need to be
93 set to the desired active area. Field &v4l2-selection; <structfield> reserved
94 </structfield> is ignored and must be filled with zeros.  The driver may adjust
95 coordinates of the requested rectangle. An application may
96 introduce constraints to control rounding behaviour. The &v4l2-selection;
97 <structfield>flags</structfield> field must be set to one of the following:
98
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>
120
121 Please refer to <xref linkend="sel-const-adjust" />.
122
123 </para>
124
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:
129
130 <orderedlist>
131   <listitem>
132     <para>Satisfy constraints from &v4l2-selection; <structfield>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>
147
148 On success the &v4l2-rect; <structfield>r</structfield> field 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>
154
155   </refsect1>
156
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>0x0000</entry>
166             <entry>The area that is currently cropped by hardware.</entry>
167           </row>
168           <row>
169             <entry><constant>V4L2_SEL_TGT_CROP_DEFAULT</constant></entry>
170             <entry>0x0001</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>0x0002</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>0x0100</entry>
181             <entry>The area to which data is composed by hardware.</entry>
182           </row>
183           <row>
184             <entry><constant>V4L2_SEL_TGT_COMPOSE_DEFAULT</constant></entry>
185             <entry>0x0101</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>0x0102</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>0x0103</entry>
196             <entry>The active area and all padding pixels that are inserted or modified by hardware.</entry>
197           </row>
198         </tbody>
199       </tgroup>
200     </table>
201   </refsect1>
202
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>Indicates that the adjusted rectangle must contain the original
213             &v4l2-selection; <structfield>r</structfield> rectangle.</entry>
214           </row>
215           <row>
216             <entry><constant>V4L2_SEL_FLAG_LE</constant></entry>
217             <entry>0x00000002</entry>
218             <entry>Indicates that the adjusted rectangle must be inside the original
219             &v4l2-rect; <structfield>r</structfield> rectangle.</entry>
220           </row>
221         </tbody>
222       </tgroup>
223     </table>
224   </refsect1>
225
226     <section>
227       <figure id="sel-const-adjust">
228         <title>Size adjustments with constraint flags.</title>
229         <mediaobject>
230           <imageobject>
231             <imagedata fileref="constraints.png" format="PNG" />
232           </imageobject>
233           <textobject>
234             <phrase>Behaviour of rectangle adjustment for different constraint
235             flags.</phrase>
236           </textobject>
237         </mediaobject>
238       </figure>
239     </section>
240
241   <refsect1>
242     <table pgwide="1" frame="none" id="v4l2-selection">
243       <title>struct <structname>v4l2_selection</structname></title>
244       <tgroup cols="3">
245         &cs-str;
246         <tbody valign="top">
247           <row>
248             <entry>__u32</entry>
249             <entry><structfield>type</structfield></entry>
250             <entry>Type of the buffer (from &v4l2-buf-type;).</entry>
251           </row>
252           <row>
253             <entry>__u32</entry>
254             <entry><structfield>target</structfield></entry>
255             <entry>Used to select between <link linkend="v4l2-sel-target"> cropping
256             and composing rectangles</link>.</entry>
257           </row>
258           <row>
259             <entry>__u32</entry>
260             <entry><structfield>flags</structfield></entry>
261             <entry>Flags controlling the selection rectangle adjustments, refer to
262             <link linkend="v4l2-sel-flags">selection flags</link>.</entry>
263           </row>
264           <row>
265             <entry>&v4l2-rect;</entry>
266             <entry><structfield>r</structfield></entry>
267             <entry>The selection rectangle.</entry>
268           </row>
269           <row>
270             <entry>__u32</entry>
271             <entry><structfield>reserved[9]</structfield></entry>
272             <entry>Reserved fields for future use.</entry>
273           </row>
274         </tbody>
275       </tgroup>
276     </table>
277   </refsect1>
278
279   <refsect1>
280     &return-value;
281     <variablelist>
282       <varlistentry>
283         <term><errorcode>EINVAL</errorcode></term>
284         <listitem>
285           <para>Given buffer type <structfield>type</structfield> or
286 the selection target <structfield>target</structfield> is not supported,
287 or the <structfield>flags</structfield> argument is not valid.</para>
288         </listitem>
289       </varlistentry>
290       <varlistentry>
291         <term><errorcode>ERANGE</errorcode></term>
292         <listitem>
293           <para>It is not possible to adjust &v4l2-rect; <structfield>
294 r</structfield> rectangle to satisfy all contraints given in the
295 <structfield>flags</structfield> argument.</para>
296         </listitem>
297       </varlistentry>
298       <varlistentry>
299         <term><errorcode>EBUSY</errorcode></term>
300         <listitem>
301           <para>It is not possible to apply change of the selection rectangle
302 at the moment. Usually because streaming is in progress.</para>
303         </listitem>
304       </varlistentry>
305     </variablelist>
306   </refsect1>
307
308 </refentry>