00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _RC_QUADRATIC_H_
00020 #define _RC_QUADRATIC_H_
00021
00022 #define RC_MODEL_HISTORY 21
00023
00024 typedef struct
00025 {
00026 float bit_rate;
00027 float frame_rate;
00028 float PrevBitRate;
00029 double GAMMAP;
00030 double BETAP;
00031 double GOPTargetBufferLevel;
00032 double TargetBufferLevel;
00033 double AveWp;
00034 double AveWb;
00035 int MyInitialQp;
00036 int PAverageQp;
00037
00038
00039 double PreviousPictureMAD;
00040 double MADPictureC1;
00041 double MADPictureC2;
00042 double PMADPictureC1;
00043 double PMADPictureC2;
00044
00045 double PPictureMAD [RC_MODEL_HISTORY];
00046 double PictureMAD [RC_MODEL_HISTORY];
00047 double ReferenceMAD[RC_MODEL_HISTORY];
00048 double m_rgQp [RC_MODEL_HISTORY];
00049 double m_rgRp [RC_MODEL_HISTORY];
00050 double Pm_rgQp [RC_MODEL_HISTORY];
00051 double Pm_rgRp [RC_MODEL_HISTORY];
00052
00053 double m_X1;
00054 double m_X2;
00055 double Pm_X1;
00056 double Pm_X2;
00057 int Pm_Qp;
00058 int Pm_Hp;
00059
00060 int MADm_windowSize;
00061 int m_windowSize;
00062 int m_Qc;
00063
00064 int PPreHeader;
00065 int PrevLastQP;
00066 int CurrLastQP;
00067 int NumberofBFrames;
00068
00069 int TotalFrameQP;
00070 int NumberofBasicUnit;
00071 int PAveHeaderBits1;
00072 int PAveHeaderBits2;
00073 int PAveHeaderBits3;
00074 int PAveFrameQP;
00075 int TotalNumberofBasicUnit;
00076 int CodedBasicUnit;
00077
00078 int NumberofCodedPFrame;
00079 int TotalQpforPPicture;
00080 int NumberofPPicture;
00081
00082 double CurrentFrameMAD;
00083 double CurrentBUMAD;
00084 double TotalBUMAD;
00085 double PreviousFrameMAD;
00086 double PreviousWholeFrameMAD;
00087
00088 int DDquant;
00089 unsigned int MBPerRow;
00090 int QPLastPFrame;
00091 int QPLastGOP;
00092
00093
00094 int FieldQPBuffer;
00095 int FrameQPBuffer;
00096 int FrameAveHeaderBits;
00097 int FieldAveHeaderBits;
00098 double *BUPFMAD;
00099 double *BUCFMAD;
00100 double *FCBUCFMAD;
00101 double *FCBUPFMAD;
00102
00103 Boolean GOPOverdue;
00104 int64 Pprev_bits;
00105
00106
00107 int Xp, Xb;
00108 int Target;
00109 int TargetField;
00110 int Np, Nb, bits_topfield;
00111
00112 int UpperBound1, UpperBound2, LowerBound;
00113 double Wp, Wb;
00114 double DeltaP;
00115 int TotalPFrame;
00116 int PMaxQpChange;
00117 } rc_quadratic;
00118
00119
00120
00121 void rc_alloc_quadratic( rc_quadratic **prc );
00122 void rc_free_quadratic ( rc_quadratic **prc );
00123 void rc_copy_quadratic ( rc_quadratic *dst, rc_quadratic *src );
00124
00125
00126 void rc_init_seq (rc_quadratic *prc);
00127 void rc_init_GOP (rc_quadratic *prc, int np, int nb);
00128 void rc_update_pict_frame (rc_quadratic *prc, int nbits);
00129 void rc_init_pict (rc_quadratic *prc, int fieldpic, int topfield, int targetcomputation, float mult);
00130 void rc_update_pict (rc_quadratic *prc, int nbits);
00131 void rc_update_picture (int bits);
00132
00133 int updateQPRC0(rc_quadratic *prc, int topfield);
00134 int updateQPRC1(rc_quadratic *prc, int topfield);
00135 int updateQPRC2(rc_quadratic *prc, int topfield);
00136 int updateQPRC3(rc_quadratic *prc, int topfield);
00137
00138
00139 void updateQPInterlace ( rc_quadratic *prc );
00140 void updateQPNonPicAFF ( rc_quadratic *prc );
00141 void updateBottomField ( rc_quadratic *prc );
00142 int updateFirstP ( rc_quadratic *prc, int topfield );
00143 int updateNegativeTarget( rc_quadratic *prc, int topfield, int m_Qp );
00144 int updateFirstBU ( rc_quadratic *prc, int topfield );
00145 void updateLastBU ( rc_quadratic *prc, int topfield );
00146 void predictCurrPicMAD ( rc_quadratic *prc );
00147 void updateModelQPBU ( rc_quadratic *prc, int topfield, int m_Qp );
00148 void updateQPInterlaceBU ( rc_quadratic *prc );
00149 void updateModelQPFrame ( rc_quadratic *prc, int m_Bits );
00150
00151 void updateRCModel (rc_quadratic *prc);
00152 void updateMADModel (rc_quadratic *prc);
00153 void RCModelEstimator (rc_quadratic *prc, int n_windowSize, Boolean *m_rgRejected);
00154 void MADModelEstimator(rc_quadratic *prc, int n_windowSize, Boolean *PictureRejected);
00155 int updateComplexity (rc_quadratic *prc, Boolean is_updated, int nbits );
00156 void updatePparams (rc_quadratic *prc, int complexity );
00157 void updateBparams (rc_quadratic *prc, int complexity );
00158
00159
00160 int rc_handle_mb ( int prev_mb, Macroblock *currMB, Slice *currSlice );
00161 void rc_init_top_field ( void );
00162 void rc_init_bottom_field ( int TopFieldBits );
00163 void rc_init_frame_rdpic ( float rateRatio );
00164 void rc_allocate_memory ( void );
00165 void rc_free_memory ( void );
00166 void rc_update_mb_stats ( Macroblock *currMB, int *bitCount );
00167 void rc_save_state ( void );
00168 void rc_restore_state ( void );
00169
00170
00171 rc_quadratic *quadratic_RC;
00172
00173 rc_quadratic *quadratic_RC_init, *quadratic_RC_best;
00174
00175
00176 int (*updateQP) (rc_quadratic *prc, int topfield);
00177 void (*rc_update_pict_frame_ptr)(rc_quadratic *prc, int nbits);
00178 void (*rc_update_picture_ptr) (int bits);
00179 void (*rc_init_pict_ptr) (rc_quadratic *prc, int fieldpic, int topfield, int targetcomputation, float mult);
00180
00181 #endif