30 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
31 #define VBI_NB_COLORS 40
32 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
33 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
34 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
35 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
36 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
37 #define MAX_BUFFERED_PAGES 25
38 #define BITMAP_CHAR_WIDTH 12
39 #define BITMAP_CHAR_HEIGHT 10
79 if (*--t !=
' ' || (len-1 > 0 && *(t-1) & 0x80))
88 av_freep(&(*sub_rect)->pict.data[0]);
89 av_freep(&(*sub_rect)->pict.data[1]);
138 sz = vbi_print_page_region(page, vbi_text,
TEXT_MAXSZ-1,
"UTF-8",
141 page->columns, page->rows-chop_top);
156 in += strspn(in,
" \n");
158 for (nl = 0; in[nl]; ++nl)
159 if (in[nl] ==
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
195 int chop_top,
uint8_t transparent_color,
int resx,
int resy)
200 for (iy = 0; iy < resy; iy++) {
203 vbi_char *vcnext = vc + page->columns;
204 for (; vc < vcnext; vc++) {
206 switch (vc->opacity) {
207 case VBI_TRANSPARENT_SPACE:
208 memset(pixel, transparent_color, BITMAP_CHAR_WIDTH);
211 case VBI_SEMI_TRANSPARENT:
214 case VBI_TRANSPARENT_FULL:
215 for(; pixel < pixelnext; pixel++)
216 if (*pixel == vc->background)
217 *pixel = transparent_color;
232 vbi_char *vc = page->text + (chop_top * page->columns);
233 vbi_char *vcend = page->text + (page->rows * page->columns);
235 for (; vc < vcend; vc++) {
236 if (vc->opacity != VBI_TRANSPARENT_SPACE) {
253 vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
255 0, chop_top, page->columns, page->rows - chop_top,
269 for (ci = 0; ci < cmax; ci++) {
272 r =
VBI_R(page->color_map[ci]);
273 g =
VBI_G(page->color_map[ci]);
274 b =
VBI_B(page->color_map[ci]);
275 a =
VBI_A(page->color_map[ci]);
276 ((uint32_t *)sub_rect->
pict.
data[1])[ci] =
RGBA(r, g, b, a);
277 av_dlog(ctx,
"palette %0x\n", ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
279 ((uint32_t *)sub_rect->
pict.
data[1])[cmax] =
RGBA(0, 0, 0, 0);
296 snprintf(pgno_str,
sizeof pgno_str,
"%03x", ev->ev.ttx_page.pgno);
298 pgno_str, ev->ev.ttx_page.subno & 0xFF);
300 if (strcmp(ctx->
pgno,
"*") && !strstr(ctx->
pgno, pgno_str))
305 res = vbi_fetch_vt_page(ctx->
vbi, &page,
306 ev->ev.ttx_page.pgno,
307 ev->ev.ttx_page.subno,
308 VBI_WST_LEVEL_3p5, 25,
TRUE);
314 fprintf(stderr,
"\nSaving res=%d dy0=%d dy1=%d...\n",
315 res, page.dirty.y0, page.dirty.y1);
318 if (!vbi_export_stdio(ctx->ex, stderr, &page))
319 fprintf(stderr,
"failed: %s\n", vbi_export_errstr(ctx->ex));
322 vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
324 ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
327 page.columns, page.rows, chop_top);
332 ctx->
pages = new_pages;
335 cur_page->
pgno = ev->ev.ttx_page.pgno;
336 cur_page->
subno = ev->ev.ttx_page.subno;
359 vbi_unref_page(&page);
364 return (data_identifier >= 0x10 && data_identifier <= 0x1F ||
365 data_identifier >= 0x99 && data_identifier <= 0x9B);
372 int data_unit_id = buf[0];
373 int data_unit_length = buf[1];
374 if (data_unit_length + 2 > size)
376 if (data_unit_id == 0x02 || data_unit_id == 0x03) {
377 if (data_unit_length != 0x2c)
380 int line_offset = buf[2] & 0x1f;
381 int field_parity = buf[2] & 0x20;
383 ctx->
sliced[lines].id = VBI_SLICED_TELETEXT_B;
384 ctx->
sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
385 for (i = 0; i < 42; i++)
386 ctx->
sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
390 size -= data_unit_length + 2;
391 buf += data_unit_length + 2;
405 if (!(ctx->
vbi = vbi_decoder_new()))
407 if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE,
handler, ctx)) {
408 vbi_decoder_delete(ctx->
vbi);
419 const int full_pes_size = pkt->
size + 45;
422 if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
430 av_dlog(avctx,
"ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
431 ctx, pkt->
size, lines, (
double)pkt->
pts/90000.0);
436 for(i = 0; i < lines; i++)
440 vbi_decode(ctx->
vbi, ctx->
sliced, lines, 0.0);
475 for (i = 0; i < ctx->
nb_pages - 1; i++)
490 unsigned int maj,
min, rev;
492 vbi_version(&maj, &min, &rev);
493 if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
509 ctx->ex = vbi_export_new(
"text", &t);
525 vbi_decoder_delete(ctx->
vbi);
536 #define OFFSET(x) offsetof(TeletextContext, x)
537 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
541 {
"txt_format",
"format of the subtitles (bitmap or text)",
OFFSET(format_id),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD,
"txt_format"},
546 {
"txt_chop_spaces",
"chops leading and trailing spaces from text",
OFFSET(chop_spaces),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
SD},
547 {
"txt_duration",
"display duration of teletext pages in msecs",
OFFSET(sub_duration),
AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000,
SD},
548 {
"txt_transparent",
"force transparent background of the teletext",
OFFSET(transparent_bg),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
560 .
name =
"libzvbi_teletextdec",
570 .priv_class= &teletext_class,
int ff_ass_bprint_dialog(AVBPrint *buf, const char *dialog, int ts_start, int duration, int raw)
Add an ASS dialog line to an AVBPrint buffer.
static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
int x
top left corner of pict, undefined when pict is not set
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
int nb_colors
number of colors in pict, undefined when pict is not set
vbi_sliced sliced[MAX_SLICES]
static int chop_spaces_utf8(const unsigned char *t, int len)
static int create_ass_text(TeletextContext *ctx, const char *text, char **ass)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static int slice_to_vbi_lines(TeletextContext *ctx, uint8_t *buf, int size)
int w
width of pict, undefined when pict is not set
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
8 bit with AV_PIX_FMT_RGB32 palette
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
int ff_ass_subtitle_header_default(AVCodecContext *avctx)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS with default style.
static void handler(vbi_event *ev, void *user_data)
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define BITMAP_CHAR_HEIGHT
#define AV_LOG_VERBOSE
Detailed information.
#define MAX_BUFFERED_PAGES
int h
height of pict, undefined when pict is not set
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BPRINT_SIZE_UNLIMITED
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int y
top left corner of pict, undefined when pict is not set
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVS_Value void * user_data
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.
Libavcodec external API header.
#define BITMAP_CHAR_WIDTH
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
AVCodec ff_libzvbi_teletext_decoder
A bitmap, pict will be set.
AVPicture pict
data+linesize for the bitmap of this subtitle.
int width
picture width / height.
static void teletext_flush(AVCodecContext *avctx)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
static void flush(AVCodecContext *avctx)
#define av_dlog(pctx,...)
av_dlog macros
static int teletext_close_decoder(AVCodecContext *avctx)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static const AVOption options[]
main external API structure.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height)
Allocate memory for the pixels of a picture and setup the AVPicture fields for it.
static int teletext_init_decoder(AVCodecContext *avctx)
rational number numerator/denominator
static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
static const AVClass teletext_class
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
static int data_identifier_is_teletext(int data_identifier)
uint32_t start_display_time
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
Formatted text, the ass field must be set by the decoder and is authoritative.
void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size, const char *linebreaks, int keep_ass_markup)
Escape a text subtitle using ASS syntax into an AVBPrint buffer.
char * ass
0 terminated ASS/SSA compatible event line.
static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top, uint8_t transparent_color, int resx, int resy)
static void subtitle_rect_free(AVSubtitleRect **sub_rect)
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVSubtitleRect * sub_rect
#define AV_NOPTS_VALUE
Undefined timestamp value.