vidioc-g-selection.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 the multiplanar buffer types. Use <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant>
  55. instead of <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</constant> and use
  56. <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>V4L2_SEL_TGT_COMPOSE</constant>).
  60. Please refer to table <xref linkend="v4l2-selections-common" /> or <xref linkend="selection-api" />
  61. for additional targets. The <structfield>flags</structfield> and <structfield>reserved
  62. </structfield> fields of &v4l2-selection; are ignored and they must be filled
  63. with zeros. The driver fills the rest of the structure or
  64. returns &EINVAL; if incorrect buffer type or target was used. If cropping
  65. (composing) is not supported then the active rectangle is not mutable and it is
  66. always equal to the bounds rectangle. Finally, the &v4l2-rect;
  67. <structfield>r</structfield> rectangle is filled with the current cropping
  68. (composing) coordinates. The coordinates are expressed in driver-dependent
  69. units. The only exception are rectangles for images in raw formats, whose
  70. coordinates are always expressed in pixels.</para>
  71. <para>To change the cropping (composing) rectangle set the &v4l2-selection;
  72. <structfield>type</structfield> field to the respective buffer type. Do not
  73. use multiplanar buffers. Use <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant>
  74. instead of <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</constant>. Use
  75. <constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant> instead of
  76. <constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</constant>. The next step is
  77. setting the value of &v4l2-selection; <structfield>target</structfield> to
  78. <constant>V4L2_SEL_TGT_CROP</constant> (<constant>V4L2_SEL_TGT_COMPOSE</constant>).
  79. Please refer to table <xref linkend="v4l2-selections-common" /> or <xref linkend="selection-api" />
  80. for additional targets. The &v4l2-rect; <structfield>r</structfield> rectangle need to be
  81. set to the desired active area. Field &v4l2-selection; <structfield> reserved
  82. </structfield> is ignored and must be filled with zeros. The driver may adjust
  83. coordinates of the requested rectangle. An application may
  84. introduce constraints to control rounding behaviour. The &v4l2-selection;
  85. <structfield>flags</structfield> field must be set to one of the following:
  86. <itemizedlist>
  87. <listitem>
  88. <para><constant>0</constant> - The driver can adjust the rectangle size freely
  89. and shall choose a crop/compose rectangle as close as possible to the requested
  90. one.</para>
  91. </listitem>
  92. <listitem>
  93. <para><constant>V4L2_SEL_FLAG_GE</constant> - The driver is not allowed to
  94. shrink the rectangle. The original rectangle must lay inside the adjusted
  95. one.</para>
  96. </listitem>
  97. <listitem>
  98. <para><constant>V4L2_SEL_FLAG_LE</constant> - The driver is not allowed to
  99. enlarge the rectangle. The adjusted rectangle must lay inside the original
  100. one.</para>
  101. </listitem>
  102. <listitem>
  103. <para><constant>V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE</constant> - The driver
  104. must choose the size exactly the same as in the requested rectangle.</para>
  105. </listitem>
  106. </itemizedlist>
  107. Please refer to <xref linkend="sel-const-adjust" />.
  108. </para>
  109. <para> The driver may have to adjusts the requested dimensions against hardware
  110. limits and other parts as the pipeline, i.e. the bounds given by the
  111. capture/output window or TV display. The closest possible values of horizontal
  112. and vertical offset and sizes are chosen according to following priority:
  113. <orderedlist>
  114. <listitem>
  115. <para>Satisfy constraints from &v4l2-selection; <structfield>flags</structfield>.</para>
  116. </listitem>
  117. <listitem>
  118. <para>Adjust width, height, left, and top to hardware limits and alignments.</para>
  119. </listitem>
  120. <listitem>
  121. <para>Keep center of adjusted rectangle as close as possible to the original one.</para>
  122. </listitem>
  123. <listitem>
  124. <para>Keep width and height as close as possible to original ones.</para>
  125. </listitem>
  126. <listitem>
  127. <para>Keep horizontal and vertical offset as close as possible to original ones.</para>
  128. </listitem>
  129. </orderedlist>
  130. On success the &v4l2-rect; <structfield>r</structfield> field contains
  131. the adjusted rectangle. When the parameters are unsuitable the application may
  132. modify the cropping (composing) or image parameters and repeat the cycle until
  133. satisfactory parameters have been negotiated. If constraints flags have to be
  134. violated at then ERANGE is returned. The error indicates that <emphasis>there
  135. exist no rectangle</emphasis> that satisfies the constraints.</para>
  136. <para>Selection targets and flags are documented in <xref
  137. linkend="v4l2-selections-common"/>.</para>
  138. <para>
  139. <figure id="sel-const-adjust">
  140. <title>Size adjustments with constraint flags.</title>
  141. <mediaobject>
  142. <imageobject>
  143. <imagedata fileref="constraints.png" format="PNG" />
  144. </imageobject>
  145. <textobject>
  146. <phrase>Behaviour of rectangle adjustment for different constraint
  147. flags.</phrase>
  148. </textobject>
  149. </mediaobject>
  150. </figure>
  151. </para>
  152. <para>
  153. <table pgwide="1" frame="none" id="v4l2-selection">
  154. <title>struct <structname>v4l2_selection</structname></title>
  155. <tgroup cols="3">
  156. &cs-str;
  157. <tbody valign="top">
  158. <row>
  159. <entry>__u32</entry>
  160. <entry><structfield>type</structfield></entry>
  161. <entry>Type of the buffer (from &v4l2-buf-type;).</entry>
  162. </row>
  163. <row>
  164. <entry>__u32</entry>
  165. <entry><structfield>target</structfield></entry>
  166. <entry>Used to select between <link linkend="v4l2-selections-common"> cropping
  167. and composing rectangles</link>.</entry>
  168. </row>
  169. <row>
  170. <entry>__u32</entry>
  171. <entry><structfield>flags</structfield></entry>
  172. <entry>Flags controlling the selection rectangle adjustments, refer to
  173. <link linkend="v4l2-selection-flags">selection flags</link>.</entry>
  174. </row>
  175. <row>
  176. <entry>&v4l2-rect;</entry>
  177. <entry><structfield>r</structfield></entry>
  178. <entry>The selection rectangle.</entry>
  179. </row>
  180. <row>
  181. <entry>__u32</entry>
  182. <entry><structfield>reserved[9]</structfield></entry>
  183. <entry>Reserved fields for future use. Drivers and applications must zero this array.</entry>
  184. </row>
  185. </tbody>
  186. </tgroup>
  187. </table>
  188. </para>
  189. </refsect1>
  190. <refsect1>
  191. &return-value;
  192. <variablelist>
  193. <varlistentry>
  194. <term><errorcode>EINVAL</errorcode></term>
  195. <listitem>
  196. <para>Given buffer type <structfield>type</structfield> or
  197. the selection target <structfield>target</structfield> is not supported,
  198. or the <structfield>flags</structfield> argument is not valid.</para>
  199. </listitem>
  200. </varlistentry>
  201. <varlistentry>
  202. <term><errorcode>ERANGE</errorcode></term>
  203. <listitem>
  204. <para>It is not possible to adjust &v4l2-rect; <structfield>
  205. r</structfield> rectangle to satisfy all contraints given in the
  206. <structfield>flags</structfield> argument.</para>
  207. </listitem>
  208. </varlistentry>
  209. <varlistentry>
  210. <term><errorcode>EBUSY</errorcode></term>
  211. <listitem>
  212. <para>It is not possible to apply change of the selection rectangle
  213. at the moment. Usually because streaming is in progress.</para>
  214. </listitem>
  215. </varlistentry>
  216. </variablelist>
  217. </refsect1>
  218. </refentry>