vidioc-g-selection.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 &v4l2-selection;
  53. <structfield> type </structfield> field to the respective buffer type.
  54. Do not 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 the value of &v4l2-selection; <structfield>target</structfield> field
  59. to <constant> V4L2_SEL_TGT_CROP </constant> (<constant>
  60. V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref
  61. linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional
  62. targets. The <structfield>flags</structfield> and <structfield>reserved
  63. </structfield> fields of &v4l2-selection; are ignored and they must be filled
  64. 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, the &v4l2-rect;
  68. <structfield>r</structfield> rectangle 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 the &v4l2-selection;
  73. <structfield>type</structfield> field 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 the value of &v4l2-selection; <structfield>target</structfield> to
  79. <constant>V4L2_SEL_TGT_CROP</constant> (<constant>
  80. V4L2_SEL_TGT_COMPOSE </constant>). Please refer to table <xref
  81. linkend="v4l2-selections-common" /> or <xref linkend="selection-api" /> for additional
  82. targets. The &v4l2-rect; <structfield>r</structfield> rectangle need to be
  83. set to the desired active area. Field &v4l2-selection; <structfield> reserved
  84. </structfield> is ignored and must be filled with zeros. The driver may adjust
  85. coordinates of the requested rectangle. An application may
  86. introduce constraints to control rounding behaviour. The &v4l2-selection;
  87. <structfield>flags</structfield> field must be set to one of the following:
  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 &v4l2-selection; <structfield>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 &v4l2-rect; <structfield>r</structfield> field 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. <para>Selection targets and flags are documented in <xref
  139. linkend="v4l2-selections-common"/>.</para>
  140. <para>
  141. <figure id="sel-const-adjust">
  142. <title>Size adjustments with constraint flags.</title>
  143. <mediaobject>
  144. <imageobject>
  145. <imagedata fileref="constraints.png" format="PNG" />
  146. </imageobject>
  147. <textobject>
  148. <phrase>Behaviour of rectangle adjustment for different constraint
  149. flags.</phrase>
  150. </textobject>
  151. </mediaobject>
  152. </figure>
  153. </para>
  154. <para>
  155. <table pgwide="1" frame="none" id="v4l2-selection">
  156. <title>struct <structname>v4l2_selection</structname></title>
  157. <tgroup cols="3">
  158. &cs-str;
  159. <tbody valign="top">
  160. <row>
  161. <entry>__u32</entry>
  162. <entry><structfield>type</structfield></entry>
  163. <entry>Type of the buffer (from &v4l2-buf-type;).</entry>
  164. </row>
  165. <row>
  166. <entry>__u32</entry>
  167. <entry><structfield>target</structfield></entry>
  168. <entry>Used to select between <link linkend="v4l2-selections-common"> cropping
  169. and composing rectangles</link>.</entry>
  170. </row>
  171. <row>
  172. <entry>__u32</entry>
  173. <entry><structfield>flags</structfield></entry>
  174. <entry>Flags controlling the selection rectangle adjustments, refer to
  175. <link linkend="v4l2-selection-flags">selection flags</link>.</entry>
  176. </row>
  177. <row>
  178. <entry>&v4l2-rect;</entry>
  179. <entry><structfield>r</structfield></entry>
  180. <entry>The selection rectangle.</entry>
  181. </row>
  182. <row>
  183. <entry>__u32</entry>
  184. <entry><structfield>reserved[9]</structfield></entry>
  185. <entry>Reserved fields for future use.</entry>
  186. </row>
  187. </tbody>
  188. </tgroup>
  189. </table>
  190. </para>
  191. </refsect1>
  192. <refsect1>
  193. &return-value;
  194. <variablelist>
  195. <varlistentry>
  196. <term><errorcode>EINVAL</errorcode></term>
  197. <listitem>
  198. <para>Given buffer type <structfield>type</structfield> or
  199. the selection target <structfield>target</structfield> is not supported,
  200. or the <structfield>flags</structfield> argument is not valid.</para>
  201. </listitem>
  202. </varlistentry>
  203. <varlistentry>
  204. <term><errorcode>ERANGE</errorcode></term>
  205. <listitem>
  206. <para>It is not possible to adjust &v4l2-rect; <structfield>
  207. r</structfield> rectangle to satisfy all contraints given in the
  208. <structfield>flags</structfield> argument.</para>
  209. </listitem>
  210. </varlistentry>
  211. <varlistentry>
  212. <term><errorcode>EBUSY</errorcode></term>
  213. <listitem>
  214. <para>It is not possible to apply change of the selection rectangle
  215. at the moment. Usually because streaming is in progress.</para>
  216. </listitem>
  217. </varlistentry>
  218. </variablelist>
  219. </refsect1>
  220. </refentry>