FFmpeg
Data Structures | Macros | Functions | Variables
libzvbi-teletextdec.c File Reference
#include "avcodec.h"
#include "libavcodec/ass.h"
#include "codec_internal.h"
#include "libavcodec/dvbtxt.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/bprint.h"
#include "libavutil/internal.h"
#include "libavutil/log.h"
#include "libavutil/common.h"
#include <libzvbi.h>

Go to the source code of this file.

Data Structures

struct  TeletextPage
 
struct  TeletextContext
 

Macros

#define TEXT_MAXSZ   (25 * (56 + 1) * 4 + 2)
 
#define VBI_NB_COLORS   40
 
#define VBI_TRANSPARENT_BLACK   8
 
#define RGBA(r, g, b, a)   (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
 
#define VBI_R(rgba)   (((rgba) >> 0) & 0xFF)
 
#define VBI_G(rgba)   (((rgba) >> 8) & 0xFF)
 
#define VBI_B(rgba)   (((rgba) >> 16) & 0xFF)
 
#define VBI_A(rgba)   (((rgba) >> 24) & 0xFF)
 
#define MAX_BUFFERED_PAGES   25
 
#define BITMAP_CHAR_WIDTH   12
 
#define BITMAP_CHAR_HEIGHT   10
 
#define MAX_SLICES   64
 
#define IS_TXT_SPACE(ch)
 
#define OFFSET(x)   offsetof(TeletextContext, x)
 
#define SD   AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Functions

static int my_ass_subtitle_header (AVCodecContext *avctx)
 
static int chop_spaces_utf8 (const unsigned char *t, int len)
 
static void subtitle_rect_free (AVSubtitleRect **sub_rect)
 
static char * create_ass_text (TeletextContext *ctx, const char *text)
 
