xine-lib 1.2.11
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cc_decoder.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <inttypes.h>
#include <xine/xine_internal.h>
#include <xine/video_out.h>
#include <xine/xineutils.h>
#include <xine/osd.h>
#include "cc_decoder.h"

Data Structures

struct  colorinfo_s
 
struct  cc_renderer_s
 
struct  cc_attribute_s
 
struct  cc_char_cell_s
 
struct  cc_row_s
 
struct  cc_buffer_s
 
struct  cc_memory_s
 
struct  cc_decoder_s
 

Macros

#define NTSC_FRAME_DURATION   3003
 
#define CC_ROWS   15
 
#define CC_COLUMNS   32
 
#define CC_CHANNELS   2
 
#define CAP_BG_COL   1
 
#define NUM_FG_COL   7
 
#define TRANSP_SPACE
 

Typedefs

typedef struct colorinfo_s colorinfo_t
 
typedef struct cc_attribute_s cc_attribute_t
 
typedef struct cc_char_cell_s cc_char_cell_t
 
typedef struct cc_row_s cc_row_t
 
typedef struct cc_buffer_s cc_buffer_t
 
typedef struct cc_memory_s cc_memory_t
 

Enumerations

enum  {
  WHITE , GREEN , BLUE , CYAN ,
  RED , YELLOW , MAGENTA , BLACK ,
  TRANSPARENT
}
 

Functions

static void get_font_metrics (osd_renderer_t *renderer, const char *fontname, int font_size, int *maxw, int *maxh)
 
static int good_parity (uint16_t data)
 
static clut_t interpolate_color (clut_t src, clut_t dest, int steps, int current_step)
 
static void ccrow_fill_transp (cc_row_t *rowbuf)
 
static int ccrow_find_next_text_part (cc_row_t *this, int pos)
 
static int ccrow_find_end_of_text_part (cc_row_t *this, int pos)
 
static int ccrow_find_current_attr (cc_row_t *this, int pos)
 
static int ccrow_find_next_attr_change (cc_row_t *this, int pos, int lastpos)
 
static void ccrow_set_attributes (cc_renderer_t *renderer, cc_row_t *this, int pos)
 
static void ccrow_render (cc_renderer_t *renderer, cc_row_t *this, int rownum)
 
static int ccbuf_has_displayable (cc_buffer_t *this)
 
static void ccbuf_add_char (cc_buffer_t *this, uint8_t c)
 
static void ccbuf_set_cursor (cc_buffer_t *this, int row, int column, int underline, int italics, int color)
 
static void ccbuf_apply_attribute (cc_buffer_t *this, cc_attribute_t *attr)
 
static void ccbuf_tab (cc_buffer_t *this, int tabsize)
 
static void ccbuf_render (cc_renderer_t *renderer, cc_buffer_t *this)
 
static void ccmem_clear (cc_memory_t *this)
 
static void ccmem_init (cc_memory_t *this)
 
static void ccmem_exit (cc_memory_t *this)
 
static void cc_renderer_build_palette (cc_renderer_t *this)
 
static int64_t cc_renderer_calc_vpts (cc_renderer_t *this, int64_t pts, uint32_t ntsc_frame_offset)
 
static int cc_renderer_on_display (cc_renderer_t *this)
 
static void cc_renderer_hide_caption (cc_renderer_t *this, int64_t vpts)
 
static void cc_renderer_show_caption (cc_renderer_t *this, cc_buffer_t *buf, int64_t vpts)
 
static void cc_renderer_free_osd_object (cc_renderer_t *this)
 
static void cc_renderer_adjust_osd_object (cc_renderer_t *this)
 
cc_renderer_tcc_renderer_open (osd_renderer_t *osd_renderer, metronom_t *metronom, cc_state_t *cc_state, int video_width, int video_height)
 
void cc_renderer_close (cc_renderer_t *this_obj)
 
void cc_renderer_update_cfg (cc_renderer_t *this_obj, int video_width, int video_height)
 
static void cc_set_channel (cc_decoder_t *this, int channel)
 
static cc_buffer_tactive_ccbuffer (cc_decoder_t *this)
 
static int cc_onscreen_displayable (cc_decoder_t *this)
 
static void cc_hide_displayed (cc_decoder_t *this)
 
static void cc_show_displayed (cc_decoder_t *this)
 
static void cc_swap_buffers (cc_decoder_t *this)
 
static void cc_decode_standard_char (cc_decoder_t *this, uint8_t c1, uint8_t c2)
 
