26 #define SCREEN_ROWS 15 27 #define SCREEN_COLUMNS 32 29 #define SET_FLAG(var, val) ( (var) |= ( 1 << (val)) ) 30 #define UNSET_FLAG(var, val) ( (var) &= ~( 1 << (val)) ) 31 #define CHECK_FLAG(var, val) ( (var) & ( 1 << (val)) ) 352 uint8_t cc_valid = (*cc_data_pair & 4) >>2;
353 uint8_t cc_type = *cc_data_pair & 3;
359 if (cc_type==0 || cc_type==1) {
364 cc_data_pair[1]=0x7F;
369 if ((cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] == 0xFD)
370 && (cc_data_pair[1] & 0x7F) == 0 && (cc_data_pair[2] & 0x7F) == 0)
374 if (cc_type == 3 || cc_type == 2)
378 cc_data_pair[1] &= 0x7F;
379 cc_data_pair[2] &= 0x7F;
416 if (i > ctx->
cursor_row - keep_lines && i <= ctx->cursor_row)
421 for (i = 0; i < keep_lines && screen->
row_used; i++) {
422 const int i_row = ctx->
cursor_row - keep_lines + i + 1;
446 const char *charset = screen->
charsets[
i];
459 const char *font = screen->
fonts[
i];
460 const char *charset = screen->
charsets[
i];
461 const char *
override;
462 int x, y, seen_char = 0;
474 const char *e_tag =
"", *s_tag =
"";
479 if (prev_font != font[j]) {
488 e_tag =
"{\\u0}{\\i0}";
499 s_tag =
"{\\u1}{\\i1}";
508 }
else if (row[j] ==
' ' && !seen_char) {
554 static const int8_t row_map[] = {
555 11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
557 const int index = ( (hi<<1) & 0x0e) | ( (lo>>5) & 0x01 );
561 if (row_map[index] <= 0) {
574 for (i = 0; i < indent; i++) {
656 ff_dlog(ctx,
"(%c,%c)\n", hi, lo);
672 if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
673 ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
675 }
else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
676 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
678 }
else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
707 ff_dlog(ctx,
"carriage return\n");
728 ff_dlog(ctx,
"Unknown command 0x%hhx 0x%hhx\n", hi, lo);
731 }
else if (hi >= 0x11 && hi <= 0x13) {
734 }
else if (hi >= 0x20) {
738 }
else if (hi == 0x17 && lo >= 0x21 && lo <= 0x23) {
741 for (i = 0; i < lo - 0x20; i++) {
746 ff_dlog(ctx,
"Unknown command 0x%hhx 0x%hhx\n", hi, lo);
768 for (i = 0; i <
len; i += 3) {
776 process_cc608(ctx, start_time, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
818 #define OFFSET(x) offsetof(CCaptionSubContext, x) 819 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM 821 {
"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 },
842 .priv_class = &ccaption_dec_class,
static void handle_edm(CCaptionSubContext *ctx, int64_t pts)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static void process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo)
static void flush(AVCodecContext *avctx)
static void handle_pac(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int ff_ass_subtitle_header(AVCodecContext *avctx, const char *font, int font_size, int color, int back_color, int bold, int italic, int underline, int border_style, int alignment)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
static av_cold int init(AVCodecContext *avctx)
uint8_t charsets[SCREEN_ROWS+1][SCREEN_COLUMNS+1]
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_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_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int readorder, int layer, const char *style, const char *speaker)
Add an ASS dialog to a subtitle.
static struct Screen * get_writing_screen(CCaptionSubContext *ctx)
static void handle_delete_end_of_row(CCaptionSubContext *ctx, char hi, char lo)
static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define CHECK_FLAG(var, val)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int64_t start_time
#define ASS_DEFAULT_ALIGNMENT
static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
static int reap_screen(CCaptionSubContext *ctx, int64_t pts)
static void handle_eoc(CCaptionSubContext *ctx, int64_t pts)
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
#define ASS_DEFAULT_PLAYRESY
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define ASS_DEFAULT_BACK_COLOR
#define i(width, name, range_min, range_max)
#define ASS_DEFAULT_UNDERLINE
#define AV_BPRINT_SIZE_UNLIMITED
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * name
Name of the codec implementation.
AVCodec ff_ccaption_decoder
#define ASS_DEFAULT_FONT_SIZE
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
#define SET_FLAG(var, val)
static av_cold int init_decoder(AVCodecContext *avctx)
uint8_t characters[SCREEN_ROWS+1][SCREEN_COLUMNS+1]
static int capture_screen(CCaptionSubContext *ctx)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
uint8_t fonts[SCREEN_ROWS+1][SCREEN_COLUMNS+1]
Libavcodec external API header.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static const unsigned char pac2_attribs[32][3]
main external API structure.
static void flush_decoder(AVCodecContext *avctx)
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static const AVClass ccaption_dec_class
static const AVRational ms_tb
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static void roll_up(CCaptionSubContext *ctx)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
#define ASS_DEFAULT_COLOR
static const char * charset_overrides[4][128]
static const AVOption options[]
#define UNSET_FLAG(var, val)
#define ASS_DEFAULT_ITALIC
static void handle_textattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
int flags2
AV_CODEC_FLAG2_*.
static const struct twinvq_data tab
static av_cold int close_decoder(AVCodecContext *avctx)
#define ASS_DEFAULT_PLAYRESX
static int validate_cc_data_pair(uint8_t *cc_data_pair)
This function after validating parity bit, also remove it from data pair.
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
uint8_t colors[SCREEN_ROWS+1][SCREEN_COLUMNS+1]