ZVBI Library  0.2.33
Data Structures | Typedefs | Enumerations | Functions
Raw VBI decoder
Raw VBI

Converting raw VBI samples to bits and bytes. More...

Data Structures

struct  vbi_bit_slicer
 Bit slicer context. More...
struct  vbi_raw_decoder
 Raw vbi decoder context. More...

Typedefs

typedef struct vbi_bit_slicer vbi_bit_slicer
 Bit slicer context.
typedef struct vbi_raw_decoder vbi_raw_decoder
 Raw vbi decoder context.

Enumerations

enum  vbi_pixfmt {
  VBI_PIXFMT_YUV420 = 1,
  VBI_PIXFMT_YUYV,
  VBI_PIXFMT_YVYU,
  VBI_PIXFMT_UYVY,
  VBI_PIXFMT_VYUY,
  VBI_PIXFMT_PAL8,
  VBI_PIXFMT_RGBA32_LE = 32,
  VBI_PIXFMT_RGBA32_BE,
  VBI_PIXFMT_BGRA32_LE,
  VBI_PIXFMT_BGRA32_BE,
  VBI_PIXFMT_ABGR32_BE = 32,
  VBI_PIXFMT_ABGR32_LE,
  VBI_PIXFMT_ARGB32_BE,
  VBI_PIXFMT_ARGB32_LE,
  VBI_PIXFMT_RGB24,
  VBI_PIXFMT_BGR24,
  VBI_PIXFMT_RGB16_LE,
  VBI_PIXFMT_RGB16_BE,
  VBI_PIXFMT_BGR16_LE,
  VBI_PIXFMT_BGR16_BE,
  VBI_PIXFMT_RGBA15_LE,
  VBI_PIXFMT_RGBA15_BE,
  VBI_PIXFMT_BGRA15_LE,
  VBI_PIXFMT_BGRA15_BE,
  VBI_PIXFMT_ARGB15_LE,
  VBI_PIXFMT_ARGB15_BE,
  VBI_PIXFMT_ABGR15_LE,
  VBI_PIXFMT_ABGR15_BE
}
 Image format used as source to vbi_bit_slice() and vbi_raw_decode(). More...
enum  vbi_modulation {
  VBI_MODULATION_NRZ_LSB,
  VBI_MODULATION_NRZ_MSB,
  VBI_MODULATION_BIPHASE_LSB,
  VBI_MODULATION_BIPHASE_MSB
}
 Modulation used for VBI data transmission. More...

Functions

void vbi_bit_slicer_init (vbi_bit_slicer *slicer, int raw_samples, int sampling_rate, int cri_rate, int bit_rate, unsigned int cri_frc, unsigned int cri_mask, int cri_bits, int frc_bits, int payload, vbi_modulation modulation, vbi_pixfmt fmt)
_vbi_inline vbi_bool vbi_bit_slice (vbi_bit_slicer *slicer, uint8_t *raw, uint8_t *buf)
void vbi_raw_decoder_init (vbi_raw_decoder *rd)
void vbi_raw_decoder_reset (vbi_raw_decoder *rd)
void vbi_raw_decoder_destroy (vbi_raw_decoder *rd)
unsigned int vbi_raw_decoder_add_services (vbi_raw_decoder *rd, unsigned int services, int strict)
unsigned int vbi_raw_decoder_check_services (vbi_raw_decoder *rd, unsigned int services, int strict)
unsigned int vbi_raw_decoder_remove_services (vbi_raw_decoder *rd, unsigned int services)
void vbi_raw_decoder_resize (vbi_raw_decoder *rd, int *start, unsigned int *count)
unsigned int vbi_raw_decoder_parameters (vbi_raw_decoder *rd, unsigned int services, int scanning, int *max_rate)
int vbi_raw_decode (vbi_raw_decoder *rd, uint8_t *raw, vbi_sliced *out)

Detailed Description

Converting raw VBI samples to bits and bytes.

The libzvbi already offers hardware interfaces to obtain sliced VBI data for further processing. However if you want to write your own interface or decode data services not covered by libzvbi you can use these lower level functions.


