FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dvbsubdec.c
Date: 2026-11-01 05:14:56
Exec Total Coverage
Lines: 480 850 56.5%
Functions: 19 23 82.6%
Branches: 271 597 45.4%

Line Branch Exec Source
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 "codec_internal.h"
26 #include "decode.h"
27 #include "libavutil/colorspace.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/thread.h"
32
33 #define DVBSUB_PAGE_SEGMENT 0x10
34 #define DVBSUB_REGION_SEGMENT 0x11
35 #define DVBSUB_CLUT_SEGMENT 0x12
36 #define DVBSUB_OBJECT_SEGMENT 0x13
37 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
38 #define DVBSUB_END_DISPLAY_SEGMENT 0x80
39
40 #define cm (ff_crop_tab + MAX_NEG_CROP)
41
42 #define RGBA(r,g,b,a) (((unsigned)(a) << 24) | ((r) << 16) | ((g) << 8) | (b))
43
44 typedef struct DVBSubCLUT {
45 int id;
46 int version;
47
48 uint32_t clut4[4];
49 uint32_t clut16[16];
50 uint32_t clut256[256];
51
52 struct DVBSubCLUT *next;
53 } DVBSubCLUT;
54
55 static DVBSubCLUT default_clut;
56
57 typedef struct DVBSubObjectDisplay {
58 int object_id;
59 int region_id;
60
61 int x_pos;
62 int y_pos;
63
64 int fgcolor;
65 int bgcolor;
66
67 struct DVBSubObjectDisplay *region_list_next;
68 struct DVBSubObjectDisplay *object_list_next;
69 } DVBSubObjectDisplay;
70
71 typedef struct DVBSubObject {
72 int id;
73 int version;
74
75 int type;
76
77 DVBSubObjectDisplay *display_list;
78
79 struct DVBSubObject *next;
80 } DVBSubObject;
81
82 typedef struct DVBSubRegionDisplay {
83 int region_id;
84
85 int x_pos;
86 int y_pos;
87
88 struct DVBSubRegionDisplay *next;
89 } DVBSubRegionDisplay;
90
91 typedef struct DVBSubRegion {
92 int id;
93 int version;
94
95 int width;
96 int height;
97 int depth;
98
99 int clut;
100 int bgcolor;
101
102 uint8_t computed_clut[4*256];
103 int has_computed_clut;
104
105 uint8_t *pbuf;
106 int buf_size;
107 int dirty;
108
109 DVBSubObjectDisplay *display_list;
110
111 struct DVBSubRegion *next;
112 } DVBSubRegion;
113
114 typedef struct DVBSubDisplayDefinition {
115 int version;
116
117 int x;
118 int y;
119 int width;
120 int height;
121 } DVBSubDisplayDefinition;
122
123 typedef struct DVBSubContext {
124 AVClass *class;
125 int composition_id;
126 int ancillary_id;
127
128 int version;
129 int time_out;
130 int compute_edt; /**< if 1 end display time calculated using pts
131 if 0 (Default) calculated using time out */
132 int compute_clut;
133 int clut_count2[257][256];
134 int substream;
135 int64_t prev_start;
136 DVBSubRegion *region_list;
137 DVBSubCLUT *clut_list;
138 DVBSubObject *object_list;
139
140 DVBSubRegionDisplay *display_list;
141 DVBSubDisplayDefinition *display_definition;
142 } DVBSubContext;
143
144
145 252 static DVBSubObject* get_object(DVBSubContext *ctx, int object_id)
146 {
147 252 DVBSubObject *ptr = ctx->object_list;
148
149
4/4
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 168 times.
324 while (ptr && ptr->id != object_id) {
150 72 ptr = ptr->next;
151 }
152
153 252 return ptr;
154 }
155
156 158 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
157 {
158 158 DVBSubCLUT *ptr = ctx->clut_list;
159
160
4/4
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 132 times.
230 while (ptr && ptr->id != clut_id) {
161 72 ptr = ptr->next;
162 }
163
164 158 return ptr;
165 }
166
167 546 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
168 {
169 546 DVBSubRegion *ptr = ctx->region_list;
170
171
4/4
✓ Branch 0 taken 1756 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 1266 times.
✓ Branch 3 taken 490 times.
1812 while (ptr && ptr->id != region_id) {
172 1266 ptr = ptr->next;
173 }
174
175 546 return ptr;
176 }
177
178 170 static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
179 {
180 DVBSubObject *object, *obj2, **obj2_ptr;
181 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
182
183
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 170 times.
254 while (region->display_list) {
184 84 display = region->display_list;
185
186 84 object = get_object(ctx, display->object_id);
187
188
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (object) {
189 84 obj_disp_ptr = &object->display_list;
190 84 obj_disp = *obj_disp_ptr;
191
192
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
84 while (obj_disp && obj_disp != display) {
193 ✗ obj_disp_ptr = &obj_disp->object_list_next;
194 ✗ obj_disp = *obj_disp_ptr;
195 }
196
197
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (obj_disp) {
198 84 *obj_disp_ptr = obj_disp->object_list_next;
199
200
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (!object->display_list) {
201 84 obj2_ptr = &ctx->object_list;
202 84 obj2 = *obj2_ptr;
203
204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 while (obj2 != object) {
205 ✗ av_assert0(obj2);
206 ✗ obj2_ptr = &obj2->next;
207 ✗ obj2 = *obj2_ptr;
208 }
209
210 84 *obj2_ptr = obj2->next;
211
212 84 av_freep(&obj2);
213 }
214 }
215 }
216
217 84 region->display_list = display->region_list_next;
218
219 84 av_freep(&display);
220 }
221
222 170 }
223
224 37 static void delete_cluts(DVBSubContext *ctx)
225 {
226
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 37 times.
63 while (ctx->clut_list) {
227 26 DVBSubCLUT *clut = ctx->clut_list;
228
229 26 ctx->clut_list = clut->next;
230
231 26 av_freep(&clut);
232 }
233 37 }
234
235 37 static void delete_objects(DVBSubContext *ctx)
236 {
237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 while (ctx->object_list) {
238 ✗ DVBSubObject *object = ctx->object_list;
239
240 ✗ ctx->object_list = object->next;
241
242 ✗ av_freep(&object);
243 }
244 37 }
245
246 37 static void delete_regions(DVBSubContext *ctx)
247 {
248
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 37 times.
93 while (ctx->region_list) {
249 56 DVBSubRegion *region = ctx->region_list;
250
251 56 ctx->region_list = region->next;
252
253 56 delete_region_display_list(ctx, region);
254
255 56 av_freep(&region->pbuf);
256 56 av_freep(&region);
257 }
258 37 }
259
260 10 static av_cold void init_default_clut(void)
261 {
262 10 int i, r, g, b, a = 0;
263
264 10 default_clut.id = -1;
265 10 default_clut.next = NULL;
266
267 10 default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
268 10 default_clut.clut4[1] = RGBA(255, 255, 255, 255);
269 10 default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
270 10 default_clut.clut4[3] = RGBA(127, 127, 127, 255);
271
272 10 default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
273
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 10 times.
160 for (i = 1; i < 16; i++) {
274
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 80 times.
150 if (i < 8) {
275
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 r = (i & 1) ? 255 : 0;
276
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 g = (i & 2) ? 255 : 0;
277
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 b = (i & 4) ? 255 : 0;
278 } else {
279
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 40 times.
80 r = (i & 1) ? 127 : 0;
280
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 40 times.
80 g = (i & 2) ? 127 : 0;
281
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 40 times.
80 b = (i & 4) ? 127 : 0;
282 }
283 150 default_clut.clut16[i] = RGBA(r, g, b, 255);
284 }
285
286 10 default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
287
2/2
✓ Branch 0 taken 2550 times.
✓ Branch 1 taken 10 times.
2560 for (i = 1; i < 256; i++) {
288
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 2480 times.
2550 if (i < 8) {
289
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 r = (i & 1) ? 255 : 0;
290
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 g = (i & 2) ? 255 : 0;
291
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 30 times.
70 b = (i & 4) ? 255 : 0;
292 70 a = 63;
293 } else {
294
4/5
✓ Branch 0 taken 560 times.
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 640 times.
✓ Branch 3 taken 640 times.
✗ Branch 4 not taken.
2480 switch (i & 0x88) {
295 560 case 0x00:
296
4/4
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 280 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 240 times.
560 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
297
4/4
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 280 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 240 times.
560 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
298
4/4
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 280 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 240 times.
560 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
299 560 a = 255;
300 560 break;
301 640 case 0x08:
302
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
303
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
304
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
305 640 a = 127;
306 640 break;
307 640 case 0x80:
308
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
309
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
310
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
311 640 a = 255;
312 640 break;
313 640 case 0x88:
314
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
315
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
316
4/4
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 320 times.
640 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
317 640 a = 255;
318 640 break;
319 }
320 }
321 2550 default_clut.clut256[i] = RGBA(r, g, b, a);
322 }
323 10 }
324
325 23 static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
326 {
327 static AVOnce init_static_once = AV_ONCE_INIT;
328 23 DVBSubContext *ctx = avctx->priv_data;
329
330
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 if (ctx->substream < 0) {
331 23 ctx->composition_id = -1;
332 23 ctx->ancillary_id = -1;
333 ✗ } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
334 ✗ av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
335 ✗ ctx->composition_id = -1;
336 ✗ ctx->ancillary_id = -1;
337 } else {
338 ✗ if (avctx->extradata_size > 5*ctx->substream + 2) {
339 ✗ ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream);
340 ✗ ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2);
341 } else {
342 ✗ av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream);
343 ✗ ctx->composition_id = AV_RB16(avctx->extradata);
344 ✗ ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
345 }
346 }
347
348 23 ctx->version = -1;
349 23 ctx->prev_start = AV_NOPTS_VALUE;
350
351 23 ff_thread_once(&init_static_once, init_default_clut);
352
353 23 return 0;
354 }
355
356 23 static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
357 {
358 23 DVBSubContext *ctx = avctx->priv_data;
359 DVBSubRegionDisplay *display;
360
361 23 delete_regions(ctx);
362
363 23 delete_objects(ctx);
364
365 23 delete_cluts(ctx);
366
367 23 av_freep(&ctx->display_definition);
368
369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
23 while (ctx->display_list) {
370 ✗ display = ctx->display_list;
371 ✗ ctx->display_list = display->next;
372
373 ✗ av_freep(&display);
374 }
375
376 23 return 0;
377 }
378
379 ✗ static int dvbsub_read_2bit_string(AVCodecContext *avctx,
380 uint8_t *destbuf, int dbuf_len,
381 const uint8_t **srcbuf, int buf_size,
382 int non_mod, uint8_t *map_table, int x_pos)
383 {
384 GetBitContext gb;
385
386 int bits;
387 int run_length;
388 ✗ int pixels_read = x_pos;
389
390 ✗ init_get_bits(&gb, *srcbuf, buf_size << 3);
391
392 ✗ destbuf += x_pos;
393
394 ✗ while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
395 ✗ bits = get_bits(&gb, 2);
396
397 ✗ if (bits) {
398 ✗ if (non_mod != 1 || bits != 1) {
399 ✗ if (map_table)
400 ✗ *destbuf++ = map_table[bits];
401 else
402 ✗ *destbuf++ = bits;
403 }
404 ✗ pixels_read++;
405 } else {
406 ✗ bits = get_bits1(&gb);
407 ✗ if (bits == 1) {
408 ✗ run_length = get_bits(&gb, 3) + 3;
409 ✗ bits = get_bits(&gb, 2);
410
411 ✗ if (non_mod == 1 && bits == 1)
412 ✗ pixels_read += run_length;
413 else {
414 ✗ if (map_table)
415 ✗ bits = map_table[bits];
416 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
417 ✗ *destbuf++ = bits;
418 ✗ pixels_read++;
419 }
420 }
421 } else {
422 ✗ bits = get_bits1(&gb);
423 ✗ if (bits == 0) {
424 ✗ bits = get_bits(&gb, 2);
425 ✗ if (bits == 2) {
426 ✗ run_length = get_bits(&gb, 4) + 12;
427 ✗ bits = get_bits(&gb, 2);
428
429 ✗ if (non_mod == 1 && bits == 1)
430 ✗ pixels_read += run_length;
431 else {
432 ✗ if (map_table)
433 ✗ bits = map_table[bits];
434 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
435 ✗ *destbuf++ = bits;
436 ✗ pixels_read++;
437 }
438 }
439 ✗ } else if (bits == 3) {
440 ✗ run_length = get_bits(&gb, 8) + 29;
441 ✗ bits = get_bits(&gb, 2);
442
443 ✗ if (non_mod == 1 && bits == 1)
444 ✗ pixels_read += run_length;
445 else {
446 ✗ if (map_table)
447 ✗ bits = map_table[bits];
448 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
449 ✗ *destbuf++ = bits;
450 ✗ pixels_read++;
451 }
452 }
453 ✗ } else if (bits == 1) {
454 ✗ if (map_table)
455 ✗ bits = map_table[0];
456 else
457 ✗ bits = 0;
458 ✗ run_length = 2;
459 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
460 ✗ *destbuf++ = bits;
461 ✗ pixels_read++;
462 }
463 } else {
464 ✗ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
465 ✗ return pixels_read;
466 }
467 } else {
468 ✗ if (map_table)
469 ✗ bits = map_table[0];
470 else
471 ✗ bits = 0;
472 ✗ *destbuf++ = bits;
473 ✗ pixels_read++;
474 }
475 }
476 }
477 }
478
479 ✗ if (get_bits(&gb, 6))
480 ✗ av_log(avctx, AV_LOG_ERROR, "line overflow\n");
481
482 ✗ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
483
484 ✗ return pixels_read;
485 }
486
487 3024 static int dvbsub_read_4bit_string(AVCodecContext *avctx, uint8_t *destbuf, int dbuf_len,
488 const uint8_t **srcbuf, int buf_size,
489 int non_mod, uint8_t *map_table, int x_pos)
490 {
491 GetBitContext gb;
492
493 int bits;
494 int run_length;
495 3024 int pixels_read = x_pos;
496
497 3024 init_get_bits(&gb, *srcbuf, buf_size << 3);
498
499 3024 destbuf += x_pos;
500
501
2/4
✓ Branch 1 taken 140208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 140208 times.
✗ Branch 4 not taken.
140208 while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
502 140208 bits = get_bits(&gb, 4);
503
504
2/2
✓ Branch 0 taken 124470 times.
✓ Branch 1 taken 15738 times.
140208 if (bits) {
505
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 124470 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
124470 if (non_mod != 1 || bits != 1) {
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 124470 times.
124470 if (map_table)
507 ✗ *destbuf++ = map_table[bits];
508 else
509 124470 *destbuf++ = bits;
510 }
511 124470 pixels_read++;
512 } else {
513 15738 bits = get_bits1(&gb);
514
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12714 times.
15738 if (bits == 0) {
515 3024 run_length = get_bits(&gb, 3);
516
517
1/2
✓ Branch 0 taken 3024 times.
✗ Branch 1 not taken.
3024 if (run_length == 0) {
518 3024 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
519 3024 return pixels_read;
520 }
521
522 ✗ run_length += 2;
523
524 ✗ if (map_table)
525 ✗ bits = map_table[0];
526 else
527 ✗ bits = 0;
528
529 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
530 ✗ *destbuf++ = bits;
531 ✗ pixels_read++;
532 }
533 } else {
534 12714 bits = get_bits1(&gb);
535
2/2
✓ Branch 0 taken 7076 times.
✓ Branch 1 taken 5638 times.
12714 if (bits == 0) {
536 7076 run_length = get_bits(&gb, 2) + 4;
537 7076 bits = get_bits(&gb, 4);
538
539
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7076 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7076 if (non_mod == 1 && bits == 1)
540 ✗ pixels_read += run_length;
541 else {
542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7076 times.
7076 if (map_table)
543 ✗ bits = map_table[bits];
544
3/4
✓ Branch 0 taken 34674 times.
✓ Branch 1 taken 7076 times.
✓ Branch 2 taken 34674 times.
✗ Branch 3 not taken.
41750 while (run_length-- > 0 && pixels_read < dbuf_len) {
545 34674 *destbuf++ = bits;
546 34674 pixels_read++;
547 }
548 }
549 } else {
550 5638 bits = get_bits(&gb, 2);
551
2/2
✓ Branch 0 taken 3482 times.
✓ Branch 1 taken 2156 times.
5638 if (bits == 2) {
552 3482 run_length = get_bits(&gb, 4) + 9;
553 3482 bits = get_bits(&gb, 4);
554
555
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3482 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3482 if (non_mod == 1 && bits == 1)
556 ✗ pixels_read += run_length;
557 else {
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3482 times.
3482 if (map_table)
559 ✗ bits = map_table[bits];
560
3/4
✓ Branch 0 taken 42732 times.
✓ Branch 1 taken 3482 times.
✓ Branch 2 taken 42732 times.
✗ Branch 3 not taken.
46214 while (run_length-- > 0 && pixels_read < dbuf_len) {
561 42732 *destbuf++ = bits;
562 42732 pixels_read++;
563 }
564 }
565
1/2
✓ Branch 0 taken 2156 times.
✗ Branch 1 not taken.
2156 } else if (bits == 3) {
566 2156 run_length = get_bits(&gb, 8) + 25;
567 2156 bits = get_bits(&gb, 4);
568
569
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2156 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2156 if (non_mod == 1 && bits == 1)
570 ✗ pixels_read += run_length;
571 else {
572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2156 times.
2156 if (map_table)
573 ✗ bits = map_table[bits];
574
3/4
✓ Branch 0 taken 181884 times.
✓ Branch 1 taken 2156 times.
✓ Branch 2 taken 181884 times.
✗ Branch 3 not taken.
184040 while (run_length-- > 0 && pixels_read < dbuf_len) {
575 181884 *destbuf++ = bits;
576 181884 pixels_read++;
577 }
578 }
579 ✗ } else if (bits == 1) {
580 ✗ if (map_table)
581 ✗ bits = map_table[0];
582 else
583 ✗ bits = 0;
584 ✗ run_length = 2;
585 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
586 ✗ *destbuf++ = bits;
587 ✗ pixels_read++;
588 }
589 } else {
590 ✗ if (map_table)
591 ✗ bits = map_table[0];
592 else
593 ✗ bits = 0;
594 ✗ *destbuf++ = bits;
595 ✗ pixels_read ++;
596 }
597 }
598 }
599 }
600 }
601
602 ✗ if (get_bits(&gb, 8))
603 ✗ av_log(avctx, AV_LOG_ERROR, "line overflow\n");
604
605 ✗ (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
606
607 ✗ return pixels_read;
608 }
609
610 ✗ static int dvbsub_read_8bit_string(AVCodecContext *avctx,
611 uint8_t *destbuf, int dbuf_len,
612 const uint8_t **srcbuf, int buf_size,
613 int non_mod, uint8_t *map_table, int x_pos)
614 {
615 int bits;
616 int run_length;
617 ✗ int pixels_read = x_pos;
618 ✗ GetByteContext gb0, *const gb = &gb0;
619
620 ✗ bytestream2_init(gb, *srcbuf, buf_size);
621 ✗ destbuf += x_pos;
622
623 ✗ while (bytestream2_get_bytes_left(gb) && pixels_read < dbuf_len) {
624 ✗ bits = bytestream2_get_byteu(gb);
625
626 ✗ if (bits) {
627 ✗ if (non_mod != 1 || bits != 1) {
628 ✗ if (map_table)
629 ✗ *destbuf++ = map_table[bits];
630 else
631 ✗ *destbuf++ = bits;
632 }
633 ✗ pixels_read++;
634 } else {
635 ✗ bits = bytestream2_get_byte(gb);
636 ✗ run_length = bits & 0x7f;
637 ✗ if ((bits & 0x80) == 0) {
638 ✗ if (run_length == 0) {
639 ✗ *srcbuf += bytestream2_tell(gb);
640 ✗ return pixels_read;
641 }
642
643 ✗ bits = 0;
644 } else {
645 ✗ bits = bytestream2_get_byte(gb);
646 }
647 ✗ if (non_mod == 1 && bits == 1)
648 ✗ pixels_read += run_length;
649 else {
650 ✗ if (map_table)
651 ✗ bits = map_table[bits];
652 ✗ while (run_length-- > 0 && pixels_read < dbuf_len) {
653 ✗ *destbuf++ = bits;
654 ✗ pixels_read++;
655 }
656 }
657 }
658 }
659
660 ✗ if (bytestream2_get_byte(gb))
661 ✗ av_log(avctx, AV_LOG_ERROR, "line overflow\n");
662
663 /* Workaround our own buggy encoder which only put one zero at the end */
664 ✗ if (!bytestream2_peek_byte(gb))
665 ✗ bytestream2_get_byte(gb);
666
667 ✗ *srcbuf += bytestream2_tell(gb);
668 ✗ return pixels_read;
669 }
670
671 ✗ static void compute_default_clut(DVBSubContext *ctx, uint8_t *clut, AVSubtitleRect *rect, int w, int h)
672 {
673 ✗ uint8_t list[256] = {0};
674 uint8_t list_inv[256];
675 ✗ int counttab[256] = {0};
676 ✗ int (*counttab2)[256] = ctx->clut_count2;
677 int count, i, x, y;
678 ✗ ptrdiff_t stride = rect->linesize[0];
679
680 ✗ memset(ctx->clut_count2, 0 , sizeof(ctx->clut_count2));
681
682 #define V(x,y) rect->data[0][(x) + (y)*stride]
683 ✗ for (y = 0; y<h; y++) {
684 ✗ for (x = 0; x<w; x++) {
685 ✗ int v = V(x,y) + 1;
686 ✗ int vl = x ? V(x-1,y) + 1 : 0;
687 ✗ int vr = x+1<w ? V(x+1,y) + 1 : 0;
688 ✗ int vt = y ? V(x,y-1) + 1 : 0;
689 ✗ int vb = y+1<h ? V(x,y+1) + 1 : 0;
690 ✗ counttab[v-1] += !!((v!=vl) + (v!=vr) + (v!=vt) + (v!=vb));
691 ✗ counttab2[vl][v-1] ++;
692 ✗ counttab2[vr][v-1] ++;
693 ✗ counttab2[vt][v-1] ++;
694 ✗ counttab2[vb][v-1] ++;
695 }
696 }
697 #define L(x,y) list[d[(x) + (y)*stride]]
698
699 ✗ for (i = 0; i<256; i++) {
700 ✗ counttab2[i+1][i] = 0;
701 }
702 ✗ for (i = 0; i<256; i++) {
703 ✗ int bestscore = 0;
704 ✗ int bestv = 0;
705
706 ✗ for (x = 0; x < 256; x++) {
707 ✗ int scorev = 0;
708 ✗ if (list[x])
709 ✗ continue;
710 ✗ scorev += counttab2[0][x];
711 ✗ for (y = 0; y < 256; y++) {
712 ✗ scorev += list[y] * counttab2[y+1][x];
713 }
714
715 ✗ if (scorev) {
716 ✗ int score = 1024LL*scorev / counttab[x];
717 ✗ if (score > bestscore) {
718 ✗ bestscore = score;
719 ✗ bestv = x;
720 }
721 }
722 }
723 ✗ if (!bestscore)
724 ✗ break;
725 ✗ list [ bestv ] = 1;
726 ✗ list_inv[ i ] = bestv;
727 }
728
729 ✗ count = FFMAX(i - 1, 1);
730 ✗ for (i--; i >= 0; i--) {
731 ✗ int v = i * 255 / count;
732 ✗ AV_WN32(clut + 4*list_inv[i], RGBA(v/2,v,v/2,v));
733 }
734 ✗ }
735
736
737 92 static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_output)
738 {
739 92 DVBSubContext *ctx = avctx->priv_data;
740 DVBSubRegionDisplay *display;
741 92 DVBSubDisplayDefinition *display_def = ctx->display_definition;
742 DVBSubRegion *region;
743 AVSubtitleRect *rect;
744 const DVBSubCLUT *clut;
745 const uint32_t *clut_table;
746 int i;
747 92 int offset_x=0, offset_y=0;
748 92 int ret = 0;
749
750
751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (display_def) {
752 ✗ offset_x = display_def->x;
753 ✗ offset_y = display_def->y;
754 }
755
756 /* Not touching AVSubtitles again*/
757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (sub->num_rects) {
758 ✗ avpriv_request_sample(ctx, "Different Version of Segment asked Twice");
759 ✗ return AVERROR_PATCHWELCOME;
760 }
761
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 92 times.
224 for (display = ctx->display_list; display; display = display->next) {
762 132 region = get_region(ctx, display->region_id);
763
2/4
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
132 if (region && region->dirty)
764 132 sub->num_rects++;
765 }
766
767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (ctx->compute_edt == 0) {
768 ✗ sub->end_display_time = ctx->time_out * 1000;
769 ✗ *got_output = 1;
770
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 2 times.
92 } else if (ctx->prev_start != AV_NOPTS_VALUE) {
771 90 sub->end_display_time = av_rescale_q((sub->pts - ctx->prev_start ), AV_TIME_BASE_Q, (AVRational){ 1, 1000 }) - 1;
772 90 *got_output = 1;
773 }
774
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 20 times.
92 if (sub->num_rects > 0) {
775
776 72 sub->rects = av_calloc(sub->num_rects, sizeof(*sub->rects));
777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (!sub->rects) {
778 ✗ ret = AVERROR(ENOMEM);
779 ✗ goto fail;
780 }
781
782
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 72 times.
204 for (i = 0; i < sub->num_rects; i++) {
783 132 sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!sub->rects[i]) {
785 ✗ ret = AVERROR(ENOMEM);
786 ✗ goto fail;
787 }
788 }
789
790 72 i = 0;
791
792
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 72 times.
204 for (display = ctx->display_list; display; display = display->next) {
793 132 region = get_region(ctx, display->region_id);
794
795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!region)
796 ✗ continue;
797
798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!region->dirty)
799 ✗ continue;
800
801 132 rect = sub->rects[i];
802 132 rect->x = display->x_pos + offset_x;
803 132 rect->y = display->y_pos + offset_y;
804 132 rect->w = region->width;
805 132 rect->h = region->height;
806 132 rect->nb_colors = (1 << region->depth);
807 132 rect->type = SUBTITLE_BITMAP;
808 132 rect->linesize[0] = region->width;
809
810 132 clut = get_clut(ctx, region->clut);
811
812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!clut)
813 ✗ clut = &default_clut;
814
815
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
132 switch (region->depth) {
816 ✗ case 2:
817 ✗ clut_table = clut->clut4;
818 ✗ break;
819 ✗ case 8:
820 ✗ clut_table = clut->clut256;
821 ✗ break;
822 132 case 4:
823 default:
824 132 clut_table = clut->clut16;
825 132 break;
826 }
827
828 132 rect->data[1] = av_mallocz(AVPALETTE_SIZE);
829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!rect->data[1]) {
830 ✗ ret = AVERROR(ENOMEM);
831 ✗ goto fail;
832 }
833 132 memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(*clut_table));
834
835 132 rect->data[0] = av_memdup(region->pbuf, region->buf_size);
836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (!rect->data[0]) {
837 ✗ ret = AVERROR(ENOMEM);
838 ✗ goto fail;
839 }
840
841
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 132 times.
132 if ((clut == &default_clut && ctx->compute_clut < 0) || ctx->compute_clut == 1) {
842 ✗ if (!region->has_computed_clut) {
843 ✗ compute_default_clut(ctx, region->computed_clut, rect, rect->w, rect->h);
844 ✗ region->has_computed_clut = 1;
845 }
846
847 ✗ memcpy(rect->data[1], region->computed_clut, sizeof(region->computed_clut));
848 }
849
850 132 i++;
851 }
852 }
853
854 92 return 0;
855 ✗ fail:
856 ✗ if (sub->rects) {
857 ✗ for (i=0; i < sub->num_rects; i++) {
858 ✗ rect = sub->rects[i];
859 ✗ if (rect) {
860 ✗ av_freep(&rect->data[0]);
861 ✗ av_freep(&rect->data[1]);
862 }
863 ✗ av_freep(&sub->rects[i]);
864 }
865 ✗ av_freep(&sub->rects);
866 }
867 ✗ sub->num_rects = 0;
868 ✗ return ret;
869 }
870
871 168 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
872 const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
873 {
874 168 DVBSubContext *ctx = avctx->priv_data;
875
876 168 DVBSubRegion *region = get_region(ctx, display->region_id);
877 168 const uint8_t *buf_end = buf + buf_size;
878 uint8_t *pbuf;
879 int x_pos, y_pos;
880 int i;
881
882 168 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
883 168 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
884 168 uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
885 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
886 uint8_t *map_table;
887
888 #if 0
889 ff_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
890 top_bottom ? "bottom" : "top");
891
892 for (i = 0; i < buf_size; i++) {
893 if (i % 16 == 0)
894 ff_dlog(avctx, "0x%8p: ", buf+i);
895
896 ff_dlog(avctx, "%02x ", buf[i]);
897 if (i % 16 == 15)
898 ff_dlog(avctx, "\n");
899 }
900
901 if (i % 16)
902 ff_dlog(avctx, "\n");
903 #endif
904
905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if (!region)
906 ✗ return;
907
908 168 pbuf = region->pbuf;
909 168 region->dirty = 1;
910
911 168 x_pos = display->x_pos;
912 168 y_pos = display->y_pos;
913
914 168 y_pos += top_bottom;
915
916
2/2
✓ Branch 0 taken 6048 times.
✓ Branch 1 taken 168 times.
6216 while (buf < buf_end) {
917
4/6
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 3024 times.
✓ Branch 2 taken 3024 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6048 times.
6048 if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) {
918 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf);
919 ✗ return;
920 }
921
922
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 3024 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 3024 times.
✗ Branch 7 not taken.
6048 switch (*buf++) {
923 ✗ case 0x10:
924 ✗ if (region->depth == 8)
925 ✗ map_table = map2to8;
926 ✗ else if (region->depth == 4)
927 ✗ map_table = map2to4;
928 else
929 ✗ map_table = NULL;
930
931 ✗ x_pos = dvbsub_read_2bit_string(avctx, pbuf + (y_pos * region->width),
932 ✗ region->width, &buf, buf_end - buf,
933 non_mod, map_table, x_pos);
934 ✗ break;
935 3024 case 0x11:
936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3024 times.
3024 if (region->depth < 4) {
937 ✗ av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
938 ✗ return;
939 }
940
941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3024 times.
3024 if (region->depth == 8)
942 ✗ map_table = map4to8;
943 else
944 3024 map_table = NULL;
945
946 3024 x_pos = dvbsub_read_4bit_string(avctx, pbuf + (y_pos * region->width),
947 3024 region->width, &buf, buf_end - buf,
948 non_mod, map_table, x_pos);
949 3024 break;
950 ✗ case 0x12:
951 ✗ if (region->depth < 8) {
952 ✗ av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
953 ✗ return;
954 }
955
956 ✗ x_pos = dvbsub_read_8bit_string(avctx, pbuf + (y_pos * region->width),
957 ✗ region->width, &buf, buf_end - buf,
958 non_mod, NULL, x_pos);
959 ✗ break;
960
961 ✗ case 0x20:
962 ✗ map2to4[0] = (*buf) >> 4;
963 ✗ map2to4[1] = (*buf++) & 0xf;
964 ✗ map2to4[2] = (*buf) >> 4;
965 ✗ map2to4[3] = (*buf++) & 0xf;
966 ✗ break;
967 ✗ case 0x21:
968 ✗ for (i = 0; i < 4; i++)
969 ✗ map2to8[i] = *buf++;
970 ✗ break;
971 ✗ case 0x22:
972 ✗ for (i = 0; i < 16; i++)
973 ✗ map4to8[i] = *buf++;
974 ✗ break;
975
976 3024 case 0xf0:
977 3024 x_pos = display->x_pos;
978 3024 y_pos += 2;
979 3024 break;
980 ✗ default:
981 ✗ av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
982 }
983 }
984
985
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (ctx->compute_clut != -2)
986 168 region->has_computed_clut = 0;
987 }
988
989 84 static int dvbsub_parse_object_segment(AVCodecContext *avctx,
990 const uint8_t *buf, int buf_size)
991 {
992 84 DVBSubContext *ctx = avctx->priv_data;
993
994 84 const uint8_t *buf_end = buf + buf_size;
995 int object_id;
996 DVBSubObject *object;
997 DVBSubObjectDisplay *display;
998 int top_field_len, bottom_field_len;
999
1000 int coding_method, non_modifying_color;
1001
1002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (buf_size < 3)
1003 ✗ return AVERROR_INVALIDDATA;
1004
1005 84 object_id = AV_RB16(buf);
1006 84 buf += 2;
1007
1008 84 object = get_object(ctx, object_id);
1009
1010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (!object)
1011 ✗ return AVERROR_INVALIDDATA;
1012
1013 84 coding_method = ((*buf) >> 2) & 3;
1014 84 non_modifying_color = ((*buf++) >> 1) & 1;
1015
1016
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (coding_method == 0) {
1017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (buf_end - buf < 4)
1018 ✗ return AVERROR_INVALIDDATA;
1019 84 top_field_len = AV_RB16(buf);
1020 84 buf += 2;
1021 84 bottom_field_len = AV_RB16(buf);
1022 84 buf += 2;
1023
1024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (buf + top_field_len + bottom_field_len > buf_end) {
1025 ✗ av_log(avctx, AV_LOG_ERROR, "Field data size %d+%d too large\n", top_field_len, bottom_field_len);
1026 ✗ return AVERROR_INVALIDDATA;
1027 }
1028
1029
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 84 times.
168 for (display = object->display_list; display; display = display->object_list_next) {
1030 84 const uint8_t *block = buf;
1031 84 int bfl = bottom_field_len;
1032
1033 84 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
1034 non_modifying_color);
1035
1036
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (bottom_field_len > 0)
1037 84 block = buf + top_field_len;
1038 else
1039 ✗ bfl = top_field_len;
1040
1041 84 dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1,
1042 non_modifying_color);
1043 }
1044 ✗ } else if (coding_method == 1) {
1045 ✗ avpriv_report_missing_feature(avctx, "coded as a string of characters");
1046 ✗ return AVERROR_PATCHWELCOME;
1047 ✗ } else if (coding_method == 2) {
1048 ✗ avpriv_report_missing_feature(avctx, "progressive coding of pixels");
1049 ✗ return AVERROR_PATCHWELCOME;
1050 } else {
1051 ✗ av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
1052 ✗ return AVERROR_INVALIDDATA;
1053 }
1054
1055 84 return 0;
1056 }
1057
1058 26 static int dvbsub_parse_clut_segment(AVCodecContext *avctx,
1059 const uint8_t *buf, int buf_size)
1060 {
1061 26 DVBSubContext *ctx = avctx->priv_data;
1062
1063 26 const uint8_t *buf_end = buf + buf_size;
1064 int i, clut_id;
1065 int version;
1066 DVBSubCLUT *clut;
1067 int entry_id, depth , full_range;
1068 int y, cr, cb, alpha;
1069 int r, g, b, r_add, g_add, b_add;
1070
1071 ff_dlog(avctx, "DVB clut packet:\n");
1072
1073
2/2
✓ Branch 0 taken 1456 times.
✓ Branch 1 taken 26 times.
1482 for (i=0; i < buf_size; i++) {
1074 ff_dlog(avctx, "%02x ", buf[i]);
1075 1456 if (i % 16 == 15)
1076 ff_dlog(avctx, "\n");
1077 }
1078
1079 26 if (i % 16)
1080 ff_dlog(avctx, "\n");
1081
1082 26 clut_id = *buf++;
1083 26 version = ((*buf)>>4)&15;
1084 26 buf += 1;
1085
1086 26 clut = get_clut(ctx, clut_id);
1087
1088
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (!clut) {
1089 26 clut = av_memdup(&default_clut, sizeof(*clut));
1090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (!clut)
1091 ✗ return AVERROR(ENOMEM);
1092
1093 26 clut->id = clut_id;
1094 26 clut->version = -1;
1095
1096 26 clut->next = ctx->clut_list;
1097 26 ctx->clut_list = clut;
1098 }
1099
1100
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (clut->version != version) {
1101
1102 26 clut->version = version;
1103
1104
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 26 times.
260 while (buf + 4 < buf_end) {
1105 234 entry_id = *buf++;
1106
1107 234 depth = (*buf) & 0xe0;
1108
1109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (depth == 0) {
1110 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
1111 }
1112
1113 234 full_range = (*buf++) & 1;
1114
1115
1/2
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
234 if (full_range) {
1116 234 y = *buf++;
1117 234 cr = *buf++;
1118 234 cb = *buf++;
1119 234 alpha = *buf++;
1120 } else {
1121 ✗ y = buf[0] & 0xfc;
1122 ✗ cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
1123 ✗ cb = (buf[1] << 2) & 0xf0;
1124 ✗ alpha = (buf[1] << 6) & 0xc0;
1125
1126 ✗ buf += 2;
1127 }
1128
1129
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 208 times.
234 if (y == 0)
1130 26 alpha = 0xff;
1131
1132 234 YUV_TO_RGB1_CCIR(cb, cr);
1133 234 YUV_TO_RGB2_CCIR(r, g, b, y);
1134
1135 ff_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
1136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (!!(depth & 0x80) + !!(depth & 0x40) + !!(depth & 0x20) > 1) {
1137 ff_dlog(avctx, "More than one bit level marked: %x\n", depth);
1138 ✗ if (avctx->strict_std_compliance > FF_COMPLIANCE_NORMAL)
1139 ✗ return AVERROR_INVALIDDATA;
1140 }
1141
1142
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
234 if (depth & 0x80 && entry_id < 4)
1143 ✗ clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
1144
2/4
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 234 times.
✗ Branch 3 not taken.
234 else if (depth & 0x40 && entry_id < 16)
1145 234 clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
1146 ✗ else if (depth & 0x20)
1147 ✗ clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
1148 }
1149 }
1150
1151 26 return 0;
1152 }
1153
1154
1155 114 static int dvbsub_parse_region_segment(AVCodecContext *avctx,
1156 const uint8_t *buf, int buf_size)
1157 {
1158 114 DVBSubContext *ctx = avctx->priv_data;
1159
1160 114 const uint8_t *buf_end = buf + buf_size;
1161 int region_id, object_id;
1162 av_unused int version;
1163 DVBSubRegion *region;
1164 DVBSubObject *object;
1165 DVBSubObjectDisplay *display;
1166 int fill;
1167 int ret;
1168
1169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (buf_size < 10)
1170 ✗ return AVERROR_INVALIDDATA;
1171
1172 114 region_id = *buf++;
1173
1174 114 region = get_region(ctx, region_id);
1175
1176
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 58 times.
114 if (!region) {
1177 56 region = av_mallocz(sizeof(*region));
1178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (!region)
1179 ✗ return AVERROR(ENOMEM);
1180
1181 56 region->id = region_id;
1182 56 region->version = -1;
1183
1184 56 region->next = ctx->region_list;
1185 56 ctx->region_list = region;
1186 }
1187
1188 114 version = ((*buf)>>4) & 15;
1189 114 fill = ((*buf++) >> 3) & 1;
1190
1191 114 region->width = AV_RB16(buf);
1192 114 buf += 2;
1193 114 region->height = AV_RB16(buf);
1194 114 buf += 2;
1195
1196 114 ret = av_image_check_size2(region->width, region->height, avctx->max_pixels, AV_PIX_FMT_PAL8, 0, avctx);
1197
2/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if (ret >= 0 && region->width * region->height > 320 * 1024 * 8 / 2) {
1198 ✗ ret = AVERROR_INVALIDDATA;
1199 ✗ av_log(avctx, AV_LOG_ERROR, "Pixel buffer memory constraint violated\n");
1200 }
1201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (ret < 0) {
1202 ✗ region->width= region->height= 0;
1203 ✗ return ret;
1204 }
1205
1206
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 58 times.
114 if (region->width * region->height != region->buf_size) {
1207 56 av_free(region->pbuf);
1208
1209 56 region->buf_size = region->width * region->height;
1210
1211 56 region->pbuf = av_malloc(region->buf_size);
1212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (!region->pbuf) {
1213 ✗ region->buf_size =
1214 ✗ region->width =
1215 ✗ region->height = 0;
1216 ✗ return AVERROR(ENOMEM);
1217 }
1218
1219 56 fill = 1;
1220 56 region->dirty = 0;
1221 }
1222
1223 114 region->depth = 1 << (((*buf++) >> 2) & 7);
1224
2/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if (region->depth < 2 || region->depth > 8) {
1225 ✗ av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth);
1226 ✗ region->depth= 4;
1227 }
1228 114 region->clut = *buf++;
1229
1230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (region->depth == 8) {
1231 ✗ region->bgcolor = *buf++;
1232 ✗ buf += 1;
1233 } else {
1234 114 buf += 1;
1235
1236
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if (region->depth == 4)
1237 114 region->bgcolor = (((*buf++) >> 4) & 15);
1238 else
1239 ✗ region->bgcolor = (((*buf++) >> 2) & 3);
1240 }
1241
1242 ff_dlog(avctx, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
1243
1244
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 58 times.
114 if (fill) {
1245 56 memset(region->pbuf, region->bgcolor, region->buf_size);
1246 ff_dlog(avctx, "Fill region (%d)\n", region->bgcolor);
1247 }
1248
1249 114 delete_region_display_list(ctx, region);
1250
1251
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 114 times.
198 while (buf + 5 < buf_end) {
1252 84 object_id = AV_RB16(buf);
1253 84 buf += 2;
1254
1255 84 object = get_object(ctx, object_id);
1256
1257
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (!object) {
1258 84 object = av_mallocz(sizeof(*object));
1259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (!object)
1260 ✗ return AVERROR(ENOMEM);
1261
1262 84 object->id = object_id;
1263 84 object->next = ctx->object_list;
1264 84 ctx->object_list = object;
1265 }
1266
1267 84 object->type = (*buf) >> 6;
1268
1269 84 display = av_mallocz(sizeof(*display));
1270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (!display)
1271 ✗ return AVERROR(ENOMEM);
1272
1273 84 display->object_id = object_id;
1274 84 display->region_id = region_id;
1275
1276 84 display->x_pos = AV_RB16(buf) & 0xfff;
1277 84 buf += 2;
1278 84 display->y_pos = AV_RB16(buf) & 0xfff;
1279 84 buf += 2;
1280
1281
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (display->x_pos >= region->width ||
1282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 display->y_pos >= region->height) {
1283 ✗ av_log(avctx, AV_LOG_ERROR, "Object outside region\n");
1284 ✗ av_free(display);
1285 ✗ return AVERROR_INVALIDDATA;
1286 }
1287
1288
2/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
84 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
1289 ✗ display->fgcolor = *buf++;
1290 ✗ display->bgcolor = *buf++;
1291 }
1292
1293 84 display->region_list_next = region->display_list;
1294 84 region->display_list = display;
1295
1296 84 display->object_list_next = object->display_list;
1297 84 object->display_list = display;
1298 }
1299
1300 114 return 0;
1301 }
1302
1303 92 static int dvbsub_parse_page_segment(AVCodecContext *avctx,
1304 const uint8_t *buf, int buf_size, AVSubtitle *sub, int *got_output)
1305 {
1306 92 DVBSubContext *ctx = avctx->priv_data;
1307 DVBSubRegionDisplay *display;
1308 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
1309
1310 92 const uint8_t *buf_end = buf + buf_size;
1311 int region_id;
1312 int page_state;
1313 int timeout;
1314 int version;
1315
1316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (buf_size < 1)
1317 ✗ return AVERROR_INVALIDDATA;
1318
1319 92 timeout = *buf++;
1320 92 version = ((*buf)>>4) & 15;
1321 92 page_state = ((*buf++) >> 2) & 3;
1322
1323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (ctx->version == version) {
1324 ✗ return 0;
1325 }
1326
1327 92 ctx->time_out = timeout;
1328 92 ctx->version = version;
1329
1330 ff_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
1331
1332
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 if (ctx->compute_edt == 1)
1333 92 save_subtitle_set(avctx, sub, got_output);
1334
1335
3/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
92 if (page_state == 1 || page_state == 2) {
1336 14 delete_regions(ctx);
1337 14 delete_objects(ctx);
1338 14 delete_cluts(ctx);
1339 }
1340
1341 92 tmp_display_list = ctx->display_list;
1342 92 ctx->display_list = NULL;
1343
1344
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 92 times.
224 while (buf + 5 < buf_end) {
1345 132 region_id = *buf++;
1346 132 buf += 1;
1347
1348 132 display = ctx->display_list;
1349
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 132 times.
✓ Branch 2 taken 60 times.
✗ Branch 3 not taken.
192 while (display && display->region_id != region_id) {
1350 60 display = display->next;
1351 }
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (display) {
1353 ✗ av_log(avctx, AV_LOG_ERROR, "duplicate region\n");
1354 ✗ break;
1355 }
1356
1357 132 display = tmp_display_list;
1358 132 tmp_ptr = &tmp_display_list;
1359
1360
4/4
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 128 times.
190 while (display && display->region_id != region_id) {
1361 58 tmp_ptr = &display->next;
1362 58 display = display->next;
1363 }
1364
1365
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 128 times.
132 if (!display) {
1366 4 display = av_mallocz(sizeof(*display));
1367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!display)
1368 ✗ return AVERROR(ENOMEM);
1369 }
1370
1371 132 display->region_id = region_id;
1372
1373 132 display->x_pos = AV_RB16(buf);
1374 132 buf += 2;
1375 132 display->y_pos = AV_RB16(buf);
1376 132 buf += 2;
1377
1378 132 *tmp_ptr = display->next;
1379
1380 132 display->next = ctx->display_list;
1381 132 ctx->display_list = display;
1382
1383 ff_dlog(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
1384 }
1385
1386
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 92 times.
96 while (tmp_display_list) {
1387 4 display = tmp_display_list;
1388
1389 4 tmp_display_list = display->next;
1390
1391 4 av_freep(&display);
1392 }
1393
1394 92 return 0;
1395 }
1396
1397 ✗ static int dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
1398 const uint8_t *buf,
1399 int buf_size)
1400 {
1401 ✗ DVBSubContext *ctx = avctx->priv_data;
1402 ✗ DVBSubDisplayDefinition *display_def = ctx->display_definition;
1403 int dds_version, info_byte;
1404
1405 ✗ if (buf_size < 5)
1406 ✗ return AVERROR_INVALIDDATA;
1407
1408 ✗ info_byte = bytestream_get_byte(&buf);
1409 ✗ dds_version = info_byte >> 4;
1410 ✗ if (display_def && display_def->version == dds_version)
1411 ✗ return 0; // already have this display definition version
1412
1413 ✗ if (!display_def) {
1414 ✗ display_def = av_mallocz(sizeof(*display_def));
1415 ✗ if (!display_def)
1416 ✗ return AVERROR(ENOMEM);
1417 ✗ ctx->display_definition = display_def;
1418 }
1419
1420 ✗ display_def->version = dds_version;
1421 ✗ display_def->x = 0;
1422 ✗ display_def->y = 0;
1423 ✗ display_def->width = bytestream_get_be16(&buf) + 1;
1424 ✗ display_def->height = bytestream_get_be16(&buf) + 1;
1425 ✗ if (!avctx->width || !avctx->height) {
1426 ✗ int ret = ff_set_dimensions(avctx, display_def->width, display_def->height);
1427 ✗ if (ret < 0)
1428 ✗ return ret;
1429 }
1430
1431 ✗ if (info_byte & 1<<3) { // display_window_flag
1432 ✗ if (buf_size < 13)
1433 ✗ return AVERROR_INVALIDDATA;
1434
1435 ✗ display_def->x = bytestream_get_be16(&buf);
1436 ✗ display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
1437 ✗ display_def->y = bytestream_get_be16(&buf);
1438 ✗ display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
1439 }
1440
1441 ✗ return 0;
1442 }
1443
1444 92 static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
1445 int buf_size, AVSubtitle *sub,int *got_output)
1446 {
1447 92 DVBSubContext *ctx = avctx->priv_data;
1448
1449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (ctx->compute_edt == 0)
1450 ✗ save_subtitle_set(avctx, sub, got_output);
1451 92 return 0;
1452 }
1453
1454 92 static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub,
1455 int *got_sub_ptr, const AVPacket *avpkt)
1456 {
1457 92 const uint8_t *buf = avpkt->data;
1458 92 int buf_size = avpkt->size;
1459 92 DVBSubContext *ctx = avctx->priv_data;
1460 const uint8_t *p, *p_end;
1461 int segment_type;
1462 int page_id;
1463 int segment_length;
1464 int i;
1465 92 int ret = 0;
1466 92 int got_page = 0;
1467 92 int got_region = 0;
1468 92 int got_object = 0;
1469 92 int got_end_display = 0;
1470 92 int got_displaydef = 0;
1471
1472 ff_dlog(avctx, "DVB sub packet:\n");
1473
1474
2/2
✓ Branch 0 taken 102316 times.
✓ Branch 1 taken 92 times.
102408 for (i=0; i < buf_size; i++) {
1475 ff_dlog(avctx, "%02x ", buf[i]);
1476 102316 if (i % 16 == 15)
1477 ff_dlog(avctx, "\n");
1478 }
1479
1480 92 if (i % 16)
1481 ff_dlog(avctx, "\n");
1482
1483
2/4
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
92 if (buf_size <= 6 || *buf != 0x0f) {
1484 ff_dlog(avctx, "incomplete or broken packet");
1485 ✗ return AVERROR_INVALIDDATA;
1486 }
1487
1488 92 p = buf;
1489 92 p_end = buf + buf_size;
1490
1491
3/4
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 408 times.
✗ Branch 3 not taken.
500 while (p_end - p >= 6 && *p == 0x0f) {
1492 408 p += 1;
1493 408 segment_type = *p++;
1494 408 page_id = AV_RB16(p);
1495 408 p += 2;
1496 408 segment_length = AV_RB16(p);
1497 408 p += 2;
1498
1499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if (avctx->debug & FF_DEBUG_STARTCODE) {
1500 ✗ av_log(avctx, AV_LOG_DEBUG, "segment_type:%d page_id:%d segment_length:%d\n", segment_type, page_id, segment_length);
1501 }
1502
1503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if (p_end - p < segment_length) {
1504 ff_dlog(avctx, "incomplete or broken packet");
1505 ✗ ret = -1;
1506 ✗ goto end;
1507 }
1508
1509
2/4
✓ Branch 0 taken 408 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 408 times.
✗ Branch 3 not taken.
408 if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
1510
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
408 ctx->composition_id == -1 || ctx->ancillary_id == -1) {
1511 408 int ret = 0;
1512
5/7
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 84 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 92 times.
✗ Branch 6 not taken.
408 switch (segment_type) {
1513 92 case DVBSUB_PAGE_SEGMENT:
1514 92 ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, got_sub_ptr);
1515 92 got_page = 1;
1516 92 break;
1517 114 case DVBSUB_REGION_SEGMENT:
1518 114 ret = dvbsub_parse_region_segment(avctx, p, segment_length);
1519 114 got_region = 1;
1520 114 break;
1521 26 case DVBSUB_CLUT_SEGMENT:
1522 26 ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
1523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0) goto end;
1524 26 break;
1525 84 case DVBSUB_OBJECT_SEGMENT:
1526 84 ret = dvbsub_parse_object_segment(avctx, p, segment_length);
1527 84 got_object = 1;
1528 84 break;
1529 ✗ case DVBSUB_DISPLAYDEFINITION_SEGMENT:
1530 ✗ ret = dvbsub_parse_display_definition_segment(avctx, p,
1531 segment_length);
1532 ✗ got_displaydef = 1;
1533 ✗ break;
1534 92 case DVBSUB_END_DISPLAY_SEGMENT:
1535 92 ret = dvbsub_display_end_segment(avctx, p, segment_length, sub, got_sub_ptr);
1536 92 got_end_display = 1;
1537 92 break;
1538 ✗ default:
1539 ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",
1540 segment_type, page_id, segment_length);
1541 ✗ break;
1542 }
1543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if (ret < 0)
1544 ✗ goto end;
1545 }
1546
1547 408 p += segment_length;
1548 }
1549
1550 // Even though not mandated by the spec, we're imposing a minimum requirement
1551 // for a useful packet to have at least one page, region and object segment.
1552
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 72 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
92 if (got_page && got_region && got_object) {
1553
1554
4/6
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 70 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
72 if (!got_displaydef && !avctx->width && !avctx->height) {
1555 // Default from ETSI EN 300 743 V1.3.1 (7.2.1)
1556 2 avctx->width = 720;
1557 2 avctx->height = 576;
1558 }
1559
1560 // Some streams do not send an end-of-display segment but if we have all the other
1561 // segments then we need no further data.
1562
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if (!got_end_display) {
1563 ✗ av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, emulating\n");
1564 ✗ dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
1565 }
1566 }
1567 92 end:
1568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if (ret < 0) {
1569 ✗ return ret;
1570 } else {
1571
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 if (ctx->compute_edt == 1)
1572 92 FFSWAP(int64_t, ctx->prev_start, sub->pts);
1573 }
1574
1575 92 return p - buf;
1576 }
1577
1578 #define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
1579 #define OFFSET(x) offsetof(DVBSubContext, x)
1580 static const AVOption options[] = {
1581 {"compute_edt", "compute end of time using pts or timeout", OFFSET(compute_edt), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DS},
1582 {"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},
1583 {"dvb_substream", "", OFFSET(substream), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
1584 {NULL}
1585 };
1586 static const AVClass dvbsubdec_class = {
1587 .class_name = "DVB Sub Decoder",
1588 .item_name = av_default_item_name,
1589 .option = options,
1590 .version = LIBAVUTIL_VERSION_INT,
1591 };
1592
1593 const FFCodec ff_dvbsub_decoder = {
1594 .p.name = "dvbsub",
1595 CODEC_LONG_NAME("DVB subtitles"),
1596 .p.type = AVMEDIA_TYPE_SUBTITLE,
1597 .p.id = AV_CODEC_ID_DVB_SUBTITLE,
1598 .priv_data_size = sizeof(DVBSubContext),
1599 .init = dvbsub_init_decoder,
1600 .close = dvbsub_close_decoder,
1601 FF_CODEC_DECODE_SUB_CB(dvbsub_decode),
1602 .p.priv_class = &dvbsubdec_class,
1603 };
1604