1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 4. Interfaces</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="v4l2spec.html" title="Part I. Video for Linux Two API Specification"><link rel="prev" href="field-order.html" title="Field Order"><link rel="next" href="overlay.html" title="Video Overlay Interface"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><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="field-order.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="overlay.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="devices"></a>Chapter 4. Interfaces</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="devices.html#capture">Video Capture Interface</a></span></dt><dd><dl><dt><span class="section"><a href="devices.html#id-1.4.7.2.4">Querying Capabilities</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.5">Supplemental Functions</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.6">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.7">Reading Images</a></span></dt></dl></dd><dt><span class="section"><a href="overlay.html">Video Overlay Interface</a></span></dt><dd><dl><dt><span class="section"><a href="overlay.html#id-1.4.7.3.7">Querying Capabilities</a></span></dt><dt><span class="section"><a href="overlay.html#id-1.4.7.3.8">Supplemental Functions</a></span></dt><dt><span class="section"><a href="overlay.html#id-1.4.7.3.9">Setup</a></span></dt><dt><span class="section"><a href="overlay.html#id-1.4.7.3.10">Overlay Window</a></span></dt><dt><span class="section"><a href="overlay.html#id-1.4.7.3.11">Enabling Overlay</a></span></dt></dl></dd><dt><span class="section"><a href="output.html">Video Output Interface</a></span></dt><dd><dl><dt><span class="section"><a href="output.html#id-1.4.7.4.4">Querying Capabilities</a></span></dt><dt><span class="section"><a href="output.html#id-1.4.7.4.5">Supplemental Functions</a></span></dt><dt><span class="section"><a href="output.html#id-1.4.7.4.6">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="output.html#id-1.4.7.4.7">Writing Images</a></span></dt></dl></dd><dt><span class="section"><a href="osd.html">Video Output Overlay Interface</a></span></dt><dd><dl><dt><span class="section"><a href="osd.html#id-1.4.7.5.5">Querying Capabilities</a></span></dt><dt><span class="section"><a href="osd.html#id-1.4.7.5.6">Framebuffer</a></span></dt><dt><span class="section"><a href="osd.html#id-1.4.7.5.7">Overlay Window and Scaling</a></span></dt><dt><span class="section"><a href="osd.html#id-1.4.7.5.8">Enabling Overlay</a></span></dt></dl></dd><dt><span class="section"><a href="codec.html">Codec Interface</a></span></dt><dt><span class="section"><a href="effect.html">Effect Devices Interface</a></span></dt><dt><span class="section"><a href="raw-vbi.html">Raw VBI Data Interface</a></span></dt><dd><dl><dt><span class="section"><a href="raw-vbi.html#id-1.4.7.8.6">Querying Capabilities</a></span></dt><dt><span class="section"><a href="raw-vbi.html#id-1.4.7.8.7">Supplemental Functions</a></span></dt><dt><span class="section"><a href="raw-vbi.html#id-1.4.7.8.8">Raw VBI Format Negotiation</a></span></dt><dt><span class="section"><a href="raw-vbi.html#id-1.4.7.8.9">Reading and writing VBI images</a></span></dt></dl></dd><dt><span class="section"><a href="sliced.html">Sliced VBI Data Interface</a></span></dt><dd><dl><dt><span class="section"><a href="sliced.html#id-1.4.7.9.5">Querying Capabilities</a></span></dt><dt><span class="section"><a href="sliced.html#id-1.4.7.9.6">Supplemental Functions</a></span></dt><dt><span class="section"><a href="sliced.html#sliced-vbi-format-negotitation">Sliced VBI Format Negotiation</a></span></dt><dt><span class="section"><a href="sliced.html#id-1.4.7.9.8">Reading and writing sliced VBI data</a></span></dt><dt><span class="section"><a href="sliced.html#id-1.4.7.9.9">Sliced VBI Data in MPEG Streams</a></span></dt></dl></dd><dt><span class="section"><a href="ttx.html">Teletext Interface</a></span></dt><dt><span class="section"><a href="radio.html">Radio Interface</a></span></dt><dd><dl><dt><span class="section"><a href="radio.html#id-1.4.7.11.4">Querying Capabilities</a></span></dt><dt><span class="section"><a href="radio.html#id-1.4.7.11.5">Supplemental Functions</a></span></dt><dt><span class="section"><a href="radio.html#id-1.4.7.11.6">Programming</a></span></dt></dl></dd><dt><span class="section"><a href="rds.html">RDS Interface</a></span></dt><dd><dl><dt><span class="section"><a href="rds.html#id-1.4.7.12.6">Querying Capabilities</a></span></dt><dt><span class="section"><a href="rds.html#reading-rds-data">Reading RDS data</a></span></dt><dt><span class="section"><a href="rds.html#writing-rds-data">Writing RDS data</a></span></dt><dt><span class="section"><a href="rds.html#id-1.4.7.12.9">RDS datastructures</a></span></dt></dl></dd><dt><span class="section"><a href="sdr.html">Software Defined Radio Interface (SDR)</a></span></dt><dd><dl><dt><span class="section"><a href="sdr.html#id-1.4.7.13.5">Querying Capabilities</a></span></dt><dt><span class="section"><a href="sdr.html#id-1.4.7.13.6">Supplemental Functions</a></span></dt><dt><span class="section"><a href="sdr.html#id-1.4.7.13.7">Data Format Negotiation</a></span></dt></dl></dd><dt><span class="section"><a href="event.html">Event Interface</a></span></dt><dt><span class="section"><a href="subdev.html">Sub-device Interface</a></span></dt><dd><dl><dt><span class="section"><a href="subdev.html#id-1.4.7.15.7">Controls</a></span></dt><dt><span class="section"><a href="subdev.html#id-1.4.7.15.8">Events</a></span></dt><dt><span class="section"><a href="subdev.html#pad-level-formats">Pad-level Formats</a></span></dt><dt><span class="section"><a href="subdev.html#v4l2-mbus-format">Media Bus Formats</a></span></dt></dl></dd></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="capture"></a>Video Capture Interface</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="devices.html#id-1.4.7.2.4">Querying Capabilities</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.5">Supplemental Functions</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.6">Image Format Negotiation</a></span></dt><dt><span class="section"><a href="devices.html#id-1.4.7.2.7">Reading Images</a></span></dt></dl></div><p>Video capture devices sample an analog video signal and store
2the digitized images in memory. Today nearly all devices can capture
3at full 25 or 30 frames/second. With this interface applications can
4control the capture process and move images from the driver into user
5space.</p><p>Conventionally V4L2 video capture devices are accessed through
6character device special files named <code class="filename">/dev/video</code>
7and <code class="filename">/dev/video0</code> to
8<code class="filename">/dev/video63</code> with major number 81 and minor
9numbers 0 to 63. <code class="filename">/dev/video</code> is typically a
10symbolic link to the preferred video device. Note the same device
11files are used for video output devices.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="id-1.4.7.2.4"></a>Querying Capabilities</h3></div></div></div><p>Devices supporting the video capture interface set the
12<code class="constant">V4L2_CAP_VIDEO_CAPTURE</code> or
13<code class="constant">V4L2_CAP_VIDEO_CAPTURE_MPLANE</code> flag in the
14<em class="structfield"><code>capabilities</code></em> field of struct <a class="link" href="vidioc-querycap.html#v4l2-capability" title="Table A.93. struct v4l2_capability">v4l2_capability</a>
15returned by the <a class="link" href="vidioc-querycap.html" title="ioctl VIDIOC_QUERYCAP"><code class="constant">VIDIOC_QUERYCAP</code></a> ioctl. As secondary device functions
16they may also support the <a class="link" href="overlay.html" title="Video Overlay Interface">video overlay</a>
17(<code class="constant">V4L2_CAP_VIDEO_OVERLAY</code>) and the <a class="link" href="raw-vbi.html" title="Raw VBI Data Interface">raw VBI capture</a>
18(<code class="constant">V4L2_CAP_VBI_CAPTURE</code>) interface. At least one of
19the read/write or streaming I/O methods must be supported. Tuners and
20audio inputs are optional.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="id-1.4.7.2.5"></a>Supplemental Functions</h3></div></div></div><p>Video capture devices shall support <a class="link" href="audio.html" title="Audio Inputs and Outputs">audio input</a>, <a class="link" href="tuner.html" title="Tuners and Modulators">tuner</a>, <a class="link" href="control.html" title="User Controls">controls</a>,
21<a class="link" href="crop.html" title="Image Cropping, Insertion and Scaling">cropping and scaling</a> and <a class="link" href="streaming-par.html" title="Streaming Parameters">streaming parameter</a> ioctls as needed.
22The <a class="link" href="video.html" title="Video Inputs and Outputs">video input</a> and <a class="link" href="standard.html" title="Video Standards">video standard</a> ioctls must be supported by
23all video capture devices.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="id-1.4.7.2.6"></a>Image Format Negotiation</h3></div></div></div><p>The result of a capture operation is determined by
24cropping and image format parameters. The former select an area of the
25video picture to capture, the latter how images are stored in memory,
26i. e. in RGB or YUV format, the number of bits per pixel or width and
27height. Together they also define how images are scaled in the
28process.</p><p>As usual these parameters are <span class="emphasis"><em>not</em></span> reset
29at <a class="link" href="func-open.html" title="V4L2 open()"><code class="function">open()</code></a> time to permit Unix tool chains, programming a device
30and then reading from it as if it was a plain file. Well written V4L2
31applications ensure they really get what they want, including cropping
32and scaling.</p><p>Cropping initialization at minimum requires to reset the
33parameters to defaults. An example is given in <a class="xref" href="crop.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
34<em class="structfield"><code>type</code></em> field of a struct <a class="link" href="vidioc-g-fmt.html#v4l2-format" title="Table A.72. struct v4l2_format">v4l2_format</a> to
35<code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE</code> or
36<code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</code> and call the
37<a class="link" href="vidioc-g-fmt.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
38the struct <a class="link" href="pixfmt.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a> <em class="structfield"><code>pix</code></em> or the
39struct <a class="link" href="ch02s02.html#v4l2-pix-format-mplane" title="Table 2.3. struct v4l2_pix_format_mplane">v4l2_pix_format_mplane</a> <em class="structfield"><code>pix_mp</code></em> member of the
40<em class="structfield"><code>fmt</code></em> union.</p><p>To request different parameters applications set the
41<em class="structfield"><code>type</code></em> field of a struct <a class="link" href="vidioc-g-fmt.html#v4l2-format" title="Table A.72. struct v4l2_format">v4l2_format</a> as above and
42initialize all fields of the struct <a class="link" href="pixfmt.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a>
43<em class="structfield"><code>vbi</code></em> member of the
44<em class="structfield"><code>fmt</code></em> union, or better just modify the
45results of <code class="constant">VIDIOC_G_FMT</code>, and call the
46<a class="link" href="vidioc-g-fmt.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
47adjust the parameters and finally return the actual parameters as
48<code class="constant">VIDIOC_G_FMT</code> does.</p><p>Like <code class="constant">VIDIOC_S_FMT</code> the
49<a class="link" href="vidioc-g-fmt.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
50without disabling I/O or possibly time consuming hardware
51preparations.</p><p>The contents of struct <a class="link" href="pixfmt.html#v4l2-pix-format" title="Table 2.1. struct v4l2_pix_format">v4l2_pix_format</a> and struct <a class="link" href="ch02s02.html#v4l2-pix-format-mplane" title="Table 2.3. struct v4l2_pix_format_mplane">v4l2_pix_format_mplane</a>
52are discussed in <a class="xref" href="pixfmt.html" title="Chapter 2. Image Formats">Chapter 2, <i>Image Formats</i></a>. See also the specification of the
53<code class="constant">VIDIOC_G_FMT</code>, <code class="constant">VIDIOC_S_FMT</code>
54and <code class="constant">VIDIOC_TRY_FMT</code> ioctls for details. Video
55capture devices must implement both the
56<code class="constant">VIDIOC_G_FMT</code> and
57<code class="constant">VIDIOC_S_FMT</code> ioctl, even if
58<code class="constant">VIDIOC_S_FMT</code> ignores all requests and always
59returns default parameters as <code class="constant">VIDIOC_G_FMT</code> does.
60<code class="constant">VIDIOC_TRY_FMT</code> is optional.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="id-1.4.7.2.7"></a>Reading Images</h3></div></div></div><p>A video capture device may support the <a class="link" href="io.html#rw" title="Read/Write">read() function</a> and/or streaming (<a class="link" href="mmap.html" title="Streaming I/O (Memory Mapping)">memory mapping</a> or <a class="link" href="userp.html" title="Streaming I/O (User Pointers)">user pointer</a>) I/O. See <a class="xref" href="io.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="field-order.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="v4l2spec.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="overlay.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>
61