FFmpeg
Data Structures | Macros | Functions | Variables
libaribcaption.c File Reference
#include "avcodec.h"
#include "codec_internal.h"
#include "internal.h"
#include "libavcodec/ass.h"
#include "libavutil/avstring.h"
#include "libavutil/avutil.h"
#include "libavutil/thread.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include <aribcaption/aribcaption.h>

Go to the source code of this file.

Data Structures

struct  ARIBCaptionContext
 

Macros

#define DEFAULT_FONT_ASS   "sans-serif"
 
#define ARIBC_BPRINT_SIZE_INIT   64
 
#define ARIBC_BPRINT_SIZE_MAX   (8 * 1024)
 
#define ARIBC_ALPHA_MAX_NUM   4
 
#define ARIBC_ALPHA_DEFAULT_FRONT   0xFF
 
#define ARIBC_ALPHA_DEFAULT_BACK   0x80
 
#define ARIBCC_COLOR_RGB(c)   ((c) & 0xFFFFFF)
 
#define ARIBCC_COLOR_DIFF_RGB(c1, c2)   (((c1) ^ (c2)) & 0x00FFFFFF)
 
#define ARIBCC_COLOR_DIFF_A(c1, c2)   (((c1) ^ (c2)) & 0xFF000000)
 
#define CLUT_RGBA(r, g, b, a)   (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
 
#define CLUT_A(c)   (((c) >> 24) & 0xFF)
 
#define CLUT_R(c)   (((c) >> 16) & 0xFF)
 
#define CLUT_G(c)   (((c) >> 8) & 0xFF)
 
#define CLUT_B(c)   ( (c) & 0xFF)
 
#define ARIBCC_COLOR_TO_CLUT_RGBA(c, a)
 
#define ASS_SINGLE_RECT   0
 
#define OFFSET(x)   offsetof(ARIBCaptionContext, x)
 
#define SD   AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Functions

static void hex_dump_debug (void *ctx, const char *buf, int buf_size)
 
static void logcat_callback (aribcc_loglevel_t level, const char *message, void *userdata)
 
static void estimate_video_frame_size (ARIBCaptionContext *ctx)
 
static void clut_set_alpha (ARIBCaptionContext *ctx, uint8_t a)
 
static uint8_t clut_find_nearlest_alpha (ARIBCaptionContext *ctx, uint8_t a)
 
static int clut_find (ARIBCaptionContext *ctx, uint32_t rgba)
 
static int clut_color_distance (uint32_t rgba1, uint32_t rgba2)
 
static uint8_t clut_pick_or_set (ARIBCaptionContext *ctx, int r, int g, int b, int a)
 
static void clut_init (ARIBCaptionContext *ctx, aribcc_caption_region_t *region)
 
static int aribcaption_trans_bitmap_subtitle (ARIBCaptionContext *ctx)
 aribcaption_trans_{bitmap|ass|text}_subtitle() More...
 
static int set_ass_header (ARIBCaptionContext *ctx)
 
static void set_ass_color (AVBPrint *buf, int color_num, aribcc_color_t new_color, aribcc_color_t old_color)
 
static int aribcaption_trans_ass_subtitle (ARIBCaptionContext *ctx)
 
static int aribcaption_trans_text_subtitle (ARIBCaptionContext *ctx)
 
