FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
pgssubdec.c File Reference
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "mathops.h"
#include "libavutil/colorspace.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  PGSSubObjectRef
 
struct  PGSSubPresentation
 
struct  PGSSubObject
 
struct  PGSSubObjects
 
struct  PGSSubPalette
 
struct  PGSSubPalettes
 
struct  PGSSubContext
 

Macros

#define RGBA(r, g, b, a)   (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
 
#define MAX_EPOCH_PALETTES   8
 
#define MAX_EPOCH_OBJECTS   64
 
#define MAX_OBJECT_REFS   2
 
#define OFFSET(x)   offsetof(PGSSubContext, x)
 
#define SD   AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Enumerations

enum  SegmentType {
  PALETTE_SEGMENT = 0x14, OBJECT_SEGMENT = 0x15, PRESENTATION_SEGMENT = 0x16, WINDOW_SEGMENT = 0x17,
  DISPLAY_SEGMENT = 0x80, SEGMENT_TYPE_AUTO = 0, SEGMENT_TYPE_MP4, SEGMENT_TYPE_WEBM,
  SEGMENT_TYPE_NB, SEGMENT_TYPE_MPEGTS, SEGMENT_TYPE_FMP4
}
 

Functions

static void flush_cache (AVCodecContext *avctx)
 
static PGSSubObjectfind_object (int id, PGSSubObjects *objects)
 
static PGSSubPalettefind_palette (int id, PGSSubPalettes *palettes)
 
static av_cold int init_decoder (AVCodecContext *avctx)
 
static av_cold int close_decoder (AVCodecContext *avctx)
 
static int decode_rle (AVCodecContext *avctx, AVSubtitleRect *rect, const uint8_t *buf, unsigned int buf_size)
 Decode the RLE data. More...
 
