// This should be moved to 708.c // This works for popon, but bad for paint on and roll up // Please understand this function before you try to use it, setting null values have different effects than you may assume void sei_encode_eia608 (sei_t* sei, cea708_t* cea708, uint16_t cc_data) { // This one is full, flush and init a new one // shoudl this be 32? I cant remember if (31 == cea708->user_data.cc_count) { sei_append_708 (sei,cea708); } if (0 == cea708->user_data.cc_count) { // This is a new 708 header, but a continuation of a 608 stream cea708_add_cc_data (cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command (eia608_control_resume_caption_loading, DEFAULT_CHANNEL)); } if (0 == cc_data) { // Finished sei_encode_eia608 (sei,cea708,eia608_control_command (eia608_control_end_of_caption, DEFAULT_CHANNEL)); sei_append_708 (sei,cea708); return; } cea708_add_cc_data (cea708, 1, cc_type_ntsc_cc_field_1, cc_data); }
libcaption_stauts_t sei_from_caption_clear(sei_t* sei) { cea708_t cea708; cea708_init(&cea708, sei->timestamp); // set up a new popon frame cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_end_of_caption, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_end_of_caption, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_erase_non_displayed_memory, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_erase_non_displayed_memory, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_erase_display_memory, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_erase_display_memory, DEFAULT_CHANNEL)); sei_append_708(sei, &cea708); return LIBCAPTION_OK; }
//////////////////////////////////////////////////////////////////////////////// // TODO move this out of sei libcaption_stauts_t sei_from_caption_frame(sei_t* sei, caption_frame_t* frame) { int r, c; int unl, prev_unl; cea708_t cea708; const char* data; uint16_t prev_cc_data; eia608_style_t styl, prev_styl; sei_init(sei, frame->timestamp); cea708_init(&cea708, frame->timestamp); // set up a new popon frame cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_erase_non_displayed_memory, DEFAULT_CHANNEL)); cea708_add_cc_data(&cea708, 1, cc_type_ntsc_cc_field_1, eia608_control_command(eia608_control_resume_caption_loading, DEFAULT_CHANNEL)); for (r = 0; r < SCREEN_ROWS; ++r) { prev_unl = 0, prev_styl = eia608_style_white; // Calculate preamble for (c = 0; c < SCREEN_COLS && 0 == *caption_frame_read_char(frame, r, c, &styl, &unl); ++c) { } // This row is blank if (SCREEN_COLS == c) { continue; } // Write preamble if (0 < c || (0 == unl && eia608_style_white == styl)) { int tab = c % 4; sei_encode_eia608(sei, &cea708, eia608_row_column_pramble(r, c, DEFAULT_CHANNEL, 0)); if (tab) { sei_encode_eia608(sei, &cea708, eia608_tab(tab, DEFAULT_CHANNEL)); } } else { sei_encode_eia608(sei, &cea708, eia608_row_style_pramble(r, DEFAULT_CHANNEL, styl, unl)); prev_unl = unl, prev_styl = styl; } // Write the row for (prev_cc_data = 0, data = caption_frame_read_char(frame, r, c, 0, 0); (*data) && c < SCREEN_COLS; ++c, data = caption_frame_read_char(frame, r, c, &styl, &unl)) { uint16_t cc_data = eia608_from_utf8_1(data, DEFAULT_CHANNEL); if (unl != prev_unl || styl != prev_styl) { sei_encode_eia608(sei, &cea708, eia608_midrow_change(DEFAULT_CHANNEL, styl, unl)); prev_unl = unl, prev_styl = styl; } if (!cc_data) { // We do't want to write bad data, so just ignore it. } else if (eia608_is_basicna(prev_cc_data)) { if (eia608_is_basicna(cc_data)) { // previous and current chars are both basicna, combine them into current sei_encode_eia608(sei, &cea708, eia608_from_basicna(prev_cc_data, cc_data)); } else if (eia608_is_westeu(cc_data)) { // extended charcters overwrite the previous charcter, so insert a dummy char thren write the extended char sei_encode_eia608(sei, &cea708, eia608_from_basicna(prev_cc_data, eia608_from_utf8_1(EIA608_CHAR_SPACE, DEFAULT_CHANNEL))); sei_encode_eia608(sei, &cea708, cc_data); } else { // previous was basic na, but current isnt; write previous and current sei_encode_eia608(sei, &cea708, prev_cc_data); sei_encode_eia608(sei, &cea708, cc_data); } prev_cc_data = 0; // previous is handled, we can forget it now } else if (eia608_is_westeu(cc_data)) { // extended chars overwrite the previous chars, so insert a dummy char // TODO create a map of alternamt chars for eia608_is_westeu instead of using space sei_encode_eia608(sei, &cea708, eia608_from_utf8_1(EIA608_CHAR_SPACE, DEFAULT_CHANNEL)); sei_encode_eia608(sei, &cea708, cc_data); } else if (eia608_is_basicna(cc_data)) { prev_cc_data = cc_data; } else { sei_encode_eia608(sei, &cea708, cc_data); } if (eia608_is_specialna(cc_data)) { // specialna are treated as control charcters. Duplicated control charcters are discarded // So we write a resume after a specialna as a noop to break repetition detection // TODO only do this if the same charcter is repeated sei_encode_eia608(sei, &cea708, eia608_control_command(eia608_control_resume_caption_loading, DEFAULT_CHANNEL)); } } if (0 != prev_cc_data) { sei_encode_eia608(sei, &cea708, prev_cc_data); } } sei_encode_eia608(sei, &cea708, 0); // flush sei->timestamp = frame->timestamp; // assumes in order frames // sei_dump (sei); return LIBCAPTION_OK; }