FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ccaption_dec.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 277 425 65.2%
Branches: 167 270 61.9%

Line Branch Exec Source
1 /*
2 * Closed Caption Decoding
3 * Copyright (c) 2015 Anshul Maheshwari
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 "ass.h"
24 #include "internal.h"
25 #include "libavutil/opt.h"
26
27 #define SCREEN_ROWS 15
28 #define SCREEN_COLUMNS 32
29
30 #define SET_FLAG(var, val) ( (var) |= ( 1 << (val)) )
31 #define UNSET_FLAG(var, val) ( (var) &= ~( 1 << (val)) )
32 #define CHECK_FLAG(var, val) ( (var) & ( 1 << (val)) )
33
34 static const AVRational ms_tb = {1, 1000};
35
36 enum cc_mode {
37 CCMODE_POPON,
38 CCMODE_PAINTON,
39 CCMODE_ROLLUP,
40 CCMODE_TEXT,
41 };
42
43 enum cc_color_code {
44 CCCOL_WHITE,
45 CCCOL_GREEN,
46 CCCOL_BLUE,
47 CCCOL_CYAN,
48 CCCOL_RED,
49 CCCOL_YELLOW,
50 CCCOL_MAGENTA,
51 CCCOL_USERDEFINED,
52 CCCOL_BLACK,
53 CCCOL_TRANSPARENT,
54 };
55
56 enum cc_font {
57 CCFONT_REGULAR,
58 CCFONT_ITALICS,
59 CCFONT_UNDERLINED,
60 CCFONT_UNDERLINED_ITALICS,
61 };
62
63 enum cc_charset {
64 CCSET_BASIC_AMERICAN,
65 CCSET_SPECIAL_AMERICAN,
66 CCSET_EXTENDED_SPANISH_FRENCH_MISC,
67 CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH,
68 };
69
70 static const char *charset_overrides[4][128] =
71 {
72 [CCSET_BASIC_AMERICAN] = {
73 [0x27] = "\u2019",
74 [0x2a] = "\u00e1",
75 [0x5c] = "\u00e9",
76 [0x5e] = "\u00ed",
77 [0x5f] = "\u00f3",
78 [0x60] = "\u00fa",
79 [0x7b] = "\u00e7",
80 [0x7c] = "\u00f7",
81 [0x7d] = "\u00d1",
82 [0x7e] = "\u00f1",
83 [0x7f] = "\u2588"
84 },
85 [CCSET_SPECIAL_AMERICAN] = {
86 [0x30] = "\u00ae",
87 [0x31] = "\u00b0",
88 [0x32] = "\u00bd",
89 [0x33] = "\u00bf",
90 [0x34] = "\u2122",
91 [0x35] = "\u00a2",
92 [0x36] = "\u00a3",
93 [0x37] = "\u266a",
94 [0x38] = "\u00e0",
95 [0x39] = "\u00A0",
96 [0x3a] = "\u00e8",
97 [0x3b] = "\u00e2",
98 [0x3c] = "\u00ea",
99 [0x3d] = "\u00ee",
100 [0x3e] = "\u00f4",
101 [0x3f] = "\u00fb",
102 },
103 [CCSET_EXTENDED_SPANISH_FRENCH_MISC] = {
104 [0x20] = "\u00c1",
105 [0x21] = "\u00c9",
106 [0x22] = "\u00d3",
107 [0x23] = "\u00da",
108 [0x24] = "\u00dc",
109 [0x25] = "\u00fc",
110 [0x26] = "\u00b4",
111 [0x27] = "\u00a1",
112 [0x28] = "*",
113 [0x29] = "\u2018",
114 [0x2a] = "-",
115 [0x2b] = "\u00a9",
116 [0x2c] = "\u2120",
117 [0x2d] = "\u00b7",
118 [0x2e] = "\u201c",
119 [0x2f] = "\u201d",
120 [0x30] = "\u00c0",
121 [0x31] = "\u00c2",
122 [0x32] = "\u00c7",
123 [0x33] = "\u00c8",
124 [0x34] = "\u00ca",
125 [0x35] = "\u00cb",
126 [0x36] = "\u00eb",
127 [0x37] = "\u00ce",
128 [0x38] = "\u00cf",
129 [0x39] = "\u00ef",
130 [0x3a] = "\u00d4",
131 [0x3b] = "\u00d9",
132 [0x3c] = "\u00f9",
133 [0x3d] = "\u00db",
134 [0x3e] = "\u00ab",
135 [0x3f] = "\u00bb",
136 },
137 [CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH] = {
138 [0x20] = "\u00c3",
139 [0x21] = "\u00e3",
140 [0x22] = "\u00cd",
141 [0x23] = "\u00cc",
142 [0x24] = "\u00ec",
143 [0x25] = "\u00d2",
144 [0x26] = "\u00f2",
145 [0x27] = "\u00d5",
146 [0x28] = "\u00f5",
147 [0x29] = "{",
148 [0x2a] = "}",
149 [0x2b] = "\\",
150 [0x2c] = "^",
151 [0x2d] = "_",
152 [0x2e] = "|",
153 [0x2f] = "~",
154 [0x30] = "\u00c4",
155 [0x31] = "\u00e4",
156 [0x32] = "\u00d6",
157 [0x33] = "\u00f6",
158 [0x34] = "\u00df",
159 [0x35] = "\u00a5",
160 [0x36] = "\u00a4",
161 [0x37] = "\u00a6",
162 [0x38] = "\u00c5",
163 [0x39] = "\u00e5",
164 [0x3a] = "\u00d8",
165 [0x3b] = "\u00f8",
166 [0x3c] = "\u250c",
167 [0x3d] = "\u2510",
168 [0x3e] = "\u2514",
169 [0x3f] = "\u2518",
170 },
171 };
172
173 static const unsigned char bg_attribs[8] = // Color
174 {
175 CCCOL_WHITE,
176 CCCOL_GREEN,
177 CCCOL_BLUE,
178 CCCOL_CYAN,
179 CCCOL_RED,
180 CCCOL_YELLOW,
181 CCCOL_MAGENTA,
182 CCCOL_BLACK,
183 };
184
185 static const unsigned char pac2_attribs[32][3] = // Color, font, ident
186 {
187 { CCCOL_WHITE, CCFONT_REGULAR, 0 }, // 0x40 || 0x60
188 { CCCOL_WHITE, CCFONT_UNDERLINED, 0 }, // 0x41 || 0x61
189 { CCCOL_GREEN, CCFONT_REGULAR, 0 }, // 0x42 || 0x62
190 { CCCOL_GREEN, CCFONT_UNDERLINED, 0 }, // 0x43 || 0x63
191 { CCCOL_BLUE, CCFONT_REGULAR, 0 }, // 0x44 || 0x64
192 { CCCOL_BLUE, CCFONT_UNDERLINED, 0 }, // 0x45 || 0x65
193 { CCCOL_CYAN, CCFONT_REGULAR, 0 }, // 0x46 || 0x66
194 { CCCOL_CYAN, CCFONT_UNDERLINED, 0 }, // 0x47 || 0x67
195 { CCCOL_RED, CCFONT_REGULAR, 0 }, // 0x48 || 0x68
196 { CCCOL_RED, CCFONT_UNDERLINED, 0 }, // 0x49 || 0x69
197 { CCCOL_YELLOW, CCFONT_REGULAR, 0 }, // 0x4a || 0x6a
198 { CCCOL_YELLOW, CCFONT_UNDERLINED, 0 }, // 0x4b || 0x6b
199 { CCCOL_MAGENTA, CCFONT_REGULAR, 0 }, // 0x4c || 0x6c
200 { CCCOL_MAGENTA, CCFONT_UNDERLINED, 0 }, // 0x4d || 0x6d
201 { CCCOL_WHITE, CCFONT_ITALICS, 0 }, // 0x4e || 0x6e
202 { CCCOL_WHITE, CCFONT_UNDERLINED_ITALICS, 0 }, // 0x4f || 0x6f
203 { CCCOL_WHITE, CCFONT_REGULAR, 0 }, // 0x50 || 0x70
204 { CCCOL_WHITE, CCFONT_UNDERLINED, 0 }, // 0x51 || 0x71
205 { CCCOL_WHITE, CCFONT_REGULAR, 4 }, // 0x52 || 0x72
206 { CCCOL_WHITE, CCFONT_UNDERLINED, 4 }, // 0x53 || 0x73
207 { CCCOL_WHITE, CCFONT_REGULAR, 8 }, // 0x54 || 0x74
208 { CCCOL_WHITE, CCFONT_UNDERLINED, 8 }, // 0x55 || 0x75
209 { CCCOL_WHITE, CCFONT_REGULAR, 12 }, // 0x56 || 0x76
210 { CCCOL_WHITE, CCFONT_UNDERLINED, 12 }, // 0x57 || 0x77
211 { CCCOL_WHITE, CCFONT_REGULAR, 16 }, // 0x58 || 0x78
212 { CCCOL_WHITE, CCFONT_UNDERLINED, 16 }, // 0x59 || 0x79
213 { CCCOL_WHITE, CCFONT_REGULAR, 20 }, // 0x5a || 0x7a
214 { CCCOL_WHITE, CCFONT_UNDERLINED, 20 }, // 0x5b || 0x7b
215 { CCCOL_WHITE, CCFONT_REGULAR, 24 }, // 0x5c || 0x7c
216 { CCCOL_WHITE, CCFONT_UNDERLINED, 24 }, // 0x5d || 0x7d
217 { CCCOL_WHITE, CCFONT_REGULAR, 28 }, // 0x5e || 0x7e
218 { CCCOL_WHITE, CCFONT_UNDERLINED, 28 } // 0x5f || 0x7f
219 /* total 32 entries */
220 };
221
222 struct Screen {
223 /* +1 is used to compensate null character of string */
224 uint8_t characters[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
225 uint8_t charsets[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
226 uint8_t colors[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
227 uint8_t bgs[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
228 uint8_t fonts[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
229 /*
230 * Bitmask of used rows; if a bit is not set, the
231 * corresponding row is not used.
232 * for setting row 1 use row | (1 << 0)
233 * for setting row 15 use row | (1 << 14)
234 */
235 int16_t row_used;
236 };
237
238 typedef struct CCaptionSubContext {
239 AVClass *class;
240 int real_time;
241 int real_time_latency_msec;
242 int data_field;
243 struct Screen screen[2];
244 int active_screen;
245 uint8_t cursor_row;
246 uint8_t cursor_column;
247 uint8_t cursor_color;
248 uint8_t bg_color;
249 uint8_t cursor_font;
250 uint8_t cursor_charset;
251 AVBPrint buffer[2];
252 int buffer_index;
253 int buffer_changed;
254 int rollup;
255 enum cc_mode mode;
256 int64_t buffer_time[2];
257 int screen_touched;
258 int64_t last_real_time;
259 uint8_t prev_cmd[2];
260 int readorder;
261 } CCaptionSubContext;
262
263 8 static av_cold int init_decoder(AVCodecContext *avctx)
264 {
265 int ret;
266 8 CCaptionSubContext *ctx = avctx->priv_data;
267
268 8 av_bprint_init(&ctx->buffer[0], 0, AV_BPRINT_SIZE_UNLIMITED);
269 8 av_bprint_init(&ctx->buffer[1], 0, AV_BPRINT_SIZE_UNLIMITED);
270 /* taking by default roll up to 2 */
271 8 ctx->mode = CCMODE_ROLLUP;
272 8 ctx->bg_color = CCCOL_BLACK;
273 8 ctx->rollup = 2;
274 8 ctx->cursor_row = 10;
275 8 ret = ff_ass_subtitle_header(avctx, "Monospace",
276 ASS_DEFAULT_FONT_SIZE,
277 ASS_DEFAULT_COLOR,
278 ASS_DEFAULT_BACK_COLOR,
279 ASS_DEFAULT_BOLD,
280 ASS_DEFAULT_ITALIC,
281 ASS_DEFAULT_UNDERLINE,
282 3,
283 ASS_DEFAULT_ALIGNMENT);
284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0) {
285 return ret;
286 }
287
288 8 return ret;
289 }
290
291 8 static av_cold int close_decoder(AVCodecContext *avctx)
292 {
293 8 CCaptionSubContext *ctx = avctx->priv_data;
294 8 av_bprint_finalize(&ctx->buffer[0], NULL);
295 8 av_bprint_finalize(&ctx->buffer[1], NULL);
296 8 return 0;
297 }
298
299 static void flush_decoder(AVCodecContext *avctx)
300 {
301 CCaptionSubContext *ctx = avctx->priv_data;
302 ctx->screen[0].row_used = 0;
303 ctx->screen[1].row_used = 0;
304 ctx->prev_cmd[0] = 0;
305 ctx->prev_cmd[1] = 0;
306 ctx->mode = CCMODE_ROLLUP;
307 ctx->rollup = 2;
308 ctx->cursor_row = 10;
309 ctx->cursor_column = 0;
310 ctx->cursor_font = 0;
311 ctx->cursor_color = 0;
312 ctx->bg_color = CCCOL_BLACK;
313 ctx->cursor_charset = 0;
314 ctx->active_screen = 0;
315 ctx->last_real_time = 0;
316 ctx->screen_touched = 0;
317 ctx->buffer_changed = 0;
318 if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
319 ctx->readorder = 0;
320 av_bprint_clear(&ctx->buffer[0]);
321 av_bprint_clear(&ctx->buffer[1]);
322 }
323
324 /**
325 * @param ctx closed caption context just to print log
326 */
327 5815 static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
328 {
329 5815 uint8_t col = ctx->cursor_column;
330 5815 char *row = screen->characters[ctx->cursor_row];
331 5815 char *font = screen->fonts[ctx->cursor_row];
332 5815 char *color = screen->colors[ctx->cursor_row];
333 5815 char *bg = screen->bgs[ctx->cursor_row];
334 5815 char *charset = screen->charsets[ctx->cursor_row];
335
336
2/2
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 7 times.
5815 if (col < SCREEN_COLUMNS) {
337 5808 row[col] = ch;
338 5808 font[col] = ctx->cursor_font;
339 5808 color[col] = ctx->cursor_color;
340 5808 bg[col] = ctx->bg_color;
341 5808 charset[col] = ctx->cursor_charset;
342 5808 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
343
2/2
✓ Branch 0 taken 4221 times.
✓ Branch 1 taken 1587 times.
5808 if (ch) ctx->cursor_column++;
344 5808 return;
345 }
346 /* We have extra space at end only for null character */
347
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 else if (col == SCREEN_COLUMNS && ch == 0) {
348 7 row[col] = ch;
349 7 return;
350 }
351 else {
352 av_log(ctx, AV_LOG_WARNING, "Data Ignored since exceeding screen width\n");
353 return;
354 }
355 }
356
357 /**
358 * This function after validating parity bit, also remove it from data pair.
359 * The first byte doesn't pass parity, we replace it with a solid blank
360 * and process the pair.
361 * If the second byte doesn't pass parity, it returns INVALIDDATA
362 * user can ignore the whole pair and pass the other pair.
363 */
364 8337 static int validate_cc_data_pair(const uint8_t *cc_data_pair, uint8_t *hi)
365 {
366 8337 uint8_t cc_valid = (*cc_data_pair & 4) >>2;
367 8337 uint8_t cc_type = *cc_data_pair & 3;
368
369 8337 *hi = cc_data_pair[1];
370
371
2/2
✓ Branch 0 taken 4658 times.
✓ Branch 1 taken 3679 times.
8337 if (!cc_valid)
372 4658 return AVERROR_INVALIDDATA;
373
374 // if EIA-608 data then verify parity.
375
4/4
✓ Branch 0 taken 754 times.
✓ Branch 1 taken 2925 times.
✓ Branch 2 taken 476 times.
✓ Branch 3 taken 278 times.
3679 if (cc_type==0 || cc_type==1) {
376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3401 times.
3401 if (!av_parity(cc_data_pair[2])) {
377 return AVERROR_INVALIDDATA;
378 }
379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3401 times.
3401 if (!av_parity(cc_data_pair[1])) {
380 *hi = 0x7F;
381 }
382 }
383
384 //Skip non-data
385
5/6
✓ Branch 0 taken 3679 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 956 times.
✓ Branch 3 taken 2723 times.
✓ Branch 4 taken 274 times.
✓ Branch 5 taken 682 times.
3679 if ((cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] == 0xFD)
386
3/4
✓ Branch 0 taken 442 times.
✓ Branch 1 taken 2555 times.
✓ Branch 2 taken 442 times.
✗ Branch 3 not taken.
2997 && (cc_data_pair[1] & 0x7F) == 0 && (cc_data_pair[2] & 0x7F) == 0)
387 442 return AVERROR_PATCHWELCOME;
388
389 //skip 708 data
390
4/4
✓ Branch 0 taken 3159 times.
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 200 times.
✓ Branch 3 taken 2959 times.
3237 if (cc_type == 3 || cc_type == 2)
391 278 return AVERROR_PATCHWELCOME;
392
393 2959 return 0;
394 }
395
396 1811 static struct Screen *get_writing_screen(CCaptionSubContext *ctx)
397 {
398
2/3
✓ Branch 0 taken 1676 times.
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
1811 switch (ctx->mode) {
399 1676 case CCMODE_POPON:
400 // use Inactive screen
401
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 812 times.
1676 return ctx->screen + !ctx->active_screen;
402 135 case CCMODE_PAINTON:
403 case CCMODE_ROLLUP:
404 case CCMODE_TEXT:
405 // use active screen
406 135 return ctx->screen + ctx->active_screen;
407 }
408 /* It was never an option */
409 return NULL;
410 }
411
412 9 static void roll_up(CCaptionSubContext *ctx)
413 {
414 struct Screen *screen;
415 int i, keep_lines;
416
417
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ctx->mode == CCMODE_TEXT)
418 return;
419
420 9 screen = get_writing_screen(ctx);
421
422 /* +1 signify cursor_row starts from 0
423 * Can't keep lines less then row cursor pos
424 */
425
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 keep_lines = FFMIN(ctx->cursor_row + 1, ctx->rollup);
426
427
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 9 times.
144 for (i = 0; i < SCREEN_ROWS; i++) {
428
4/4
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 70 times.
135 if (i > ctx->cursor_row - keep_lines && i <= ctx->cursor_row)
429 18 continue;
430 117 UNSET_FLAG(screen->row_used, i);
431 }
432
433
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 2 times.
23 for (i = 0; i < keep_lines && screen->row_used; i++) {
434 14 const int i_row = ctx->cursor_row - keep_lines + i + 1;
435
436 14 memcpy(screen->characters[i_row], screen->characters[i_row+1], SCREEN_COLUMNS);
437 14 memcpy(screen->colors[i_row], screen->colors[i_row+1], SCREEN_COLUMNS);
438 14 memcpy(screen->bgs[i_row], screen->bgs[i_row+1], SCREEN_COLUMNS);
439 14 memcpy(screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
440 14 memcpy(screen->charsets[i_row], screen->charsets[i_row+1], SCREEN_COLUMNS);
441
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
14 if (CHECK_FLAG(screen->row_used, i_row + 1))
442 7 SET_FLAG(screen->row_used, i_row);
443 }
444
445 9 UNSET_FLAG(screen->row_used, ctx->cursor_row);
446 }
447
448 211 static int capture_screen(CCaptionSubContext *ctx)
449 {
450 211 int i, j, tab = 0;
451 211 struct Screen *screen = ctx->screen + ctx->active_screen;
452 211 enum cc_font prev_font = CCFONT_REGULAR;
453 211 enum cc_color_code prev_color = CCCOL_WHITE;
454 211 enum cc_color_code prev_bg_color = CCCOL_BLACK;
455 211 const int bidx = ctx->buffer_index;
456
457 211 av_bprint_clear(&ctx->buffer[bidx]);
458
459
4/4
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 1575 times.
✓ Branch 3 taken 105 times.
1786 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
460 {
461
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 1367 times.
1575 if (CHECK_FLAG(screen->row_used, i)) {
462 208 const char *row = screen->characters[i];
463 208 const char *charset = screen->charsets[i];
464 208 j = 0;
465
3/4
✓ Branch 0 taken 1164 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1164 times.
✗ Branch 3 not taken.
1372 while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN)
466 1164 j++;
467
4/4
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 52 times.
208 if (!tab || j < tab)
468 156 tab = j;
469 }
470 }
471
472
4/4
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 1575 times.
✓ Branch 3 taken 105 times.
1786 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
473 {
474
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 1367 times.
1575 if (CHECK_FLAG(screen->row_used, i)) {
475 208 const char *row = screen->characters[i];
476 208 const char *font = screen->fonts[i];
477 208 const char *bg = screen->bgs[i];
478 208 const char *color = screen->colors[i];
479 208 const char *charset = screen->charsets[i];
480 const char *override;
481 208 int x, y, seen_char = 0;
482 208 j = 0;
483
484 /* skip leading space */
485
5/6
✓ Branch 0 taken 1003 times.
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 1003 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 971 times.
✓ Branch 5 taken 32 times.
1179 while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN && j < tab)
486 971 j++;
487
488 208 x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
489 208 y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
490 208 av_bprintf(&ctx->buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
491
492
2/2
✓ Branch 0 taken 3680 times.
✓ Branch 1 taken 7 times.
3687 for (; j < SCREEN_COLUMNS; j++) {
493 3680 const char *e_tag = "", *s_tag = "", *c_tag = "", *b_tag = "";
494
495
2/2
✓ Branch 0 taken 201 times.
✓ Branch 1 taken 3479 times.
3680 if (row[j] == 0)
496 201 break;
497
498
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 3439 times.
3479 if (prev_font != font[j]) {
499
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
40 switch (prev_font) {
500 10 case CCFONT_ITALICS:
501 10 e_tag = "{\\i0}";
502 10 break;
503 case CCFONT_UNDERLINED:
504 e_tag = "{\\u0}";
505 break;
506 case CCFONT_UNDERLINED_ITALICS:
507 e_tag = "{\\u0}{\\i0}";
508 break;
509 }
510
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
40 switch (font[j]) {
511 30 case CCFONT_ITALICS:
512 30 s_tag = "{\\i1}";
513 30 break;
514 case CCFONT_UNDERLINED:
515 s_tag = "{\\u1}";
516 break;
517 case CCFONT_UNDERLINED_ITALICS:
518 s_tag = "{\\u1}{\\i1}";
519 break;
520 }
521 }
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3479 times.
3479 if (prev_color != color[j]) {
523 switch (color[j]) {
524 case CCCOL_WHITE:
525 c_tag = "{\\c&HFFFFFF&}";
526 break;
527 case CCCOL_GREEN:
528 c_tag = "{\\c&H00FF00&}";
529 break;
530 case CCCOL_BLUE:
531 c_tag = "{\\c&HFF0000&}";
532 break;
533 case CCCOL_CYAN:
534 c_tag = "{\\c&HFFFF00&}";
535 break;
536 case CCCOL_RED:
537 c_tag = "{\\c&H0000FF&}";
538 break;
539 case CCCOL_YELLOW:
540 c_tag = "{\\c&H00FFFF&}";
541 break;
542 case CCCOL_MAGENTA:
543 c_tag = "{\\c&HFF00FF&}";
544 break;
545 }
546 }
547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3479 times.
3479 if (prev_bg_color != bg[j]) {
548 switch (bg[j]) {
549 case CCCOL_WHITE:
550 b_tag = "{\\3c&HFFFFFF&}";
551 break;
552 case CCCOL_GREEN:
553 b_tag = "{\\3c&H00FF00&}";
554 break;
555 case CCCOL_BLUE:
556 b_tag = "{\\3c&HFF0000&}";
557 break;
558 case CCCOL_CYAN:
559 b_tag = "{\\3c&HFFFF00&}";
560 break;
561 case CCCOL_RED:
562 b_tag = "{\\3c&H0000FF&}";
563 break;
564 case CCCOL_YELLOW:
565 b_tag = "{\\3c&H00FFFF&}";
566 break;
567 case CCCOL_MAGENTA:
568 b_tag = "{\\3c&HFF00FF&}";
569 break;
570 case CCCOL_BLACK:
571 b_tag = "{\\3c&H000000&}";
572 break;
573 }
574 }
575
576 3479 prev_font = font[j];
577 3479 prev_color = color[j];
578 3479 prev_bg_color = bg[j];
579 3479 override = charset_overrides[(int)charset[j]][(int)row[j]];
580
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3468 times.
3479 if (override) {
581 11 av_bprintf(&ctx->buffer[bidx], "%s%s%s%s%s", e_tag, s_tag, c_tag, b_tag, override);
582 11 seen_char = 1;
583
4/4
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 2715 times.
✓ Branch 2 taken 193 times.
✓ Branch 3 taken 560 times.
3468 } else if (row[j] == ' ' && !seen_char) {
584 193 av_bprintf(&ctx->buffer[bidx], "%s%s%s%s\\h", e_tag, s_tag, c_tag, b_tag);
585 } else {
586 3275 av_bprintf(&ctx->buffer[bidx], "%s%s%s%s%c", e_tag, s_tag, c_tag, b_tag, row[j]);
587 3275 seen_char = 1;
588 }
589
590 }
591 208 av_bprintf(&ctx->buffer[bidx], "\\N");
592 }
593 }
594
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 211 times.
211 if (!av_bprint_is_complete(&ctx->buffer[bidx]))
595 return AVERROR(ENOMEM);
596
3/4
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 105 times.
✗ Branch 3 not taken.
211 if (screen->row_used && ctx->buffer[bidx].len >= 2) {
597 105 ctx->buffer[bidx].len -= 2;
598 105 ctx->buffer[bidx].str[ctx->buffer[bidx].len] = 0;
599 }
600 211 ctx->buffer_changed = 1;
601 211 return 0;
602 }
603
604 203 static void update_time(CCaptionSubContext *ctx, int64_t pts)
605 {
606 203 ctx->buffer_time[0] = ctx->buffer_time[1];
607 203 ctx->buffer_time[1] = pts;
608 203 }
609
610 static void handle_bgattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
611 {
612 const int i = (lo & 0xf) >> 1;
613
614 ctx->bg_color = bg_attribs[i];
615 }
616
617 11 static void handle_textattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
618 {
619 11 int i = lo - 0x20;
620 11 struct Screen *screen = get_writing_screen(ctx);
621
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (i >= 32)
623 return;
624
625 11 ctx->cursor_color = pac2_attribs[i][0];
626 11 ctx->cursor_font = pac2_attribs[i][1];
627
628 11 SET_FLAG(screen->row_used, ctx->cursor_row);
629 11 write_char(ctx, screen, ' ');
630 }
631
632 197 static void handle_pac(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
633 {
634 static const int8_t row_map[] = {
635 11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
636 };
637 197 const int index = ( (hi<<1) & 0x0e) | ( (lo>>5) & 0x01 );
638 197 struct Screen *screen = get_writing_screen(ctx);
639 int indent, i;
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
197 if (row_map[index] <= 0) {
642 av_log(ctx, AV_LOG_DEBUG, "Invalid pac index encountered\n");
643 return;
644 }
645
646 197 lo &= 0x1f;
647
648 197 ctx->cursor_row = row_map[index] - 1;
649 197 ctx->cursor_color = pac2_attribs[lo][0];
650 197 ctx->cursor_font = pac2_attribs[lo][1];
651 197 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
652 197 ctx->cursor_column = 0;
653 197 indent = pac2_attribs[lo][2];
654
2/2
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 197 times.
1333 for (i = 0; i < indent; i++) {
655 1136 write_char(ctx, screen, ' ');
656 }
657 }
658
659 197 static int handle_edm(CCaptionSubContext *ctx)
660 {
661 197 struct Screen *screen = ctx->screen + ctx->active_screen;
662 int ret;
663
664 // In buffered mode, keep writing to screen until it is wiped.
665 // Before wiping the display, capture contents to emit subtitle.
666
1/2
✓ Branch 0 taken 197 times.
✗ Branch 1 not taken.
197 if (!ctx->real_time)
667 197 ret = capture_screen(ctx);
668
669 197 screen->row_used = 0;
670 197 ctx->bg_color = CCCOL_BLACK;
671
672 // In realtime mode, emit an empty caption so the last one doesn't
673 // stay on the screen.
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
197 if (ctx->real_time)
675 ret = capture_screen(ctx);
676
677 197 return ret;
678 }
679
680 93 static int handle_eoc(CCaptionSubContext *ctx)
681 {
682 int ret;
683
684 93 ctx->active_screen = !ctx->active_screen;
685
686 // In buffered mode, we wait til the *next* EOC and
687 // capture what was already on the screen since the last EOC.
688
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 if (!ctx->real_time)
689 93 ret = handle_edm(ctx);
690
691 93 ctx->cursor_column = 0;
692
693 // In realtime mode, we display the buffered contents (after
694 // flipping the buffer to active above) as soon as EOC arrives.
695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (ctx->real_time)
696 ret = capture_screen(ctx);
697
698 93 return ret;
699 }
700
701 static void handle_delete_end_of_row(CCaptionSubContext *ctx)
702 {
703 struct Screen *screen = get_writing_screen(ctx);
704 write_char(ctx, screen, 0);
705 }
706
707 1594 static void handle_char(CCaptionSubContext *ctx, char hi, char lo)
708 {
709 1594 struct Screen *screen = get_writing_screen(ctx);
710
711 1594 SET_FLAG(screen->row_used, ctx->cursor_row);
712
713
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1594 times.
1594 switch (hi) {
714 case 0x11:
715 ctx->cursor_charset = CCSET_SPECIAL_AMERICAN;
716 break;
717 case 0x12:
718 if (ctx->cursor_column > 0)
719 ctx->cursor_column -= 1;
720 ctx->cursor_charset = CCSET_EXTENDED_SPANISH_FRENCH_MISC;
721 break;
722 case 0x13:
723 if (ctx->cursor_column > 0)
724 ctx->cursor_column -= 1;
725 ctx->cursor_charset = CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH;
726 break;
727 1594 default:
728 1594 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
729 1594 write_char(ctx, screen, hi);
730 1594 break;
731 }
732
733
2/2
✓ Branch 0 taken 1480 times.
✓ Branch 1 taken 114 times.
1594 if (lo) {
734 1480 write_char(ctx, screen, lo);
735 }
736 1594 write_char(ctx, screen, 0);
737
738
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 1481 times.
1594 if (ctx->mode != CCMODE_POPON)
739 113 ctx->screen_touched = 1;
740
741 if (lo)
742 ff_dlog(ctx, "(%c,%c)\n", hi, lo);
743 else
744 ff_dlog(ctx, "(%c)\n", hi);
745 1594 }
746
747 2757 static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
748 {
749 2757 int ret = 0;
750
751
4/4
✓ Branch 0 taken 914 times.
✓ Branch 1 taken 1843 times.
✓ Branch 2 taken 648 times.
✓ Branch 3 taken 266 times.
2757 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
752 648 return 0;
753 }
754
755 /* set prev command */
756 2109 ctx->prev_cmd[0] = hi;
757 2109 ctx->prev_cmd[1] = lo;
758
759
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2109 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2109 times.
✗ Branch 7 not taken.
2109 if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
760
5/6
✓ Branch 0 taken 515 times.
✓ Branch 1 taken 1594 times.
✓ Branch 2 taken 197 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 197 times.
✗ Branch 5 not taken.
2109 ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
761 197 handle_pac(ctx, hi, lo);
762
5/8
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1901 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1901 times.
1912 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
763 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
764 11 handle_textattr(ctx, hi, lo);
765
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1901 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1901 } else if ((hi == 0x10 && lo >= 0x20 && lo <= 0x2f)) {
766 handle_bgattr(ctx, hi, lo);
767
4/6
✓ Branch 0 taken 1594 times.
✓ Branch 1 taken 307 times.
✓ Branch 2 taken 1594 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1594 times.
1901 } else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
768
5/10
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 104 times.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 93 times.
✗ Branch 9 not taken.
307 switch (lo) {
769 92 case 0x20:
770 /* resume caption loading */
771 92 ctx->mode = CCMODE_POPON;
772 92 break;
773 case 0x24:
774 handle_delete_end_of_row(ctx);
775 break;
776 9 case 0x25:
777 case 0x26:
778 case 0x27:
779 9 ctx->rollup = lo - 0x23;
780 9 ctx->mode = CCMODE_ROLLUP;
781 9 break;
782 case 0x29:
783 /* resume direct captioning */
784 ctx->mode = CCMODE_PAINTON;
785 break;
786 case 0x2b:
787 /* resume text display */
788 ctx->mode = CCMODE_TEXT;
789 break;
790 104 case 0x2c:
791 /* erase display memory */
792 104 handle_edm(ctx);
793 104 break;
794 9 case 0x2d:
795 /* carriage return */
796 ff_dlog(ctx, "carriage return\n");
797
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 if (!ctx->real_time)
798 6 ret = capture_screen(ctx);
799 9 roll_up(ctx);
800 9 ctx->cursor_column = 0;
801 9 break;
802 case 0x2e:
803 /* erase buffered (non displayed) memory */
804 // Only in realtime mode. In buffered mode, we re-use the inactive screen
805 // for our own buffering.
806 if (ctx->real_time) {
807 struct Screen *screen = ctx->screen + !ctx->active_screen;
808 screen->row_used = 0;
809 }
810 break;
811 93 case 0x2f:
812 /* end of caption */
813 ff_dlog(ctx, "handle_eoc\n");
814 93 ret = handle_eoc(ctx);
815 93 break;
816 default:
817 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
818 break;
819 }
820
2/4
✓ Branch 0 taken 1594 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1594 times.
1594 } else if (hi >= 0x11 && hi <= 0x13) {
821 /* Special characters */
822 handle_char(ctx, hi, lo);
823
1/2
✓ Branch 0 taken 1594 times.
✗ Branch 1 not taken.
1594 } else if (hi >= 0x20) {
824 /* Standard characters (always in pairs) */
825 1594 handle_char(ctx, hi, lo);
826 1594 ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
827 } else if (hi == 0x17 && lo >= 0x21 && lo <= 0x23) {
828 int i;
829 /* Tab offsets (spacing) */
830 for (i = 0; i < lo - 0x20; i++) {
831 handle_char(ctx, ' ', 0);
832 }
833 } else {
834 /* Ignoring all other non data code */
835 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
836 }
837
838 2109 return ret;
839 }
840
841 580 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
842 {
843 580 CCaptionSubContext *ctx = avctx->priv_data;
844 580 AVSubtitle *sub = data;
845 580 int64_t in_time = sub->pts;
846 int64_t start_time;
847 int64_t end_time;
848 580 int bidx = ctx->buffer_index;
849 580 const uint8_t *bptr = avpkt->data;
850 580 int len = avpkt->size;
851 580 int ret = 0;
852 int i;
853
854
2/2
✓ Branch 0 taken 8337 times.
✓ Branch 1 taken 580 times.
8917 for (i = 0; i < len; i += 3) {
855 8337 uint8_t hi, cc_type = bptr[i] & 1;
856
857
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8333 times.
8337 if (ctx->data_field < 0)
858 4 ctx->data_field = cc_type;
859
860
2/2
✓ Branch 1 taken 5378 times.
✓ Branch 2 taken 2959 times.
8337 if (validate_cc_data_pair(bptr + i, &hi))
861 8134 continue;
862
863
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 2757 times.
2959 if (cc_type != ctx->data_field)
864 202 continue;
865
866 2757 ret = process_cc608(ctx, hi & 0x7f, bptr[i + 2] & 0x7f);
867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2757 times.
2757 if (ret < 0)
868 return ret;
869
870
2/2
✓ Branch 0 taken 2554 times.
✓ Branch 1 taken 203 times.
2757 if (!ctx->buffer_changed)
871 2554 continue;
872 203 ctx->buffer_changed = 0;
873
874
3/4
✓ Branch 0 taken 203 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197 times.
✓ Branch 3 taken 6 times.
203 if (!ctx->real_time && ctx->mode == CCMODE_POPON)
875 197 ctx->buffer_index = bidx = !ctx->buffer_index;
876
877 203 update_time(ctx, in_time);
878
879
3/4
✓ Branch 0 taken 106 times.
✓ Branch 1 taken 97 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 106 times.
203 if (ctx->buffer[bidx].str[0] || ctx->real_time) {
880 ff_dlog(ctx, "cdp writing data (%s)\n", ctx->buffer[bidx].str);
881 97 start_time = ctx->buffer_time[0];
882 97 sub->pts = start_time;
883 97 end_time = ctx->buffer_time[1];
884
1/2
✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
97 if (!ctx->real_time)
885 97 sub->end_display_time = av_rescale_q(end_time - start_time,
886 97 AV_TIME_BASE_Q, ms_tb);
887 else
888 sub->end_display_time = -1;
889 97 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 97 times.
97 if (ret < 0)
891 return ret;
892 97 ctx->last_real_time = sub->pts;
893 97 ctx->screen_touched = 0;
894 }
895 }
896
897
5/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 576 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
580 if (!bptr && !ctx->real_time && ctx->buffer[!ctx->buffer_index].str[0]) {
898 bidx = !ctx->buffer_index;
899 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
900 if (ret < 0)
901 return ret;
902 sub->pts = ctx->buffer_time[1];
903 sub->end_display_time = av_rescale_q(ctx->buffer_time[1] - ctx->buffer_time[0],
904 AV_TIME_BASE_Q, ms_tb);
905 if (sub->end_display_time == 0)
906 sub->end_display_time = ctx->buffer[bidx].len * 20;
907 }
908
909
4/4
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 444 times.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 98 times.
580 if (ctx->real_time && ctx->screen_touched &&
910
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30 times.
38 sub->pts >= ctx->last_real_time + av_rescale_q(ctx->real_time_latency_msec, ms_tb, AV_TIME_BASE_Q)) {
911 8 ctx->last_real_time = sub->pts;
912 8 ctx->screen_touched = 0;
913
914 8 capture_screen(ctx);
915 8 ctx->buffer_changed = 0;
916
917 8 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (ret < 0)
919 return ret;
920 8 sub->end_display_time = -1;
921 }
922
923 580 *got_sub = sub->num_rects > 0;
924 580 return ret;
925 }
926
927 #define OFFSET(x) offsetof(CCaptionSubContext, x)
928 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
929 static const AVOption options[] = {
930 { "real_time", "emit subtitle events as they are decoded for real-time display", OFFSET(real_time), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, SD },
931 { "real_time_latency_msec", "minimum elapsed time between emitting real-time subtitle events", OFFSET(real_time_latency_msec), AV_OPT_TYPE_INT, { .i64 = 200 }, 0, 500, SD },
932 { "data_field", "select data field", OFFSET(data_field), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, "data_field" },
933 { "auto", "pick first one that appears", 0, AV_OPT_TYPE_CONST, { .i64 =-1 }, 0, 0, SD, "data_field" },
934 { "first", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD, "data_field" },
935 { "second", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, SD, "data_field" },
936 {NULL}
937 };
938
939 static const AVClass ccaption_dec_class = {
940 .class_name = "Closed caption Decoder",
941 .item_name = av_default_item_name,
942 .option = options,
943 .version = LIBAVUTIL_VERSION_INT,
944 };
945
946 const AVCodec ff_ccaption_decoder = {
947 .name = "cc_dec",
948 .long_name = NULL_IF_CONFIG_SMALL("Closed Caption (EIA-608 / CEA-708)"),
949 .type = AVMEDIA_TYPE_SUBTITLE,
950 .id = AV_CODEC_ID_EIA_608,
951 .priv_data_size = sizeof(CCaptionSubContext),
952 .init = init_decoder,
953 .close = close_decoder,
954 .flush = flush_decoder,
955 .decode = decode,
956 .priv_class = &ccaption_dec_class,
957 .capabilities = AV_CODEC_CAP_DELAY,
958 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
959 };
960