Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncRateCtrl.h
- Timestamp:
- 16 Apr 2013, 06:39:31 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncRateCtrl.h
r2 r125 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 54 54 //! \ingroup TLibEncoder 55 55 //! \{ 56 57 #if RATE_CONTROL_LAMBDA_DOMAIN 58 #include "../TLibEncoder/TEncCfg.h" 59 #include <list> 60 #include <cassert> 61 62 const Int g_RCInvalidQPValue = -999; 63 const Int g_RCSmoothWindowSize = 40; 64 const Int g_RCMaxPicListSize = 32; 65 const Double g_RCWeightPicTargetBitInGOP = 0.9; 66 const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP; 67 68 struct TRCLCU 69 { 70 Int m_actualBits; 71 Int m_QP; // QP of skip mode is set to g_RCInvalidQPValue 72 Int m_targetBits; 73 Double m_lambda; 74 Double m_MAD; 75 Int m_numberOfPixel; 76 }; 77 78 struct TRCParameter 79 { 80 Double m_alpha; 81 Double m_beta; 82 }; 83 84 class TEncRCSeq 85 { 86 public: 87 TEncRCSeq(); 88 ~TEncRCSeq(); 89 90 public: 91 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel ); 92 Void destroy(); 93 Void initBitsRatio( Int bitsRatio[] ); 94 Void initGOPID2Level( Int GOPID2Level[] ); 95 Void initPicPara( TRCParameter* picPara = NULL ); // NULL to initial with default value 96 Void initLCUPara( TRCParameter** LCUPara = NULL ); // NULL to initial with default value 97 Void updateAfterPic ( Int bits ); 98 Int getRefineBitsForIntra( Int orgBits ); 99 100 public: 101 Int getTotalFrames() { return m_totalFrames; } 102 Int getTargetRate() { return m_targetRate; } 103 Int getFrameRate() { return m_frameRate; } 104 Int getGOPSize() { return m_GOPSize; } 105 Int getPicWidth() { return m_picWidth; } 106 Int getPicHeight() { return m_picHeight; } 107 Int getLCUWidth() { return m_LCUWidth; } 108 Int getLCUHeight() { return m_LCUHeight; } 109 Int getNumberOfLevel() { return m_numberOfLevel; } 110 Int getAverageBits() { return m_averageBits; } 111 Int getLeftAverageBits() { assert( m_framesLeft > 0 ); return (Int)(m_bitsLeft / m_framesLeft); } 112 Bool getUseLCUSeparateModel() { return m_useLCUSeparateModel; } 113 114 Int getNumPixel() { return m_numberOfPixel; } 115 Int64 getTargetBits() { return m_targetBits; } 116 Int getNumberOfLCU() { return m_numberOfLCU; } 117 Int* getBitRatio() { return m_bitsRatio; } 118 Int getBitRatio( Int idx ) { assert( idx<m_GOPSize); return m_bitsRatio[idx]; } 119 Int* getGOPID2Level() { return m_GOPID2Level; } 120 Int getGOPID2Level( Int ID ) { assert( ID < m_GOPSize ); return m_GOPID2Level[ID]; } 121 TRCParameter* getPicPara() { return m_picPara; } 122 TRCParameter getPicPara( Int level ) { assert( level < m_numberOfLevel ); return m_picPara[level]; } 123 Void setPicPara( Int level, TRCParameter para ) { assert( level < m_numberOfLevel ); m_picPara[level] = para; } 124 TRCParameter** getLCUPara() { return m_LCUPara; } 125 TRCParameter* getLCUPara( Int level ) { assert( level < m_numberOfLevel ); return m_LCUPara[level]; } 126 TRCParameter getLCUPara( Int level, Int LCUIdx ) { assert( LCUIdx < m_numberOfLCU ); return getLCUPara(level)[LCUIdx]; } 127 Void setLCUPara( Int level, Int LCUIdx, TRCParameter para ) { assert( level < m_numberOfLevel ); assert( LCUIdx < m_numberOfLCU ); m_LCUPara[level][LCUIdx] = para; } 128 129 Int getFramesLeft() { return m_framesLeft; } 130 Int64 getBitsLeft() { return m_bitsLeft; } 131 132 Double getSeqBpp() { return m_seqTargetBpp; } 133 Double getAlphaUpdate() { return m_alphaUpdate; } 134 Double getBetaUpdate() { return m_betaUpdate; } 135 136 private: 137 Int m_totalFrames; 138 Int m_targetRate; 139 Int m_frameRate; 140 Int m_GOPSize; 141 Int m_picWidth; 142 Int m_picHeight; 143 Int m_LCUWidth; 144 Int m_LCUHeight; 145 Int m_numberOfLevel; 146 Int m_averageBits; 147 148 Int m_numberOfPixel; 149 Int64 m_targetBits; 150 Int m_numberOfLCU; 151 Int* m_bitsRatio; 152 Int* m_GOPID2Level; 153 TRCParameter* m_picPara; 154 TRCParameter** m_LCUPara; 155 156 Int m_framesLeft; 157 Int64 m_bitsLeft; 158 Double m_seqTargetBpp; 159 Double m_alphaUpdate; 160 Double m_betaUpdate; 161 Bool m_useLCUSeparateModel; 162 }; 163 164 class TEncRCGOP 165 { 166 public: 167 TEncRCGOP(); 168 ~TEncRCGOP(); 169 170 public: 171 Void create( TEncRCSeq* encRCSeq, Int numPic ); 172 Void destroy(); 173 Void updateAfterPicture( Int bitsCost ); 174 175 private: 176 Int xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize ); 177 178 public: 179 TEncRCSeq* getEncRCSeq() { return m_encRCSeq; } 180 Int getNumPic() { return m_numPic;} 181 Int getTargetBits() { return m_targetBits; } 182 Int getPicLeft() { return m_picLeft; } 183 Int getBitsLeft() { return m_bitsLeft; } 184 Int getTargetBitInGOP( Int i ) { return m_picTargetBitInGOP[i]; } 185 186 private: 187 TEncRCSeq* m_encRCSeq; 188 Int* m_picTargetBitInGOP; 189 Int m_numPic; 190 Int m_targetBits; 191 Int m_picLeft; 192 Int m_bitsLeft; 193 }; 194 195 class TEncRCPic 196 { 197 public: 198 TEncRCPic(); 199 ~TEncRCPic(); 200 201 public: 202 Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures ); 203 Void destroy(); 204 205 Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures ); 206 Int estimatePicQP ( Double lambda, list<TEncRCPic*>& listPreviousPictures ); 207 Double getLCUTargetBpp(); 208 Double getLCUEstLambda( Double bpp ); 209 Int getLCUEstQP( Double lambda, Int clipPicQP ); 210 211 Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true ); 212 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage ); 213 214 Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures ); 215 Double getEffectivePercentage(); 216 Double calAverageQP(); 217 Double calAverageLambda(); 218 219 private: 220 Int xEstPicTargetBits( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP ); 221 Int xEstPicHeaderBits( list<TEncRCPic*>& listPreviousPictures, Int frameLevel ); 222 223 public: 224 TEncRCSeq* getRCSequence() { return m_encRCSeq; } 225 TEncRCGOP* getRCGOP() { return m_encRCGOP; } 226 227 Int getFrameLevel() { return m_frameLevel; } 228 Int getNumberOfPixel() { return m_numberOfPixel; } 229 Int getNumberOfLCU() { return m_numberOfLCU; } 230 Int getTargetBits() { return m_targetBits; } 231 Void setTargetBits( Int bits ) { m_targetBits = bits; } 232 Int getEstHeaderBits() { return m_estHeaderBits; } 233 Int getLCULeft() { return m_LCULeft; } 234 Int getBitsLeft() { return m_bitsLeft; } 235 Int getPixelsLeft() { return m_pixelsLeft; } 236 Int getBitsCoded() { return m_targetBits - m_estHeaderBits - m_bitsLeft; } 237 Int getLCUCoded() { return m_numberOfLCU - m_LCULeft; } 238 TRCLCU* getLCU() { return m_LCUs; } 239 TRCLCU& getLCU( Int LCUIdx ) { return m_LCUs[LCUIdx]; } 240 Int getPicActualHeaderBits() { return m_picActualHeaderBits; } 241 Double getTotalMAD() { return m_totalMAD; } 242 Void setTotalMAD( Double MAD ) { m_totalMAD = MAD; } 243 Int getPicActualBits() { return m_picActualBits; } 244 Int getPicActualQP() { return m_picQP; } 245 Double getPicActualLambda() { return m_picLambda; } 246 Int getPicEstQP() { return m_estPicQP; } 247 Void setPicEstQP( Int QP ) { m_estPicQP = QP; } 248 Double getPicEstLambda() { return m_estPicLambda; } 249 Void setPicEstLambda( Double lambda ) { m_picLambda = lambda; } 250 251 private: 252 TEncRCSeq* m_encRCSeq; 253 TEncRCGOP* m_encRCGOP; 254 255 Int m_frameLevel; 256 Int m_numberOfPixel; 257 Int m_numberOfLCU; 258 Int m_targetBits; 259 Int m_estHeaderBits; 260 Int m_estPicQP; 261 Double m_estPicLambda; 262 263 Int m_LCULeft; 264 Int m_bitsLeft; 265 Int m_pixelsLeft; 266 267 TRCLCU* m_LCUs; 268 Int m_picActualHeaderBits; // only SH and potential APS 269 Double m_totalMAD; 270 Int m_picActualBits; // the whole picture, including header 271 Int m_picQP; // in integer form 272 Double m_picLambda; 273 TEncRCPic* m_lastPicture; 274 }; 275 276 class TEncRateCtrl 277 { 278 public: 279 TEncRateCtrl(); 280 ~TEncRateCtrl(); 281 282 public: 283 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] ); 284 Void destroy(); 285 Void initRCPic( Int frameLevel ); 286 Void initRCGOP( Int numberOfPictures ); 287 Void destroyRCGOP(); 288 289 public: 290 Void setRCQP ( Int QP ) { m_RCQP = QP; } 291 Int getRCQP () { return m_RCQP; } 292 TEncRCSeq* getRCSeq() { assert ( m_encRCSeq != NULL ); return m_encRCSeq; } 293 TEncRCGOP* getRCGOP() { assert ( m_encRCGOP != NULL ); return m_encRCGOP; } 294 TEncRCPic* getRCPic() { assert ( m_encRCPic != NULL ); return m_encRCPic; } 295 list<TEncRCPic*>& getPicList() { return m_listRCPictures; } 296 297 private: 298 TEncRCSeq* m_encRCSeq; 299 TEncRCGOP* m_encRCGOP; 300 TEncRCPic* m_encRCPic; 301 list<TEncRCPic*> m_listRCPictures; 302 Int m_RCQP; 303 }; 304 305 #else 56 306 57 307 // ==================================================================================================================== … … 181 431 #endif 182 432 183 433 #endif 434 435
Note: See TracChangeset for help on using the changeset viewer.