Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp
r1179 r1313 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 37 37 #include "TEncRateCtrl.h" 38 38 #include "../TLibCommon/TComPic.h" 39 #include "../TLibCommon/TComChromaFormat.h" 39 40 40 41 #include <cmath> … … 116 117 m_betaUpdate = 0.2; 117 118 } 119 118 120 m_averageBits = (Int)(m_targetBits / totalFrames); 119 121 Int picWidthInBU = ( m_picWidth % m_LCUWidth ) == 0 ? m_picWidth / m_LCUWidth : m_picWidth / m_LCUWidth + 1; … … 222 224 else 223 225 { 224 m_picPara[i].m_alpha = ALPHA; 226 m_picPara[i].m_alpha = ALPHA; 225 227 m_picPara[i].m_beta = BETA2; 226 228 } … … 402 404 Double maxNumber = 10000.0; 403 405 for ( Int i=0; i<g_RCIterationNum; i++ ) 404 { 406 { 405 407 Double fx = 0.0; 406 408 for ( Int j=0; j<GOPSize; j++ ) … … 698 700 if (eSliceType == I_SLICE) 699 701 { 700 estLambda = calculateLambdaIntra(alpha, beta, pow(m_totalCostIntra/(Double)m_numberOfPixel, BETA1), bpp); 702 estLambda = calculateLambdaIntra(alpha, beta, pow(m_totalCostIntra/(Double)m_numberOfPixel, BETA1), bpp); 701 703 } 702 704 else … … 704 706 estLambda = alpha * pow( bpp, beta ); 705 707 } 706 708 707 709 Double lastLevelLambda = -1.0; 708 710 Double lastPicLambda = -1.0; … … 786 788 Int TEncRCPic::estimatePicQP( Double lambda, list<TEncRCPic*>& listPreviousPictures ) 787 789 { 788 Int QP = Int( 4.2005 * log( lambda ) + 13.7122 + 0.5 ); 790 Int QP = Int( 4.2005 * log( lambda ) + 13.7122 + 0.5 ); 789 791 790 792 Int lastLevelQP = g_RCInvalidQPValue; … … 889 891 890 892 891 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 893 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 892 894 { 893 895 Int LCUIdx = getLCUCoded(); … … 914 916 else 915 917 { 916 Double totalWeight = 0;917 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )918 {919 totalWeight += m_LCUs[i].m_bitWeight;920 }921 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );922 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );918 Double totalWeight = 0; 919 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ ) 920 { 921 totalWeight += m_LCUs[i].m_bitWeight; 922 } 923 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() ); 924 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 ); 923 925 } 924 926 … … 1073 1075 //for Lambda clip, LCU level clip 1074 1076 Double clipNeighbourLambda = -1.0; 1075 for ( int i=LCUIdx - 1; i>=0; i-- )1077 for ( Int i=LCUIdx - 1; i>=0; i-- ) 1076 1078 { 1077 1079 if ( m_LCUs[i].m_lambda > 0 ) … … 1085 1087 { 1086 1088 estLambda = Clip3( clipNeighbourLambda * pow( 2.0, -1.0/3.0 ), clipNeighbourLambda * pow( 2.0, 1.0/3.0 ), estLambda ); 1087 } 1089 } 1088 1090 1089 1091 if ( clipPicLambda > 0.0 ) … … 1111 1113 //for Lambda clip, LCU level clip 1112 1114 Int clipNeighbourQP = g_RCInvalidQPValue; 1113 for ( int i=LCUIdx - 1; i>=0; i-- )1115 for ( Int i=LCUIdx - 1; i>=0; i-- ) 1114 1116 { 1115 1117 if ( (getLCU(i)).m_QP > g_RCInvalidQPValue ) … … 1130 1132 } 1131 1133 1132 Void TEncRCPic::updateAfter LCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter )1134 Void TEncRCPic::updateAfterCTU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter ) 1133 1135 { 1134 1136 m_LCUs[LCUIdx].m_actualBits = bits; … … 1177 1179 calLambda = Clip3( inputLambda / 10.0, inputLambda * 10.0, calLambda ); 1178 1180 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1179 double lnbpp = log( bpp );1181 Double lnbpp = log( bpp ); 1180 1182 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1181 1183 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; … … 1183 1185 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1184 1186 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1187 1185 1188 TRCParameter rcPara; 1186 1189 rcPara.m_alpha = alpha; … … 1232 1235 } 1233 1236 1234 Double avgLambda; 1237 Double avgLambda; 1235 1238 if( numTotalLCUs == 0 ) 1236 1239 { … … 1243 1246 return avgLambda; 1244 1247 } 1248 1245 1249 1246 1250 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType) … … 1267 1271 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 1268 1272 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 1273 1269 1274 if (eSliceType == I_SLICE) 1270 1275 { … … 1273 1278 else 1274 1279 { 1275 // update parameters 1276 Double picActualBits = ( Double )m_picActualBits; 1277 Double picActualBpp = picActualBits/(Double)m_numberOfPixel; 1278 Double calLambda = alpha * pow( picActualBpp, beta ); 1279 Double inputLambda = m_picLambda; 1280 1281 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 ) 1282 { 1283 alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 ); 1284 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1280 // update parameters 1281 Double picActualBits = ( Double )m_picActualBits; 1282 Double picActualBpp = picActualBits/(Double)m_numberOfPixel; 1283 Double calLambda = alpha * pow( picActualBpp, beta ); 1284 Double inputLambda = m_picLambda; 1285 1286 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 ) 1287 { 1288 alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 ); 1289 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1290 1291 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1292 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1293 1294 TRCParameter rcPara; 1295 rcPara.m_alpha = alpha; 1296 rcPara.m_beta = beta; 1297 m_encRCSeq->setPicPara( m_frameLevel, rcPara ); 1298 1299 return; 1300 } 1301 1302 calLambda = Clip3( inputLambda / 10.0, inputLambda * 10.0, calLambda ); 1303 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1304 Double lnbpp = log( picActualBpp ); 1305 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1306 1307 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1285 1308 1286 1309 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1287 1310 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1288 TRCParameter rcPara;1289 rcPara.m_alpha = alpha;1290 rcPara.m_beta = beta;1291 m_encRCSeq->setPicPara( m_frameLevel, rcPara );1292 1293 return;1294 }1295 1296 calLambda = Clip3( inputLambda / 10.0, inputLambda * 10.0, calLambda );1297 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;1298 double lnbpp = log( picActualBpp );1299 lnbpp = Clip3( -5.0, -0.1, lnbpp );1300 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;1301 1302 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );1303 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta );1304 1311 } 1305 1312 … … 1333 1340 1334 1341 iIntraBits = (Int)(alpha* pow(m_totalCostIntra*4.0/(Double)orgBits, beta)*(Double)orgBits+0.5); 1335 1342 1336 1343 return iIntraBits; 1337 1344 } 1338 1345 1339 Double TEncRCPic::calculateLambdaIntra( double alpha, double beta, double MADPerPixel, double bitsPerPixel)1346 Double TEncRCPic::calculateLambdaIntra(Double alpha, Double beta, Double MADPerPixel, Double bitsPerPixel) 1340 1347 { 1341 1348 return ( (alpha/256.0) * pow( MADPerPixel/bitsPerPixel, beta ) ); 1342 1349 } 1343 1350 1344 Void TEncRCPic::updateAlphaBetaIntra( double *alpha, double *beta)1351 Void TEncRCPic::updateAlphaBetaIntra(Double *alpha, Double *beta) 1345 1352 { 1346 1353 Double lnbpp = log(pow(m_totalCostIntra / (Double)m_numberOfPixel, BETA1)); … … 1353 1360 1354 1361 1355 Void TEncRCPic::getLCUInitTargetBits() 1362 Void TEncRCPic::getLCUInitTargetBits() 1356 1363 { 1357 1364 Int iAvgBits = 0; … … 1366 1373 1367 1374 1368 Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP) 1375 Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP) 1369 1376 { 1370 1377 Int LCUIdx = getLCUCoded(); … … 1378 1385 1379 1386 Int clipNeighbourQP = g_RCInvalidQPValue; 1380 for ( int i=LCUIdx-1; i>=0; i--)1387 for (Int i=LCUIdx-1; i>=0; i--) 1381 1388 { 1382 1389 if ((getLCU(i)).m_QP > g_RCInvalidQPValue) … … 1392 1399 if ( clipNeighbourQP > g_RCInvalidQPValue ) 1393 1400 { 1394 maxQP = min(clipNeighbourQP + 1, maxQP); 1395 minQP = max(clipNeighbourQP - 1, minQP); 1401 maxQP = min(clipNeighbourQP + 1, maxQP); 1402 minQP = max(clipNeighbourQP - 1, minQP); 1396 1403 } 1397 1404 … … 1515 1522 bitsRatio[3] = 14; 1516 1523 } 1524 1517 1525 if ( keepHierBits == 2 ) 1518 1526 { … … 1566 1574 bitsRatio[7] = 1; 1567 1575 } 1576 1568 1577 if ( keepHierBits == 2 ) 1569 1578 { … … 1577 1586 } 1578 1587 1579 Int* GOPID2Level = new int[ GOPSize ];1580 for ( int i=0; i<GOPSize; i++ )1588 Int* GOPID2Level = new Int[ GOPSize ]; 1589 for ( Int i=0; i<GOPSize; i++ ) 1581 1590 { 1582 1591 GOPID2Level[i] = 1; … … 1586 1595 } 1587 1596 } 1597 1588 1598 if ( keepHierBits > 0 ) 1589 1599 { … … 1659 1669 m_encRCGOP = NULL; 1660 1670 } 1661
Note: See TracChangeset for help on using the changeset viewer.