dev-overlay.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <title>Video Overlay Interface</title>
  2. <subtitle>Also known as Framebuffer Overlay or Previewing</subtitle>
  3. <para>Video overlay devices have the ability to genlock (TV-)video
  4. into the (VGA-)video signal of a graphics card, or to store captured
  5. images directly in video memory of a graphics card, typically with
  6. clipping. This can be considerable more efficient than capturing
  7. images and displaying them by other means. In the old days when only
  8. nuclear power plants needed cooling towers this used to be the only
  9. way to put live video into a window.</para>
  10. <para>Video overlay devices are accessed through the same character
  11. special files as <link linkend="capture">video capture</link> devices.
  12. Note the default function of a <filename>/dev/video</filename> device
  13. is video capturing. The overlay function is only available after
  14. calling the &VIDIOC-S-FMT; ioctl.</para>
  15. <para>The driver may support simultaneous overlay and capturing
  16. using the read/write and streaming I/O methods. If so, operation at
  17. the nominal frame rate of the video standard is not guaranteed. Frames
  18. may be directed away from overlay to capture, or one field may be used
  19. for overlay and the other for capture if the capture parameters permit
  20. this.</para>
  21. <para>Applications should use different file descriptors for
  22. capturing and overlay. This must be supported by all drivers capable
  23. of simultaneous capturing and overlay. Optionally these drivers may
  24. also permit capturing and overlay with a single file descriptor for
  25. compatibility with V4L and earlier versions of V4L2.<footnote>
  26. <para>A common application of two file descriptors is the
  27. XFree86 <link linkend="xvideo">Xv/V4L</link> interface driver and
  28. a V4L2 application. While the X server controls video overlay, the
  29. application can take advantage of memory mapping and DMA.</para>
  30. <para>In the opinion of the designers of this API, no driver
  31. writer taking the efforts to support simultaneous capturing and
  32. overlay will restrict this ability by requiring a single file
  33. descriptor, as in V4L and earlier versions of V4L2. Making this
  34. optional means applications depending on two file descriptors need
  35. backup routines to be compatible with all drivers, which is
  36. considerable more work than using two fds in applications which do
  37. not. Also two fd's fit the general concept of one file descriptor for
  38. each logical stream. Hence as a complexity trade-off drivers
  39. <emphasis>must</emphasis> support two file descriptors and
  40. <emphasis>may</emphasis> support single fd operation.</para>
  41. </footnote></para>
  42. <section>
  43. <title>Querying Capabilities</title>
  44. <para>Devices supporting the video overlay interface set the
  45. <constant>V4L2_CAP_VIDEO_OVERLAY</constant> flag in the
  46. <structfield>capabilities</structfield> field of &v4l2-capability;
  47. returned by the &VIDIOC-QUERYCAP; ioctl. The overlay I/O method specified
  48. below must be supported. Tuners and audio inputs are optional.</para>
  49. </section>
  50. <section>
  51. <title>Supplemental Functions</title>
  52. <para>Video overlay devices shall support <link
  53. linkend="audio">audio input</link>, <link
  54. linkend="tuner">tuner</link>, <link linkend="control">controls</link>,
  55. <link linkend="crop">cropping and scaling</link> and <link
  56. linkend="streaming-par">streaming parameter</link> ioctls as needed.
  57. The <link linkend="video">video input</link> and <link
  58. linkend="standard">video standard</link> ioctls must be supported by
  59. all video overlay devices.</para>
  60. </section>
  61. <section>
  62. <title>Setup</title>
  63. <para>Before overlay can commence applications must program the
  64. driver with frame buffer parameters, namely the address and size of
  65. the frame buffer and the image format, for example RGB 5:6:5. The
  66. &VIDIOC-G-FBUF; and &VIDIOC-S-FBUF; ioctls are available to get
  67. and set these parameters, respectively. The
  68. <constant>VIDIOC_S_FBUF</constant> ioctl is privileged because it
  69. allows to set up DMA into physical memory, bypassing the memory
  70. protection mechanisms of the kernel. Only the superuser can change the
  71. frame buffer address and size. Users are not supposed to run TV
  72. applications as root or with SUID bit set. A small helper application
  73. with suitable privileges should query the graphics system and program
  74. the V4L2 driver at the appropriate time.</para>
  75. <para>Some devices add the video overlay to the output signal
  76. of the graphics card. In this case the frame buffer is not modified by
  77. the video device, and the frame buffer address and pixel format are
  78. not needed by the driver. The <constant>VIDIOC_S_FBUF</constant> ioctl
  79. is not privileged. An application can check for this type of device by
  80. calling the <constant>VIDIOC_G_FBUF</constant> ioctl.</para>
  81. <para>A driver may support any (or none) of five clipping/blending
  82. methods:<orderedlist>
  83. <listitem>
  84. <para>Chroma-keying displays the overlaid image only where
  85. pixels in the primary graphics surface assume a certain color.</para>
  86. </listitem>
  87. <listitem>
  88. <para>A bitmap can be specified where each bit corresponds
  89. to a pixel in the overlaid image. When the bit is set, the
  90. corresponding video pixel is displayed, otherwise a pixel of the
  91. graphics surface.</para>
  92. </listitem>
  93. <listitem>
  94. <para>A list of clipping rectangles can be specified. In
  95. these regions <emphasis>no</emphasis> video is displayed, so the
  96. graphics surface can be seen here.</para>
  97. </listitem>
  98. <listitem>
  99. <para>The framebuffer has an alpha channel that can be used
  100. to clip or blend the framebuffer with the video.</para>
  101. </listitem>
  102. <listitem>
  103. <para>A global alpha value can be specified to blend the
  104. framebuffer contents with video images.</para>
  105. </listitem>
  106. </orderedlist></para>
  107. <para>When simultaneous capturing and overlay is supported and
  108. the hardware prohibits different image and frame buffer formats, the
  109. format requested first takes precedence. The attempt to capture
  110. (&VIDIOC-S-FMT;) or overlay (&VIDIOC-S-FBUF;) may fail with an
  111. &EBUSY; or return accordingly modified parameters..</para>
  112. </section>
  113. <section>
  114. <title>Overlay Window</title>
  115. <para>The overlaid image is determined by cropping and overlay
  116. window parameters. The former select an area of the video picture to
  117. capture, the latter how images are overlaid and clipped. Cropping
  118. initialization at minimum requires to reset the parameters to
  119. defaults. An example is given in <xref linkend="crop" />.</para>
  120. <para>The overlay window is described by a &v4l2-window;. It
  121. defines the size of the image, its position over the graphics surface
  122. and the clipping to be applied. To get the current parameters
  123. applications set the <structfield>type</structfield> field of a
  124. &v4l2-format; to <constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant> and
  125. call the &VIDIOC-G-FMT; ioctl. The driver fills the
  126. <structname>v4l2_window</structname> substructure named
  127. <structfield>win</structfield>. It is not possible to retrieve a
  128. previously programmed clipping list or bitmap.</para>
  129. <para>To program the overlay window applications set the
  130. <structfield>type</structfield> field of a &v4l2-format; to
  131. <constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant>, initialize the
  132. <structfield>win</structfield> substructure and call the
  133. &VIDIOC-S-FMT; ioctl. The driver adjusts the parameters against
  134. hardware limits and returns the actual parameters as
  135. <constant>VIDIOC_G_FMT</constant> does. Like
  136. <constant>VIDIOC_S_FMT</constant>, the &VIDIOC-TRY-FMT; ioctl can be
  137. used to learn about driver capabilities without actually changing
  138. driver state. Unlike <constant>VIDIOC_S_FMT</constant> this also works
  139. after the overlay has been enabled.</para>
  140. <para>The scaling factor of the overlaid image is implied by the
  141. width and height given in &v4l2-window; and the size of the cropping
  142. rectangle. For more information see <xref linkend="crop" />.</para>
  143. <para>When simultaneous capturing and overlay is supported and
  144. the hardware prohibits different image and window sizes, the size
  145. requested first takes precedence. The attempt to capture or overlay as
  146. well (&VIDIOC-S-FMT;) may fail with an &EBUSY; or return accordingly
  147. modified parameters.</para>
  148. <table pgwide="1" frame="none" id="v4l2-window">
  149. <title>struct <structname>v4l2_window</structname></title>
  150. <tgroup cols="3">
  151. &cs-str;
  152. <tbody valign="top">
  153. <row>
  154. <entry>&v4l2-rect;</entry>
  155. <entry><structfield>w</structfield></entry>
  156. <entry>Size and position of the window relative to the
  157. top, left corner of the frame buffer defined with &VIDIOC-S-FBUF;. The
  158. window can extend the frame buffer width and height, the
  159. <structfield>x</structfield> and <structfield>y</structfield>
  160. coordinates can be negative, and it can lie completely outside the
  161. frame buffer. The driver clips the window accordingly, or if that is
  162. not possible, modifies its size and/or position.</entry>
  163. </row>
  164. <row>
  165. <entry>&v4l2-field;</entry>
  166. <entry><structfield>field</structfield></entry>
  167. <entry>Applications set this field to determine which
  168. video field shall be overlaid, typically one of
  169. <constant>V4L2_FIELD_ANY</constant> (0),
  170. <constant>V4L2_FIELD_TOP</constant>,
  171. <constant>V4L2_FIELD_BOTTOM</constant> or
  172. <constant>V4L2_FIELD_INTERLACED</constant>. Drivers may have to choose
  173. a different field order and return the actual setting here.</entry>
  174. </row>
  175. <row>
  176. <entry>__u32</entry>
  177. <entry><structfield>chromakey</structfield></entry>
  178. <entry>When chroma-keying has been negotiated with
  179. &VIDIOC-S-FBUF; applications set this field to the desired pixel value
  180. for the chroma key. The format is the same as the pixel format of the
  181. framebuffer (&v4l2-framebuffer;
  182. <structfield>fmt.pixelformat</structfield> field), with bytes in host
  183. order. E.&nbsp;g. for <link
  184. linkend="V4L2-PIX-FMT-BGR32"><constant>V4L2_PIX_FMT_BGR24</constant></link>
  185. the value should be 0xRRGGBB on a little endian, 0xBBGGRR on a big
  186. endian host.</entry>
  187. </row>
  188. <row>
  189. <entry>&v4l2-clip; *</entry>
  190. <entry><structfield>clips</structfield></entry>
  191. <entry>When chroma-keying has <emphasis>not</emphasis>
  192. been negotiated and &VIDIOC-G-FBUF; indicated this capability,
  193. applications can set this field to point to an array of
  194. clipping rectangles.</entry>
  195. </row>
  196. <row>
  197. <entry></entry>
  198. <entry></entry>
  199. <entry>Like the window coordinates
  200. <structfield>w</structfield>, clipping rectangles are defined relative
  201. to the top, left corner of the frame buffer. However clipping
  202. rectangles must not extend the frame buffer width and height, and they
  203. must not overlap. If possible applications should merge adjacent
  204. rectangles. Whether this must create x-y or y-x bands, or the order of
  205. rectangles, is not defined. When clip lists are not supported the
  206. driver ignores this field. Its contents after calling &VIDIOC-S-FMT;
  207. are undefined.</entry>
  208. </row>
  209. <row>
  210. <entry>__u32</entry>
  211. <entry><structfield>clipcount</structfield></entry>
  212. <entry>When the application set the
  213. <structfield>clips</structfield> field, this field must contain the
  214. number of clipping rectangles in the list. When clip lists are not
  215. supported the driver ignores this field, its contents after calling
  216. <constant>VIDIOC_S_FMT</constant> are undefined. When clip lists are
  217. supported but no clipping is desired this field must be set to
  218. zero.</entry>
  219. </row>
  220. <row>
  221. <entry>void *</entry>
  222. <entry><structfield>bitmap</structfield></entry>
  223. <entry>When chroma-keying has
  224. <emphasis>not</emphasis> been negotiated and &VIDIOC-G-FBUF; indicated
  225. this capability, applications can set this field to point to a
  226. clipping bit mask.</entry>
  227. </row>
  228. <row>
  229. <entry spanname="hspan"><para>It must be of the same size
  230. as the window, <structfield>w.width</structfield> and
  231. <structfield>w.height</structfield>. Each bit corresponds to a pixel
  232. in the overlaid image, which is displayed only when the bit is
  233. <emphasis>set</emphasis>. Pixel coordinates translate to bits like:
  234. <programlisting>
  235. ((__u8 *) <structfield>bitmap</structfield>)[<structfield>w.width</structfield> * y + x / 8] &amp; (1 &lt;&lt; (x &amp; 7))</programlisting></para><para>where <structfield>0</structfield> &le; x &lt;
  236. <structfield>w.width</structfield> and <structfield>0</structfield> &le;
  237. y &lt;<structfield>w.height</structfield>.<footnote>
  238. <para>Should we require
  239. <structfield>w.width</structfield> to be a multiple of
  240. eight?</para>
  241. </footnote></para><para>When a clipping
  242. bit mask is not supported the driver ignores this field, its contents
  243. after calling &VIDIOC-S-FMT; are undefined. When a bit mask is supported
  244. but no clipping is desired this field must be set to
  245. <constant>NULL</constant>.</para><para>Applications need not create a
  246. clip list or bit mask. When they pass both, or despite negotiating
  247. chroma-keying, the results are undefined. Regardless of the chosen
  248. method, the clipping abilities of the hardware may be limited in
  249. quantity or quality. The results when these limits are exceeded are
  250. undefined.<footnote>
  251. <para>When the image is written into frame buffer
  252. memory it will be undesirable if the driver clips out less pixels
  253. than expected, because the application and graphics system are not
  254. aware these regions need to be refreshed. The driver should clip out
  255. more pixels or not write the image at all.</para>
  256. </footnote></para></entry>
  257. </row>
  258. <row>
  259. <entry>__u8</entry>
  260. <entry><structfield>global_alpha</structfield></entry>
  261. <entry>The global alpha value used to blend the
  262. framebuffer with video images, if global alpha blending has been
  263. negotiated (<constant>V4L2_FBUF_FLAG_GLOBAL_ALPHA</constant>, see
  264. &VIDIOC-S-FBUF;, <xref linkend="framebuffer-flags" />).</entry>
  265. </row>
  266. <row>
  267. <entry></entry>
  268. <entry></entry>
  269. <entry>Note this field was added in Linux 2.6.23, extending the structure. However
  270. the <link linkend="vidioc-g-fmt">VIDIOC_G/S/TRY_FMT</link> ioctls,
  271. which take a pointer to a <link
  272. linkend="v4l2-format">v4l2_format</link> parent structure with padding
  273. bytes at the end, are not affected.</entry>
  274. </row>
  275. </tbody>
  276. </tgroup>
  277. </table>
  278. <table pgwide="1" frame="none" id="v4l2-clip">
  279. <title>struct <structname>v4l2_clip</structname><footnote>
  280. <para>The X Window system defines "regions" which are
  281. vectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 -
  282. x1 and height = y2 - y1, so one cannot pass X11 clip lists
  283. directly.</para>
  284. </footnote></title>
  285. <tgroup cols="3">
  286. &cs-str;
  287. <tbody valign="top">
  288. <row>
  289. <entry>&v4l2-rect;</entry>
  290. <entry><structfield>c</structfield></entry>
  291. <entry>Coordinates of the clipping rectangle, relative to
  292. the top, left corner of the frame buffer. Only window pixels
  293. <emphasis>outside</emphasis> all clipping rectangles are
  294. displayed.</entry>
  295. </row>
  296. <row>
  297. <entry>&v4l2-clip; *</entry>
  298. <entry><structfield>next</structfield></entry>
  299. <entry>Pointer to the next clipping rectangle, NULL when
  300. this is the last rectangle. Drivers ignore this field, it cannot be
  301. used to pass a linked list of clipping rectangles.</entry>
  302. </row>
  303. </tbody>
  304. </tgroup>
  305. </table>
  306. <!-- NB for easier reading this table is duplicated
  307. in the vidioc-cropcap chapter.-->
  308. <table pgwide="1" frame="none" id="v4l2-rect">
  309. <title>struct <structname>v4l2_rect</structname></title>
  310. <tgroup cols="3">
  311. &cs-str;
  312. <tbody valign="top">
  313. <row>
  314. <entry>__s32</entry>
  315. <entry><structfield>left</structfield></entry>
  316. <entry>Horizontal offset of the top, left corner of the
  317. rectangle, in pixels.</entry>
  318. </row>
  319. <row>
  320. <entry>__s32</entry>
  321. <entry><structfield>top</structfield></entry>
  322. <entry>Vertical offset of the top, left corner of the
  323. rectangle, in pixels. Offsets increase to the right and down.</entry>
  324. </row>
  325. <row>
  326. <entry>__u32</entry>
  327. <entry><structfield>width</structfield></entry>
  328. <entry>Width of the rectangle, in pixels.</entry>
  329. </row>
  330. <row>
  331. <entry>__u32</entry>
  332. <entry><structfield>height</structfield></entry>
  333. <entry>Height of the rectangle, in pixels.</entry>
  334. </row>
  335. </tbody>
  336. </tgroup>
  337. </table>
  338. </section>
  339. <section>
  340. <title>Enabling Overlay</title>
  341. <para>To start or stop the frame buffer overlay applications call
  342. the &VIDIOC-OVERLAY; ioctl.</para>
  343. </section>