static int parse_object_segment (AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 Parse the picture segment packet. More...
 
static int parse_palette_segment (AVCodecContext *avctx, const uint8_t *buf, int buf_size)
 Parse the palette segment packet. More...
 
static int parse_presentation_segment (AVCodecContext *avctx, const uint8_t *buf, int buf_size, int64_t pts)
 Parse the presentation segment packet. More...
 
static int display_end_segment (AVCodecContext *avctx, AVSubtitle *sub, const uint8_t *buf, int buf_size)
 Parse the display segment packet. More...
 
static int decode (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
 

Variables

static const AVOption options []
 
static const AVClass pgsdec_class
 
const FFCodec ff_pgssub_decoder
 

Detailed Description

PGS subtitle decoder

Definition in file pgssubdec.c.

Macro Definition Documentation

◆ RGBA

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

Definition at line 36 of file pgssubdec.c.

◆ MAX_EPOCH_PALETTES

#define MAX_EPOCH_PALETTES   8

Definition at line 37 of file pgssubdec.c.

◆ MAX_EPOCH_OBJECTS

#define MAX_EPOCH_OBJECTS   64

Definition at line 38 of file pgssubdec.c.

◆ MAX_OBJECT_REFS

#define MAX_OBJECT_REFS   2

Definition at line 39 of file pgssubdec.c.

◆ OFFSET

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

Definition at line 678 of file pgssubdec.c.

◆ SD

Definition at line 679 of file pgssubdec.c.

Enumeration Type Documentation

◆ SegmentType

Enumerator
PALETTE_SEGMENT 
OBJECT_SEGMENT 
PRESENTATION_SEGMENT 
WINDOW_SEGMENT 
DISPLAY_SEGMENT 
SEGMENT_TYPE_AUTO 
SEGMENT_TYPE_MP4 
SEGMENT_TYPE_WEBM 
SEGMENT_TYPE_NB 
SEGMENT_TYPE_MPEGTS 
SEGMENT_TYPE_FMP4 

Definition at line 41 of file pgssubdec.c.

Function Documentation

◆ flush_cache()

static void flush_cache ( AVCodecContext avctx)
static

Definition at line 101 of file pgssubdec.c.

Referenced by close_decoder(), and parse_presentation_segment().

◆ find_object()

static PGSSubObject* find_object ( int  id,
PGSSubObjects objects 
)
static

Definition at line 115 of file pgssubdec.c.

Referenced by display_end_segment(), and parse_object_segment().

◆ find_palette()

static PGSSubPalette* find_palette ( int  id,
PGSSubPalettes palettes 
)
static

Definition at line 126 of file pgssubdec.c.

Referenced by display_end_segment(), and parse_palette_segment().

◆ init_decoder()

static av_cold int init_decoder ( AVCodecContext avctx)
static

Definition at line 137 of file pgssubdec.c.

◆ close_decoder()

static av_cold int close_decoder ( AVCodecContext avctx)
static

Definition at line 144 of file pgssubdec.c.

◆ decode_rle()

static int decode_rle ( AVCodecContext avctx,
AVSubtitleRect rect,
const uint8_t *  buf,
unsigned int  buf_size 
)
static

Decode the RLE data.

The subtitle is stored as a Run Length Encoded image.

Parameters
avctxcontains the current codec context
subpointer to the processed subtitle data
bufpointer to the RLE data to process
buf_sizesize of the RLE data to process

Definition at line 161 of file pgssubdec.c.

Referenced by display_end_segment().

◆ parse_object_segment()

static int parse_object_segment ( AVCodecContext avctx,
const uint8_t *  buf,
int  buf_size 
)
static

Parse the picture segment packet.

The picture segment contains details on the sequence id, width, height and Run Length Encoded (RLE) bitmap data.

Parameters
avctxcontains the current codec context
bufpointer to the packet to process
buf_sizesize of packet to process

Definition at line 231 of file pgssubdec.c.

Referenced by decode().

◆ parse_palette_segment()

static int parse_palette_segment ( AVCodecContext avctx,
const uint8_t *  buf,
int  buf_size 
)
static

Parse the palette segment packet.

The palette segment contains details of the palette, a maximum of 256 colors can be defined.

Parameters
avctxcontains the current codec context
bufpointer to the packet to process
buf_sizesize of packet to process

Definition at line 326 of file pgssubdec.c.

Referenced by decode().

◆ parse_presentation_segment()

static int parse_presentation_segment ( AVCodecContext avctx,
const uint8_t *  buf,
int  buf_size,
int64_t  pts 
)
static

Parse the presentation segment packet.

The presentation segment contains details on the video width, video height, x & y subtitle position.

Parameters
avctxcontains the current codec context
bufpointer to the packet to process
buf_sizesize of packet to process
Todo:
TODO: Implement cropping

Definition at line 388 of file pgssubdec.c.

Referenced by decode().

◆ display_end_segment()

static int display_end_segment ( AVCodecContext avctx,
AVSubtitle sub,
const uint8_t *  buf,
int  buf_size 
)
static

Parse the display segment packet.

The display segment controls the updating of the display.

Parameters
avctxcontains the current codec context
datapointer to the data pertaining the subtitle to display
bufpointer to the packet to process
buf_sizesize of packet to process

Definition at line 496 of file pgssubdec.c.

Referenced by decode().

◆ decode()

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

Definition at line 591 of file pgssubdec.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{"forced_subs_only", "Only show forced subtitles", OFFSET(forced_subs_only), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, SD},
{ NULL },
}

Definition at line 680 of file pgssubdec.c.

◆ pgsdec_class

const AVClass pgsdec_class
static
Initial value:
= {
.class_name = "PGS subtitle decoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 685 of file pgssubdec.c.

◆ ff_pgssub_decoder

const FFCodec ff_pgssub_decoder
Initial value:
= {
.p.name = "pgssub",
CODEC_LONG_NAME("HDMV Presentation Graphic Stream subtitles"),
.priv_data_size = sizeof(PGSSubContext),
.close = close_decoder,
.p.priv_class = &pgsdec_class,
}

Definition at line 692 of file pgssubdec.c.

AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
init_decoder
static av_cold int init_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:137
options
static const AVOption options[]
Definition: pgssubdec.c:680
AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
Definition: codec_id.h:556
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
OFFSET
#define OFFSET(x)
Definition: pgssubdec.c:678
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
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
decode
static int decode(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Definition: pgssubdec.c:591
SD
#define SD
Definition: pgssubdec.c:679
PGSSubContext
Definition: pgssubdec.c:93
close_decoder
static av_cold int close_decoder(AVCodecContext *avctx)
Definition: pgssubdec.c:144
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition: codec_internal.h:309
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
pgsdec_class
static const AVClass pgsdec_class
Definition: pgssubdec.c:685