Import 2.1.118
[davej-history.git] / Documentation / video4linux / API.html
blob5b3780cc308be3c8bd5b97ad73815deb96f7addc
1 <HTML><HEAD>
2 <TITLE>Video4Linux Kernel API Reference v0.1:19980516</TITLE>
3 </HEAD>
4 <BODY bgcolor="#ffffff">
5 <H3>Devices</H3>
6 Video4Linux provides the following sets of device files. These live on the
7 character device formerly known as "/dev/bttv". /dev/bttv should be a
8 symlink to /dev/video0 for most people.
9 <P>
10 <TABLE>
11 <TR><TH>Device Name</TH><TH>Minor Range</TH><TH>Function</TH>
12 <TR><TD>/dev/video</TD><TD>0-63</TD><TD>Video Capture Interface</TD>
13 <TR><TD>/dev/radio</TD><TD>64-127</TD><TD>AM/FM Radio Devices</TD>
14 <TR><TD>/dev/vtx</TD><TD>192-223</TD><TD>Teletext Interface Chips</TD>
15 <TR><TD>/dev/vbi</TD><TD>224-239</TD><TD>Raw VBI Data (Intercast/teletext)</TD>
16 </TABLE>
17 <P>
18 Video4Linux programs open and scan the devices to find what they are looking
19 for. Capability queries define what each interface supports. The
20 described API is only defined for video capture cards. The relevant subset
21 applies to radio cards. Teletext interfaces talk the existing VTX API.
22 <P>
23 <H3>Capability Query Ioctl</H3>
24 The <B>VIDIOCGCAP</B> ioctl call is used to obtain the capability
25 information for a video device. The <b>struct video_capability</b> object
26 passed to the ioctl is completed and returned. It contains the following
27 information
28 <P>
29 <TABLE>
30 <TR><TD><b>name[32]</b><TD>Cannonical name for this interface</TD>
31 <TR><TD><b>type</b><TD>Type of interface</TD>
32 <TR><TD><b>channels</b><TD>Number of radio/tv channels if appropriate</TD>
33 <TR><TD><b>audios</b><TD>Number of audio devices if appropriate</TD>
34 <TR><TD><b>maxwidth</b><TD>Maximum capture width in pixels</TD>
35 <TR><TD><b>maxheight</b><TD>Maximum capture height in pixels</TD>
36 <TR><TD><b>minwidth</b><TD>Minimum capture width in pixels</TD>
37 <TR><TD><b>minheight</b><TD>Minimum capture height in pixels</TD>
38 </TABLE>
39 <P>
40 The type field lists the capability flags for the device. These are
41 as follows
42 <P>
43 <TABLE>
44 <TR><TH>Name</TH><TH>Description</TH>
45 <TR><TD><b>VID_TYPE_CAPTURE</b><TD>Can capture to memory</TD>
46 <TR><TD><b>VID_TYPE_TUNER</b><TD>Has a tuner of some form</TD>
47 <TR><TD><b>VID_TYPE_TELETEXT</b><TD>Has teletext capability</TD>
48 <TR><TD><b>VID_TYPE_OVERLAY</b><TD>Can overlay its image onto the frame buffer</TD>
49 <TR><TD><b>VID_TYPE_CHROMAKEY</b><TD>Overlay is Chromakeyed</TD>
50 <TR><TD><b>VID_TYPE_CLIPPING</b><TD>Overlay clipping is supported</TD>
51 <TR><TD><b>VID_TYPE_FRAMERAM</b><TD>Overlay overwrites frame buffer memory</TD>
52 <TR><TD><b>VID_TYPE_SCALES</b><TD>The hardware supports image scaling</TD>
53 <TR><TD><b>VID_TYPE_MONOCHROME</b><TD>Image capture is grey scale only</TD>
54 <TR><TD><b>VID_TYPE_SUBCAPTURE</b><TD>Capture can be of only part of the image</TD>
55 </TABLE>
56 <P>
57 The minimum and maximum sizes listed for a capture device do not imply all
58 that all height/width ratios or sizes within the range are possible. A
59 request to set a size will be honoured by the largest available capture
60 size whose capture is no large than the requested rectangle in either
61 direction. For example the quickcam has 3 fixed settings.
62 <P>
63 <H3>Frame Buffer</H3>
64 Capture cards that drop data directly onto the frame buffer must be told the
65 base address of the frame buffer, its size and organisation. This is a
66 privileged ioctl and one that eventually X itself should set.
67 <P>
68 The <b>VIDIOCSFBUF</b> ioctl sets the frame buffer parameters for a capture
69 card. If the card does not do direct writes to the frame buffer then this
70 ioctl will be unsupported. The <b>VIDIOCGFBUF</b> ioctl returns the
71 currently used parameters. The structure used in both cases is a
72 <b>struct video_buffer</b>.
73 <P>
74 <TABLE>
75 <TR><TD><b>void *base</b></TD><TD>Base physical address of the buffer</TD>
76 <TR><TD><b>int height</b></TD><TD>Height of the frame buffer</TD>
77 <TR><TD><b>int width</b></TD><TD>Width of the frame buffer</TD>
78 <TR><TD><b>int depth</b></TD><TD>Depth of the frame buffer</TD>
79 <TR><TD><b>int bytesperline</b></TD><TD>Number of bytes of memory between the start of two adjacent lines</TD>
80 </TABLE>
81 <P>
82 Note that these values reflect the physical layout of the frame buffer.
83 The visible area may be smaller. In fact under XFree86 this is commonly the
84 case. XFree86 DGA can provide the parameters required to set up this ioctl.
85 Setting the base address to NULL indicates there is no physical frame buffer
86 access.
87 <P>
88 <H3>Capture Windows</H3>
89 The capture area is described by a <b>struct video_window</b>. This defines
90 a capture area and the clipping information if relevant. The
91 <b>VIDIOCGWIN</b> ioctl recovers the current settings and the
92 <b>VIDIOCSWIN</b> sets new values. A successful call to <b>VIDIOCSWIN</b>
93 indicates that a suitable set of parameters have been chosen. They do not
94 indicate that exactly what was requested was granted. The program should
95 call <b>VIDIOCGWIN</b> to check if the nearest match was suitable. The
96 <b>struct video_window</b> contains the following fields.
97 <P>
98 <TABLE>
99 <TR><TD><b>x</b><TD>The X co-ordinate specified in X windows format.</TD>
100 <TR><TD><b>y</b><TD>The Y co-ordinate specified in X windows format.</TD>
101 <TR><TD><b>width</b><TD>The width of the image capture.</TD>
102 <TR><TD><b>height</b><TD>The height of the image capture.</TD>
103 <TR><TD><b>chromakey</b><TD>A host order RGB32 value for the chroma key.</TD>
104 <TR><TD><b>flags</b><TD>Additional capture flags.</TD>
105 <TR><TD><b>clips</b><TD>A list of clipping rectangles. <em>(Set only)</em)</TD>
106 <TR><TD><b>clipcount</b><TD>The number of clipping rectangles. <em>(Set only)</em></TD>
107 </TABLE>
109 Clipping rectangles are passed as an array. Each clip consists of the following
110 fields available to the user.
112 <TABLE>
113 <TR><TD><b>x</b></TD><TD>X co-ordinate of rectangle to skip</TD>
114 <TR><TD><b>y</b></TD><TD>Y co-ordinate of rectangle to skip</TD>
115 <TR><TD><b>width</b></TD><TD>Width of rectangle to skip</TD>
116 <TR><TD><b>height</b></TD><TD>Height of rectangle to skip</TD>
117 </TABLE>
119 Merely setting the window does not enable capturing. Overlay capturing
120 is activatied by passing the <b>VIDIOCCAPTURE</b> ioctl a value of 1, and
121 disabled by passing it a value of 0.
123 Some capture devices can capture a subfield of the image they actually see.
124 This is indicated when VIDEO_TYPE_SUBCAPTURE is defined.
125 The video_capture describes the time and spacial subfields to capture.
126 The video_capture structure contains the following fields.
128 <TABLE>
129 <TR><TD><b>x</b></TD><TD>X co-ordinate of source rectangle to grab</TD>
130 <TR><TD><b>y</b></TD><TD>Y co-ordinate of source rectangle to grab</TD>
131 <TR><TD><b>width</b></TD><TD>Width of source rectangle to grab</TD>
132 <TR><TD><b>height</b></TD><TD>Height of source rectangle to grab</TD>
133 <TR><TD><b>decimation</b></TD><TD>Decimation to apply</TD>
134 <TR><TD><b>flags</b></TD><TD>Flag settings for grabbing</TD>
135 </TABLE>
136 The available flags are
138 <TABLE>
139 <TR><TH>Name</TH><TH>Description</TH>
140 <TR><TD><b>VIDEO_CAPTURE_ODD</b><TD>Capture only odd frames</TD>
141 <TR><TD><b>VIDEO_CAPTURE_EVEN</b><TD>Capture only even frames</TD>
142 </TABLE>
144 <H3>Video Sources</H3>
145 Each video4linux video or audio device captures from one or more
146 source <b>channels</b>. Each channel can be queries with the
147 <b>VDIOCGCHAN</b> ioctl call. Before invoking this function the caller
148 must set the channel field to the channel that is being queried. On return
149 the <b>struct video_channel</b> is filled in with information about the
150 nature of the channel itself.
152 The <b>VIDIOCSCHAN</b> ioctl takes an integer argument and switches the
153 capture to this input. It is not defined whether paramters such as colour
154 settings or tuning are maintained across a channel switch. The caller should
155 maintain settings as desired for each channel. (This is reasonable as
156 different video inputs may have different properties).
158 The <b>struct video_channel</b> consists of the following
160 <TABLE>
161 <TR><TD><b>channel</b></TD><TD>The channel number</TD>
162 <TR><TD><b>name</b></TD><TD>The input name - preferably reflecting the label
163 on the card input itself</TD>
164 <TR><TD><b>tuners</b></TD><TD>Number of tuners for this input</TD>
165 <TR><TD><b>flags</b></TD><TD>Properties the tuner has</TD>
166 <TR><TD><b>type</b></TD><TD>Input type (if known)</TD>
167 <TR><TD><b>norm</b><TD>The norm for this channel</TD>
168 </TABLE>
170 The flags defined are
172 <TABLE>
173 <TR><TD><b>VIDEO_VC_TUNER</b><TD>Channel has tuners.</TD>
174 <TR><TD><b>VIDEO_VC_AUDIO</b><TD>Channel has audio.</TD>
175 <TR><TD><b>VIDEO_VC_NORM</b><TD>Channel has norm setting.</TD>
176 </TABLE>
178 The types defined are
180 <TABLE>
181 <TR><TD><b>VIDEO_TYPE_TV</b><TD>The input is a TV input.</TD>
182 <TR><TD><b>VIDEO_TYPE_CAMERA</b><TD>The input is a camera.</TD>
183 </TABLE>
185 <H3>Image Properties</H3>
186 The image properties of the picture can be queried with the <b>VIDIOCGPICT</b>
187 ioctl which fills in a <b>struct video_picture</b>. The <b>VIDIOCSPICT</b>
188 ioctl allows values to be changed. All values except for the palette type
189 are scaled between 0-65535.
191 The <b>struct video_picture</b> consists of the following fields
193 <TABLE>
194 <TR><TD><b>brightness</b><TD>Picture brightness</TD>
195 <TR><TD><b>hue</b><TD>Picture hue (colour only)</TD>
196 <TR><TD><b>colour</b><TD>Picture colour (colour only)</TD>
197 <TR><TD><b>contrast</b><TD>Picture contrast</TD>
198 <TR><TD><b>whiteness</b><TD>The whiteness (greyscale only)</TD>
199 <TR><TD><b>depth</b><TD>The capture depth (may need to match the frame buffer depth)</TD>
200 <TR><TD><b>palette</b><TD>Reports the palette that should be used for this image</TD>
201 </TABLE>
203 The following palettes are defined
205 <TABLE>
206 <TR><TD><b>VIDEO_PALETTE_GREY</b><TD>Linear intensity grey scale (255 is brightest).</TD>
207 <TR><TD><b>VIDEO_PALETTE_HI240</b><TD>The BT848 8bit colour cube.</TD>
208 <TR><TD><b>VIDEO_PALETTE_RGB565</b><TD>RGB565 packed into 16 bit words.</TD>
209 <TR><TD><b>VIDEO_PALETTE_RGB555</b><TD>RGV555 packed into 16 bit words, top bit undefined.</TD>
210 <TR><TD><b>VIDEO_PALETTE_RGB24</b><TD>RGB888 packed into 24bit words.</TD>
211 <TR><TD><b>VIDEO_PALETTE_RGB32</b><TD>RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.</TD>
212 <TR><TD><b>VIDEO_PALETTE_YUV422</b><TD>Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V</TD>
213 <TR><TD><b>VIDEO_PALETTE_YUYV</b><TD>Describe me</TD>
214 <TR><TD><b>VIDEO_PALETTE_UYVY</b><TD>Describe me</TD>
215 <TR><TD><b>VIDEO_PALETTE_YUV420</b><TD>YUV420 capture</TD>
216 <TR><TD><b>VIDEO_PALETTE_YUV411</b><TD>YUV411 capture</TD>
217 <TR><TD><b>VIDEO_PALETTE_RAW</b><TD>RAW capture (BT848)</TD>
218 <TR><TD><b>VIDEO_PALETTE_YUV422P</b><TD>YUV 4:2:2 Planar</TD>
219 <TR><TD><b>VIDEO_PALETTE_YUV411P</b><TD>YUV 4:1:1 Planar</TD>
220 </TABLE>
222 <H3>Tuning</H3>
223 Each video input channel can have one or more tuners associated with it. Many
224 devices will not have tuners. TV cards and radio cards will have one or more
225 tuners attached.
227 Tuners are described by a <b>struct video_tuner</b> which can be obtained by
228 the <b>VIDIOCGTUNER</b> ioctl. Fill in the tuner number in the structure
229 then pass the structure to the ioctl to have the data filled in. The
230 tuner can be switched using <b>VIDIOCSTUNER</b> which takes an integer argument
231 giving the tuner to use. A struct tuner has the following fields
233 <TABLE>
234 <TR><TD><b>tuner</b><TD>Number of the tuner</TD>
235 <TR><TD><b>name</b><TD>Cannonical name for this tuner (eg FM/AM/TV)</TD>
236 <TR><TD><b>rangelow</b><TD>Lowest tunable frequency</TD>
237 <TR><TD><b>rangehigh</b><TD>Highest tunable frequency</TD>
238 <TR><TD><b>flags</b><TD>Flags describing the tuner</TD>
239 <TR><TD><b>mode</b><TD>The video signal mode if relevant</TD>
240 <TR><TD><b>signal</b><TD>Signal strength if known - between 0-65535</TD>
241 </TABLE>
243 The following flags exist
245 <TABLE>
246 <TR><TD><b>VIDEO_TUNER_PAL</b><TD>PAL tuning is supported</TD>
247 <TR><TD><b>VIDEO_TUNER_NTSC</b><TD>NTSC tuning is supported</TD>
248 <TR><TD><b>VIDEO_TUNER_SECAM</b><TD>SECAM tuning is supported</TD>
249 <TR><TD><b>VIDEO_TUNER_LOW</b><TD>Frequency is in a lower range</TD>
250 <TR><TD><b>VIDEO_TUNER_NORM</b><TD>The norm for this tuner is settable</TD>
251 <TR><TD><b>VIDEO_TUNER_STEREO_ON</b><TD>The tuner is seeing stereo audio</TD>
252 </TABLE>
254 The following modes are defined
256 <TABLE>
257 <TR><TD><b>VIDEO_MODE_PAL</b><TD>The tuner is in PAL mode</TD>
258 <TR><TD><b>VIDEO_MODE_NTSC</b><TD>The tuner is in NTSC mode</TD>
259 <TR><TD><b>VIDEO_MODE_SECAM</b><TD>The tuner is in SECAM mode</TD>
260 <TR><TD><b>VIDEO_MODE_AUTO</b><TD>The tuner auto switches, or mode does not apply</TD>
261 </TABLE>
263 Tuning frequencies are an unsigned 32bit value in 1/16th MHz or if the
264 <b>VIDEO_TUNER_LOW</b> flag is set they are in 1/16th KHz. The current
265 frequency is obtained as an unsigned long via the <b>VIDIOCGFREQ</b> ioctl and
266 set by the <b>VIDIOCSFREQ</b> ioctl.
268 <H3>Audio</H3>
269 TV and Radio devices have one or more audio inputs that may be selected.
270 The audio properties are queried by passing a <b>struct video_audio</b> to <b>VIDIOCGAUDIO</b> ioctl. The
271 <b>VIDIOCSAUDIO</b> ioctl sets audio properties.
273 The structure contains the following fields
275 <TABLE>
276 <TR><TD><b>audio</b><TD>The channel number</TD>
277 <TR><TD><b>volume</b><TD>The voume level</TD>
278 <TR><TD><b>bass</b><TD>The bass level</TD>
279 <TR><TD><b>treble</b><TD>The treble level</TD>
280 <TR><TD><b>flags</b><TD>Flags describing the audio channel</TD>
281 <TR><TD><b>name</b><TD>Canonical name for the audio input</TD>
282 <TR><TD><b>mode</b><TD>The mode the audio input is in</TD>
283 <TR><TD><b>balance</b><TD>The left/right balance</TD>
284 <TR><TD><b>step</b><TD>Actual step used by the hardware</TD>
285 </TABLE>
287 The following flags are defined
289 <TABLE>
290 <TR><TD><b>VIDEO_AUDIO_MUTE</b><TD>The audio is muted</TD>
291 <TR><TD><b>VIDEO_AUDIO_MUTABLE</b><TD>Audio muting is supported</TD>
292 <TR><TD><b>VIDEO_AUDIO_VOLUME</b><TD>The volume is controllable</TD>
293 <TR><TD><b>VIDEO_AUDIO_BASS</b><TD>The bass is controllable</TD>
294 <TR><TD><b>VIDEO_AUDIO_TREBLE</b><TD>The treble is controllable</TD>
295 <TR><TD><b>VIDEO_AUDIO_BALANCE</b><TD>The balance is controllable</TD>
296 </TABLE>
298 The following decoding modes are defined
300 <TABLE>
301 <TR><TD><b>VIDEO_SOUND_MONO</b><TD>Mono signal</TD>
302 <TR><TD><b>VIDEO_SOUND_STEREO</b><TD>Stereo signal (NICAM for TV)</TD>
303 <TR><TD><b>VIDEO_SOUND_LANG1</b><TD>European TV alternate language 1</TD>
304 <TR><TD><b>VIDEO_SOUND_LANG2</b><TD>European TV alternate language 2</TD>
305 </TABLE>
307 <H3>Reading Images</H3>
308 Each call to the <b>read</b> syscall returns the next available image from
309 the device. It is up to the caller to set the format and then to pass a
310 suitable size buffer and length to the function. Not all devices will support
311 read operations.
313 A second way to handle image capture is via the mmap interface if supported.
314 To use the mmap interface a user first sets the desired image size and depth
315 properties. Next the VIDIOCGMBUF ioctl is issued. This reports the size
316 of buffer to mmap and the offset within the buffer for each frame. The
317 number of frames supported is device dependant and may only be one.
319 The video_mbuf structure contains the following fields
321 <TABLE>
322 <TR><TD><b>size</b><TD>The number of bytes to map</TD>
323 <TR><TD><b>frames</b><TD>The number of frames</TD>
324 <TR><TD><b>offsets</b><TD>The offset of each frame</TD>
325 </TABLE>
327 Once the mmap has been made the VIDIOCMCAPTURE ioctl sets the image size
328 you wish to use (which should match or be below the initial query size).
329 Having done so it will begin capturing to the memory mapped buffer. Whenever
330 a buffer is "used" by the program it should called VIDIOCSYNC to free this
331 frame up and continue. <em>to add:</em>VIDIOCSYNC takes the frame number
332 you are freeing as its argument. When the buffer is unmapped or all the
333 buffers are full capture ceases. While capturing to memory the driver will
334 make a "best effort" attempt to capture to screen as well if requested. This
335 normally means all frames that "miss" memory mapped capture will go to the
336 display.
338 A final ioctl exists to allow a device to obtain related devices if a
339 driver has multiple components (for example video0 may not be associated
340 with vbi0 which would cause an intercast display program to make a bad
341 mistake). The VIDIOCGUNIT ioctl reports the unit numbers of the associated
342 devices if any exist. The video_unit structure has the following fields.
344 <TABLE>
345 <TR><TD><b>video</b><TD>Video capture device</TD>
346 <TR><TD><b>vbi</b><TD>VBI capture device</TD>
347 <TR><TD><b>radio</b><TD>Radio device</TD>
348 <TR><TD><b>audio</b><TD>Audio mixer</TD>
349 <TR><TD><b>teletext</b><TD>Teletext device</TD>
350 </TABLE>
353 </BODY>
354 </HTML>