00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #define MACROBLOCK_INTRA 1
00026 #define MACROBLOCK_PATTERN 2
00027 #define MACROBLOCK_MOTION_BACKWARD 4
00028 #define MACROBLOCK_MOTION_FORWARD 8
00029 #define MACROBLOCK_QUANT 16
00030 #define DCT_TYPE_INTERLACED 32
00031
00032 #define MOTION_TYPE_SHIFT 6
00033 #define MC_FIELD 1
00034 #define MC_FRAME 2
00035 #define MC_16X8 2
00036 #define MC_DMV 3
00037
00038
00039 #define TOP_FIELD 1
00040 #define BOTTOM_FIELD 2
00041 #define FRAME_PICTURE 3
00042
00043
00044 #define I_TYPE 1
00045 #define P_TYPE 2
00046 #define B_TYPE 3
00047 #define D_TYPE 4
00048
00049 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
00050
00051 typedef struct
00052 {
00053 uint8_t * ref[2][3];
00054 uint8_t ** ref2[2];
00055 int pmv[2][2];
00056 int f_code[2];
00057 } motion_t;
00058
00059 typedef void motion_parser_t( mpeg2_decoder_t * decoder,
00060 motion_t * motion,
00061 mpeg2_mc_fct * const * table );
00062
00063 struct mpeg2_decoder_s
00064 {
00065
00066
00067
00068
00069 uint32_t bitstream_buf;
00070 int bitstream_bits;
00071 const uint8_t * bitstream_ptr;
00072
00073 uint8_t * dest[3];
00074
00075 int offset;
00076 int stride;
00077 int uv_stride;
00078 int slice_stride;
00079 int slice_uv_stride;
00080 int stride_frame;
00081 unsigned int limit_x;
00082 unsigned int limit_y_16;
00083 unsigned int limit_y_8;
00084 unsigned int limit_y;
00085
00086
00087
00088
00089 motion_t b_motion;
00090 motion_t f_motion;
00091 motion_parser_t * motion_parser[5];
00092
00093
00094 int16_t dc_dct_pred[3];
00095
00096
00097 int16_t DCTblock[64] ATTR_ALIGN(64);
00098
00099 uint8_t * picture_dest[3];
00100 void (* convert) (void * convert_id, uint8_t * const * src,
00101 unsigned int v_offset);
00102 void * convert_id;
00103
00104 int dmv_offset;
00105 unsigned int v_offset;
00106
00107
00108
00109
00110 uint16_t * quantizer_matrix[4];
00111 uint16_t (* chroma_quantizer[2])[64];
00112 uint16_t quantizer_prescale[4][32][64];
00113 int load_intra_quantizer_matrix;
00114 int load_non_intra_quantizer_matrix;
00115
00116
00117 int width;
00118 int height;
00119 int vertical_position_extension;
00120 int chroma_format;
00121
00122
00123
00124
00125 int coding_type;
00126
00127
00128
00129
00130 int intra_dc_precision;
00131
00132 int picture_structure;
00133
00134 int frame_pred_frame_dct;
00135
00136
00137 int concealment_motion_vectors;
00138
00139 int q_scale_type;
00140
00141 int intra_vlc_format;
00142
00143 int top_field_first;
00144
00145
00146
00147
00148 const uint8_t * scan;
00149
00150 int second_field;
00151
00152 int mpeg1;
00153
00154 int aspect_ratio_information;
00155 int progressive_sequence;
00156 };
00157
00158 typedef struct
00159 {
00160 mpeg2_fbuf_t fbuf;
00161 } fbuf_alloc_t;
00162
00163 struct mpeg2dec_s
00164 {
00165 mpeg2_decoder_t decoder;
00166
00167 mpeg2_info_t info;
00168
00169 uint32_t shift;
00170 int is_display_initialized;
00171 mpeg2_state_t (* action) (struct mpeg2dec_s * mpeg2dec);
00172 mpeg2_state_t state;
00173 uint32_t ext_state;
00174
00175
00176 uint8_t * chunk_buffer;
00177
00178 uint8_t * chunk_start;
00179
00180 uint8_t * chunk_ptr;
00181 uint32_t chunk_size;
00182
00183 uint8_t code;
00184 uint8_t prev_code;
00185
00186
00187 uint32_t tag_current, tag2_current, tag_previous, tag2_previous;
00188 int num_tags;
00189 int bytes_since_tag;
00190
00191 int first;
00192 int alloc_index_user;
00193 int alloc_index;
00194 uint8_t first_decode_slice;
00195 uint8_t nb_decode_slices;
00196
00197 unsigned int user_data_len;
00198
00199 mpeg2_sequence_t new_sequence;
00200 mpeg2_sequence_t sequence;
00201 mpeg2_gop_t new_gop;
00202 mpeg2_gop_t gop;
00203 mpeg2_picture_t new_picture;
00204 mpeg2_picture_t pictures[4];
00205 mpeg2_picture_t * picture;
00206 mpeg2_fbuf_t * fbuf[3];
00207
00208 fbuf_alloc_t fbuf_alloc[3];
00209 int custom_fbuf;
00210
00211 uint8_t * yuv_buf[3][3];
00212 int yuv_index;
00213 mpeg2_convert_t * convert;
00214 void * convert_arg;
00215 unsigned int convert_id_size;
00216 int convert_stride;
00217 void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf,
00218 const mpeg2_picture_t * picture,
00219 const mpeg2_gop_t * gop);
00220
00221 uint8_t * buf_start;
00222 uint8_t * buf_end;
00223
00224 int16_t display_offset_x, display_offset_y;
00225
00226 int copy_matrix;
00227 int8_t q_scale_type, scaled[4];
00228 uint8_t quantizer_matrix[4][64];
00229 uint8_t new_quantizer_matrix[4][64];
00230
00231
00232
00233 int xvmc_last_slice_code;
00234 unsigned xxmc_mb_pic_height;
00235
00236 void *ptr_forward_ref_picture;
00237 void *ptr_backward_ref_picture;
00238 };
00239
00240 typedef struct
00241 {
00242 #ifdef ARCH_PPC
00243 uint8_t regv[12*16];
00244 #endif
00245 int dummy;
00246 } cpu_state_t;
00247
00248
00249 uint32_t mpeg2_detect_accel (void);
00250
00251
00252 void mpeg2_cpu_state_init (uint32_t accel);
00253
00254
00255 mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
00256 mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
00257
00258
00259 extern uint8_t mpeg2_scan_norm[64];
00260 extern uint8_t mpeg2_scan_alt[64];
00261 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec);
00262 void mpeg2_reset_info (mpeg2_info_t * info);
00263 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec);
00264 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec);
00265 mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec);
00266 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec);
00267 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec);
00268 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec);
00269 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec);
00270 void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec);
00271 void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec, uint32_t accels);
00272 mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec);
00273 mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec);
00274 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
00275
00276
00277 void mpeg2_mc_init (uint32_t accel);
00278
00279 typedef struct {
00280 mpeg2_mc_fct * put [8];
00281 mpeg2_mc_fct * avg [8];
00282 } mpeg2_mc_t;
00283
00284 #define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
00285 {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
00286 MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
00287 {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
00288 MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
00289 };
00290
00291 extern mpeg2_mc_t mpeg2_mc_c;
00292 extern mpeg2_mc_t mpeg2_mc_mmx;
00293 extern mpeg2_mc_t mpeg2_mc_mmxext;
00294 extern mpeg2_mc_t mpeg2_mc_3dnow;
00295 extern mpeg2_mc_t mpeg2_mc_altivec;
00296 extern mpeg2_mc_t mpeg2_mc_alpha;
00297 extern mpeg2_mc_t mpeg2_mc_vis;