Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp


Ignore:
Timestamp:
13 Aug 2015, 17:38:13 (9 years ago)
Author:
tech
Message:

Merged 14.1-update-dev1@1312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r1179 r1313  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license. 
     4 * granted under this license.
    55 *
    6 * Copyright (c) 2010-2015, ITU/ISO/IEC
     6 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    3737#include "TEncRateCtrl.h"
    3838#include "../TLibCommon/TComPic.h"
     39#include "../TLibCommon/TComChromaFormat.h"
    3940
    4041#include <cmath>
     
    116117    m_betaUpdate  = 0.2;
    117118  }
     119
    118120  m_averageBits     = (Int)(m_targetBits / totalFrames);
    119121  Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
     
    222224      else
    223225      {
    224         m_picPara[i].m_alpha = ALPHA;   
     226        m_picPara[i].m_alpha = ALPHA;
    225227        m_picPara[i].m_beta  = BETA2;
    226228      }
     
    402404  Double maxNumber = 10000.0;
    403405  for ( Int i=0; i<g_RCIterationNum; i++ )
    404   { 
     406  {
    405407    Double fx = 0.0;
    406408    for ( Int j=0; j<GOPSize; j++ )
     
    698700  if (eSliceType == I_SLICE)
    699701  {
    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);
    701703  }
    702704  else
     
    704706    estLambda = alpha * pow( bpp, beta );
    705707  }
    706  
     708
    707709  Double lastLevelLambda = -1.0;
    708710  Double lastPicLambda   = -1.0;
     
    786788Int TEncRCPic::estimatePicQP( Double lambda, list<TEncRCPic*>& listPreviousPictures )
    787789{
    788   Int QP = Int( 4.2005 * log( lambda ) + 13.7122 + 0.5 ); 
     790  Int QP = Int( 4.2005 * log( lambda ) + 13.7122 + 0.5 );
    789791
    790792  Int lastLevelQP = g_RCInvalidQPValue;
     
    889891
    890892
    891 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
     893Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType)
    892894{
    893895  Int   LCUIdx    = getLCUCoded();
     
    914916  else
    915917  {
    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 );
    923925  }
    924926
     
    10731075  //for Lambda clip, LCU level clip
    10741076  Double clipNeighbourLambda = -1.0;
    1075   for ( int i=LCUIdx - 1; i>=0; i-- )
     1077  for ( Int i=LCUIdx - 1; i>=0; i-- )
    10761078  {
    10771079    if ( m_LCUs[i].m_lambda > 0 )
     
    10851087  {
    10861088    estLambda = Clip3( clipNeighbourLambda * pow( 2.0, -1.0/3.0 ), clipNeighbourLambda * pow( 2.0, 1.0/3.0 ), estLambda );
    1087   } 
     1089  }
    10881090
    10891091  if ( clipPicLambda > 0.0 )
     
    11111113  //for Lambda clip, LCU level clip
    11121114  Int clipNeighbourQP = g_RCInvalidQPValue;
    1113   for ( int i=LCUIdx - 1; i>=0; i-- )
     1115  for ( Int i=LCUIdx - 1; i>=0; i-- )
    11141116  {
    11151117    if ( (getLCU(i)).m_QP > g_RCInvalidQPValue )
     
    11301132}
    11311133
    1132 Void TEncRCPic::updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter )
     1134Void TEncRCPic::updateAfterCTU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter )
    11331135{
    11341136  m_LCUs[LCUIdx].m_actualBits = bits;
     
    11771179  calLambda = Clip3( inputLambda / 10.0, inputLambda * 10.0, calLambda );
    11781180  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    1179   double lnbpp = log( bpp );
     1181  Double lnbpp = log( bpp );
    11801182  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    11811183  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
     
    11831185  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    11841186  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
     1187
    11851188  TRCParameter rcPara;
    11861189  rcPara.m_alpha = alpha;
     
    12321235  }
    12331236
    1234   Double avgLambda; 
     1237  Double avgLambda;
    12351238  if( numTotalLCUs == 0 )
    12361239  {
     
    12431246  return avgLambda;
    12441247}
     1248
    12451249
    12461250Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
     
    12671271  Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    12681272  Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     1273
    12691274  if (eSliceType == I_SLICE)
    12701275  {
     
    12731278  else
    12741279  {
    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;
    12851308
    12861309    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    12871310    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  );
    13041311  }
    13051312
     
    13331340
    13341341  iIntraBits = (Int)(alpha* pow(m_totalCostIntra*4.0/(Double)orgBits, beta)*(Double)orgBits+0.5);
    1335  
     1342
    13361343  return iIntraBits;
    13371344}
    13381345
    1339 Double TEncRCPic::calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel)
     1346Double TEncRCPic::calculateLambdaIntra(Double alpha, Double beta, Double MADPerPixel, Double bitsPerPixel)
    13401347{
    13411348  return ( (alpha/256.0) * pow( MADPerPixel/bitsPerPixel, beta ) );
    13421349}
    13431350
    1344 Void TEncRCPic::updateAlphaBetaIntra(double *alpha, double *beta)
     1351Void TEncRCPic::updateAlphaBetaIntra(Double *alpha, Double *beta)
    13451352{
    13461353  Double lnbpp = log(pow(m_totalCostIntra / (Double)m_numberOfPixel, BETA1));
     
    13531360
    13541361
    1355 Void TEncRCPic::getLCUInitTargetBits() 
     1362Void TEncRCPic::getLCUInitTargetBits()
    13561363{
    13571364  Int iAvgBits     = 0;
     
    13661373
    13671374
    1368 Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP) 
     1375Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP)
    13691376{
    13701377  Int   LCUIdx = getLCUCoded();
     
    13781385
    13791386  Int clipNeighbourQP = g_RCInvalidQPValue;
    1380   for (int i=LCUIdx-1; i>=0; i--)
     1387  for (Int i=LCUIdx-1; i>=0; i--)
    13811388  {
    13821389    if ((getLCU(i)).m_QP > g_RCInvalidQPValue)
     
    13921399  if ( clipNeighbourQP > g_RCInvalidQPValue )
    13931400  {
    1394     maxQP = min(clipNeighbourQP + 1, maxQP); 
    1395     minQP = max(clipNeighbourQP - 1, minQP); 
     1401    maxQP = min(clipNeighbourQP + 1, maxQP);
     1402    minQP = max(clipNeighbourQP - 1, minQP);
    13961403  }
    13971404
     
    15151522        bitsRatio[3] = 14;
    15161523      }
     1524
    15171525      if ( keepHierBits == 2 )
    15181526      {
     
    15661574        bitsRatio[7] = 1;
    15671575      }
     1576
    15681577      if ( keepHierBits == 2 )
    15691578      {
     
    15771586  }
    15781587
    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++ )
    15811590  {
    15821591    GOPID2Level[i] = 1;
     
    15861595    }
    15871596  }
     1597
    15881598  if ( keepHierBits > 0 )
    15891599  {
     
    16591669  m_encRCGOP = NULL;
    16601670}
    1661 
Note: See TracChangeset for help on using the changeset viewer.