static int gen_sub_text (TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
 
static void bprint_color (const char *type, AVBPrint *buf, vbi_page *page, unsigned ci)
 
static void get_trim_info (vbi_page *page, vbi_char *row, int *leading, int *trailing, int *olen)
 
static void decode_string (vbi_page *page, vbi_char *row, AVBPrint *buf, int start, int end, vbi_color *cur_color, vbi_color *cur_back_color)
 
static int gen_sub_ass (TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
 
static void fix_transparency (TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top, int resx, int resy)
 
static int gen_sub_bitmap (TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
 
static void handler (vbi_event *ev, void *user_data)
 
static int slice_to_vbi_lines (TeletextContext *ctx, const uint8_t *buf, int size)
 
static int teletext_decode_frame (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *pkt)
 
static int teletext_init_decoder (AVCodecContext *avctx)
 
static int teletext_close_decoder (AVCodecContext *avctx)
 
static void teletext_flush (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass teletext_class
 
const FFCodec ff_libzvbi_teletext_decoder
 

Macro Definition Documentation

◆ TEXT_MAXSZ

#define TEXT_MAXSZ   (25 * (56 + 1) * 4 + 2)

Definition at line 34 of file libzvbi-teletextdec.c.

◆ VBI_NB_COLORS

#define VBI_NB_COLORS   40

Definition at line 35 of file libzvbi-teletextdec.c.

◆ VBI_TRANSPARENT_BLACK

#define VBI_TRANSPARENT_BLACK   8

Definition at line 36 of file libzvbi-teletextdec.c.

◆ RGBA

#define RGBA (   r,
  g,
  b,
  a 
)    (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

Definition at line 37 of file libzvbi-teletextdec.c.

◆ VBI_R

#define VBI_R (   rgba)    (((rgba) >> 0) & 0xFF)

Definition at line 38 of file libzvbi-teletextdec.c.

◆ VBI_G

#define VBI_G (   rgba)    (((rgba) >> 8) & 0xFF)

Definition at line 39 of file libzvbi-teletextdec.c.

◆ VBI_B

#define VBI_B (   rgba)    (((rgba) >> 16) & 0xFF)

Definition at line 40 of file libzvbi-teletextdec.c.

◆ VBI_A

#define VBI_A (   rgba)    (((rgba) >> 24) & 0xFF)

Definition at line 41 of file libzvbi-teletextdec.c.

◆ MAX_BUFFERED_PAGES

#define MAX_BUFFERED_PAGES   25

Definition at line 42 of file libzvbi-teletextdec.c.

◆ BITMAP_CHAR_WIDTH

#define BITMAP_CHAR_WIDTH   12

Definition at line 43 of file libzvbi-teletextdec.c.

◆ BITMAP_CHAR_HEIGHT

#define BITMAP_CHAR_HEIGHT   10

Definition at line 44 of file libzvbi-teletextdec.c.

◆ MAX_SLICES

#define MAX_SLICES   64

Definition at line 45 of file libzvbi-teletextdec.c.

◆ IS_TXT_SPACE

#define IS_TXT_SPACE (   ch)
Value:
((ch).unicode < 0x0020 || (ch).unicode >= 0xe000 || (ch).unicode == 0x00a0 ||\
(ch).size > VBI_DOUBLE_SIZE || (ch).opacity == VBI_TRANSPARENT_SPACE)

Definition at line 242 of file libzvbi-teletextdec.c.

◆ OFFSET

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

Definition at line 788 of file libzvbi-teletextdec.c.

◆ SD

Definition at line 789 of file libzvbi-teletextdec.c.

Function Documentation

◆ my_ass_subtitle_header()

static int my_ass_subtitle_header ( AVCodecContext avctx)
static

Definition at line 85 of file libzvbi-teletextdec.c.

Referenced by teletext_init_decoder().

◆ chop_spaces_utf8()

static int chop_spaces_utf8 ( const unsigned char *  t,
int  len 
)
static

Definition at line 131 of file libzvbi-teletextdec.c.

Referenced by gen_sub_text().

◆ subtitle_rect_free()

static void subtitle_rect_free ( AVSubtitleRect **  sub_rect)
static

Definition at line 142 of file libzvbi-teletextdec.c.

Referenced by teletext_close_decoder(), and teletext_decode_frame().

◆ create_ass_text()

static char* create_ass_text ( TeletextContext ctx,
const char *  text 
)
static

Definition at line 150 of file libzvbi-teletextdec.c.

Referenced by gen_sub_text().

◆ gen_sub_text()

static int gen_sub_text ( TeletextContext ctx,
AVSubtitleRect sub_rect,
vbi_page *  page,
int  chop_top 
)
static

Definition at line 167 of file libzvbi-teletextdec.c.

Referenced by handler().

◆ bprint_color()

static void bprint_color ( const char *  type,
AVBPrint *  buf,
vbi_page *  page,
unsigned  ci 
)
static

Definition at line 234 of file libzvbi-teletextdec.c.

Referenced by decode_string().

◆ get_trim_info()

static void get_trim_info ( vbi_page *  page,
vbi_char *  row,
int *  leading,
int *  trailing,
int *  olen 
)
static

Definition at line 245 of file libzvbi-teletextdec.c.

Referenced by gen_sub_ass().

◆ decode_string()

static void decode_string ( vbi_page *  page,
vbi_char *  row,
AVBPrint *  buf,
int  start,
int  end,
vbi_color *  cur_color,
vbi_color *  cur_back_color 
)
static

Definition at line 265 of file libzvbi-teletextdec.c.

Referenced by gen_sub_ass().

◆ gen_sub_ass()

static int gen_sub_ass ( TeletextContext ctx,
AVSubtitleRect sub_rect,
vbi_page *  page,
int  chop_top 
)
static

Definition at line 295 of file libzvbi-teletextdec.c.

Referenced by handler().

◆ fix_transparency()

static void fix_transparency ( TeletextContext ctx,
AVSubtitleRect sub_rect,
vbi_page *  page,
int  chop_top,
int  resx,
int  resy 
)
static

Definition at line 412 of file libzvbi-teletextdec.c.

Referenced by gen_sub_bitmap().

◆ gen_sub_bitmap()

static int gen_sub_bitmap ( TeletextContext ctx,
AVSubtitleRect sub_rect,
vbi_page *  page,
int  chop_top 
)
static

Definition at line 451 of file libzvbi-teletextdec.c.

Referenced by handler().

◆ handler()

static void handler ( vbi_event *  ev,
void *  user_data 
)
static

◆ slice_to_vbi_lines()

static int slice_to_vbi_lines ( TeletextContext ctx,
const uint8_t *  buf,
int  size 
)
static

Definition at line 584 of file libzvbi-teletextdec.c.

Referenced by teletext_decode_frame().

◆ teletext_decode_frame()

static int teletext_decode_frame ( AVCodecContext avctx,
AVSubtitle sub,
int *  got_sub_ptr,
const AVPacket pkt 
)
static

Definition at line 640 of file libzvbi-teletextdec.c.

◆ teletext_init_decoder()

static int teletext_init_decoder ( AVCodecContext avctx)
static

Definition at line 726 of file libzvbi-teletextdec.c.

◆ teletext_close_decoder()

static int teletext_close_decoder ( AVCodecContext avctx)
static

Definition at line 763 of file libzvbi-teletextdec.c.

Referenced by teletext_flush().

◆ teletext_flush()

static void teletext_flush ( AVCodecContext avctx)
static

Definition at line 783 of file libzvbi-teletextdec.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{"txt_page", "page numbers to decode, subtitle for subtitles, * for all", OFFSET(pgno), AV_OPT_TYPE_STRING, {.str = "*"}, 0, 0, SD},
{"txt_default_region", "default G0 character set used for decoding", OFFSET(default_region), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 87, SD},
{"txt_chop_top", "discards the top teletext line", OFFSET(chop_top), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
{"txt_format", "format of the subtitles (bitmap or text or ass)", OFFSET(format_id), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, SD, .unit = "txt_format"},
{"bitmap", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, SD, .unit = "txt_format"},
{"text", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, SD, .unit = "txt_format"},
{"ass", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, SD, .unit = "txt_format"},
{"txt_left", "x offset of generated bitmaps", OFFSET(x_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
{"txt_top", "y offset of generated bitmaps", OFFSET(y_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
{"txt_chop_spaces", "chops leading and trailing spaces from text", OFFSET(chop_spaces), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
{"txt_duration", "display duration of teletext pages in msecs", OFFSET(sub_duration), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 86400000, SD},
{"txt_transparent", "force transparent background of the teletext", OFFSET(transparent_bg), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD},
{"txt_opacity", "set opacity of the transparent background", OFFSET(opacity), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 255, SD},
{ NULL },
}

Definition at line 790 of file libzvbi-teletextdec.c.

◆ teletext_class

const AVClass teletext_class
static
Initial value:
= {
.class_name = "libzvbi_teletextdec",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 807 of file libzvbi-teletextdec.c.

◆ ff_libzvbi_teletext_decoder

const FFCodec ff_libzvbi_teletext_decoder
Initial value:
= {
.p.name = "libzvbi_teletextdec",
CODEC_LONG_NAME("Libzvbi DVB teletext decoder"),
.p.capabilities = AV_CODEC_CAP_DELAY,
.p.priv_class = &teletext_class,
.p.wrapper_name = "libzvbi",
.priv_data_size = sizeof(TeletextContext),
.flush = teletext_flush,
}

Definition at line 814 of file libzvbi-teletextdec.c.

AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
OFFSET
#define OFFSET(x)
Definition: libzvbi-teletextdec.c:788
AV_CODEC_ID_DVB_TELETEXT
@ AV_CODEC_ID_DVB_TELETEXT
Definition: codec_id.h:563
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
SD
#define SD
Definition: libzvbi-teletextdec.c:789
NULL
#define NULL
Definition: coverity.c:32
teletext_close_decoder
static int teletext_close_decoder(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:763
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
TeletextContext
Definition: libzvbi-teletextdec.c:55
teletext_decode_frame
static int teletext_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *pkt)
Definition: libzvbi-teletextdec.c:640
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
teletext_init_decoder
static int teletext_init_decoder(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:726
options
static const AVOption options[]
Definition: libzvbi-teletextdec.c:790
teletext_flush
static void teletext_flush(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:783
teletext_class
static const AVClass teletext_class
Definition: libzvbi-teletextdec.c:807
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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:314
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299