FFmpeg
dvbsubdec.c
Go to the documentation of this file.
1 /*
2  * DVB subtitle decoding
3  * Copyright (c) 2005 Ian Caulfield
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avcodec.h"
23 #include "get_bits.h"
24 #include "bytestream.h"
25 #include "internal.h"
26 #include "libavutil/colorspace.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/thread.h"
30 
31 #define DVBSUB_PAGE_SEGMENT 0x10
32 #define DVBSUB_REGION_SEGMENT 0x11
33 #define DVBSUB_CLUT_SEGMENT 0x12
34 #define DVBSUB_OBJECT_SEGMENT 0x13
35 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
36 #define DVBSUB_DISPLAY_SEGMENT 0x80
37 
38 #define cm (ff_crop_tab + MAX_NEG_CROP)
39 
40 #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
41 
42 typedef struct DVBSubCLUT {
43  int id;
44  int version;
45 
46  uint32_t clut4[4];
47  uint32_t clut16[16];
48  uint32_t clut256[256];
49 
50  struct DVBSubCLUT *next;
51 } DVBSubCLUT;
52 
54 
55 typedef struct DVBSubObjectDisplay {
56  int object_id;
57  int region_id;
58 
59  int x_pos;
60  int y_pos;
61 
62  int fgcolor;
63  int bgcolor;
64 
68 
69 typedef struct DVBSubObject {
70  int id;
71  int version;
72 
73  int type;
74 
76 
77  struct DVBSubObject *next;
78 } DVBSubObject;
79 
80 typedef struct DVBSubRegionDisplay {
81  int region_id;
82 
83  int x_pos;
84  int y_pos;
85 
88 
89 typedef struct DVBSubRegion {
90  int id;
91  int version;
92 
93  int width;
94  int height;
95  int depth;
96 
97  int clut;
98  int bgcolor;
99 
100  uint8_t computed_clut[4*256];
102 
103  uint8_t *pbuf;
104  int buf_size;
105  int dirty;
106 
108 
110 } DVBSubRegion;
111 
112 typedef struct DVBSubDisplayDefinition {
113  int version;
114 
115  int x;
116  int y;
117  int width;
118  int height;
120 
121 typedef struct DVBSubContext {
122  AVClass *class;
125 
126  int version;
127  int time_out;
128  int compute_edt; /**< if 1 end display time calculated using pts
129  if 0 (Default) calculated using time out */
131  int clut_count2[257][256];
133  int64_t prev_start;
137 
140 } DVBSubContext;
141 
142 
143 static DVBSubObject* get_object(DVBSubContext *ctx, int object_id)
144 {
145  DVBSubObject *ptr = ctx->object_list;
146 
147  while (ptr && ptr->id != object_id) {
148  ptr = ptr->next;
149  }
150 
151  return ptr;
152 }
153 
154 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
155 {
156  DVBSubCLUT *ptr = ctx->clut_list;
157 
158  while (ptr && ptr->id != clut_id) {
159  ptr = ptr->next;
160  }
161 
162  return ptr;
163 }
164 
165 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
166 {
167  DVBSubRegion *ptr = ctx->region_list;
168 
169  while (ptr && ptr->id != region_id) {
170  ptr = ptr->next;
171  }
172 
173  return ptr;
174 }
175 
177 {
178  DVBSubObject *object, *obj2, **obj2_ptr;
179  DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
180 
181  while (region->display_list) {
182  display = region->display_list;
183 
184  object = get_object(ctx, display->object_id);
185 
186  if (object) {
187  obj_disp_ptr = &object->display_list;
188  obj_disp = *obj_disp_ptr;
189 
190  while (obj_disp && obj_disp != display) {
191  obj_disp_ptr = &obj_disp->object_list_next;
192  obj_disp = *obj_disp_ptr;
193  }
194 
195  if (obj_disp) {
196  *obj_disp_ptr = obj_disp->object_list_next;
197 
198  if (!object->display_list) {
199  obj2_ptr = &ctx->object_list;
200  obj2 = *obj2_ptr;
201 
202  while (obj2 != object) {
203  av_assert0(obj2);
204  obj2_ptr = &obj2->next;
205  obj2 = *obj2_ptr;
206  }
207 
208  *obj2_ptr = obj2->next;
209 
210  av_freep(&obj2);
211  }
212  }
213  }
214 
215  region->display_list = display->region_list_next;
216 
217  av_freep(&display);
218  }
219 
220 }
221 
223 {
224  while (ctx->clut_list) {
225  DVBSubCLUT *clut = ctx->clut_list;
226 
227  ctx->clut_list = clut->next;
228 
229  av_freep(&clut);
230  }
231 }
232 
234 {
235  while (ctx->object_list) {
236  DVBSubObject *object = ctx->object_list;
237 
238  ctx->object_list = object->next;
239 
240  av_freep(&object);
241  }
242 }
243 
245 {
246  while (ctx->region_list) {
247  DVBSubRegion *region = ctx->region_list;
248 
249  ctx->region_list = region->next;
250 
252 
253  av_freep(&region->pbuf);
254  av_freep(&region);
255  }
256 }
257 
258 static av_cold void init_default_clut(void)
259 {
260  int i, r, g, b, a = 0;
261 
262  default_clut.id = -1;
264 
265  default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
266  default_clut.clut4[1] = RGBA(255, 255, 255, 255);
267  default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
268  default_clut.clut4[3] = RGBA(127, 127, 127, 255);
269 
270  default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
271  for (i = 1; i < 16; i++) {
272  if (i < 8) {
273  r = (i & 1) ? 255 : 0;
274  g = (i & 2) ? 255 : 0;
275  b = (i & 4) ? 255 : 0;
276  } else {
277  r = (i & 1) ? 127 : 0;
278  g = (i & 2) ? 127 : 0;
279  b = (i & 4) ? 127 : 0;
280  }
281  default_clut.clut16[i] = RGBA(r, g, b, 255);
282  }
283 
284  default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
285  for (i = 1; i < 256; i++) {
286  if (i < 8) {
287  r = (i & 1) ? 255 : 0;
288  g = (i & 2) ? 255 : 0;
289  b = (i & 4) ? 255 : 0;
290  a = 63;
291  } else {
292  switch (i & 0x88) {
293  case 0x00:
294  r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
295  g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
296  b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
297  a = 255;
298  break;
299  case 0x08:
300  r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
301  g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
302  b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
303  a = 127;
304  break;
305  case 0x80:
306  r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
307  g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
308  b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
309  a = 255;
310  break;
311  case 0x88:
312  r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
313  g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
314  b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
315  a = 255;
316  break;
317  }
318  }
319  default_clut.clut256[i] = RGBA(r, g, b, a);
320  }
321 }
322 
324 {
325  static AVOnce init_static_once = AV_ONCE_INIT;
326  DVBSubContext *ctx = avctx->priv_data;
327 
328  if (ctx->substream < 0) {
329  ctx->composition_id = -1;
330  ctx->ancillary_id = -1;
331  } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
332  av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
333  ctx->composition_id = -1;
334  ctx->ancillary_id = -1;
335  } else {
336  if (avctx->extradata_size > 5*ctx->substream + 2) {
337  ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream);
338  ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2);
339  } else {
340  av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream);
341  ctx->composition_id = AV_RB16(avctx->extradata);
342  ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
343  }
344  }
345 
346  ctx->version = -1;
347  ctx->prev_start = AV_NOPTS_VALUE;
348 
349  ff_thread_once(&init_static_once, init_default_clut);
350 
351  return 0;
352 }
353 
355 {
356  DVBSubContext *ctx = avctx->priv_data;
357  DVBSubRegionDisplay *display;
358 
360 
362 
363  delete_cluts(ctx);
364 
365  av_freep(&ctx->display_definition);
366 
367  while (ctx->display_list) {
368  display = ctx->display_list;
369  ctx->display_list = display->next;
370 
371  av_freep(&display);
372  }
373 
374  return 0;
375 }
376 
378  uint8_t *destbuf, int dbuf_len,
379  const uint8_t **srcbuf, int buf_size,
380  int non_mod, uint8_t *map_table, int x_pos)
381 {
382  GetBitContext gb;
383 
384  int bits;
385  int run_length;
386  int pixels_read = x_pos;
387 
388  init_get_bits(&gb, *srcbuf, buf_size << 3);
389 
390  destbuf += x_pos;
391 
392  while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
393  bits = get_bits(&gb, 2);
394 
395  if (bits) {
396  if (non_mod != 1 || bits != 1) {
397  if (map_table)
398  *destbuf++ = map_table[bits];
399  else
400  *destbuf++ = bits;
401  }
402  pixels_read++;
403  } else {
404  bits = get_bits1(&gb);
405  if (bits == 1) {
406  run_length = get_bits(&gb, 3) + 3;
407  bits = get_bits(&gb, 2);
408 
409  if (non_mod == 1 && bits == 1)
410  pixels_read += run_length;
411  else {
412  if (map_table)
413  bits = map_table[bits];
414  while (run_length-- > 0 && pixels_read < dbuf_len) {
415  *destbuf++ = bits;
416  pixels_read++;
417  }
418  }
419  } else {
420  bits = get_bits1(&gb);
421  if (bits == 0) {
422  bits = get_bits(&gb, 2);
423  if (bits == 2) {
424  run_length = get_bits(&gb, 4) + 12;
425  bits = get_bits(&gb, 2);
426 
427  if (non_mod == 1 && bits == 1)
428  pixels_read += run_length;
429  else {
430  if (map_table)
431  bits = map_table[bits];
432  while (run_length-- > 0 && pixels_read < dbuf_len) {
433  *destbuf++ = bits;
434  pixels_read++;
435  }
436  }
437  } else if (bits == 3) {
438  run_length = get_bits(&gb, 8) + 29;
439  bits = get_bits(&gb, 2);
440 
441  if (non_mod == 1 && bits == 1)
442  pixels_read += run_length;
443  else {
444  if (map_table)
445  bits = map_table[bits];
446  while (run_length-- > 0 && pixels_read < dbuf_len) {
447  *destbuf++ = bits;
448  pixels_read++;
449  }
450  }
451  } else if (bits == 1) {
452  if (map_table)
453  bits = map_table[0];
454  else
455  bits = 0;
456  run_length = 2;
457  while (run_length-- > 0 && pixels_read < dbuf_len) {
458  *destbuf++ = bits;
459  pixels_read++;
460  }
461  } else {
462  (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
463  return pixels_read;
464  }
465  } else {
466  if (map_table)
467  bits = map_table[0];
468  else
469  bits = 0;
470  *destbuf++ = bits;
471  pixels_read++;
472  }
473  }
474  }
475  }
476 
477  if (get_bits(&gb, 6))
478  av_log(avctx, AV_LOG_ERROR, "line overflow\n");
479 
480  (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
481 
482  return pixels_read;
483 }
484 
485 static int dvbsub_read_4bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len,
486  const uint8_t **srcbuf, int buf_size,
487  int non_mod, uint8_t *map_table, int x_pos)
488 {
489  GetBitContext gb;
490 
491  int bits;
492  int run_length;
493  int pixels_read = x_pos;
494 
495  init_get_bits(&gb, *srcbuf, buf_size << 3);
496 
497  destbuf += x_pos;
498 
499  while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
500  bits = get_bits(&gb, 4);
501 
502  if (bits) {
503  if (non_mod != 1 || bits != 1) {
504  if (map_table)
505  *destbuf++ = map_table[bits];
506  else
507  *destbuf++ = bits;
508  }
509  pixels_read++;
510  } else {
511  bits = get_bits1(&gb);
512  if (bits == 0) {
513  run_length = get_bits(&gb, 3);
514 
515  if (run_length == 0) {
516  (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
517  return pixels_read;
518  }
519 
520  run_length += 2;
521 
522  if (map_table)
523  bits = map_table[0];
524  else
525  bits = 0;
526 
527  while (run_length-- > 0 && pixels_read < dbuf_len) {
528  *destbuf++ = bits;
529  pixels_read++;
530  }
531  } else {
532  bits = get_bits1(&gb);
533  if (bits == 0) {
534  run_length = get_bits(&gb, 2) + 4;
535  bits = get_bits(&gb, 4);
536 
537  if (non_mod == 1 && bits == 1)
538  pixels_read += run_length;
539  else {
540  if (map_table)
541  bits = map_table[bits];
542  while (run_length-- > 0 && pixels_read < dbuf_len) {
543  *destbuf++ = bits;
544  pixels_read++;
545  }
546  }
547  } else {
548  bits = get_bits(&gb, 2);
549  if (bits == 2) {
550  run_length = get_bits(&gb, 4) + 9;
551  bits = get_bits(&gb, 4);
552 
553  if (non_mod == 1 && bits == 1)
554  pixels_read += run_length;
555  else {
556  if (map_table)
557  bits = map_table[bits];
558  while (run_length-- > 0 && pixels_read < dbuf_len) {
559  *destbuf++ = bits;
560  pixels_read++;
561  }
562  }
563  } else if (bits == 3) {
564  run_length = get_bits(&gb, 8) + 25;
565  bits = get_bits(&gb, 4);
566 
567  if (non_mod == 1 && bits == 1)
568  pixels_read += run_length;
569  else {
570  if (map_table)
571  bits = map_table[bits];
572  while (run_length-- > 0 && pixels_read < dbuf_len) {
573  *destbuf++ = bits;
574  pixels_read++;
575  }
576  }
577  } else if (bits == 1) {
578  if (map_table)
579  bits = map_table[0];
580  else
581  bits = 0;
582  run_length = 2;
583  while (run_length-- > 0 && pixels_read < dbuf_len) {
584  *destbuf++ = bits;
585  pixels_read++;
586  }
587  } else {
588  if (map_table)
589  bits = map_table[0];
590  else
591  bits = 0;
592  *destbuf++ = bits;
593  pixels_read ++;
594  }
595  }
596  }
597  }
598  }
599 
600  if (get_bits(&gb, 8))
601  av_log(avctx, AV_LOG_ERROR, "line overflow\n");
602 
603  (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
604 
605  return pixels_read;
606 }
607 
609  uint8_t *destbuf, int dbuf_len,
610  const uint8_t **srcbuf, int buf_size,
611  int non_mod, uint8_t *map_table, int x_pos)
612 {
613  const uint8_t *sbuf_end = (*srcbuf) + buf_size;
614  int bits;
615  int run_length;
616  int pixels_read = x_pos;
617 
618  destbuf += x_pos;
619 
620  while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
621  bits = *(*srcbuf)++;
622 
623  if (bits) {
624  if (non_mod != 1 || bits != 1) {
625  if (map_table)
626  *destbuf++ = map_table[bits];
627  else
628  *destbuf++ = bits;
629  }
630  pixels_read++;
631  } else {
632  bits = *(*srcbuf)++;
633  run_length = bits & 0x7f;
634  if ((bits & 0x80) == 0) {
635  if (run_length == 0) {
636  return pixels_read;
637  }
638 
639  bits = 0;
640  } else {
641  bits = *(*srcbuf)++;
642  }
643  if (non_mod == 1 && bits == 1)
644  pixels_read += run_length;
645  else {
646  if (map_table)
647  bits = map_table[bits];
648  while (run_length-- > 0 && pixels_read < dbuf_len) {
649  *destbuf++ = bits;
650  pixels_read++;
651  }
652  }
653  }
654  }
655 
656  if (*(*srcbuf)++)
657  av_log(avctx, AV_LOG_ERROR, "line overflow\n");
658 
659  return pixels_read;
660 }
661 
662 static void compute_default_clut(DVBSubContext *ctx, uint8_t *clut, AVSubtitleRect *rect, int w, int h)
663 {
664  uint8_t list[256] = {0};
665  uint8_t list_inv[256];
666  int counttab[256] = {0};
667  int (*counttab2)[256] = ctx->clut_count2;
668  int count, i, x, y;
669  ptrdiff_t stride = rect->linesize[0];
670 
671  memset(ctx->clut_count2, 0 , sizeof(ctx->clut_count2));
672 
673 #define V(x,y) rect->data[0][(x) + (y)*stride]
674  for (y = 0; y<h; y++) {
675  for (x = 0; x<w; x++) {
676  int v = V(x,y) + 1;
677  int vl = x ? V(x-1,y) + 1 : 0;
678  int vr = x+1<w ? V(x+1,y) + 1 : 0;
679  int vt = y ? V(x,y-1) + 1 : 0;
680  int vb = y+1<h ? V(x,y+1) + 1 : 0;
681  counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
682  counttab2[vl][v-1] ++;
683  counttab2[vr][v-1] ++;
684  counttab2[vt][v-1] ++;
685  counttab2[vb][v-1] ++;
686  }
687  }
688 #define L(x,y) list[d[(x) + (y)*stride]]
689 
690  for (i = 0; i<256; i++) {
691  counttab2[i+1][i] = 0;
692  }
693  for (i = 0; i<256; i++) {
694  int bestscore = 0;
695  int bestv = 0;
696 
697  for (x = 0; x < 256; x++) {
698  int scorev = 0;
699  if (list[x])
700  continue;
701  scorev += counttab2[0][x];
702  for (y = 0; y < 256; y++) {
703  scorev += list[y] * counttab2[y+1][x];
704  }
705 
706  if (scorev) {
707  int score = 1024LL*scorev / counttab[x];
708  if (score > bestscore) {
709  bestscore = score;
710  bestv = x;
711  }
712  }
713  }
714  if (!bestscore)
715  break;
716  list [ bestv ] = 1;
717  list_inv[ i ] = bestv;
718  }
719 
720  count = FFMAX(i - 1, 1);
721  for (i--; i >= 0; i--) {
722  int v = i * 255 / count;
723  AV_WN32(clut + 4*list_inv[i], RGBA(v/2,v,v/2,v));
724  }
725 }
726 
727 
728 static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
729 {
730  DVBSubContext *ctx = avctx->priv_data;
731  DVBSubRegionDisplay *display;
732  DVBSubDisplayDefinition *display_def = ctx->display_definition;
733  DVBSubRegion *region;
735  const DVBSubCLUT *clut;
736  const uint32_t *clut_table;
737  int i;
738  int offset_x=0, offset_y=0;
739  int ret = 0;
740 
741 
742  if (display_def) {
743  offset_x = display_def->x;
744  offset_y = display_def->y;
745  }
746 
747  /* Not touching AVSubtitles again*/
748  if (sub->num_rects) {
749  avpriv_request_sample(ctx, "Different Version of Segment asked Twice");
750  return AVERROR_PATCHWELCOME;
751  }
752  for (display = ctx->display_list; display; display = display->next) {
753  region = get_region(ctx, display->region_id);
754  if (region && region->dirty)
755  sub->num_rects++;
756  }
757 
758  if (ctx->compute_edt == 0) {
759  sub->end_display_time = ctx->time_out * 1000;
760  *got_output = 1;
761  } else if (ctx->prev_start != AV_NOPTS_VALUE) {
762  sub->end_display_time = av_rescale_q((sub->pts - ctx->prev_start ), AV_TIME_BASE_Q, (AVRational){ 1, 1000 }) - 1;
763  *got_output = 1;
764  }
765  if (sub->num_rects > 0) {
766 
767  sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects);
768  if (!sub->rects) {
769  ret = AVERROR(ENOMEM);
770  goto fail;
771  }
772 
773  for (i = 0; i < sub->num_rects; i++) {
774  sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
775  if (!sub->rects[i]) {
776  ret = AVERROR(ENOMEM);
777  goto fail;
778  }
779  }
780 
781  i = 0;
782 
783  for (display = ctx->display_list; display; display = display->next) {
784  region = get_region(ctx, display->region_id);
785 
786  if (!region)
787  continue;
788 
789  if (!region->dirty)
790  continue;
791 
792  rect = sub->rects[i];
793  rect->x = display->x_pos + offset_x;
794  rect->y = display->y_pos + offset_y;
795  rect->w = region->width;
796  rect->h = region->height;
797  rect->nb_colors = (1 << region->depth);
798  rect->type = SUBTITLE_BITMAP;
799  rect->linesize[0] = region->width;
800 
801  clut = get_clut(ctx, region->clut);
802 
803  if (!clut)
804  clut = &default_clut;
805 
806  switch (region->depth) {
807  case 2:
808  clut_table = clut->clut4;
809  break;
810  case 8:
811  clut_table = clut->clut256;
812  break;
813  case 4:
814  default:
815  clut_table = clut->clut16;
816  break;
817  }
818 
819  rect->data[1] = av_mallocz(AVPALETTE_SIZE);
820  if (!rect->data[1]) {
821  ret = AVERROR(ENOMEM);
822  goto fail;
823  }
824  memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(*clut_table));
825 
826  rect->data[0] = av_malloc(region->buf_size);
827  if (!rect->data[0]) {
828  ret = AVERROR(ENOMEM);
829  goto fail;
830  }
831 
832  memcpy(rect->data[0], region->pbuf, region->buf_size);
833 
834  if ((clut == &default_clut && ctx->compute_clut < 0) || ctx->compute_clut == 1) {
835  if (!region->has_computed_clut) {
837  region->has_computed_clut = 1;
838  }
839 
840  memcpy(rect->data[1], region->computed_clut, sizeof(region->computed_clut));
841  }
842 
843  i++;
844  }
845  }
846 
847  return 0;
848 fail:
849  if (sub->rects) {
850  for (i=0; i < sub->num_rects; i++) {
851  rect = sub->rects[i];
852  if (rect) {
853  av_freep(&rect->data[0]);
854  av_freep(&rect->data[1]);
855  }
856  av_freep(&sub->rects[i]);
857  }
858  av_freep(&sub->rects);
859  }
860  sub->num_rects = 0;
861  return ret;
862 }
863 
865  const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
866 {
867  DVBSubContext *ctx = avctx->priv_data;
868 
869  DVBSubRegion *region = get_region(ctx, display->region_id);
870  const uint8_t *buf_end = buf + buf_size;
871  uint8_t *pbuf;
872  int x_pos, y_pos;
873  int i;
874 
875  uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
876  uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
877  uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
878  0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
879  uint8_t *map_table;
880 
881 #if 0
882  ff_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
883  top_bottom ? "bottom" : "top");
884 
885  for (i = 0; i < buf_size; i++) {
886  if (i % 16 == 0)
887  ff_dlog(avctx, "0x%8p: ", buf+i);
888 
889  ff_dlog(avctx, "%02x ", buf[i]);
890  if (i % 16 == 15)
891  ff_dlog(avctx, "\n");
892  }
893 
894  if (i % 16)
895  ff_dlog(avctx, "\n");
896 #endif
897 
898  if (!region)
899  return;
900 
901  pbuf = region->pbuf;
902  region->dirty = 1;
903 
904  x_pos = display->x_pos;
905  y_pos = display->y_pos;
906 
907  y_pos += top_bottom;
908 
909  while (buf < buf_end) {
910  if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) {
911  av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf);
912  return;
913  }
914 
915  switch (*buf++) {
916  case 0x10:
917  if (region->depth == 8)
918  map_table = map2to8;
919  else if (region->depth == 4)
920  map_table = map2to4;
921  else
922  map_table = NULL;
923 
924  x_pos = dvbsub_read_2bit_string(avctx, pbuf + (y_pos * region->width),
925  region->width, &buf, buf_end - buf,
926  non_mod, map_table, x_pos);
927  break;
928  case 0x11:
929  if (region->depth < 4) {
930  av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
931  return;
932  }
933 
934  if (region->depth == 8)
935  map_table = map4to8;
936  else
937  map_table = NULL;
938 
939  x_pos = dvbsub_read_4bit_string(avctx, pbuf + (y_pos * region->width),
940  region->width, &buf, buf_end - buf,
941  non_mod, map_table, x_pos);
942  break;
943  case 0x12:
944  if (region->depth < 8) {
945  av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
946  return;
947  }
948 
949  x_pos = dvbsub_read_8bit_string(avctx, pbuf + (y_pos * region->width),
950  region->width, &buf, buf_end - buf,
951  non_mod, NULL, x_pos);
952  break;
953 
954  case 0x20:
955  map2to4[0] = (*buf) >> 4;
956  map2to4[1] = (*buf++) & 0xf;
957  map2to4[2] = (*buf) >> 4;
958  map2to4[3] = (*buf++) & 0xf;
959  break;
960  case 0x21:
961  for (i = 0; i < 4; i++)
962  map2to8[i] = *buf++;
963  break;
964  case 0x22:
965  for (i = 0; i < 16; i++)
966  map4to8[i] = *buf++;
967  break;
968 
969  case 0xf0:
970  x_pos = display->x_pos;
971  y_pos += 2;
972  break;
973  default:
974  av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
975  }
976  }
977 
978  if (ctx->compute_clut != -2)
979  region->has_computed_clut = 0;
980 }
981 
983  const uint8_t *buf, int buf_size)
984 {
985  DVBSubContext *ctx = avctx->priv_data;
986 
987  const uint8_t *buf_end = buf + buf_size;
988  int object_id;
989  DVBSubObject *object;
990  DVBSubObjectDisplay *display;
991  int top_field_len, bottom_field_len;
992 
993  int coding_method, non_modifying_color;
994 
995  object_id = AV_RB16(buf);
996  buf += 2;
997 
998  object = get_object(ctx, object_id);
999 
1000  if (!object)
1001  return AVERROR_INVALIDDATA;
1002 
1003  coding_method = ((*buf) >> 2) & 3;
1004  non_modifying_color = ((*buf++) >> 1) & 1;
1005 
1006  if (coding_method == 0) {
1007  top_field_len = AV_RB16(buf);
1008  buf += 2;
1009  bottom_field_len = AV_RB16(buf);
1010  buf += 2;
1011 
1012  if (buf + top_field_len + bottom_field_len > buf_end) {
1013  av_log(avctx, AV_LOG_ERROR, "Field data size %d+%d too large\n", top_field_len, bottom_field_len);
1014  return AVERROR_INVALIDDATA;
1015  }
1016 
1017  for (display = object->display_list; display; display = display->object_list_next) {
1018  const uint8_t *block = buf;
1019  int bfl = bottom_field_len;
1020 
1021  dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
1022  non_modifying_color);
1023 
1024  if (bottom_field_len > 0)
1025  block = buf + top_field_len;
1026  else
1027  bfl = top_field_len;
1028 
1029  dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1,
1030  non_modifying_color);
1031  }
1032  } else if (coding_method == 1) {
1033  avpriv_report_missing_feature(avctx, "coded as a string of characters");
1034  return AVERROR_PATCHWELCOME;
1035  } else if (coding_method == 2) {
1036  avpriv_report_missing_feature(avctx, "progressive coding of pixels");
1037  return AVERROR_PATCHWELCOME;
1038  } else {
1039  av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
1040  return AVERROR_INVALIDDATA;
1041  }
1042 
1043  return 0;
1044 }
1045 
1047  const uint8_t *buf, int buf_size)
1048 {
1049  DVBSubContext *ctx = avctx->priv_data;
1050 
1051  const uint8_t *buf_end = buf + buf_size;
1052  int i, clut_id;
1053  int version;
1054  DVBSubCLUT *clut;
1055  int entry_id, depth , full_range;
1056  int y, cr, cb, alpha;
1057  int r, g, b, r_add, g_add, b_add;
1058 
1059  ff_dlog(avctx, "DVB clut packet:\n");
1060 
1061  for (i=0; i < buf_size; i++) {
1062  ff_dlog(avctx, "%02x ", buf[i]);
1063  if (i % 16 == 15)
1064  ff_dlog(avctx, "\n");
1065  }
1066 
1067  if (i % 16)
1068  ff_dlog(avctx, "\n");
1069 
1070  clut_id = *buf++;
1071  version = ((*buf)>>4)&15;
1072  buf += 1;
1073 
1074  clut = get_clut(ctx, clut_id);
1075 
1076  if (!clut) {
1077  clut = av_malloc(sizeof(*clut));
1078  if (!clut)
1079  return AVERROR(ENOMEM);
1080 
1081  memcpy(clut, &default_clut, sizeof(*clut));
1082 
1083  clut->id = clut_id;
1084  clut->version = -1;
1085 
1086  clut->next = ctx->clut_list;
1087  ctx->clut_list = clut;
1088  }
1089 
1090  if (clut->version != version) {
1091 
1092  clut->version = version;
1093 
1094  while (buf + 4 < buf_end) {
1095  entry_id = *buf++;
1096 
1097  depth = (*buf) & 0xe0;
1098 
1099  if (depth == 0) {
1100  av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
1101  }
1102 
1103  full_range = (*buf++) & 1;
1104 
1105  if (full_range) {
1106  y = *buf++;
1107  cr = *buf++;
1108  cb = *buf++;
1109  alpha = *buf++;
1110  } else {
1111  y = buf[0] & 0xfc;
1112  cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
1113  cb = (buf[1] << 2) & 0xf0;
1114  alpha = (buf[1] << 6) & 0xc0;
1115 
1116  buf += 2;
1117  }
1118 
1119  if (y == 0)
1120  alpha = 0xff;
1121 
1123  YUV_TO_RGB2_CCIR(r, g, b, y);
1124 
1125  ff_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
1126  if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) {
1127  ff_dlog(avctx, "More than one bit level marked: %x\n", depth);
1129  return AVERROR_INVALIDDATA;
1130  }
1131 
1132  if (depth & 0x80 && entry_id < 4)
1133  clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
1134  else if (depth & 0x40 && entry_id < 16)
1135  clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
1136  else if (depth & 0x20)
1137  clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
1138  }
1139  }
1140 
1141  return 0;
1142 }
1143 
1144 
1146  const uint8_t *buf, int buf_size)
1147 {
1148  DVBSubContext *ctx = avctx->priv_data;
1149 
1150  const uint8_t *buf_end = buf + buf_size;
1151  int region_id, object_id;
1152  int av_unused version;
1153  DVBSubRegion *region;
1154  DVBSubObject *object;
1155  DVBSubObjectDisplay *display;
1156  int fill;
1157  int ret;
1158 
1159  if (buf_size < 10)
1160  return AVERROR_INVALIDDATA;
1161 
1162  region_id = *buf++;
1163 
1164  region = get_region(ctx, region_id);
1165 
1166  if (!region) {
1167  region = av_mallocz(sizeof(*region));
1168  if (!region)
1169  return AVERROR(ENOMEM);
1170 
1171  region->id = region_id;
1172  region->version = -1;
1173 
1174  region->next = ctx->region_list;
1175  ctx->region_list = region;
1176  }
1177 
1178  version = ((*buf)>>4) & 15;
1179  fill = ((*buf++) >> 3) & 1;
1180 
1181  region->width = AV_RB16(buf);
1182  buf += 2;
1183  region->height = AV_RB16(buf);
1184  buf += 2;
1185 
1186  ret = av_image_check_size2(region->width, region->height, avctx->max_pixels, AV_PIX_FMT_PAL8, 0, avctx);
1187  if (ret >= 0 && region->width * region->height * 2 > 320 * 1024 * 8) {
1189  av_log(avctx, AV_LOG_ERROR, "Pixel buffer memory constraint violated\n");
1190  }
1191  if (ret < 0) {
1192  region->width= region->height= 0;
1193  return ret;
1194  }
1195 
1196  if (region->width * region->height != region->buf_size) {
1197  av_free(region->pbuf);
1198 
1199  region->buf_size = region->width * region->height;
1200 
1201  region->pbuf = av_malloc(region->buf_size);
1202  if (!region->pbuf) {
1203  region->buf_size =
1204  region->width =
1205  region->height = 0;
1206  return AVERROR(ENOMEM);
1207  }
1208 
1209  fill = 1;
1210  region->dirty = 0;
1211  }
1212 
1213  region->depth = 1 << (((*buf++) >> 2) & 7);
1214  if (region->depth < 2 || region->depth > 8) {
1215  av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth);
1216  region->depth= 4;
1217  }
1218  region->clut = *buf++;
1219 
1220  if (region->depth == 8) {
1221  region->bgcolor = *buf++;
1222  buf += 1;
1223  } else {
1224  buf += 1;
1225 
1226  if (region->depth == 4)
1227  region->bgcolor = (((*buf++) >> 4) & 15);
1228  else
1229  region->bgcolor = (((*buf++) >> 2) & 3);
1230  }
1231 
1232  ff_dlog(avctx, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
1233 
1234  if (fill) {
1235  memset(region->pbuf, region->bgcolor, region->buf_size);
1236  ff_dlog(avctx, "Fill region (%d)\n", region->bgcolor);
1237  }
1238 
1240 
1241  while (buf + 5 < buf_end) {
1242  object_id = AV_RB16(buf);
1243  buf += 2;
1244 
1245  object = get_object(ctx, object_id);
1246 
1247  if (!object) {
1248  object = av_mallocz(sizeof(*object));
1249  if (!object)
1250  return AVERROR(ENOMEM);
1251 
1252  object->id = object_id;
1253  object->next = ctx->object_list;
1254  ctx->object_list = object;
1255  }
1256 
1257  object->type = (*buf) >> 6;
1258 
1259  display = av_mallocz(sizeof(*display));
1260  if (!display)
1261  return AVERROR(ENOMEM);
1262 
1263  display->object_id = object_id;
1264  display->region_id = region_id;
1265 
1266  display->x_pos = AV_RB16(buf) & 0xfff;
1267  buf += 2;
1268  display->y_pos = AV_RB16(buf) & 0xfff;
1269  buf += 2;
1270 
1271  if (display->x_pos >= region->width ||
1272  display->y_pos >= region->height) {
1273  av_log(avctx, AV_LOG_ERROR, "Object outside region\n");
1274  av_free(display);
1275  return AVERROR_INVALIDDATA;
1276  }
1277 
1278  if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
1279  display->fgcolor = *buf++;
1280  display->bgcolor = *buf++;
1281  }
1282 
1283  display->region_list_next = region->display_list;
1284  region->display_list = display;
1285 
1286  display->object_list_next = object->display_list;
1287  object->display_list = display;
1288  }
1289 
1290  return 0;
1291 }
1292 
1294  const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
1295 {
1296  DVBSubContext *ctx = avctx->priv_data;
1297  DVBSubRegionDisplay *display;
1298  DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
1299 
1300  const uint8_t *buf_end = buf + buf_size;
1301  int region_id;
1302  int page_state;
1303  int timeout;
1304  int version;
1305 
1306  if (buf_size < 1)
1307  return AVERROR_INVALIDDATA;
1308 
1309  timeout = *buf++;
1310  version = ((*buf)>>4) & 15;
1311  page_state = ((*buf++) >> 2) & 3;
1312 
1313  if (ctx->version == version) {
1314  return 0;
1315  }
1316 
1317  ctx->time_out = timeout;
1318  ctx->version = version;
1319 
1320  ff_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
1321 
1322  if (ctx->compute_edt == 1)
1323  save_subtitle_set(avctx, sub, got_output);
1324 
1325  if (page_state == 1 || page_state == 2) {
1328  delete_cluts(ctx);
1329  }
1330 
1331  tmp_display_list = ctx->display_list;
1332  ctx->display_list = NULL;
1333 
1334  while (buf + 5 < buf_end) {
1335  region_id = *buf++;
1336  buf += 1;
1337 
1338  display = ctx->display_list;
1339  while (display && display->region_id != region_id) {
1340  display = display->next;
1341  }
1342  if (display) {
1343  av_log(avctx, AV_LOG_ERROR, "duplicate region\n");
1344  break;
1345  }
1346 
1347  display = tmp_display_list;
1348  tmp_ptr = &tmp_display_list;
1349 
1350  while (display && display->region_id != region_id) {
1351  tmp_ptr = &display->next;
1352  display = display->next;
1353  }
1354 
1355  if (!display) {
1356  display = av_mallocz(sizeof(*display));
1357  if (!display)
1358  return AVERROR(ENOMEM);
1359  }
1360 
1361  display->region_id = region_id;
1362 
1363  display->x_pos = AV_RB16(buf);
1364  buf += 2;
1365  display->y_pos = AV_RB16(buf);
1366  buf += 2;
1367 
1368  *tmp_ptr = display->next;
1369 
1370  display->next = ctx->display_list;
1371  ctx->display_list = display;
1372 
1373  ff_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
1374  }
1375 
1376  while (tmp_display_list) {
1377  display = tmp_display_list;
1378 
1379  tmp_display_list = display->next;
1380 
1381  av_freep(&display);
1382  }
1383 
1384  return 0;
1385 }
1386 
1387 
1388 #ifdef DEBUG
1389 static void png_save(DVBSubContext *ctx, const char *filename, uint32_t *bitmap, int w, int h)
1390 {
1391  int x, y, v;
1392  FILE *f;
1393  char fname[40], fname2[40];
1394  char command[1024];
1395 
1396  snprintf(fname, sizeof(fname), "%s.ppm", filename);
1397 
1398  f = fopen(fname, "w");
1399  if (!f) {
1400  perror(fname);
1401  return;
1402  }
1403  fprintf(f, "P6\n"
1404  "%d %d\n"
1405  "%d\n",
1406  w, h, 255);
1407  for(y = 0; y < h; y++) {
1408  for(x = 0; x < w; x++) {
1409  v = bitmap[y * w + x];
1410  putc((v >> 16) & 0xff, f);
1411  putc((v >> 8) & 0xff, f);
1412  putc((v >> 0) & 0xff, f);
1413  }
1414  }
1415  fclose(f);
1416 
1417 
1418  snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename);
1419 
1420  f = fopen(fname2, "w");
1421  if (!f) {
1422  perror(fname2);
1423  return;
1424  }
1425  fprintf(f, "P5\n"
1426  "%d %d\n"
1427  "%d\n",
1428  w, h, 255);
1429  for(y = 0; y < h; y++) {
1430  for(x = 0; x < w; x++) {
1431  v = bitmap[y * w + x];
1432  putc((v >> 24) & 0xff, f);
1433  }
1434  }
1435  fclose(f);
1436 
1437  snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
1438  if (system(command) != 0) {
1439  av_log(ctx, AV_LOG_ERROR, "Error running pnmtopng\n");
1440  return;
1441  }
1442 
1443  snprintf(command, sizeof(command), "rm %s %s", fname, fname2);
1444  if (system(command) != 0) {
1445  av_log(ctx, AV_LOG_ERROR, "Error removing %s and %s\n", fname, fname2);
1446  return;
1447  }
1448 }
1449 
1450 static int save_display_set(DVBSubContext *ctx)
1451 {
1452  DVBSubRegion *region;
1453  DVBSubRegionDisplay *display;
1454  const DVBSubCLUT *clut;
1455  const uint32_t *clut_table;
1456  int x_pos, y_pos, width, height;
1457  int x, y, y_off, x_off;
1458  uint32_t *pbuf;
1459  char filename[32];
1460  static int fileno_index = 0;
1461 
1462  x_pos = -1;
1463  y_pos = -1;
1464  width = 0;
1465  height = 0;
1466 
1467  for (display = ctx->display_list; display; display = display->next) {
1468  region = get_region(ctx, display->region_id);
1469 
1470  if (!region)
1471  return -1;
1472 
1473  if (x_pos == -1) {
1474  x_pos = display->x_pos;
1475  y_pos = display->y_pos;
1476  width = region->width;
1477  height = region->height;
1478  } else {
1479  if (display->x_pos < x_pos) {
1480  width += (x_pos - display->x_pos);
1481  x_pos = display->x_pos;
1482  }
1483 
1484  if (display->y_pos < y_pos) {
1485  height += (y_pos - display->y_pos);
1486  y_pos = display->y_pos;
1487  }
1488 
1489  if (display->x_pos + region->width > x_pos + width) {
1490  width = display->x_pos + region->width - x_pos;
1491  }
1492 
1493  if (display->y_pos + region->height > y_pos + height) {
1494  height = display->y_pos + region->height - y_pos;
1495  }
1496  }
1497  }
1498 
1499  if (x_pos >= 0) {
1500 
1501  pbuf = av_malloc(width * height * 4);
1502  if (!pbuf)
1503  return -1;
1504 
1505  for (display = ctx->display_list; display; display = display->next) {
1506  region = get_region(ctx, display->region_id);
1507 
1508  if (!region)
1509  return -1;
1510 
1511  x_off = display->x_pos - x_pos;
1512  y_off = display->y_pos - y_pos;
1513 
1514  clut = get_clut(ctx, region->clut);
1515 
1516  if (!clut)
1517  clut = &default_clut;
1518 
1519  switch (region->depth) {
1520  case 2:
1521  clut_table = clut->clut4;
1522  break;
1523  case 8:
1524  clut_table = clut->clut256;
1525  break;
1526  case 4:
1527  default:
1528  clut_table = clut->clut16;
1529  break;
1530  }
1531 
1532  for (y = 0; y < region->height; y++) {
1533  for (x = 0; x < region->width; x++) {
1534  pbuf[((y + y_off) * width) + x_off + x] =
1535  clut_table[region->pbuf[y * region->width + x]];
1536  }
1537  }
1538 
1539  }
1540 
1541  snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index);
1542 
1543  png_save(ctx, filename, pbuf, width, height);
1544 
1545  av_freep(&pbuf);
1546  }
1547 
1548  fileno_index++;
1549  return 0;
1550 }
1551 #endif /* DEBUG */
1552 
1554  const uint8_t *buf,
1555  int buf_size)
1556 {
1557  DVBSubContext *ctx = avctx->priv_data;
1558  DVBSubDisplayDefinition *display_def = ctx->display_definition;
1559  int dds_version, info_byte;
1560 
1561  if (buf_size < 5)
1562  return AVERROR_INVALIDDATA;
1563 
1564  info_byte = bytestream_get_byte(&buf);
1565  dds_version = info_byte >> 4;
1566  if (display_def && display_def->version == dds_version)
1567  return 0; // already have this display definition version
1568 
1569  if (!display_def) {
1570  display_def = av_mallocz(sizeof(*display_def));
1571  if (!display_def)
1572  return AVERROR(ENOMEM);
1573  ctx->display_definition = display_def;
1574  }
1575 
1576  display_def->version = dds_version;
1577  display_def->x = 0;
1578  display_def->y = 0;
1579  display_def->width = bytestream_get_be16(&buf) + 1;
1580  display_def->height = bytestream_get_be16(&buf) + 1;
1581  if (!avctx->width || !avctx->height) {
1582  int ret = ff_set_dimensions(avctx, display_def->width, display_def->height);
1583  if (ret < 0)
1584  return ret;
1585  }
1586 
1587  if (info_byte & 1<<3) { // display_window_flag
1588  if (buf_size < 13)
1589  return AVERROR_INVALIDDATA;
1590 
1591  display_def->x = bytestream_get_be16(&buf);
1592  display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
1593  display_def->y = bytestream_get_be16(&buf);
1594  display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
1595  }
1596 
1597  return 0;
1598 }
1599 
1600 static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
1601  int buf_size, AVSubtitle *sub,int *got_output)
1602 {
1603  DVBSubContext *ctx = avctx->priv_data;
1604 
1605  if (ctx->compute_edt == 0)
1606  save_subtitle_set(avctx, sub, got_output);
1607 #ifdef DEBUG
1608  save_display_set(ctx);
1609 #endif
1610  return 0;
1611 }
1612 
1613 static int dvbsub_decode(AVCodecContext *avctx,
1614  void *data, int *got_sub_ptr,
1615  AVPacket *avpkt)
1616 {
1617  const uint8_t *buf = avpkt->data;
1618  int buf_size = avpkt->size;
1619  DVBSubContext *ctx = avctx->priv_data;
1620  AVSubtitle *sub = data;
1621  const uint8_t *p, *p_end;
1622  int segment_type;
1623  int page_id;
1624  int segment_length;
1625  int i;
1626  int ret = 0;
1627  int got_segment = 0;
1628  int got_dds = 0;
1629 
1630  ff_dlog(avctx, "DVB sub packet:\n");
1631 
1632  for (i=0; i < buf_size; i++) {
1633  ff_dlog(avctx, "%02x ", buf[i]);
1634  if (i % 16 == 15)
1635  ff_dlog(avctx, "\n");
1636  }
1637 
1638  if (i % 16)
1639  ff_dlog(avctx, "\n");
1640 
1641  if (buf_size <= 6 || *buf != 0x0f) {
1642  ff_dlog(avctx, "incomplete or broken packet");
1643  return AVERROR_INVALIDDATA;
1644  }
1645 
1646  p = buf;
1647  p_end = buf + buf_size;
1648 
1649  while (p_end - p >= 6 && *p == 0x0f) {
1650  p += 1;
1651  segment_type = *p++;
1652  page_id = AV_RB16(p);
1653  p += 2;
1654  segment_length = AV_RB16(p);
1655  p += 2;
1656 
1657  if (avctx->debug & FF_DEBUG_STARTCODE) {
1658  av_log(avctx, AV_LOG_DEBUG, "segment_type:%d page_id:%d segment_length:%d\n", segment_type, page_id, segment_length);
1659  }
1660 
1661  if (p_end - p < segment_length) {
1662  ff_dlog(avctx, "incomplete or broken packet");
1663  ret = -1;
1664  goto end;
1665  }
1666 
1667  if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
1668  ctx->composition_id == -1 || ctx->ancillary_id == -1) {
1669  int ret = 0;
1670  switch (segment_type) {
1671  case DVBSUB_PAGE_SEGMENT:
1672  ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, got_sub_ptr);
1673  got_segment |= 1;
1674  break;
1675  case DVBSUB_REGION_SEGMENT:
1676  ret = dvbsub_parse_region_segment(avctx, p, segment_length);
1677  got_segment |= 2;
1678  break;
1679  case DVBSUB_CLUT_SEGMENT:
1680  ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
1681  if (ret < 0) goto end;
1682  got_segment |= 4;
1683  break;
1684  case DVBSUB_OBJECT_SEGMENT:
1685  ret = dvbsub_parse_object_segment(avctx, p, segment_length);
1686  got_segment |= 8;
1687  break;
1690  segment_length);
1691  got_dds = 1;
1692  break;
1694  ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, got_sub_ptr);
1695  if (got_segment == 15 && !got_dds && !avctx->width && !avctx->height) {
1696  // Default from ETSI EN 300 743 V1.3.1 (7.2.1)
1697  avctx->width = 720;
1698  avctx->height = 576;
1699  }
1700  got_segment |= 16;
1701  break;
1702  default:
1703  ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",
1704  segment_type, page_id, segment_length);
1705  break;
1706  }
1707  if (ret < 0)
1708  goto end;
1709  }
1710 
1711  p += segment_length;
1712  }
1713  // Some streams do not send a display segment but if we have all the other
1714  // segments then we need no further data.
1715  if (got_segment == 15) {
1716  av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n");
1717  dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
1718  }
1719 
1720 end:
1721  if (ret < 0) {
1722  *got_sub_ptr = 0;
1724  return ret;
1725  } else {
1726  if (ctx->compute_edt == 1)
1727  FFSWAP(int64_t, ctx->prev_start, sub->pts);
1728  }
1729 
1730  return p - buf;
1731 }
1732 
1733 #define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
1734 #define OFFSET(x) offsetof(DVBSubContext, x)
1735 static const AVOption options[] = {
1736  {"compute_edt", "compute end of time using pts or timeout", OFFSET(compute_edt), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DS},
1737  {"compute_clut", "compute clut when not available(-1) or only once (-2) or always(1) or never(0)", OFFSET(compute_clut), AV_OPT_TYPE_BOOL, {.i64 = -1}, -2, 1, DS},
1738  {"dvb_substream", "", OFFSET(substream), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
1739  {NULL}
1740 };
1741 static const AVClass dvbsubdec_class = {
1742  .class_name = "DVB Sub Decoder",
1743  .item_name = av_default_item_name,
1744  .option = options,
1745  .version = LIBAVUTIL_VERSION_INT,
1746 };
1747 
1749  .name = "dvbsub",
1750  .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
1751  .type = AVMEDIA_TYPE_SUBTITLE,
1753  .priv_data_size = sizeof(DVBSubContext),
1755  .close = dvbsub_close_decoder,
1756  .decode = dvbsub_decode,
1757  .priv_class = &dvbsubdec_class,
1758  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1759 };
DVBSubObjectDisplay::object_id
int object_id
Definition: dvbsubdec.c:56
AVSubtitle
Definition: avcodec.h:2389
DVBSubDisplayDefinition::version
int version
Definition: dvbsubdec.c:113
rect::w
int w
Definition: f_ebur128.c:91
AVCodec
AVCodec.
Definition: codec.h:197
stride
int stride
Definition: mace.c:144
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:187
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
DVBSUB_DISPLAY_SEGMENT
#define DVBSUB_DISPLAY_SEGMENT
Definition: dvbsubdec.c:36
DVBSubRegion::width
int width
Definition: dvbsubdec.c:93
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
delete_cluts
static void delete_cluts(DVBSubContext *ctx)
Definition: dvbsubdec.c:222
r
const char * r
Definition: vf_curves.c:116
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
opt.h
DVBSubRegionDisplay
Definition: dvbsubdec.c:80
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:108
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:215
DVBSubContext::prev_start
int64_t prev_start
Definition: dvbsubdec.c:133
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:32
thread.h
dvbsubdec_class
static const AVClass dvbsubdec_class
Definition: dvbsubdec.c:1741
get_region
static DVBSubRegion * get_region(DVBSubContext *ctx, int region_id)
Definition: dvbsubdec.c:165
rect
Definition: f_ebur128.c:91
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AVSubtitleRect
Definition: avcodec.h:2361
dvbsub_parse_region_segment
static int dvbsub_parse_region_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: dvbsubdec.c:1145
rect::y
int y
Definition: f_ebur128.c:91
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
DVBSubRegion::clut
int clut
Definition: dvbsubdec.c:97
DVBSubContext::compute_edt
int compute_edt
if 1 end display time calculated using pts if 0 (Default) calculated using time out
Definition: dvbsubdec.c:128
av_unused
#define av_unused
Definition: attributes.h:131
options
static const AVOption options[]
Definition: dvbsubdec.c:1735
w
uint8_t w
Definition: llviddspenc.c:39
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:365
DVBSUB_PAGE_SEGMENT
#define DVBSUB_PAGE_SEGMENT
Definition: dvbsubdec.c:31
AVOption
AVOption.
Definition: opt.h:248
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:142
DVBSubObject::display_list
DVBSubObjectDisplay * display_list
Definition: dvbsubdec.c:75
DVBSubObjectDisplay::y_pos
int y_pos
Definition: dvbsubdec.c:60
DVBSubDisplayDefinition::x
int x
Definition: dvbsubdec.c:115
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:196
YUV_TO_RGB1_CCIR
#define YUV_TO_RGB1_CCIR(cb1, cr1)
Definition: colorspace.h:34
delete_objects
static void delete_objects(DVBSubContext *ctx)
Definition: dvbsubdec.c:233
DVBSubContext::display_list
DVBSubRegionDisplay * display_list
Definition: dvbsubdec.c:138
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
DVBSubRegionDisplay::x_pos
int x_pos
Definition: dvbsubdec.c:83
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
compute_default_clut
static void compute_default_clut(DVBSubContext *ctx, uint8_t *clut, AVSubtitleRect *rect, int w, int h)
Definition: dvbsubdec.c:662
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
DVBSubObject::id
int id
Definition: dvbsubdec.c:70
OFFSET
#define OFFSET(x)
Definition: dvbsubdec.c:1734
get_object
static DVBSubObject * get_object(DVBSubContext *ctx, int object_id)
Definition: dvbsubdec.c:143
DVBSubRegion::pbuf
uint8_t * pbuf
Definition: dvbsubdec.c:103
fail
#define fail()
Definition: checkasm.h:134
GetBitContext
Definition: get_bits.h:61
DVBSubContext::substream
int substream
Definition: dvbsubdec.c:132
DVBSubRegion::bgcolor
int bgcolor
Definition: dvbsubdec.c:98
DVBSubRegionDisplay::region_id
int region_id
Definition: dvbsubdec.c:81
DVBSubContext::time_out
int time_out
Definition: dvbsubdec.c:127
av_image_check_size2
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:286
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:436
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:519
DVBSubContext::region_list
DVBSubRegion * region_list
Definition: dvbsubdec.c:134
colorspace.h
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
av_cold
#define av_cold
Definition: attributes.h:90
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
DVBSUB_DISPLAYDEFINITION_SEGMENT
#define DVBSUB_DISPLAYDEFINITION_SEGMENT
Definition: dvbsubdec.c:35
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:603
full_range
bool full_range
Definition: hwcontext_videotoolbox.c:37
V
#define V(x, y)
width
#define width
DVBSubRegion::display_list
DVBSubObjectDisplay * display_list
Definition: dvbsubdec.c:107
g
const char * g
Definition: vf_curves.c:117
bits
uint8_t bits
Definition: vp3data.h:141
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
DVBSubObjectDisplay::region_list_next
struct DVBSubObjectDisplay * region_list_next
Definition: dvbsubdec.c:65
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:202
ctx
AVFormatContext * ctx
Definition: movenc.c:48
get_bits.h
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
DVBSUB_CLUT_SEGMENT
#define DVBSUB_CLUT_SEGMENT
Definition: dvbsubdec.c:33
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1990
DVBSubObjectDisplay::region_id
int region_id
Definition: dvbsubdec.c:57
DVBSubDisplayDefinition::width
int width
Definition: dvbsubdec.c:117
f
#define f(width, name)
Definition: cbs_vp9.c:255
command
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:873
DVBSubContext::clut_list
DVBSubCLUT * clut_list
Definition: dvbsubdec.c:135
delete_regions
static void delete_regions(DVBSubContext *ctx)
Definition: dvbsubdec.c:244
DVBSUB_OBJECT_SEGMENT
#define DVBSUB_OBJECT_SEGMENT
Definition: dvbsubdec.c:34
DVBSubDisplayDefinition
Definition: dvbsubdec.c:112
dvbsub_decode
static int dvbsub_decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt)
Definition: dvbsubdec.c:1613
save_subtitle_set
static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
Definition: dvbsubdec.c:728
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:173
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
DVBSubRegion::id
int id
Definition: dvbsubdec.c:90
NULL
#define NULL
Definition: coverity.c:32
DVBSubCLUT
Definition: dvbsubdec.c:42
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
dvbsub_parse_display_definition_segment
static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: dvbsubdec.c:1553
dvbsub_close_decoder
static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
Definition: dvbsubdec.c:354
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
dvbsub_parse_clut_segment
static int dvbsub_parse_clut_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: dvbsubdec.c:1046
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
system
FFmpeg currently uses a custom build system
Definition: build_system.txt:1
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
dvbsub_parse_pixel_data_block
static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
Definition: dvbsubdec.c:864
DVBSubCLUT::clut256
uint32_t clut256[256]
Definition: dvbsubdec.c:48
DVBSUB_REGION_SEGMENT
#define DVBSUB_REGION_SEGMENT
Definition: dvbsubdec.c:32
list
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 list
Definition: filter_design.txt:25
DVBSubDisplayDefinition::y
int y
Definition: dvbsubdec.c:116
YUV_TO_RGB2_CCIR
#define YUV_TO_RGB2_CCIR(r, g, b, y1)
Definition: colorspace.h:55
DVBSubObject::type
int type
Definition: dvbsubdec.c:73
DVBSubCLUT::clut16
uint32_t clut16[16]
Definition: dvbsubdec.c:47
DVBSubCLUT::next
struct DVBSubCLUT * next
Definition: dvbsubdec.c:50
dvbsub_parse_object_segment
static int dvbsub_parse_object_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: dvbsubdec.c:982
DVBSubContext::compute_clut
int compute_clut
Definition: dvbsubdec.c:130
AVOnce
#define AVOnce
Definition: thread.h:172
dvbsub_read_2bit_string
static int dvbsub_read_2bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table, int x_pos)
Definition: dvbsubdec.c:377
DVBSubRegion::next
struct DVBSubRegion * next
Definition: dvbsubdec.c:109
dvbsub_display_end_segment
static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
Definition: dvbsubdec.c:1600
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
AVPacket::size
int size
Definition: packet.h:366
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
init_default_clut
static av_cold void init_default_clut(void)
Definition: dvbsubdec.c:258
DVBSubRegion
Definition: dvbsubdec.c:89
DVBSubRegion::buf_size
int buf_size
Definition: dvbsubdec.c:104
DVBSubCLUT::clut4
uint32_t clut4[4]
Definition: dvbsubdec.c:46
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
DVBSubObjectDisplay::fgcolor
int fgcolor
Definition: dvbsubdec.c:62
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
rect::h
int h
Definition: f_ebur128.c:91
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
DVBSubContext::display_definition
DVBSubDisplayDefinition * display_definition
Definition: dvbsubdec.c:139
DVBSubObject::version
int version
Definition: dvbsubdec.c:71
DVBSubRegion::dirty
int dirty
Definition: dvbsubdec.c:105
get_clut
static DVBSubCLUT * get_clut(DVBSubContext *ctx, int clut_id)
Definition: dvbsubdec.c:154
height
#define height
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
version
version
Definition: libkvazaar.c:306
rect::x
int x
Definition: f_ebur128.c:91
FF_COMPLIANCE_NORMAL
#define FF_COMPLIANCE_NORMAL
Definition: avcodec.h:1389
delete_region_display_list
static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
Definition: dvbsubdec.c:176
SUBTITLE_BITMAP
@ SUBTITLE_BITMAP
A bitmap, pict will be set.
Definition: avcodec.h:2344
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:192
DVBSubContext::composition_id
int composition_id
Definition: dvbsubdec.c:123
DVBSubRegion::depth
int depth
Definition: dvbsubdec.c:95
i
int i
Definition: input.c:407
DVBSubObject::next
struct DVBSubObject * next
Definition: dvbsubdec.c:77
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:602
DVBSubRegion::height
int height
Definition: dvbsubdec.c:94
DVBSubObjectDisplay::x_pos
int x_pos
Definition: dvbsubdec.c:59
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
FF_DEBUG_STARTCODE
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:1416
dvbsub_init_decoder
static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
Definition: dvbsubdec.c:323
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:243
DVBSubObject
Definition: dvbsubdec.c:69
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
AVCodecContext::height
int height
Definition: avcodec.h:674
avcodec.h
DVBSubRegion::has_computed_clut
int has_computed_clut
Definition: dvbsubdec.c:101
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
DVBSubRegionDisplay::y_pos
int y_pos
Definition: dvbsubdec.c:84
ret
ret
Definition: filter_design.txt:187
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:72
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1386
DVBSubRegion::version
int version
Definition: dvbsubdec.c:91
DVBSubRegion::computed_clut
uint8_t computed_clut[4 *256]
Definition: dvbsubdec.c:100
AVCodecContext
main external API structure.
Definition: avcodec.h:501
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
default_clut
static DVBSubCLUT default_clut
Definition: dvbsubdec.c:53
DVBSubContext::ancillary_id
int ancillary_id
Definition: dvbsubdec.c:124
DVBSubCLUT::version
int version
Definition: dvbsubdec.c:44
DS
#define DS
Definition: dvbsubdec.c:1733
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1408
DVBSubContext::clut_count2
int clut_count2[257][256]
Definition: dvbsubdec.c:131
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:84
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
DVBSubObjectDisplay::object_list_next
struct DVBSubObjectDisplay * object_list_next
Definition: dvbsubdec.c:66
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
DVBSubContext::object_list
DVBSubObject * object_list
Definition: dvbsubdec.c:136
AVPacket
This structure stores compressed data.
Definition: packet.h:342
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:528
DVBSubContext::version
int version
Definition: dvbsubdec.c:126
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:216
dvbsub_read_8bit_string
static int dvbsub_read_8bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table, int x_pos)
Definition: dvbsubdec.c:608
dvbsub_read_4bit_string
static int dvbsub_read_4bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len, const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table, int x_pos)
Definition: dvbsubdec.c:485
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:674
bytestream.h
RGBA
#define RGBA(r, g, b, a)
Definition: dvbsubdec.c:40
imgutils.h
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
dvbsub_parse_page_segment
static int dvbsub_parse_page_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
Definition: dvbsubdec.c:1293
h
h
Definition: vp9dsp_template.c:2038
DVBSubObjectDisplay
Definition: dvbsubdec.c:55
DVBSubObjectDisplay::bgcolor
int bgcolor
Definition: dvbsubdec.c:63
int
int
Definition: ffmpeg_filter.c:156
DVBSubCLUT::id
int id
Definition: dvbsubdec.c:43
ff_dvbsub_decoder
const AVCodec ff_dvbsub_decoder
Definition: dvbsubdec.c:1748
snprintf
#define snprintf
Definition: snprintf.h:34
DVBSubRegionDisplay::next
struct DVBSubRegionDisplay * next
Definition: dvbsubdec.c:86
DVBSubDisplayDefinition::height
int height
Definition: dvbsubdec.c:118
DVBSubContext
Definition: dvbsubdec.c:121
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98