3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7 * See http://libmpeg2.sourceforge.net/ for updates.
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.
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.
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
23 * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
24 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
28 #ifndef LIBMPEG2_MPEG2_INTERNAL_H
29 #define LIBMPEG2_MPEG2_INTERNAL_H
31 #define STATE_INTERNAL_NORETURN ((mpeg2_state_t)-1)
33 /* macroblock modes */
34 #define MACROBLOCK_INTRA 1
35 #define MACROBLOCK_PATTERN 2
36 #define MACROBLOCK_MOTION_BACKWARD 4
37 #define MACROBLOCK_MOTION_FORWARD 8
38 #define MACROBLOCK_QUANT 16
39 #define DCT_TYPE_INTERLACED 32
41 #define MOTION_TYPE_SHIFT 6
47 /* picture structure */
49 #define BOTTOM_FIELD 2
50 #define FRAME_PICTURE 3
52 /* picture coding type */
58 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
67 typedef void motion_parser_t (mpeg2_decoder_t
* decoder
,
69 mpeg2_mc_fct
* const * table
);
71 struct mpeg2_decoder_s
{
72 /* first, state that carries information from one macroblock to the */
73 /* next inside a slice, and is never used outside of mpeg2_slice() */
75 /* bit parsing stuff */
76 uint32_t bitstream_buf
; /* current 32 bit working set */
77 int bitstream_bits
; /* used bits in working set */
78 const uint8_t * bitstream_ptr
; /* buffer with stream data */
89 unsigned int limit_y_16
;
90 unsigned int limit_y_8
;
94 /* The f_ and b_ correspond to the forward and backward motion */
98 motion_parser_t
* motion_parser
[5];
100 /* predictor for DC coefficients in intra blocks */
101 int16_t dc_dct_pred
[3];
103 /* DCT coefficients */
104 int16_t DCTblock
[64] ATTR_ALIGN(64);
106 uint8_t * picture_dest
[3];
107 void (* convert
) (void * convert_id
, uint8_t * const * src
,
108 unsigned int v_offset
);
112 unsigned int v_offset
;
114 /* now non-slice-specific information */
116 /* sequence header stuff */
117 uint16_t * quantizer_matrix
[4];
118 uint16_t (* chroma_quantizer
[2])[64];
119 uint16_t quantizer_prescale
[4][32][64];
121 /* The width and height of the picture snapped to macroblock units */
124 int vertical_position_extension
;
127 /* picture header stuff */
129 /* what type of picture this is (I, P, B, D) */
132 /* picture coding extension stuff */
134 /* quantization factor for intra dc coefficients */
135 int intra_dc_precision
;
136 /* top/bottom/both fields */
137 int picture_structure
;
138 /* bool to indicate all predictions are frame based */
139 int frame_pred_frame_dct
;
140 /* bool to indicate whether intra blocks have motion vectors */
141 /* (for concealment) */
142 int concealment_motion_vectors
;
143 /* bool to use different vlc tables */
144 int intra_vlc_format
;
145 /* used for DMV MC */
148 /* stuff derived from bitstream */
150 /* pointer to the zigzag scan we're supposed to be using */
151 const uint8_t * scan
;
157 /* XXX: stuff due to xine shit */
160 int quantizer_scales
[32];
171 mpeg2_decoder_t decoder
;
176 int is_display_initialized
;
177 mpeg2_state_t (* action
) (struct mpeg2dec_s
* mpeg2dec
);
181 /* allocated in init - gcc has problems allocating such big structures */
182 uint8_t * chunk_buffer
;
183 /* pointer to start of the current chunk */
184 uint8_t * chunk_start
;
185 /* pointer to current position in chunk_buffer */
187 /* last start code ? */
191 uint32_t tag_current
, tag2_current
, tag_previous
, tag2_previous
;
196 int alloc_index_user
;
198 uint8_t first_decode_slice
;
199 uint8_t nb_decode_slices
;
201 unsigned int user_data_len
;
203 mpeg2_sequence_t new_sequence
;
204 mpeg2_sequence_t sequence
;
207 mpeg2_picture_t new_picture
;
208 mpeg2_picture_t pictures
[4];
209 mpeg2_picture_t
* picture
;
210 /*const*/ mpeg2_fbuf_t
* fbuf
[3]; /* 0: current fbuf, 1-2: prediction fbufs */
212 fbuf_alloc_t fbuf_alloc
[3];
215 uint8_t * yuv_buf
[3][3];
217 mpeg2_convert_t
* convert
;
219 unsigned int convert_id_size
;
221 void (* convert_start
) (void * id
, const mpeg2_fbuf_t
* fbuf
,
222 const mpeg2_picture_t
* picture
,
223 const mpeg2_gop_t
* gop
);
228 int16_t display_offset_x
, display_offset_y
;
231 int8_t scaled
[4]; /* XXX: MOVED */
232 //int8_t q_scale_type, scaled[4];
233 uint8_t quantizer_matrix
[4][64];
234 uint8_t new_quantizer_matrix
[4][64];
236 unsigned char *pending_buffer
;
248 uint32_t mpeg2_detect_accel (uint32_t accel
);
251 void mpeg2_cpu_state_init (uint32_t accel
);
254 mpeg2_state_t
mpeg2_seek_header (mpeg2dec_t
* mpeg2dec
);
255 mpeg2_state_t
mpeg2_parse_header (mpeg2dec_t
* mpeg2dec
);
258 void mpeg2_header_state_init (mpeg2dec_t
* mpeg2dec
);
259 void mpeg2_reset_info (mpeg2_info_t
* info
);
260 int mpeg2_header_sequence (mpeg2dec_t
* mpeg2dec
);
261 int mpeg2_header_gop (mpeg2dec_t
* mpeg2dec
);
262 mpeg2_state_t
mpeg2_header_picture_start (mpeg2dec_t
* mpeg2dec
);
263 int mpeg2_header_picture (mpeg2dec_t
* mpeg2dec
);
264 int mpeg2_header_extension (mpeg2dec_t
* mpeg2dec
);
265 int mpeg2_header_user_data (mpeg2dec_t
* mpeg2dec
);
266 void mpeg2_header_sequence_finalize (mpeg2dec_t
* mpeg2dec
);
267 void mpeg2_header_gop_finalize (mpeg2dec_t
* mpeg2dec
);
268 void mpeg2_header_picture_finalize (mpeg2dec_t
* mpeg2dec
, uint32_t accels
);
269 mpeg2_state_t
mpeg2_header_slice_start (mpeg2dec_t
* mpeg2dec
);
270 mpeg2_state_t
mpeg2_header_end (mpeg2dec_t
* mpeg2dec
);
271 void mpeg2_set_fbuf (mpeg2dec_t
* mpeg2dec
, int b_type
);
274 extern void mpeg2_idct_init (uint32_t accel
);
275 extern uint8_t mpeg2_scan_norm
[64];
276 extern uint8_t mpeg2_scan_alt
[64];
279 void mpeg2_idct_copy_sse2 (int16_t * block
, uint8_t * dest
, int stride
);
280 void mpeg2_idct_add_sse2 (int last
, int16_t * block
,
281 uint8_t * dest
, int stride
);
282 void mpeg2_idct_copy_mmxext (int16_t * block
, uint8_t * dest
, int stride
);
283 void mpeg2_idct_add_mmxext (int last
, int16_t * block
,
284 uint8_t * dest
, int stride
);
285 void mpeg2_idct_copy_mmx (int16_t * block
, uint8_t * dest
, int stride
);
286 void mpeg2_idct_add_mmx (int last
, int16_t * block
,
287 uint8_t * dest
, int stride
);
288 void mpeg2_idct_mmx_init (void);
291 void mpeg2_idct_copy_altivec (int16_t * block
, uint8_t * dest
, int stride
);
292 void mpeg2_idct_add_altivec (int last
, int16_t * block
,
293 uint8_t * dest
, int stride
);
294 void mpeg2_idct_altivec_init (void);
297 void mpeg2_idct_copy_mvi (int16_t * block
, uint8_t * dest
, int stride
);
298 void mpeg2_idct_add_mvi (int last
, int16_t * block
,
299 uint8_t * dest
, int stride
);
300 void mpeg2_idct_copy_alpha (int16_t * block
, uint8_t * dest
, int stride
);
301 void mpeg2_idct_add_alpha (int last
, int16_t * block
,
302 uint8_t * dest
, int stride
);
303 void mpeg2_idct_alpha_init (void);
306 void mpeg2_mc_init (uint32_t accel
);
309 mpeg2_mc_fct
* put
[8];
310 mpeg2_mc_fct
* avg
[8];
313 #define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
314 {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
315 MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
316 {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
317 MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
320 extern mpeg2_mc_t mpeg2_mc_c
;
321 extern mpeg2_mc_t mpeg2_mc_mmx
;
322 extern mpeg2_mc_t mpeg2_mc_mmxext
;
323 extern mpeg2_mc_t mpeg2_mc_3dnow
;
324 extern mpeg2_mc_t mpeg2_mc_altivec
;
325 extern mpeg2_mc_t mpeg2_mc_alpha
;
326 extern mpeg2_mc_t mpeg2_mc_vis
;
327 extern mpeg2_mc_t mpeg2_mc_arm
;
329 #endif /* LIBMPEG2_MPEG2_INTERNAL_H */