00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define STATE_INTERNAL_NORETURN ((mpeg2_state_t)-1)
00025
00026
00027 #define MACROBLOCK_INTRA 1
00028 #define MACROBLOCK_PATTERN 2
00029 #define MACROBLOCK_MOTION_BACKWARD 4
00030 #define MACROBLOCK_MOTION_FORWARD 8
00031 #define MACROBLOCK_QUANT 16
00032 #define DCT_TYPE_INTERLACED 32
00033
00034 #define MOTION_TYPE_SHIFT 6
00035 #define MC_FIELD 1
00036 #define MC_FRAME 2
00037 #define MC_16X8 2
00038 #define MC_DMV 3
00039
00040
00041 #define TOP_FIELD 1
00042 #define BOTTOM_FIELD 2
00043 #define FRAME_PICTURE 3
00044
00045
00046 #define I_TYPE 1
00047 #define P_TYPE 2
00048 #define B_TYPE 3
00049 #define D_TYPE 4
00050
00051 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
00052
00053 typedef struct {
00054 uint8_t * ref[2][3];
00055 uint8_t ** ref2[2];
00056 int pmv[2][2];
00057 int f_code[2];
00058 } motion_t;
00059
00060 typedef void motion_parser_t (mpeg2_decoder_t * decoder,
00061 motion_t * motion,
00062 mpeg2_mc_fct * const * table);
00063
00064 struct mpeg2_decoder_s {
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
00114
00115 int width;
00116 int height;
00117 int vertical_position_extension;
00118 int chroma_format;
00119
00120
00121
00122
00123 int coding_type;
00124
00125
00126
00127
00128 int intra_dc_precision;
00129
00130 int picture_structure;
00131
00132 int frame_pred_frame_dct;
00133
00134
00135 int concealment_motion_vectors;
00136
00137 int intra_vlc_format;
00138
00139 int top_field_first;
00140
00141
00142
00143
00144 const uint8_t * scan;
00145
00146 int second_field;
00147
00148 int mpeg1;
00149 };
00150
00151 typedef struct {
00152 mpeg2_fbuf_t fbuf;
00153 } fbuf_alloc_t;
00154
00155 struct mpeg2dec_s {
00156 mpeg2_decoder_t decoder;
00157
00158 mpeg2_info_t info;
00159
00160 uint32_t shift;
00161 int is_display_initialized;
00162 mpeg2_state_t (* action) (struct mpeg2dec_s * mpeg2dec);
00163 mpeg2_state_t state;
00164 uint32_t ext_state;
00165
00166
00167 uint8_t * chunk_buffer;
00168
00169 uint8_t * chunk_start;
00170
00171 uint8_t * chunk_ptr;
00172
00173 uint8_t code;
00174
00175
00176 uint32_t tag_current, tag2_current, tag_previous, tag2_previous;
00177 int num_tags;
00178 int bytes_since_tag;
00179
00180 int first;
00181 int alloc_index_user;
00182 int alloc_index;
00183 uint8_t first_decode_slice;
00184 uint8_t nb_decode_slices;
00185
00186 unsigned int user_data_len;
00187
00188 mpeg2_sequence_t new_sequence;
00189 mpeg2_sequence_t sequence;
00190 mpeg2_gop_t new_gop;
00191 mpeg2_gop_t gop;
00192 mpeg2_picture_t new_picture;
00193 mpeg2_picture_t pictures[4];
00194 mpeg2_picture_t * picture;
00195 mpeg2_fbuf_t * fbuf[3];
00196
00197 fbuf_alloc_t fbuf_alloc[3];
00198 int custom_fbuf;
00199
00200 uint8_t * yuv_buf[3][3];
00201 int yuv_index;
00202 mpeg2_convert_t * convert;
00203 void * convert_arg;
00204 unsigned int convert_id_size;
00205 int convert_stride;
00206 void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf,
00207 const mpeg2_picture_t * picture,
00208 const mpeg2_gop_t * gop);
00209
00210 uint8_t * buf_start;
00211 uint8_t * buf_end;
00212
00213 int16_t display_offset_x, display_offset_y;
00214
00215 int copy_matrix;
00216 int8_t q_scale_type, scaled[4];
00217 uint8_t quantizer_matrix[4][64];
00218 uint8_t new_quantizer_matrix[4][64];
00219 };
00220
00221 typedef struct {
00222 #if ARCH_PPC
00223 uint8_t regv[12*16];
00224 #endif
00225 int dummy;
00226 } cpu_state_t;
00227
00228
00229 uint32_t mpeg2_detect_accel (uint32_t accel);
00230
00231
00232 void mpeg2_cpu_state_init (uint32_t accel);
00233
00234
00235 mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
00236 mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
00237
00238
00239 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec);
00240 void mpeg2_reset_info (mpeg2_info_t * info);
00241 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec);
00242 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec);
00243 mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec);
00244 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec);
00245 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec);
00246 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec);
00247 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec);
00248 void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec);
00249 void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec, uint32_t accels);
00250 mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec);
00251 mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec);
00252 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
00253
00254
00255 void mpeg2_idct_init (uint32_t accel);
00256
00257
00258 void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride);
00259 void mpeg2_idct_add_mmxext (int last, int16_t * block,
00260 uint8_t * dest, int stride);
00261 void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride);
00262 void mpeg2_idct_add_mmx (int last, int16_t * block,
00263 uint8_t * dest, int stride);
00264 void mpeg2_idct_mmx_init (void);
00265
00266
00267 void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride);
00268 void mpeg2_idct_add_altivec (int last, int16_t * block,
00269 uint8_t * dest, int stride);
00270 void mpeg2_idct_altivec_init (void);
00271
00272
00273 void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, int stride);
00274 void mpeg2_idct_add_mvi (int last, int16_t * block,
00275 uint8_t * dest, int stride);
00276 void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, int stride);
00277 void mpeg2_idct_add_alpha (int last, int16_t * block,
00278 uint8_t * dest, int stride);
00279 void mpeg2_idct_alpha_init (void);
00280
00281
00282 void mpeg2_mc_init (uint32_t accel);
00283
00284 typedef struct {
00285 mpeg2_mc_fct * put [8];
00286 mpeg2_mc_fct * avg [8];
00287 } mpeg2_mc_t;
00288
00289 #define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
00290 {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
00291 MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
00292 {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
00293 MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
00294 };
00295
00296 extern mpeg2_mc_t mpeg2_mc_c;
00297 extern mpeg2_mc_t mpeg2_mc_mmx;
00298 extern mpeg2_mc_t mpeg2_mc_mmxext;
00299 extern mpeg2_mc_t mpeg2_mc_3dnow;
00300 extern mpeg2_mc_t mpeg2_mc_altivec;
00301 extern mpeg2_mc_t mpeg2_mc_alpha;
00302 extern mpeg2_mc_t mpeg2_mc_vis;