Typedef Documentation

Bit slicer context.

The contents of this structure are private, use vbi_bit_slicer_init() to initialize.

Raw vbi decoder context.

Only the sampling parameters are public. See vbi_raw_decoder_parameters() and vbi_raw_decoder_add_services() for usage.


Enumeration Type Documentation

enum vbi_pixfmt

Image format used as source to vbi_bit_slice() and vbi_raw_decode().

SymbolByte 0Byte 1Byte 2Byte 3
Planar YUV 4:2:0 data.
VBI_PIXFMT_YUV420
Y planeU planeV plane
Y00Y01Y02Y03
Y10Y11Y12Y13
Y20Y21Y22Y23
Y30Y31Y32Y33
Cb00Cb01
Cb10Cb11
Cr00Cr01
Cr10Cr11
Packed YUV 4:2:2 data.
VBI_PIXFMT_YUYVY0CbY1Cr
VBI_PIXFMT_YVYUY0CrY1Cb
VBI_PIXFMT_UYVYCbY0CrY1
VBI_PIXFMT_VYUYCrY0CbY1
Packed 32 bit RGB data.
VBI_PIXFMT_RGBA32_LE VBI_PIXFMT_ARGB32_BE r7 ... r0g7 ... g0 b7 ... b0a7 ... a0
VBI_PIXFMT_BGRA32_LE VBI_PIXFMT_ARGB32_BE b7 ... b0g7 ... g0 r7 ... r0a7 ... a0
VBI_PIXFMT_ARGB32_LE VBI_PIXFMT_BGRA32_BE a7 ... a0r7 ... r0 g7 ... g0b7 ... b0
VBI_PIXFMT_ABGR32_LE VBI_PIXFMT_RGBA32_BE a7 ... a0b7 ... b0 g7 ... g0r7 ... r0
Packed 24 bit RGB data.
VBI_PIXFMT_RGBA24 r7 ... r0g7 ... g0 b7 ... b0 
VBI_PIXFMT_BGRA24 b7 ... b0g7 ... g0 r7 ... r0 
Packed 16 bit RGB data.
VBI_PIXFMT_RGB16_LE g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3   
VBI_PIXFMT_BGR16_LE g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3   
VBI_PIXFMT_RGB16_BE b4 b3 b2 b1 b0 g5 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0   
VBI_PIXFMT_BGR16_BE r4 r3 r2 r1 r0 g5 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0   
Packed 15 bit RGB data.
VBI_PIXFMT_RGBA15_LE g2 g1 g0 r4 r3 r2 r1 r0 a0 b4 b3 b2 b1 b0 g4 g3   
VBI_PIXFMT_BGRA15_LE g2 g1 g0 b4 b3 b2 b1 b0 a0 r4 r3 r2 r1 r0 g4 g3   
VBI_PIXFMT_ARGB15_LE g1 g0 r4 r3 r2 r1 r0 a0 b4 b3 b2 b1 b0 g4 g3 g2   
VBI_PIXFMT_ABGR15_LE g1 g0 b4 b3 b2 b1 b0 a0 r4 r3 r2 r1 r0 g4 g3 g2   
VBI_PIXFMT_RGBA15_BE a0 b4 b3 b2 b1 b0 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0   
VBI_PIXFMT_BGRA15_BE a0 r4 r3 r2 r1 r0 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0   
VBI_PIXFMT_ARGB15_BE b4 b3 b2 b1 b0 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0 a0   
VBI_PIXFMT_ABGR15_BE r4 r3 r2 r1 r0 g4 g3 g2 g1 g0 b4 b3 b2 b1 b0 a0   

Modulation used for VBI data transmission.

Enumerator:
VBI_MODULATION_NRZ_LSB 

The data is 'non-return to zero' coded, logical '1' bits are described by high sample values, logical '0' bits by low values. The data is last significant bit first transmitted.

VBI_MODULATION_NRZ_MSB 

'Non-return to zero' coded, most significant bit first transmitted.

VBI_MODULATION_BIPHASE_LSB 