static int aribcaption_decode (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
 
static void aribcaption_flush (AVCodecContext *avctx)
 
static int aribcaption_close (AVCodecContext *avctx)
 
static int aribcaption_init (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass aribcaption_class
 
const FFCodec ff_libaribcaption_decoder
 

Macro Definition Documentation

◆ DEFAULT_FONT_ASS

#define DEFAULT_FONT_ASS   "sans-serif"

Definition at line 35 of file libaribcaption.c.

◆ ARIBC_BPRINT_SIZE_INIT

#define ARIBC_BPRINT_SIZE_INIT   64

Definition at line 38 of file libaribcaption.c.

◆ ARIBC_BPRINT_SIZE_MAX

#define ARIBC_BPRINT_SIZE_MAX   (8 * 1024)

Definition at line 39 of file libaribcaption.c.

◆ ARIBC_ALPHA_MAX_NUM

#define ARIBC_ALPHA_MAX_NUM   4

Definition at line 40 of file libaribcaption.c.

◆ ARIBC_ALPHA_DEFAULT_FRONT

#define ARIBC_ALPHA_DEFAULT_FRONT   0xFF

Definition at line 41 of file libaribcaption.c.

◆ ARIBC_ALPHA_DEFAULT_BACK

#define ARIBC_ALPHA_DEFAULT_BACK   0x80

Definition at line 42 of file libaribcaption.c.

◆ ARIBCC_COLOR_RGB

#define ARIBCC_COLOR_RGB (   c)    ((c) & 0xFFFFFF)

Definition at line 44 of file libaribcaption.c.

◆ ARIBCC_COLOR_DIFF_RGB

#define ARIBCC_COLOR_DIFF_RGB (   c1,
  c2 
)    (((c1) ^ (c2)) & 0x00FFFFFF)

Definition at line 45 of file libaribcaption.c.

◆ ARIBCC_COLOR_DIFF_A

#define ARIBCC_COLOR_DIFF_A (   c1,
  c2 
)    (((c1) ^ (c2)) & 0xFF000000)

Definition at line 46 of file libaribcaption.c.

◆ CLUT_RGBA

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

Definition at line 48 of file libaribcaption.c.

◆ CLUT_A

#define CLUT_A (   c)    (((c) >> 24) & 0xFF)

Definition at line 49 of file libaribcaption.c.

◆ CLUT_R

#define CLUT_R (   c)    (((c) >> 16) & 0xFF)

Definition at line 50 of file libaribcaption.c.

◆ CLUT_G

#define CLUT_G (   c)    (((c) >> 8) & 0xFF)

Definition at line 51 of file libaribcaption.c.

◆ CLUT_B

#define CLUT_B (   c)    ( (c) & 0xFF)

Definition at line 52 of file libaribcaption.c.

◆ ARIBCC_COLOR_TO_CLUT_RGBA

#define ARIBCC_COLOR_TO_CLUT_RGBA (   c,
  a 
)
Value:
(((ARIBCC_COLOR_A(c) ? ARIBCC_COLOR_A(c) : (a)) << 24) | \
(ARIBCC_COLOR_R(c) << 16) | \
(ARIBCC_COLOR_G(c) << 8) | \
(ARIBCC_COLOR_B(c)))

Definition at line 54 of file libaribcaption.c.

◆ ASS_SINGLE_RECT

#define ASS_SINGLE_RECT   0

Definition at line 1109 of file libaribcaption.c.

◆ OFFSET

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

Definition at line 1112 of file libaribcaption.c.

◆ SD

Definition at line 1113 of file libaribcaption.c.

Function Documentation

◆ hex_dump_debug()

static void hex_dump_debug ( void *  ctx,
const char *  buf,
int  buf_size 
)
static

Definition at line 105 of file libaribcaption.c.

Referenced by aribcaption_decode().

◆ logcat_callback()

static void logcat_callback ( aribcc_loglevel_t  level,
const char *  message,
void *  userdata 
)
static

Definition at line 118 of file libaribcaption.c.

Referenced by aribcaption_init().

◆ estimate_video_frame_size()

static void estimate_video_frame_size ( ARIBCaptionContext ctx)
static

Definition at line 139 of file libaribcaption.c.

Referenced by aribcaption_init(), and aribcaption_trans_bitmap_subtitle().

◆ clut_set_alpha()

static void clut_set_alpha ( ARIBCaptionContext ctx,
uint8_t  a 
)
static

Definition at line 164 of file libaribcaption.c.

Referenced by clut_init().

◆ clut_find_nearlest_alpha()

static uint8_t clut_find_nearlest_alpha ( ARIBCaptionContext ctx,
uint8_t  a 
)
static

Definition at line 179 of file libaribcaption.c.

Referenced by clut_pick_or_set().

◆ clut_find()

static int clut_find ( ARIBCaptionContext ctx,
uint32_t  rgba 
)
static

Definition at line 200 of file libaribcaption.c.

Referenced by clut_init().

◆ clut_color_distance()

static int clut_color_distance ( uint32_t  rgba1,
uint32_t  rgba2 
)
inlinestatic

