1 #ifndef CCX_DECODER_608_H 2 #define CCX_DECODER_608_H 3 #include "ccx_common_platform.h" 4 #include "ccx_common_structs.h" 5 #include "ccx_decoders_structs.h" 6 7 extern LLONG ts_start_of_xds; 8 9 /* 10 This variable (ccx_decoder_608_report) holds data on the cc channels & xds packets that are encountered during file parse. 11 This can be interesting if you just want to know what kind of data a file holds that has 608 packets. CCExtractor uses it 12 for the report functionality. 13 */ 14 struct ccx_decoder_608_report 15 { 16 uint8_t xds : 1; 17 uint8_t cc_channels[4]; 18 }; 19 20 typedef struct ccx_decoder_608_settings 21 { 22 int direct_rollup; // Write roll-up captions directly instead of line by line? 23 int force_rollup; // 0=Disabled, 1, 2 or 3=max lines in roll-up mode 24 int no_rollup; // If 1, write one line at a time 25 unsigned char default_color; // Default color to use. 26 int screens_to_process; // How many screenfuls we want? Use -1 for unlimited 27 struct ccx_decoder_608_report *report; 28 } ccx_decoder_608_settings; 29 30 typedef struct ccx_decoder_608_context 31 { 32 ccx_decoder_608_settings *settings; 33 eia608_screen buffer1; 34 eia608_screen buffer2; 35 int cursor_row, cursor_column; 36 int visible_buffer; 37 int screenfuls_counter; // Number of meaningful screenfuls written 38 LLONG current_visible_start_ms; // At what time did the current visible buffer became so? 39 enum cc_modes mode; 40 unsigned char last_c1, last_c2; 41 int channel; // Currently selected channel 42 unsigned char current_color; // Color we are currently using to write 43 unsigned char font; // Font we are currently using to write 44 int rollup_base_row; 45 LLONG ts_start_of_current_line; /* Time at which the first character for current line was received, =-1 no character received yet */ 46 LLONG ts_last_char_received; /* Time at which the last written character was received, =-1 no character received yet */ 47 int new_channel; // The new channel after a channel change 48 int my_field; // Used for sanity checks 49 int my_channel; // Used for sanity checks 50 long bytes_processed_608; // To be written ONLY by process_608 51 int have_cursor_position; 52 53 int *halt; // Can be used to halt the feeding of caption data. Set to 1 if screens_to_progress != -1 && screenfuls_counter >= screens_to_process 54 int cc_to_stdout; // If this is set to 1, the stdout will be flushed when data was written to the screen during a process_608 call. 55 struct ccx_decoder_608_report *report; 56 LLONG subs_delay; // ms to delay (or advance) subs 57 enum ccx_output_format output_format; // What kind of output format should be used? 58 int textprinted; 59 struct ccx_common_timing_ctx *timing; 60 61 } ccx_decoder_608_context; 62 63 64 #define MAX_COLOR 10 65 extern const char *color_text[MAX_COLOR][2]; 66 67 typedef enum ccx_decoder_608_color_code 68 { 69 COL_WHITE = 0, 70 COL_GREEN = 1, 71 COL_BLUE = 2, 72 COL_CYAN = 3, 73 COL_RED = 4, 74 COL_YELLOW = 5, 75 COL_MAGENTA = 6, 76 COL_USERDEFINED = 7, 77 COL_BLACK = 8, 78 COL_TRANSPARENT = 9 79 } ccx_decoder_608_color_code; 80 81 82 enum font_bits 83 { 84 FONT_REGULAR = 0, 85 FONT_ITALICS = 1, 86 FONT_UNDERLINED = 2, 87 FONT_UNDERLINED_ITALICS = 3 88 }; 89 90 enum command_code 91 { 92 COM_UNKNOWN = 0, 93 COM_ERASEDISPLAYEDMEMORY = 1, 94 COM_RESUMECAPTIONLOADING = 2, 95 COM_ENDOFCAPTION = 3, 96 COM_TABOFFSET1 = 4, 97 COM_TABOFFSET2 = 5, 98 COM_TABOFFSET3 = 6, 99 COM_ROLLUP2 = 7, 100 COM_ROLLUP3 = 8, 101 COM_ROLLUP4 = 9, 102 COM_CARRIAGERETURN = 10, 103 COM_ERASENONDISPLAYEDMEMORY = 11, 104 COM_BACKSPACE = 12, 105 COM_RESUMETEXTDISPLAY = 13, 106 COM_ALARMOFF =14, 107 COM_ALARMON = 15, 108 COM_DELETETOENDOFROW = 16, 109 COM_RESUMEDIRECTCAPTIONING = 17, 110 // Non existing commands we insert to have the decoder 111 // special stuff for us. 112 COM_FAKE_RULLUP1 = 18 113 }; 114 115 116 void ccx_decoder_608_dinit_library(void **ctx); 117 /* 118 * 119 */ 120 ccx_decoder_608_context* ccx_decoder_608_init_library(struct ccx_decoder_608_settings *settings, int channel, 121 int field, int *halt, 122 int cc_to_stdout, 123 enum ccx_output_format output_format, struct ccx_common_timing_ctx *timing); 124 125 /** 126 * @param data raw cc608 data to be processed 127 * 128 * @param length length of data passed 129 * 130 * @param private_data context of cc608 where important information related to 608 131 * are stored. 132 * 133 * @param sub pointer to subtitle should be memset to 0 when passed first time 134 * subtitle are stored when structure return 135 * 136 * @return number of bytes used from data, -1 when any error is encountered 137 */ 138 int process608(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub); 139 140 /** 141 * Issue a EraseDisplayedMemory here so if there's any captions pending 142 * they get written to cc_subtitle 143 */ 144 void flush_608_context(ccx_decoder_608_context *context, struct cc_subtitle *sub); 145 146 int write_cc_buffer(ccx_decoder_608_context *context, struct cc_subtitle *sub); 147 148 #endif 149