Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 | |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 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 |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 67 | setting the value of &v4l2-selection; <structfield>target</structfield> field |
Sylwester Nawrocki | c133482 | 2012-05-20 11:17:12 -0300 | [diff] [blame] | 68 | to <constant> V4L2_SEL_TGT_CROP </constant> (<constant> |
| 69 | V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref |
Sakari Ailus | 64b9ce8 | 2012-06-01 13:56:53 -0300 | [diff] [blame] | 70 | linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 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 |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 76 | always equal to the bounds rectangle. Finally, the &v4l2-rect; |
| 77 | <structfield>r</structfield> rectangle is filled with the current cropping |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 | |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 82 | <para> To change the cropping (composing) rectangle set the &v4l2-selection; |
| 83 | <structfield>type</structfield> field to the respective buffer type. Do not |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 88 | setting the value of &v4l2-selection; <structfield>target</structfield> to |
Sylwester Nawrocki | c133482 | 2012-05-20 11:17:12 -0300 | [diff] [blame] | 89 | <constant>V4L2_SEL_TGT_CROP</constant> (<constant> |
| 90 | V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref |
Sakari Ailus | 64b9ce8 | 2012-06-01 13:56:53 -0300 | [diff] [blame] | 91 | linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 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: |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 132 | <para>Satisfy constraints from &v4l2-selection; <structfield>flags</structfield>.</para> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 | |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 148 | On success the &v4l2-rect; <structfield>r</structfield> field contains |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 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 | |
Sakari Ailus | 9fe75aa | 2012-06-13 16:01:10 -0300 | [diff] [blame] | 157 | <para>Selection targets and flags are documented in <xref |
Sakari Ailus | 64b9ce8 | 2012-06-01 13:56:53 -0300 | [diff] [blame] | 158 | linkend="v4l2-selections-common"/>.</para> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 159 | |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 160 | <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 Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 184 | <entry>Type of the buffer (from &v4l2-buf-type;).</entry> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 185 | </row> |
| 186 | <row> |
| 187 | <entry>__u32</entry> |
| 188 | <entry><structfield>target</structfield></entry> |
Sakari Ailus | 64b9ce8 | 2012-06-01 13:56:53 -0300 | [diff] [blame] | 189 | <entry>Used to select between <link linkend="v4l2-selections-common"> cropping |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 190 | and composing rectangles</link>.</entry> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 191 | </row> |
| 192 | <row> |
| 193 | <entry>__u32</entry> |
| 194 | <entry><structfield>flags</structfield></entry> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 195 | <entry>Flags controlling the selection rectangle adjustments, refer to |
Sakari Ailus | 9fe75aa | 2012-06-13 16:01:10 -0300 | [diff] [blame] | 196 | <link linkend="v4l2-selection-flags">selection flags</link>.</entry> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 197 | </row> |
| 198 | <row> |
| 199 | <entry>&v4l2-rect;</entry> |
| 200 | <entry><structfield>r</structfield></entry> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 201 | <entry>The selection rectangle.</entry> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 202 | </row> |
| 203 | <row> |
| 204 | <entry>__u32</entry> |
| 205 | <entry><structfield>reserved[9]</structfield></entry> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 206 | <entry>Reserved fields for future use.</entry> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 207 | </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 Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 219 | <para>Given buffer type <structfield>type</structfield> or |
| 220 | the selection target <structfield>target</structfield> is not supported, |
| 221 | or the <structfield>flags</structfield> argument is not valid.</para> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 222 | </listitem> |
| 223 | </varlistentry> |
| 224 | <varlistentry> |
| 225 | <term><errorcode>ERANGE</errorcode></term> |
| 226 | <listitem> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 227 | <para>It is not possible to adjust &v4l2-rect; <structfield> |
| 228 | r</structfield> rectangle to satisfy all contraints given in the |
| 229 | <structfield>flags</structfield> argument.</para> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 230 | </listitem> |
| 231 | </varlistentry> |
| 232 | <varlistentry> |
| 233 | <term><errorcode>EBUSY</errorcode></term> |
| 234 | <listitem> |
Sylwester Nawrocki | 9080d5d | 2012-03-09 06:46:28 -0300 | [diff] [blame] | 235 | <para>It is not possible to apply change of the selection rectangle |
| 236 | at the moment. Usually because streaming is in progress.</para> |
Tomasz Stanislawski | 8af4922 | 2011-08-19 07:00:04 -0300 | [diff] [blame] | 237 | </listitem> |
| 238 | </varlistentry> |
| 239 | </variablelist> |
| 240 | </refsect1> |
| 241 | |
| 242 | </refentry> |