vidioc-g-selection.xml 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<refentry id="vidioc-g-selection">

  <refmeta>
    <refentrytitle>ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</refentrytitle>
    &manvol;
  </refmeta>

  <refnamediv>
    <refname>VIDIOC_G_SELECTION</refname>
    <refname>VIDIOC_S_SELECTION</refname>
    <refpurpose>Get or set one of the selection rectangles</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <funcsynopsis>
      <funcprototype>
	<funcdef>int <function>ioctl</function></funcdef>
	<paramdef>int <parameter>fd</parameter></paramdef>
	<paramdef>int <parameter>request</parameter></paramdef>
	<paramdef>struct v4l2_selection *<parameter>argp</parameter></paramdef>
      </funcprototype>
    </funcsynopsis>
  </refsynopsisdiv>

  <refsect1>
    <title>Arguments</title>

    <variablelist>
      <varlistentry>
	<term><parameter>fd</parameter></term>
	<listitem>
	  <para>&fd;</para>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter>request</parameter></term>
	<listitem>
	  <para>VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</para>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter>argp</parameter></term>
	<listitem>
	  <para></para>
	</listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1>
    <title>Description</title>

    <note>
      <title>Experimental</title>
      <para>This is an <link linkend="experimental"> experimental </link>
      interface and may change in the future.</para>
    </note>

    <para>The ioctls are used to query and configure selection rectangles.</para>

61 62 63
<para> To query the cropping (composing) rectangle set &v4l2-selection;
<structfield> type </structfield> field to the respective buffer type.
Do not use multiplanar buffers.  Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
64 65 66
</constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
</constant>.  Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
<constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>.  The next step is
67
setting the value of &v4l2-selection; <structfield>target</structfield> field
68 69
to <constant> V4L2_SEL_TGT_CROP </constant> (<constant>
V4L2_SEL_TGT_COMPOSE </constant>).  Please refer to table <xref
70
linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
71 72 73
targets.  The <structfield>flags</structfield> and <structfield>reserved
</structfield> fields of &v4l2-selection; are ignored and they must be filled
with zeros.  The driver fills the rest of the structure or
74 75
returns &EINVAL; if incorrect buffer type or target was used. If cropping
(composing) is not supported then the active rectangle is not mutable and it is
76 77
always equal to the bounds rectangle.  Finally, the &v4l2-rect;
<structfield>r</structfield> rectangle is filled with the current cropping
78 79 80 81
(composing) coordinates. The coordinates are expressed in driver-dependent
units. The only exception are rectangles for images in raw formats, whose
coordinates are always expressed in pixels.  </para>

