1
|
1 /*
|
|
2 * mpeg2_internal.h
|
9852
|
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
|
|
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
1
|
5 *
|
|
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
9852
|
7 * See http://libmpeg2.sourceforge.net/ for updates.
|
1
|
8 *
|
|
9 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * mpeg2dec is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23
|
36
|
24 /* macroblock modes */
|
1
|
25 #define MACROBLOCK_INTRA 1
|
|
26 #define MACROBLOCK_PATTERN 2
|
|
27 #define MACROBLOCK_MOTION_BACKWARD 4
|
|
28 #define MACROBLOCK_MOTION_FORWARD 8
|
|
29 #define MACROBLOCK_QUANT 16
|
|
30 #define DCT_TYPE_INTERLACED 32
|
36
|
31 /* motion_type */
|
1
|
32 #define MOTION_TYPE_MASK (3*64)
|
|
33 #define MOTION_TYPE_BASE 64
|
|
34 #define MC_FIELD (1*64)
|
|
35 #define MC_FRAME (2*64)
|
|
36 #define MC_16X8 (2*64)
|
|
37 #define MC_DMV (3*64)
|
|
38
|
36
|
39 /* picture structure */
|
1
|
40 #define TOP_FIELD 1
|
|
41 #define BOTTOM_FIELD 2
|
|
42 #define FRAME_PICTURE 3
|
|
43
|
36
|
44 /* picture coding type */
|
1
|
45 #define I_TYPE 1
|
|
46 #define P_TYPE 2
|
|
47 #define B_TYPE 3
|
|
48 #define D_TYPE 4
|
|
49
|
9852
|
50 typedef struct {
|
1
|
51 uint8_t * ref[2][3];
|
9852
|
52 uint8_t ** ref2[2];
|
1
|
53 int pmv[2][2];
|
|
54 int f_code[2];
|
|
55 } motion_t;
|
|
56
|
9852
|
57 struct decoder_s {
|
36
|
58 /* first, state that carries information from one macroblock to the */
|
9852
|
59 /* next inside a slice, and is never used outside of mpeg2_slice() */
|
36
|
60
|
|
61 /* DCT coefficients - should be kept aligned ! */
|
|
62 int16_t DCTblock[64];
|
|
63
|
|
64 /* bit parsing stuff */
|
9852
|
65 uint32_t bitstream_buf; /* current 32 bit working set */
|
|
66 int bitstream_bits; /* used bits in working set */
|
|
67 const uint8_t * bitstream_ptr; /* buffer with stream data */
|
|
68
|
|
69 uint8_t * dest[3];
|
|
70 uint8_t * picture_dest[3];
|
|
71 void (* convert) (void * fbuf_id, uint8_t * const * src,
|
|
72 unsigned int v_offset);
|
|
73 void * fbuf_id;
|
|
74
|
|
75 int offset;
|
|
76 int stride;
|
|
77 int uv_stride;
|
|
78 unsigned int limit_x;
|
|
79 unsigned int limit_y_16;
|
|
80 unsigned int limit_y_8;
|
|
81 unsigned int limit_y;
|
36
|
82
|
|
83 /* Motion vectors */
|
|
84 /* The f_ and b_ correspond to the forward and backward motion */
|
|
85 /* predictors */
|
1
|
86 motion_t b_motion;
|
|
87 motion_t f_motion;
|
|
88
|
36
|
89 /* predictor for DC coefficients in intra blocks */
|
1
|
90 int16_t dc_dct_pred[3];
|
|
91
|
36
|
92 int quantizer_scale; /* remove */
|
9852
|
93 int dmv_offset; /* remove */
|
|
94 unsigned int v_offset; /* remove */
|
36
|
95
|
|
96 /* now non-slice-specific information */
|
|
97
|
|
98 /* sequence header stuff */
|
|
99 uint8_t intra_quantizer_matrix [64];
|
|
100 uint8_t non_intra_quantizer_matrix [64];
|
|
101
|
|
102 /* The width and height of the picture snapped to macroblock units */
|
9852
|
103 int width;
|
|
104 int height;
|
|
105 int vertical_position_extension;
|
36
|
106
|
|
107 /* picture header stuff */
|
|
108
|
|
109 /* what type of picture this is (I, P, B, D) */
|
9852
|
110 int coding_type;
|
|
111
|
36
|
112 /* picture coding extension stuff */
|
9852
|
113
|
36
|
114 /* quantization factor for intra dc coefficients */
|
|
115 int intra_dc_precision;
|
|
116 /* top/bottom/both fields */
|
|
117 int picture_structure;
|
|
118 /* bool to indicate all predictions are frame based */
|
|
119 int frame_pred_frame_dct;
|
|
120 /* bool to indicate whether intra blocks have motion vectors */
|
|
121 /* (for concealment) */
|
|
122 int concealment_motion_vectors;
|
|
123 /* bit to indicate which quantization table to use */
|
|
124 int q_scale_type;
|
|
125 /* bool to use different vlc tables */
|
|
126 int intra_vlc_format;
|
|
127 /* used for DMV MC */
|
|
128 int top_field_first;
|
|
129
|
|
130 /* stuff derived from bitstream */
|
|
131
|
|
132 /* pointer to the zigzag scan we're supposed to be using */
|
9852
|
133 const uint8_t * scan;
|
36
|
134
|
|
135 int second_field;
|
|
136
|
|
137 int mpeg1;
|
9855
|
138
|
|
139 /* for MPlayer: */
|
|
140 char* quant_store;
|
|
141 int quant_stride;
|
9852
|
142 };
|
36
|
143
|
9852
|
144 typedef struct {
|
|
145 fbuf_t fbuf;
|
|
146 } fbuf_alloc_t;
|
|
147
|
|
148 struct mpeg2dec_s {
|
|
149 decoder_t decoder;
|
|
150
|
|
151 mpeg2_info_t info;
|
|
152
|
|
153 uint32_t shift;
|
|
154 int is_display_initialized;
|
|
155 int (* action) (struct mpeg2dec_s * mpeg2dec);
|
|
156 int state;
|
|
157 uint32_t ext_state;
|
79
|
158
|
9852
|
159 /* allocated in init - gcc has problems allocating such big structures */
|
|
160 uint8_t * chunk_buffer;
|
|
161 /* pointer to start of the current chunk */
|
|
162 uint8_t * chunk_start;
|
|
163 /* pointer to current position in chunk_buffer */
|
|
164 uint8_t * chunk_ptr;
|
|
165 /* last start code ? */
|
|
166 uint8_t code;
|
|
167
|
|
168 /* PTS */
|
|
169 uint32_t pts_current, pts_previous;
|
|
170 int num_pts;
|
|
171 int bytes_since_pts;
|
|
172
|
|
173 int first;
|
|
174 int alloc_index_user;
|
|
175 int alloc_index;
|
|
176 uint8_t first_decode_slice;
|
|
177 uint8_t nb_decode_slices;
|
|
178
|
|
179 sequence_t new_sequence;
|
|
180 sequence_t sequence;
|
|
181 picture_t pictures[4];
|
|
182 picture_t * picture;
|
|
183 /*const*/ fbuf_t * fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */
|
|
184
|
|
185 fbuf_alloc_t fbuf_alloc[3];
|
|
186 int custom_fbuf;
|
79
|
187
|
9852
|
188 uint8_t * yuv_buf[3][3];
|
|
189 int yuv_index;
|
|
190 void * convert_id;
|
|
191 int convert_size[3];
|
|
192 void (* convert_start) (void * id, uint8_t * const * dest, int flags);
|
|
193 void (* convert_copy) (void * id, uint8_t * const * src,
|
|
194 unsigned int v_offset);
|
1
|
195
|
9852
|
196 uint8_t * buf_start;
|
|
197 uint8_t * buf_end;
|
|
198
|
|
199 int16_t display_offset_x, display_offset_y;
|
|
200 };
|
|
201
|
|
202 typedef struct {
|
|
203 #ifdef ARCH_PPC
|
|
204 uint8_t regv[12*16];
|
|
205 #endif
|
|
206 int dummy;
|
|
207 } cpu_state_t;
|
1
|
208
|
9852
|
209 /* alloc.c */
|
|
210 #define ALLOC_MPEG2DEC 0
|
|
211 #define ALLOC_CHUNK 1
|
|
212 #define ALLOC_YUV 2
|
|
213 #define ALLOC_CONVERT_ID 3
|
|
214 #define ALLOC_CONVERTED 4
|
|
215 void * mpeg2_malloc (int size, int reason);
|
|
216 void mpeg2_free (void * buf);
|
1
|
217
|
9852
|
218 /* cpu_accel.c */
|
|
219 uint32_t mpeg2_detect_accel (void);
|
1
|
220
|
9852
|
221 /* cpu_state.c */
|
|
222 void mpeg2_cpu_state_init (uint32_t accel);
|
1
|
223
|
9852
|
224 /* decode.c */
|
|
225 int mpeg2_seek_sequence (mpeg2dec_t * mpeg2dec);
|
|
226 int mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
|
|
227 int mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
|
|
228
|
|
229 /* header.c */
|
|
230 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec);
|
|
231 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec);
|
|
232 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec);
|
|
233 int mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec);
|
|
234 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec);
|
|
235 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec);
|
|
236 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec);
|
|
237 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec);
|
|
238 int mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec);
|
|
239 int mpeg2_header_end (mpeg2dec_t * mpeg2dec);
|
|
240 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int coding_type);
|
1
|
241
|
36
|
242 /* idct.c */
|
9852
|
243 void mpeg2_idct_init (uint32_t accel);
|
1
|
244
|
36
|
245 /* idct_mlib.c */
|
9852
|
246 void mpeg2_idct_add_mlib (int last, int16_t * block,
|
|
247 uint8_t * dest, int stride);
|
|
248 void mpeg2_idct_copy_mlib_non_ieee (int16_t * block, uint8_t * dest,
|
|
249 int stride);
|
|
250 void mpeg2_idct_add_mlib_non_ieee (int last, int16_t * block,
|
|
251 uint8_t * dest, int stride);
|
1
|
252
|
36
|
253 /* idct_mmx.c */
|
9852
|
254 void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride);
|
|
255 void mpeg2_idct_add_mmxext (int last, int16_t * block,
|
|
256 uint8_t * dest, int stride);
|
|
257 void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride);
|
|
258 void mpeg2_idct_add_mmx (int last, int16_t * block,
|
|
259 uint8_t * dest, int stride);
|
|
260 void mpeg2_idct_mmx_init (void);
|
|
261
|
|
262 /* idct_altivec.c */
|
|
263 void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride);
|
|
264 void mpeg2_idct_add_altivec (int last, int16_t * block,
|
|
265 uint8_t * dest, int stride);
|
|
266 void mpeg2_idct_altivec_init (void);
|
|
267
|
|
268 /* idct_alpha.c */
|
|
269 void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, int stride);
|
|
270 void mpeg2_idct_add_mvi (int last, int16_t * block,
|
|
271 uint8_t * dest, int stride);
|
|
272 void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, int stride);
|
|
273 void mpeg2_idct_add_alpha (int last, int16_t * block,
|
|
274 uint8_t * dest, int stride);
|
|
275 void mpeg2_idct_alpha_init(int no_mvi);
|
1
|
276
|
36
|
277 /* motion_comp.c */
|
9852
|
278 void mpeg2_mc_init (uint32_t accel);
|
|
279
|
|
280 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
|
1
|
281
|
9852
|
282 typedef struct {
|
|
283 mpeg2_mc_fct * put [8];
|
|
284 mpeg2_mc_fct * avg [8];
|
|
285 } mpeg2_mc_t;
|
1
|
286
|
9852
|
287 #define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
|
|
288 {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
|
|
289 MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
|
|
290 {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
|
|
291 MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
|
1
|
292 };
|
|
293
|
9852
|
294 extern mpeg2_mc_t mpeg2_mc_c;
|
|
295 extern mpeg2_mc_t mpeg2_mc_mmx;
|
|
296 extern mpeg2_mc_t mpeg2_mc_mmxext;
|
|
297 extern mpeg2_mc_t mpeg2_mc_3dnow;
|
|
298 extern mpeg2_mc_t mpeg2_mc_altivec;
|
|
299 extern mpeg2_mc_t mpeg2_mc_alpha;
|
|
300 extern mpeg2_mc_t mpeg2_mc_mlib;
|