blob: f76d8a6d9b92df2133babc08456ac3bfc4d9c171 [file] [log] [blame]
Tomasz Stanislawski8af49222011-08-19 07:00:04 -03001<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
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030061<para> To query the cropping (composing) rectangle set &v4l2-selection;
62<structfield> type </structfield> field to the respective buffer type.
63Do not use multiplanar buffers. Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
Tomasz Stanislawski8af49222011-08-19 07:00:04 -030064</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
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030067setting the value of &v4l2-selection; <structfield>target</structfield> field
Sylwester Nawrockic1334822012-05-20 11:17:12 -030068to <constant> V4L2_SEL_TGT_CROP </constant> (<constant>
69V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref
Sakari Ailus64b9ce82012-06-01 13:56:53 -030070linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030071targets. The <structfield>flags</structfield> and <structfield>reserved
72</structfield> fields of &v4l2-selection; are ignored and they must be filled
73with zeros. The driver fills the rest of the structure or
Tomasz Stanislawski8af49222011-08-19 07:00:04 -030074returns &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
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030076always equal to the bounds rectangle. Finally, the &v4l2-rect;
77<structfield>r</structfield> rectangle is filled with the current cropping
Tomasz Stanislawski8af49222011-08-19 07:00:04 -030078(composing) coordinates. The coordinates are expressed in driver-dependent
79units. The only exception are rectangles for images in raw formats, whose
80coordinates are always expressed in pixels. </para>
81
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030082<para> To change the cropping (composing) rectangle set the &v4l2-selection;
83<structfield>type</structfield> field to the respective buffer type. Do not
Tomasz Stanislawski8af49222011-08-19 07:00:04 -030084use 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
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030088setting the value of &v4l2-selection; <structfield>target</structfield> to
Sylwester Nawrockic1334822012-05-20 11:17:12 -030089<constant>V4L2_SEL_TGT_CROP</constant> (<constant>
90V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref
Sakari Ailus64b9ce82012-06-01 13:56:53 -030091linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -030092targets. The &v4l2-rect; <structfield>r</structfield> rectangle need to be
93set to the desired active area. Field &v4l2-selection; <structfield> reserved
94</structfield> is ignored and must be filled with zeros. The driver may adjust
95coordinates of the requested rectangle. An application may
96introduce constraints to control rounding behaviour. The &v4l2-selection;
97<structfield>flags</structfield> field must be set to one of the following:
Tomasz Stanislawski8af49222011-08-19 07:00:04 -030098
99<itemizedlist>
100 <listitem>
101<para><constant>0</constant> - The driver can adjust the rectangle size freely
102and shall choose a crop/compose rectangle as close as possible to the requested
103one.</para>
104 </listitem>
105 <listitem>
106<para><constant>V4L2_SEL_FLAG_GE</constant> - The driver is not allowed to
107shrink the rectangle. The original rectangle must lay inside the adjusted
108one.</para>
109 </listitem>
110 <listitem>
111<para><constant>V4L2_SEL_FLAG_LE</constant> - The driver is not allowed to
112enlarge the rectangle. The adjusted rectangle must lay inside the original
113one.</para>
114 </listitem>
115 <listitem>
116<para><constant>V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</constant> - The driver
117must choose the size exactly the same as in the requested rectangle.</para>
118 </listitem>
119</itemizedlist>
120
121Please refer to <xref linkend="sel-const-adjust" />.
122
123</para>
124
125<para> The driver may have to adjusts the requested dimensions against hardware
126limits and other parts as the pipeline, i.e. the bounds given by the
127capture/output window or TV display. The closest possible values of horizontal
128and vertical offset and sizes are chosen according to following priority:
129
130<orderedlist>
131 <listitem>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300132 <para>Satisfy constraints from &v4l2-selection; <structfield>flags</structfield>.</para>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300133 </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
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300148On success the &v4l2-rect; <structfield>r</structfield> field contains
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300149the adjusted rectangle. When the parameters are unsuitable the application may
150modify the cropping (composing) or image parameters and repeat the cycle until
151satisfactory parameters have been negotiated. If constraints flags have to be
152violated at then ERANGE is returned. The error indicates that <emphasis> there
153exist no rectangle </emphasis> that satisfies the constraints.</para>
154
155 </refsect1>
156
Sakari Ailus9fe75aa2012-06-13 16:01:10 -0300157 <para>Selection targets and flags are documented in <xref
Sakari Ailus64b9ce82012-06-01 13:56:53 -0300158 linkend="v4l2-selections-common"/>.</para>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300159
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300160 <section>
161 <figure id="sel-const-adjust">
162 <title>Size adjustments with constraint flags.</title>
163 <mediaobject>
164 <imageobject>
165 <imagedata fileref="constraints.png" format="PNG" />
166 </imageobject>
167 <textobject>
168 <phrase>Behaviour of rectangle adjustment for different constraint
169 flags.</phrase>
170 </textobject>
171 </mediaobject>
172 </figure>
173 </section>
174
175 <refsect1>
176 <table pgwide="1" frame="none" id="v4l2-selection">
177 <title>struct <structname>v4l2_selection</structname></title>
178 <tgroup cols="3">
179 &cs-str;
180 <tbody valign="top">
181 <row>
182 <entry>__u32</entry>
183 <entry><structfield>type</structfield></entry>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300184 <entry>Type of the buffer (from &v4l2-buf-type;).</entry>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300185 </row>
186 <row>
187 <entry>__u32</entry>
188 <entry><structfield>target</structfield></entry>
Sakari Ailus64b9ce82012-06-01 13:56:53 -0300189 <entry>Used to select between <link linkend="v4l2-selections-common"> cropping
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300190 and composing rectangles</link>.</entry>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300191 </row>
192 <row>
193 <entry>__u32</entry>
194 <entry><structfield>flags</structfield></entry>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300195 <entry>Flags controlling the selection rectangle adjustments, refer to
Sakari Ailus9fe75aa2012-06-13 16:01:10 -0300196 <link linkend="v4l2-selection-flags">selection flags</link>.</entry>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300197 </row>
198 <row>
199 <entry>&v4l2-rect;</entry>
200 <entry><structfield>r</structfield></entry>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300201 <entry>The selection rectangle.</entry>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300202 </row>
203 <row>
204 <entry>__u32</entry>
205 <entry><structfield>reserved[9]</structfield></entry>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300206 <entry>Reserved fields for future use.</entry>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300207 </row>
208 </tbody>
209 </tgroup>
210 </table>
211 </refsect1>
212
213 <refsect1>
214 &return-value;
215 <variablelist>
216 <varlistentry>
217 <term><errorcode>EINVAL</errorcode></term>
218 <listitem>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300219 <para>Given buffer type <structfield>type</structfield> or
220the selection target <structfield>target</structfield> is not supported,
221or the <structfield>flags</structfield> argument is not valid.</para>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300222 </listitem>
223 </varlistentry>
224 <varlistentry>
225 <term><errorcode>ERANGE</errorcode></term>
226 <listitem>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300227 <para>It is not possible to adjust &v4l2-rect; <structfield>
228r</structfield> rectangle to satisfy all contraints given in the
229<structfield>flags</structfield> argument.</para>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300230 </listitem>
231 </varlistentry>
232 <varlistentry>
233 <term><errorcode>EBUSY</errorcode></term>
234 <listitem>
Sylwester Nawrocki9080d5d2012-03-09 06:46:28 -0300235 <para>It is not possible to apply change of the selection rectangle
236at the moment. Usually because streaming is in progress.</para>
Tomasz Stanislawski8af49222011-08-19 07:00:04 -0300237 </listitem>
238 </varlistentry>
239 </variablelist>
240 </refsect1>
241
242</refentry>