2 * Closed Caption Decoding
3 * Copyright (c) 2015 Anshul Maheshwari
5 * This file is part of FFmpeg.
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.
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.
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
24 #include "libavutil/opt.h"
26 #define SCREEN_ROWS 15
27 #define SCREEN_COLUMNS 32
29 #define SET_FLAG(var, val) ( (var) |= ( 1 << (val)) )
30 #define UNSET_FLAG(var, val) ( (var) &= ~( 1 << (val)) )
31 #define CHECK_FLAG(var, val) ( (var) & ( 1 << (val)) )
33 static const AVRational ms_tb = {1, 1000};
59 CCFONT_UNDERLINED_ITALICS,
64 CCSET_SPECIAL_AMERICAN,
65 CCSET_EXTENDED_SPANISH_FRENCH_MISC,
66 CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH,
69 static const char *charset_overrides[4][128] =
71 [CCSET_BASIC_AMERICAN] = {
84 [CCSET_SPECIAL_AMERICAN] = {
102 [CCSET_EXTENDED_SPANISH_FRENCH_MISC] = {
136 [CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH] = {
172 static const unsigned char pac2_attribs[32][3] = // Color, font, ident
174 { CCCOL_WHITE, CCFONT_REGULAR, 0 }, // 0x40 || 0x60
175 { CCCOL_WHITE, CCFONT_UNDERLINED, 0 }, // 0x41 || 0x61
176 { CCCOL_GREEN, CCFONT_REGULAR, 0 }, // 0x42 || 0x62
177 { CCCOL_GREEN, CCFONT_UNDERLINED, 0 }, // 0x43 || 0x63
178 { CCCOL_BLUE, CCFONT_REGULAR, 0 }, // 0x44 || 0x64
179 { CCCOL_BLUE, CCFONT_UNDERLINED, 0 }, // 0x45 || 0x65
180 { CCCOL_CYAN, CCFONT_REGULAR, 0 }, // 0x46 || 0x66
181 { CCCOL_CYAN, CCFONT_UNDERLINED, 0 }, // 0x47 || 0x67
182 { CCCOL_RED, CCFONT_REGULAR, 0 }, // 0x48 || 0x68
183 { CCCOL_RED, CCFONT_UNDERLINED, 0 }, // 0x49 || 0x69
184 { CCCOL_YELLOW, CCFONT_REGULAR, 0 }, // 0x4a || 0x6a
185 { CCCOL_YELLOW, CCFONT_UNDERLINED, 0 }, // 0x4b || 0x6b
186 { CCCOL_MAGENTA, CCFONT_REGULAR, 0 }, // 0x4c || 0x6c
187 { CCCOL_MAGENTA, CCFONT_UNDERLINED, 0 }, // 0x4d || 0x6d
188 { CCCOL_WHITE, CCFONT_ITALICS, 0 }, // 0x4e || 0x6e
189 { CCCOL_WHITE, CCFONT_UNDERLINED_ITALICS, 0 }, // 0x4f || 0x6f
190 { CCCOL_WHITE, CCFONT_REGULAR, 0 }, // 0x50 || 0x70
191 { CCCOL_WHITE, CCFONT_UNDERLINED, 0 }, // 0x51 || 0x71
192 { CCCOL_WHITE, CCFONT_REGULAR, 4 }, // 0x52 || 0x72
193 { CCCOL_WHITE, CCFONT_UNDERLINED, 4 }, // 0x53 || 0x73
194 { CCCOL_WHITE, CCFONT_REGULAR, 8 }, // 0x54 || 0x74
195 { CCCOL_WHITE, CCFONT_UNDERLINED, 8 }, // 0x55 || 0x75
196 { CCCOL_WHITE, CCFONT_REGULAR, 12 }, // 0x56 || 0x76
197 { CCCOL_WHITE, CCFONT_UNDERLINED, 12 }, // 0x57 || 0x77
198 { CCCOL_WHITE, CCFONT_REGULAR, 16 }, // 0x58 || 0x78
199 { CCCOL_WHITE, CCFONT_UNDERLINED, 16 }, // 0x59 || 0x79
200 { CCCOL_WHITE, CCFONT_REGULAR, 20 }, // 0x5a || 0x7a
201 { CCCOL_WHITE, CCFONT_UNDERLINED, 20 }, // 0x5b || 0x7b
202 { CCCOL_WHITE, CCFONT_REGULAR, 24 }, // 0x5c || 0x7c
203 { CCCOL_WHITE, CCFONT_UNDERLINED, 24 }, // 0x5d || 0x7d
204 { CCCOL_WHITE, CCFONT_REGULAR, 28 }, // 0x5e || 0x7e
205 { CCCOL_WHITE, CCFONT_UNDERLINED, 28 } // 0x5f || 0x7f
206 /* total 32 entries */
210 /* +1 is used to compensate null character of string */
211 uint8_t characters[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
212 uint8_t charsets[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
213 uint8_t colors[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
214 uint8_t fonts[SCREEN_ROWS+1][SCREEN_COLUMNS+1];
216 * Bitmask of used rows; if a bit is not set, the
217 * corresponding row is not used.
218 * for setting row 1 use row | (1 << 0)
219 * for setting row 15 use row | (1 << 14)
224 typedef struct CCaptionSubContext {
228 struct Screen screen[2];
231 uint8_t cursor_column;
232 uint8_t cursor_color;
234 uint8_t cursor_charset;
240 int64_t buffer_time[2];
242 int64_t last_real_time;
245 } CCaptionSubContext;
247 static av_cold int init_decoder(AVCodecContext *avctx)
250 CCaptionSubContext *ctx = avctx->priv_data;
252 av_bprint_init(&ctx->buffer[0], 0, AV_BPRINT_SIZE_UNLIMITED);
253 av_bprint_init(&ctx->buffer[1], 0, AV_BPRINT_SIZE_UNLIMITED);
254 /* taking by default roll up to 2 */
255 ctx->mode = CCMODE_ROLLUP;
257 ctx->cursor_row = 10;
258 ret = ff_ass_subtitle_header(avctx, "Monospace",
259 ASS_DEFAULT_FONT_SIZE,
261 ASS_DEFAULT_BACK_COLOR,
264 ASS_DEFAULT_UNDERLINE,
266 ASS_DEFAULT_ALIGNMENT);
274 static av_cold int close_decoder(AVCodecContext *avctx)
276 CCaptionSubContext *ctx = avctx->priv_data;
277 av_bprint_finalize(&ctx->buffer[0], NULL);
278 av_bprint_finalize(&ctx->buffer[1], NULL);
282 static void flush_decoder(AVCodecContext *avctx)
284 CCaptionSubContext *ctx = avctx->priv_data;
285 ctx->screen[0].row_used = 0;
286 ctx->screen[1].row_used = 0;
287 ctx->prev_cmd[0] = 0;
288 ctx->prev_cmd[1] = 0;
289 ctx->mode = CCMODE_ROLLUP;
291 ctx->cursor_row = 10;
292 ctx->cursor_column = 0;
293 ctx->cursor_font = 0;
294 ctx->cursor_color = 0;
295 ctx->cursor_charset = 0;
296 ctx->active_screen = 0;
297 ctx->last_real_time = 0;
298 ctx->screen_touched = 0;
299 ctx->buffer_changed = 0;
300 if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
302 av_bprint_clear(&ctx->buffer[0]);
303 av_bprint_clear(&ctx->buffer[1]);
307 * @param ctx closed caption context just to print log
309 static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
311 uint8_t col = ctx->cursor_column;
312 char *row = screen->characters[ctx->cursor_row];
313 char *font = screen->fonts[ctx->cursor_row];
314 char *color = screen->colors[ctx->cursor_row];
315 char *charset = screen->charsets[ctx->cursor_row];
317 if (col < SCREEN_COLUMNS) {
319 font[col] = ctx->cursor_font;
320 color[col] = ctx->cursor_color;
321 charset[col] = ctx->cursor_charset;
322 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
323 if (ch) ctx->cursor_column++;
326 /* We have extra space at end only for null character */
327 else if (col == SCREEN_COLUMNS && ch == 0) {
332 av_log(ctx, AV_LOG_WARNING, "Data Ignored since exceeding screen width\n");
338 * This function after validating parity bit, also remove it from data pair.
339 * The first byte doesn't pass parity, we replace it with a solid blank
340 * and process the pair.
341 * If the second byte doesn't pass parity, it returns INVALIDDATA
342 * user can ignore the whole pair and pass the other pair.
344 static int validate_cc_data_pair(uint8_t *cc_data_pair)
346 uint8_t cc_valid = (*cc_data_pair & 4) >>2;
347 uint8_t cc_type = *cc_data_pair & 3;
350 return AVERROR_INVALIDDATA;
352 // if EIA-608 data then verify parity.
353 if (cc_type==0 || cc_type==1) {
354 if (!av_parity(cc_data_pair[2])) {
355 return AVERROR_INVALIDDATA;
357 if (!av_parity(cc_data_pair[1])) {
358 cc_data_pair[1]=0x7F;
363 if ((cc_data_pair[0] == 0xFA || cc_data_pair[0] == 0xFC || cc_data_pair[0] == 0xFD)
364 && (cc_data_pair[1] & 0x7F) == 0 && (cc_data_pair[2] & 0x7F) == 0)
365 return AVERROR_PATCHWELCOME;
368 if (cc_type == 3 || cc_type == 2)
369 return AVERROR_PATCHWELCOME;
374 static struct Screen *get_writing_screen(CCaptionSubContext *ctx)
378 // use Inactive screen
379 return ctx->screen + !ctx->active_screen;
384 return ctx->screen + ctx->active_screen;
386 /* It was never an option */
390 static void roll_up(CCaptionSubContext *ctx)
392 struct Screen *screen;
395 if (ctx->mode == CCMODE_TEXT)
398 screen = get_writing_screen(ctx);
400 /* +1 signify cursor_row starts from 0
401 * Can't keep lines less then row cursor pos
403 keep_lines = FFMIN(ctx->cursor_row + 1, ctx->rollup);
405 for (i = 0; i < SCREEN_ROWS; i++) {
406 if (i > ctx->cursor_row - keep_lines && i <= ctx->cursor_row)
408 UNSET_FLAG(screen->row_used, i);
411 for (i = 0; i < keep_lines && screen->row_used; i++) {
412 const int i_row = ctx->cursor_row - keep_lines + i + 1;
414 memcpy(screen->characters[i_row], screen->characters[i_row+1], SCREEN_COLUMNS);
415 memcpy(screen->colors[i_row], screen->colors[i_row+1], SCREEN_COLUMNS);
416 memcpy(screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
417 memcpy(screen->charsets[i_row], screen->charsets[i_row+1], SCREEN_COLUMNS);
418 if (CHECK_FLAG(screen->row_used, i_row + 1))
419 SET_FLAG(screen->row_used, i_row);
422 UNSET_FLAG(screen->row_used, ctx->cursor_row);
425 static int capture_screen(CCaptionSubContext *ctx)
428 struct Screen *screen = ctx->screen + ctx->active_screen;
429 enum cc_font prev_font = CCFONT_REGULAR;
430 enum cc_color_code prev_color = CCCOL_WHITE;
431 const int bidx = ctx->buffer_index;
433 av_bprint_clear(&ctx->buffer[bidx]);
435 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
437 if (CHECK_FLAG(screen->row_used, i)) {
438 const char *row = screen->characters[i];
439 const char *charset = screen->charsets[i];
441 while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN)
448 for (i = 0; screen->row_used && i < SCREEN_ROWS; i++)
450 if (CHECK_FLAG(screen->row_used, i)) {
451 const char *row = screen->characters[i];
452 const char *font = screen->fonts[i];
453 const char *color = screen->colors[i];
454 const char *charset = screen->charsets[i];
455 const char *override;
456 int x, y, seen_char = 0;
459 /* skip leading space */
460 while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN && j < tab)
463 x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
464 y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
465 av_bprintf(&ctx->buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
467 for (; j < SCREEN_COLUMNS; j++) {
468 const char *e_tag = "", *s_tag = "", *c_tag = "";
473 if (prev_font != font[j]) {
478 case CCFONT_UNDERLINED:
481 case CCFONT_UNDERLINED_ITALICS:
482 e_tag = "{\\u0}{\\i0}";
489 case CCFONT_UNDERLINED:
492 case CCFONT_UNDERLINED_ITALICS:
493 s_tag = "{\\u1}{\\i1}";
497 if (prev_color != color[j]) {
500 c_tag = "{\\c&HFFFFFF&}";
503 c_tag = "{\\c&H00FF00&}";
506 c_tag = "{\\c&HFF0000&}";
509 c_tag = "{\\c&HFFFF00&}";
512 c_tag = "{\\c&H0000FF&}";
515 c_tag = "{\\c&H00FFFF&}";
518 c_tag = "{\\c&HFF00FF&}";
524 prev_color = color[j];
525 override = charset_overrides[(int)charset[j]][(int)row[j]];
527 av_bprintf(&ctx->buffer[bidx], "%s%s%s%s", e_tag, s_tag, c_tag, override);
529 } else if (row[j] == ' ' && !seen_char) {
530 av_bprintf(&ctx->buffer[bidx], "%s%s%s\\h", e_tag, s_tag, c_tag);
532 av_bprintf(&ctx->buffer[bidx], "%s%s%s%c", e_tag, s_tag, c_tag, row[j]);
537 av_bprintf(&ctx->buffer[bidx], "\\N");
540 if (!av_bprint_is_complete(&ctx->buffer[bidx]))
541 return AVERROR(ENOMEM);
542 if (screen->row_used && ctx->buffer[bidx].len >= 2) {
543 ctx->buffer[bidx].len -= 2;
544 ctx->buffer[bidx].str[ctx->buffer[bidx].len] = 0;
546 ctx->buffer_changed = 1;
550 static void update_time(CCaptionSubContext *ctx, int64_t pts)
552 ctx->buffer_time[0] = ctx->buffer_time[1];
553 ctx->buffer_time[1] = pts;
556 static void handle_textattr(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
559 struct Screen *screen = get_writing_screen(ctx);
564 ctx->cursor_color = pac2_attribs[i][0];
565 ctx->cursor_font = pac2_attribs[i][1];
567 SET_FLAG(screen->row_used, ctx->cursor_row);
568 write_char(ctx, screen, ' ');
571 static void handle_pac(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
573 static const int8_t row_map[] = {
574 11, -1, 1, 2, 3, 4, 12, 13, 14, 15, 5, 6, 7, 8, 9, 10
576 const int index = ( (hi<<1) & 0x0e) | ( (lo>>5) & 0x01 );
577 struct Screen *screen = get_writing_screen(ctx);
580 if (row_map[index] <= 0) {
581 av_log(ctx, AV_LOG_DEBUG, "Invalid pac index encountered\n");
587 ctx->cursor_row = row_map[index] - 1;
588 ctx->cursor_color = pac2_attribs[lo][0];
589 ctx->cursor_font = pac2_attribs[lo][1];
590 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
591 ctx->cursor_column = 0;
592 indent = pac2_attribs[lo][2];
593 for (i = 0; i < indent; i++) {
594 write_char(ctx, screen, ' ');
598 static int handle_edm(CCaptionSubContext *ctx)
600 struct Screen *screen = ctx->screen + ctx->active_screen;
603 // In buffered mode, keep writing to screen until it is wiped.
604 // Before wiping the display, capture contents to emit subtitle.
606 ret = capture_screen(ctx);
608 screen->row_used = 0;
610 // In realtime mode, emit an empty caption so the last one doesn't
611 // stay on the screen.
613 ret = capture_screen(ctx);
618 static int handle_eoc(CCaptionSubContext *ctx)
622 ctx->active_screen = !ctx->active_screen;
624 // In buffered mode, we wait til the *next* EOC and
625 // capture what was already on the screen since the last EOC.
627 ret = handle_edm(ctx);
629 ctx->cursor_column = 0;
631 // In realtime mode, we display the buffered contents (after
632 // flipping the buffer to active above) as soon as EOC arrives.
634 ret = capture_screen(ctx);
639 static void handle_delete_end_of_row(CCaptionSubContext *ctx)
641 struct Screen *screen = get_writing_screen(ctx);
642 write_char(ctx, screen, 0);
645 static void handle_char(CCaptionSubContext *ctx, char hi, char lo)
647 struct Screen *screen = get_writing_screen(ctx);
649 SET_FLAG(screen->row_used, ctx->cursor_row);
653 ctx->cursor_charset = CCSET_SPECIAL_AMERICAN;
656 if (ctx->cursor_column > 0)
657 ctx->cursor_column -= 1;
658 ctx->cursor_charset = CCSET_EXTENDED_SPANISH_FRENCH_MISC;
661 if (ctx->cursor_column > 0)
662 ctx->cursor_column -= 1;
663 ctx->cursor_charset = CCSET_EXTENDED_PORTUGUESE_GERMAN_DANISH;
666 ctx->cursor_charset = CCSET_BASIC_AMERICAN;
667 write_char(ctx, screen, hi);
672 write_char(ctx, screen, lo);
674 write_char(ctx, screen, 0);
676 if (ctx->mode != CCMODE_POPON)
677 ctx->screen_touched = 1;
680 ff_dlog(ctx, "(%c,%c)\n", hi, lo);
682 ff_dlog(ctx, "(%c)\n", hi);
685 static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo)
689 if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
693 /* set prev command */
694 ctx->prev_cmd[0] = hi;
695 ctx->prev_cmd[1] = lo;
697 if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
698 ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
699 handle_pac(ctx, hi, lo);
700 } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
701 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
702 handle_textattr(ctx, hi, lo);
703 } else if (hi == 0x14 || hi == 0x15 || hi == 0x1c) {
706 /* resume caption loading */
707 ctx->mode = CCMODE_POPON;
710 handle_delete_end_of_row(ctx);
715 ctx->rollup = lo - 0x23;
716 ctx->mode = CCMODE_ROLLUP;
719 /* resume direct captioning */
720 ctx->mode = CCMODE_PAINTON;
723 /* resume text display */
724 ctx->mode = CCMODE_TEXT;
727 /* erase display memory */
731 /* carriage return */
732 ff_dlog(ctx, "carriage return\n");
734 ret = capture_screen(ctx);
736 ctx->cursor_column = 0;
739 /* erase buffered (non displayed) memory */
740 // Only in realtime mode. In buffered mode, we re-use the inactive screen
741 // for our own buffering.
742 if (ctx->real_time) {
743 struct Screen *screen = ctx->screen + !ctx->active_screen;
744 screen->row_used = 0;
749 ff_dlog(ctx, "handle_eoc\n");
750 ret = handle_eoc(ctx);
753 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
756 } else if (hi >= 0x11 && hi <= 0x13) {
757 /* Special characters */
758 handle_char(ctx, hi, lo);
759 } else if (hi >= 0x20) {
760 /* Standard characters (always in pairs) */
761 handle_char(ctx, hi, lo);
762 ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
763 } else if (hi == 0x17 && lo >= 0x21 && lo <= 0x23) {
765 /* Tab offsets (spacing) */
766 for (i = 0; i < lo - 0x20; i++) {
767 handle_char(ctx, ' ', 0);
770 /* Ignoring all other non data code */
771 ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
777 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
779 CCaptionSubContext *ctx = avctx->priv_data;
780 AVSubtitle *sub = data;
781 int64_t in_time = sub->pts;
784 int bidx = ctx->buffer_index;
785 uint8_t *bptr = NULL;
786 int len = avpkt->size;
792 for (i = 0; i < len; i += 3) {
793 uint8_t cc_type = bptr[i] & 1;
795 if (ctx->data_field < 0)
796 ctx->data_field = cc_type;
798 if (validate_cc_data_pair(bptr + i))
801 if (cc_type != ctx->data_field)
804 ret = process_cc608(ctx, bptr[i + 1] & 0x7f, bptr[i + 2] & 0x7f);
808 if (!ctx->buffer_changed)
810 ctx->buffer_changed = 0;
812 if (!ctx->real_time && ctx->mode == CCMODE_POPON)
813 ctx->buffer_index = bidx = !ctx->buffer_index;
815 update_time(ctx, in_time);
817 if (ctx->buffer[bidx].str[0] || ctx->real_time) {
818 ff_dlog(ctx, "cdp writing data (%s)\n", ctx->buffer[bidx].str);
819 start_time = ctx->buffer_time[0];
820 sub->pts = start_time;
821 end_time = ctx->buffer_time[1];
823 sub->end_display_time = av_rescale_q(end_time - start_time,
824 AV_TIME_BASE_Q, ms_tb);
826 sub->end_display_time = -1;
827 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
830 ctx->last_real_time = sub->pts;
831 ctx->screen_touched = 0;
835 if (!bptr && !ctx->real_time && ctx->buffer[!ctx->buffer_index].str[0]) {
836 bidx = !ctx->buffer_index;
837 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
840 sub->pts = ctx->buffer_time[1];
841 sub->end_display_time = av_rescale_q(ctx->buffer_time[1] - ctx->buffer_time[0],
842 AV_TIME_BASE_Q, ms_tb);
843 if (sub->end_display_time == 0)
844 sub->end_display_time = ctx->buffer[bidx].len * 20;
847 if (ctx->real_time && ctx->screen_touched &&
848 sub->pts > ctx->last_real_time + av_rescale_q(200, ms_tb, AV_TIME_BASE_Q)) {
849 ctx->last_real_time = sub->pts;
850 ctx->screen_touched = 0;
853 ctx->buffer_changed = 0;
855 ret = ff_ass_add_rect(sub, ctx->buffer[bidx].str, ctx->readorder++, 0, NULL, NULL);
858 sub->end_display_time = -1;
861 *got_sub = sub->num_rects > 0;
865 #define OFFSET(x) offsetof(CCaptionSubContext, x)
866 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
867 static const AVOption options[] = {
868 { "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 },
869 { "data_field", "select data field", OFFSET(data_field), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, SD, "data_field" },
870 { "auto", "pick first one that appears", 0, AV_OPT_TYPE_CONST, { .i64 =-1 }, 0, 0, SD, "data_field" },
871 { "first", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, SD, "data_field" },
872 { "second", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, SD, "data_field" },
876 static const AVClass ccaption_dec_class = {
877 .class_name = "Closed caption Decoder",
878 .item_name = av_default_item_name,
880 .version = LIBAVUTIL_VERSION_INT,
883 AVCodec ff_ccaption_decoder = {
885 .long_name = NULL_IF_CONFIG_SMALL("Closed Caption (EIA-608 / CEA-708)"),
886 .type = AVMEDIA_TYPE_SUBTITLE,
887 .id = AV_CODEC_ID_EIA_608,
888 .priv_data_size = sizeof(CCaptionSubContext),
889 .init = init_decoder,
890 .close = close_decoder,
891 .flush = flush_decoder,
893 .priv_class = &ccaption_dec_class,
894 .capabilities = AV_CODEC_CAP_DELAY,