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 #ifndef MPEG2_INTERNAL_H
24 #define MPEG2_INTERNAL_H
26 #include "config.h" /* for Rockbox CPU_ #defines */
28 /* macroblock modes */
29 #define MACROBLOCK_INTRA 1
30 #define MACROBLOCK_PATTERN 2
31 #define MACROBLOCK_MOTION_BACKWARD 4
32 #define MACROBLOCK_MOTION_FORWARD 8
33 #define MACROBLOCK_QUANT 16
34 #define DCT_TYPE_INTERLACED 32
36 #define MOTION_TYPE_SHIFT 6
42 /* picture structure */
44 #define BOTTOM_FIELD 2
45 #define FRAME_PICTURE 3
47 /* picture coding type */
53 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
57 uint8_t * ref
[2][MPEG2_COMPONENTS
];
63 typedef void motion_parser_t(mpeg2_decoder_t
* decoder
,
65 mpeg2_mc_fct
* const * table
);
67 struct mpeg2_decoder_s
69 /* first, state that carries information from one macroblock to the */
70 /* next inside a slice, and is never used outside of mpeg2_slice() */
72 /* bit parsing stuff */
73 uint32_t bitstream_buf
; /* current 32 bit working set */
74 int bitstream_bits
; /* used bits in working set */
75 const uint8_t * bitstream_ptr
; /* buffer with stream data */
77 uint8_t * dest
[MPEG2_COMPONENTS
];
86 unsigned int limit_y_16
;
87 unsigned int limit_y_8
;
91 /* The f_ and b_ correspond to the forward and backward motion */
95 motion_parser_t
* motion_parser
[5];
97 /* predictor for DC coefficients in intra blocks */
98 int16_t dc_dct_pred
[MPEG2_COMPONENTS
];
100 /* DCT coefficients */
101 int16_t * ATTR_ALIGN(16) DCTblock
; /* put buffer separately to have it in IRAM */
103 uint8_t * picture_dest
[MPEG2_COMPONENTS
];
104 void (* convert
) (void * convert_id
, uint8_t * const * src
,
105 unsigned int v_offset
);
109 unsigned int v_offset
;
111 /* now non-slice-specific information */
113 /* sequence header stuff */
114 uint16_t * quantizer_matrix
[4];
115 uint16_t (* chroma_quantizer
[2])[64];
116 uint16_t quantizer_prescale
[4][32][64];
118 /* The width and height of the picture snapped to macroblock units */
121 int vertical_position_extension
;
124 /* picture header stuff */
126 /* what type of picture this is (I, P, B, D) */
129 /* picture coding extension stuff */
131 /* quantization factor for intra dc coefficients */
132 int intra_dc_precision
;
133 /* top/bottom/both fields */
134 int picture_structure
;
135 /* bool to indicate all predictions are frame based */
136 int frame_pred_frame_dct
;
137 /* bool to indicate whether intra blocks have motion vectors */
138 /* (for concealment) */
139 int concealment_motion_vectors
;
140 /* bool to use different vlc tables */
141 int intra_vlc_format
;
142 /* used for DMV MC */
145 /* stuff derived from bitstream */
147 /* pointer to the zigzag scan we're supposed to be using */
148 const uint8_t * scan
;
162 mpeg2_decoder_t decoder
;
167 int is_display_initialized
;
168 mpeg2_state_t (* action
) (struct mpeg2dec_s
* mpeg2dec
);
172 /* allocated in init - gcc has problems allocating such big structures */
173 uint8_t * ATTR_ALIGN(4) chunk_buffer
;
174 /* pointer to start of the current chunk */
175 uint8_t * chunk_start
;
176 /* pointer to current position in chunk_buffer */
178 /* last start code ? */
182 uint32_t tag_current
, tag2_current
, tag_previous
, tag2_previous
;
187 int alloc_index_user
;
189 uint8_t first_decode_slice
;
190 uint8_t nb_decode_slices
;
192 unsigned int user_data_len
;
194 mpeg2_sequence_t new_sequence
;
195 mpeg2_sequence_t sequence
;
198 mpeg2_picture_t new_picture
;
199 mpeg2_picture_t pictures
[4];
200 mpeg2_picture_t
* picture
;
201 /*const*/ mpeg2_fbuf_t
* fbuf
[3]; /* 0: current fbuf, 1-2: prediction fbufs */
203 fbuf_alloc_t fbuf_alloc
[3];
206 uint8_t * yuv_buf
[3][MPEG2_COMPONENTS
];
208 mpeg2_convert_t
* convert
;
210 unsigned int convert_id_size
;
212 void (* convert_start
) (void * id
, const mpeg2_fbuf_t
* fbuf
,
213 const mpeg2_picture_t
* picture
,
214 const mpeg2_gop_t
* gop
);
219 int16_t display_offset_x
, display_offset_y
;
222 int8_t q_scale_type
, scaled
[4];
223 uint8_t quantizer_matrix
[4][64];
224 uint8_t new_quantizer_matrix
[4][64];
228 mpeg2_state_t
mpeg2_seek_header (mpeg2dec_t
* mpeg2dec
);
229 mpeg2_state_t
mpeg2_parse_header (mpeg2dec_t
* mpeg2dec
);
232 void mpeg2_header_state_init (mpeg2dec_t
* mpeg2dec
);
233 void mpeg2_reset_info (mpeg2_info_t
* info
);
234 int mpeg2_header_sequence (mpeg2dec_t
* mpeg2dec
);
235 int mpeg2_header_gop (mpeg2dec_t
* mpeg2dec
);
236 mpeg2_state_t
mpeg2_header_picture_start (mpeg2dec_t
* mpeg2dec
);
237 int mpeg2_header_picture (mpeg2dec_t
* mpeg2dec
);
238 int mpeg2_header_extension (mpeg2dec_t
* mpeg2dec
);
239 int mpeg2_header_user_data (mpeg2dec_t
* mpeg2dec
);
240 void mpeg2_header_sequence_finalize (mpeg2dec_t
* mpeg2dec
);
241 void mpeg2_header_gop_finalize (mpeg2dec_t
* mpeg2dec
);
242 void mpeg2_header_picture_finalize (mpeg2dec_t
* mpeg2dec
);
243 mpeg2_state_t
mpeg2_header_slice_start (mpeg2dec_t
* mpeg2dec
);
244 mpeg2_state_t
mpeg2_header_end (mpeg2dec_t
* mpeg2dec
);
245 void mpeg2_set_fbuf (mpeg2dec_t
* mpeg2dec
, int b_type
);
248 void mpeg2_idct_init (void);
249 void mpeg2_idct_copy(int16_t * block
, uint8_t * dest
,
251 void mpeg2_idct_add(const int last
, int16_t * block
,
252 uint8_t * dest
, const int stride
);
254 extern const uint8_t default_mpeg2_scan_norm
[64];
255 extern const uint8_t default_mpeg2_scan_alt
[64];
256 extern uint8_t mpeg2_scan_norm
[64];
257 extern uint8_t mpeg2_scan_alt
[64];
260 void mpeg2_mc_init (void);
264 mpeg2_mc_fct
* put
[8];
265 mpeg2_mc_fct
* avg
[8];
268 extern const mpeg2_mc_t mpeg2_mc
;
270 #endif /* MPEG2_INTERNAL_H */