The data is 'bi-phase' coded. Each data bit is described by two complementary signalling elements, a logical '1' by a sequence of '10' elements, a logical '0' by a '01' sequence. The data is last significant bit first transmitted.

VBI_MODULATION_BIPHASE_MSB 

'Bi-phase' coded, most significant bit first transmitted.


Function Documentation

void vbi_bit_slicer_init ( vbi_bit_slicer slicer,
int  raw_samples,
int  sampling_rate,
int  cri_rate,
int  bit_rate,
unsigned int  cri_frc,
unsigned int  cri_mask,
int  cri_bits,
int  frc_bits,
int  payload,
vbi_modulation  modulation,
vbi_pixfmt  fmt 
)
Parameters:
slicerPointer to vbi_bit_slicer object to be initialized.
raw_samplesNumber of samples or pixels in one raw vbi line later passed to vbi_bit_slice(). This limits the number of bytes read from the sample buffer.
sampling_rateRaw vbi sampling rate in Hz, that is the number of samples or pixels sampled per second by the hardware.
cri_rateThe Clock Run In is a NRZ modulated sequence of '0' and '1' bits prepending most data transmissions to synchronize data acquisition circuits. This parameter gives the CRI bit rate in Hz, that is the number of CRI bits transmitted per second.
bit_rateThe transmission bit rate of all data bits following the CRI in Hz.
cri_frcThe FRaming Code usually following the CRI is a bit sequence identifying the data service, and per libzvbi definition modulated and transmitted at the same bit rate as the payload (however nothing stops you from counting all nominal CRI and FRC bits as CRI). The bit slicer compares the bits in this word, lsb last transmitted, against the transmitted CRI and FRC. Decoding of payload starts with the next bit after a match.
cri_maskOf the CRI bits in cri_frc, only these bits are actually significant for a match. For instance it is wise not to rely on the very first CRI bits transmitted. Note this mask is not shifted left by frc_bits.
cri_bits
frc_bitsNumber of CRI and FRC bits in cri_frc, respectively. Their sum is limited to 32.
payloadNumber of payload bits. Only this data will be stored in the vbi_bit_slice() output. If this number is no multiple of eight, the most significant bits of the last byte are undefined.
modulationModulation of the vbi data, see vbi_modulation.
fmtFormat of the raw data, see vbi_pixfmt.

Initializes vbi_bit_slicer object. Usually you will not use this function but vbi_raw_decode(), the vbi image decoder which handles all these details.

_vbi_inline vbi_bool vbi_bit_slice ( vbi_bit_slicer slicer,
uint8_t *  raw,
uint8_t *  buf 
)
Parameters:
slicerPointer to initialized vbi_bit_slicer object.
rawInput data. At least the number of pixels or samples given as raw_samples to vbi_bit_slicer_init().
bufOutput data. The buffer must be large enough to store the number of bits given as payload to vbi_bit_slicer_init().

Decode one scan line of raw vbi data. Note the bit slicer tries to adapt to the average signal amplitude, you should avoid using the same vbi_bit_slicer object for data from different devices.

Note:
As a matter of speed this function does not lock the slicer. When you want to share a vbi_bit_slicer object between multiple threads you must implement your own locking mechanism.
Returns:
FALSE if the raw data does not contain the expected information, i. e. the CRI/FRC has not been found. This may also result from a too weak or noisy signal. Error correction must be implemented at a higher layer.
void vbi_raw_decoder_init ( vbi_raw_decoder rd)
Parameters:
rdPointer to a vbi_raw_decoder structure.

Initializes a vbi_raw_decoder structure.

void vbi_raw_decoder_reset ( vbi_raw_decoder rd)
Parameters:
rdInitialized vbi_raw_decoder structure.

Reset a vbi_raw_decoder structure. This removes all previously added services to be decoded (if any) but does not touch the sampling parameters. You are free to change the sampling parameters after calling this.

void vbi_raw_decoder_destroy ( vbi_raw_decoder rd)
Parameters:
rdPointer to initialized vbi_raw_decoder structure, can be NULL.

Free all resources associated with rd.

