FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
libzvbi-teletextdec.c
Go to the documentation of this file.
1 /*
2  * Teletext decoding for ffmpeg
3  * Copyright (c) 2005-2010, 2012 Wolfram Gloger
4  * Copyright (c) 2013 Marton Balint
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "avcodec.h"
22 #include "libavcodec/ass.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/bprint.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/intreadwrite.h"
27 #include "libavutil/log.h"
28 
29 #include <libzvbi.h>
30 
31 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
32 #define VBI_NB_COLORS 40
33 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
34 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
35 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
36 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
37 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
38 #define MAX_BUFFERED_PAGES 25
39 #define BITMAP_CHAR_WIDTH 12
40 #define BITMAP_CHAR_HEIGHT 10
41 #define MAX_SLICES 64
42 
43 typedef struct TeletextPage
44 {
46  int pgno;
47  int subno;
48  int64_t pts;
49 } TeletextPage;
50 
51 typedef struct TeletextContext
52 {
53  AVClass *class;
54  char *pgno;
55  int x_offset;
56  int y_offset;
57  int format_id; /* 0 = bitmap, 1 = text/ass */
58  int chop_top;
59  int sub_duration; /* in msec */
62 
65  int nb_pages;
66  int64_t pts;
68 
69  vbi_decoder * vbi;
70 #ifdef DEBUG
71  vbi_export * ex;
72 #endif
73  vbi_sliced sliced[MAX_SLICES];
75 
76 static int chop_spaces_utf8(const unsigned char* t, int len)
77 {
78  t += len;
79  while (len > 0) {
80  if (*--t != ' ' || (len-1 > 0 && *(t-1) & 0x80))
81  break;
82  --len;
83  }
84  return len;
85 }
86 
87 static void subtitle_rect_free(AVSubtitleRect **sub_rect)
88 {
89  av_freep(&(*sub_rect)->pict.data[0]);
90  av_freep(&(*sub_rect)->pict.data[1]);
91  av_freep(&(*sub_rect)->ass);
92  av_freep(sub_rect);
93 }
94 
95 static int create_ass_text(TeletextContext *ctx, const char *text, char **ass)
96 {
97  int ret;
98  AVBPrint buf, buf2;
99  const int ts_start = av_rescale_q(ctx->pts, AV_TIME_BASE_Q, (AVRational){1, 100});
100  const int ts_duration = av_rescale_q(ctx->sub_duration, (AVRational){1, 1000}, (AVRational){1, 100});
101 
102  /* First we escape the plain text into buf. */
104  ff_ass_bprint_text_event(&buf, text, strlen(text), "", 0);
105  av_bprintf(&buf, "\r\n");
106 
107  if (!av_bprint_is_complete(&buf)) {
109  return AVERROR(ENOMEM);
110  }
111 
112  /* Then we create the ass dialog line in buf2 from the escaped text in buf. */
114  ff_ass_bprint_dialog(&buf2, buf.str, ts_start, ts_duration, 0);
116 
117  if (!av_bprint_is_complete(&buf2)) {
118  av_bprint_finalize(&buf2, NULL);
119  return AVERROR(ENOMEM);
120  }
121 
122  if ((ret = av_bprint_finalize(&buf2, ass)) < 0)
123  return ret;
124 
125  return 0;
126 }
127 
128 /* Draw a page as text */
129 static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
130 {
131  const char *in;
132  AVBPrint buf;
133  char *vbi_text = av_malloc(TEXT_MAXSZ);
134  int sz;
135 
136  if (!vbi_text)
137  return AVERROR(ENOMEM);
138 
139  sz = vbi_print_page_region(page, vbi_text, TEXT_MAXSZ-1, "UTF-8",
140  /*table mode*/ TRUE, FALSE,
141  0, chop_top,
142  page->columns, page->rows-chop_top);
143  if (sz <= 0) {
144  av_log(ctx, AV_LOG_ERROR, "vbi_print error\n");
145  av_free(vbi_text);
146  return AVERROR_EXTERNAL;
147  }
148  vbi_text[sz] = '\0';
149  in = vbi_text;
150  av_bprint_init(&buf, 0, TEXT_MAXSZ);
151 
152  if (ctx->chop_spaces) {
153  for (;;) {
154  int nl, sz;
155 
156  // skip leading spaces and newlines
157  in += strspn(in, " \n");
158  // compute end of row
159  for (nl = 0; in[nl]; ++nl)
160  if (in[nl] == '\n' && (nl==0 || !(in[nl-1] & 0x80)))
161  break;
162  if (!in[nl])
163  break;
164  // skip trailing spaces
165  sz = chop_spaces_utf8(in, nl);
166  av_bprint_append_data(&buf, in, sz);
167  av_bprintf(&buf, "\n");
168  in += nl;
169  }
170  } else {
171  av_bprintf(&buf, "%s\n", vbi_text);
172  }
173  av_free(vbi_text);
174 
175  if (!av_bprint_is_complete(&buf)) {
176  av_bprint_finalize(&buf, NULL);
177  return AVERROR(ENOMEM);
178  }
179 
180  if (buf.len) {
181  int ret;
182  sub_rect->type = SUBTITLE_ASS;
183  if ((ret = create_ass_text(ctx, buf.str, &sub_rect->ass)) < 0) {
184  av_bprint_finalize(&buf, NULL);
185  return ret;
186  }
187  av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
188  } else {
189  sub_rect->type = SUBTITLE_NONE;
190  }
191  av_bprint_finalize(&buf, NULL);
192  return 0;
193 }
194 
195 static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page,
196  int chop_top, uint8_t transparent_color, int resx, int resy)
197 {
198  int iy;
199 
200  // Hack for transparency, inspired by VLC code...
201  for (iy = 0; iy < resy; iy++) {
202  uint8_t *pixel = sub_rect->pict.data[0] + iy * sub_rect->pict.linesize[0];
203  vbi_char *vc = page->text + (iy / BITMAP_CHAR_HEIGHT + chop_top) * page->columns;
204  vbi_char *vcnext = vc + page->columns;
205  for (; vc < vcnext; vc++) {
206  uint8_t *pixelnext = pixel + BITMAP_CHAR_WIDTH;
207  switch (vc->opacity) {
208  case VBI_TRANSPARENT_SPACE:
209  memset(pixel, transparent_color, BITMAP_CHAR_WIDTH);
210  break;
211  case VBI_OPAQUE:
212  case VBI_SEMI_TRANSPARENT:
213  if (!ctx->transparent_bg)
214  break;
215  case VBI_TRANSPARENT_FULL:
216  for(; pixel < pixelnext; pixel++)
217  if (*pixel == vc->background)
218  *pixel = transparent_color;
219  break;
220  }
221  pixel = pixelnext;
222  }
223  }
224 }
225 
226 /* Draw a page as bitmap */
227 static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
228 {
229  int resx = page->columns * BITMAP_CHAR_WIDTH;
230  int resy = (page->rows - chop_top) * BITMAP_CHAR_HEIGHT;
231  uint8_t ci, cmax = 0;
232  int ret;
233  vbi_char *vc = page->text + (chop_top * page->columns);
234  vbi_char *vcend = page->text + (page->rows * page->columns);
235 
236  for (; vc < vcend; vc++) {
237  if (vc->opacity != VBI_TRANSPARENT_SPACE) {
238  cmax = VBI_NB_COLORS;
239  break;
240  }
241  }
242 
243  if (cmax == 0) {
244  av_log(ctx, AV_LOG_DEBUG, "dropping empty page %3x\n", page->pgno);
245  sub_rect->type = SUBTITLE_NONE;
246  return 0;
247  }
248 
249  if ((ret = avpicture_alloc(&sub_rect->pict, AV_PIX_FMT_PAL8, resx, resy)) < 0)
250  return ret;
251  // Yes, we want to allocate the palette on our own because AVSubtitle works this way
252  sub_rect->pict.data[1] = NULL;
253 
254  vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
255  sub_rect->pict.data[0], sub_rect->pict.linesize[0],
256  0, chop_top, page->columns, page->rows - chop_top,
257  /*reveal*/ 1, /*flash*/ 1);
258 
259  fix_transparency(ctx, sub_rect, page, chop_top, cmax, resx, resy);
260  sub_rect->x = ctx->x_offset;
261  sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT;
262  sub_rect->w = resx;
263  sub_rect->h = resy;
264  sub_rect->nb_colors = (int)cmax + 1;
265  sub_rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
266  if (!sub_rect->pict.data[1]) {
267  av_freep(&sub_rect->pict.data[0]);
268  return AVERROR(ENOMEM);
269  }
270  for (ci = 0; ci < cmax; ci++) {
271  int r, g, b, a;
272 
273  r = VBI_R(page->color_map[ci]);
274  g = VBI_G(page->color_map[ci]);
275  b = VBI_B(page->color_map[ci]);
276  a = VBI_A(page->color_map[ci]);
277  ((uint32_t *)sub_rect->pict.data[1])[ci] = RGBA(r, g, b, a);
278  ff_dlog(ctx, "palette %0x\n", ((uint32_t *)sub_rect->pict.data[1])[ci]);
279  }
280  ((uint32_t *)sub_rect->pict.data[1])[cmax] = RGBA(0, 0, 0, 0);
281  sub_rect->type = SUBTITLE_BITMAP;
282  return 0;
283 }
284 
285 static void handler(vbi_event *ev, void *user_data)
286 {
287  TeletextContext *ctx = user_data;
288  TeletextPage *new_pages;
289  vbi_page page;
290  int res;
291  char pgno_str[12];
292  vbi_subno subno;
293  vbi_page_type vpt;
294  int chop_top;
295  char *lang;
296 
297  snprintf(pgno_str, sizeof pgno_str, "%03x", ev->ev.ttx_page.pgno);
298  av_log(ctx, AV_LOG_DEBUG, "decoded page %s.%02x\n",
299  pgno_str, ev->ev.ttx_page.subno & 0xFF);
300 
301  if (strcmp(ctx->pgno, "*") && !strstr(ctx->pgno, pgno_str))
302  return;
303  if (ctx->handler_ret < 0)
304  return;
305 
306  res = vbi_fetch_vt_page(ctx->vbi, &page,
307  ev->ev.ttx_page.pgno,
308  ev->ev.ttx_page.subno,
309  VBI_WST_LEVEL_3p5, 25, TRUE);
310 
311  if (!res)
312  return;
313 
314 #ifdef DEBUG
315  fprintf(stderr, "\nSaving res=%d dy0=%d dy1=%d...\n",
316  res, page.dirty.y0, page.dirty.y1);
317  fflush(stderr);
318 
319  if (!vbi_export_stdio(ctx->ex, stderr, &page))
320  fprintf(stderr, "failed: %s\n", vbi_export_errstr(ctx->ex));
321 #endif
322 
323  vpt = vbi_classify_page(ctx->vbi, ev->ev.ttx_page.pgno, &subno, &lang);
324  chop_top = ctx->chop_top ||
325  ((page.rows > 1) && (vpt == VBI_SUBTITLE_PAGE));
326 
327  av_log(ctx, AV_LOG_DEBUG, "%d x %d page chop:%d\n",
328  page.columns, page.rows, chop_top);
329 
330  if (ctx->nb_pages < MAX_BUFFERED_PAGES) {
331  if ((new_pages = av_realloc_array(ctx->pages, ctx->nb_pages + 1, sizeof(TeletextPage)))) {
332  TeletextPage *cur_page = new_pages + ctx->nb_pages;
333  ctx->pages = new_pages;
334  cur_page->sub_rect = av_mallocz(sizeof(*cur_page->sub_rect));
335  cur_page->pts = ctx->pts;
336  cur_page->pgno = ev->ev.ttx_page.pgno;
337  cur_page->subno = ev->ev.ttx_page.subno;
338  if (cur_page->sub_rect) {
339  res = (ctx->format_id == 0) ?
340  gen_sub_bitmap(ctx, cur_page->sub_rect, &page, chop_top) :
341  gen_sub_text (ctx, cur_page->sub_rect, &page, chop_top);
342  if (res < 0) {
343  av_freep(&cur_page->sub_rect);
344  ctx->handler_ret = res;
345  } else {
346  ctx->pages[ctx->nb_pages++] = *cur_page;
347  }
348  } else {
349  ctx->handler_ret = AVERROR(ENOMEM);
350  }
351  } else {
352  ctx->handler_ret = AVERROR(ENOMEM);
353  }
354  } else {
355  //TODO: If multiple packets contain more than one page, pages may got queued up, and this may happen...
356  av_log(ctx, AV_LOG_ERROR, "Buffered too many pages, dropping page %s.\n", pgno_str);
357  ctx->handler_ret = AVERROR(ENOSYS);
358  }
359 
360  vbi_unref_page(&page);
361 }
362 
363 static inline int data_identifier_is_teletext(int data_identifier) {
364  /* See EN 301 775 section 4.4.2. */
365  return (data_identifier >= 0x10 && data_identifier <= 0x1F ||
366  data_identifier >= 0x99 && data_identifier <= 0x9B);
367 }
368 
370 {
371  int lines = 0;
372  while (size >= 2 && lines < MAX_SLICES) {
373  int data_unit_id = buf[0];
374  int data_unit_length = buf[1];
375  if (data_unit_length + 2 > size)
376  return AVERROR_INVALIDDATA;
377  if (data_unit_id == 0x02 || data_unit_id == 0x03) {
378  if (data_unit_length != 0x2c)
379  return AVERROR_INVALIDDATA;
380  else {
381  int line_offset = buf[2] & 0x1f;
382  int field_parity = buf[2] & 0x20;
383  int i;
384  ctx->sliced[lines].id = VBI_SLICED_TELETEXT_B;
385  ctx->sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
386  for (i = 0; i < 42; i++)
387  ctx->sliced[lines].data[i] = vbi_rev8(buf[4 + i]);
388  lines++;
389  }
390  }
391  size -= data_unit_length + 2;
392  buf += data_unit_length + 2;
393  }
394  if (size)
395  av_log(ctx, AV_LOG_WARNING, "%d bytes remained after slicing data\n", size);
396  return lines;
397 }
398 
399 static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
400 {
401  TeletextContext *ctx = avctx->priv_data;
402  AVSubtitle *sub = data;
403  int ret = 0;
404 
405  if (!ctx->vbi) {
406  if (!(ctx->vbi = vbi_decoder_new()))
407  return AVERROR(ENOMEM);
408  if (!vbi_event_handler_add(ctx->vbi, VBI_EVENT_TTX_PAGE, handler, ctx)) {
409  vbi_decoder_delete(ctx->vbi);
410  ctx->vbi = NULL;
411  return AVERROR(ENOMEM);
412  }
413  }
414 
415  if (avctx->pkt_timebase.den && pkt->pts != AV_NOPTS_VALUE)
416  ctx->pts = av_rescale_q(pkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
417 
418  if (pkt->size) {
419  int lines;
420  const int full_pes_size = pkt->size + 45; /* PES header is 45 bytes */
421 
422  // We allow unreasonably big packets, even if the standard only allows a max size of 1472
423  if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
424  return AVERROR_INVALIDDATA;
425 
426  ctx->handler_ret = pkt->size;
427 
428  if (data_identifier_is_teletext(*pkt->data)) {
429  if ((lines = slice_to_vbi_lines(ctx, pkt->data + 1, pkt->size - 1)) < 0)
430  return lines;
431  ff_dlog(avctx, "ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
432  ctx, pkt->size, lines, (double)pkt->pts/90000.0);
433  if (lines > 0) {
434 #ifdef DEBUG
435  int i;
436  av_log(avctx, AV_LOG_DEBUG, "line numbers:");
437  for(i = 0; i < lines; i++)
438  av_log(avctx, AV_LOG_DEBUG, " %d", ctx->sliced[i].line);
439  av_log(avctx, AV_LOG_DEBUG, "\n");
440 #endif
441  vbi_decode(ctx->vbi, ctx->sliced, lines, 0.0);
442  ctx->lines_processed += lines;
443  }
444  }
445  ctx->pts = AV_NOPTS_VALUE;
446  ret = ctx->handler_ret;
447  }
448 
449  if (ret < 0)
450  return ret;
451 
452  // is there a subtitle to pass?
453  if (ctx->nb_pages) {
454  int i;
455  sub->format = ctx->format_id;
456  sub->start_display_time = 0;
457  sub->end_display_time = ctx->sub_duration;
458  sub->num_rects = 0;
459  sub->pts = ctx->pages->pts;
460 
461  if (ctx->pages->sub_rect->type != SUBTITLE_NONE) {
462  sub->rects = av_malloc(sizeof(*sub->rects));
463  if (sub->rects) {
464  sub->num_rects = 1;
465  sub->rects[0] = ctx->pages->sub_rect;
466  } else {
467  ret = AVERROR(ENOMEM);
468  }
469  } else {
470  av_log(avctx, AV_LOG_DEBUG, "sending empty sub\n");
471  sub->rects = NULL;
472  }
473  if (!sub->rects) // no rect was passed
475 
476  for (i = 0; i < ctx->nb_pages - 1; i++)
477  ctx->pages[i] = ctx->pages[i + 1];
478  ctx->nb_pages--;
479 
480  if (ret >= 0)
481  *data_size = 1;
482  } else
483  *data_size = 0;
484 
485  return ret;
486 }
487 
489 {
490  TeletextContext *ctx = avctx->priv_data;
491  unsigned int maj, min, rev;
492 
493  vbi_version(&maj, &min, &rev);
494  if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
495  av_log(avctx, AV_LOG_ERROR, "decoder needs zvbi version >= 0.2.26.\n");
496  return AVERROR_EXTERNAL;
497  }
498 
499  if (ctx->format_id == 0) {
500  avctx->width = 41 * BITMAP_CHAR_WIDTH;
501  avctx->height = 25 * BITMAP_CHAR_HEIGHT;
502  }
503 
504  ctx->vbi = NULL;
505  ctx->pts = AV_NOPTS_VALUE;
506 
507 #ifdef DEBUG
508  {
509  char *t;
510  ctx->ex = vbi_export_new("text", &t);
511  }
512 #endif
513  av_log(avctx, AV_LOG_VERBOSE, "page filter: %s\n", ctx->pgno);
514  return (ctx->format_id == 1) ? ff_ass_subtitle_header_default(avctx) : 0;
515 }
516 
518 {
519  TeletextContext *ctx = avctx->priv_data;
520 
521  ff_dlog(avctx, "lines_total=%u\n", ctx->lines_processed);
522  while (ctx->nb_pages)
523  subtitle_rect_free(&ctx->pages[--ctx->nb_pages].sub_rect);
524  av_freep(&ctx->pages);
525 
526  vbi_decoder_delete(ctx->vbi);
527  ctx->vbi = NULL;
528  ctx->pts = AV_NOPTS_VALUE;
529  return 0;
530 }
531 
532 static void teletext_flush(AVCodecContext *avctx)
533 {
534  teletext_close_decoder(avctx);
535 }
536 
537 #define OFFSET(x) offsetof(TeletextContext, x)
538 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
539 static const AVOption options[] = {
540  {"txt_page", "list of teletext page numbers to decode, * is all", OFFSET(pgno), AV_OPT_TYPE_STRING, {.str = "*"}, 0, 0, SD},
541  {"txt_chop_top", "discards the top teletext line", OFFSET(chop_top), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
542  {"txt_format", "format of the subtitles (bitmap or text)", OFFSET(format_id), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD, "txt_format"},
543  {"bitmap", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, SD, "txt_format"},
544  {"text", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, SD, "txt_format"},
545  {"txt_left", "x offset of generated bitmaps", OFFSET(x_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
546  {"txt_top", "y offset of generated bitmaps", OFFSET(y_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
547  {"txt_chop_spaces", "chops leading and trailing spaces from text", OFFSET(chop_spaces), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
548  {"txt_duration", "display duration of teletext pages in msecs", OFFSET(sub_duration), AV_OPT_TYPE_INT, {.i64 = 30000}, 0, 86400000, SD},
549  {"txt_transparent", "force transparent background of the teletext", OFFSET(transparent_bg), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD},
550  { NULL },
551 };
552 
553 static const AVClass teletext_class = {
554  .class_name = "libzvbi_teletextdec",
555  .item_name = av_default_item_name,
556  .option = options,
557  .version = LIBAVUTIL_VERSION_INT,
558 };
559 
561  .name = "libzvbi_teletextdec",
562  .long_name = NULL_IF_CONFIG_SMALL("Libzvbi DVB teletext decoder"),
563  .type = AVMEDIA_TYPE_SUBTITLE,
565  .priv_data_size = sizeof(TeletextContext),
567  .close = teletext_close_decoder,
569  .capabilities = AV_CODEC_CAP_DELAY,
571  .priv_class= &teletext_class,
572 };
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.
Definition: ass.c:106
#define NULL
Definition: coverity.c:32
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.
Definition: error.h:59
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3746
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3774
AVOption.
Definition: opt.h:255
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define VBI_NB_COLORS
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
const char * g
Definition: vf_curves.c:108
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define VBI_A(rgba)
#define TEXT_MAXSZ
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:3778
int size
Definition: avcodec.h:1424
const char * b
Definition: vf_curves.c:109
vbi_sliced sliced[MAX_SLICES]
static int chop_spaces_utf8(const unsigned char *t, int len)
unsigned num_rects
Definition: avcodec.h:3803
#define OFFSET(x)
static AVPacket pkt
AVCodec.
Definition: avcodec.h:3472
#define MAX_SLICES
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.
Definition: bprint.c:235
AVSubtitleRect ** rects
Definition: avcodec.h:3804
static int slice_to_vbi_lines(TeletextContext *ctx, uint8_t *buf, int size)
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:3776
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:882
uint8_t
#define av_malloc(s)
8 bit with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:74
AVOptions.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
Definition: avcodec.h:3745
#define AVPALETTE_SIZE
Definition: pixfmt.h:33
int ff_ass_subtitle_header_default(AVCodecContext *avctx)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS with default style.
Definition: ass.c:80
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.
Definition: bprint.c:158
uint8_t * data
Definition: avcodec.h:1423
#define ff_dlog(a,...)
#define BITMAP_CHAR_HEIGHT
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
ptrdiff_t size
Definition: opengl_enc.c:101
#define MAX_BUFFERED_PAGES
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:3777
#define av_log(a,...)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:3318
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_BPRINT_SIZE_UNLIMITED
#define SD
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:3775
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define FALSE
Definition: windows2linux.h:37
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
AVS_Value void * user_data
Definition: avisynth_c.h:562
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
const char * name
Name of the codec implementation.
Definition: avcodec.h:3479
#define VBI_G(rgba)
Libavcodec external API header.
#define BITMAP_CHAR_WIDTH
uint32_t end_display_time
Definition: avcodec.h:3802
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:3805
AVCodec ff_libzvbi_teletext_decoder
common internal API header
A bitmap, pict will be set.
Definition: avcodec.h:3756
#define VBI_B(rgba)
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3784
int width
picture width / height.
Definition: avcodec.h:1681
#define TRUE
Definition: windows2linux.h:33
uint16_t format
Definition: avcodec.h:3800
static void teletext_flush(AVCodecContext *avctx)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
#define RGBA(r, g, b, a)
#define VBI_R(rgba)
static int teletext_close_decoder(AVCodecContext *avctx)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:252
static const AVOption options[]
main external API structure.
Definition: avcodec.h:1502
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
void * buf
Definition: avisynth_c.h:553
Describe the class of an AVClass context structure.
Definition: log.h:67
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.
Definition: avpicture.c:54
static int teletext_init_decoder(AVCodecContext *avctx)
rational number numerator/denominator
Definition: rational.h:43
#define snprintf
Definition: snprintf.h:34
static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
uint8_t pixel
Definition: tiny_ssim.c:42
static const AVClass teletext_class
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:523
static int data_identifier_is_teletext(int data_identifier)
if(ret< 0)
Definition: vf_mcdeint.c:280
uint32_t start_display_time
Definition: avcodec.h:3801
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:208
int den
denominator
Definition: rational.h:45
TeletextPage * pages
static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
void * priv_data
Definition: avcodec.h:1544
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition: avcodec.h:3768
#define av_free(p)
int len
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.
Definition: ass.c:187
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3794
static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top, uint8_t transparent_color, int resx, int resy)
#define av_freep(p)
static void subtitle_rect_free(AVSubtitleRect **sub_rect)
enum AVSubtitleType type
Definition: avcodec.h:3785
float min
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
This structure stores compressed data.
Definition: avcodec.h:1400
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1416
AVSubtitleRect * sub_rect
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240