mpeg2_internal.h

Go to the documentation of this file.
00001 /* $Id$
00002  * mpeg2_internal.h
00003  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
00004  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
00005  *
00006  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
00007  * See http://libmpeg2.sourceforge.net/ for updates.
00008  *
00009  * mpeg2dec is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * mpeg2dec is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00024 /* macroblock modes */
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 /* motion_type */
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 /* picture structure */
00039 #define TOP_FIELD 1
00040 #define BOTTOM_FIELD 2
00041 #define FRAME_PICTURE 3
00042 
00043 /* picture coding type */
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     /* first, state that carries information from one macroblock to the */
00066     /* next inside a slice, and is never used outside of mpeg2_slice() */
00067 
00068     /* bit parsing stuff */
00069     uint32_t bitstream_buf;     /* current 32 bit working set */
00070     int bitstream_bits;         /* used bits in working set */
00071     const uint8_t * bitstream_ptr;  /* buffer with stream data */
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     /* Motion vectors */
00087     /* The f_ and b_ correspond to the forward and backward motion */
00088     /* predictors */
00089     motion_t b_motion;
00090     motion_t f_motion;
00091     motion_parser_t * motion_parser[5];
00092 
00093     /* predictor for DC coefficients in intra blocks */
00094     int16_t dc_dct_pred[3];
00095 
00096     /* DCT coefficients */
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     /* now non-slice-specific information */
00108 
00109     /* sequence header stuff */
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     /* The width and height of the picture snapped to macroblock units */
00117     int width;
00118     int height;
00119     int vertical_position_extension;
00120     int chroma_format;
00121 
00122     /* picture header stuff */
00123 
00124     /* what type of picture this is (I, P, B, D) */
00125     int coding_type;
00126 
00127     /* picture coding extension stuff */
00128 
00129     /* quantization factor for intra dc coefficients */
00130     int intra_dc_precision;
00131     /* top/bottom/both fields */
00132     int picture_structure;
00133     /* bool to indicate all predictions are frame based */
00134     int frame_pred_frame_dct;
00135     /* bool to indicate whether intra blocks have motion vectors */
00136     /* (for concealment) */
00137     int concealment_motion_vectors;
00138     /* bit to indicate which quantization table to use */
00139     int q_scale_type;
00140     /* bool to use different vlc tables */
00141     int intra_vlc_format;
00142     /* used for DMV MC */
00143     int top_field_first;
00144 
00145     /* stuff derived from bitstream */
00146 
00147     /* pointer to the zigzag scan we're supposed to be using */
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     /* allocated in init - gcc has problems allocating such big structures */
00176     uint8_t * chunk_buffer;
00177     /* pointer to start of the current chunk */
00178     uint8_t * chunk_start;
00179     /* pointer to current position in chunk_buffer */
00180     uint8_t * chunk_ptr;
00181     uint32_t chunk_size;
00182     /* last start code ? */
00183     uint8_t code;
00184     uint8_t prev_code;
00185 
00186     /* picture tags */
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     /*const*/ mpeg2_fbuf_t * fbuf[3];   /* 0: current fbuf, 1-2: prediction fbufs */
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     /* a spu decoder for possible closed captions */
00232     //spu_decoder_t *cc_dec;
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 /* cpu_accel.c */
00249 uint32_t mpeg2_detect_accel (void);
00250 
00251 /* cpu_state.c */
00252 void mpeg2_cpu_state_init (uint32_t accel);
00253 
00254 /* decode.c */
00255 mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
00256 mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
00257 
00258 /* header.c */
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 /* motion_comp.c */
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;

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1