1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Video Standards</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="common.html" title="Chapter&#160;1.&#160;Common API Elements"><link rel="prev" href="tuner.html" title="Tuners and Modulators"><link rel="next" href="dv-timings.html" title="Digital Video (DV) Timings"></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">Video Standards</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tuner.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;1.&#160;Common API Elements</th><td width="20%" align="right">&#160;<a accesskey="n" href="dv-timings.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="standard"></a>Video Standards</h2></div></div></div><p>Video devices typically support one or more different video
2standards or variations of standards. Each video input and output may
3support another set of standards. This set is reported by the
4<em class="structfield"><code>std</code></em> field of struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a> and
5struct&#160;<a class="link" href="vidioc-enumoutput.html#v4l2-output" title="Table&#160;A.43.&#160;struct v4l2_output">v4l2_output</a> returned by the <a class="link" href="vidioc-enuminput.html" title="ioctl VIDIOC_ENUMINPUT"><code class="constant">VIDIOC_ENUMINPUT</code></a> and
6<a class="link" href="vidioc-enumoutput.html" title="ioctl VIDIOC_ENUMOUTPUT"><code class="constant">VIDIOC_ENUMOUTPUT</code></a> ioctls, respectively.</p><p>V4L2 defines one bit for each analog video standard
7currently in use worldwide, and sets aside bits for driver defined
8standards, e.&#160;g. hybrid standards to watch NTSC video tapes on PAL TVs
9and vice versa. Applications can use the predefined bits to select a
10particular standard, although presenting the user a menu of supported
11standards is preferred. To enumerate and query the attributes of the
12supported standards applications use the <a class="link" href="vidioc-enumstd.html" title="ioctl VIDIOC_ENUMSTD"><code class="constant">VIDIOC_ENUMSTD</code></a> ioctl.</p><p>Many of the defined standards are actually just variations
13of a few major standards. The hardware may in fact not distinguish
14between them, or do so internal and switch automatically. Therefore
15enumerated standards also contain sets of one or more standard
16bits.</p><p>Assume a hypothetic tuner capable of demodulating B/PAL,
17G/PAL and I/PAL signals. The first enumerated standard is a set of B
18and G/PAL, switched automatically depending on the selected radio
19frequency in UHF or VHF band. Enumeration gives a "PAL-B/G" or "PAL-I"
20choice. Similar a Composite input may collapse standards, enumerating
21"PAL-B/G/H/I", "NTSC-M" and "SECAM-D/K".<a href="#ftn.idp1096857284" class="footnote" name="idp1096857284"><sup class="footnote">[5]</sup></a></p><p>To query and select the standard used by the current video
22input or output applications call the <a class="link" href="vidioc-g-std.html" title="ioctl VIDIOC_G_STD, VIDIOC_S_STD"><code class="constant">VIDIOC_G_STD</code></a> and
23<a class="link" href="vidioc-g-std.html" title="ioctl VIDIOC_G_STD, VIDIOC_S_STD"><code class="constant">VIDIOC_S_STD</code></a> ioctl, respectively. The <span class="emphasis"><em>received</em></span>
24standard can be sensed with the <a class="link" href="vidioc-querystd.html" title="ioctl VIDIOC_QUERYSTD"><code class="constant">VIDIOC_QUERYSTD</code></a> ioctl. Note that the
25parameter of all these ioctls is a pointer to a <a class="link" href="vidioc-enumstd.html#v4l2-std-id" title="Table&#160;A.48.&#160;typedef v4l2_std_id">v4l2_std_id</a> type
26(a standard set), <span class="emphasis"><em>not</em></span> an index into the standard
27enumeration. Drivers must implement all video standard ioctls
28when the device has one or more video inputs or outputs.</p><p>Special rules apply to devices such as USB cameras where the notion of video
29standards makes little sense. More generally for any capture or output device
30which is: </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>incapable of capturing fields or frames at the nominal
31rate of the video standard, or</p></li><li class="listitem"><p>that does not support the video standard formats at all.</p></li></ul></div><p> Here the driver shall set the
32<em class="structfield"><code>std</code></em> field of struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a> and struct&#160;<a class="link" href="vidioc-enumoutput.html#v4l2-output" title="Table&#160;A.43.&#160;struct v4l2_output">v4l2_output</a>
33to zero and the <code class="constant">VIDIOC_G_STD</code>,
34<code class="constant">VIDIOC_S_STD</code>,
35<code class="constant">VIDIOC_QUERYSTD</code> and
36<code class="constant">VIDIOC_ENUMSTD</code> ioctls shall return the
37<span class="errorcode">ENOTTY</span> error code or the <span class="errorcode">EINVAL</span> error code.</p><p>Applications can make use of the <a class="xref" href="vidioc-enuminput.html#input-capabilities" title="Table&#160;A.42.&#160;Input capabilities">Table&#160;A.42, &#8220;Input capabilities&#8221;</a> and
38<a class="xref" href="vidioc-enumoutput.html#output-capabilities" title="Table&#160;A.45.&#160;Output capabilities">Table&#160;A.45, &#8220;Output capabilities&#8221;</a> flags to determine whether the video standard ioctls
39can be used with the given input or output.</p><div class="example"><a name="idp1096867468"></a><p class="title"><b>Example&#160;1.5.&#160;Information about the current video standard</b></p><div class="example-contents"><pre class="programlisting">
40<a class="link" href="vidioc-enumstd.html#v4l2-std-id" title="Table&#160;A.48.&#160;typedef v4l2_std_id">v4l2_std_id</a> std_id;
41struct&#160;<a class="link" href="vidioc-enumstd.html#v4l2-standard" title="Table&#160;A.46.&#160;struct v4l2_standard">v4l2_standard</a> standard;
42
43if (-1 == ioctl(fd, <a class="link" href="vidioc-g-std.html" title="ioctl VIDIOC_G_STD, VIDIOC_S_STD"><code class="constant">VIDIOC_G_STD</code></a>, &amp;std_id)) {
44	/* Note when VIDIOC_ENUMSTD always returns ENOTTY this
45	   is no video device or it falls under the USB exception,
46	   and VIDIOC_G_STD returning ENOTTY is no error. */
47
48	perror("VIDIOC_G_STD");
49	exit(EXIT_FAILURE);
50}
51
52memset(&amp;standard, 0, sizeof(standard));
53standard.index = 0;
54
55while (0 == ioctl(fd, <a class="link" href="vidioc-enumstd.html" title="ioctl VIDIOC_ENUMSTD"><code class="constant">VIDIOC_ENUMSTD</code></a>, &amp;standard)) {
56	if (standard.id &amp; std_id) {
57	       printf("Current video standard: %s\n", standard.name);
58	       exit(EXIT_SUCCESS);
59	}
60
61	standard.index++;
62}
63
64/* EINVAL indicates the end of the enumeration, which cannot be
65   empty unless this device falls under the USB exception. */
66
67if (errno == EINVAL || standard.index == 0) {
68	perror("VIDIOC_ENUMSTD");
69	exit(EXIT_FAILURE);
70}
71      </pre></div></div><br class="example-break"><div class="example"><a name="idp1096871812"></a><p class="title"><b>Example&#160;1.6.&#160;Listing the video standards supported by the current
72input</b></p><div class="example-contents"><pre class="programlisting">
73struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a> input;
74struct&#160;<a class="link" href="vidioc-enumstd.html#v4l2-standard" title="Table&#160;A.46.&#160;struct v4l2_standard">v4l2_standard</a> standard;
75
76memset(&amp;input, 0, sizeof(input));
77
78if (-1 == ioctl(fd, <a class="link" href="vidioc-g-input.html" title="ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT"><code class="constant">VIDIOC_G_INPUT</code></a>, &amp;input.index)) {
79	perror("VIDIOC_G_INPUT");
80	exit(EXIT_FAILURE);
81}
82
83if (-1 == ioctl(fd, <a class="link" href="vidioc-enuminput.html" title="ioctl VIDIOC_ENUMINPUT"><code class="constant">VIDIOC_ENUMINPUT</code></a>, &amp;input)) {
84	perror("VIDIOC_ENUM_INPUT");
85	exit(EXIT_FAILURE);
86}
87
88printf("Current input %s supports:\n", input.name);
89
90memset(&amp;standard, 0, sizeof(standard));
91standard.index = 0;
92
93while (0 == ioctl(fd, <a class="link" href="vidioc-enumstd.html" title="ioctl VIDIOC_ENUMSTD"><code class="constant">VIDIOC_ENUMSTD</code></a>, &amp;standard)) {
94	if (standard.id &amp; input.std)
95		printf("%s\n", standard.name);
96
97	standard.index++;
98}
99
100/* EINVAL indicates the end of the enumeration, which cannot be
101   empty unless this device falls under the USB exception. */
102
103if (errno != EINVAL || standard.index == 0) {
104	perror("VIDIOC_ENUMSTD");
105	exit(EXIT_FAILURE);
106}
107      </pre></div></div><br class="example-break"><div class="example"><a name="idp1096876036"></a><p class="title"><b>Example&#160;1.7.&#160;Selecting a new video standard</b></p><div class="example-contents"><pre class="programlisting">
108struct&#160;<a class="link" href="vidioc-enuminput.html#v4l2-input" title="Table&#160;A.39.&#160;struct v4l2_input">v4l2_input</a> input;
109<a class="link" href="vidioc-enumstd.html#v4l2-std-id" title="Table&#160;A.48.&#160;typedef v4l2_std_id">v4l2_std_id</a> std_id;
110
111memset(&amp;input, 0, sizeof(input));
112
113if (-1 == ioctl(fd, <a class="link" href="vidioc-g-input.html" title="ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT"><code class="constant">VIDIOC_G_INPUT</code></a>, &amp;input.index)) {
114	perror("VIDIOC_G_INPUT");
115	exit(EXIT_FAILURE);
116}
117
118if (-1 == ioctl(fd, <a class="link" href="vidioc-enuminput.html" title="ioctl VIDIOC_ENUMINPUT"><code class="constant">VIDIOC_ENUMINPUT</code></a>, &amp;input)) {
119	perror("VIDIOC_ENUM_INPUT");
120	exit(EXIT_FAILURE);
121}
122
123if (0 == (input.std &amp; V4L2_STD_PAL_BG)) {
124	fprintf(stderr, "Oops. B/G PAL is not supported.\n");
125	exit(EXIT_FAILURE);
126}
127
128/* Note this is also supposed to work when only B
129   <span class="emphasis"><em>or</em></span> G/PAL is supported. */
130
131std_id = V4L2_STD_PAL_BG;
132
133if (-1 == ioctl(fd, <a class="link" href="vidioc-g-std.html" title="ioctl VIDIOC_G_STD, VIDIOC_S_STD"><code class="constant">VIDIOC_S_STD</code></a>, &amp;std_id)) {
134	perror("VIDIOC_S_STD");
135	exit(EXIT_FAILURE);
136}
137      </pre></div></div><br class="example-break"><div class="footnotes"><br><hr style="width:100; text-align:left;margin-left: 0"><div id="ftn.idp1096857284" class="footnote"><p><a href="#idp1096857284" class="para"><sup class="para">[5] </sup></a>Some users are already confused by technical terms PAL,
138NTSC and SECAM. There is no point asking them to distinguish between
139B, G, D, or K when the software or hardware can do that
140automatically.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tuner.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="common.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="dv-timings.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Tuners and Modulators&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Digital Video (DV) Timings</td></tr></table></div></body></html>
141