FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
ccaption_dec.c File Reference
#include <assert.h>
#include "avcodec.h"
#include "ass.h"
#include "codec_internal.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  Screen
 
struct  CCaptionSubContext
 

Macros

#define SCREEN_ROWS   15
 
#define SCREEN_COLUMNS   32
 
#define SET_FLAG(var, val)   ( (var) |= ( 1 << (val)) )
 
#define UNSET_FLAG(var, val)   ( (var) &= ~( 1 << (val)) )
 
#define CHECK_FLAG(var, val)   ( (var) & ( 1 << (val)) )
 
#define CHARSET_OVERRIDE_LIST(START_SET, ENTRY, END_SET)
 
#define START_SET(IDX)   [IDX] = {
 
#define ENTRY(idx, string)   [idx] = string,
 
#define END_SET   },
 
#define EMPTY_START(IDX)
 
#define EMPTY_END
 
#define ASSERT_ENTRY(IDX, str)
 
#define OFFSET(x)   offsetof(CCaptionSubContext, x)
 
#define SD   AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Enumerations

enum  cc_mode { CCMODE_POPON, CCMODE_PAINTON, CCMODE_ROLLUP, CCMODE_TEXT }
 
enum  cc_color_code {
  CCCOL_WHITE, CCCOL_GREEN, CCCOL_BLUE, CCCOL_CYAN,
  CCCOL_RED, CCCOL_YELLOW, CCCOL_MAGENTA, CCCOL_USERDEFINED,
  CCCOL_BLACK, CCCOL_TRANSPARENT
}
 
enum  cc_font { CCFONT_REGULAR, CCFONT_ITALICS, CCFONT_UNDERLINED, CCFONT_UNDERLINED_ITALICS }
 
enum  cc_charset { CCSET_BASIC_AMERICAN, CCSET_SPECIAL_AMERICAN, CCSET_EXTENDED_SPANISH_FRENCH_MISC, CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH }
 

Functions

static av_cold int init_decoder (AVCodecContext *avctx)
 
static av_cold int close_decoder (AVCodecContext *avctx)
 
static void flush_decoder (AVCodecContext *avctx)
 
static void write_char (CCaptionSubContext *ctx, struct Screen *screen, char ch)
 
static int validate_cc_data_pair (const uint8_t *cc_data_pair, uint8_t *hi)
 This function after validating parity bit, also remove it from data pair. More...
 
static struct Screenget_writing_screen (CCaptionSubContext *ctx)
 
static void roll_up (CCaptionSubContext *ctx)
 
static int capture_screen (CCaptionSubContext *ctx)
 
static void update_time (CCaptionSubContext *ctx, int64_t pts)
 
static void handle_bgattr (CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
 
static void handle_textattr (CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
 
static void handle_pac (CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
 
static int handle_edm (CCaptionSubContext *ctx)
 
static int handle_eoc (CCaptionSubContext *ctx)
 
static void handle_delete_end_of_row (CCaptionSubContext *ctx)
 
static void handle_char (CCaptionSubContext *ctx, char hi, char lo)
 
static int process_cc608 (CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
 
static int decode (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub, const AVPacket *avpkt)
 

Variables

static const AVRational ms_tb = {1, 1000}
 
static const char charset_overrides [4][128][sizeof("\u266a")]
 
static const unsigned char bg_attribs [8]
 
static const unsigned char pac2_attribs [32][3]
 
static const AVOption options []
 
static const AVClass ccaption_dec_class
 
const FFCodec ff_ccaption_decoder
 

Macro Definition Documentation

◆ SCREEN_ROWS

#define SCREEN_ROWS   15

Definition at line 28 of file ccaption_dec.c.

◆ SCREEN_COLUMNS

#define SCREEN_COLUMNS   32

Definition at line 29 of file ccaption_dec.c.

◆ SET_FLAG

#define SET_FLAG (   var,
  val 
)    ( (var) |= ( 1 << (val)) )

Definition at line 31 of file ccaption_dec.c.

◆ UNSET_FLAG

#define UNSET_FLAG (   var,
  val 
)    ( (var) &= ~( 1 << (val)) )

Definition at line 32 of file ccaption_dec.c.

◆ CHECK_FLAG

#define CHECK_FLAG (   var,
  val 
)    ( (var) & ( 1 << (val)) )

Definition at line 33 of file ccaption_dec.c.

◆ CHARSET_OVERRIDE_LIST

#define CHARSET_OVERRIDE_LIST (   START_SET,
  ENTRY,
  END_SET 
)

Definition at line 71 of file ccaption_dec.c.

◆ START_SET

#define START_SET (   IDX)    [IDX] = {

◆ ENTRY

#define ENTRY (   idx,
  string 
)    [idx] = string,

◆ END_SET

#define END_SET   },

◆ EMPTY_START

#define EMPTY_START (   IDX)

Definition at line 182 of file ccaption_dec.c.

