1 <title>Raw VBI Data Interface</title> 2 3 <para>VBI is an abbreviation of Vertical Blanking Interval, a gap 4in the sequence of lines of an analog video signal. During VBI 5no picture information is transmitted, allowing some time while the 6electron beam of a cathode ray tube TV returns to the top of the 7screen. Using an oscilloscope you will find here the vertical 8synchronization pulses and short data packages ASK 9modulated<footnote><para>ASK: Amplitude-Shift Keying. A high signal 10level represents a '1' bit, a low level a '0' bit.</para></footnote> 11onto the video signal. These are transmissions of services such as 12Teletext or Closed Caption.</para> 13 14 <para>Subject of this interface type is raw VBI data, as sampled off 15a video signal, or to be added to a signal for output. 16The data format is similar to uncompressed video images, a number of 17lines times a number of samples per line, we call this a VBI image.</para> 18 19 <para>Conventionally V4L2 VBI devices are accessed through character 20device special files named <filename>/dev/vbi</filename> and 21<filename>/dev/vbi0</filename> to <filename>/dev/vbi31</filename> with 22major number 81 and minor numbers 224 to 255. 23<filename>/dev/vbi</filename> is typically a symbolic link to the 24preferred VBI device. This convention applies to both input and output 25devices.</para> 26 27 <para>To address the problems of finding related video and VBI 28devices VBI capturing and output is also available as device function 29under <filename>/dev/video</filename>. To capture or output raw VBI 30data with these devices applications must call the &VIDIOC-S-FMT; 31ioctl. Accessed as <filename>/dev/vbi</filename>, raw VBI capturing 32or output is the default device function.</para> 33 34 <section> 35 <title>Querying Capabilities</title> 36 37 <para>Devices supporting the raw VBI capturing or output API set 38the <constant>V4L2_CAP_VBI_CAPTURE</constant> or 39<constant>V4L2_CAP_VBI_OUTPUT</constant> flags, respectively, in the 40<structfield>capabilities</structfield> field of &v4l2-capability; 41returned by the &VIDIOC-QUERYCAP; ioctl. At least one of the 42read/write, streaming or asynchronous I/O methods must be 43supported. VBI devices may or may not have a tuner or modulator.</para> 44 </section> 45 46 <section> 47 <title>Supplemental Functions</title> 48 49 <para>VBI devices shall support <link linkend="video">video 50input or output</link>, <link linkend="tuner">tuner or 51modulator</link>, and <link linkend="control">controls</link> ioctls 52as needed. The <link linkend="standard">video standard</link> ioctls provide 53information vital to program a VBI device, therefore must be 54supported.</para> 55 </section> 56 57 <section> 58 <title>Raw VBI Format Negotiation</title> 59 60 <para>Raw VBI sampling abilities can vary, in particular the 61sampling frequency. To properly interpret the data V4L2 specifies an 62ioctl to query the sampling parameters. Moreover, to allow for some 63flexibility applications can also suggest different parameters.</para> 64 65 <para>As usual these parameters are <emphasis>not</emphasis> 66reset at &func-open; time to permit Unix tool chains, programming a 67device and then reading from it as if it was a plain file. Well 68written V4L2 applications should always ensure they really get what 69they want, requesting reasonable parameters and then checking if the 70actual parameters are suitable.</para> 71 72 <para>To query the current raw VBI capture parameters 73applications set the <structfield>type</structfield> field of a 74&v4l2-format; to <constant>V4L2_BUF_TYPE_VBI_CAPTURE</constant> or 75<constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant>, and call the 76&VIDIOC-G-FMT; ioctl with a pointer to this structure. Drivers fill 77the &v4l2-vbi-format; <structfield>vbi</structfield> member of the 78<structfield>fmt</structfield> union.</para> 79 80 <para>To request different parameters applications set the 81<structfield>type</structfield> field of a &v4l2-format; as above and 82initialize all fields of the &v4l2-vbi-format; 83<structfield>vbi</structfield> member of the 84<structfield>fmt</structfield> union, or better just modify the 85results of <constant>VIDIOC_G_FMT</constant>, and call the 86&VIDIOC-S-FMT; ioctl with a pointer to this structure. Drivers return 87an &EINVAL; only when the given parameters are ambiguous, otherwise 88they modify the parameters according to the hardware capabilites and 89return the actual parameters. When the driver allocates resources at 90this point, it may return an &EBUSY; to indicate the returned 91parameters are valid but the required resources are currently not 92available. That may happen for instance when the video and VBI areas 93to capture would overlap, or when the driver supports multiple opens 94and another process already requested VBI capturing or output. Anyway, 95applications must expect other resource allocation points which may 96return <errorcode>EBUSY</errorcode>, at the &VIDIOC-STREAMON; ioctl 97and the first read(), write() and select() call.</para> 98 99 <para>VBI devices must implement both the 100<constant>VIDIOC_G_FMT</constant> and 101<constant>VIDIOC_S_FMT</constant> ioctl, even if 102<constant>VIDIOC_S_FMT</constant> ignores all requests and always 103returns default parameters as <constant>VIDIOC_G_FMT</constant> does. 104<constant>VIDIOC_TRY_FMT</constant> is optional.</para> 105 106 <table pgwide="1" frame="none" id="v4l2-vbi-format"> 107 <title>struct <structname>v4l2_vbi_format</structname></title> 108 <tgroup cols="3"> 109 &cs-str; 110 <tbody valign="top"> 111 <row> 112 <entry>__u32</entry> 113 <entry><structfield>sampling_rate</structfield></entry> 114 <entry>Samples per second, i. e. unit 1 Hz.</entry> 115 </row> 116 <row> 117 <entry>__u32</entry> 118 <entry><structfield>offset</structfield></entry> 119 <entry><para>Horizontal offset of the VBI image, 120relative to the leading edge of the line synchronization pulse and 121counted in samples: The first sample in the VBI image will be located 122<structfield>offset</structfield> / 123<structfield>sampling_rate</structfield> seconds following the leading 124edge. See also <xref linkend="vbi-hsync" />.</para></entry> 125 </row> 126 <row> 127 <entry>__u32</entry> 128 <entry><structfield>samples_per_line</structfield></entry> 129 <entry></entry> 130 </row> 131 <row> 132 <entry>__u32</entry> 133 <entry><structfield>sample_format</structfield></entry> 134 <entry><para>Defines the sample format as in <xref 135linkend="pixfmt" />, a four-character-code.<footnote> 136 <para>A few devices may be unable to 137sample VBI data at all but can extend the video capture window to the 138VBI region.</para> 139 </footnote> Usually this is 140<constant>V4L2_PIX_FMT_GREY</constant>, i. e. each sample 141consists of 8 bits with lower values oriented towards the black level. 142Do not assume any other correlation of values with the signal level. 143For example, the MSB does not necessarily indicate if the signal is 144'high' or 'low' because 128 may not be the mean value of the 145signal. Drivers shall not convert the sample format by software.</para></entry> 146 </row> 147 <row> 148 <entry>__u32</entry> 149 <entry><structfield>start</structfield>[2]</entry> 150 <entry>This is the scanning system line number 151associated with the first line of the VBI image, of the first and the 152second field respectively. See <xref linkend="vbi-525" /> and 153<xref linkend="vbi-625" /> for valid values. VBI input drivers can 154return start values 0 if the hardware cannot reliable identify 155scanning lines, VBI acquisition may not require this 156information.</entry> 157 </row> 158 <row> 159 <entry>__u32</entry> 160 <entry><structfield>count</structfield>[2]</entry> 161 <entry>The number of lines in the first and second 162field image, respectively.</entry> 163 </row> 164 <row> 165 <entry spanname="hspan"><para>Drivers should be as 166flexibility as possible. For example, it may be possible to extend or 167move the VBI capture window down to the picture area, implementing a 168'full field mode' to capture data service transmissions embedded in 169the picture.</para><para>An application can set the first or second 170<structfield>count</structfield> value to zero if no data is required 171from the respective field; <structfield>count</structfield>[1] if the 172scanning system is progressive, &ie; not interlaced. The 173corresponding start value shall be ignored by the application and 174driver. Anyway, drivers may not support single field capturing and 175return both count values non-zero.</para><para>Both 176<structfield>count</structfield> values set to zero, or line numbers 177outside the bounds depicted in <xref linkend="vbi-525" /> and <xref 178 linkend="vbi-625" />, or a field image covering 179lines of two fields, are invalid and shall not be returned by the 180driver.</para><para>To initialize the <structfield>start</structfield> 181and <structfield>count</structfield> fields, applications must first 182determine the current video standard selection. The &v4l2-std-id; or 183the <structfield>framelines</structfield> field of &v4l2-standard; can 184be evaluated for this purpose.</para></entry> 185 </row> 186 <row> 187 <entry>__u32</entry> 188 <entry><structfield>flags</structfield></entry> 189 <entry>See <xref linkend="vbifmt-flags" /> below. Currently 190only drivers set flags, applications must set this field to 191zero.</entry> 192 </row> 193 <row> 194 <entry>__u32</entry> 195 <entry><structfield>reserved</structfield>[2]</entry> 196 <entry>This array is reserved for future extensions. 197Drivers and applications must set it to zero.</entry> 198 </row> 199 </tbody> 200 </tgroup> 201 </table> 202 203 <table pgwide="1" frame="none" id="vbifmt-flags"> 204 <title>Raw VBI Format Flags</title> 205 <tgroup cols="3"> 206 &cs-def; 207 <tbody valign="top"> 208 <row> 209 <entry><constant>V4L2_VBI_UNSYNC</constant></entry> 210 <entry>0x0001</entry> 211 <entry><para>This flag indicates hardware which does not 212properly distinguish between fields. Normally the VBI image stores the 213first field (lower scanning line numbers) first in memory. This may be 214a top or bottom field depending on the video standard. When this flag 215is set the first or second field may be stored first, however the 216fields are still in correct temporal order with the older field first 217in memory.<footnote> 218 <para>Most VBI services transmit on both fields, but 219some have different semantics depending on the field number. These 220cannot be reliable decoded or encoded when 221<constant>V4L2_VBI_UNSYNC</constant> is set.</para> 222 </footnote></para></entry> 223 </row> 224 <row> 225 <entry><constant>V4L2_VBI_INTERLACED</constant></entry> 226 <entry>0x0002</entry> 227 <entry>By default the two field images will be passed 228sequentially; all lines of the first field followed by all lines of 229the second field (compare <xref linkend="field-order" /> 230<constant>V4L2_FIELD_SEQ_TB</constant> and 231<constant>V4L2_FIELD_SEQ_BT</constant>, whether the top or bottom 232field is first in memory depends on the video standard). When this 233flag is set, the two fields are interlaced (cf. 234<constant>V4L2_FIELD_INTERLACED</constant>). The first line of the 235first field followed by the first line of the second field, then the 236two second lines, and so on. Such a layout may be necessary when the 237hardware has been programmed to capture or output interlaced video 238images and is unable to separate the fields for VBI capturing at 239the same time. For simplicity setting this flag implies that both 240<structfield>count</structfield> values are equal and non-zero.</entry> 241 </row> 242 </tbody> 243 </tgroup> 244 </table> 245 246 <figure id="vbi-hsync"> 247 <title>Line synchronization</title> 248 <mediaobject> 249 <imageobject> 250 <imagedata fileref="vbi_hsync.pdf" format="PS" /> 251 </imageobject> 252 <imageobject> 253 <imagedata fileref="vbi_hsync.gif" format="GIF" /> 254 </imageobject> 255 <textobject> 256 <phrase>Line synchronization diagram</phrase> 257 </textobject> 258 </mediaobject> 259 </figure> 260 261 <figure id="vbi-525"> 262 <title>ITU-R 525 line numbering (M/NTSC and M/PAL)</title> 263 <mediaobject> 264 <imageobject> 265 <imagedata fileref="vbi_525.pdf" format="PS" /> 266 </imageobject> 267 <imageobject> 268 <imagedata fileref="vbi_525.gif" format="GIF" /> 269 </imageobject> 270 <textobject> 271 <phrase>NTSC field synchronization diagram</phrase> 272 </textobject> 273 <caption> 274 <para>(1) For the purpose of this specification field 2 275starts in line 264 and not 263.5 because half line capturing is not 276supported.</para> 277 </caption> 278 </mediaobject> 279 </figure> 280 281 <figure id="vbi-625"> 282 <title>ITU-R 625 line numbering</title> 283 <mediaobject> 284 <imageobject> 285 <imagedata fileref="vbi_625.pdf" format="PS" /> 286 </imageobject> 287 <imageobject> 288 <imagedata fileref="vbi_625.gif" format="GIF" /> 289 </imageobject> 290 <textobject> 291 <phrase>PAL/SECAM field synchronization diagram</phrase> 292 </textobject> 293 <caption> 294 <para>(1) For the purpose of this specification field 2 295starts in line 314 and not 313.5 because half line capturing is not 296supported.</para> 297 </caption> 298 </mediaobject> 299 </figure> 300 301 <para>Remember the VBI image format depends on the selected 302video standard, therefore the application must choose a new standard or 303query the current standard first. Attempts to read or write data ahead 304of format negotiation, or after switching the video standard which may 305invalidate the negotiated VBI parameters, should be refused by the 306driver. A format change during active I/O is not permitted.</para> 307 </section> 308 309 <section> 310 <title>Reading and writing VBI images</title> 311 312 <para>To assure synchronization with the field number and easier 313implementation, the smallest unit of data passed at a time is one 314frame, consisting of two fields of VBI images immediately following in 315memory.</para> 316 317 <para>The total size of a frame computes as follows:</para> 318 319 <programlisting> 320(<structfield>count</structfield>[0] + <structfield>count</structfield>[1]) * 321<structfield>samples_per_line</structfield> * sample size in bytes</programlisting> 322 323 <para>The sample size is most likely always one byte, 324applications must check the <structfield>sample_format</structfield> 325field though, to function properly with other drivers.</para> 326 327 <para>A VBI device may support <link 328 linkend="rw">read/write</link> and/or streaming (<link 329 linkend="mmap">memory mapping</link> or <link 330 linkend="userp">user pointer</link>) I/O. The latter bears the 331possibility of synchronizing video and 332VBI data by using buffer timestamps.</para> 333 334 <para>Remember the &VIDIOC-STREAMON; ioctl and the first read(), 335write() and select() call can be resource allocation points returning 336an &EBUSY; if the required hardware resources are temporarily 337unavailable, for example the device is already in use by another 338process.</para> 339 </section> 340