<?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>Chapter 4. Interfaces</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="pt01.html" title="Part I. Video for Linux Two API Specification" /><link rel="prev" href="ch03s06.html" title="Field Order" /><link rel="next" href="ch04s02.html" title="Video Overlay Interface" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Interfaces</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s06.html">Prev</a> </td><th width="60%" align="center">Part I. Video for Linux Two API Specification</th><td width="20%" align="right"> <a accesskey="n" href="ch04s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 4. Interfaces"><div class="titlepage"><div><div><h2 class="title"><a id="devices"></a>Chapter 4. Interfaces</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="ch04.html#capture">Video Capture Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04.html#id2650920">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04.html#id2651594">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04.html#id2651658">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="ch04.html#id2651862">Reading Images</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s02.html">Video Overlay Interface</a></span></dt><dd><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></dd><dt><span class="section"><a href="ch04s03.html">Video Output Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s03.html#id2654206">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s03.html#id2654867">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04s03.html#id2654928">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="ch04s03.html#id2655131">Writing Images</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s04.html">Video Output Overlay Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s04.html#id2655641">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s04.html#id2655678">Framebuffer</a></span></dt><dt><span class="section"><a href="ch04s04.html#id2655812">Overlay Window and Scaling</a></span></dt><dt><span class="section"><a href="ch04s04.html#id2655987">Enabling Overlay</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s05.html">Codec Interface</a></span></dt><dt><span class="section"><a href="ch04s06.html">Effect Devices Interface</a></span></dt><dt><span class="section"><a href="ch04s07.html">Raw VBI Data Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s07.html#id2656750">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s07.html#id2656791">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04s07.html#id2656831">Raw VBI Format Negotiation</a></span></dt><dt><span class="section"><a href="ch04s07.html#id2657629">Reading and writing VBI images</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s08.html">Sliced VBI Data Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s08.html#id2658885">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s08.html#id2658932">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04s08.html#sliced-vbi-format-negotitation">Sliced VBI Format Negotiation</a></span></dt><dt><span class="section"><a href="ch04s08.html#id2659926">Reading and writing sliced VBI data</a></span></dt><dt><span class="section"><a href="ch04s08.html#id2660280">Sliced VBI Data in MPEG Streams</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s09.html">Teletext Interface</a></span></dt><dt><span class="section"><a href="ch04s10.html">Radio Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s10.html#id2664131">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s10.html#id2664424">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04s10.html#id2664456">Programming</a></span></dt></dl></dd><dt><span class="section"><a href="ch04s11.html">RDS Interface</a></span></dt><dd><dl><dt><span class="section"><a href="ch04s11.html#id2663624">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04s11.html#id2664843">Reading RDS data</a></span></dt></dl></dd></dl></div><div class="section" title="Video Capture Interface"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="capture"></a>Video Capture Interface</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ch04.html#id2650920">Querying Capabilities</a></span></dt><dt><span class="section"><a href="ch04.html#id2651594">Supplemental Functions</a></span></dt><dt><span class="section"><a href="ch04.html#id2651658">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="ch04.html#id2651862">Reading Images</a></span></dt></dl></div><p>Video capture devices sample an analog video signal and store the digitized images in memory. Today nearly all devices can capture at full 25 or 30 frames/second. With this interface applications can control the capture process and move images from the driver into user space.</p><p>Conventionally V4L2 video capture devices are accessed through character device special files named <code class="filename">/dev/video</code> and <code class="filename">/dev/video0</code> to <code class="filename">/dev/video63</code> with major number 81 and minor numbers 0 to 63. <code class="filename">/dev/video</code> is typically a symbolic link to the preferred video device. Note the same device files are used for video output devices.</p><div class="section" title="Querying Capabilities"><div class="titlepage"><div><div><h3 class="title"><a id="id2650920"></a>Querying Capabilities</h3></div></div></div><p>Devices supporting the video capture interface set the <code class="constant">V4L2_CAP_VIDEO_CAPTURE</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. As secondary device functions they may also support the <a class="link" href="ch04s02.html" title="Video Overlay Interface">video overlay</a> (<code class="constant">V4L2_CAP_VIDEO_OVERLAY</code>) and the <a class="link" href="ch04s07.html" title="Raw VBI Data Interface">raw VBI capture</a> (<code class="constant">V4L2_CAP_VBI_CAPTURE</code>) interface. At least one of the read/write or streaming I/O methods 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="id2651594"></a>Supplemental Functions</h3></div></div></div><p>Video capture 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 capture devices.</p></div><div class="section" title="Image Format Negotiation"><div class="titlepage"><div><div><h3 class="title"><a id="id2651658"></a>Image Format Negotiation</h3></div></div></div><p>The result of a capture operation is determined by cropping and image format parameters. The former select an area of the video picture to capture, the latter how images are stored in memory, i. e. in RGB or YUV format, the number of bits per pixel or width and height. Together they also define how images are scaled in the process.</p><p>As usual these parameters are <span class="emphasis"><em>not</em></span> reset at <a class="link" href="re64.html" title="V4L2 open()"><code class="function">open()</code></a> time to permit Unix tool chains, programming a device and then reading from it as if it was a plain file. Well written V4L2 applications ensure they really get what they want, including cropping and scaling.</p><p>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>To query the current image format 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_CAPTURE</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 with a pointer to this structure. Drivers fill the struct <a class="link" href="ch02.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a> <em class="structfield"><code>pix</code></em> member of the <em class="structfield"><code>fmt</code></em> union.</p><p>To request different 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> as above and initialize all fields of the struct <a class="link" href="ch02.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a> <em class="structfield"><code>vbi</code></em> member of the <em class="structfield"><code>fmt</code></em> union, or better just modify the results of <code class="constant">VIDIOC_G_FMT</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_S_FMT</code></a> ioctl with a pointer to this structure. Drivers may adjust the parameters and finally return the actual parameters as <code class="constant">VIDIOC_G_FMT</code> does.</p><p>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 hardware limitations without disabling I/O or possibly time consuming hardware preparations.</p><p>The contents of struct <a class="link" href="ch02.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a> are discussed in <a class="xref" href="ch02.html" title="Chapter 2. Image Formats">Chapter 2, <i>Image Formats</i></a>. See also the specification of the <code class="constant">VIDIOC_G_FMT</code>, <code class="constant">VIDIOC_S_FMT</code> and <code class="constant">VIDIOC_TRY_FMT</code> ioctls for details. Video capture devices must implement both the <code class="constant">VIDIOC_G_FMT</code> and <code class="constant">VIDIOC_S_FMT</code> ioctl, even if <code class="constant">VIDIOC_S_FMT</code> ignores all requests and always returns default parameters as <code class="constant">VIDIOC_G_FMT</code> does. <code class="constant">VIDIOC_TRY_FMT</code> is optional.</p></div><div class="section" title="Reading Images"><div class="titlepage"><div><div><h3 class="title"><a id="id2651862"></a>Reading Images</h3></div></div></div><p>A video capture device may support the <a class="link" href="ch03.html#rw" title="Read/Write">read() function</a> and/or streaming (<a class="link" href="ch03s02.html" title="Streaming I/O (Memory Mapping)">memory mapping</a> or <a class="link" href="ch03s03.html" title="Streaming I/O (User Pointers)">user pointer</a>) I/O. See <a class="xref" href="ch03.html" title="Chapter 3. Input/Output">Chapter 3, <i>Input/Output</i></a> for details.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Field Order </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Video Overlay Interface</td></tr></table></div></body></html>