unsigned int vbi_raw_decoder_add_services ( vbi_raw_decoder rd,
unsigned int  services,
int  strict 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
servicesSet of VBI_SLICED_ symbols.
strictA value of 0, 1 or 2 requests loose, reliable or strict matching of sampling parameters. For example if the data service requires knowledge of line numbers while they are not known, 0 will accept the service (which may work if the scan lines are populated in a non-confusing way) but 1 or 2 will not. If the data service may use more lines than are sampled, 1 will accept but 2 will not. If unsure, set to 1.

After you initialized the sampling parameters in rd (according to the abilities of your raw vbi source), this function adds one or more data services to be decoded. The libzvbi raw vbi decoder can decode up to eight data services in parallel. You can call this function while already decoding, it does not change sampling parameters and you must not change them either after calling this.

Returns:
Set of VBI_SLICED_ symbols describing the data services that actually will be decoded. This excludes those services not decodable given the sampling parameters in rd.
unsigned int vbi_raw_decoder_check_services ( vbi_raw_decoder rd,
unsigned int  services,
int  strict 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
servicesSet of VBI_SLICED_ symbols.
strictSee description of vbi_raw_decoder_add_services()

Check which of the given services can be decoded with current capture parameters at a given strictness level.

Returns:
Subset of services actually decodable.
unsigned int vbi_raw_decoder_remove_services ( vbi_raw_decoder rd,
unsigned int  services 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
servicesSet of VBI_SLICED_ symbols.

Removes one or more data services to be decoded from the vbi_raw_decoder structure. This function can be called at any time and does not touch sampling parameters.

Returns:
Set of VBI_SLICED_ symbols describing the remaining data services that will be decoded.
void vbi_raw_decoder_resize ( vbi_raw_decoder rd,
int *  start,
unsigned int *  count 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
startArray of start line indices for both fields
countArray of line counts for both fields

Grows or shrinks the internal state arrays for VBI geometry changes

unsigned int vbi_raw_decoder_parameters ( vbi_raw_decoder rd,
unsigned int  services,
int  scanning,
int *  max_rate 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
servicesSet of VBI_SLICED_ symbols. Here (and only here) you can add VBI_SLICED_VBI_625 or VBI_SLICED_VBI_525 to include all vbi scan lines in the calculated sampling parameters.
scanningWhen 525 accept only NTSC services, when 625 only PAL/SECAM services. When scanning is 0, determine the scanning from the requested services, an ambiguous set will pick a 525 or 625 line system at random.
max_rateIf given, the highest data bit rate in Hz of all services requested is stored here. (The sampling rate should be at least twice as high; rd->sampling_rate will be set to a more reasonable value of 27 MHz derived from ITU-R Rec. 601.)

Calculate the sampling parameters in rd required to receive and decode the requested data services. rd->sampling_format will be VBI_PIXFMT_YUV420, rd->bytes_per_line set accordingly to a reasonable minimum. This function can be used to initialize hardware prior to calling vbi_raw_decoder_add_service().

Returns:
Set of VBI_SLICED_ symbols describing the data services covered by the calculated sampling parameters. This excludes services the libzvbi raw decoder cannot decode.
int vbi_raw_decode ( vbi_raw_decoder rd,
uint8_t *  raw,
vbi_sliced out 
)
Parameters:
rdInitialized vbi_raw_decoder structure.
rawA raw vbi image as defined in the vbi_raw_decoder structure (rd->sampling_format, rd->bytes_per_line, rd->count[0] + rd->count[1] scan lines).
outBuffer to store the decoded vbi_sliced data. Since every vbi scan line may contain data, this must be an array of vbi_sliced with the same number of entries as scan lines in the raw image (rd->count[0] + rd->count[1]).

Decode a raw vbi image, consisting of several scan lines of raw vbi data, into sliced vbi data. The output is sorted by line number.

Note this function attempts to learn which lines carry which data service, or none, to speed up decoding. You should avoid using the same vbi_raw_decoder structure for different sources.

Returns:
The number of lines decoded, i. e. the number of vbi_sliced records written.