Definition at line 211 of file libaribcaption.c.

Referenced by clut_pick_or_set().

◆ clut_pick_or_set()

static uint8_t clut_pick_or_set ( ARIBCaptionContext ctx,
int  r,
int  g,
int  b,
int  a 
)
static

Definition at line 218 of file libaribcaption.c.

Referenced by aribcaption_trans_bitmap_subtitle().

◆ clut_init()

static void clut_init ( ARIBCaptionContext ctx,
aribcc_caption_region_t *  region 
)
static

Definition at line 253 of file libaribcaption.c.

Referenced by aribcaption_trans_bitmap_subtitle().

◆ aribcaption_trans_bitmap_subtitle()

static int aribcaption_trans_bitmap_subtitle ( ARIBCaptionContext ctx)
static

aribcaption_trans_{bitmap|ass|text}_subtitle()

Transfer decoded subtitle to AVSubtitle with corresponding subtitle type.

Parameters
ctxpointer to the ARIBCaptionContext
Returns
> 0 number of rectangles to be displayed = 0 no subtitle < 0 error code

Definition at line 316 of file libaribcaption.c.

Referenced by aribcaption_decode().

◆ set_ass_header()

static int set_ass_header ( ARIBCaptionContext ctx)
static

Definition at line 498 of file libaribcaption.c.

Referenced by aribcaption_init(), and aribcaption_trans_ass_subtitle().

◆ set_ass_color()

static void set_ass_color ( AVBPrint *  buf,
int  color_num,
aribcc_color_t  new_color,
aribcc_color_t  old_color 
)
static

Definition at line 570 of file libaribcaption.c.

Referenced by aribcaption_trans_ass_subtitle().

◆ aribcaption_trans_ass_subtitle()

static int aribcaption_trans_ass_subtitle ( ARIBCaptionContext ctx)
static

Definition at line 581 of file libaribcaption.c.

Referenced by aribcaption_decode().

◆ aribcaption_trans_text_subtitle()

static int aribcaption_trans_text_subtitle ( ARIBCaptionContext ctx)
static

Definition at line 791 of file libaribcaption.c.

Referenced by aribcaption_decode().

◆ aribcaption_decode()

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

Definition at line 843 of file libaribcaption.c.

◆ aribcaption_flush()

static void aribcaption_flush ( AVCodecContext avctx)
static

Definition at line 929 of file libaribcaption.c.

◆ aribcaption_close()

static int aribcaption_close ( AVCodecContext avctx)
static

Definition at line 941 of file libaribcaption.c.

◆ aribcaption_init()

static int aribcaption_init ( AVCodecContext avctx)
static

Definition at line 956 of file libaribcaption.c.

Variable Documentation

◆ options

const AVOption options[]
static

Definition at line 1114 of file libaribcaption.c.

◆ aribcaption_class

const AVClass aribcaption_class
static
Initial value:
= {
.class_name = "aribcaption decoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1162 of file libaribcaption.c.

◆ ff_libaribcaption_decoder

const FFCodec ff_libaribcaption_decoder
Initial value:
= {
.p.name = "libaribcaption",
.p.long_name = NULL_IF_CONFIG_SMALL("ARIB STD-B24 caption decoder"),
.priv_data_size = sizeof(ARIBCaptionContext),
.p.priv_class = &aribcaption_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1169 of file libaribcaption.c.

aribcaption_class
static const AVClass aribcaption_class
Definition: libaribcaption.c:1162
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
aribcaption_init
static int aribcaption_init(AVCodecContext *avctx)
Definition: libaribcaption.c:956
options
static const AVOption options[]
Definition: libaribcaption.c:1114
AV_CODEC_ID_ARIB_CAPTION
@ AV_CODEC_ID_ARIB_CAPTION
Definition: codec_id.h:574
aribcaption_flush
static void aribcaption_flush(AVCodecContext *avctx)
Definition: libaribcaption.c:929
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
aribcaption_decode
static int aribcaption_decode(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Definition: libaribcaption.c:843
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
aribcaption_close
static int aribcaption_close(AVCodecContext *avctx)
Definition: libaribcaption.c:941
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition: codec_internal.h:290
ARIBCaptionContext
Definition: libaribcaption.c:59