vidioc-g-selection.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <refentry id="vidioc-g-selection">
  2. <refmeta>
  3. <refentrytitle>ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>VIDIOC_G_SELECTION</refname>
  8. <refname>VIDIOC_S_SELECTION</refname>
  9. <refpurpose>Get or set one of the selection rectangles</refpurpose>
  10. </refnamediv>
  11. <refsynopsisdiv>
  12. <funcsynopsis>
  13. <funcprototype>
  14. <funcdef>int <function>ioctl</function></funcdef>
  15. <paramdef>int <parameter>fd</parameter></paramdef>
  16. <paramdef>int <parameter>request</parameter></paramdef>
  17. <paramdef>struct v4l2_selection *<parameter>argp</parameter></paramdef>
  18. </funcprototype>
  19. </funcsynopsis>
  20. </refsynopsisdiv>
  21. <refsect1>
  22. <title>Arguments</title>
  23. <variablelist>
  24. <varlistentry>
  25. <term><parameter>fd</parameter></term>
  26. <listitem>
  27. <para>&fd;</para>
  28. </listitem>
  29. </varlistentry>
  30. <varlistentry>
  31. <term><parameter>request</parameter></term>
  32. <listitem>
  33. <para>VIDIOC_G_SELECTION, VIDIOC_S_SELECTION</para>
  34. </listitem>
  35. </varlistentry>
  36. <varlistentry>
  37. <term><parameter>argp</parameter></term>
  38. <listitem>
  39. <para></para>
  40. </listitem>
  41. </varlistentry>
  42. </variablelist>
  43. </refsect1>
  44. <refsect1>
  45. <title>Description</title>
  46. <note>
  47. <title>Experimental</title>
  48. <para>This is an <link linkend="experimental"> experimental </link>
  49. interface and may change in the future.</para>
  50. </note>
  51. <para>The ioctls are used to query and configure selection rectangles.</para>
  52. <para> To query the cropping (composing) rectangle set <structfield>
  53. &v4l2-selection;::type </structfield> to the respective buffer type. Do not
  54. use multiplanar buffers. Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
  55. </constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
  56. </constant>. Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
  57. <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>. The next step is
  58. setting <structfield> &v4l2-selection;::target </structfield> to value
  59. <constant> V4L2_SEL_TGT_CROP_ACTIVE </constant> (<constant>
  60. V4L2_SEL_TGT_COMPOSE_ACTIVE </constant>). Please refer to table <xref
  61. linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
  62. targets. Fields <structfield> &v4l2-selection;::flags </structfield> and
  63. <structfield> &v4l2-selection;::reserved </structfield> are ignored and they
  64. must be filled with zeros. The driver fills the rest of the structure or
  65. returns &EINVAL; if incorrect buffer type or target was used. If cropping
  66. (composing) is not supported then the active rectangle is not mutable and it is
  67. always equal to the bounds rectangle. Finally, structure <structfield>
  68. &v4l2-selection;::r </structfield> is filled with the current cropping
  69. (composing) coordinates. The coordinates are expressed in driver-dependent
  70. units. The only exception are rectangles for images in raw formats, whose
  71. coordinates are always expressed in pixels. </para>
  72. <para> To change the cropping (composing) rectangle set <structfield>
  73. &v4l2-selection;::type </structfield> to the respective buffer type. Do not
  74. use multiplanar buffers. Use <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE
  75. </constant> instead of <constant> V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
  76. </constant>. Use <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT </constant> instead of
  77. <constant> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE </constant>. The next step is
  78. setting <structfield> &v4l2-selection;::target </structfield> to value
  79. <constant> V4L2_SEL_TGT_CROP_ACTIVE </constant> (<constant>
  80. V4L2_SEL_TGT_COMPOSE_ACTIVE </constant>). Please refer to table <xref
  81. linkend="v4l2-sel-target" /> or <xref linkend="selection-api" /> for additional
  82. targets. Set desired active area into the field <structfield>
  83. &v4l2-selection;::r </structfield>. Field <structfield>
  84. &v4l2-selection;::reserved </structfield> is ignored and must be filled with
  85. zeros. The driver may adjust the rectangle coordinates. An application may
  86. introduce constraints to control rounding behaviour. Set the field
  87. <structfield> &v4l2-selection;::flags </structfield> to one of values:
  88. <itemizedlist>
  89. <listitem>
  90. <para><constant>0</constant> - The driver can adjust the rectangle size freely
  91. and shall choose a crop/compose rectangle as close as possible to the requested
  92. one.</para>
  93. </listitem>
  94. <listitem>
  95. <para><constant>V4L2_SEL_FLAG_GE</constant> - The driver is not allowed to
  96. shrink the rectangle. The original rectangle must lay inside the adjusted
  97. one.</para>
  98. </listitem>
  99. <listitem>
  100. <para><constant>V4L2_SEL_FLAG_LE</constant> - The driver is not allowed to
  101. enlarge the rectangle. The adjusted rectangle must lay inside the original
  102. one.</para>
  103. </listitem>
  104. <listitem>
  105. <para><constant>V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</constant> - The driver
  106. must choose the size exactly the same as in the requested rectangle.</para>
  107. </listitem>
  108. </itemizedlist>
  109. Please refer to <xref linkend="sel-const-adjust" />.
  110. </para>
  111. <para> The driver may have to adjusts the requested dimensions against hardware
  112. limits and other parts as the pipeline, i.e. the bounds given by the
  113. capture/output window or TV display. The closest possible values of horizontal
  114. and vertical offset and sizes are chosen according to following priority:
  115. <orderedlist>
  116. <listitem>
  117. <para>Satisfy constraints from <structfield>&v4l2-selection;::flags</structfield>.</para>
  118. </listitem>
  119. <listitem>
  120. <para>Adjust width, height, left, and top to hardware limits and alignments.</para>
  121. </listitem>
  122. <listitem>
  123. <para>Keep center of adjusted rectangle as close as possible to the original one.</para>
  124. </listitem>
  125. <listitem>
  126. <para>Keep width and height as close as possible to original ones.</para>
  127. </listitem>
  128. <listitem>
  129. <para>Keep horizontal and vertical offset as close as possible to original ones.</para>
  130. </listitem>
  131. </orderedlist>
  132. On success the field <structfield> &v4l2-selection;::r </structfield> contains
  133. the adjusted rectangle. When the parameters are unsuitable the application may
  134. modify the cropping (composing) or image parameters and repeat the cycle until
  135. satisfactory parameters have been negotiated. If constraints flags have to be
  136. violated at then ERANGE is returned. The error indicates that <emphasis> there
  137. exist no rectangle </emphasis> that satisfies the constraints.</para>
  138. </refsect1>
  139. <refsect1>
  140. <table frame="none" pgwide="1" id="v4l2-sel-target">
  141. <title>Selection targets.</title>
  142. <tgroup cols="3">
  143. &cs-def;
  144. <tbody valign="top">
  145. <row>
  146. <entry><constant>V4L2_SEL_TGT_CROP_ACTIVE</constant></entry>
  147. <entry>0</entry>
  148. <entry>area that is currently cropped by hardware</entry>
  149. </row>
  150. <row>
  151. <entry><constant>V4L2_SEL_TGT_CROP_DEFAULT</constant></entry>
  152. <entry>1</entry>
  153. <entry>suggested cropping rectangle that covers the "whole picture"</entry>
  154. </row>
  155. <row>
  156. <entry><constant>V4L2_SEL_TGT_CROP_BOUNDS</constant></entry>
  157. <entry>2</entry>
  158. <entry>limits for the cropping rectangle</entry>
  159. </row>
  160. <row>
  161. <entry><constant>V4L2_SEL_TGT_COMPOSE_ACTIVE</constant></entry>
  162. <entry>256</entry>
  163. <entry>area to which data are composed by hardware</entry>
  164. </row>
  165. <row>
  166. <entry><constant>V4L2_SEL_TGT_COMPOSE_DEFAULT</constant></entry>
  167. <entry>257</entry>
  168. <entry>suggested composing rectangle that covers the "whole picture"</entry>
  169. </row>
  170. <row>
  171. <entry><constant>V4L2_SEL_TGT_COMPOSE_BOUNDS</constant></entry>
  172. <entry>258</entry>
  173. <entry>limits for the composing rectangle</entry>
  174. </row>
  175. <row>
  176. <entry><constant>V4L2_SEL_TGT_COMPOSE_PADDED</constant></entry>
  177. <entry>259</entry>
  178. <entry>the active area and all padding pixels that are inserted or modified by the hardware</entry>
  179. </row>
  180. </tbody>
  181. </tgroup>
  182. </table>
  183. </refsect1>
  184. <refsect1>
  185. <table frame="none" pgwide="1" id="v4l2-sel-flags">
  186. <title>Selection constraint flags</title>
  187. <tgroup cols="3">
  188. &cs-def;
  189. <tbody valign="top">
  190. <row>
  191. <entry><constant>V4L2_SEL_FLAG_GE</constant></entry>
  192. <entry>0x00000001</entry>
  193. <entry>indicate that adjusted rectangle must contain a rectangle from <structfield>&v4l2-selection;::r</structfield></entry>
  194. </row>
  195. <row>
  196. <entry><constant>V4L2_SEL_FLAG_LE</constant></entry>
  197. <entry>0x00000002</entry>
  198. <entry>indicate that adjusted rectangle must be inside a rectangle from <structfield>&v4l2-selection;::r</structfield></entry>
  199. </row>
  200. </tbody>
  201. </tgroup>
  202. </table>
  203. </refsect1>
  204. <section>
  205. <figure id="sel-const-adjust">
  206. <title>Size adjustments with constraint flags.</title>
  207. <mediaobject>
  208. <imageobject>
  209. <imagedata fileref="constraints.png" format="PNG" />
  210. </imageobject>
  211. <textobject>
  212. <phrase>Behaviour of rectangle adjustment for different constraint
  213. flags.</phrase>
  214. </textobject>
  215. </mediaobject>
  216. </figure>
  217. </section>
  218. <refsect1>
  219. <table pgwide="1" frame="none" id="v4l2-selection">
  220. <title>struct <structname>v4l2_selection</structname></title>
  221. <tgroup cols="3">
  222. &cs-str;
  223. <tbody valign="top">
  224. <row>
  225. <entry>__u32</entry>
  226. <entry><structfield>type</structfield></entry>
  227. <entry>Type of the buffer (from &v4l2-buf-type;)</entry>
  228. </row>
  229. <row>
  230. <entry>__u32</entry>
  231. <entry><structfield>target</structfield></entry>
  232. <entry>used to select between <link linkend="v4l2-sel-target"> cropping and composing rectangles </link></entry>
  233. </row>
  234. <row>
  235. <entry>__u32</entry>
  236. <entry><structfield>flags</structfield></entry>
  237. <entry>control over coordinates adjustments, refer to <link linkend="v4l2-sel-flags">selection flags</link></entry>
  238. </row>
  239. <row>
  240. <entry>&v4l2-rect;</entry>
  241. <entry><structfield>r</structfield></entry>
  242. <entry>selection rectangle</entry>
  243. </row>
  244. <row>
  245. <entry>__u32</entry>
  246. <entry><structfield>reserved[9]</structfield></entry>
  247. <entry>Reserved fields for future use</entry>
  248. </row>
  249. </tbody>
  250. </tgroup>
  251. </table>
  252. </refsect1>
  253. <refsect1>
  254. &return-value;
  255. <variablelist>
  256. <varlistentry>
  257. <term><errorcode>EINVAL</errorcode></term>
  258. <listitem>
  259. <para>The buffer <structfield> &v4l2-selection;::type </structfield>
  260. or <structfield> &v4l2-selection;::target </structfield> is not supported, or
  261. the <structfield> &v4l2-selection;::flags </structfield> are invalid.</para>
  262. </listitem>
  263. </varlistentry>
  264. <varlistentry>
  265. <term><errorcode>ERANGE</errorcode></term>
  266. <listitem>
  267. <para>it is not possible to adjust a rectangle <structfield>
  268. &v4l2-selection;::r </structfield> that satisfies all contraints from
  269. <structfield> &v4l2-selection;::flags </structfield>.</para>
  270. </listitem>
  271. </varlistentry>
  272. <varlistentry>
  273. <term><errorcode>EBUSY</errorcode></term>
  274. <listitem>
  275. <para>it is not possible to apply change of selection rectangle at the moment.
  276. Usually because streaming is in progress.</para>
  277. </listitem>
  278. </varlistentry>
  279. </variablelist>
  280. </refsect1>
  281. </refentry>