82 83
<para> To change the cropping (composing) rectangle set the &v4l2-selection;
<structfield>type</structfield> field to the respective buffer type.  Do not
84 85 86 87
use multiplanar buffers.  Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
</constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
</constant>.  Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
<constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>.  The next step is
88
setting the value of &v4l2-selection; <structfield>target</structfield> to
89 90
<constant>V4L2_SEL_TGT_CROP</constant> (<constant>
V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref
91
linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
92 93 94 95 96 97
targets.  The &v4l2-rect; <structfield>r</structfield> rectangle need to be
set to the desired active area. Field &v4l2-selection; <structfield> reserved
</structfield> is ignored and must be filled with zeros.  The driver may adjust
coordinates of the requested rectangle. An application may
introduce constraints to control rounding behaviour. The &v4l2-selection;
<structfield>flags</structfield> field must be set to one of the following:
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

<itemizedlist>
  <listitem>
<para><constant>0</constant> - The driver can adjust the rectangle size freely
and shall choose a crop/compose rectangle as close as possible to the requested
one.</para>
  </listitem>
  <listitem>
<para><constant>V4L2_SEL_FLAG_GE</constant> - The driver is not allowed to
shrink the rectangle.  The original rectangle must lay inside the adjusted
one.</para>
  </listitem>
  <listitem>
<para><constant>V4L2_SEL_FLAG_LE</constant> - The driver is not allowed to
enlarge the rectangle.  The adjusted rectangle must lay inside the original
one.</para>
  </listitem>
  <listitem>
<para><constant>V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</constant> - The driver
must choose the size exactly the same as in the requested rectangle.</para>
  </listitem>
</itemizedlist>

Please refer to <xref linkend="sel-const-adjust" />.

</para>

<para> The driver may have to adjusts the requested dimensions against hardware
limits and other parts as the pipeline, i.e. the bounds given by the
capture/output window or TV display. The closest possible values of horizontal
and vertical offset and sizes are chosen according to following priority:

<orderedlist>
  <listitem>
132
    <para>Satisfy constraints from &v4l2-selection; <structfield>flags</structfield>.</para>
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  </listitem>
  <listitem>
    <para>Adjust width, height, left, and top to hardware limits and alignments.</para>
  </listitem>
  <listitem>
    <para>Keep center of adjusted rectangle as close as possible to the original one.</para>
  </listitem>
  <listitem>
    <para>Keep width and height as close as possible to original ones.</para>
  </listitem>
  <listitem>
    <para>Keep horizontal and vertical offset as close as possible to original ones.</para>
  </listitem>
</orderedlist>

148
On success the &v4l2-rect; <structfield>r</structfield> field contains
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
the adjusted rectangle. When the parameters are unsuitable the application may
modify the cropping (composing) or image parameters and repeat the cycle until
satisfactory parameters have been negotiated. If constraints flags have to be
violated at then ERANGE is returned. The error indicates that <emphasis> there
exist no rectangle </emphasis> that satisfies the constraints.</para>

  </refsect1>

  <refsect1>
    <table frame="none" pgwide="1" id="v4l2-sel-target">
      <title>Selection targets.</title>
      <tgroup cols="3">
	&cs-def;
	<tbody valign="top">
	  <row>
164
            <entry><constant>V4L2_SEL_TGT_CROP</constant></entry>
165 166
            <entry>0x0000</entry>
            <entry>The area that is currently cropped by hardware.</entry>
167 168 169
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_TGT_CROP_DEFAULT</constant></entry>
170 171
            <entry>0x0001</entry>
            <entry>Suggested cropping rectangle that covers the "whole picture".</entry>
172 173 174
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_TGT_CROP_BOUNDS</constant></entry>
175 176
            <entry>0x0002</entry>
            <entry>Limits for the cropping rectangle.</entry>
177 178
	  </row>
	  <row>
179
            <entry><constant>V4L2_SEL_TGT_COMPOSE</constant></entry>
180 181
            <entry>0x0100</entry>
            <entry>The area to which data is composed by hardware.</entry>
182 183 184
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_TGT_COMPOSE_DEFAULT</constant></entry>
185 186
            <entry>0x0101</entry>
            <entry>Suggested composing rectangle that covers the "whole picture".</entry>
187 188 189
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
190 191
            <entry>0x0102</entry>
            <entry>Limits for the composing rectangle.</entry>
192 193 194
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_TGT_COMPOSE_PADDED</constant></entry>
195
            <entry>0x0103</entry>
196 197
            <entry>The active area and all padding pixels that are inserted or
	      modified by hardware.</entry>
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	  </row>
	</tbody>
      </tgroup>
    </table>
  </refsect1>

  <refsect1>
    <table frame="none" pgwide="1" id="v4l2-sel-flags">
      <title>Selection constraint flags</title>
      <tgroup cols="3">
	&cs-def;
	<tbody valign="top">
	  <row>
            <entry><constant>V4L2_SEL_FLAG_GE</constant></entry>
            <entry>0x00000001</entry>
213 214
            <entry>Indicates that the adjusted rectangle must contain the original
	    &v4l2-selection; <structfield>r</structfield> rectangle.</entry>
215 216 217 218
	  </row>
	  <row>
            <entry><constant>V4L2_SEL_FLAG_LE</constant></entry>
            <entry>0x00000002</entry>
219 220
            <entry>Indicates that the adjusted rectangle must be inside the original
	    &v4l2-rect; <structfield>r</structfield> rectangle.</entry>
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
	  </row>
	</tbody>
      </tgroup>
    </table>
  </refsect1>

    <section>
      <figure id="sel-const-adjust">
	<title>Size adjustments with constraint flags.</title>
	<mediaobject>
	  <imageobject>
	    <imagedata fileref="constraints.png" format="PNG" />
	  </imageobject>
	  <textobject>
	    <phrase>Behaviour of rectangle adjustment for different constraint
            flags.</phrase>
	  </textobject>
	</mediaobject>
      </figure>
    </section>

  <refsect1>
    <table pgwide="1" frame="none" id="v4l2-selection">
      <title>struct <structname>v4l2_selection</structname></title>
      <tgroup cols="3">
	&cs-str;
	<tbody valign="top">
	  <row>
	    <entry>__u32</entry>
	    <entry><structfield>type</structfield></entry>
251
	    <entry>Type of the buffer (from &v4l2-buf-type;).</entry>
252 253 254 255
	  </row>
	  <row>
	    <entry>__u32</entry>
	    <entry><structfield>target</structfield></entry>
256 257
            <entry>Used to select between <link linkend="v4l2-sel-target"> cropping
	    and composing rectangles</link>.</entry>
258 259 260 261
	  </row>
	  <row>
	    <entry>__u32</entry>
	    <entry><structfield>flags</structfield></entry>
262 263
            <entry>Flags controlling the selection rectangle adjustments, refer to
	    <link linkend="v4l2-sel-flags">selection flags</link>.</entry>
264 265 266 267
	  </row>
	  <row>
	    <entry>&v4l2-rect;</entry>
	    <entry><structfield>r</structfield></entry>
268
	    <entry>The selection rectangle.</entry>
269 270 271 272
	  </row>
	  <row>
	    <entry>__u32</entry>
	    <entry><structfield>reserved[9]</structfield></entry>
273
	    <entry>Reserved fields for future use.</entry>
274 275 276 277 278 279 280 281 282 283 284 285
	  </row>
	</tbody>
      </tgroup>
    </table>
  </refsect1>

  <refsect1>
    &return-value;
    <variablelist>
      <varlistentry>
	<term><errorcode>EINVAL</errorcode></term>
	<listitem>
286 287 288
	  <para>Given buffer type <structfield>type</structfield> or
the selection target <structfield>target</structfield> is not supported,
or the <structfield>flags</structfield> argument is not valid.</para>
289 290 291 292 293
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><errorcode>ERANGE</errorcode></term>
	<listitem>
294 295 296
	  <para>It is not possible to adjust &v4l2-rect; <structfield>
r</structfield> rectangle to satisfy all contraints given in the
<structfield>flags</structfield> argument.</para>
297 298 299 300 301
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><errorcode>EBUSY</errorcode></term>
	<listitem>
302 303
	  <para>It is not possible to apply change of the selection rectangle
at the moment. Usually because streaming is in progress.</para>
304 305 306 307 308 309
	</listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

</refentry>