static void cc_decode_PAC (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_ext_attribute (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_special_char (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_midrow_attr (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_misc_control_code (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_tab (cc_decoder_t *this, int channel, uint8_t c1, uint8_t c2)
 
static void cc_decode_EIA608 (cc_decoder_t *this, uint16_t data)
 
void decode_cc (cc_decoder_t *this, uint8_t *buffer, uint32_t buf_len, int64_t pts)
 
cc_decoder_tcc_decoder_open (cc_state_t *cc_state)
 
void cc_decoder_close (cc_decoder_t *this)
 

Variables

static const int text_colormap [7]
 
static const colorinfo_t cc_text_trans [7]
 
static const colorinfo_t cc_text_solid [7]
 
static const uint8_t cc_text_trans_alpha [TEXT_PALETTE_SIZE]
 
static const uint8_t cc_text_solid_alpha [TEXT_PALETTE_SIZE]
 
static const colorinfo_t *const cc_text_palettes [2]
 
static const uint8_t *const cc_alpha_palettes [2]
 
static const int rowdata []
 
static const uint8_t specialchar []
 
static const int chartbl [128]
 Character translation table. More...
 
static const int parity_table [256]
 Parity table for packets. More...
 

Macro Definition Documentation

◆ CAP_BG_COL

#define CAP_BG_COL   1

◆ CC_CHANNELS

#define CC_CHANNELS   2

◆ CC_COLUMNS

#define CC_COLUMNS   32

◆ CC_ROWS

#define CC_ROWS   15

◆ NTSC_FRAME_DURATION

#define NTSC_FRAME_DURATION   3003

◆ NUM_FG_COL

#define NUM_FG_COL   7

◆ TRANSP_SPACE

#define TRANSP_SPACE
Value:
0x19 /* code for transparent space, essentially
arbitrary */

Typedef Documentation

◆ cc_attribute_t

◆ cc_buffer_t

typedef struct cc_buffer_s cc_buffer_t

◆ cc_char_cell_t

◆ cc_memory_t

typedef struct cc_memory_s cc_memory_t

◆ cc_row_t

typedef struct cc_row_s cc_row_t

◆ colorinfo_t

typedef struct colorinfo_s colorinfo_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
WHITE 
GREEN 
BLUE 
CYAN 
RED 
YELLOW 
MAGENTA 
BLACK 
TRANSPARENT 

Function Documentation

◆ active_ccbuffer()

static cc_buffer_t * active_ccbuffer ( cc_decoder_t this)
static

◆ cc_decode_EIA608()

static void cc_decode_EIA608 ( cc_decoder_t this,
uint16_t  data 
)
static

◆ cc_decode_ext_attribute()

static void cc_decode_ext_attribute ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

References cc_set_channel().

Referenced by cc_decode_EIA608().

◆ cc_decode_midrow_attr()

static void cc_decode_midrow_attr ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decode_misc_control_code()

static void cc_decode_misc_control_code ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decode_PAC()

static void cc_decode_PAC ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decode_special_char()

static void cc_decode_special_char ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decode_standard_char()

static void cc_decode_standard_char ( cc_decoder_t this,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decode_tab()

static void cc_decode_tab ( cc_decoder_t this,
int  channel,
uint8_t  c1,
uint8_t  c2 
)
static

◆ cc_decoder_close()

void cc_decoder_close ( cc_decoder_t this)

References ccmem_exit().

Referenced by spucc_do_close().

◆ cc_decoder_open()

cc_decoder_t * cc_decoder_open ( cc_state_t cc_state)

References ccmem_init(), and NULL.

Referenced by spucc_do_init().

◆ cc_hide_displayed()

static void cc_hide_displayed ( cc_decoder_t this)
static

◆ cc_onscreen_displayable()

static int cc_onscreen_displayable ( cc_decoder_t this)
static

References ccbuf_has_displayable().

Referenced by cc_show_displayed().

◆ cc_renderer_adjust_osd_object()

static void cc_renderer_adjust_osd_object ( cc_renderer_t this)
static

◆ cc_renderer_build_palette()

static void cc_renderer_build_palette ( cc_renderer_t this)
static

◆ cc_renderer_calc_vpts()

static int64_t cc_renderer_calc_vpts ( cc_renderer_t this,
int64_t  pts,
uint32_t  ntsc_frame_offset 
)
static

◆ cc_renderer_close()

void cc_renderer_close ( cc_renderer_t this_obj)

References cc_renderer_free_osd_object().

Referenced by spucc_do_close().

◆ cc_renderer_free_osd_object()

static void cc_renderer_free_osd_object ( cc_renderer_t this)
static

◆ cc_renderer_hide_caption()

static void cc_renderer_hide_caption ( cc_renderer_t this,
int64_t  vpts 
)
static

◆ cc_renderer_on_display()

static int cc_renderer_on_display ( cc_renderer_t this)
static

Referenced by cc_hide_displayed().

◆ cc_renderer_open()

cc_renderer_t * cc_renderer_open ( osd_renderer_t osd_renderer,
metronom_t metronom,
cc_state_t cc_state,
int  video_width,
int  video_height 
)

References cc_renderer_update_cfg(), and NULL.

Referenced by spucc_do_init().

◆ cc_renderer_show_caption()

static void cc_renderer_show_caption ( cc_renderer_t this,
cc_buffer_t buf,
int64_t  vpts 
)
static

◆ cc_renderer_update_cfg()

void cc_renderer_update_cfg ( cc_renderer_t this_obj,
int  video_width,
int  video_height 
)

◆ cc_set_channel()

static void cc_set_channel ( cc_decoder_t this,
int  channel 
)
static

◆ cc_show_displayed()

static void cc_show_displayed ( cc_decoder_t this)
static

◆ cc_swap_buffers()

static void cc_swap_buffers ( cc_decoder_t this)
static

◆ ccbuf_add_char()

static void ccbuf_add_char ( cc_buffer_t this,
uint8_t  c 
)
static

◆ ccbuf_apply_attribute()

static void ccbuf_apply_attribute ( cc_buffer_t this,
cc_attribute_t attr 
)
static

◆ ccbuf_has_displayable()

static int ccbuf_has_displayable ( cc_buffer_t this)
static

References CC_ROWS.

Referenced by cc_onscreen_displayable().

◆ ccbuf_render()

static void ccbuf_render ( cc_renderer_t renderer,
cc_buffer_t this 
)
static

References CC_ROWS, and ccrow_render().

Referenced by cc_renderer_show_caption().

◆ ccbuf_set_cursor()

static void ccbuf_set_cursor ( cc_buffer_t this,
int  row,
int  column,
int  underline,
int  italics,
int  color 
)
static

◆ ccbuf_tab()

static void ccbuf_tab ( cc_buffer_t this,
int  tabsize 
)
static

References CC_COLUMNS, and cc_row_s::pos.

Referenced by cc_decode_tab().

◆ ccmem_clear()

static void ccmem_clear ( cc_memory_t this)
static

◆ ccmem_exit()

static void ccmem_exit ( cc_memory_t this)
static

Referenced by cc_decoder_close().

◆ ccmem_init()

static void ccmem_init ( cc_memory_t this)
static

References ccmem_clear().

Referenced by cc_decoder_open().

◆ ccrow_fill_transp()

static void ccrow_fill_transp ( cc_row_t rowbuf)
static

◆ ccrow_find_current_attr()

static int ccrow_find_current_attr ( cc_row_t this,
int  pos 
)
static

Referenced by ccrow_render().

◆ ccrow_find_end_of_text_part()

static int ccrow_find_end_of_text_part ( cc_row_t this,
int  pos 
)
static

References TRANSP_SPACE.

Referenced by ccrow_render().

◆ ccrow_find_next_attr_change()

static int ccrow_find_next_attr_change ( cc_row_t this,
int  pos,
int  lastpos 
)
static

Referenced by ccrow_render().

◆ ccrow_find_next_text_part()

static int ccrow_find_next_text_part ( cc_row_t this,
int  pos 
)
static

References TRANSP_SPACE.

Referenced by ccrow_render().

◆ ccrow_render()

static void ccrow_render ( cc_renderer_t renderer,
cc_row_t this,
int  rownum 
)
static

◆ ccrow_set_attributes()

static void ccrow_set_attributes ( cc_renderer_t renderer,
cc_row_t this,
int  pos 
)
static

◆ decode_cc()

void decode_cc ( cc_decoder_t this,
uint8_t *  buffer,
uint32_t  buf_len,
int64_t  pts 
)

References cc_decode_EIA608(), and good_parity().

Referenced by spudec_decode_data().

◆ get_font_metrics()

static void get_font_metrics ( osd_renderer_t renderer,
const char *  fontname,
int  font_size,
int *  maxw,
int *  maxh 
)
static

◆ good_parity()

static int good_parity ( uint16_t  data)
static

References parity_table.

Referenced by decode_cc().

◆ interpolate_color()

static clut_t interpolate_color ( clut_t  src,
clut_t  dest,
int  steps,
int  current_step 
)
static

Variable Documentation

◆ cc_alpha_palettes

const uint8_t* const cc_alpha_palettes[2]
static
Initial value:
= {
}
static const uint8_t cc_text_solid_alpha[TEXT_PALETTE_SIZE]
Definition: cc_decoder.c:203
static const uint8_t cc_text_trans_alpha[TEXT_PALETTE_SIZE]
Definition: cc_decoder.c:199

Referenced by cc_renderer_build_palette().

◆ cc_text_palettes

const colorinfo_t* const cc_text_palettes[2]
static
Initial value:
= {
}
static const colorinfo_t cc_text_trans[7]
Definition: cc_decoder.c:96
static const colorinfo_t cc_text_solid[7]
Definition: cc_decoder.c:147

Referenced by cc_renderer_build_palette().

◆ cc_text_solid

const colorinfo_t cc_text_solid[7]
static

◆ cc_text_solid_alpha

const uint8_t cc_text_solid_alpha[TEXT_PALETTE_SIZE]
static
Initial value:
= {
0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15
}

◆ cc_text_trans

const colorinfo_t cc_text_trans[7]
static

◆ cc_text_trans_alpha

const uint8_t cc_text_trans_alpha[TEXT_PALETTE_SIZE]
static
Initial value:
= {
0, 8, 9, 10, 11, 12, 15, 15, 15, 15, 15
}

◆ chartbl

const int chartbl[128]
static
Initial value:
= {
'\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
'\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
'\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f',
'\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27',
'\x28', '\x29', '\xe1', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f',
'\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37',
'\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f',
'\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47',
'\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f',
'\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57',
'\x58', '\x59', '\x5a', '\x5b', '\xe9', '\x5d', '\xed', '\xf3',
'\xfa', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67',
'\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f',
'\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77',
'\x78', '\x79', '\x7a', '\xe7', '\xf7', '\xd1', '\xf1', '\xa4'
}

Character translation table.

EIA 608 codes are not all the same as ASCII

The code to produce the characters table would be the following:

static void build_char_table(void) { int i; // first the normal ASCII codes for (i = 0; i < 128; i++) chartbl[i] = (char) i; // now the special codes chartbl[0x2a] = 225; // á chartbl[0x5c] = 233; // é chartbl[0x5e] = 237; // í chartbl[0x5f] = 243; // ó chartbl[0x60] = 250; // ú chartbl[0x7b] = 231; // ç chartbl[0x7c] = 247; // ÷ chartbl[0x7d] = 209; // Ñ chartbl[0x7e] = 241; // ñ chartbl[0x7f] = 164; // ¤ FIXME: should be a solid block ('█'; U+2588) }

Referenced by cc_decode_standard_char(), and ccbuf_apply_attribute().

◆ parity_table

const int parity_table[256]
static
Initial value:
= {
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0
}

Parity table for packets.

CC codes use odd parity for error detection, since they originally were transmitted via noisy video signals.

The code to produce the parity table would be the following:

static int parity(uint8_t byte) { int i; int ones = 0;

for (i = 0; i < 7; i++) { if (byte & (1 << i)) ones++; }

return ones & 1; }

static void build_parity_table(void) { uint8_t byte; int parity_v; for (byte = 0; byte <= 127; byte++) { parity_v = parity(byte); // CC uses odd parity (i.e., # of 1's in byte is odd.) parity_table[byte] = parity_v; parity_table[byte | 0x80] = !parity_v; } }

Referenced by good_parity().

◆ rowdata

const int rowdata[]
static
Initial value:
= {10, -1, 0, 1, 2, 3, 11, 12, 13, 14, 4, 5, 6,
7, 8, 9}

Referenced by cc_decode_PAC().

◆ specialchar

const uint8_t specialchar[]
static
Initial value:
= {
174 , 176 , 189 , 191 ,
'T' , 162 , 163 , 182 ,
224 , 0x19 ,232 , 226 ,
234 , 238 , 244 , 251
}

Referenced by cc_decode_special_char().

◆ text_colormap

const int text_colormap[7]
static
Initial value:
= {
}
#define OSD_TEXT2
Definition: osd.h:282
#define OSD_TEXT4
Definition: osd.h:284
#define OSD_TEXT7
Definition: osd.h:287
#define OSD_TEXT5
Definition: osd.h:285
#define OSD_TEXT3
Definition: osd.h:283
#define OSD_TEXT1
Definition: osd.h:281
#define OSD_TEXT6
Definition: osd.h:286

Referenced by ccrow_render().