xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/dev-sliced-vbi.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: V4L
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _sliced:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun*************************
7*4882a593SmuzhiyunSliced VBI Data Interface
8*4882a593Smuzhiyun*************************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunVBI stands for Vertical Blanking Interval, a gap in the sequence of
11*4882a593Smuzhiyunlines of an analog video signal. During VBI no picture information is
12*4882a593Smuzhiyuntransmitted, allowing some time while the electron beam of a cathode ray
13*4882a593Smuzhiyuntube TV returns to the top of the screen.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSliced VBI devices use hardware to demodulate data transmitted in the
16*4882a593SmuzhiyunVBI. V4L2 drivers shall *not* do this by software, see also the
17*4882a593Smuzhiyun:ref:`raw VBI interface <raw-vbi>`. The data is passed as short
18*4882a593Smuzhiyunpackets of fixed size, covering one scan line each. The number of
19*4882a593Smuzhiyunpackets per video frame is variable.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunSliced VBI capture and output devices are accessed through the same
22*4882a593Smuzhiyuncharacter special files as raw VBI devices. When a driver supports both
23*4882a593Smuzhiyuninterfaces, the default function of a ``/dev/vbi`` device is *raw* VBI
24*4882a593Smuzhiyuncapturing or output, and the sliced VBI function is only available after
25*4882a593Smuzhiyuncalling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl as defined
26*4882a593Smuzhiyunbelow. Likewise a ``/dev/video`` device may support the sliced VBI API,
27*4882a593Smuzhiyunhowever the default function here is video capturing or output.
28*4882a593SmuzhiyunDifferent file descriptors must be used to pass raw and sliced VBI data
29*4882a593Smuzhiyunsimultaneously, if this is supported by the driver.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunQuerying Capabilities
32*4882a593Smuzhiyun=====================
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunDevices supporting the sliced VBI capturing or output API set the
35*4882a593Smuzhiyun``V4L2_CAP_SLICED_VBI_CAPTURE`` or ``V4L2_CAP_SLICED_VBI_OUTPUT`` flag
36*4882a593Smuzhiyunrespectively, in the ``capabilities`` field of struct
37*4882a593Smuzhiyun:c:type:`v4l2_capability` returned by the
38*4882a593Smuzhiyun:ref:`VIDIOC_QUERYCAP` ioctl. At least one of the
39*4882a593Smuzhiyunread/write, streaming or asynchronous :ref:`I/O methods <io>` must be
40*4882a593Smuzhiyunsupported. Sliced VBI devices may have a tuner or modulator.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunSupplemental Functions
43*4882a593Smuzhiyun======================
44*4882a593Smuzhiyun
45*4882a593SmuzhiyunSliced VBI devices shall support :ref:`video input or output <video>`
46*4882a593Smuzhiyunand :ref:`tuner or modulator <tuner>` ioctls if they have these
47*4882a593Smuzhiyuncapabilities, and they may support :ref:`control` ioctls.
48*4882a593SmuzhiyunThe :ref:`video standard <standard>` ioctls provide information vital
49*4882a593Smuzhiyunto program a sliced VBI device, therefore must be supported.
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun.. _sliced-vbi-format-negotitation:
52*4882a593Smuzhiyun
53*4882a593SmuzhiyunSliced VBI Format Negotiation
54*4882a593Smuzhiyun=============================
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunTo find out which data services are supported by the hardware
57*4882a593Smuzhiyunapplications can call the
58*4882a593Smuzhiyun:ref:`VIDIOC_G_SLICED_VBI_CAP <VIDIOC_G_SLICED_VBI_CAP>` ioctl.
59*4882a593SmuzhiyunAll drivers implementing the sliced VBI interface must support this
60*4882a593Smuzhiyunioctl. The results may differ from those of the
61*4882a593Smuzhiyun:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl when the number of VBI
62*4882a593Smuzhiyunlines the hardware can capture or output per frame, or the number of
63*4882a593Smuzhiyunservices it can identify on a given line are limited. For example on PAL
64*4882a593Smuzhiyunline 16 the hardware may be able to look for a VPS or Teletext signal,
65*4882a593Smuzhiyunbut not both at the same time.
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunTo determine the currently selected services applications set the
68*4882a593Smuzhiyun``type`` field of struct :c:type:`v4l2_format` to
69*4882a593Smuzhiyun``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE`` or
70*4882a593Smuzhiyun``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``, and the
71*4882a593Smuzhiyun:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl fills the ``fmt.sliced``
72*4882a593Smuzhiyunmember, a struct
73*4882a593Smuzhiyun:c:type:`v4l2_sliced_vbi_format`.
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunApplications can request different parameters by initializing or
76*4882a593Smuzhiyunmodifying the ``fmt.sliced`` member and calling the
77*4882a593Smuzhiyun:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with a pointer to the
78*4882a593Smuzhiyunstruct :c:type:`v4l2_format` structure.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunThe sliced VBI API is more complicated than the raw VBI API because the
81*4882a593Smuzhiyunhardware must be told which VBI service to expect on each scan line. Not
82*4882a593Smuzhiyunall services may be supported by the hardware on all lines (this is
83*4882a593Smuzhiyunespecially true for VBI output where Teletext is often unsupported and
84*4882a593Smuzhiyunother services can only be inserted in one specific line). In many
85*4882a593Smuzhiyuncases, however, it is sufficient to just set the ``service_set`` field
86*4882a593Smuzhiyunto the required services and let the driver fill the ``service_lines``
87*4882a593Smuzhiyunarray according to hardware capabilities. Only if more precise control
88*4882a593Smuzhiyunis needed should the programmer set the ``service_lines`` array
89*4882a593Smuzhiyunexplicitly.
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunThe :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl modifies the parameters
92*4882a593Smuzhiyunaccording to hardware capabilities. When the driver allocates resources
93*4882a593Smuzhiyunat this point, it may return an ``EBUSY`` error code if the required
94*4882a593Smuzhiyunresources are temporarily unavailable. Other resource allocation points
95*4882a593Smuzhiyunwhich may return ``EBUSY`` can be the
96*4882a593Smuzhiyun:ref:`VIDIOC_STREAMON` ioctl and the first
97*4882a593Smuzhiyun:c:func:`read()`, :c:func:`write()` and
98*4882a593Smuzhiyun:c:func:`select()` call.
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun.. c:type:: v4l2_sliced_vbi_format
101*4882a593Smuzhiyun
102*4882a593Smuzhiyunstruct v4l2_sliced_vbi_format
103*4882a593Smuzhiyun-----------------------------
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun.. raw:: latex
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun    \begingroup
108*4882a593Smuzhiyun    \scriptsize
109*4882a593Smuzhiyun    \setlength{\tabcolsep}{2pt}
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun.. tabularcolumns:: |p{.85cm}|p{3.3cm}|p{4.4cm}|p{4.4cm}|p{4.4cm}|
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun.. cssclass:: longtable
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun.. flat-table::
116*4882a593Smuzhiyun    :header-rows:  0
117*4882a593Smuzhiyun    :stub-columns: 0
118*4882a593Smuzhiyun    :widths:       3 3 2 2 2
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun    * - __u16
121*4882a593Smuzhiyun      - ``service_set``
122*4882a593Smuzhiyun      - :cspan:`2`
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun	If ``service_set`` is non-zero when passed with
125*4882a593Smuzhiyun	:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
126*4882a593Smuzhiyun	:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`, the ``service_lines``
127*4882a593Smuzhiyun	array will be filled by the driver according to the services
128*4882a593Smuzhiyun	specified in this field. For example, if ``service_set`` is
129*4882a593Smuzhiyun	initialized with ``V4L2_SLICED_TELETEXT_B | V4L2_SLICED_WSS_625``,
130*4882a593Smuzhiyun	a driver for the cx25840 video decoder sets lines 7-22 of both
131*4882a593Smuzhiyun	fields [#f1]_ to ``V4L2_SLICED_TELETEXT_B`` and line 23 of the first
132*4882a593Smuzhiyun	field to ``V4L2_SLICED_WSS_625``. If ``service_set`` is set to
133*4882a593Smuzhiyun	zero, then the values of ``service_lines`` will be used instead.
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun	On return the driver sets this field to the union of all elements
136*4882a593Smuzhiyun	of the returned ``service_lines`` array. It may contain less
137*4882a593Smuzhiyun	services than requested, perhaps just one, if the hardware cannot
138*4882a593Smuzhiyun	handle more services simultaneously. It may be empty (zero) if
139*4882a593Smuzhiyun	none of the requested services are supported by the hardware.
140*4882a593Smuzhiyun    * - __u16
141*4882a593Smuzhiyun      - ``service_lines``\ [2][24]
142*4882a593Smuzhiyun      - :cspan:`2`
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun	Applications initialize this array with sets of data services the
145*4882a593Smuzhiyun	driver shall look for or insert on the respective scan line.
146*4882a593Smuzhiyun	Subject to hardware capabilities drivers return the requested set,
147*4882a593Smuzhiyun	a subset, which may be just a single service, or an empty set.
148*4882a593Smuzhiyun	When the hardware cannot handle multiple services on the same line
149*4882a593Smuzhiyun	the driver shall choose one. No assumptions can be made on which
150*4882a593Smuzhiyun	service the driver chooses.
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun	Data services are defined in :ref:`vbi-services2`. Array indices
153*4882a593Smuzhiyun	map to ITU-R line numbers\ [#f2]_ as follows:
154*4882a593Smuzhiyun    * -
155*4882a593Smuzhiyun      -
156*4882a593Smuzhiyun      - Element
157*4882a593Smuzhiyun      - 525 line systems
158*4882a593Smuzhiyun      - 625 line systems
159*4882a593Smuzhiyun    * -
160*4882a593Smuzhiyun      -
161*4882a593Smuzhiyun      - ``service_lines``\ [0][1]
162*4882a593Smuzhiyun      - 1
163*4882a593Smuzhiyun      - 1
164*4882a593Smuzhiyun    * -
165*4882a593Smuzhiyun      -
166*4882a593Smuzhiyun      - ``service_lines``\ [0][23]
167*4882a593Smuzhiyun      - 23
168*4882a593Smuzhiyun      - 23
169*4882a593Smuzhiyun    * -
170*4882a593Smuzhiyun      -
171*4882a593Smuzhiyun      - ``service_lines``\ [1][1]
172*4882a593Smuzhiyun      - 264
173*4882a593Smuzhiyun      - 314
174*4882a593Smuzhiyun    * -
175*4882a593Smuzhiyun      -
176*4882a593Smuzhiyun      - ``service_lines``\ [1][23]
177*4882a593Smuzhiyun      - 286
178*4882a593Smuzhiyun      - 336
179*4882a593Smuzhiyun    * -
180*4882a593Smuzhiyun      -
181*4882a593Smuzhiyun      - :cspan:`2` Drivers must set ``service_lines`` [0][0] and
182*4882a593Smuzhiyun	``service_lines``\ [1][0] to zero. The
183*4882a593Smuzhiyun	``V4L2_VBI_ITU_525_F1_START``, ``V4L2_VBI_ITU_525_F2_START``,
184*4882a593Smuzhiyun	``V4L2_VBI_ITU_625_F1_START`` and ``V4L2_VBI_ITU_625_F2_START``
185*4882a593Smuzhiyun	defines give the start line numbers for each field for each 525 or
186*4882a593Smuzhiyun	625 line format as a convenience. Don't forget that ITU line
187*4882a593Smuzhiyun	numbering starts at 1, not 0.
188*4882a593Smuzhiyun    * - __u32
189*4882a593Smuzhiyun      - ``io_size``
190*4882a593Smuzhiyun      - :cspan:`2` Maximum number of bytes passed by one
191*4882a593Smuzhiyun	:c:func:`read()` or :c:func:`write()` call,
192*4882a593Smuzhiyun	and the buffer size in bytes for the
193*4882a593Smuzhiyun	:ref:`VIDIOC_QBUF` and
194*4882a593Smuzhiyun	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. Drivers set this field
195*4882a593Smuzhiyun	to the size of struct
196*4882a593Smuzhiyun	:c:type:`v4l2_sliced_vbi_data` times the
197*4882a593Smuzhiyun	number of non-zero elements in the returned ``service_lines``
198*4882a593Smuzhiyun	array (that is the number of lines potentially carrying data).
199*4882a593Smuzhiyun    * - __u32
200*4882a593Smuzhiyun      - ``reserved``\ [2]
201*4882a593Smuzhiyun      - :cspan:`2` This array is reserved for future extensions.
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun	Applications and drivers must set it to zero.
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun.. raw:: latex
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun    \endgroup
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun.. _vbi-services2:
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunSliced VBI services
212*4882a593Smuzhiyun-------------------
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun.. raw:: latex
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun    \scriptsize
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun.. tabularcolumns:: |p{4.1cm}|p{1.1cm}|p{2.4cm}|p{2.0cm}|p{7.3cm}|
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun.. flat-table::
221*4882a593Smuzhiyun    :header-rows:  1
222*4882a593Smuzhiyun    :stub-columns: 0
223*4882a593Smuzhiyun    :widths:       2 1 1 2 2
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun    * - Symbol
226*4882a593Smuzhiyun      - Value
227*4882a593Smuzhiyun      - Reference
228*4882a593Smuzhiyun      - Lines, usually
229*4882a593Smuzhiyun      - Payload
230*4882a593Smuzhiyun    * - ``V4L2_SLICED_TELETEXT_B`` (Teletext System B)
231*4882a593Smuzhiyun      - 0x0001
232*4882a593Smuzhiyun      - :ref:`ets300706`,
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun	:ref:`itu653`
235*4882a593Smuzhiyun      - PAL/SECAM line 7-22, 320-335 (second field 7-22)
236*4882a593Smuzhiyun      - Last 42 of the 45 byte Teletext packet, that is without clock
237*4882a593Smuzhiyun	run-in and framing code, lsb first transmitted.
238*4882a593Smuzhiyun    * - ``V4L2_SLICED_VPS``
239*4882a593Smuzhiyun      - 0x0400
240*4882a593Smuzhiyun      - :ref:`ets300231`
241*4882a593Smuzhiyun      - PAL line 16
242*4882a593Smuzhiyun      - Byte number 3 to 15 according to Figure 9 of ETS 300 231, lsb
243*4882a593Smuzhiyun	first transmitted.
244*4882a593Smuzhiyun    * - ``V4L2_SLICED_CAPTION_525``
245*4882a593Smuzhiyun      - 0x1000
246*4882a593Smuzhiyun      - :ref:`cea608`
247*4882a593Smuzhiyun      - NTSC line 21, 284 (second field 21)
248*4882a593Smuzhiyun      - Two bytes in transmission order, including parity bit, lsb first
249*4882a593Smuzhiyun	transmitted.
250*4882a593Smuzhiyun    * - ``V4L2_SLICED_WSS_625``
251*4882a593Smuzhiyun      - 0x4000
252*4882a593Smuzhiyun      - :ref:`itu1119`,
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun	:ref:`en300294`
255*4882a593Smuzhiyun      - PAL/SECAM line 23
256*4882a593Smuzhiyun      -
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun	::
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun	    Byte         0                 1
261*4882a593Smuzhiyun		  msb         lsb  msb           lsb
262*4882a593Smuzhiyun	     Bit  7 6 5 4 3 2 1 0  x x 13 12 11 10 9
263*4882a593Smuzhiyun    * - ``V4L2_SLICED_VBI_525``
264*4882a593Smuzhiyun      - 0x1000
265*4882a593Smuzhiyun      - :cspan:`2` Set of services applicable to 525 line systems.
266*4882a593Smuzhiyun    * - ``V4L2_SLICED_VBI_625``
267*4882a593Smuzhiyun      - 0x4401
268*4882a593Smuzhiyun      - :cspan:`2` Set of services applicable to 625 line systems.
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun.. raw:: latex
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun    \normalsize
273*4882a593Smuzhiyun
274*4882a593SmuzhiyunDrivers may return an ``EINVAL`` error code when applications attempt to
275*4882a593Smuzhiyunread or write data without prior format negotiation, after switching the
276*4882a593Smuzhiyunvideo standard (which may invalidate the negotiated VBI parameters) and
277*4882a593Smuzhiyunafter switching the video input (which may change the video standard as
278*4882a593Smuzhiyuna side effect). The :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl may
279*4882a593Smuzhiyunreturn an ``EBUSY`` error code when applications attempt to change the
280*4882a593Smuzhiyunformat while i/o is in progress (between a
281*4882a593Smuzhiyun:ref:`VIDIOC_STREAMON` and
282*4882a593Smuzhiyun:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` call, and after the first
283*4882a593Smuzhiyun:c:func:`read()` or :c:func:`write()` call).
284*4882a593Smuzhiyun
285*4882a593SmuzhiyunReading and writing sliced VBI data
286*4882a593Smuzhiyun===================================
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunA single :c:func:`read()` or :c:func:`write()`
289*4882a593Smuzhiyuncall must pass all data belonging to one video frame. That is an array
290*4882a593Smuzhiyunof struct :c:type:`v4l2_sliced_vbi_data` structures with one or
291*4882a593Smuzhiyunmore elements and a total size not exceeding ``io_size`` bytes. Likewise
292*4882a593Smuzhiyunin streaming I/O mode one buffer of ``io_size`` bytes must contain data
293*4882a593Smuzhiyunof one video frame. The ``id`` of unused
294*4882a593Smuzhiyunstruct :c:type:`v4l2_sliced_vbi_data` elements must be zero.
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun.. c:type:: v4l2_sliced_vbi_data
297*4882a593Smuzhiyun
298*4882a593Smuzhiyunstruct v4l2_sliced_vbi_data
299*4882a593Smuzhiyun---------------------------
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun.. flat-table::
304*4882a593Smuzhiyun    :header-rows:  0
305*4882a593Smuzhiyun    :stub-columns: 0
306*4882a593Smuzhiyun    :widths:       3 1 4
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun    * - __u32
309*4882a593Smuzhiyun      - ``id``
310*4882a593Smuzhiyun      - A flag from :ref:`vbi-services` identifying the type of data in
311*4882a593Smuzhiyun	this packet. Only a single bit must be set. When the ``id`` of a
312*4882a593Smuzhiyun	captured packet is zero, the packet is empty and the contents of
313*4882a593Smuzhiyun	other fields are undefined. Applications shall ignore empty
314*4882a593Smuzhiyun	packets. When the ``id`` of a packet for output is zero the
315*4882a593Smuzhiyun	contents of the ``data`` field are undefined and the driver must
316*4882a593Smuzhiyun	no longer insert data on the requested ``field`` and ``line``.
317*4882a593Smuzhiyun    * - __u32
318*4882a593Smuzhiyun      - ``field``
319*4882a593Smuzhiyun      - The video field number this data has been captured from, or shall
320*4882a593Smuzhiyun	be inserted at. ``0`` for the first field, ``1`` for the second
321*4882a593Smuzhiyun	field.
322*4882a593Smuzhiyun    * - __u32
323*4882a593Smuzhiyun      - ``line``
324*4882a593Smuzhiyun      - The field (as opposed to frame) line number this data has been
325*4882a593Smuzhiyun	captured from, or shall be inserted at. See :ref:`vbi-525` and
326*4882a593Smuzhiyun	:ref:`vbi-625` for valid values. Sliced VBI capture devices can
327*4882a593Smuzhiyun	set the line number of all packets to ``0`` if the hardware cannot
328*4882a593Smuzhiyun	reliably identify scan lines. The field number must always be
329*4882a593Smuzhiyun	valid.
330*4882a593Smuzhiyun    * - __u32
331*4882a593Smuzhiyun      - ``reserved``
332*4882a593Smuzhiyun      - This field is reserved for future extensions. Applications and
333*4882a593Smuzhiyun	drivers must set it to zero.
334*4882a593Smuzhiyun    * - __u8
335*4882a593Smuzhiyun      - ``data``\ [48]
336*4882a593Smuzhiyun      - The packet payload. See :ref:`vbi-services` for the contents and
337*4882a593Smuzhiyun	number of bytes passed for each data type. The contents of padding
338*4882a593Smuzhiyun	bytes at the end of this array are undefined, drivers and
339*4882a593Smuzhiyun	applications shall ignore them.
340*4882a593Smuzhiyun
341*4882a593SmuzhiyunPackets are always passed in ascending line number order, without
342*4882a593Smuzhiyunduplicate line numbers. The :c:func:`write()` function and
343*4882a593Smuzhiyunthe :ref:`VIDIOC_QBUF` ioctl must return an ``EINVAL``
344*4882a593Smuzhiyunerror code when applications violate this rule. They must also return an
345*4882a593SmuzhiyunEINVAL error code when applications pass an incorrect field or line
346*4882a593Smuzhiyunnumber, or a combination of ``field``, ``line`` and ``id`` which has not
347*4882a593Smuzhiyunbeen negotiated with the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` or
348*4882a593Smuzhiyun:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. When the line numbers are
349*4882a593Smuzhiyununknown the driver must pass the packets in transmitted order. The
350*4882a593Smuzhiyundriver can insert empty packets with ``id`` set to zero anywhere in the
351*4882a593Smuzhiyunpacket array.
352*4882a593Smuzhiyun
353*4882a593SmuzhiyunTo assure synchronization and to distinguish from frame dropping, when a
354*4882a593Smuzhiyuncaptured frame does not carry any of the requested data services drivers
355*4882a593Smuzhiyunmust pass one or more empty packets. When an application fails to pass
356*4882a593SmuzhiyunVBI data in time for output, the driver must output the last VPS and WSS
357*4882a593Smuzhiyunpacket again, and disable the output of Closed Caption and Teletext
358*4882a593Smuzhiyundata, or output data which is ignored by Closed Caption and Teletext
359*4882a593Smuzhiyundecoders.
360*4882a593Smuzhiyun
361*4882a593SmuzhiyunA sliced VBI device may support :ref:`read/write <rw>` and/or
362*4882a593Smuzhiyunstreaming (:ref:`memory mapping <mmap>` and/or
363*4882a593Smuzhiyun:ref:`user pointer <userp>`) I/O. The latter bears the possibility of
364*4882a593Smuzhiyunsynchronizing video and VBI data by using buffer timestamps.
365*4882a593Smuzhiyun
366*4882a593SmuzhiyunSliced VBI Data in MPEG Streams
367*4882a593Smuzhiyun===============================
368*4882a593Smuzhiyun
369*4882a593SmuzhiyunIf a device can produce an MPEG output stream, it may be capable of
370*4882a593Smuzhiyunproviding
371*4882a593Smuzhiyun:ref:`negotiated sliced VBI services <sliced-vbi-format-negotitation>`
372*4882a593Smuzhiyunas data embedded in the MPEG stream. Users or applications control this
373*4882a593Smuzhiyunsliced VBI data insertion with the
374*4882a593Smuzhiyun:ref:`V4L2_CID_MPEG_STREAM_VBI_FMT <v4l2-mpeg-stream-vbi-fmt>`
375*4882a593Smuzhiyuncontrol.
376*4882a593Smuzhiyun
377*4882a593SmuzhiyunIf the driver does not provide the
378*4882a593Smuzhiyun:ref:`V4L2_CID_MPEG_STREAM_VBI_FMT <v4l2-mpeg-stream-vbi-fmt>`
379*4882a593Smuzhiyuncontrol, or only allows that control to be set to
380*4882a593Smuzhiyun:ref:`V4L2_MPEG_STREAM_VBI_FMT_NONE <v4l2-mpeg-stream-vbi-fmt>`,
381*4882a593Smuzhiyunthen the device cannot embed sliced VBI data in the MPEG stream.
382*4882a593Smuzhiyun
383*4882a593SmuzhiyunThe
384*4882a593Smuzhiyun:ref:`V4L2_CID_MPEG_STREAM_VBI_FMT <v4l2-mpeg-stream-vbi-fmt>`
385*4882a593Smuzhiyuncontrol does not implicitly set the device driver to capture nor cease
386*4882a593Smuzhiyuncapturing sliced VBI data. The control only indicates to embed sliced
387*4882a593SmuzhiyunVBI data in the MPEG stream, if an application has negotiated sliced VBI
388*4882a593Smuzhiyunservice be captured.
389*4882a593Smuzhiyun
390*4882a593SmuzhiyunIt may also be the case that a device can embed sliced VBI data in only
391*4882a593Smuzhiyuncertain types of MPEG streams: for example in an MPEG-2 PS but not an
392*4882a593SmuzhiyunMPEG-2 TS. In this situation, if sliced VBI data insertion is requested,
393*4882a593Smuzhiyunthe sliced VBI data will be embedded in MPEG stream types when
394*4882a593Smuzhiyunsupported, and silently omitted from MPEG stream types where sliced VBI
395*4882a593Smuzhiyundata insertion is not supported by the device.
396*4882a593Smuzhiyun
397*4882a593SmuzhiyunThe following subsections specify the format of the embedded sliced VBI
398*4882a593Smuzhiyundata.
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunMPEG Stream Embedded, Sliced VBI Data Format: NONE
401*4882a593Smuzhiyun--------------------------------------------------
402*4882a593Smuzhiyun
403*4882a593SmuzhiyunThe
404*4882a593Smuzhiyun:ref:`V4L2_MPEG_STREAM_VBI_FMT_NONE <v4l2-mpeg-stream-vbi-fmt>`
405*4882a593Smuzhiyunembedded sliced VBI format shall be interpreted by drivers as a control
406*4882a593Smuzhiyunto cease embedding sliced VBI data in MPEG streams. Neither the device
407*4882a593Smuzhiyunnor driver shall insert "empty" embedded sliced VBI data packets in the
408*4882a593SmuzhiyunMPEG stream when this format is set. No MPEG stream data structures are
409*4882a593Smuzhiyunspecified for this format.
410*4882a593Smuzhiyun
411*4882a593SmuzhiyunMPEG Stream Embedded, Sliced VBI Data Format: IVTV
412*4882a593Smuzhiyun--------------------------------------------------
413*4882a593Smuzhiyun
414*4882a593SmuzhiyunThe
415*4882a593Smuzhiyun:ref:`V4L2_MPEG_STREAM_VBI_FMT_IVTV <v4l2-mpeg-stream-vbi-fmt>`
416*4882a593Smuzhiyunembedded sliced VBI format, when supported, indicates to the driver to
417*4882a593Smuzhiyunembed up to 36 lines of sliced VBI data per frame in an MPEG-2 *Private
418*4882a593SmuzhiyunStream 1 PES* packet encapsulated in an MPEG-2 *Program Pack* in the
419*4882a593SmuzhiyunMPEG stream.
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun*Historical context*: This format specification originates from a
422*4882a593Smuzhiyuncustom, embedded, sliced VBI data format used by the ``ivtv`` driver.
423*4882a593SmuzhiyunThis format has already been informally specified in the kernel sources
424*4882a593Smuzhiyunin the file ``Documentation/userspace-api/media/drivers/cx2341x-uapi.rst`` . The
425*4882a593Smuzhiyunmaximum size of the payload and other aspects of this format are driven
426*4882a593Smuzhiyunby the CX23415 MPEG decoder's capabilities and limitations with respect
427*4882a593Smuzhiyunto extracting, decoding, and displaying sliced VBI data embedded within
428*4882a593Smuzhiyunan MPEG stream.
429*4882a593Smuzhiyun
430*4882a593SmuzhiyunThis format's use is *not* exclusive to the ``ivtv`` driver *nor*
431*4882a593Smuzhiyunexclusive to CX2341x devices, as the sliced VBI data packet insertion
432*4882a593Smuzhiyuninto the MPEG stream is implemented in driver software. At least the
433*4882a593Smuzhiyun``cx18`` driver provides sliced VBI data insertion into an MPEG-2 PS in
434*4882a593Smuzhiyunthis format as well.
435*4882a593Smuzhiyun
436*4882a593SmuzhiyunThe following definitions specify the payload of the MPEG-2 *Private
437*4882a593SmuzhiyunStream 1 PES* packets that contain sliced VBI data when
438*4882a593Smuzhiyun:ref:`V4L2_MPEG_STREAM_VBI_FMT_IVTV <v4l2-mpeg-stream-vbi-fmt>`
439*4882a593Smuzhiyunis set. (The MPEG-2 *Private Stream 1 PES* packet header and
440*4882a593Smuzhiyunencapsulating MPEG-2 *Program Pack* header are not detailed here. Please
441*4882a593Smuzhiyunrefer to the MPEG-2 specifications for details on those packet headers.)
442*4882a593Smuzhiyun
443*4882a593SmuzhiyunThe payload of the MPEG-2 *Private Stream 1 PES* packets that contain
444*4882a593Smuzhiyunsliced VBI data is specified by struct
445*4882a593Smuzhiyun:c:type:`v4l2_mpeg_vbi_fmt_ivtv`. The
446*4882a593Smuzhiyunpayload is variable length, depending on the actual number of lines of
447*4882a593Smuzhiyunsliced VBI data present in a video frame. The payload may be padded at
448*4882a593Smuzhiyunthe end with unspecified fill bytes to align the end of the payload to a
449*4882a593Smuzhiyun4-byte boundary. The payload shall never exceed 1552 bytes (2 fields
450*4882a593Smuzhiyunwith 18 lines/field with 43 bytes of data/line and a 4 byte magic
451*4882a593Smuzhiyunnumber).
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun.. c:type:: v4l2_mpeg_vbi_fmt_ivtv
454*4882a593Smuzhiyun
455*4882a593Smuzhiyunstruct v4l2_mpeg_vbi_fmt_ivtv
456*4882a593Smuzhiyun-----------------------------
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun.. tabularcolumns:: |p{1.0cm}|p{3.8cm}|p{1.0cm}|p{11.2cm}|
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun.. flat-table::
461*4882a593Smuzhiyun    :header-rows:  0
462*4882a593Smuzhiyun    :stub-columns: 0
463*4882a593Smuzhiyun    :widths:       1 1 2
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun    * - __u8
466*4882a593Smuzhiyun      - ``magic``\ [4]
467*4882a593Smuzhiyun      - A "magic" constant from :ref:`v4l2-mpeg-vbi-fmt-ivtv-magic` that
468*4882a593Smuzhiyun	indicates this is a valid sliced VBI data payload and also
469*4882a593Smuzhiyun	indicates which member of the anonymous union, ``itv0`` or
470*4882a593Smuzhiyun	``ITV0``, to use for the payload data.
471*4882a593Smuzhiyun    * - union {
472*4882a593Smuzhiyun      - (anonymous)
473*4882a593Smuzhiyun    * - struct :c:type:`v4l2_mpeg_vbi_itv0`
474*4882a593Smuzhiyun      - ``itv0``
475*4882a593Smuzhiyun      - The primary form of the sliced VBI data payload that contains
476*4882a593Smuzhiyun	anywhere from 1 to 35 lines of sliced VBI data. Line masks are
477*4882a593Smuzhiyun	provided in this form of the payload indicating which VBI lines
478*4882a593Smuzhiyun	are provided.
479*4882a593Smuzhiyun    * - struct :ref:`v4l2_mpeg_vbi_ITV0 <v4l2-mpeg-vbi-itv0-1>`
480*4882a593Smuzhiyun      - ``ITV0``
481*4882a593Smuzhiyun      - An alternate form of the sliced VBI data payload used when 36
482*4882a593Smuzhiyun	lines of sliced VBI data are present. No line masks are provided
483*4882a593Smuzhiyun	in this form of the payload; all valid line mask bits are
484*4882a593Smuzhiyun	implcitly set.
485*4882a593Smuzhiyun    * - }
486*4882a593Smuzhiyun      -
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun.. _v4l2-mpeg-vbi-fmt-ivtv-magic:
489*4882a593Smuzhiyun
490*4882a593SmuzhiyunMagic Constants for struct v4l2_mpeg_vbi_fmt_ivtv magic field
491*4882a593Smuzhiyun-------------------------------------------------------------
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun.. flat-table::
496*4882a593Smuzhiyun    :header-rows:  1
497*4882a593Smuzhiyun    :stub-columns: 0
498*4882a593Smuzhiyun    :widths:       3 1 4
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun    * - Defined Symbol
501*4882a593Smuzhiyun      - Value
502*4882a593Smuzhiyun      - Description
503*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_MAGIC0``
504*4882a593Smuzhiyun      - "itv0"
505*4882a593Smuzhiyun      - Indicates the ``itv0`` member of the union in struct
506*4882a593Smuzhiyun	:c:type:`v4l2_mpeg_vbi_fmt_ivtv` is
507*4882a593Smuzhiyun	valid.
508*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_MAGIC1``
509*4882a593Smuzhiyun      - "ITV0"
510*4882a593Smuzhiyun      - Indicates the ``ITV0`` member of the union in struct
511*4882a593Smuzhiyun	:c:type:`v4l2_mpeg_vbi_fmt_ivtv` is
512*4882a593Smuzhiyun	valid and that 36 lines of sliced VBI data are present.
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun.. c:type:: v4l2_mpeg_vbi_itv0
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun.. c:type:: v4l2_mpeg_vbi_ITV0
518*4882a593Smuzhiyun
519*4882a593Smuzhiyunstructs v4l2_mpeg_vbi_itv0 and v4l2_mpeg_vbi_ITV0
520*4882a593Smuzhiyun-------------------------------------------------
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun.. tabularcolumns:: |p{5.2cm}|p{2.4cm}|p{9.9cm}|
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun.. flat-table::
525*4882a593Smuzhiyun    :header-rows:  0
526*4882a593Smuzhiyun    :stub-columns: 0
527*4882a593Smuzhiyun    :widths:       1 1 2
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun    * - __le32
530*4882a593Smuzhiyun      - ``linemask``\ [2]
531*4882a593Smuzhiyun      - Bitmasks indicating the VBI service lines present. These
532*4882a593Smuzhiyun	``linemask`` values are stored in little endian byte order in the
533*4882a593Smuzhiyun	MPEG stream. Some reference ``linemask`` bit positions with their
534*4882a593Smuzhiyun	corresponding VBI line number and video field are given below.
535*4882a593Smuzhiyun	b\ :sub:`0` indicates the least significant bit of a ``linemask``
536*4882a593Smuzhiyun	value:
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun	::
540*4882a593Smuzhiyun
541*4882a593Smuzhiyun	    linemask[0] b0:     line  6  first field
542*4882a593Smuzhiyun	    linemask[0] b17:    line 23  first field
543*4882a593Smuzhiyun	    linemask[0] b18:    line  6  second field
544*4882a593Smuzhiyun	    linemask[0] b31:    line 19  second field
545*4882a593Smuzhiyun	    linemask[1] b0:     line 20  second field
546*4882a593Smuzhiyun	    linemask[1] b3:     line 23  second field
547*4882a593Smuzhiyun	    linemask[1] b4-b31: unused and set to 0
548*4882a593Smuzhiyun    * - struct
549*4882a593Smuzhiyun	:c:type:`v4l2_mpeg_vbi_itv0_line`
550*4882a593Smuzhiyun      - ``line``\ [35]
551*4882a593Smuzhiyun      - This is a variable length array that holds from 1 to 35 lines of
552*4882a593Smuzhiyun	sliced VBI data. The sliced VBI data lines present correspond to
553*4882a593Smuzhiyun	the bits set in the ``linemask`` array, starting from b\ :sub:`0`
554*4882a593Smuzhiyun	of ``linemask``\ [0] up through b\ :sub:`31` of ``linemask``\ [0],
555*4882a593Smuzhiyun	and from b\ :sub:`0` of ``linemask``\ [1] up through b\ :sub:`3` of
556*4882a593Smuzhiyun	``linemask``\ [1]. ``line``\ [0] corresponds to the first bit
557*4882a593Smuzhiyun	found set in the ``linemask`` array, ``line``\ [1] corresponds to
558*4882a593Smuzhiyun	the second bit found set in the ``linemask`` array, etc. If no
559*4882a593Smuzhiyun	``linemask`` array bits are set, then ``line``\ [0] may contain
560*4882a593Smuzhiyun	one line of unspecified data that should be ignored by
561*4882a593Smuzhiyun	applications.
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun.. _v4l2-mpeg-vbi-itv0-1:
565*4882a593Smuzhiyun
566*4882a593Smuzhiyunstruct v4l2_mpeg_vbi_ITV0
567*4882a593Smuzhiyun-------------------------
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun.. tabularcolumns:: |p{5.2cm}|p{2.4cm}|p{9.9cm}|
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun.. flat-table::
572*4882a593Smuzhiyun    :header-rows:  0
573*4882a593Smuzhiyun    :stub-columns: 0
574*4882a593Smuzhiyun    :widths:       1 1 2
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun    * - struct
577*4882a593Smuzhiyun	:c:type:`v4l2_mpeg_vbi_itv0_line`
578*4882a593Smuzhiyun      - ``line``\ [36]
579*4882a593Smuzhiyun      - A fixed length array of 36 lines of sliced VBI data. ``line``\ [0]
580*4882a593Smuzhiyun	through ``line``\ [17] correspond to lines 6 through 23 of the
581*4882a593Smuzhiyun	first field. ``line``\ [18] through ``line``\ [35] corresponds to
582*4882a593Smuzhiyun	lines 6 through 23 of the second field.
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun
585*4882a593Smuzhiyun.. c:type:: v4l2_mpeg_vbi_itv0_line
586*4882a593Smuzhiyun
587*4882a593Smuzhiyunstruct v4l2_mpeg_vbi_itv0_line
588*4882a593Smuzhiyun------------------------------
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun.. flat-table::
593*4882a593Smuzhiyun    :header-rows:  0
594*4882a593Smuzhiyun    :stub-columns: 0
595*4882a593Smuzhiyun    :widths:       1 1 2
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun    * - __u8
598*4882a593Smuzhiyun      - ``id``
599*4882a593Smuzhiyun      - A line identifier value from
600*4882a593Smuzhiyun	:ref:`ITV0-Line-Identifier-Constants` that indicates the type of
601*4882a593Smuzhiyun	sliced VBI data stored on this line.
602*4882a593Smuzhiyun    * - __u8
603*4882a593Smuzhiyun      - ``data``\ [42]
604*4882a593Smuzhiyun      - The sliced VBI data for the line.
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun.. _ITV0-Line-Identifier-Constants:
608*4882a593Smuzhiyun
609*4882a593SmuzhiyunLine Identifiers for struct v4l2_mpeg_vbi_itv0_line id field
610*4882a593Smuzhiyun------------------------------------------------------------
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun.. tabularcolumns:: |p{7.0cm}|p{1.8cm}|p{8.7cm}|
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun.. flat-table::
615*4882a593Smuzhiyun    :header-rows:  1
616*4882a593Smuzhiyun    :stub-columns: 0
617*4882a593Smuzhiyun    :widths:       3 1 4
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun    * - Defined Symbol
620*4882a593Smuzhiyun      - Value
621*4882a593Smuzhiyun      - Description
622*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_TELETEXT_B``
623*4882a593Smuzhiyun      - 1
624*4882a593Smuzhiyun      - Refer to :ref:`Sliced VBI services <vbi-services2>` for a
625*4882a593Smuzhiyun	description of the line payload.
626*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_CAPTION_525``
627*4882a593Smuzhiyun      - 4
628*4882a593Smuzhiyun      - Refer to :ref:`Sliced VBI services <vbi-services2>` for a
629*4882a593Smuzhiyun	description of the line payload.
630*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_WSS_625``
631*4882a593Smuzhiyun      - 5
632*4882a593Smuzhiyun      - Refer to :ref:`Sliced VBI services <vbi-services2>` for a
633*4882a593Smuzhiyun	description of the line payload.
634*4882a593Smuzhiyun    * - ``V4L2_MPEG_VBI_IVTV_VPS``
635*4882a593Smuzhiyun      - 7
636*4882a593Smuzhiyun      - Refer to :ref:`Sliced VBI services <vbi-services2>` for a
637*4882a593Smuzhiyun	description of the line payload.
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun.. [#f1]
641*4882a593Smuzhiyun   According to :ref:`ETS 300 706 <ets300706>` lines 6-22 of the first
642*4882a593Smuzhiyun   field and lines 5-22 of the second field may carry Teletext data.
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun.. [#f2]
645*4882a593Smuzhiyun   See also :ref:`vbi-525` and :ref:`vbi-625`.
646