Path: blob/master/Documentation/DocBook/v4l/dev-raw-vbi.xml
10821 views
<title>Raw VBI Data Interface</title>12<para>VBI is an abbreviation of Vertical Blanking Interval, a gap3in the sequence of lines of an analog video signal. During VBI4no picture information is transmitted, allowing some time while the5electron beam of a cathode ray tube TV returns to the top of the6screen. Using an oscilloscope you will find here the vertical7synchronization pulses and short data packages ASK8modulated<footnote><para>ASK: Amplitude-Shift Keying. A high signal9level represents a '1' bit, a low level a '0' bit.</para></footnote>10onto the video signal. These are transmissions of services such as11Teletext or Closed Caption.</para>1213<para>Subject of this interface type is raw VBI data, as sampled off14a video signal, or to be added to a signal for output.15The data format is similar to uncompressed video images, a number of16lines times a number of samples per line, we call this a VBI image.</para>1718<para>Conventionally V4L2 VBI devices are accessed through character19device special files named <filename>/dev/vbi</filename> and20<filename>/dev/vbi0</filename> to <filename>/dev/vbi31</filename> with21major number 81 and minor numbers 224 to 255.22<filename>/dev/vbi</filename> is typically a symbolic link to the23preferred VBI device. This convention applies to both input and output24devices.</para>2526<para>To address the problems of finding related video and VBI27devices VBI capturing and output is also available as device function28under <filename>/dev/video</filename>. To capture or output raw VBI29data with these devices applications must call the &VIDIOC-S-FMT;30ioctl. Accessed as <filename>/dev/vbi</filename>, raw VBI capturing31or output is the default device function.</para>3233<section>34<title>Querying Capabilities</title>3536<para>Devices supporting the raw VBI capturing or output API set37the <constant>V4L2_CAP_VBI_CAPTURE</constant> or38<constant>V4L2_CAP_VBI_OUTPUT</constant> flags, respectively, in the39<structfield>capabilities</structfield> field of &v4l2-capability;40returned by the &VIDIOC-QUERYCAP; ioctl. At least one of the41read/write, streaming or asynchronous I/O methods must be42supported. VBI devices may or may not have a tuner or modulator.</para>43</section>4445<section>46<title>Supplemental Functions</title>4748<para>VBI devices shall support <link linkend="video">video49input or output</link>, <link linkend="tuner">tuner or50modulator</link>, and <link linkend="control">controls</link> ioctls51as needed. The <link linkend="standard">video standard</link> ioctls provide52information vital to program a VBI device, therefore must be53supported.</para>54</section>5556<section>57<title>Raw VBI Format Negotiation</title>5859<para>Raw VBI sampling abilities can vary, in particular the60sampling frequency. To properly interpret the data V4L2 specifies an61ioctl to query the sampling parameters. Moreover, to allow for some62flexibility applications can also suggest different parameters.</para>6364<para>As usual these parameters are <emphasis>not</emphasis>65reset at &func-open; time to permit Unix tool chains, programming a66device and then reading from it as if it was a plain file. Well67written V4L2 applications should always ensure they really get what68they want, requesting reasonable parameters and then checking if the69actual parameters are suitable.</para>7071<para>To query the current raw VBI capture parameters72applications set the <structfield>type</structfield> field of a73&v4l2-format; to <constant>V4L2_BUF_TYPE_VBI_CAPTURE</constant> or74<constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant>, and call the75&VIDIOC-G-FMT; ioctl with a pointer to this structure. Drivers fill76the &v4l2-vbi-format; <structfield>vbi</structfield> member of the77<structfield>fmt</structfield> union.</para>7879<para>To request different parameters applications set the80<structfield>type</structfield> field of a &v4l2-format; as above and81initialize all fields of the &v4l2-vbi-format;82<structfield>vbi</structfield> member of the83<structfield>fmt</structfield> union, or better just modify the84results of <constant>VIDIOC_G_FMT</constant>, and call the85&VIDIOC-S-FMT; ioctl with a pointer to this structure. Drivers return86an &EINVAL; only when the given parameters are ambiguous, otherwise87they modify the parameters according to the hardware capabilites and88return the actual parameters. When the driver allocates resources at89this point, it may return an &EBUSY; to indicate the returned90parameters are valid but the required resources are currently not91available. That may happen for instance when the video and VBI areas92to capture would overlap, or when the driver supports multiple opens93and another process already requested VBI capturing or output. Anyway,94applications must expect other resource allocation points which may95return <errorcode>EBUSY</errorcode>, at the &VIDIOC-STREAMON; ioctl96and the first read(), write() and select() call.</para>9798<para>VBI devices must implement both the99<constant>VIDIOC_G_FMT</constant> and100<constant>VIDIOC_S_FMT</constant> ioctl, even if101<constant>VIDIOC_S_FMT</constant> ignores all requests and always102returns default parameters as <constant>VIDIOC_G_FMT</constant> does.103<constant>VIDIOC_TRY_FMT</constant> is optional.</para>104105<table pgwide="1" frame="none" id="v4l2-vbi-format">106<title>struct <structname>v4l2_vbi_format</structname></title>107<tgroup cols="3">108&cs-str;109<tbody valign="top">110<row>111<entry>__u32</entry>112<entry><structfield>sampling_rate</structfield></entry>113<entry>Samples per second, i. e. unit 1 Hz.</entry>114</row>115<row>116<entry>__u32</entry>117<entry><structfield>offset</structfield></entry>118<entry><para>Horizontal offset of the VBI image,119relative to the leading edge of the line synchronization pulse and120counted in samples: The first sample in the VBI image will be located121<structfield>offset</structfield> /122<structfield>sampling_rate</structfield> seconds following the leading123edge. See also <xref linkend="vbi-hsync" />.</para></entry>124</row>125<row>126<entry>__u32</entry>127<entry><structfield>samples_per_line</structfield></entry>128<entry></entry>129</row>130<row>131<entry>__u32</entry>132<entry><structfield>sample_format</structfield></entry>133<entry><para>Defines the sample format as in <xref134linkend="pixfmt" />, a four-character-code.<footnote>135<para>A few devices may be unable to136sample VBI data at all but can extend the video capture window to the137VBI region.</para>138</footnote> Usually this is139<constant>V4L2_PIX_FMT_GREY</constant>, i. e. each sample140consists of 8 bits with lower values oriented towards the black level.141Do not assume any other correlation of values with the signal level.142For example, the MSB does not necessarily indicate if the signal is143'high' or 'low' because 128 may not be the mean value of the144signal. Drivers shall not convert the sample format by software.</para></entry>145</row>146<row>147<entry>__u32</entry>148<entry><structfield>start</structfield>[2]</entry>149<entry>This is the scanning system line number150associated with the first line of the VBI image, of the first and the151second field respectively. See <xref linkend="vbi-525" /> and152<xref linkend="vbi-625" /> for valid values. VBI input drivers can153return start values 0 if the hardware cannot reliable identify154scanning lines, VBI acquisition may not require this155information.</entry>156</row>157<row>158<entry>__u32</entry>159<entry><structfield>count</structfield>[2]</entry>160<entry>The number of lines in the first and second161field image, respectively.</entry>162</row>163<row>164<entry spanname="hspan"><para>Drivers should be as165flexibility as possible. For example, it may be possible to extend or166move the VBI capture window down to the picture area, implementing a167'full field mode' to capture data service transmissions embedded in168the picture.</para><para>An application can set the first or second169<structfield>count</structfield> value to zero if no data is required170from the respective field; <structfield>count</structfield>[1] if the171scanning system is progressive, &ie; not interlaced. The172corresponding start value shall be ignored by the application and173driver. Anyway, drivers may not support single field capturing and174return both count values non-zero.</para><para>Both175<structfield>count</structfield> values set to zero, or line numbers176outside the bounds depicted in <xref linkend="vbi-525" /> and <xref177linkend="vbi-625" />, or a field image covering178lines of two fields, are invalid and shall not be returned by the179driver.</para><para>To initialize the <structfield>start</structfield>180and <structfield>count</structfield> fields, applications must first181determine the current video standard selection. The &v4l2-std-id; or182the <structfield>framelines</structfield> field of &v4l2-standard; can183be evaluated for this purpose.</para></entry>184</row>185<row>186<entry>__u32</entry>187<entry><structfield>flags</structfield></entry>188<entry>See <xref linkend="vbifmt-flags" /> below. Currently189only drivers set flags, applications must set this field to190zero.</entry>191</row>192<row>193<entry>__u32</entry>194<entry><structfield>reserved</structfield>[2]</entry>195<entry>This array is reserved for future extensions.196Drivers and applications must set it to zero.</entry>197</row>198</tbody>199</tgroup>200</table>201202<table pgwide="1" frame="none" id="vbifmt-flags">203<title>Raw VBI Format Flags</title>204<tgroup cols="3">205&cs-def;206<tbody valign="top">207<row>208<entry><constant>V4L2_VBI_UNSYNC</constant></entry>209<entry>0x0001</entry>210<entry><para>This flag indicates hardware which does not211properly distinguish between fields. Normally the VBI image stores the212first field (lower scanning line numbers) first in memory. This may be213a top or bottom field depending on the video standard. When this flag214is set the first or second field may be stored first, however the215fields are still in correct temporal order with the older field first216in memory.<footnote>217<para>Most VBI services transmit on both fields, but218some have different semantics depending on the field number. These219cannot be reliable decoded or encoded when220<constant>V4L2_VBI_UNSYNC</constant> is set.</para>221</footnote></para></entry>222</row>223<row>224<entry><constant>V4L2_VBI_INTERLACED</constant></entry>225<entry>0x0002</entry>226<entry>By default the two field images will be passed227sequentially; all lines of the first field followed by all lines of228the second field (compare <xref linkend="field-order" />229<constant>V4L2_FIELD_SEQ_TB</constant> and230<constant>V4L2_FIELD_SEQ_BT</constant>, whether the top or bottom231field is first in memory depends on the video standard). When this232flag is set, the two fields are interlaced (cf.233<constant>V4L2_FIELD_INTERLACED</constant>). The first line of the234first field followed by the first line of the second field, then the235two second lines, and so on. Such a layout may be necessary when the236hardware has been programmed to capture or output interlaced video237images and is unable to separate the fields for VBI capturing at238the same time. For simplicity setting this flag implies that both239<structfield>count</structfield> values are equal and non-zero.</entry>240</row>241</tbody>242</tgroup>243</table>244245<figure id="vbi-hsync">246<title>Line synchronization</title>247<mediaobject>248<imageobject>249<imagedata fileref="vbi_hsync.pdf" format="PS" />250</imageobject>251<imageobject>252<imagedata fileref="vbi_hsync.gif" format="GIF" />253</imageobject>254<textobject>255<phrase>Line synchronization diagram</phrase>256</textobject>257</mediaobject>258</figure>259260<figure id="vbi-525">261<title>ITU-R 525 line numbering (M/NTSC and M/PAL)</title>262<mediaobject>263<imageobject>264<imagedata fileref="vbi_525.pdf" format="PS" />265</imageobject>266<imageobject>267<imagedata fileref="vbi_525.gif" format="GIF" />268</imageobject>269<textobject>270<phrase>NTSC field synchronization diagram</phrase>271</textobject>272<caption>273<para>(1) For the purpose of this specification field 2274starts in line 264 and not 263.5 because half line capturing is not275supported.</para>276</caption>277</mediaobject>278</figure>279280<figure id="vbi-625">281<title>ITU-R 625 line numbering</title>282<mediaobject>283<imageobject>284<imagedata fileref="vbi_625.pdf" format="PS" />285</imageobject>286<imageobject>287<imagedata fileref="vbi_625.gif" format="GIF" />288</imageobject>289<textobject>290<phrase>PAL/SECAM field synchronization diagram</phrase>291</textobject>292<caption>293<para>(1) For the purpose of this specification field 2294starts in line 314 and not 313.5 because half line capturing is not295supported.</para>296</caption>297</mediaobject>298</figure>299300<para>Remember the VBI image format depends on the selected301video standard, therefore the application must choose a new standard or302query the current standard first. Attempts to read or write data ahead303of format negotiation, or after switching the video standard which may304invalidate the negotiated VBI parameters, should be refused by the305driver. A format change during active I/O is not permitted.</para>306</section>307308<section>309<title>Reading and writing VBI images</title>310311<para>To assure synchronization with the field number and easier312implementation, the smallest unit of data passed at a time is one313frame, consisting of two fields of VBI images immediately following in314memory.</para>315316<para>The total size of a frame computes as follows:</para>317318<programlisting>319(<structfield>count</structfield>[0] + <structfield>count</structfield>[1]) *320<structfield>samples_per_line</structfield> * sample size in bytes</programlisting>321322<para>The sample size is most likely always one byte,323applications must check the <structfield>sample_format</structfield>324field though, to function properly with other drivers.</para>325326<para>A VBI device may support <link327linkend="rw">read/write</link> and/or streaming (<link328linkend="mmap">memory mapping</link> or <link329linkend="userp">user pointer</link>) I/O. The latter bears the330possibility of synchronizing video and331VBI data by using buffer timestamps.</para>332333<para>Remember the &VIDIOC-STREAMON; ioctl and the first read(),334write() and select() call can be resource allocation points returning335an &EBUSY; if the required hardware resources are temporarily336unavailable, for example the device is already in use by another337process.</para>338</section>339340<!--341Local Variables:342mode: sgml343sgml-parent-document: "v4l2.sgml"344indent-tabs-mode: nil345End:346-->347348349