<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Video Overlay Interface</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API" /><link rel="up" href="ch04.html" title="Chapter 4. Interfaces" /><link rel="prev" href="ch04.html" title="Chapter 4. Interfaces" /><link rel="next" href="ch04s03.html" title="Video Output Interface" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Video Overlay Interface</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Interfaces</th><td width="20%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr></table><hr /></div><div class="section" title="Video Overlay Interface"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="overlay"></a>Video Overlay Interface</h2></div><div><h3 class="subtitle">Also known as Framebuffer Overlay or Previewing</h3></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ch04s02.html#id2651328">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s02.html#id2651364">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04s02.html#id2652514">Setup</a></span></dt><dt><span class="section"><a href="ch04s02.html#id2652661">Overlay Window</a></span></dt><dt><span class="section"><a href="ch04s02.html#id2653512">Enabling Overlay</a></span></dt></dl></div><p>Video overlay devices have the ability to genlock (TV-)video into the (VGA-)video signal of a graphics card, or to store captured images directly in video memory of a graphics card, typically with clipping. This can be considerable more efficient than capturing images and displaying them by other means. In the old days when only nuclear power plants needed cooling towers this used to be the only way to put live video into a window.</p><p>Video overlay devices are accessed through the same character special files as <a class="link" href="ch04.html#capture" title="Video Capture Interface">video capture</a> devices. Note the default function of a <code class="filename">/dev/video</code> device is video capturing. The overlay function is only available after calling the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a> ioctl.</p><p>The driver may support simultaneous overlay and capturing using the read/write and streaming I/O methods. If so, operation at the nominal frame rate of the video standard is not guaranteed. Frames may be directed away from overlay to capture, or one field may be used for overlay and the other for capture if the capture parameters permit this.</p><p>Applications should use different file descriptors for capturing and overlay. This must be supported by all drivers capable of simultaneous capturing and overlay. Optionally these drivers may also permit capturing and overlay with a single file descriptor for compatibility with V4L and earlier versions of V4L2.<sup>[<a id="id2651289" href="#ftn.id2651289" class="footnote">20</a>]</sup></p><div class="section" title="Querying Capabilities"><div class="titlepage"><div><div><h3 class="title"><a id="id2651328"></a>Querying Capabilities</h3></div></div></div><p>Devices supporting the video overlay interface set the <code class="constant">V4L2_CAP_VIDEO_OVERLAY</code> flag in the <em class="structfield"><code>capabilities</code></em> field of struct <a class="link" href="re56.html#v4l2-capability" title="Table A.66. struct v4l2_capability">v4l2_capability</a> returned by the <a class="link" href="re56.html" title="ioctl VIDIOC_QUERYCAP"><code class="constant">VIDIOC_QUERYCAP</code></a> ioctl. The overlay I/O method specified below must be supported. Tuners and audio inputs are optional.</p></div><div class="section" title="Supplemental Functions"><div class="titlepage"><div><div><h3 class="title"><a id="id2651364"></a>Supplemental Functions</h3></div></div></div><p>Video overlay devices shall support <a class="link" href="ch01s05.html" title="Audio Inputs and Outputs">audio input</a>, <a class="link" href="ch01s06.html" title="Tuners and Modulators">tuner</a>, <a class="link" href="ch01s08.html" title="User Controls">controls</a>, <a class="link" href="ch01s11.html" title="Image Cropping, Insertion and Scaling">cropping and scaling</a> and <a class="link" href="ch01s12.html" title="Streaming Parameters">streaming parameter</a> ioctls as needed. The <a class="link" href="ch01s04.html" title="Video Inputs and Outputs">video input</a> and <a class="link" href="ch01s07.html" title="Video Standards">video standard</a> ioctls must be supported by all video overlay devices.</p></div><div class="section" title="Setup"><div class="titlepage"><div><div><h3 class="title"><a id="id2652514"></a>Setup</h3></div></div></div><p>Before overlay can commence applications must program the driver with frame buffer parameters, namely the address and size of the frame buffer and the image format, for example RGB 5:6:5. The <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_G_FBUF</code></a> and <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_S_FBUF</code></a> ioctls are available to get and set these parameters, respectively. The <code class="constant">VIDIOC_S_FBUF</code> ioctl is privileged because it allows to set up DMA into physical memory, bypassing the memory protection mechanisms of the kernel. Only the superuser can change the frame buffer address and size. Users are not supposed to run TV applications as root or with SUID bit set. A small helper application with suitable privileges should query the graphics system and program the V4L2 driver at the appropriate time.</p><p>Some devices add the video overlay to the output signal of the graphics card. In this case the frame buffer is not modified by the video device, and the frame buffer address and pixel format are not needed by the driver. The <code class="constant">VIDIOC_S_FBUF</code> ioctl is not privileged. An application can check for this type of device by calling the <code class="constant">VIDIOC_G_FBUF</code> ioctl.</p><p>A driver may support any (or none) of five clipping/blending methods:</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>Chroma-keying displays the overlaid image only where pixels in the primary graphics surface assume a certain color.</p></li><li class="listitem"><p>A bitmap can be specified where each bit corresponds to a pixel in the overlaid image. When the bit is set, the corresponding video pixel is displayed, otherwise a pixel of the graphics surface.</p></li><li class="listitem"><p>A list of clipping rectangles can be specified. In these regions <span class="emphasis"><em>no</em></span> video is displayed, so the graphics surface can be seen here.</p></li><li class="listitem"><p>The framebuffer has an alpha channel that can be used to clip or blend the framebuffer with the video.</p></li><li class="listitem"><p>A global alpha value can be specified to blend the framebuffer contents with video images.</p></li></ol></div><p>When simultaneous capturing and overlay is supported and the hardware prohibits different image and frame buffer formats, the format requested first takes precedence. The attempt to capture (<a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a>) or overlay (<a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_S_FBUF</code></a>) may fail with an <span class="errorcode">EBUSY</span> error code or return accordingly modified parameters..</p></div><div class="section" title="Overlay Window"><div class="titlepage"><div><div><h3 class="title"><a id="id2652661"></a>Overlay Window</h3></div></div></div><p>The overlaid image is determined by cropping and overlay window parameters. The former select an area of the video picture to capture, the latter how images are overlaid and clipped. Cropping initialization at minimum requires to reset the parameters to defaults. An example is given in <a class="xref" href="ch01s11.html" title="Image Cropping, Insertion and Scaling">the section called “Image Cropping, Insertion and Scaling”</a>.</p><p>The overlay window is described by a struct <a class="link" href="ch04s02.html#v4l2-window" title="Table 4.1. struct v4l2_window">v4l2_window</a>. It defines the size of the image, its position over the graphics surface and the clipping to be applied. To get the current parameters applications set the <em class="structfield"><code>type</code></em> field of a struct <a class="link" href="re41.html#v4l2-format" title="Table A.46. struct v4l2_format">v4l2_format</a> to <code class="constant">V4L2_BUF_TYPE_VIDEO_OVERLAY</code> and call the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_G_FMT</code></a> ioctl. The driver fills the <span class="structname">v4l2_window</span> substructure named <em class="structfield"><code>win</code></em>. It is not possible to retrieve a previously programmed clipping list or bitmap.</p><p>To program the overlay window applications set the <em class="structfield"><code>type</code></em> field of a struct <a class="link" href="re41.html#v4l2-format" title="Table A.46. struct v4l2_format">v4l2_format</a> to <code class="constant">V4L2_BUF_TYPE_VIDEO_OVERLAY</code>, initialize the <em class="structfield"><code>win</code></em> substructure and call the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a> ioctl. The driver adjusts the parameters against hardware limits and returns the actual parameters as <code class="constant">VIDIOC_G_FMT</code> does. Like <code class="constant">VIDIOC_S_FMT</code>, the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_TRY_FMT</code></a> ioctl can be used to learn about driver capabilities without actually changing driver state. Unlike <code class="constant">VIDIOC_S_FMT</code> this also works after the overlay has been enabled.</p><p>The scaling factor of the overlaid image is implied by the width and height given in struct <a class="link" href="ch04s02.html#v4l2-window" title="Table 4.1. struct v4l2_window">v4l2_window</a> and the size of the cropping rectangle. For more information see <a class="xref" href="ch01s11.html" title="Image Cropping, Insertion and Scaling">the section called “Image Cropping, Insertion and Scaling”</a>.</p><p>When simultaneous capturing and overlay is supported and the hardware prohibits different image and window sizes, the size requested first takes precedence. The attempt to capture or overlay as well (<a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a>) may fail with an <span class="errorcode">EBUSY</span> error code or return accordingly modified parameters.</p><div class="table"><a id="v4l2-window"></a><p class="title"><b>Table 4.1. struct <span class="structname">v4l2_window</span></b></p><div class="table-contents"><table summary="struct v4l2_window" width="100%" border="0"><colgroup><col /><col /><col /></colgroup><tbody valign="top"><tr><td valign="top">struct <a class="link" href="ch04s02.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a></td><td valign="top"><em class="structfield"><code>w</code></em></td><td valign="top">Size and position of the window relative to the top, left corner of the frame buffer defined with <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_S_FBUF</code></a>. The window can extend the frame buffer width and height, the <em class="structfield"><code>x</code></em> and <em class="structfield"><code>y</code></em> coordinates can be negative, and it can lie completely outside the frame buffer. The driver clips the window accordingly, or if that is not possible, modifies its size and/or position.</td></tr><tr><td valign="top">enum <a class="link" href="ch03s06.html#v4l2-field" title="Table 3.8. enum v4l2_field">v4l2_field</a></td><td valign="top"><em class="structfield"><code>field</code></em></td><td valign="top">Applications set this field to determine which video field shall be overlaid, typically one of <code class="constant">V4L2_FIELD_ANY</code> (0), <code class="constant">V4L2_FIELD_TOP</code>, <code class="constant">V4L2_FIELD_BOTTOM</code> or <code class="constant">V4L2_FIELD_INTERLACED</code>. Drivers may have to choose a different field order and return the actual setting here.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>chromakey</code></em></td><td valign="top">When chroma-keying has been negotiated with <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_S_FBUF</code></a> applications set this field to the desired pixel value for the chroma key. The format is the same as the pixel format of the framebuffer (struct <a class="link" href="re40.html#v4l2-framebuffer" title="Table A.43. struct v4l2_framebuffer">v4l2_framebuffer</a> <em class="structfield"><code>fmt.pixelformat</code></em> field), with bytes in host order. E. g. for <a class="link" href="re01.html#V4L2-PIX-FMT-BGR32"><code class="constant">V4L2_PIX_FMT_BGR24</code></a> the value should be 0xRRGGBB on a little endian, 0xBBGGRR on a big endian host.</td></tr><tr><td valign="top">struct <a class="link" href="ch04s02.html#v4l2-clip" title="Table 4.2. struct v4l2_clip">v4l2_clip</a> *</td><td valign="top"><em class="structfield"><code>clips</code></em></td><td valign="top">When chroma-keying has <span class="emphasis"><em>not</em></span> been negotiated and <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_G_FBUF</code></a> indicated this capability, applications can set this field to point to an array of clipping rectangles.</td></tr><tr><td valign="top"> </td><td valign="top"> </td><td valign="top">Like the window coordinates <em class="structfield"><code>w</code></em>, clipping rectangles are defined relative to the top, left corner of the frame buffer. However clipping rectangles must not extend the frame buffer width and height, and they must not overlap. If possible applications should merge adjacent rectangles. Whether this must create x-y or y-x bands, or the order of rectangles, is not defined. When clip lists are not supported the driver ignores this field. Its contents after calling <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a> are undefined.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>clipcount</code></em></td><td valign="top">When the application set the <em class="structfield"><code>clips</code></em> field, this field must contain the number of clipping rectangles in the list. When clip lists are not supported the driver ignores this field, its contents after calling <code class="constant">VIDIOC_S_FMT</code> are undefined. When clip lists are supported but no clipping is desired this field must be set to zero.</td></tr><tr><td valign="top">void *</td><td valign="top"><em class="structfield"><code>bitmap</code></em></td><td valign="top">When chroma-keying has <span class="emphasis"><em>not</em></span> been negotiated and <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_G_FBUF</code></a> indicated this capability, applications can set this field to point to a clipping bit mask.</td></tr><tr><td colspan="3" valign="top"><p>It must be of the same size as the window, <em class="structfield"><code>w.width</code></em> and <em class="structfield"><code>w.height</code></em>. Each bit corresponds to a pixel in the overlaid image, which is displayed only when the bit is <span class="emphasis"><em>set</em></span>. Pixel coordinates translate to bits like: </p><pre class="programlisting"> ((__u8 *) <em class="structfield"><code>bitmap</code></em>)[<em class="structfield"><code>w.width</code></em> * y + x / 8] & (1 << (x & 7))</pre><p>where <em class="structfield"><code>0</code></em> ≤ x < <em class="structfield"><code>w.width</code></em> and <em class="structfield"><code>0</code></em> ≤ y <<em class="structfield"><code>w.height</code></em>.<sup>[<a id="id2653161" href="#ftn.id2653161" class="footnote">a</a>]</sup></p><p>When a clipping bit mask is not supported the driver ignores this field, its contents after calling <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a> are undefined. When a bit mask is supported but no clipping is desired this field must be set to <code class="constant">NULL</code>.</p><p>Applications need not create a clip list or bit mask. When they pass both, or despite negotiating chroma-keying, the results are undefined. Regardless of the chosen method, the clipping abilities of the hardware may be limited in quantity or quality. The results when these limits are exceeded are undefined.<sup>[<a id="id2653198" href="#ftn.id2653198" class="footnote">b</a>]</sup></p></td></tr><tr><td valign="top">__u8</td><td valign="top"><em class="structfield"><code>global_alpha</code></em></td><td valign="top">The global alpha value used to blend the framebuffer with video images, if global alpha blending has been negotiated (<code class="constant">V4L2_FBUF_FLAG_GLOBAL_ALPHA</code>, see <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_S_FBUF</code></a>, <a class="xref" href="re40.html#framebuffer-flags" title="Table A.45. Frame Buffer Flags">Table A.45, “Frame Buffer Flags”</a>).</td></tr><tr><td valign="top"> </td><td valign="top"> </td><td valign="top">Note this field was added in Linux 2.6.23, extending the structure. However the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT">VIDIOC_G/S/TRY_FMT</a> ioctls, which take a pointer to a <a class="link" href="re41.html#v4l2-format" title="Table A.46. struct v4l2_format">v4l2_format</a> parent structure with padding bytes at the end, are not affected.</td></tr></tbody><tbody class="footnotes"><tr><td colspan="3"><div class="footnote"><p><sup>[<a id="ftn.id2653161" href="#id2653161" class="para">a</a>] </sup>Should we require <em class="structfield"><code>w.width</code></em> to be a multiple of eight?</p></div><div class="footnote"><p><sup>[<a id="ftn.id2653198" href="#id2653198" class="para">b</a>] </sup>When the image is written into frame buffer memory it will be undesirable if the driver clips out less pixels than expected, because the application and graphics system are not aware these regions need to be refreshed. The driver should clip out more pixels or not write the image at all.</p></div></td></tr></tbody></table></div></div><br class="table-break" /><div class="table"><a id="v4l2-clip"></a><p class="title"><b>Table 4.2. struct <span class="structname">v4l2_clip</span><sup>[<a id="id2653292" href="#ftn.id2653292" class="footnote">21</a>]</sup></b></p><div class="table-contents"><table summary="struct v4l2_clipThe X Window system defines "regions" which are vectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 - x1 and height = y2 - y1, so one cannot pass X11 clip lists directly." width="100%" border="0"><colgroup><col /><col /><col /></colgroup><tbody valign="top"><tr><td valign="top">struct <a class="link" href="ch04s02.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a></td><td valign="top"><em class="structfield"><code>c</code></em></td><td valign="top">Coordinates of the clipping rectangle, relative to the top, left corner of the frame buffer. Only window pixels <span class="emphasis"><em>outside</em></span> all clipping rectangles are displayed.</td></tr><tr><td valign="top">struct <a class="link" href="ch04s02.html#v4l2-clip" title="Table 4.2. struct v4l2_clip">v4l2_clip</a> *</td><td valign="top"><em class="structfield"><code>next</code></em></td><td valign="top">Pointer to the next clipping rectangle, NULL when this is the last rectangle. Drivers ignore this field, it cannot be used to pass a linked list of clipping rectangles.</td></tr></tbody><tbody class="footnotes"><tr><td colspan="3"><div class="footnote"><p><sup>[<a id="ftn.id2653292" href="#id2653292" class="para">21</a>] </sup>The X Window system defines "regions" which are vectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 - x1 and height = y2 - y1, so one cannot pass X11 clip lists directly.</p></div></td></tr></tbody></table></div></div><br class="table-break" /><div class="table"><a id="v4l2-rect"></a><p class="title"><b>Table 4.3. struct <span class="structname">v4l2_rect</span></b></p><div class="table-contents"><table summary="struct v4l2_rect" width="100%" border="0"><colgroup><col /><col /><col /></colgroup><tbody valign="top"><tr><td valign="top">__s32</td><td valign="top"><em class="structfield"><code>left</code></em></td><td valign="top">Horizontal offset of the top, left corner of the rectangle, in pixels.</td></tr><tr><td valign="top">__s32</td><td valign="top"><em class="structfield"><code>top</code></em></td><td valign="top">Vertical offset of the top, left corner of the rectangle, in pixels. Offsets increase to the right and down.</td></tr><tr><td valign="top">__s32</td><td valign="top"><em class="structfield"><code>width</code></em></td><td valign="top">Width of the rectangle, in pixels.</td></tr><tr><td valign="top">__s32</td><td valign="top"><em class="structfield"><code>height</code></em></td><td valign="top">Height of the rectangle, in pixels. Width and height cannot be negative, the fields are signed for hysterical reasons. </td></tr></tbody></table></div></div><br class="table-break" /></div><div class="section" title="Enabling Overlay"><div class="titlepage"><div><div><h3 class="title"><a id="id2653512"></a>Enabling Overlay</h3></div></div></div><p>To start or stop the frame buffer overlay applications call the <a class="link" href="re53.html" title="ioctl VIDIOC_OVERLAY"><code class="constant">VIDIOC_OVERLAY</code></a> ioctl.</p></div><div class="footnotes"><br /><hr width="100" align="left" /><div class="footnote"><p><sup>[<a id="ftn.id2651289" href="#id2651289" class="para">20</a>] </sup>A common application of two file descriptors is the XFree86 <a class="link" href="ch07s03.html#xvideo" title="X Video Extension">Xv/V4L</a> interface driver and a V4L2 application. While the X server controls video overlay, the application can take advantage of memory mapping and DMA.</p><p>In the opinion of the designers of this API, no driver writer taking the efforts to support simultaneous capturing and overlay will restrict this ability by requiring a single file descriptor, as in V4L and earlier versions of V4L2. Making this optional means applications depending on two file descriptors need backup routines to be compatible with all drivers, which is considerable more work than using two fds in applications which do not. Also two fd's fit the general concept of one file descriptor for each logical stream. Hence as a complexity trade-off drivers <span class="emphasis"><em>must</em></span> support two file descriptors and <span class="emphasis"><em>may</em></span> support single fd operation.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch04.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Interfaces </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Video Output Interface</td></tr></table></div></body></html>