1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix A. Function Reference"><link rel="prev" href="vidioc-g-priority.html" title="ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY"><link rel="next" href="vidioc-g-sliced-vbi-cap.html" title="ioctl VIDIOC_G_SLICED_VBI_CAP"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="vidioc-g-priority.html">Prev</a> </td><th width="60%" align="center">Appendix A. Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="vidioc-g-sliced-vbi-cap.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="vidioc-g-selection"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>VIDIOC_G_SELECTION, VIDIOC_S_SELECTION — Get or set one of the selection rectangles</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">ioctl</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">request</var>, </td></tr><tr><td> </td><td>struct v4l2_selection *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1115010956"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>fd</code></em></span></dt><dd><p>File descriptor returned by <a class="link" href="func-open.html" title="V4L2 open()"><code class="function">open()</code></a>.</p></dd><dt><span class="term"><em class="parameter"><code>request</code></em></span></dt><dd><p>VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</p></dd><dt><span class="term"><em class="parameter"><code>argp</code></em></span></dt><dd><p></p></dd></dl></div></div><div class="refsect1"><a name="idp1115087916"></a><h2>Description</h2><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Experimental</h3><p>This is an <a class="link" href="hist-v4l2.html#experimental" title="Experimental API Elements"> experimental </a> 2 interface and may change in the future.</p></div><p>The ioctls are used to query and configure selection rectangles.</p><p>To query the cropping (composing) rectangle set struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> 3<em class="structfield"><code> type </code></em> field to the respective buffer type. 4Do not use the multiplanar buffer types. Use <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE</code> 5instead of <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</code> and use 6<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT</code> instead of 7<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</code>. The next step is 8setting the value of struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> <em class="structfield"><code>target</code></em> field 9to <code class="constant">V4L2_SEL_TGT_CROP</code> (<code class="constant">V4L2_SEL_TGT_COMPOSE</code>). 10Please refer to table <a class="xref" href="apb.html#v4l2-selections-common" title="Common selection definitions">the section called “Common selection definitions”</a> or <a class="xref" href="selection-api.html" title="Experimental API for cropping, composing and scaling">the section called “Experimental API for cropping, composing and scaling”</a> 11for additional targets. The <em class="structfield"><code>flags</code></em> and <em class="structfield"><code>reserved 12</code></em> fields of struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> are ignored and they must be filled 13with zeros. The driver fills the rest of the structure or 14returns <span class="errorcode">EINVAL</span> error code if incorrect buffer type or target was used. If cropping 15(composing) is not supported then the active rectangle is not mutable and it is 16always equal to the bounds rectangle. Finally, the struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a> 17<em class="structfield"><code>r</code></em> rectangle is filled with the current cropping 18(composing) coordinates. The coordinates are expressed in driver-dependent 19units. The only exception are rectangles for images in raw formats, whose 20coordinates are always expressed in pixels.</p><p>To change the cropping (composing) rectangle set the struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> 21<em class="structfield"><code>type</code></em> field to the respective buffer type. Do not 22use multiplanar buffers. Use <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE</code> 23instead of <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</code>. Use 24<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT</code> instead of 25<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</code>. The next step is 26setting the value of struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> <em class="structfield"><code>target</code></em> to 27<code class="constant">V4L2_SEL_TGT_CROP</code> (<code class="constant">V4L2_SEL_TGT_COMPOSE</code>). 28Please refer to table <a class="xref" href="apb.html#v4l2-selections-common" title="Common selection definitions">the section called “Common selection definitions”</a> or <a class="xref" href="selection-api.html" title="Experimental API for cropping, composing and scaling">the section called “Experimental API for cropping, composing and scaling”</a> 29for additional targets. The struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a> <em class="structfield"><code>r</code></em> rectangle need to be 30set to the desired active area. Field struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> <em class="structfield"><code> reserved 31</code></em> is ignored and must be filled with zeros. The driver may adjust 32coordinates of the requested rectangle. An application may 33introduce constraints to control rounding behaviour. The struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> 34<em class="structfield"><code>flags</code></em> field must be set to one of the following: 35 36</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="constant">0</code> - The driver can adjust the rectangle size freely 37and shall choose a crop/compose rectangle as close as possible to the requested 38one.</p></li><li class="listitem"><p><code class="constant">V4L2_SEL_FLAG_GE</code> - The driver is not allowed to 39shrink the rectangle. The original rectangle must lay inside the adjusted 40one.</p></li><li class="listitem"><p><code class="constant">V4L2_SEL_FLAG_LE</code> - The driver is not allowed to 41enlarge the rectangle. The adjusted rectangle must lay inside the original 42one.</p></li><li class="listitem"><p><code class="constant">V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</code> - The driver 43must choose the size exactly the same as in the requested rectangle.</p></li></ul></div><p> 44 45Please refer to <a class="xref" href="vidioc-g-selection.html#sel-const-adjust" title="Figure A.1. Size adjustments with constraint flags.">Figure A.1, “Size adjustments with constraint flags.”</a>. 46 47</p><p> The driver may have to adjusts the requested dimensions against hardware 48limits and other parts as the pipeline, i.e. the bounds given by the 49capture/output window or TV display. The closest possible values of horizontal 50and vertical offset and sizes are chosen according to following priority: 51 52</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>Satisfy constraints from struct <a class="link" href="vidioc-g-selection.html#v4l2-selection" title="Table A.84. struct v4l2_selection">v4l2_selection</a> <em class="structfield"><code>flags</code></em>.</p></li><li class="listitem"><p>Adjust width, height, left, and top to hardware limits and alignments.</p></li><li class="listitem"><p>Keep center of adjusted rectangle as close as possible to the original one.</p></li><li class="listitem"><p>Keep width and height as close as possible to original ones.</p></li><li class="listitem"><p>Keep horizontal and vertical offset as close as possible to original ones.</p></li></ol></div><p> 53 54On success the struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a> <em class="structfield"><code>r</code></em> field contains 55the adjusted rectangle. When the parameters are unsuitable the application may 56modify the cropping (composing) or image parameters and repeat the cycle until 57satisfactory parameters have been negotiated. If constraints flags have to be 58violated at then ERANGE is returned. The error indicates that <span class="emphasis"><em>there 59exist no rectangle</em></span> that satisfies the constraints.</p><p>Selection targets and flags are documented in <a class="xref" href="apb.html#v4l2-selections-common" title="Common selection definitions">the section called “Common selection definitions”</a>.</p><p> 60 </p><div class="figure"><a name="sel-const-adjust"></a><p class="title"><b>Figure A.1. Size adjustments with constraint flags.</b></p><div class="figure-contents"><div class="mediaobject"><img src="constraints.png" alt="Behaviour of rectangle adjustment for different constraint flags."></div></div></div><p><br class="figure-break"> 61 </p><p> 62 </p><div class="table"><a name="v4l2-selection"></a><p class="title"><b>Table A.84. struct <span class="structname">v4l2_selection</span></b></p><div class="table-contents"><table summary="struct v4l2_selection" width="100%" border="0"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><tbody valign="top"><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>type</code></em></td><td valign="top">Type of the buffer (from enum <a class="link" href="buffer.html#v4l2-buf-type" title="Table 3.3. enum v4l2_buf_type">v4l2_buf_type</a>).</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>target</code></em></td><td valign="top">Used to select between <a class="link" href="apb.html#v4l2-selections-common" title="Common selection definitions"> cropping 63 and composing rectangles</a>.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>flags</code></em></td><td valign="top">Flags controlling the selection rectangle adjustments, refer to 64 <a class="link" href="apb.html#v4l2-selection-flags" title="Selection flags">selection flags</a>.</td></tr><tr><td valign="top">struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a></td><td valign="top"><em class="structfield"><code>r</code></em></td><td valign="top">The selection rectangle.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>reserved[9]</code></em></td><td valign="top">Reserved fields for future use.</td></tr></tbody></table></div></div><p><br class="table-break"> 65 </p></div><div class="refsect1"><a name="idp1115121980"></a><h2>Return Value</h2><p>On success <span class="returnvalue">0</span> is returned, on error <span class="returnvalue">-1</span> and the <code class="varname">errno</code> variable is set appropriately. The generic error codes are described at the <a class="link" href="gen_errors.html#gen-errors" title="Table 19.1. Generic error codes">Generic Error Codes</a> chapter.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorcode">EINVAL</span></span></dt><dd><p>Given buffer type <em class="structfield"><code>type</code></em> or 66the selection target <em class="structfield"><code>target</code></em> is not supported, 67or the <em class="structfield"><code>flags</code></em> argument is not valid.</p></dd><dt><span class="term"><span class="errorcode">ERANGE</span></span></dt><dd><p>It is not possible to adjust struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a> <em class="structfield"><code> 68r</code></em> rectangle to satisfy all contraints given in the 69<em class="structfield"><code>flags</code></em> argument.</p></dd><dt><span class="term"><span class="errorcode">EBUSY</span></span></dt><dd><p>It is not possible to apply change of the selection rectangle 70at the moment. Usually because streaming is in progress.</p></dd></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="vidioc-g-priority.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="vidioc-g-sliced-vbi-cap.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ioctl VIDIOC_G_SLICED_VBI_CAP</td></tr></table></div></body></html> 71