◆ EMPTY_END

#define EMPTY_END

Definition at line 183 of file ccaption_dec.c.

◆ ASSERT_ENTRY

#define ASSERT_ENTRY (   IDX,
  str 
)
Value:
static_assert(sizeof(str) <= sizeof(charset_overrides[0][0]), \
"'" str "' string takes too much space");

Definition at line 184 of file ccaption_dec.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(CCaptionSubContext, x)

Definition at line 939 of file ccaption_dec.c.

◆ SD

Definition at line 940 of file ccaption_dec.c.

Enumeration Type Documentation

◆ cc_mode

enum cc_mode
Enumerator
CCMODE_POPON 
CCMODE_PAINTON 
CCMODE_ROLLUP 
CCMODE_TEXT 

Definition at line 37 of file ccaption_dec.c.

◆ cc_color_code

Enumerator
CCCOL_WHITE 
CCCOL_GREEN 
CCCOL_BLUE 
CCCOL_CYAN 
CCCOL_RED 
CCCOL_YELLOW 
CCCOL_MAGENTA 
CCCOL_USERDEFINED 
CCCOL_BLACK 
CCCOL_TRANSPARENT 

Definition at line 44 of file ccaption_dec.c.

◆ cc_font

enum cc_font
Enumerator
CCFONT_REGULAR 
CCFONT_ITALICS 
CCFONT_UNDERLINED 
CCFONT_UNDERLINED_ITALICS 

Definition at line 57 of file ccaption_dec.c.

◆ cc_charset

enum cc_charset
Enumerator
CCSET_BASIC_AMERICAN 
CCSET_SPECIAL_AMERICAN 
CCSET_EXTENDED_SPANISH_FRENCH_MISC 
CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH 

Definition at line 64 of file ccaption_dec.c.

Function Documentation

◆ init_decoder()

static av_cold int init_decoder ( AVCodecContext avctx)
static

Definition at line 279 of file ccaption_dec.c.

◆ close_decoder()

static av_cold int close_decoder ( AVCodecContext avctx)
static

Definition at line 301 of file ccaption_dec.c.

◆ flush_decoder()

static void flush_decoder ( AVCodecContext avctx)
static

Definition at line 309 of file ccaption_dec.c.

◆ write_char()

static void write_char ( CCaptionSubContext ctx,
struct Screen screen,
char  ch 
)
static
Parameters
ctxclosed caption context just to print log

Definition at line 337 of file ccaption_dec.c.

Referenced by handle_char(), handle_delete_end_of_row(), handle_pac(), and handle_textattr().

◆ validate_cc_data_pair()

static int validate_cc_data_pair ( const uint8_t *  cc_data_pair,
uint8_t *  hi 
)
static

This function after validating parity bit, also remove it from data pair.

The first byte doesn't pass parity, we replace it with a solid blank and process the pair. If the second byte doesn't pass parity, it returns INVALIDDATA user can ignore the whole pair and pass the other pair.

Definition at line 374 of file ccaption_dec.c.

Referenced by decode().

◆ get_writing_screen()

static struct Screen* get_writing_screen ( CCaptionSubContext ctx)
static

◆ roll_up()

static void roll_up ( CCaptionSubContext ctx)
static

Definition at line 422 of file ccaption_dec.c.

Referenced by process_cc608().

◆ capture_screen()

static int capture_screen ( CCaptionSubContext ctx)
static

Definition at line 458 of file ccaption_dec.c.

Referenced by decode(), handle_edm(), handle_eoc(), and process_cc608().

◆ update_time()

static void update_time ( CCaptionSubContext ctx,
int64_t  pts 
)
static

Definition at line 614 of file ccaption_dec.c.

Referenced by decode().

◆ handle_bgattr()

static void handle_bgattr ( CCaptionSubContext ctx,
uint8_t  hi,
uint8_t  lo 
)
static

Definition at line 620 of file ccaption_dec.c.

Referenced by process_cc608().

◆ handle_textattr()

static void handle_textattr ( CCaptionSubContext ctx,
uint8_t  hi,
uint8_t  lo 
)
static

Definition at line 627 of file ccaption_dec.c.

Referenced by process_cc608().

◆ handle_pac()

static void handle_pac ( CCaptionSubContext ctx,
uint8_t  hi,
uint8_t  lo 
)
static

Definition at line 642 of file ccaption_dec.c.

Referenced by process_cc608().

◆ handle_edm()

static int handle_edm ( CCaptionSubContext ctx)
static

Definition at line 669 of file ccaption_dec.c.

Referenced by handle_eoc(), and process_cc608().

◆ handle_eoc()

static int handle_eoc ( CCaptionSubContext ctx)
static

Definition at line 690 of file ccaption_dec.c.

Referenced by process_cc608().

◆ handle_delete_end_of_row()

static void handle_delete_end_of_row ( CCaptionSubContext ctx)
static

