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