22 #include "libavutil/opt.h"
23 #include "libavutil/intreadwrite.h"
27 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
28 #define VBI_NB_COLORS 40
29 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
30 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
31 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
32 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
33 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
68 if (*--t !=
' ' || (len-1 > 0 && *(t-1) & 0x80))
89 sz = vbi_print_page_region(page, vbi_text,
TEXT_MAXSZ-1,
"UTF-8",
92 page->columns, page->rows-chop_top);
110 in += strspn(in,
" \n");
112 for (nl = 0; in[nl]; ++nl)
113 if (in[nl] ==
'\n' && (nl==0 || !(in[nl-1] & 0x80)))
125 strcpy(text, vbi_text);
133 sub_rect->
text = text;
149 for (iy = 0; iy < resy; iy++) {
151 vbi_char *vc = page->text + (iy / 10 + chop_top) * page->columns;
152 vbi_char *vcnext = vc + page->columns;
153 for (; vc < vcnext; vc++) {
154 uint8_t *pixelnext = pixel + 12;
155 switch (vc->opacity) {
156 case VBI_TRANSPARENT_SPACE:
157 memset(pixel, transparent_color, 12);
160 case VBI_SEMI_TRANSPARENT:
163 case VBI_TRANSPARENT_FULL:
164 for(; pixel < pixelnext; pixel++)
165 if (*pixel == vc->background)
166 *pixel = transparent_color;
179 int resx = page->columns * 12;
180 int resy = (page->rows - chop_top) * 10;
183 vbi_char *vc = page->text + (chop_top * page->columns);
184 vbi_char *vcend = page->text + (page->rows * page->columns);
186 for (; vc < vcend; vc++) {
187 if (vc->opacity != VBI_TRANSPARENT_SPACE) {
204 vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
206 0, chop_top, page->columns, page->rows - chop_top,
220 for (ci = 0; ci < cmax; ci++) {
223 r =
VBI_R(page->color_map[ci]);
224 g =
VBI_G(page->color_map[ci]);
225 b =
VBI_B(page->color_map[ci]);
226 a =
VBI_A(page->color_map[ci]);
227 ((uint32_t *)sub_rect->
pict.
data[1])[ci] =
RGBA(r, g, b, a);
230 ((uint32_t *)sub_rect->
pict.
data[1])[ci]);
233 ((uint32_t *)sub_rect->
pict.
data[1])[cmax] =
RGBA(0, 0, 0, 0);
250 snprintf(pgno_str,
sizeof pgno_str,
"%03x", ev->ev.ttx_page.pgno);
252 pgno_str, ev->ev.ttx_page.subno & 0xFF);
254 if (strcmp(ctx->
pgno,
"*") && !strstr(ctx->
pgno, pgno_str))
258 res = vbi_fetch_vt_page(ctx->
vbi, &page,
259 ev->ev.ttx_page.pgno,
260 ev->ev.ttx_page.subno,
261 VBI_WST_LEVEL_3p5, 25,
TRUE);
267 fprintf(stderr,
"\nSaving res=%d dy0=%d dy1=%d...\n",
268 res, page.dirty.y0, page.dirty.y1);
271 if (!vbi_export_stdio(ctx->ex, stderr, &page))
272 fprintf(stderr,
"failed: %s\n", vbi_export_errstr(ctx->ex));
275 vpt = vbi_classify_page(ctx->
vbi, ev->ev.ttx_page.pgno, &subno, &lang);
277 ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
280 page.columns, page.rows, chop_top);
296 vbi_unref_page(&page);
301 void *
data,
int *data_size,
307 unsigned int left = pkt->
size;
308 uint8_t pesheader[45] = {0x00, 0x00, 0x01, 0xbd, 0x00, 0x00, 0x85, 0x80, 0x24, 0x21, 0x00, 0x01, 0x00, 0x01};
309 int pesheader_size =
sizeof(pesheader);
310 const uint8_t *pesheader_buf = pesheader;
313 if (!(ctx->
vbi = vbi_decoder_new()))
315 if (!vbi_event_handler_add(ctx->
vbi, VBI_EVENT_TTX_PAGE,
handler, ctx)) {
316 vbi_decoder_delete(ctx->
vbi);
321 if (!ctx->
dx && (!(ctx->
dx = vbi_dvb_pes_demux_new ( NULL, NULL))))
325 if ((pesheader_size + left) < 184 || (pesheader_size + left) > 65504 || (pesheader_size + left) % 184 != 0)
328 memset(pesheader + 14, 0xff, pesheader_size - 14);
329 AV_WB16(pesheader + 4, left + pesheader_size - 6);
334 vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, NULL, &pesheader_buf, &pesheader_size);
338 unsigned int lines = vbi_dvb_demux_cor(ctx->
dx, ctx->
sliced, 64, &pts, &buf, &left);
341 "ctx=%p buf_size=%d left=%u lines=%u pts=%f pkt_pts=%f\n",
342 ctx, pkt->
size, left, lines, (
double)pts/90000.0, (
double)pkt->
pts/90000.0);
347 for(i=0; i<lines; ++i)
349 "lines=%d id=%x\n", i, ctx->
sliced[i].id);
351 vbi_decode(ctx->
vbi, ctx->
sliced, lines, (
double)pts/90000.0);
387 unsigned int maj,
min, rev;
389 vbi_version(&maj, &min, &rev);
390 if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
398 if (!strcmp(ctx->
format,
"bitmap")) {
400 }
else if (!strcmp(ctx->
format,
"text")) {
410 ctx->ex = vbi_export_new(
"text", &t);
425 vbi_dvb_demux_delete(ctx->
dx);
426 vbi_decoder_delete(ctx->
vbi);
437 #define OFFSET(x) offsetof(TeletextContext, x)
438 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
445 {
"txt_chop_spaces",
"chops leading and trailing spaces from text",
OFFSET(chop_spaces),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
SD},
446 {
"txt_duration",
"display duration of teletext pages in msecs",
OFFSET(sub_duration),
AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000,
SD},
447 {
"txt_transparent",
"force transparent background of the teletext",
OFFSET(transparent_bg),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
459 .
name =
"libzvbi_teletextdec",
468 .priv_class= &teletext_class,
static void fix_transparency(TeletextContext *ctx, vbi_page *page, int chop_top, uint8_t transparent_color, int resx, int resy)
int x
top left corner of pict, undefined when pict is not set
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
#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
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int chop_spaces_utf8(const unsigned char *t, int len)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int w
width of pict, undefined when pict is not set
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const char * name
Name of the codec implementation.
static void handler(vbi_event *ev, void *user_data)
#define AV_LOG_VERBOSE
Detailed information.
int h
height of pict, undefined when pict is not set
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
const OptionDef options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
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
static int gen_sub_text(TeletextContext *ctx, vbi_page *page, int chop_top)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Libavcodec external API header.
uint32_t end_display_time
AVCodec ff_libzvbi_teletext_decoder
A bitmap, pict will be set.
AVPicture pict
data+linesize for the bitmap of this subtitle.
AVSubtitleRect * sub_rect
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void teletext_flush(AVCodecContext *avctx)
static void flush(AVCodecContext *avctx)
static int teletext_close_decoder(AVCodecContext *avctx)
Plain text, the text field must be set by the decoder and is authoritative.
main external API structure.
static void close(AVCodecParserContext *s)
#define AVERROR_OPTION_NOT_FOUND
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)
static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
static int gen_sub_bitmap(TeletextContext *ctx, vbi_page *page, int chop_top)
static const AVClass teletext_class
uint32_t start_display_time
#define AVERROR_INVALIDDATA
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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-> out
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
char * text
0 terminated plain UTF-8 text
8 bit with PIX_FMT_RGB32 palette
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...