Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
0002 .. c:namespace:: V4L
0003 
0004 .. _raw-vbi:
0005 
0006 **********************
0007 Raw VBI Data Interface
0008 **********************
0009 
0010 VBI is an abbreviation of Vertical Blanking Interval, a gap in the
0011 sequence of lines of an analog video signal. During VBI no picture
0012 information is transmitted, allowing some time while the electron beam
0013 of a cathode ray tube TV returns to the top of the screen. Using an
0014 oscilloscope you will find here the vertical synchronization pulses and
0015 short data packages ASK modulated [#f1]_ onto the video signal. These are
0016 transmissions of services such as Teletext or Closed Caption.
0017 
0018 Subject of this interface type is raw VBI data, as sampled off a video
0019 signal, or to be added to a signal for output. The data format is
0020 similar to uncompressed video images, a number of lines times a number
0021 of samples per line, we call this a VBI image.
0022 
0023 Conventionally V4L2 VBI devices are accessed through character device
0024 special files named ``/dev/vbi`` and ``/dev/vbi0`` to ``/dev/vbi31``
0025 with major number 81 and minor numbers 224 to 255. ``/dev/vbi`` is
0026 typically a symbolic link to the preferred VBI device. This convention
0027 applies to both input and output devices.
0028 
0029 To address the problems of finding related video and VBI devices VBI
0030 capturing and output is also available as device function under
0031 ``/dev/video``. To capture or output raw VBI data with these devices
0032 applications must call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
0033 Accessed as ``/dev/vbi``, raw VBI capturing or output is the default
0034 device function.
0035 
0036 Querying Capabilities
0037 =====================
0038 
0039 Devices supporting the raw VBI capturing or output API set the
0040 ``V4L2_CAP_VBI_CAPTURE`` or ``V4L2_CAP_VBI_OUTPUT`` flags, respectively,
0041 in the ``capabilities`` field of struct
0042 :c:type:`v4l2_capability` returned by the
0043 :ref:`VIDIOC_QUERYCAP` ioctl. At least one of the
0044 read/write, streaming or asynchronous I/O methods must be supported. VBI
0045 devices may or may not have a tuner or modulator.
0046 
0047 Supplemental Functions
0048 ======================
0049 
0050 VBI devices shall support :ref:`video input or output <video>`,
0051 :ref:`tuner or modulator <tuner>`, and :ref:`controls <control>`
0052 ioctls as needed. The :ref:`video standard <standard>` ioctls provide
0053 information vital to program a VBI device, therefore must be supported.
0054 
0055 Raw VBI Format Negotiation
0056 ==========================
0057 
0058 Raw VBI sampling abilities can vary, in particular the sampling
0059 frequency. To properly interpret the data V4L2 specifies an ioctl to
0060 query the sampling parameters. Moreover, to allow for some flexibility
0061 applications can also suggest different parameters.
0062 
0063 As usual these parameters are *not* reset at :c:func:`open()`
0064 time to permit Unix tool chains, programming a device and then reading
0065 from it as if it was a plain file. Well written V4L2 applications should
0066 always ensure they really get what they want, requesting reasonable
0067 parameters and then checking if the actual parameters are suitable.
0068 
0069 To query the current raw VBI capture parameters applications set the
0070 ``type`` field of a struct :c:type:`v4l2_format` to
0071 ``V4L2_BUF_TYPE_VBI_CAPTURE`` or ``V4L2_BUF_TYPE_VBI_OUTPUT``, and call
0072 the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this
0073 structure. Drivers fill the struct
0074 :c:type:`v4l2_vbi_format` ``vbi`` member of the
0075 ``fmt`` union.
0076 
0077 To request different parameters applications set the ``type`` field of a
0078 struct :c:type:`v4l2_format` as above and initialize all
0079 fields of the struct :c:type:`v4l2_vbi_format`
0080 ``vbi`` member of the ``fmt`` union, or better just modify the results
0081 of :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
0082 ioctl with a pointer to this structure. Drivers return an ``EINVAL`` error
0083 code only when the given parameters are ambiguous, otherwise they modify
0084 the parameters according to the hardware capabilities and return the
0085 actual parameters. When the driver allocates resources at this point, it
0086 may return an ``EBUSY`` error code to indicate the returned parameters are
0087 valid but the required resources are currently not available. That may
0088 happen for instance when the video and VBI areas to capture would
0089 overlap, or when the driver supports multiple opens and another process
0090 already requested VBI capturing or output. Anyway, applications must
0091 expect other resource allocation points which may return ``EBUSY``, at the
0092 :ref:`VIDIOC_STREAMON` ioctl and the first :c:func:`read()`
0093 , :c:func:`write()` and :c:func:`select()` calls.
0094 
0095 VBI devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and
0096 :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all requests
0097 and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does.
0098 :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional.
0099 
0100 .. tabularcolumns:: |p{1.6cm}|p{4.2cm}|p{11.5cm}|
0101 
0102 .. c:type:: v4l2_vbi_format
0103 
0104 .. cssclass:: longtable
0105 
0106 .. flat-table:: struct v4l2_vbi_format
0107     :header-rows:  0
0108     :stub-columns: 0
0109     :widths:       1 1 2
0110 
0111     * - __u32
0112       - ``sampling_rate``
0113       - Samples per second, i. e. unit 1 Hz.
0114     * - __u32
0115       - ``offset``
0116       - Horizontal offset of the VBI image, relative to the leading edge
0117         of the line synchronization pulse and counted in samples: The
0118         first sample in the VBI image will be located ``offset`` /
0119         ``sampling_rate`` seconds following the leading edge. See also
0120         :ref:`vbi-hsync`.
0121     * - __u32
0122       - ``samples_per_line``
0123       -
0124     * - __u32
0125       - ``sample_format``
0126       - Defines the sample format as in :ref:`pixfmt`, a
0127         four-character-code. [#f2]_ Usually this is ``V4L2_PIX_FMT_GREY``,
0128         i. e. each sample consists of 8 bits with lower values oriented
0129         towards the black level. Do not assume any other correlation of
0130         values with the signal level. For example, the MSB does not
0131         necessarily indicate if the signal is 'high' or 'low' because 128
0132         may not be the mean value of the signal. Drivers shall not convert
0133         the sample format by software.
0134     * - __u32
0135       - ``start``\ [#f2]_
0136       - This is the scanning system line number associated with the first
0137         line of the VBI image, of the first and the second field
0138         respectively. See :ref:`vbi-525` and :ref:`vbi-625` for valid
0139         values. The ``V4L2_VBI_ITU_525_F1_START``,
0140         ``V4L2_VBI_ITU_525_F2_START``, ``V4L2_VBI_ITU_625_F1_START`` and
0141         ``V4L2_VBI_ITU_625_F2_START`` defines give the start line numbers
0142         for each field for each 525 or 625 line format as a convenience.
0143         Don't forget that ITU line numbering starts at 1, not 0. VBI input
0144         drivers can return start values 0 if the hardware cannot reliable
0145         identify scanning lines, VBI acquisition may not require this
0146         information.
0147     * - __u32
0148       - ``count``\ [#f2]_
0149       - The number of lines in the first and second field image,
0150         respectively.
0151     * - :cspan:`2`
0152 
0153         Drivers should be as flexibility as possible. For example, it may
0154         be possible to extend or move the VBI capture window down to the
0155         picture area, implementing a 'full field mode' to capture data
0156         service transmissions embedded in the picture.
0157 
0158         An application can set the first or second ``count`` value to zero
0159         if no data is required from the respective field; ``count``\ [1]
0160         if the scanning system is progressive, i. e. not interlaced. The
0161         corresponding start value shall be ignored by the application and
0162         driver. Anyway, drivers may not support single field capturing and
0163         return both count values non-zero.
0164 
0165         Both ``count`` values set to zero, or line numbers are outside the
0166         bounds depicted\ [#f4]_, or a field image covering lines of two
0167         fields, are invalid and shall not be returned by the driver.
0168 
0169         To initialize the ``start`` and ``count`` fields, applications
0170         must first determine the current video standard selection. The
0171         :ref:`v4l2_std_id <v4l2-std-id>` or the ``framelines`` field
0172         of struct :c:type:`v4l2_standard` can be evaluated
0173         for this purpose.
0174     * - __u32
0175       - ``flags``
0176       - See :ref:`vbifmt-flags` below. Currently only drivers set flags,
0177         applications must set this field to zero.
0178     * - __u32
0179       - ``reserved``\ [#f2]_
0180       - This array is reserved for future extensions. Drivers and
0181         applications must set it to zero.
0182 
0183 .. tabularcolumns:: |p{4.4cm}|p{1.5cm}|p{11.4cm}|
0184 
0185 .. _vbifmt-flags:
0186 
0187 .. flat-table:: Raw VBI Format Flags
0188     :header-rows:  0
0189     :stub-columns: 0
0190     :widths:       3 1 4
0191 
0192     * - ``V4L2_VBI_UNSYNC``
0193       - 0x0001
0194       - This flag indicates hardware which does not properly distinguish
0195         between fields. Normally the VBI image stores the first field
0196         (lower scanning line numbers) first in memory. This may be a top
0197         or bottom field depending on the video standard. When this flag is
0198         set the first or second field may be stored first, however the
0199         fields are still in correct temporal order with the older field
0200         first in memory. [#f3]_
0201     * - ``V4L2_VBI_INTERLACED``
0202       - 0x0002
0203       - By default the two field images will be passed sequentially; all
0204         lines of the first field followed by all lines of the second field
0205         (compare :ref:`field-order` ``V4L2_FIELD_SEQ_TB`` and
0206         ``V4L2_FIELD_SEQ_BT``, whether the top or bottom field is first in
0207         memory depends on the video standard). When this flag is set, the
0208         two fields are interlaced (cf. ``V4L2_FIELD_INTERLACED``). The
0209         first line of the first field followed by the first line of the
0210         second field, then the two second lines, and so on. Such a layout
0211         may be necessary when the hardware has been programmed to capture
0212         or output interlaced video images and is unable to separate the
0213         fields for VBI capturing at the same time. For simplicity setting
0214         this flag implies that both ``count`` values are equal and
0215         non-zero.
0216 
0217 
0218 .. _vbi-hsync:
0219 
0220 .. kernel-figure:: vbi_hsync.svg
0221     :alt:   vbi_hsync.svg
0222     :align: center
0223 
0224     **Figure 4.1. Line synchronization**
0225 
0226 .. _vbi-525:
0227 
0228 .. kernel-figure:: vbi_525.svg
0229     :alt:   vbi_525.svg
0230     :align: center
0231 
0232     **Figure 4.2. ITU-R 525 line numbering (M/NTSC and M/PAL)**
0233 
0234 .. _vbi-625:
0235 
0236 .. kernel-figure:: vbi_625.svg
0237     :alt:   vbi_625.svg
0238     :align: center
0239 
0240     **Figure 4.3. ITU-R 625 line numbering**
0241 
0242 Remember the VBI image format depends on the selected video standard,
0243 therefore the application must choose a new standard or query the
0244 current standard first. Attempts to read or write data ahead of format
0245 negotiation, or after switching the video standard which may invalidate
0246 the negotiated VBI parameters, should be refused by the driver. A format
0247 change during active I/O is not permitted.
0248 
0249 Reading and writing VBI images
0250 ==============================
0251 
0252 To assure synchronization with the field number and easier
0253 implementation, the smallest unit of data passed at a time is one frame,
0254 consisting of two fields of VBI images immediately following in memory.
0255 
0256 The total size of a frame computes as follows:
0257 
0258 .. code-block:: c
0259 
0260     (count[0] + count[1]) * samples_per_line * sample size in bytes
0261 
0262 The sample size is most likely always one byte, applications must check
0263 the ``sample_format`` field though, to function properly with other
0264 drivers.
0265 
0266 A VBI device may support :ref:`read/write <rw>` and/or streaming
0267 (:ref:`memory mapping <mmap>` or :ref:`user pointer <userp>`) I/O.
0268 The latter bears the possibility of synchronizing video and VBI data by
0269 using buffer timestamps.
0270 
0271 Remember the :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` ioctl and the
0272 first :c:func:`read()`, :c:func:`write()` and
0273 :c:func:`select()` call can be resource allocation
0274 points returning an ``EBUSY`` error code if the required hardware resources
0275 are temporarily unavailable, for example the device is already in use by
0276 another process.
0277 
0278 .. [#f1]
0279    ASK: Amplitude-Shift Keying. A high signal level represents a '1'
0280    bit, a low level a '0' bit.
0281 
0282 .. [#f2]
0283    A few devices may be unable to sample VBI data at all but can extend
0284    the video capture window to the VBI region.
0285 
0286 .. [#f3]
0287    Most VBI services transmit on both fields, but some have different
0288    semantics depending on the field number. These cannot be reliable
0289    decoded or encoded when ``V4L2_VBI_UNSYNC`` is set.
0290 
0291 .. [#f4]
0292    The valid values ar shown at :ref:`vbi-525` and :ref:`vbi-625`.