Definition at line 711 of file ccaption_dec.c.

Referenced by process_cc608().

◆ handle_char()

static void handle_char ( CCaptionSubContext ctx,
char  hi,
char  lo 
)
static

Definition at line 717 of file ccaption_dec.c.

Referenced by process_cc608().

◆ process_cc608()

static int process_cc608 ( CCaptionSubContext ctx,
uint8_t  hi,
uint8_t  lo 
)
static

Definition at line 757 of file ccaption_dec.c.

Referenced by decode().

◆ decode()

static int decode ( AVCodecContext avctx,
AVSubtitle sub,
int got_sub,
const AVPacket avpkt 
)
static

Definition at line 851 of file ccaption_dec.c.

Variable Documentation

◆ ms_tb

const AVRational ms_tb = {1, 1000}
static

Definition at line 35 of file ccaption_dec.c.

Referenced by decode().

◆ charset_overrides

const char charset_overrides[4][128][sizeof("\u266a")]
static
Initial value:
=
{
#define START_SET(IDX)
#define ENTRY(idx, string)
#define END_SET
}

Definition at line 172 of file ccaption_dec.c.

Referenced by capture_screen().

◆ bg_attribs

const unsigned char bg_attribs[8]
static
Initial value:

Definition at line 189 of file ccaption_dec.c.

Referenced by handle_bgattr().

◆ pac2_attribs

const unsigned char pac2_attribs[32][3]
static

Definition at line 201 of file ccaption_dec.c.

Referenced by handle_pac(), and handle_textattr().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "real_time", "emit subtitle events as they are decoded for real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, SD },
{ "real_time_latency_msec", "minimum elapsed time between emitting real-time subtitle events", OFFSET(real_time_latency_msec), AV_OPT_TYPE_INT, { .i64 = 200 }, 0, 500, SD },
{ "data_field", "select data field", OFFSET(data_field), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, .unit = "data_field" },
{ "auto", "pick first one that appears", 0, AV_OPT_TYPE_CONST, { .i64 =-1 }, 0, 0, SD, .unit = "data_field" },
{ "first", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD, .unit = "data_field" },
{ "second", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, SD, .unit = "data_field" },
{NULL}
}

Definition at line 941 of file ccaption_dec.c.

◆ ccaption_dec_class

const AVClass ccaption_dec_class
static
Initial value:
= {
.class_name = "Closed Captions Decoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 951 of file ccaption_dec.c.

◆ ff_ccaption_decoder

const FFCodec ff_ccaption_decoder
Initial value:
= {
.p.name = "cc_dec",
CODEC_LONG_NAME("Closed Captions (EIA-608 / CEA-708)"),
.p.priv_class = &ccaption_dec_class,
.p.capabilities = AV_CODEC_CAP_DELAY,
.priv_data_size = sizeof(CCaptionSubContext),
.close = close_decoder,
}

Definition at line 958 of file ccaption_dec.c.

CCCOL_YELLOW
@ CCCOL_YELLOW
Definition: ccaption_dec.c:50
AV_CODEC_ID_EIA_608
@ AV_CODEC_ID_EIA_608
Definition: codec_id.h:559
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
CCaptionSubContext
Definition: ccaption_dec.c:254
OFFSET
#define OFFSET(x)
Definition: ccaption_dec.c:939
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
CCCOL_BLUE
@ CCCOL_BLUE
Definition: ccaption_dec.c:47
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:367
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
charset_overrides
static const char charset_overrides[4][128][sizeof("\u266a")]
Definition: ccaption_dec.c:172
CCCOL_BLACK
@ CCCOL_BLACK
Definition: ccaption_dec.c:53
flush_decoder
static void flush_decoder(AVCodecContext *avctx)
Definition: ccaption_dec.c:309
init_decoder
static av_cold int init_decoder(AVCodecContext *avctx)
Definition: ccaption_dec.c:279
options
static const AVOption options[]
Definition: ccaption_dec.c:941
CCCOL_GREEN
@ CCCOL_GREEN
Definition: ccaption_dec.c:46
close_decoder
static av_cold int close_decoder(AVCodecContext *avctx)
Definition: ccaption_dec.c:301
CCCOL_CYAN
@ CCCOL_CYAN
Definition: ccaption_dec.c:48
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
decode
static int decode(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub, const AVPacket *avpkt)
Definition: ccaption_dec.c:851
ccaption_dec_class
static const AVClass ccaption_dec_class
Definition: ccaption_dec.c:951
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition: codec_internal.h:290
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
CCCOL_RED
@ CCCOL_RED
Definition: ccaption_dec.c:49
CCCOL_WHITE
@ CCCOL_WHITE
Definition: ccaption_dec.c:45
CCCOL_MAGENTA
@ CCCOL_MAGENTA
Definition: ccaption_dec.c:51
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
SD
#define SD
Definition: ccaption_dec.c:940