mpeg2_internal.h

Go to the documentation of this file.
00001 /* $Id: 2191df3811785017612b0197ce36823dd801f500 $
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 #ifndef LIBMPEG2_MPEG2_INTERNAL_H
00025 #define LIBMPEG2_MPEG2_INTERNAL_H
00026 
00027 #define STATE_INTERNAL_NORETURN ((mpeg2_state_t)-1)
00028 
00029 /* macroblock modes */
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 /* motion_type */
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 /* picture structure */
00044 #define TOP_FIELD 1
00045 #define BOTTOM_FIELD 2
00046 #define FRAME_PICTURE 3
00047 
00048 /* picture coding type */
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     /* first, state that carries information from one macroblock to the */
00069     /* next inside a slice, and is never used outside of mpeg2_slice() */
00070 
00071     /* bit parsing stuff */
00072     uint32_t bitstream_buf;     /* current 32 bit working set */
00073     int bitstream_bits;         /* used bits in working set */
00074     const uint8_t * bitstream_ptr;  /* buffer with stream data */
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     /* Motion vectors */
00090     /* The f_ and b_ correspond to the forward and backward motion */
00091     /* predictors */
00092     motion_t b_motion;
00093     motion_t f_motion;
00094     motion_parser_t * motion_parser[5];
00095 
00096     /* predictor for DC coefficients in intra blocks */
00097     int16_t dc_dct_pred[3];
00098 
00099     /* DCT coefficients */
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     /* now non-slice-specific information */
00111 
00112     /* sequence header stuff */
00113     uint16_t * quantizer_matrix[4];
00114     uint16_t (* chroma_quantizer[2])[64];
00115     uint16_t quantizer_prescale[4][32][64];
00116 
00117     /* The width and height of the picture snapped to macroblock units */
00118     int width;
00119     int height;
00120     int vertical_position_extension;
00121     int chroma_format;
00122 
00123     /* picture header stuff */
00124 
00125     /* what type of picture this is (I, P, B, D) */
00126     int coding_type;
00127 
00128     /* picture coding extension stuff */
00129 
00130     /* quantization factor for intra dc coefficients */
00131     int intra_dc_precision;
00132     /* top/bottom/both fields */
00133     int picture_structure;
00134     /* bool to indicate all predictions are frame based */
00135     int frame_pred_frame_dct;
00136     /* bool to indicate whether intra blocks have motion vectors */
00137     /* (for concealment) */
00138     int concealment_motion_vectors;
00139     /* bool to use different vlc tables */
00140     int intra_vlc_format;
00141     /* used for DMV MC */
00142     int top_field_first;
00143 
00144     /* stuff derived from bitstream */
00145 
00146     /* pointer to the zigzag scan we're supposed to be using */
00147     const uint8_t * scan;
00148 
00149     int second_field;
00150 
00151     int mpeg1;
00152 
00153     /* XXX: stuff due to xine shit */
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     /* allocated in init - gcc has problems allocating such big structures */
00173     uint8_t * chunk_buffer;
00174     /* pointer to start of the current chunk */
00175     uint8_t * chunk_start;
00176     /* pointer to current position in chunk_buffer */
00177     uint8_t * chunk_ptr;
00178     /* last start code ? */
00179     uint8_t code;
00180 
00181     /* picture tags */
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     /*const*/ mpeg2_fbuf_t * fbuf[3];   /* 0: current fbuf, 1-2: prediction fbufs */
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]; /* XXX: MOVED */
00223     //int8_t q_scale_type, scaled[4];
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 /* cpu_accel.c */
00236 uint32_t mpeg2_detect_accel (uint32_t accel);
00237 
00238 /* cpu_state.c */
00239 void mpeg2_cpu_state_init (uint32_t accel);
00240 
00241 /* decode.c */
00242 mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
00243 mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
00244 
00245 /* header.c */
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 /* idct.c */
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 /* idct_mmx.c */
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 /* idct_altivec.c */
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 /* idct_alpha.c */
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 /* motion_comp.c */
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 /* LIBMPEG2_MPEG2_INTERNAL_H */

Generated on Wed Mar 31 08:05:20 2010 for VLC by  doxygen 1.5.6