Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mpeg2_internal.h

Go to the documentation of this file.
00001 /*
00002  * mpeg2_internal.h
00003  * Copyright (C) 2000-2002 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_MASK (3*64)
00033 #define MOTION_TYPE_BASE 64
00034 #define MC_FIELD (1*64)
00035 #define MC_FRAME (2*64)
00036 #define MC_16X8 (2*64)
00037 #define MC_DMV (3*64)
00038 
00039 /* picture structure */
00040 #define TOP_FIELD 1
00041 #define BOTTOM_FIELD 2
00042 #define FRAME_PICTURE 3
00043 
00044 /* picture coding type */
00045 #define I_TYPE 1
00046 #define P_TYPE 2
00047 #define B_TYPE 3
00048 #define D_TYPE 4
00049 
00050 typedef struct {
00051     uint8_t * ref[2][3];
00052     uint8_t ** ref2[2];
00053     int pmv[2][2];
00054     int f_code[2];
00055 } motion_t;
00056 
00057 struct decoder_s {
00058     /* first, state that carries information from one macroblock to the */
00059     /* next inside a slice, and is never used outside of mpeg2_slice() */
00060 
00061     /* DCT coefficients - should be kept aligned ! */
00062     int16_t DCTblock[64];
00063 
00064     /* bit parsing stuff */
00065     uint32_t bitstream_buf;             /* current 32 bit working set */
00066     int bitstream_bits;                 /* used bits in working set */
00067     const uint8_t * bitstream_ptr;      /* buffer with stream data */
00068 
00069     uint8_t * dest[3];
00070     uint8_t * picture_dest[3];
00071     void (* convert) (void * fbuf_id, uint8_t * const * src,
00072                       unsigned int v_offset);
00073     void * fbuf_id;
00074 
00075     int offset;
00076     int stride;
00077     int uv_stride;
00078     unsigned int limit_x;
00079     unsigned int limit_y_16;
00080     unsigned int limit_y_8;
00081     unsigned int limit_y;
00082 
00083     /* Motion vectors */
00084     /* The f_ and b_ correspond to the forward and backward motion */
00085     /* predictors */
00086     motion_t b_motion;
00087     motion_t f_motion;
00088 
00089     /* predictor for DC coefficients in intra blocks */
00090     int16_t dc_dct_pred[3];
00091 
00092     int quantizer_scale;        /* remove */
00093     int dmv_offset;             /* remove */
00094     unsigned int v_offset;      /* remove */
00095 
00096     /* now non-slice-specific information */
00097 
00098     /* sequence header stuff */
00099     uint8_t intra_quantizer_matrix [64];
00100     uint8_t non_intra_quantizer_matrix [64];
00101 
00102     /* The width and height of the picture snapped to macroblock units */
00103     int width;
00104     int height;
00105     int vertical_position_extension;
00106 
00107     /* picture header stuff */
00108 
00109     /* what type of picture this is (I, P, B, D) */
00110     int coding_type;
00111 
00112     /* picture coding extension stuff */
00113 
00114     /* quantization factor for intra dc coefficients */
00115     int intra_dc_precision;
00116     /* top/bottom/both fields */
00117     int picture_structure;
00118     /* bool to indicate all predictions are frame based */
00119     int frame_pred_frame_dct;
00120     /* bool to indicate whether intra blocks have motion vectors */
00121     /* (for concealment) */
00122     int concealment_motion_vectors;
00123     /* bit to indicate which quantization table to use */
00124     int q_scale_type;
00125     /* bool to use different vlc tables */
00126     int intra_vlc_format;
00127     /* used for DMV MC */
00128     int top_field_first;
00129 
00130     /* stuff derived from bitstream */
00131 
00132     /* pointer to the zigzag scan we're supposed to be using */
00133     const uint8_t * scan;
00134 
00135     int second_field;
00136 
00137     int mpeg1;
00138 };
00139 
00140 typedef struct {
00141     fbuf_t fbuf;
00142 } fbuf_alloc_t;
00143 
00144 struct mpeg2dec_s {
00145     decoder_t decoder;
00146 
00147     mpeg2_info_t info;
00148 
00149     uint32_t shift;
00150     int is_display_initialized;
00151     int (* action) (struct mpeg2dec_s * mpeg2dec);
00152     int state;
00153     uint32_t ext_state;
00154 
00155     /* allocated in init - gcc has problems allocating such big structures */
00156     uint8_t * chunk_buffer;
00157     /* pointer to start of the current chunk */
00158     uint8_t * chunk_start;
00159     /* pointer to current position in chunk_buffer */
00160     uint8_t * chunk_ptr;
00161     /* last start code ? */
00162     uint8_t code;
00163 
00164     /* PTS */
00165     uint32_t pts_current, pts_previous;
00166     int num_pts;
00167     int bytes_since_pts;
00168 
00169     int first;
00170     int alloc_index_user;
00171     int alloc_index;
00172     uint8_t first_decode_slice;
00173     uint8_t nb_decode_slices;
00174 
00175     sequence_t new_sequence;
00176     sequence_t sequence;
00177     picture_t pictures[4];
00178     picture_t * picture;
00179     /*const*/ fbuf_t * fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */
00180 
00181     fbuf_alloc_t fbuf_alloc[3];
00182     int custom_fbuf;
00183 
00184     uint8_t * yuv_buf[3][3];
00185     int yuv_index;
00186     void * convert_id;
00187     int convert_size[3];
00188     void (* convert_start) (void * id, uint8_t * const * dest, int flags);
00189     void (* convert_copy) (void * id, uint8_t * const * src,
00190                            unsigned int v_offset);
00191 
00192     uint8_t * buf_start;
00193     uint8_t * buf_end;
00194 
00195     int16_t display_offset_x, display_offset_y;
00196 };
00197 
00198 typedef struct {
00199 #ifdef ARCH_PPC
00200     uint8_t regv[12*16];
00201 #endif
00202     int dummy;
00203 } cpu_state_t;
00204 
00205 /* alloc.c */
00206 #define ALLOC_MPEG2DEC 0
00207 #define ALLOC_CHUNK 1
00208 #define ALLOC_YUV 2
00209 #define ALLOC_CONVERT_ID 3
00210 #define ALLOC_CONVERTED 4
00211 void * mpeg2_malloc (int size, int reason);
00212 void mpeg2_free (void * buf);
00213 
00214 /* cpu_accel.c */
00215 uint32_t mpeg2_detect_accel (void);
00216 
00217 /* cpu_state.c */
00218 void mpeg2_cpu_state_init (uint32_t accel);
00219 
00220 /* decode.c */
00221 int mpeg2_seek_sequence (mpeg2dec_t * mpeg2dec);
00222 int mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
00223 int mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
00224 
00225 /* header.c */
00226 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec);
00227 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec);
00228 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec);
00229 int mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec);
00230 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec);
00231 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec);
00232 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec);
00233 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec);
00234 int mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec);
00235 int mpeg2_header_end (mpeg2dec_t * mpeg2dec);
00236 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int coding_type);
00237 
00238 /* idct.c */
00239 void mpeg2_idct_init (uint32_t accel);
00240 
00241 /* idct_mlib.c */
00242 void mpeg2_idct_add_mlib (int last, int16_t * block,
00243                           uint8_t * dest, int stride);
00244 void mpeg2_idct_copy_mlib_non_ieee (int16_t * block, uint8_t * dest,
00245                                     int stride);
00246 void mpeg2_idct_add_mlib_non_ieee (int last, int16_t * block,
00247                                    uint8_t * dest, int stride);
00248 
00249 /* idct_mmx.c */
00250 void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride);
00251 void mpeg2_idct_add_mmxext (int last, int16_t * block,
00252                             uint8_t * dest, int stride);
00253 void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride);
00254 void mpeg2_idct_add_mmx (int last, int16_t * block,
00255                          uint8_t * dest, int stride);
00256 void mpeg2_idct_mmx_init (void);
00257 
00258 /* idct_altivec.c */
00259 void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride);
00260 void mpeg2_idct_add_altivec (int last, int16_t * block,
00261                              uint8_t * dest, int stride);
00262 void mpeg2_idct_altivec_init (void);
00263 
00264 /* idct_alpha.c */
00265 void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, int stride);
00266 void mpeg2_idct_add_mvi (int last, int16_t * block,
00267                          uint8_t * dest, int stride);
00268 void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, int stride);
00269 void mpeg2_idct_add_alpha (int last, int16_t * block,
00270                            uint8_t * dest, int stride);
00271 void mpeg2_idct_alpha_init(int no_mvi);
00272 
00273 /* motion_comp.c */
00274 void mpeg2_mc_init (uint32_t accel);
00275 
00276 typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
00277 
00278 typedef struct {
00279     mpeg2_mc_fct * put [8];
00280     mpeg2_mc_fct * avg [8];
00281 } mpeg2_mc_t;
00282 
00283 #define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = {                    \
00284     {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
00285      MC_put_o_8_##x,  MC_put_x_8_##x,  MC_put_y_8_##x,  MC_put_xy_8_##x}, \
00286     {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
00287      MC_avg_o_8_##x,  MC_avg_x_8_##x,  MC_avg_y_8_##x,  MC_avg_xy_8_##x}  \
00288 };
00289 
00290 extern mpeg2_mc_t mpeg2_mc_c;
00291 extern mpeg2_mc_t mpeg2_mc_mmx;
00292 extern mpeg2_mc_t mpeg2_mc_mmxext;
00293 extern mpeg2_mc_t mpeg2_mc_3dnow;
00294 extern mpeg2_mc_t mpeg2_mc_altivec;
00295 extern mpeg2_mc_t mpeg2_mc_alpha;
00296 extern mpeg2_mc_t mpeg2_mc_mlib;
 

Powered by Plone

This site conforms to the following standards: