mpegvideo.h

Go to the documentation of this file.
00001 /*
00002  * Generic DCT based hybrid video encoder
00003  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
00004  * Copyright (c) 2002-2004 Michael Niedermayer
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 /**
00024  * @file mpegvideo.h
00025  * mpegvideo header.
00026  */
00027 
00028 #ifndef FFMPEG_MPEGVIDEO_H
00029 #define FFMPEG_MPEGVIDEO_H
00030 
00031 #include "dsputil.h"
00032 #include "bitstream.h"
00033 #include "ratecontrol.h"
00034 #include "parser.h"
00035 #include "mpeg12data.h"
00036 #include "rl.h"
00037 
00038 #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
00039 
00040 enum OutputFormat {
00041     FMT_MPEG1,
00042     FMT_H261,
00043     FMT_H263,
00044     FMT_MJPEG,
00045     FMT_H264,
00046 };
00047 
00048 #define MPEG_BUF_SIZE (16 * 1024)
00049 
00050 #define QMAT_SHIFT_MMX 16
00051 #define QMAT_SHIFT 22
00052 
00053 #define MAX_FCODE 7
00054 #define MAX_MV 2048
00055 
00056 #define MAX_THREADS 8
00057 
00058 #define MAX_PICTURE_COUNT 32
00059 
00060 #define ME_MAP_SIZE 64
00061 #define ME_MAP_SHIFT 3
00062 #define ME_MAP_MV_BITS 11
00063 
00064 #define MAX_MB_BYTES (30*16*16*3/8 + 120)
00065 
00066 #define INPLACE_OFFSET 16
00067 
00068 /* Start codes. */
00069 #define SEQ_END_CODE            0x000001b7
00070 #define SEQ_START_CODE          0x000001b3
00071 #define GOP_START_CODE          0x000001b8
00072 #define PICTURE_START_CODE      0x00000100
00073 #define SLICE_MIN_START_CODE    0x00000101
00074 #define SLICE_MAX_START_CODE    0x000001af
00075 #define EXT_START_CODE          0x000001b5
00076 #define USER_START_CODE         0x000001b2
00077 
00078 /**
00079  * Picture.
00080  */
00081 typedef struct Picture{
00082     FF_COMMON_FRAME
00083 
00084     /**
00085      * halfpel luma planes.
00086      */
00087     uint8_t *interpolated[3];
00088     int16_t (*motion_val_base[2])[2];
00089     uint32_t *mb_type_base;
00090 #define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if there is just one type
00091 #define IS_INTRA4x4(a)   ((a)&MB_TYPE_INTRA4x4)
00092 #define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
00093 #define IS_PCM(a)        ((a)&MB_TYPE_INTRA_PCM)
00094 #define IS_INTRA(a)      ((a)&7)
00095 #define IS_INTER(a)      ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
00096 #define IS_SKIP(a)       ((a)&MB_TYPE_SKIP)
00097 #define IS_INTRA_PCM(a)  ((a)&MB_TYPE_INTRA_PCM)
00098 #define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
00099 #define IS_DIRECT(a)     ((a)&MB_TYPE_DIRECT2)
00100 #define IS_GMC(a)        ((a)&MB_TYPE_GMC)
00101 #define IS_16X16(a)      ((a)&MB_TYPE_16x16)
00102 #define IS_16X8(a)       ((a)&MB_TYPE_16x8)
00103 #define IS_8X16(a)       ((a)&MB_TYPE_8x16)
00104 #define IS_8X8(a)        ((a)&MB_TYPE_8x8)
00105 #define IS_SUB_8X8(a)    ((a)&MB_TYPE_16x16) //note reused
00106 #define IS_SUB_8X4(a)    ((a)&MB_TYPE_16x8)  //note reused
00107 #define IS_SUB_4X8(a)    ((a)&MB_TYPE_8x16)  //note reused
00108 #define IS_SUB_4X4(a)    ((a)&MB_TYPE_8x8)   //note reused
00109 #define IS_ACPRED(a)     ((a)&MB_TYPE_ACPRED)
00110 #define IS_QUANT(a)      ((a)&MB_TYPE_QUANT)
00111 #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
00112 #define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note does not work if subMBs
00113 #define HAS_CBP(a)        ((a)&MB_TYPE_CBP)
00114 
00115     int field_poc[2];           ///< h264 top/bottom POC
00116     int poc;                    ///< h264 frame POC
00117     int frame_num;              ///< h264 frame_num (raw frame_num from slice header)
00118     int pic_id;                 /**< h264 pic_num (short -> no wrap version of pic_num,
00119                                      pic_num & max_pic_num; long -> long_pic_num) */
00120     int long_ref;               ///< 1->long term reference 0->short term reference
00121     int ref_poc[2][16];         ///< h264 POCs of the frames used as reference
00122     int ref_count[2];           ///< number of entries in ref_poc
00123 
00124     int mb_var_sum;             ///< sum of MB variance for current frame
00125     int mc_mb_var_sum;          ///< motion compensated MB variance for current frame
00126     uint16_t *mb_var;           ///< Table for MB variances
00127     uint16_t *mc_mb_var;        ///< Table for motion compensated MB variances
00128     uint8_t *mb_mean;           ///< Table for MB luminance
00129     int32_t *mb_cmp_score;      ///< Table for MB cmp scores, for mb decision FIXME remove
00130     int b_frame_score;          /* */
00131 } Picture;
00132 
00133 struct MpegEncContext;
00134 
00135 /**
00136  * Motion estimation context.
00137  */
00138 typedef struct MotionEstContext{
00139     AVCodecContext *avctx;
00140     int skip;                          ///< set if ME is skipped for the current MB
00141     int co_located_mv[4][2];           ///< mv from last P-frame for direct mode ME
00142     int direct_basis_mv[4][2];
00143     uint8_t *scratchpad;               ///< data area for the ME algo, so that the ME does not need to malloc/free
00144     uint8_t *best_mb;
00145     uint8_t *temp_mb[2];
00146     uint8_t *temp;
00147     int best_bits;
00148     uint32_t *map;                     ///< map to avoid duplicate evaluations
00149     uint32_t *score_map;               ///< map to store the scores
00150     int map_generation;
00151     int pre_penalty_factor;
00152     int penalty_factor;                /*!< an estimate of the bits required to
00153                                         code a given mv value, e.g. (1,0) takes
00154                                         more bits than (0,0). We have to
00155                                         estimate whether any reduction in
00156                                         residual is worth the extra bits. */
00157     int sub_penalty_factor;
00158     int mb_penalty_factor;
00159     int flags;
00160     int sub_flags;
00161     int mb_flags;
00162     int pre_pass;                      ///< = 1 for the pre pass
00163     int dia_size;
00164     int xmin;
00165     int xmax;
00166     int ymin;
00167     int ymax;
00168     int pred_x;
00169     int pred_y;
00170     uint8_t *src[4][4];
00171     uint8_t *ref[4][4];
00172     int stride;
00173     int uvstride;
00174     /* temp variables for picture complexity calculation */
00175     int mc_mb_var_sum_temp;
00176     int mb_var_sum_temp;
00177     int scene_change_score;
00178 /*    cmp, chroma_cmp;*/
00179     op_pixels_func (*hpel_put)[4];
00180     op_pixels_func (*hpel_avg)[4];
00181     qpel_mc_func (*qpel_put)[16];
00182     qpel_mc_func (*qpel_avg)[16];
00183     uint8_t (*mv_penalty)[MAX_MV*2+1];  ///< amount of bits needed to encode a MV
00184     uint8_t *current_mv_penalty;
00185     int (*sub_motion_search)(struct MpegEncContext * s,
00186                                   int *mx_ptr, int *my_ptr, int dmin,
00187                                   int src_index, int ref_index,
00188                                   int size, int h);
00189 }MotionEstContext;
00190 
00191 /**
00192  * MpegEncContext.
00193  */
00194 typedef struct MpegEncContext {
00195     struct AVCodecContext *avctx;
00196     /* the following parameters must be initialized before encoding */
00197     int width, height;///< picture size. must be a multiple of 16
00198     int gop_size;
00199     int intra_only;   ///< if true, only intra pictures are generated
00200     int bit_rate;     ///< wanted bit rate
00201     enum OutputFormat out_format; ///< output format
00202     int h263_pred;    ///< use mpeg4/h263 ac/dc predictions
00203 
00204 /* the following codec id fields are deprecated in favor of codec_id */
00205     int h263_plus;    ///< h263 plus headers
00206     int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
00207     int h263_flv;     ///< use flv h263 header
00208 
00209     enum CodecID codec_id;     /* see CODEC_ID_xxx */
00210     int fixed_qscale; ///< fixed qscale if non zero
00211     int encoding;     ///< true if we are encoding (vs decoding)
00212     int flags;        ///< AVCodecContext.flags (HQ, MV4, ...)
00213     int flags2;       ///< AVCodecContext.flags2
00214     int max_b_frames; ///< max number of b-frames for encoding
00215     int luma_elim_threshold;
00216     int chroma_elim_threshold;
00217     int strict_std_compliance; ///< strictly follow the std (MPEG4, ...)
00218     int workaround_bugs;       ///< workaround bugs in encoders which cannot be detected automatically
00219     int codec_tag;             ///< internal codec_tag upper case converted from avctx codec_tag
00220     int stream_codec_tag;      ///< internal stream_codec_tag upper case converted from avctx stream_codec_tag
00221     /* the following fields are managed internally by the encoder */
00222 
00223     /** bit output */
00224     PutBitContext pb;
00225 
00226     /* sequence parameters */
00227     int context_initialized;
00228     int input_picture_number;  ///< used to set pic->display_picture_number, should not be used for/by anything else
00229     int coded_picture_number;  ///< used to set pic->coded_picture_number, should not be used for/by anything else
00230     int picture_number;       //FIXME remove, unclear definition
00231     int picture_in_gop_number; ///< 0-> first pic in gop, ...
00232     int b_frames_since_non_b;  ///< used for encoding, relative to not yet reordered input
00233     int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
00234     int mb_width, mb_height;   ///< number of MBs horizontally & vertically
00235     int mb_stride;             ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
00236     int b8_stride;             ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
00237     int b4_stride;             ///< 4*mb_width+1 used for some 4x4 block arrays to allow simple addressing
00238     int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication)
00239     int mb_num;                ///< number of MBs of a picture
00240     int linesize;              ///< line size, in bytes, may be different from width
00241     int uvlinesize;            ///< line size, for chroma in bytes, may be different from width
00242     Picture *picture;          ///< main picture buffer
00243     Picture **input_picture;   ///< next pictures on display order for encoding
00244     Picture **reordered_input_picture; ///< pointer to the next pictures in codedorder for encoding
00245 
00246     int start_mb_y;            ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
00247     int end_mb_y;              ///< end   mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
00248     struct MpegEncContext *thread_context[MAX_THREADS];
00249 
00250     /**
00251      * copy of the previous picture structure.
00252      * note, linesize & data, might not match the previous picture (for field pictures)
00253      */
00254     Picture last_picture;
00255 
00256     /**
00257      * copy of the next picture structure.
00258      * note, linesize & data, might not match the next picture (for field pictures)
00259      */
00260     Picture next_picture;
00261 
00262     /**
00263      * copy of the source picture structure for encoding.
00264      * note, linesize & data, might not match the source picture (for field pictures)
00265      */
00266     Picture new_picture;
00267 
00268     /**
00269      * copy of the current picture structure.
00270      * note, linesize & data, might not match the current picture (for field pictures)
00271      */
00272     Picture current_picture;    ///< buffer to store the decompressed current picture
00273 
00274     Picture *last_picture_ptr;     ///< pointer to the previous picture.
00275     Picture *next_picture_ptr;     ///< pointer to the next picture (for bidir pred)
00276     Picture *current_picture_ptr;  ///< pointer to the current picture
00277     uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
00278     int last_dc[3];                ///< last DC values for MPEG1
00279     int16_t *dc_val_base;
00280     int16_t *dc_val[3];            ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
00281     int16_t dc_cache[4*5];
00282     int y_dc_scale, c_dc_scale;
00283     const uint8_t *y_dc_scale_table;     ///< qscale -> y_dc_scale table
00284     const uint8_t *c_dc_scale_table;     ///< qscale -> c_dc_scale table
00285     const uint8_t *chroma_qscale_table;  ///< qscale -> chroma_qscale (h263)
00286     uint8_t *coded_block_base;
00287     uint8_t *coded_block;          ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
00288     int16_t (*ac_val_base)[16];
00289     int16_t (*ac_val[3])[16];      ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
00290     int ac_pred;
00291     uint8_t *prev_pict_types;     ///< previous picture types in bitstream order, used for mb skip
00292 #define PREV_PICT_TYPES_BUFFER_SIZE 256
00293     int mb_skipped;                ///< MUST BE SET only during DECODING
00294     uint8_t *mbskip_table;        /**< used to avoid copy if macroblock skipped (for black regions for example)
00295                                    and used for b-frame encoding & decoding (contains skip table of next P Frame) */
00296     uint8_t *mbintra_table;       ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
00297     uint8_t *cbp_table;           ///< used to store cbp, ac_pred for partitioned decoding
00298     uint8_t *pred_dir_table;      ///< used to store pred_dir for partitioned decoding
00299     uint8_t *allocated_edge_emu_buffer;
00300     uint8_t *edge_emu_buffer;     ///< points into the middle of allocated_edge_emu_buffer
00301     uint8_t *rd_scratchpad;       ///< scratchpad for rate distortion mb decision
00302     uint8_t *obmc_scratchpad;
00303     uint8_t *b_scratchpad;        ///< scratchpad used for writing into write only buffers
00304 
00305     int qscale;                 ///< QP
00306     int chroma_qscale;          ///< chroma QP
00307     unsigned int lambda;        ///< lagrange multipler used in rate distortion
00308     unsigned int lambda2;       ///< (lambda*lambda) >> FF_LAMBDA_SHIFT
00309     int *lambda_table;
00310     int adaptive_quant;         ///< use adaptive quantization
00311     int dquant;                 ///< qscale difference to prev qscale
00312     int pict_type;              ///< FF_I_TYPE, FF_P_TYPE, FF_B_TYPE, ...
00313     int last_pict_type; //FIXME removes
00314     int last_non_b_pict_type;   ///< used for mpeg4 gmc b-frames & ratecontrol
00315     int dropable;
00316     int frame_rate_index;
00317     int last_lambda_for[5];     ///< last lambda for a specific pict type
00318     int skipdct;                ///< skip dct and code zero residual
00319 
00320     /* motion compensation */
00321     int unrestricted_mv;        ///< mv can point outside of the coded picture
00322     int h263_long_vectors;      ///< use horrible h263v1 long vector mode
00323     int decode;                 ///< if 0 then decoding will be skipped (for encoding b frames for example)
00324 
00325     DSPContext dsp;             ///< pointers for accelerated dsp functions
00326     int f_code;                 ///< forward MV resolution
00327     int b_code;                 ///< backward MV resolution for B Frames (mpeg4)
00328     int16_t (*p_mv_table_base)[2];
00329     int16_t (*b_forw_mv_table_base)[2];
00330     int16_t (*b_back_mv_table_base)[2];
00331     int16_t (*b_bidir_forw_mv_table_base)[2];
00332     int16_t (*b_bidir_back_mv_table_base)[2];
00333     int16_t (*b_direct_mv_table_base)[2];
00334     int16_t (*p_field_mv_table_base[2][2])[2];
00335     int16_t (*b_field_mv_table_base[2][2][2])[2];
00336     int16_t (*p_mv_table)[2];            ///< MV table (1MV per MB) p-frame encoding
00337     int16_t (*b_forw_mv_table)[2];       ///< MV table (1MV per MB) forward mode b-frame encoding
00338     int16_t (*b_back_mv_table)[2];       ///< MV table (1MV per MB) backward mode b-frame encoding
00339     int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
00340     int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
00341     int16_t (*b_direct_mv_table)[2];     ///< MV table (1MV per MB) direct mode b-frame encoding
00342     int16_t (*p_field_mv_table[2][2])[2];   ///< MV table (2MV per MB) interlaced p-frame encoding
00343     int16_t (*b_field_mv_table[2][2][2])[2];///< MV table (4MV per MB) interlaced b-frame encoding
00344     uint8_t (*p_field_select_table[2]);
00345     uint8_t (*b_field_select_table[2][2]);
00346     int me_method;                       ///< ME algorithm
00347     int mv_dir;
00348 #define MV_DIR_FORWARD   1
00349 #define MV_DIR_BACKWARD  2
00350 #define MV_DIRECT        4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
00351     int mv_type;
00352 #define MV_TYPE_16X16       0   ///< 1 vector for the whole mb
00353 #define MV_TYPE_8X8         1   ///< 4 vectors (h263, mpeg4 4MV)
00354 #define MV_TYPE_16X8        2   ///< 2 vectors, one per 16x8 block
00355 #define MV_TYPE_FIELD       3   ///< 2 vectors, one per field
00356 #define MV_TYPE_DMV         4   ///< 2 vectors, special mpeg2 Dual Prime Vectors
00357     /**motion vectors for a macroblock
00358        first coordinate : 0 = forward 1 = backward
00359        second "         : depend on type
00360        third  "         : 0 = x, 1 = y
00361     */
00362     int mv[2][4][2];
00363     int field_select[2][2];
00364     int last_mv[2][2][2];             ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
00365     uint8_t *fcode_tab;               ///< smallest fcode needed for each MV
00366     int16_t direct_scale_mv[2][64];   ///< precomputed to avoid divisions in ff_mpeg4_set_direct_mv
00367 
00368     MotionEstContext me;
00369 
00370     int no_rounding;  /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
00371                         for b-frames rounding mode is always 0 */
00372 
00373     int hurry_up;     /**< when set to 1 during decoding, b frames will be skipped
00374                          when set to 2 idct/dequant will be skipped too */
00375 
00376     /* macroblock layer */
00377     int mb_x, mb_y;
00378     int mb_skip_run;
00379     int mb_intra;
00380     uint16_t *mb_type;           ///< Table for candidate MB types for encoding
00381 #define CANDIDATE_MB_TYPE_INTRA    0x01
00382 #define CANDIDATE_MB_TYPE_INTER    0x02
00383 #define CANDIDATE_MB_TYPE_INTER4V  0x04
00384 #define CANDIDATE_MB_TYPE_SKIPPED   0x08
00385 //#define MB_TYPE_GMC      0x10
00386 
00387 #define CANDIDATE_MB_TYPE_DIRECT   0x10
00388 #define CANDIDATE_MB_TYPE_FORWARD  0x20
00389 #define CANDIDATE_MB_TYPE_BACKWARD 0x40
00390 #define CANDIDATE_MB_TYPE_BIDIR    0x80
00391 
00392 #define CANDIDATE_MB_TYPE_INTER_I    0x100
00393 #define CANDIDATE_MB_TYPE_FORWARD_I  0x200
00394 #define CANDIDATE_MB_TYPE_BACKWARD_I 0x400
00395 #define CANDIDATE_MB_TYPE_BIDIR_I    0x800
00396 
00397 #define CANDIDATE_MB_TYPE_DIRECT0    0x1000
00398 
00399     int block_index[6]; ///< index to current MB in block based arrays with edges
00400     int block_wrap[6];
00401     uint8_t *dest[3];
00402 
00403     int *mb_index2xy;        ///< mb_index -> mb_x + mb_y*mb_stride
00404 
00405     /** matrix transmitted in the bitstream */
00406     uint16_t intra_matrix[64];
00407     uint16_t chroma_intra_matrix[64];
00408     uint16_t inter_matrix[64];
00409     uint16_t chroma_inter_matrix[64];
00410 #define QUANT_BIAS_SHIFT 8
00411     int intra_quant_bias;    ///< bias for the quantizer
00412     int inter_quant_bias;    ///< bias for the quantizer
00413     int min_qcoeff;          ///< minimum encodable coefficient
00414     int max_qcoeff;          ///< maximum encodable coefficient
00415     int ac_esc_length;       ///< num of bits needed to encode the longest esc
00416     uint8_t *intra_ac_vlc_length;
00417     uint8_t *intra_ac_vlc_last_length;
00418     uint8_t *inter_ac_vlc_length;
00419     uint8_t *inter_ac_vlc_last_length;
00420     uint8_t *luma_dc_vlc_length;
00421     uint8_t *chroma_dc_vlc_length;
00422 #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
00423 
00424     int coded_score[8];
00425 
00426     /** precomputed matrix (combine qscale and DCT renorm) */
00427     int (*q_intra_matrix)[64];
00428     int (*q_inter_matrix)[64];
00429     /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
00430     uint16_t (*q_intra_matrix16)[2][64];
00431     uint16_t (*q_inter_matrix16)[2][64];
00432     int block_last_index[12];  ///< last non zero coefficient in block
00433     /* scantables */
00434     DECLARE_ALIGNED_8(ScanTable, intra_scantable);
00435     ScanTable intra_h_scantable;
00436     ScanTable intra_v_scantable;
00437     ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce tha cache usage
00438 
00439     /* noise reduction */
00440     int (*dct_error_sum)[64];
00441     int dct_count[2];
00442     uint16_t (*dct_offset)[64];
00443 
00444     void *opaque;              ///< private data for the user
00445 
00446     /* bit rate control */
00447     int64_t wanted_bits;
00448     int64_t total_bits;
00449     int frame_bits;                ///< bits used for the current frame
00450     int next_lambda;               ///< next lambda used for retrying to encode a frame
00451     RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
00452 
00453     /* statistics, used for 2-pass encoding */
00454     int mv_bits;
00455     int header_bits;
00456     int i_tex_bits;
00457     int p_tex_bits;
00458     int i_count;
00459     int f_count;
00460     int b_count;
00461     int skip_count;
00462     int misc_bits; ///< cbp, mb_type
00463     int last_bits; ///< temp var used for calculating the above vars
00464 
00465     /* error concealment / resync */
00466     int error_count;
00467     uint8_t *error_status_table;       ///< table of the error status of each MB
00468 #define VP_START            1          ///< current MB is the first after a resync marker
00469 #define AC_ERROR            2
00470 #define DC_ERROR            4
00471 #define MV_ERROR            8
00472 #define AC_END              16
00473 #define DC_END              32
00474 #define MV_END              64
00475 //FIXME some prefix?
00476 
00477     int resync_mb_x;                 ///< x position of last resync marker
00478     int resync_mb_y;                 ///< y position of last resync marker
00479     GetBitContext last_resync_gb;    ///< used to search for the next resync marker
00480     int mb_num_left;                 ///< number of MBs left in this video packet (for partitioned Slices only)
00481     int next_p_frame_damaged;        ///< set if the next p frame is damaged, to avoid showing trashed b frames
00482     int error_resilience;
00483 
00484     ParseContext parse_context;
00485 
00486     /* H.263 specific */
00487     int gob_index;
00488     int obmc;                       ///< overlapped block motion compensation
00489 
00490     /* H.263+ specific */
00491     int umvplus;                    ///< == H263+ && unrestricted_mv
00492     int h263_aic;                   ///< Advanded INTRA Coding (AIC)
00493     int h263_aic_dir;               ///< AIC direction: 0 = left, 1 = top
00494     int h263_slice_structured;
00495     int alt_inter_vlc;              ///< alternative inter vlc
00496     int modified_quant;
00497     int loop_filter;
00498     int custom_pcf;
00499 
00500     /* mpeg4 specific */
00501     int time_increment_bits;        ///< number of bits to represent the fractional part of time
00502     int last_time_base;
00503     int time_base;                  ///< time in seconds of last I,P,S Frame
00504     int64_t time;                   ///< time of current frame
00505     int64_t last_non_b_time;
00506     uint16_t pp_time;               ///< time distance between the last 2 p,s,i frames
00507     uint16_t pb_time;               ///< time distance between the last b and p,s,i frame
00508     uint16_t pp_field_time;
00509     uint16_t pb_field_time;         ///< like above, just for interlaced
00510     int shape;
00511     int vol_sprite_usage;
00512     int sprite_width;
00513     int sprite_height;
00514     int sprite_left;
00515     int sprite_top;
00516     int sprite_brightness_change;
00517     int num_sprite_warping_points;
00518     int real_sprite_warping_points;
00519     int sprite_offset[2][2];         ///< sprite offset[isChroma][isMVY]
00520     int sprite_delta[2][2];          ///< sprite_delta [isY][isMVY]
00521     int sprite_shift[2];             ///< sprite shift [isChroma]
00522     int mcsel;
00523     int quant_precision;
00524     int quarter_sample;              ///< 1->qpel, 0->half pel ME/MC
00525     int scalability;
00526     int hierachy_type;
00527     int enhancement_type;
00528     int new_pred;
00529     int reduced_res_vop;
00530     int aspect_ratio_info; //FIXME remove
00531     int sprite_warping_accuracy;
00532     int low_latency_sprite;
00533     int data_partitioning;           ///< data partitioning flag from header
00534     int partitioned_frame;           ///< is current frame partitioned
00535     int rvlc;                        ///< reversible vlc
00536     int resync_marker;               ///< could this stream contain resync markers
00537     int low_delay;                   ///< no reordering needed / has no b-frames
00538     int vo_type;
00539     int vol_control_parameters;      ///< does the stream contain the low_delay flag, used to workaround buggy encoders
00540     int intra_dc_threshold;          ///< QP above whch the ac VLC should be used for intra dc
00541     int use_intra_dc_vlc;
00542     PutBitContext tex_pb;            ///< used for data partitioned VOPs
00543     PutBitContext pb2;               ///< used for data partitioned VOPs
00544     int mpeg_quant;
00545     int t_frame;                       ///< time distance of first I -> B, used for interlaced b frames
00546     int padding_bug_score;             ///< used to detect the VERY common padding bug in MPEG4
00547 
00548     /* divx specific, used to workaround (many) bugs in divx5 */
00549     int divx_version;
00550     int divx_build;
00551     int divx_packed;
00552     uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
00553     int bitstream_buffer_size;
00554     unsigned int allocated_bitstream_buffer_size;
00555 
00556     int xvid_build;
00557 
00558     /* lavc specific stuff, used to workaround bugs in libavcodec */
00559     int lavc_build;
00560 
00561     /* RV10 specific */
00562     int rv10_version; ///< RV10 version: 0 or 3
00563     int rv10_first_dc_coded[3];
00564 
00565     /* MJPEG specific */
00566     struct MJpegContext *mjpeg_ctx;
00567     int mjpeg_vsample[3];       ///< vertical sampling factors, default = {2, 1, 1}
00568     int mjpeg_hsample[3];       ///< horizontal sampling factors, default = {2, 1, 1}
00569 
00570     /* MSMPEG4 specific */
00571     int mv_table_index;