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