dev-raw-vbi.xml 15 KB

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