1 #ifndef CCX_DECODERS_STRUCTS_H
2 #define CCX_DECODERS_STRUCTS_H
3 
4 #include "ccx_common_platform.h"
5 #include "ccx_common_constants.h"
6 #include "ccx_common_timing.h"
7 #include "ccx_common_structs.h"
8 #include "list.h"
9 #include "ccx_decoders_708.h"
10 // Define max width in characters/columns on the screen
11 #define CCX_DECODER_608_SCREEN_WIDTH  32
12 #define MAXBFRAMES 50
13 #define SORTBUF (2*MAXBFRAMES+1)
14 
15 
16 /* flag raised when end of display marker arrives in Dvb Subtitle */
17 #define SUB_EOD_MARKER (1 << 0 )
18 struct cc_bitmap
19 {
20 	int x;
21 	int y;
22 	int w;
23 	int h;
24 	int nb_colors;
25 	unsigned char *data[2];
26 	int linesize[2];
27 #ifdef ENABLE_OCR
28 	char *ocr_text;
29 #endif
30 };
31 
32 enum ccx_eia608_format
33 {
34 	SFORMAT_CC_SCREEN,
35 	SFORMAT_CC_LINE,
36 	SFORMAT_XDS
37 };
38 
39 enum cc_modes
40 {
41 	MODE_POPON = 0,
42 	MODE_ROLLUP_2 = 1,
43 	MODE_ROLLUP_3 = 2,
44 	MODE_ROLLUP_4 = 3,
45 	MODE_TEXT = 4,
46 	MODE_PAINTON = 5,
47 	// Fake modes to emulate stuff
48 	MODE_FAKE_ROLLUP_1 = 100
49 };
50 
51 /**
52 * This structure have fields which need to be ignored according to format,
53 * for example if format is SFORMAT_XDS then all fields other then
54 * xds related (xds_str, xds_len and  cur_xds_packet_class) should be
55 * ignored and not to be dereferenced.
56 *
57 * TODO use union inside struct for each kind of fields
58 */
59 typedef struct eia608_screen // A CC buffer
60 {
61 	/** format of data inside this structure */
62 	enum ccx_eia608_format format;
63 	unsigned char characters[15][33];
64 	unsigned char colors[15][33];
65 	unsigned char fonts[15][33]; // Extra char at the end for a 0
66 	int row_used[15];            // Any data in row?
67 	int empty;                   // Buffer completely empty?
68 	/** start time of this CC buffer */
69 	LLONG start_time;
70 	/** end time of this CC buffer */
71 	LLONG end_time;
72 	enum cc_modes mode;
73 	int channel;  // Currently selected channel
74 	int my_field; // Used for sanity checks
75 	/** XDS string */
76 	char *xds_str;
77 	/** length of XDS string */
78 	size_t xds_len;
79 	/** Class of XDS string */
80 	int cur_xds_packet_class;
81 } eia608_screen;
82 
83 struct ccx_decoders_common_settings_t
84 {
85 	LLONG subs_delay;                                          // ms to delay (or advance) subs
86 	enum ccx_output_format output_format;                      // What kind of output format should be used?
87 	int fix_padding;                                           // Replace 0000 with 8080 in HDTV (needed for some cards)
88 	struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process
89 	int cc_to_stdout;
90 	int extract;                                               // Extract 1st, 2nd or both fields
91 	int fullbin;                                               // Disable pruning of padding cc blocks
92 	int no_rollup;
93 	int noscte20;
94 	struct ccx_decoder_608_settings *settings_608;             // Contains the settings for the 608 decoder.
95 	ccx_decoder_dtvcc_settings *settings_dtvcc;                // Same for cea 708 captions decoder (dtvcc)
96 	int cc_channel;                                            // Channel we want to dump in srt mode
97 	unsigned send_to_srv;
98 	unsigned int hauppauge_mode;                               // If 1, use PID=1003, process specially and so on
99 	int program_number;
100 	enum ccx_code_type codec;
101 	int xds_write_to_file;
102 	void *private_data;
103 };
104 
105 struct lib_cc_decode
106 {
107 	int cc_stats[4];
108 	int saw_caption_block;
109 	int processed_enough; // If 1, we have enough lines, time, etc.
110 
111 	/* 608 contexts - note that this shouldn't be global, they should be
112 	per program */
113 	void *context_cc608_field_1;
114 	void *context_cc608_field_2;
115 
116 	int no_rollup;                                             // If 1, write one line at a time
117 	int noscte20;
118 	int fix_padding;                                           // Replace 0000 with 8080 in HDTV (needed for some cards)
119 	enum ccx_output_format write_format;                       // 0 = Raw, 1 = srt, 2 = SMI
120 	struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process
121 	LLONG subs_delay;                                          // ms to delay (or advance) subs
122 	int extract;                                               // Extract 1st, 2nd or both fields
123 	int fullbin;                                               // Disable pruning of padding cc blocks
124 	struct cc_subtitle dec_sub;
125 	enum ccx_bufferdata_type in_bufferdatatype;
126 	unsigned int hauppauge_mode;                               // If 1, use PID=1003, process specially and so on
127 
128 	int frames_since_last_gop;
129 	/* GOP-based timing */
130 	int saw_gop_header;
131 	/* Time info for timed-transcript */
132 	int max_gop_length;  // (Maximum) length of a group of pictures
133 	int last_gop_length; // Length of the previous group of pictures
134 	unsigned total_pulldownfields;
135 	unsigned total_pulldownframes;
136 	int program_number;
137 	struct list_head list;
138 	struct ccx_common_timing_ctx *timing;
139 	enum ccx_code_type codec;
140 	// Set to true if data is buffered
141 	int has_ccdata_buffered;
142 	int is_alloc;
143 
144 	struct avc_ctx *avc_ctx;
145 	void *private_data;
146 
147 	/* General video information */
148 	unsigned int current_hor_size;
149 	unsigned int current_vert_size;
150 	unsigned int current_aspect_ratio;
151 	unsigned int current_frame_rate; // Assume standard fps, 29.97
152 
153 	/* Required in es_function.c */
154 	int no_bitstream_error;
155 	int saw_seqgoppic;
156 	int in_pic_data;
157 
158 	unsigned int current_progressive_sequence;
159 	unsigned int current_pulldownfields ;
160 
161 	int temporal_reference;
162 	enum ccx_frame_type picture_coding_type;
163 	unsigned picture_structure;
164 	unsigned repeat_first_field;
165 	unsigned progressive_frame;
166 	unsigned pulldownfields;
167 	/* Required in es_function.c and es_userdata.c */
168 	unsigned top_field_first; // Needs to be global
169 
170     /* Stats. Modified in es_userdata.c*/
171     int stat_numuserheaders;
172     int stat_dvdccheaders;
173     int stat_scte20ccheaders;
174     int stat_replay5000headers;
175     int stat_replay4000headers;
176     int stat_dishheaders;
177     int stat_hdtv;
178     int stat_divicom;
179     int false_pict_header;
180 
181 	ccx_dtvcc_ctx *dtvcc;
182 	int current_field;
183 	// Analyse/use the picture information
184 	int maxtref; // Use to remember the temporal reference number
185 
186 	int cc_data_count[SORTBUF];
187 	// Store fts;
188 	LLONG cc_fts[SORTBUF];
189 	// Store HD CC packets
190 	unsigned char cc_data_pkts[SORTBUF][10*31*3+1]; // *10, because MP4 seems to have different limits
191 
192 	// The sequence number of the current anchor frame.  All currently read
193 	// B-Frames belong to this I- or P-frame.
194 	int anchor_seq_number;
195 	struct ccx_decoders_xds_context *xds_ctx;
196 	struct ccx_decoder_vbi_ctx *vbi_decoder;
197 
198 	int (*writedata)(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);
199 
200 	//dvb subtitle related
201 	struct lib_cc_decode *prev;
202 };
203 
204 #endif
205