Path: blob/master/Documentation/DocBook/v4l/dev-overlay.xml
10821 views
<title>Video Overlay Interface</title>1<subtitle>Also known as Framebuffer Overlay or Previewing</subtitle>23<para>Video overlay devices have the ability to genlock (TV-)video4into the (VGA-)video signal of a graphics card, or to store captured5images directly in video memory of a graphics card, typically with6clipping. This can be considerable more efficient than capturing7images and displaying them by other means. In the old days when only8nuclear power plants needed cooling towers this used to be the only9way to put live video into a window.</para>1011<para>Video overlay devices are accessed through the same character12special files as <link linkend="capture">video capture</link> devices.13Note the default function of a <filename>/dev/video</filename> device14is video capturing. The overlay function is only available after15calling the &VIDIOC-S-FMT; ioctl.</para>1617<para>The driver may support simultaneous overlay and capturing18using the read/write and streaming I/O methods. If so, operation at19the nominal frame rate of the video standard is not guaranteed. Frames20may be directed away from overlay to capture, or one field may be used21for overlay and the other for capture if the capture parameters permit22this.</para>2324<para>Applications should use different file descriptors for25capturing and overlay. This must be supported by all drivers capable26of simultaneous capturing and overlay. Optionally these drivers may27also permit capturing and overlay with a single file descriptor for28compatibility with V4L and earlier versions of V4L2.<footnote>29<para>A common application of two file descriptors is the30XFree86 <link linkend="xvideo">Xv/V4L</link> interface driver and31a V4L2 application. While the X server controls video overlay, the32application can take advantage of memory mapping and DMA.</para>33<para>In the opinion of the designers of this API, no driver34writer taking the efforts to support simultaneous capturing and35overlay will restrict this ability by requiring a single file36descriptor, as in V4L and earlier versions of V4L2. Making this37optional means applications depending on two file descriptors need38backup routines to be compatible with all drivers, which is39considerable more work than using two fds in applications which do40not. Also two fd's fit the general concept of one file descriptor for41each logical stream. Hence as a complexity trade-off drivers42<emphasis>must</emphasis> support two file descriptors and43<emphasis>may</emphasis> support single fd operation.</para>44</footnote></para>4546<section>47<title>Querying Capabilities</title>4849<para>Devices supporting the video overlay interface set the50<constant>V4L2_CAP_VIDEO_OVERLAY</constant> flag in the51<structfield>capabilities</structfield> field of &v4l2-capability;52returned by the &VIDIOC-QUERYCAP; ioctl. The overlay I/O method specified53below must be supported. Tuners and audio inputs are optional.</para>54</section>5556<section>57<title>Supplemental Functions</title>5859<para>Video overlay devices shall support <link60linkend="audio">audio input</link>, <link61linkend="tuner">tuner</link>, <link linkend="control">controls</link>,62<link linkend="crop">cropping and scaling</link> and <link63linkend="streaming-par">streaming parameter</link> ioctls as needed.64The <link linkend="video">video input</link> and <link65linkend="standard">video standard</link> ioctls must be supported by66all video overlay devices.</para>67</section>6869<section>70<title>Setup</title>7172<para>Before overlay can commence applications must program the73driver with frame buffer parameters, namely the address and size of74the frame buffer and the image format, for example RGB 5:6:5. The75&VIDIOC-G-FBUF; and &VIDIOC-S-FBUF; ioctls are available to get76and set these parameters, respectively. The77<constant>VIDIOC_S_FBUF</constant> ioctl is privileged because it78allows to set up DMA into physical memory, bypassing the memory79protection mechanisms of the kernel. Only the superuser can change the80frame buffer address and size. Users are not supposed to run TV81applications as root or with SUID bit set. A small helper application82with suitable privileges should query the graphics system and program83the V4L2 driver at the appropriate time.</para>8485<para>Some devices add the video overlay to the output signal86of the graphics card. In this case the frame buffer is not modified by87the video device, and the frame buffer address and pixel format are88not needed by the driver. The <constant>VIDIOC_S_FBUF</constant> ioctl89is not privileged. An application can check for this type of device by90calling the <constant>VIDIOC_G_FBUF</constant> ioctl.</para>9192<para>A driver may support any (or none) of five clipping/blending93methods:<orderedlist>94<listitem>95<para>Chroma-keying displays the overlaid image only where96pixels in the primary graphics surface assume a certain color.</para>97</listitem>98<listitem>99<para>A bitmap can be specified where each bit corresponds100to a pixel in the overlaid image. When the bit is set, the101corresponding video pixel is displayed, otherwise a pixel of the102graphics surface.</para>103</listitem>104<listitem>105<para>A list of clipping rectangles can be specified. In106these regions <emphasis>no</emphasis> video is displayed, so the107graphics surface can be seen here.</para>108</listitem>109<listitem>110<para>The framebuffer has an alpha channel that can be used111to clip or blend the framebuffer with the video.</para>112</listitem>113<listitem>114<para>A global alpha value can be specified to blend the115framebuffer contents with video images.</para>116</listitem>117</orderedlist></para>118119<para>When simultaneous capturing and overlay is supported and120the hardware prohibits different image and frame buffer formats, the121format requested first takes precedence. The attempt to capture122(&VIDIOC-S-FMT;) or overlay (&VIDIOC-S-FBUF;) may fail with an123&EBUSY; or return accordingly modified parameters..</para>124</section>125126<section>127<title>Overlay Window</title>128129<para>The overlaid image is determined by cropping and overlay130window parameters. The former select an area of the video picture to131capture, the latter how images are overlaid and clipped. Cropping132initialization at minimum requires to reset the parameters to133defaults. An example is given in <xref linkend="crop" />.</para>134135<para>The overlay window is described by a &v4l2-window;. It136defines the size of the image, its position over the graphics surface137and the clipping to be applied. To get the current parameters138applications set the <structfield>type</structfield> field of a139&v4l2-format; to <constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant> and140call the &VIDIOC-G-FMT; ioctl. The driver fills the141<structname>v4l2_window</structname> substructure named142<structfield>win</structfield>. It is not possible to retrieve a143previously programmed clipping list or bitmap.</para>144145<para>To program the overlay window applications set the146<structfield>type</structfield> field of a &v4l2-format; to147<constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant>, initialize the148<structfield>win</structfield> substructure and call the149&VIDIOC-S-FMT; ioctl. The driver adjusts the parameters against150hardware limits and returns the actual parameters as151<constant>VIDIOC_G_FMT</constant> does. Like152<constant>VIDIOC_S_FMT</constant>, the &VIDIOC-TRY-FMT; ioctl can be153used to learn about driver capabilities without actually changing154driver state. Unlike <constant>VIDIOC_S_FMT</constant> this also works155after the overlay has been enabled.</para>156157<para>The scaling factor of the overlaid image is implied by the158width and height given in &v4l2-window; and the size of the cropping159rectangle. For more information see <xref linkend="crop" />.</para>160161<para>When simultaneous capturing and overlay is supported and162the hardware prohibits different image and window sizes, the size163requested first takes precedence. The attempt to capture or overlay as164well (&VIDIOC-S-FMT;) may fail with an &EBUSY; or return accordingly165modified parameters.</para>166167<table pgwide="1" frame="none" id="v4l2-window">168<title>struct <structname>v4l2_window</structname></title>169<tgroup cols="3">170&cs-str;171<tbody valign="top">172<row>173<entry>&v4l2-rect;</entry>174<entry><structfield>w</structfield></entry>175<entry>Size and position of the window relative to the176top, left corner of the frame buffer defined with &VIDIOC-S-FBUF;. The177window can extend the frame buffer width and height, the178<structfield>x</structfield> and <structfield>y</structfield>179coordinates can be negative, and it can lie completely outside the180frame buffer. The driver clips the window accordingly, or if that is181not possible, modifies its size and/or position.</entry>182</row>183<row>184<entry>&v4l2-field;</entry>185<entry><structfield>field</structfield></entry>186<entry>Applications set this field to determine which187video field shall be overlaid, typically one of188<constant>V4L2_FIELD_ANY</constant> (0),189<constant>V4L2_FIELD_TOP</constant>,190<constant>V4L2_FIELD_BOTTOM</constant> or191<constant>V4L2_FIELD_INTERLACED</constant>. Drivers may have to choose192a different field order and return the actual setting here.</entry>193</row>194<row>195<entry>__u32</entry>196<entry><structfield>chromakey</structfield></entry>197<entry>When chroma-keying has been negotiated with198&VIDIOC-S-FBUF; applications set this field to the desired pixel value199for the chroma key. The format is the same as the pixel format of the200framebuffer (&v4l2-framebuffer;201<structfield>fmt.pixelformat</structfield> field), with bytes in host202order. E. g. for <link203linkend="V4L2-PIX-FMT-BGR32"><constant>V4L2_PIX_FMT_BGR24</constant></link>204the value should be 0xRRGGBB on a little endian, 0xBBGGRR on a big205endian host.</entry>206</row>207<row>208<entry>&v4l2-clip; *</entry>209<entry><structfield>clips</structfield></entry>210<entry>When chroma-keying has <emphasis>not</emphasis>211been negotiated and &VIDIOC-G-FBUF; indicated this capability,212applications can set this field to point to an array of213clipping rectangles.</entry>214</row>215<row>216<entry></entry>217<entry></entry>218<entry>Like the window coordinates219<structfield>w</structfield>, clipping rectangles are defined relative220to the top, left corner of the frame buffer. However clipping221rectangles must not extend the frame buffer width and height, and they222must not overlap. If possible applications should merge adjacent223rectangles. Whether this must create x-y or y-x bands, or the order of224rectangles, is not defined. When clip lists are not supported the225driver ignores this field. Its contents after calling &VIDIOC-S-FMT;226are undefined.</entry>227</row>228<row>229<entry>__u32</entry>230<entry><structfield>clipcount</structfield></entry>231<entry>When the application set the232<structfield>clips</structfield> field, this field must contain the233number of clipping rectangles in the list. When clip lists are not234supported the driver ignores this field, its contents after calling235<constant>VIDIOC_S_FMT</constant> are undefined. When clip lists are236supported but no clipping is desired this field must be set to237zero.</entry>238</row>239<row>240<entry>void *</entry>241<entry><structfield>bitmap</structfield></entry>242<entry>When chroma-keying has243<emphasis>not</emphasis> been negotiated and &VIDIOC-G-FBUF; indicated244this capability, applications can set this field to point to a245clipping bit mask.</entry>246</row>247<row>248<entry spanname="hspan"><para>It must be of the same size249as the window, <structfield>w.width</structfield> and250<structfield>w.height</structfield>. Each bit corresponds to a pixel251in the overlaid image, which is displayed only when the bit is252<emphasis>set</emphasis>. Pixel coordinates translate to bits like:253<programlisting>254((__u8 *) <structfield>bitmap</structfield>)[<structfield>w.width</structfield> * y + x / 8] & (1 << (x & 7))</programlisting></para><para>where <structfield>0</structfield> ≤ x <255<structfield>w.width</structfield> and <structfield>0</structfield> ≤256y <<structfield>w.height</structfield>.<footnote>257<para>Should we require258<structfield>w.width</structfield> to be a multiple of259eight?</para>260</footnote></para><para>When a clipping261bit mask is not supported the driver ignores this field, its contents262after calling &VIDIOC-S-FMT; are undefined. When a bit mask is supported263but no clipping is desired this field must be set to264<constant>NULL</constant>.</para><para>Applications need not create a265clip list or bit mask. When they pass both, or despite negotiating266chroma-keying, the results are undefined. Regardless of the chosen267method, the clipping abilities of the hardware may be limited in268quantity or quality. The results when these limits are exceeded are269undefined.<footnote>270<para>When the image is written into frame buffer271memory it will be undesirable if the driver clips out less pixels272than expected, because the application and graphics system are not273aware these regions need to be refreshed. The driver should clip out274more pixels or not write the image at all.</para>275</footnote></para></entry>276</row>277<row>278<entry>__u8</entry>279<entry><structfield>global_alpha</structfield></entry>280<entry>The global alpha value used to blend the281framebuffer with video images, if global alpha blending has been282negotiated (<constant>V4L2_FBUF_FLAG_GLOBAL_ALPHA</constant>, see283&VIDIOC-S-FBUF;, <xref linkend="framebuffer-flags" />).</entry>284</row>285<row>286<entry></entry>287<entry></entry>288<entry>Note this field was added in Linux 2.6.23, extending the structure. However289the <link linkend="vidioc-g-fmt">VIDIOC_G/S/TRY_FMT</link> ioctls,290which take a pointer to a <link291linkend="v4l2-format">v4l2_format</link> parent structure with padding292bytes at the end, are not affected.</entry>293</row>294</tbody>295</tgroup>296</table>297298<table pgwide="1" frame="none" id="v4l2-clip">299<title>struct <structname>v4l2_clip</structname><footnote>300<para>The X Window system defines "regions" which are301vectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 -302x1 and height = y2 - y1, so one cannot pass X11 clip lists303directly.</para>304</footnote></title>305<tgroup cols="3">306&cs-str;307<tbody valign="top">308<row>309<entry>&v4l2-rect;</entry>310<entry><structfield>c</structfield></entry>311<entry>Coordinates of the clipping rectangle, relative to312the top, left corner of the frame buffer. Only window pixels313<emphasis>outside</emphasis> all clipping rectangles are314displayed.</entry>315</row>316<row>317<entry>&v4l2-clip; *</entry>318<entry><structfield>next</structfield></entry>319<entry>Pointer to the next clipping rectangle, NULL when320this is the last rectangle. Drivers ignore this field, it cannot be321used to pass a linked list of clipping rectangles.</entry>322</row>323</tbody>324</tgroup>325</table>326327<!-- NB for easier reading this table is duplicated328in the vidioc-cropcap chapter.-->329330<table pgwide="1" frame="none" id="v4l2-rect">331<title>struct <structname>v4l2_rect</structname></title>332<tgroup cols="3">333&cs-str;334<tbody valign="top">335<row>336<entry>__s32</entry>337<entry><structfield>left</structfield></entry>338<entry>Horizontal offset of the top, left corner of the339rectangle, in pixels.</entry>340</row>341<row>342<entry>__s32</entry>343<entry><structfield>top</structfield></entry>344<entry>Vertical offset of the top, left corner of the345rectangle, in pixels. Offsets increase to the right and down.</entry>346</row>347<row>348<entry>__s32</entry>349<entry><structfield>width</structfield></entry>350<entry>Width of the rectangle, in pixels.</entry>351</row>352<row>353<entry>__s32</entry>354<entry><structfield>height</structfield></entry>355<entry>Height of the rectangle, in pixels. Width and356height cannot be negative, the fields are signed for hysterical357reasons. <!-- [email protected] on 22 Oct 2002 subject358"Re:[V4L][patches!] Re:v4l2/kernel-2.5" --></entry>359</row>360</tbody>361</tgroup>362</table>363</section>364365<section>366<title>Enabling Overlay</title>367368<para>To start or stop the frame buffer overlay applications call369the &VIDIOC-OVERLAY; ioctl.</para>370</section>371372<!--373Local Variables:374mode: sgml375sgml-parent-document: "v4l2.sgml"376indent-tabs-mode: nil377End:378-->379380381