FFmpeg
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 "codec_internal.h"
24 #include "libavcodec/dvbtxt.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/log.h"
30 #include "libavutil/common.h"
31 
32 #include <libzvbi.h>
33 
34 #define TEXT_MAXSZ (25 * (56 + 1) * 4 + 2)
35 #define VBI_NB_COLORS 40
36 #define VBI_TRANSPARENT_BLACK 8
37 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
38 #define VBI_R(rgba) (((rgba) >> 0) & 0xFF)
39 #define VBI_G(rgba) (((rgba) >> 8) & 0xFF)
40 #define VBI_B(rgba) (((rgba) >> 16) & 0xFF)
41 #define VBI_A(rgba) (((rgba) >> 24) & 0xFF)
42 #define MAX_BUFFERED_PAGES 25
43 #define BITMAP_CHAR_WIDTH 12
44 #define BITMAP_CHAR_HEIGHT 10
45 #define MAX_SLICES 64
46 
47 typedef struct TeletextPage
48 {
50  int pgno;
51  int subno;
53 } TeletextPage;
54 
55 typedef struct TeletextContext
56 {
57  AVClass *class;
58  char *pgno;
60  int x_offset;
61  int y_offset;
62  int format_id; /* 0 = bitmap, 1 = text/ass, 2 = ass */
63  int chop_top;
64  int sub_duration; /* in msec */
66  int opacity;
68 
71  int nb_pages;
74 
75  vbi_decoder * vbi;
76  vbi_sliced sliced[MAX_SLICES];
77 
78  int readorder;
79  uint8_t subtitle_map[2048];
80  int last_pgno;
81  int last_p5;
84 
86 {
88  char *new_header;
89  uint8_t *event_pos;
90 
91  if (ret < 0)
92  return ret;
93 
94  event_pos = strstr(avctx->subtitle_header, "\r\n[Events]\r\n");
95  if (!event_pos)
96  return AVERROR_BUG;
97 
98  new_header = av_asprintf("%.*s%s%s",
99  (int)(event_pos - avctx->subtitle_header), avctx->subtitle_header,
100  "Style: "
101  "Teletext," /* Name */
102  "Monospace,11," /* Font{name,size} */
103  "&Hffffff,&Hffffff,&H0,&H0," /* {Primary,Secondary,Outline,Back}Colour */
104  "0,0,0,0," /* Bold, Italic, Underline, StrikeOut */
105  "160,100," /* Scale{X,Y} */
106  "0,0," /* Spacing, Angle */
107  "3,0.1,0," /* BorderStyle, Outline, Shadow */
108  "5,1,1,1," /* Alignment, Margin[LRV] */
109  "0\r\n" /* Encoding */
110  "Style: "
111  "Subtitle," /* Name */
112  "Monospace,16," /* Font{name,size} */
113  "&Hffffff,&Hffffff,&H0,&H0," /* {Primary,Secondary,Outline,Back}Colour */
114  "0,0,0,0," /* Bold, Italic, Underline, StrikeOut */
115  "100,100," /* Scale{X,Y} */
116  "0,0," /* Spacing, Angle */
117  "1,1,1," /* BorderStyle, Outline, Shadow */
118  "8,48,48,20," /* Alignment, Margin[LRV] */
119  "0\r\n" /* Encoding */
120  , event_pos);
121 
122  if (!new_header)
123  return AVERROR(ENOMEM);
124 
125  av_free(avctx->subtitle_header);
126  avctx->subtitle_header = new_header;
127  avctx->subtitle_header_size = strlen(new_header);
128  return 0;
129 }
130 
131 static int chop_spaces_utf8(const unsigned char* t, int len)
132 {
133  t += len;
134  while (len > 0) {
135  if (*--t != ' ' || (len-1 > 0 && *(t-1) & 0x80))
136  break;
137  --len;
138  }
139  return len;
140 }
141 
142 static void subtitle_rect_free(AVSubtitleRect **sub_rect)
143 {
144  av_freep(&(*sub_rect)->data[0]);
145  av_freep(&(*sub_rect)->data[1]);
146  av_freep(&(*sub_rect)->ass);
147  av_freep(sub_rect);
148 }
149 
150 static char *create_ass_text(TeletextContext *ctx, const char *text)
151 {
152  char *dialog;
153  AVBPrint buf;
154 
156  ff_ass_bprint_text_event(&buf, text, strlen(text), "", 0);
157  if (!av_bprint_is_complete(&buf)) {
158  av_bprint_finalize(&buf, NULL);
159  return NULL;
160  }
161  dialog = ff_ass_get_dialog(ctx->readorder++, 0, NULL, NULL, buf.str);
162  av_bprint_finalize(&buf, NULL);
163  return dialog;
164 }
165 
166 /* Draw a page as text */
167 static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
168 {
169  const char *in;
170  AVBPrint buf;
171  char *vbi_text = av_malloc(TEXT_MAXSZ);
172  int sz;
173 
174  if (!vbi_text)
175  return AVERROR(ENOMEM);
176 
177  sz = vbi_print_page_region(page, vbi_text, TEXT_MAXSZ-1, "UTF-8",
178  /*table mode*/ TRUE, FALSE,
179  0, chop_top,
180  page->columns, page->rows-chop_top);
181  if (sz <= 0) {
182  av_log(ctx, AV_LOG_ERROR, "vbi_print error\n");
183  av_free(vbi_text);
184  return AVERROR_EXTERNAL;
185  }
186  vbi_text[sz] = '\0';
187  in = vbi_text;
188  av_bprint_init(&buf, 0, TEXT_MAXSZ);
189 
190  if (ctx->chop_spaces) {
191  for (;;) {
192  int nl, sz;
193 
194  // skip leading spaces and newlines
195  in += strspn(in, " \n");
196  // compute end of row
197  for (nl = 0; in[nl]; ++nl)
198  if (in[nl] == '\n' && (nl==0 || !(in[nl-1] & 0x80)))
199  break;
200  if (!in[nl])
201  break;
202  // skip trailing spaces
203  sz = chop_spaces_utf8(in, nl);
204  av_bprint_append_data(&buf, in, sz);
205  av_bprintf(&buf, "\n");
206  in += nl;
207  }
208  } else {
209  av_bprintf(&buf, "%s\n", vbi_text);
210  }
211  av_free(vbi_text);
212 
213  if (!av_bprint_is_complete(&buf)) {
214  av_bprint_finalize(&buf, NULL);
215  return AVERROR(ENOMEM);
216  }
217 
218  if (buf.len) {
219  sub_rect->type = SUBTITLE_ASS;
220  sub_rect->ass = create_ass_text(ctx, buf.str);
221 
222  if (!sub_rect->ass) {
223  av_bprint_finalize(&buf, NULL);
224  return AVERROR(ENOMEM);
225  }
226  av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
227  } else {
228  sub_rect->type = SUBTITLE_NONE;
229  }
230  av_bprint_finalize(&buf, NULL);
231  return 0;
232 }
233 
234 static void bprint_color(const char *type, AVBPrint *buf, vbi_page *page, unsigned ci)
235 {
236  int r = VBI_R(page->color_map[ci]);
237  int g = VBI_G(page->color_map[ci]);
238  int b = VBI_B(page->color_map[ci]);
239  av_bprintf(buf, "{\\%s&H%02X%02X%02X&}", type, b, g, r);
240 }
241 
242 #define IS_TXT_SPACE(ch) ((ch).unicode < 0x0020 || (ch).unicode >= 0xe000 || (ch).unicode == 0x00a0 ||\
243  (ch).size > VBI_DOUBLE_SIZE || (ch).opacity == VBI_TRANSPARENT_SPACE)
244 
245 static void get_trim_info(vbi_page *page, vbi_char *row, int *leading, int *trailing, int *olen)
246 {
247  int i, len = 0;
248  int char_seen = 0;
249 
250  *leading = 0;
251 
252  for (i = 0; i < page->columns; i++) {
253  uint16_t out = IS_TXT_SPACE(row[i]) ? 32 : row[i].unicode;
254 
255  if (out == 32 && !char_seen)
256  (*leading)++;
257  else if (out != 32)
258  char_seen = 1, len = i - (*leading) + 1;
259  }
260 
261  *olen = len;
262  *trailing = len > 0 ? page->columns - *leading - len : page->columns;
263 }
264 
265 static void decode_string(vbi_page *page, vbi_char *row, AVBPrint *buf,
266  int start, int end, vbi_color *cur_color, vbi_color *cur_back_color)
267 {
268  int i;
269 
270  for (i = start; i < end; i++) {
271  uint16_t out = IS_TXT_SPACE(row[i]) ? 32 : row[i].unicode;
272 
273  if (*cur_color != row[i].foreground) {
274  bprint_color("c", buf, page, row[i].foreground);
275  *cur_color = row[i].foreground;
276  }
277  if (*cur_back_color != row[i].background) {
278  bprint_color("3c", buf, page, row[i].background);
279  *cur_back_color = row[i].background;
280  }
281 
282  if (out == 32) {
283  av_bprintf(buf, "\\h");
284  } else if (out == '\\' || out == '{' || out == '}') {
285  av_bprintf(buf, "\\%c", (char)out);
286  } else {
287  char tmp;
288  /* convert to utf-8 */
289  PUT_UTF8(out, tmp, av_bprint_chars(buf, tmp, 1););
290  }
291  }
292 }
293 
294 /* Draw a page as ass formatted text */
295 static int gen_sub_ass(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
296 {
297  int i;
298  int leading, trailing, len;
299  int last_trailing = -1, last_leading = -1;
300  int min_trailing = page->columns, min_leading = page->columns;
301  int alignment = 2;
302  int vertical_align = -1;
303  int can_align_left = 1, can_align_right = 1, can_align_center = 1;
304  int is_subtitle_page = ctx->subtitle_map[page->pgno & 0x7ff];
305  int empty_lines = 0;
306  vbi_color cur_color = VBI_WHITE;
307  vbi_color cur_back_color = VBI_BLACK;
308  AVBPrint buf;
309 
311 
312  for (i = chop_top; i < page->rows; i++) {
313  vbi_char *row = page->text + i * page->columns;
314 
315  get_trim_info(page, row, &leading, &trailing, &len);
316 
317  if (len) {
318  if (last_leading != -1 && last_leading != leading || leading > 5)
319  can_align_left = 0;
320  if (last_trailing != -1 && last_trailing != trailing || trailing > 2)
321  can_align_right = 0;
322  if (last_trailing != -1 && (FFABS((trailing - leading) - (last_trailing - last_leading)) > 1) || trailing - leading > 4)
323  can_align_center = 0;
324  last_leading = leading;
325  last_trailing = trailing;
326  min_leading = FFMIN(leading, min_leading);
327  min_trailing = FFMIN(trailing, min_trailing);
328  }
329  }
330 
331  if (!can_align_right && can_align_left && !can_align_center) {
332  ctx->last_ass_alignment = alignment = 1;
333  } else if (!can_align_right && !can_align_left && can_align_center) {
334  ctx->last_ass_alignment = alignment = 2;
335  } else if (can_align_right && !can_align_left && !can_align_center) {
336  ctx->last_ass_alignment = alignment = 3;
337  } else {
338  if (ctx->last_ass_alignment == 1 && can_align_left ||
339  ctx->last_ass_alignment == 2 && can_align_center ||
340  ctx->last_ass_alignment == 3 && can_align_right)
341  alignment = ctx->last_ass_alignment;
342  }
343 
344  for (i = chop_top; i < page->rows; i++) {
345  int j;
346  vbi_char *row = page->text + i * page->columns;
347  int is_transparent_line;
348 
349  for (j = 0; j < page->columns; j++)
350  if (row[j].opacity != VBI_TRANSPARENT_SPACE)
351  break;
352  is_transparent_line = (j == page->columns);
353 
354  len = is_transparent_line ? 0 : page->columns;
355  leading = trailing = is_transparent_line ? page->columns : 0;
356 
357  if (is_subtitle_page) {
358  if (!is_transparent_line)
359  get_trim_info(page, row, &leading, &trailing, &len);
360 
361  if (vertical_align == -1 && len) {
362  vertical_align = (2 - (av_clip(i + 1, 0, 23) / 8));
363  av_bprintf(&buf, "{\\an%d}", alignment + vertical_align * 3);
364  if (vertical_align != 2)
365  empty_lines = 0;
366  }
367 
368  if (len && empty_lines > 1)
369  for (empty_lines /= 2; empty_lines > 0; empty_lines--)
370  av_bprintf(&buf, " \\N");
371 
372  if (alignment == 1 || alignment == 2 && !can_align_center)
373  leading = min_leading;
374  if (alignment == 3 || alignment == 2 && !can_align_center)
375  trailing = min_trailing;
376  }
377 
378  if (len || !is_subtitle_page) {
379  decode_string(page, row, &buf, leading, page->columns - trailing, &cur_color, &cur_back_color);
380  av_bprintf(&buf, " \\N");
381  empty_lines = 0;
382  } else {
383  empty_lines++;
384  }
385  }
386 
387  if (vertical_align == 0)
388  for (empty_lines = (empty_lines - 1) / 2; empty_lines > 0; empty_lines--)
389  av_bprintf(&buf, " \\N");
390 
391  if (!av_bprint_is_complete(&buf)) {
392  av_bprint_finalize(&buf, NULL);
393  return AVERROR(ENOMEM);
394  }
395 
396  if (buf.len) {
397  sub_rect->type = SUBTITLE_ASS;
398  sub_rect->ass = ff_ass_get_dialog(ctx->readorder++, 0, is_subtitle_page ? "Subtitle" : "Teletext", NULL, buf.str);
399 
400  if (!sub_rect->ass) {
401  av_bprint_finalize(&buf, NULL);
402  return AVERROR(ENOMEM);
403  }
404  av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
405  } else {
406  sub_rect->type = SUBTITLE_NONE;
407  }
408  av_bprint_finalize(&buf, NULL);
409  return 0;
410 }
411 
412 static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page,
413  int chop_top, int resx, int resy)
414 {
415  int iy;
416 
417  // Hack for transparency, inspired by VLC code...
418  for (iy = 0; iy < resy; iy++) {
419  uint8_t *pixel = sub_rect->data[0] + iy * sub_rect->linesize[0];
420  vbi_char *vc = page->text + (iy / BITMAP_CHAR_HEIGHT + chop_top) * page->columns;
421  vbi_char *vcnext = vc + page->columns;
422  for (; vc < vcnext; vc++) {
423  uint8_t *pixelnext = pixel + BITMAP_CHAR_WIDTH;
424  switch (vc->opacity) {
425  case VBI_TRANSPARENT_SPACE:
427  break;
428  case VBI_OPAQUE:
429  if (!ctx->transparent_bg)
430  break;
431  case VBI_SEMI_TRANSPARENT:
432  if (ctx->opacity > 0) {
433  if (ctx->opacity < 255)
434  for(; pixel < pixelnext; pixel++)
435  if (*pixel == vc->background)
436  *pixel += VBI_NB_COLORS;
437  break;
438  }
439  case VBI_TRANSPARENT_FULL:
440  for(; pixel < pixelnext; pixel++)
441  if (*pixel == vc->background)
443  break;
444  }
445  pixel = pixelnext;
446  }
447  }
448 }
449 
450 /* Draw a page as bitmap */
451 static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
452 {
453  int resx = page->columns * BITMAP_CHAR_WIDTH;
454  int resy = (page->rows - chop_top) * BITMAP_CHAR_HEIGHT;
455  uint8_t ci;
456  vbi_char *vc = page->text + (chop_top * page->columns);
457  vbi_char *vcend = page->text + (page->rows * page->columns);
458 
459  for (; vc < vcend; vc++) {
460  if (vc->opacity != VBI_TRANSPARENT_SPACE)
461  break;
462  }
463 
464  if (vc >= vcend) {
465  av_log(ctx, AV_LOG_DEBUG, "dropping empty page %3x\n", page->pgno);
466  sub_rect->type = SUBTITLE_NONE;
467  return 0;
468  }
469 
470  sub_rect->data[0] = av_mallocz(resx * resy);
471  sub_rect->linesize[0] = resx;
472  if (!sub_rect->data[0])
473  return AVERROR(ENOMEM);
474 
475  vbi_draw_vt_page_region(page, VBI_PIXFMT_PAL8,
476  sub_rect->data[0], sub_rect->linesize[0],
477  0, chop_top, page->columns, page->rows - chop_top,
478  /*reveal*/ 1, /*flash*/ 1);
479 
480  fix_transparency(ctx, sub_rect, page, chop_top, resx, resy);
481  sub_rect->x = ctx->x_offset;
482  sub_rect->y = ctx->y_offset + chop_top * BITMAP_CHAR_HEIGHT;
483  sub_rect->w = resx;
484  sub_rect->h = resy;
485  sub_rect->nb_colors = ctx->opacity > 0 && ctx->opacity < 255 ? 2 * VBI_NB_COLORS : VBI_NB_COLORS;
486  sub_rect->data[1] = av_mallocz(AVPALETTE_SIZE);
487  if (!sub_rect->data[1]) {
488  av_freep(&sub_rect->data[0]);
489  return AVERROR(ENOMEM);
490  }
491  for (ci = 0; ci < VBI_NB_COLORS; ci++) {
492  int r, g, b, a;
493 
494  r = VBI_R(page->color_map[ci]);
495  g = VBI_G(page->color_map[ci]);
496  b = VBI_B(page->color_map[ci]);
497  a = VBI_A(page->color_map[ci]);
498  ((uint32_t *)sub_rect->data[1])[ci] = RGBA(r, g, b, a);
499  ((uint32_t *)sub_rect->data[1])[ci + VBI_NB_COLORS] = RGBA(r, g, b, ctx->opacity);
500  ff_dlog(ctx, "palette %0x\n", ((uint32_t *)sub_rect->data[1])[ci]);
501  }
502  ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK] = RGBA(0, 0, 0, 0);
503  ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK + VBI_NB_COLORS] = RGBA(0, 0, 0, 0);
504  sub_rect->type = SUBTITLE_BITMAP;
505  return 0;
506 }
507 
508 static void handler(vbi_event *ev, void *user_data)
509 {
511  TeletextPage *new_pages;
512  vbi_page page;
513  int res;
514  char pgno_str[12];
515  int chop_top;
516  int is_subtitle_page = ctx->subtitle_map[ev->ev.ttx_page.pgno & 0x7ff];
517 
518  snprintf(pgno_str, sizeof pgno_str, "%03x", ev->ev.ttx_page.pgno);
519  av_log(ctx, AV_LOG_DEBUG, "decoded page %s.%02x\n",
520  pgno_str, ev->ev.ttx_page.subno & 0xFF);
521 
522  if (strcmp(ctx->pgno, "*") && (strcmp(ctx->pgno, "subtitle") || !is_subtitle_page) && !strstr(ctx->pgno, pgno_str))
523  return;
524  if (ctx->handler_ret < 0)
525  return;
526 
527  res = vbi_fetch_vt_page(ctx->vbi, &page,
528  ev->ev.ttx_page.pgno,
529  ev->ev.ttx_page.subno,
530  VBI_WST_LEVEL_3p5, 25, TRUE);
531 
532  if (!res)
533  return;
534 
535  chop_top = ctx->chop_top || ((page.rows > 1) && is_subtitle_page);
536 
537  av_log(ctx, AV_LOG_DEBUG, "%d x %d page chop:%d\n",
538  page.columns, page.rows, chop_top);
539 
540  if (ctx->nb_pages < MAX_BUFFERED_PAGES) {
541  if ((new_pages = av_realloc_array(ctx->pages, ctx->nb_pages + 1, sizeof(TeletextPage)))) {
542  TeletextPage *cur_page = new_pages + ctx->nb_pages;
543  ctx->pages = new_pages;
544  cur_page->sub_rect = av_mallocz(sizeof(*cur_page->sub_rect));
545  cur_page->pts = ctx->pts;
546  cur_page->pgno = ev->ev.ttx_page.pgno;
547  cur_page->subno = ev->ev.ttx_page.subno;
548  if (cur_page->sub_rect) {
549  switch (ctx->format_id) {
550  case 0:
551  res = gen_sub_bitmap(ctx, cur_page->sub_rect, &page, chop_top);
552  break;
553  case 1:
554  res = gen_sub_text(ctx, cur_page->sub_rect, &page, chop_top);
555  break;
556  case 2:
557  res = gen_sub_ass(ctx, cur_page->sub_rect, &page, chop_top);
558  break;
559  default:
560  res = AVERROR_BUG;
561  break;
562  }
563  if (res < 0) {
564  av_freep(&cur_page->sub_rect);
565  ctx->handler_ret = res;
566  } else {
567  ctx->pages[ctx->nb_pages++] = *cur_page;
568  }
569  } else {
570  ctx->handler_ret = AVERROR(ENOMEM);
571  }
572  } else {
573  ctx->handler_ret = AVERROR(ENOMEM);
574  }
575  } else {
576  //TODO: If multiple packets contain more than one page, pages may got queued up, and this may happen...
577  av_log(ctx, AV_LOG_ERROR, "Buffered too many pages, dropping page %s.\n", pgno_str);
578  ctx->handler_ret = AVERROR(ENOSYS);
579  }
580 
581  vbi_unref_page(&page);
582 }
583 
584 static int slice_to_vbi_lines(TeletextContext *ctx, const uint8_t *buf, int size)
585 {
586  int lines = 0;
587  while (size >= 2 && lines < MAX_SLICES) {
588  int data_unit_id = buf[0];
589  int data_unit_length = buf[1];
590  if (data_unit_length + 2 > size)
591  return AVERROR_INVALIDDATA;
592  if (ff_data_unit_id_is_teletext(data_unit_id)) {
593  if (data_unit_length != 0x2c)
594  return AVERROR_INVALIDDATA;
595  else {
596  int line_offset = buf[2] & 0x1f;
597  int field_parity = buf[2] & 0x20;
598  uint8_t *p = ctx->sliced[lines].data;
599  int i, pmag;
600  ctx->sliced[lines].id = VBI_SLICED_TELETEXT_B;
601  ctx->sliced[lines].line = (line_offset > 0 ? (line_offset + (field_parity ? 0 : 313)) : 0);
602  for (i = 0; i < 42; i++)
603  p[i] = vbi_rev8(buf[4 + i]);
604  /* Unfortunately libzvbi does not expose page flags, and
605  * vbi_classify_page only checks MIP, so we have to manually
606  * decode the page flags and store the results. */
607  pmag = vbi_unham16p(p);
608  if (pmag >= 0 && pmag >> 3 == 0) { // We found a row 0 header
609  int page = vbi_unham16p(p + 2);
610  int flags1 = vbi_unham16p(p + 6);
611  int flags2 = vbi_unham16p(p + 8);
612  if (page >= 0 && flags1 >= 0 && flags2 >= 0) {
613  int pgno = ((pmag & 7) << 8) + page;
614  // Check for disabled NEWSFLASH flag and enabled SUBTITLE and SUPRESS_HEADER flags
615  ctx->subtitle_map[pgno] = (!(flags1 & 0x40) && flags1 & 0x80 && flags2 & 0x01);
616  // Propagate ERASE_PAGE flag for repeated page headers to work around a libzvbi bug
617  if (ctx->subtitle_map[pgno] && pgno == ctx->last_pgno) {
618  int last_byte9 = vbi_unham8(ctx->last_p5);
619  if (last_byte9 >= 0 && last_byte9 & 0x8) {
620  int byte9 = vbi_unham8(p[5]);
621  if (byte9 >= 0)
622  p[5] = vbi_ham8(byte9 | 0x8);
623  }
624  }
625  ctx->last_pgno = pgno;
626  ctx->last_p5 = p[5];
627  }
628  }
629  lines++;
630  }
631  }
632  size -= data_unit_length + 2;
633  buf += data_unit_length + 2;
634  }
635  if (size)
636  av_log(ctx, AV_LOG_WARNING, "%d bytes remained after slicing data\n", size);
637  return lines;
638 }
639 
641  int *got_sub_ptr, const AVPacket *pkt)
642 {
643  TeletextContext *ctx = avctx->priv_data;
644  int ret = 0;
645 
646  if (!ctx->vbi) {
647  if (!(ctx->vbi = vbi_decoder_new()))
648  return AVERROR(ENOMEM);
649  if (ctx->default_region != -1) {
650  av_log(avctx, AV_LOG_INFO, "Setting default zvbi region to %i\n", ctx->default_region);
651  vbi_teletext_set_default_region(ctx->vbi, ctx->default_region);
652  }
653  if (!vbi_event_handler_register(ctx->vbi, VBI_EVENT_TTX_PAGE, handler, ctx)) {
654  vbi_decoder_delete(ctx->vbi);
655  ctx->vbi = NULL;
656  return AVERROR(ENOMEM);
657  }
658  }
659 
660  if (avctx->pkt_timebase.num && pkt->pts != AV_NOPTS_VALUE)
662 
663  if (pkt->size) {
664  int lines;
665  const int full_pes_size = pkt->size + 45; /* PES header is 45 bytes */
666 
667  // We allow unreasonably big packets, even if the standard only allows a max size of 1472
668  if (full_pes_size < 184 || full_pes_size > 65504 || full_pes_size % 184 != 0)
669  return AVERROR_INVALIDDATA;
670 
671  ctx->handler_ret = pkt->size;
672 
674  if ((lines = slice_to_vbi_lines(ctx, pkt->data + 1, pkt->size - 1)) < 0)
675  return lines;
676  ff_dlog(avctx, "ctx=%p buf_size=%d lines=%u pkt_pts=%7.3f\n",
677  ctx, pkt->size, lines, (double)pkt->pts/90000.0);
678  if (lines > 0) {
679  vbi_decode(ctx->vbi, ctx->sliced, lines, 0.0);
680  ctx->lines_processed += lines;
681  }
682  }
683  ctx->pts = AV_NOPTS_VALUE;
684  ret = ctx->handler_ret;
685  }
686 
687  if (ret < 0)
688  return ret;
689 
690  // is there a subtitle to pass?
691  if (ctx->nb_pages) {
692  int i;
693  sub->format = !!ctx->format_id;
694  sub->start_display_time = 0;
695  sub->end_display_time = ctx->sub_duration;
696  sub->num_rects = 0;
697  sub->pts = ctx->pages->pts;
698 
699  if (ctx->pages->sub_rect->type != SUBTITLE_NONE) {
700  sub->rects = av_malloc(sizeof(*sub->rects));
701  if (sub->rects) {
702  sub->num_rects = 1;
703  sub->rects[0] = ctx->pages->sub_rect;
704  } else {
705  ret = AVERROR(ENOMEM);
706  }
707  } else {
708  av_log(avctx, AV_LOG_DEBUG, "sending empty sub\n");
709  sub->rects = NULL;
710  }
711  if (!sub->rects) // no rect was passed
712  subtitle_rect_free(&ctx->pages->sub_rect);
713 
714  for (i = 0; i < ctx->nb_pages - 1; i++)
715  ctx->pages[i] = ctx->pages[i + 1];
716  ctx->nb_pages--;
717 
718  if (ret >= 0)
719  *got_sub_ptr = 1;
720  } else
721  *got_sub_ptr = 0;
722 
723  return ret;
724 }
725 
727 {
728  TeletextContext *ctx = avctx->priv_data;
729  unsigned int maj, min, rev;
730 
731  vbi_version(&maj, &min, &rev);
732  if (!(maj > 0 || min > 2 || min == 2 && rev >= 26)) {
733  av_log(avctx, AV_LOG_ERROR, "decoder needs zvbi version >= 0.2.26.\n");
734  return AVERROR_EXTERNAL;
735  }
736 
737  if (ctx->format_id == 0) {
738  avctx->width = 41 * BITMAP_CHAR_WIDTH;
739  avctx->height = 25 * BITMAP_CHAR_HEIGHT;
740  }
741 
742  ctx->vbi = NULL;
743  ctx->pts = AV_NOPTS_VALUE;
744  ctx->last_pgno = -1;
745  ctx->last_ass_alignment = 2;
746 
747  if (ctx->opacity == -1)
748  ctx->opacity = ctx->transparent_bg ? 0 : 255;
749 
750  av_log(avctx, AV_LOG_VERBOSE, "page filter: %s\n", ctx->pgno);
751 
752  switch (ctx->format_id) {
753  case 0:
754  return 0;
755  case 1:
756  return ff_ass_subtitle_header_default(avctx);
757  case 2:
758  return my_ass_subtitle_header(avctx);
759  }
760  return AVERROR_BUG;
761 }
762 
764 {
765  TeletextContext *ctx = avctx->priv_data;
766 
767  ff_dlog(avctx, "lines_total=%u\n", ctx->lines_processed);
768  while (ctx->nb_pages)
769  subtitle_rect_free(&ctx->pages[--ctx->nb_pages].sub_rect);
770  av_freep(&ctx->pages);
771 
772  vbi_decoder_delete(ctx->vbi);
773  ctx->vbi = NULL;
774  ctx->pts = AV_NOPTS_VALUE;
775  ctx->last_pgno = -1;
776  ctx->last_ass_alignment = 2;
777  memset(ctx->subtitle_map, 0, sizeof(ctx->subtitle_map));
778  if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
779  ctx->readorder = 0;
780  return 0;
781 }
782 
783 static void teletext_flush(AVCodecContext *avctx)
784 {
785  teletext_close_decoder(avctx);
786 }
787 
788 #define OFFSET(x) offsetof(TeletextContext, x)
789 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
790 static const AVOption options[] = {
791  {"txt_page", "page numbers to decode, subtitle for subtitles, * for all", OFFSET(pgno), AV_OPT_TYPE_STRING, {.str = "*"}, 0, 0, SD},
792  {"txt_default_region", "default G0 character set used for decoding", OFFSET(default_region), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 87, SD},
793  {"txt_chop_top", "discards the top teletext line", OFFSET(chop_top), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
794  {"txt_format", "format of the subtitles (bitmap or text or ass)", OFFSET(format_id), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, SD, .unit = "txt_format"},
795  {"bitmap", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, SD, .unit = "txt_format"},
796  {"text", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, SD, .unit = "txt_format"},
797  {"ass", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, SD, .unit = "txt_format"},
798  {"txt_left", "x offset of generated bitmaps", OFFSET(x_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
799  {"txt_top", "y offset of generated bitmaps", OFFSET(y_offset), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 65535, SD},
800  {"txt_chop_spaces", "chops leading and trailing spaces from text", OFFSET(chop_spaces), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, SD},
801  {"txt_duration", "display duration of teletext pages in msecs", OFFSET(sub_duration), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 86400000, SD},
802  {"txt_transparent", "force transparent background of the teletext", OFFSET(transparent_bg), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SD},
803  {"txt_opacity", "set opacity of the transparent background", OFFSET(opacity), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 255, SD},
804  { NULL },
805 };
806 
807 static const AVClass teletext_class = {
808  .class_name = "libzvbi_teletextdec",
809  .item_name = av_default_item_name,
810  .option = options,
811  .version = LIBAVUTIL_VERSION_INT,
812 };
813 
815  .p.name = "libzvbi_teletextdec",
816  CODEC_LONG_NAME("Libzvbi DVB teletext decoder"),
817  .p.type = AVMEDIA_TYPE_SUBTITLE,
818  .p.id = AV_CODEC_ID_DVB_TELETEXT,
819  .p.capabilities = AV_CODEC_CAP_DELAY,
820  .p.priv_class = &teletext_class,
821  .p.wrapper_name = "libzvbi",
822  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE,
823  .priv_data_size = sizeof(TeletextContext),
825  .close = teletext_close_decoder,
827  .flush = teletext_flush,
828 };
IS_TXT_SPACE
#define IS_TXT_SPACE(ch)
Definition: libzvbi-teletextdec.c:242
AVSubtitle
Definition: avcodec.h:2254
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
PUT_UTF8
#define PUT_UTF8(val, tmp, PUT_BYTE)
Definition: common.h:541
av_clip
#define av_clip
Definition: common.h:100
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:218
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVSubtitle::rects
AVSubtitleRect ** rects
Definition: avcodec.h:2259
opt.h
TeletextContext::chop_spaces
int chop_spaces
Definition: libzvbi-teletextdec.c:67
TeletextContext::handler_ret
int handler_ret
Definition: libzvbi-teletextdec.c:73
ff_ass_subtitle_header_default
int ff_ass_subtitle_header_default(AVCodecContext *avctx)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS with default style.
Definition: ass.c:98
TeletextContext::vbi
vbi_decoder * vbi
Definition: libzvbi-teletextdec.c:75
out
FILE * out
Definition: movenc.c:55
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
int64_t
long long int64_t
Definition: coverity.c:34
OFFSET
#define OFFSET(x)
Definition: libzvbi-teletextdec.c:788
AVSubtitleRect
Definition: avcodec.h:2227
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
AVSubtitle::num_rects
unsigned num_rects
Definition: avcodec.h:2258
TeletextContext::default_region
int default_region
Definition: libzvbi-teletextdec.c:59
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVPacket::data
uint8_t * data
Definition: packet.h:539
AV_CODEC_ID_DVB_TELETEXT
@ AV_CODEC_ID_DVB_TELETEXT
Definition: codec_id.h:563
TeletextContext::format_id
int format_id
Definition: libzvbi-teletextdec.c:62
AVOption
AVOption.
Definition: opt.h:429
b
#define b
Definition: input.c:41
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
TeletextContext::chop_top
int chop_top
Definition: libzvbi-teletextdec.c:63
FFCodec
Definition: codec_internal.h:127
gen_sub_text
static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
Definition: libzvbi-teletextdec.c:167
AVCodecContext::subtitle_header
uint8_t * subtitle_header
Definition: avcodec.h:1918
gen_sub_ass
static int gen_sub_ass(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
Definition: libzvbi-teletextdec.c:295
AVSubtitleRect::linesize
int linesize[4]
Definition: avcodec.h:2239
create_ass_text
static char * create_ass_text(TeletextContext *ctx, const char *text)
Definition: libzvbi-teletextdec.c:150
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
ff_data_identifier_is_teletext
static av_always_inline int ff_data_identifier_is_teletext(int data_identifier)
Definition: dvbtxt.h:28
ff_libzvbi_teletext_decoder
const FFCodec ff_libzvbi_teletext_decoder
Definition: libzvbi-teletextdec.c:814
TeletextPage::pts
int64_t pts
Definition: libzvbi-teletextdec.c:52
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
MAX_SLICES
#define MAX_SLICES
Definition: libzvbi-teletextdec.c:45
SUBTITLE_ASS
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition: avcodec.h:2222
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
TeletextContext::pts
int64_t pts
Definition: libzvbi-teletextdec.c:72
AVSubtitleRect::x
int x
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2228
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
decode_string
static void decode_string(vbi_page *page, vbi_char *row, AVBPrint *buf, int start, int end, vbi_color *cur_color, vbi_color *cur_back_color)
Definition: libzvbi-teletextdec.c:265
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVSubtitleRect::ass
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:2251
ass.h
TeletextContext::pgno
char * pgno
Definition: libzvbi-teletextdec.c:58
ff_ass_get_dialog
char * ff_ass_get_dialog(int readorder, int layer, const char *style, const char *speaker, const char *text)
Craft an ASS dialog string.
Definition: ass.c:111
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
TeletextContext::sub_duration
int sub_duration
Definition: libzvbi-teletextdec.c:64
dvbtxt.h
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
g
const char * g
Definition: vf_curves.c:128
AVSubtitleRect::y
int y
top left corner of pict, undefined when pict is not set
Definition: avcodec.h:2229
VBI_G
#define VBI_G(rgba)
Definition: libzvbi-teletextdec.c:39
get_trim_info
static void get_trim_info(vbi_page *page, vbi_char *row, int *leading, int *trailing, int *olen)
Definition: libzvbi-teletextdec.c:245
MAX_BUFFERED_PAGES
#define MAX_BUFFERED_PAGES
Definition: libzvbi-teletextdec.c:42
ff_ass_bprint_text_event
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:173
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
TeletextContext::last_p5
int last_p5
Definition: libzvbi-teletextdec.c:81
AVSubtitle::pts
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:2260
handler
static void handler(vbi_event *ev, void *user_data)
Definition: libzvbi-teletextdec.c:508
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
if
if(ret)
Definition: filter_design.txt:179
AVSubtitleRect::w
int w
width of pict, undefined when pict is not set
Definition: avcodec.h:2230
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
SD
#define SD
Definition: libzvbi-teletextdec.c:789
NULL
#define NULL
Definition: coverity.c:32
TeletextPage::subno
int subno
Definition: libzvbi-teletextdec.c:51
teletext_close_decoder
static int teletext_close_decoder(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:763
pixel
uint8_t pixel
Definition: tiny_ssim.c:41
slice_to_vbi_lines
static int slice_to_vbi_lines(TeletextContext *ctx, const uint8_t *buf, int size)
Definition: libzvbi-teletextdec.c:584
TeletextContext::subtitle_map
uint8_t subtitle_map[2048]
Definition: libzvbi-teletextdec.c:79
bprint_color
static void bprint_color(const char *type, AVBPrint *buf, vbi_page *page, unsigned ci)
Definition: libzvbi-teletextdec.c:234
BITMAP_CHAR_HEIGHT
#define BITMAP_CHAR_HEIGHT
Definition: libzvbi-teletextdec.c:44
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVCodecContext::subtitle_header_size
int subtitle_header_size
Header containing style information for text subtitles.
Definition: avcodec.h:1917
AVSubtitleRect::data
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2238
TeletextContext
Definition: libzvbi-teletextdec.c:55
TeletextContext::x_offset
int x_offset
Definition: libzvbi-teletextdec.c:60
options
Definition: swscale.c:42
TeletextContext::last_ass_alignment
int last_ass_alignment
Definition: libzvbi-teletextdec.c:82
BITMAP_CHAR_WIDTH
#define BITMAP_CHAR_WIDTH
Definition: libzvbi-teletextdec.c:43
teletext_decode_frame
static int teletext_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *pkt)
Definition: libzvbi-teletextdec.c:640
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:515
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AVPacket::size
int size
Definition: packet.h:540
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
codec_internal.h
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:565
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
TeletextContext::pages
TeletextPage * pages
Definition: libzvbi-teletextdec.c:70
user_data
static int FUNC() user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
Definition: cbs_mpeg2_syntax_template.c:59
AVSubtitle::end_display_time
uint32_t end_display_time
Definition: avcodec.h:2257
AVSubtitleRect::type
enum AVSubtitleType type
Definition: avcodec.h:2242
ff_data_unit_id_is_teletext
static av_always_inline int ff_data_unit_id_is_teletext(int data_unit_id)
Definition: dvbtxt.h:36
SUBTITLE_NONE
@ SUBTITLE_NONE
Definition: avcodec.h:2208
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
VBI_R
#define VBI_R(rgba)
Definition: libzvbi-teletextdec.c:38
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
RGBA
#define RGBA(r, g, b, a)
Definition: libzvbi-teletextdec.c:37
TeletextPage::pgno
int pgno
Definition: libzvbi-teletextdec.c:50
VBI_B
#define VBI_B(rgba)
Definition: libzvbi-teletextdec.c:40
teletext_init_decoder
static int teletext_init_decoder(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:726
TeletextContext::readorder
int readorder
Definition: libzvbi-teletextdec.c:78
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2210
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
TeletextContext::last_pgno
int last_pgno
Definition: libzvbi-teletextdec.c:80
bprint.h
AVSubtitle::format
uint16_t format
Definition: avcodec.h:2255
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
AVSubtitleRect::nb_colors
int nb_colors
number of colors in pict, undefined when pict is not set
Definition: avcodec.h:2232
VBI_TRANSPARENT_BLACK
#define VBI_TRANSPARENT_BLACK
Definition: libzvbi-teletextdec.c:36
internal.h
options
static const AVOption options[]
Definition: libzvbi-teletextdec.c:790
common.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
TeletextContext::lines_processed
int lines_processed
Definition: libzvbi-teletextdec.c:69
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
teletext_flush
static void teletext_flush(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:783
len
int len
Definition: vorbis_enc_data.h:426
AVCodecContext::height
int height
Definition: avcodec.h:632
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVSubtitleRect::h
int h
height of pict, undefined when pict is not set
Definition: avcodec.h:2231
AVClass::class_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...
Definition: log.h:80
subtitle_rect_free
static void subtitle_rect_free(AVSubtitleRect **sub_rect)
Definition: libzvbi-teletextdec.c:142
TeletextContext::transparent_bg
int transparent_bg
Definition: libzvbi-teletextdec.c:65
TeletextContext::sliced
vbi_sliced sliced[MAX_SLICES]
Definition: libzvbi-teletextdec.c:76
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
AVCodecContext
main external API structure.
Definition: avcodec.h:451
teletext_class
static const AVClass teletext_class
Definition: libzvbi-teletextdec.c:807
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AV_CODEC_CAP_DELAY
#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: codec.h:76
FF_CODEC_DECODE_SUB_CB
#define FF_CODEC_DECODE_SUB_CB(func)
Definition: codec_internal.h:314
TeletextPage::sub_rect
AVSubtitleRect * sub_rect
Definition: libzvbi-teletextdec.c:49
TeletextPage
Definition: libzvbi-teletextdec.c:47
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AVPacket
This structure stores compressed data.
Definition: packet.h:516
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
gen_sub_bitmap
static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top)
Definition: libzvbi-teletextdec.c:451
VBI_NB_COLORS
#define VBI_NB_COLORS
Definition: libzvbi-teletextdec.c:35
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:632
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
TeletextContext::opacity
int opacity
Definition: libzvbi-teletextdec.c:66
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:145
TEXT_MAXSZ
#define TEXT_MAXSZ
Definition: libzvbi-teletextdec.c:34
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
VBI_A
#define VBI_A(rgba)
Definition: libzvbi-teletextdec.c:41
AV_CODEC_FLAG2_RO_FLUSH_NOOP
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
Definition: avcodec.h:392
TeletextContext::nb_pages
int nb_pages
Definition: libzvbi-teletextdec.c:71
fix_transparency
static void fix_transparency(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page *page, int chop_top, int resx, int resy)
Definition: libzvbi-teletextdec.c:412
av_bprint_append_data
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:163
TeletextContext::y_offset
int y_offset
Definition: libzvbi-teletextdec.c:61
chop_spaces_utf8
static int chop_spaces_utf8(const unsigned char *t, int len)
Definition: libzvbi-teletextdec.c:131
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
AVSubtitle::start_display_time
uint32_t start_display_time
Definition: avcodec.h:2256
my_ass_subtitle_header
static int my_ass_subtitle_header(AVCodecContext *avctx)
Definition: libzvbi-teletextdec.c:85
min
float min
Definition: vorbis_enc_data.h:429