Changeset 1433 in SHVCSoftware for branches/SHM-dev/source/Lib


Ignore:
Timestamp:
11 Aug 2015, 20:22:28 (10 years ago)
Author:
seregin
Message:

port rev 4587 and fixes for the previous commit

Location:
branches/SHM-dev/source/Lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h

    r1407 r1433  
    200200#endif
    201201
     202#define U0132_TARGET_BITS_SATURATION                      1 ///< Rate control with target bits saturation method
    202203
    203204// ====================================================================================================================
  • branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r1432 r1433  
    35753575  READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" );
    35763576  READ_UVLC( uiOutputBitDepthM8, "cm_output_luma_bit_depth_minus8" );
    3577   READ_UVLC( uiChromaOutputBitDepthM8  "cm_output_chroma_bit_depth_minus8" );
     3577  READ_UVLC( uiChromaOutputBitDepthM8,  "cm_output_chroma_bit_depth_minus8" );
    35783578  READ_CODE( 2, uiResQaunBit, "cm_res_quant_bit" );
    35793579
     
    36813681            for( Int nVertexIdx = 0; nVertexIdx < 4; nVertexIdx++ )
    36823682            {
    3683               pc3DAsymLUT->setCuboidVertexResTree( yIdx + y, uIdx +  , vIdx + v, nVertexIdx, 0, 0, 0 );
     3683              pc3DAsymLUT->setCuboidVertexResTree( yIdx + y, uIdx + u, vIdx + v, nVertexIdx, 0, 0, 0 );
    36843684#if R0164_CGS_LUT_BUGFIX_CHECK
    36853685              pc3DAsymLUT->xSetFilled( yIdx + y, uIdx + u, vIdx + v );
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h

    r1432 r1433  
    339339  Int       m_RCInitialQP;
    340340  Bool      m_RCForceIntraQP;
     341#if U0132_TARGET_BITS_SATURATION
     342  Bool      m_RCCpbSaturationEnabled;
     343  UInt      m_RCCpbSize;
     344  Double    m_RCInitialCpbFullness;
     345#endif
    341346  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    342347  Bool      m_CUTransquantBypassFlagForce;                    ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true.
     
    936941  Bool         getForceIntraQP        ()                             { return m_RCForceIntraQP;        }
    937942  Void         setForceIntraQP        ( Bool b )                     { m_RCForceIntraQP = b;           }
     943#if U0132_TARGET_BITS_SATURATION
     944  Bool         getCpbSaturationEnabled()                             { return m_RCCpbSaturationEnabled;}
     945  Void         setCpbSaturationEnabled( Bool b )                     { m_RCCpbSaturationEnabled = b;   }
     946  UInt         getCpbSize             ()                             { return m_RCCpbSize;}
     947  Void         setCpbSize             ( UInt ui )                    { m_RCCpbSize = ui;   }
     948  Double       getInitialCpbFullness  ()                             { return m_RCInitialCpbFullness;  }
     949  Void         setInitialCpbFullness  (Double f)                     { m_RCInitialCpbFullness = f;     }
     950#endif
    938951  Bool         getTransquantBypassEnableFlag()                       { return m_TransquantBypassEnableFlag; }
    939952  Void         setTransquantBypassEnableFlag(Bool flag)              { m_TransquantBypassEnableFlag = flag; }
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r1432 r1433  
    24322432      estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
    24332433
     2434#if U0132_TARGET_BITS_SATURATION
     2435      if (m_pcRateCtrl->getCpbSaturationEnabled() && frameLevel != 0)
     2436      {
     2437        Int estimatedCpbFullness = m_pcRateCtrl->getCpbState() + m_pcRateCtrl->getBufferingRate();
     2438
     2439        // prevent overflow
     2440        if (estimatedCpbFullness - estimatedBits > (Int)(m_pcRateCtrl->getCpbSize()*0.9f))
     2441        {
     2442          estimatedBits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.9f);
     2443        }
     2444
     2445        estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate();
     2446        // prevent underflow
     2447        if (estimatedCpbFullness - estimatedBits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f))
     2448        {
     2449          estimatedBits = max(200, estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f));
     2450        }
     2451
     2452        m_pcRateCtrl->getRCPic()->setTargetBits(estimatedBits);
     2453      }
     2454#endif
     2455
    24342456      Int sliceQP = m_pcCfg->getInitialQP();
    24352457#if SVC_EXTENSION
     
    24552477          Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
    24562478          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
     2479
     2480#if U0132_TARGET_BITS_SATURATION
     2481          if (m_pcRateCtrl->getCpbSaturationEnabled() )
     2482          {
     2483            Int estimatedCpbFullness = m_pcRateCtrl->getCpbState() + m_pcRateCtrl->getBufferingRate();
     2484
     2485            // prevent overflow
     2486            if (estimatedCpbFullness - bits > (Int)(m_pcRateCtrl->getCpbSize()*0.9f))
     2487            {
     2488              bits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.9f);
     2489            }
     2490
     2491            estimatedCpbFullness -= m_pcRateCtrl->getBufferingRate();
     2492            // prevent underflow
     2493            if (estimatedCpbFullness - bits < (Int)(m_pcRateCtrl->getCpbSize()*0.1f))
     2494            {
     2495              bits = estimatedCpbFullness - (Int)(m_pcRateCtrl->getCpbSize()*0.1f);
     2496            }
     2497          }
     2498#endif
     2499
    24572500          if ( bits < 200 )
    24582501          {
     
    28462889        m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits );
    28472890      }
     2891#if U0132_TARGET_BITS_SATURATION
     2892      if (m_pcRateCtrl->getCpbSaturationEnabled())
     2893      {
     2894        m_pcRateCtrl->updateCpbState(actualTotalBits);
     2895        printf(" [CPB %6d bits]", m_pcRateCtrl->getCpbState());
     2896      }
     2897#endif
    28482898    }
    28492899
     
    42564306#endif
    42574307#endif
    4258 Void TEncGOP::xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, ComponentID comp )
     4308Void TEncGOP::xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height, Int width, BitDepths& bitDepth, ComponentID comp )
    42594309{
    42604310  Int height2, width2;
     
    42644314  Int length = m_cgsFilterLength;
    42654315  Int shift  = bitDepth.recon[CHANNEL_TYPE_LUMA] - bitDepth.recon[CHANNEL_TYPE_CHROMA];
    4266   Int shift2 = 2*7+shift;
     4316  Int shift2 = 2*7 + shift;
    42674317  Int roundingOffset = (1 << (shift2 - 1));
    42684318  Int maxVal = (1<<(bitDepth.recon[toChannelType(comp)]-shift))-1;
    4269   height2 = (height1 * m_cgsFilterPhases) / m_iN;
    4270   width2  = (width1  * m_cgsFilterPhases) / m_iN;
     4319  height2 = (height * m_cgsFilterPhases) / m_iN;
     4320  width2  = (width  * m_cgsFilterPhases) / m_iN;
    42714321
    42724322  m_phaseFilter = comp == COMPONENT_Y ? m_phaseFilterLuma : m_phaseFilterChroma;
    42734323
    42744324  // horizontal filtering
    4275   for( Int j1 = 0; j1 < height1; j1++ )
     4325  for( Int j1 = 0; j1 < height; j1++ )
    42764326  {
    42774327    Int i0 = -m_iN;
     
    43024352  }
    43034353
    4304   for( Int k = height1; k < (height1 + (length>>1)); k++)
     4354  for( Int k = height; k < (height + (length>>1)); k++)
    43054355  {
    43064356    memcpy(m_temp[k], m_temp[k-1], (width2) * sizeof(Int));
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h

    r1432 r1433  
    292292  inline Short xClip( Short x, Int bitdepth );
    293293  Void xInitDs( const Int iWidth, const Int iHeight, const Bool allIntra, const Int posScalingFactorX);
    294   Void xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height1, Int width1, BitDepths& bitDepth, ComponentID comp );
     294  Void xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height, Int width, BitDepths& bitDepth, ComponentID comp );
    295295
    296296  Int  xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX);
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r1259 r1433  
    13791379    m_encRCSeq->initLCUPara();
    13801380  }
     1381#if U0132_TARGET_BITS_SATURATION
     1382  m_CpbSaturationEnabled = false;
     1383  m_cpbSize              = targetBitrate;
     1384  m_cpbState             = (UInt)(m_cpbSize*0.5f);
     1385  m_bufferingRate        = (Int)(targetBitrate / frameRate);
     1386#endif
    13811387
    13821388  delete[] bitsRatio;
     
    13961402}
    13971403
     1404#if U0132_TARGET_BITS_SATURATION
     1405Int  TEncRateCtrl::updateCpbState(Int actualBits)
     1406{
     1407  Int cpbState = 1;
     1408
     1409  m_cpbState -= actualBits;
     1410  if (m_cpbState < 0)
     1411  {
     1412    cpbState = -1;
     1413  }
     1414
     1415  m_cpbState += m_bufferingRate;
     1416  if (m_cpbState > m_cpbSize)
     1417  {
     1418    cpbState = 0;
     1419  }
     1420
     1421  return cpbState;
     1422}
     1423
     1424Void TEncRateCtrl::initHrdParam(const TComHRD* pcHrd, Int iFrameRate, Double fInitialCpbFullness)
     1425{
     1426  m_CpbSaturationEnabled = true;
     1427  m_cpbSize = (pcHrd->getCpbSizeValueMinus1(0, 0, 0) + 1) << (4 + pcHrd->getCpbSizeScale());
     1428  m_cpbState = (UInt)(m_cpbSize*fInitialCpbFullness);
     1429  m_bufferingRate = (UInt)(((pcHrd->getBitRateValueMinus1(0, 0, 0) + 1) << (6 + pcHrd->getBitRateScale())) / iFrameRate);
     1430  printf("\nHRD - [Initial CPB state %6d] [CPB Size %6d] [Buffering Rate %6d]\n", m_cpbState, m_cpbSize, m_bufferingRate);
     1431}
     1432#endif
     1433
    13981434Void TEncRateCtrl::destroyRCGOP()
    13991435{
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncRateCtrl.h

    r1259 r1433  
    265265  TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
    266266  Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
     267#if U0132_TARGET_BITS_SATURATION
     268  Void setBitLeft(Int bits)                               { m_bitsLeft = bits; }
     269#endif
    267270  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
    268271  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
     
    322325  TEncRCPic* getRCPic()          { assert ( m_encRCPic != NULL ); return m_encRCPic; }
    323326  list<TEncRCPic*>& getPicList() { return m_listRCPictures; }
     327#if U0132_TARGET_BITS_SATURATION
     328  Bool       getCpbSaturationEnabled()  { return m_CpbSaturationEnabled;  }
     329  UInt       getCpbState()              { return m_cpbState;       }
     330  UInt       getCpbSize()               { return m_cpbSize;        }
     331  UInt       getBufferingRate()         { return m_bufferingRate;  }
     332  Int        updateCpbState(Int actualBits);
     333  Void       initHrdParam(const TComHRD* pcHrd, Int iFrameRate, Double fInitialCpbFullness);
     334#endif
    324335
    325336private:
     
    329340  list<TEncRCPic*> m_listRCPictures;
    330341  Int        m_RCQP;
    331 };
    332 
     342#if U0132_TARGET_BITS_SATURATION
     343  Bool       m_CpbSaturationEnabled;    // Enable target bits saturation to avoid CPB overflow and underflow
     344  Int        m_cpbState;                // CPB State
     345  UInt       m_cpbSize;                 // CPB size
     346  UInt       m_bufferingRate;           // Buffering rate
    333347#endif
    334 
    335 
     348};
     349
     350#endif
     351
     352
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp

    r1406 r1433  
    228228  xInitVPS();
    229229
     230#if U0132_TARGET_BITS_SATURATION
     231  if (m_RCCpbSaturationEnabled)
     232  {
     233    m_cRateCtrl.initHrdParam(m_cSPS.getVuiParameters()->getHrdParameters(), m_iFrameRate, m_RCInitialCpbFullness);
     234  }
     235#endif
    230236  m_cRdCost.setCostMode(m_costMode);
    231237
     
    10021008    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
    10031009  }
     1010
     1011#if U0132_TARGET_BITS_SATURATION
     1012  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() || getCpbSaturationEnabled() )
     1013#else
    10041014  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
     1015#endif
    10051016  {
    10061017    xInitHrdParameters();
     
    10251036}
    10261037
     1038#if U0132_TARGET_BITS_SATURATION
     1039// calculate scale value of bitrate and initial delay
     1040Int calcScale(Int x)
     1041{
     1042  UInt iMask = 0xffffffff;
     1043  Int ScaleValue = 32;
     1044
     1045  while ((x&iMask) != 0)
     1046  {
     1047    ScaleValue--;
     1048    iMask = (iMask >> 1);
     1049  }
     1050
     1051  return ScaleValue;
     1052}
     1053#endif
    10271054Void TEncTop::xInitHrdParameters()
    10281055{
     
    10301057  Int  bitRate         = getTargetBitrate();
    10311058  Bool isRandomAccess  = getIntraPeriod() > 0;
    1032 
     1059# if U0132_TARGET_BITS_SATURATION
     1060  Int cpbSize          = getCpbSize();
     1061
     1062  if( !getVuiParametersPresentFlag() && !getCpbSaturationEnabled() )
     1063#else
    10331064  if( !getVuiParametersPresentFlag() )
     1065#endif
    10341066  {
    10351067    return;
     
    10751107  hrd->setNalHrdParametersPresentFlag( rateCnt );
    10761108  hrd->setVclHrdParametersPresentFlag( rateCnt );
    1077 
    10781109  hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams );
    10791110
     
    10901121  }
    10911122
     1123#if U0132_TARGET_BITS_SATURATION
     1124  if (calcScale(bitRate) <= 6)
     1125  {
     1126    hrd->setBitRateScale(0);
     1127  }
     1128  else
     1129  {
     1130    hrd->setBitRateScale(calcScale(bitRate) - 6);
     1131  }
     1132
     1133  if (calcScale(cpbSize) <= 4)
     1134  {
     1135    hrd->setCpbSizeScale(0);
     1136  }
     1137  else
     1138  {
     1139    hrd->setCpbSizeScale(calcScale(cpbSize) - 4);
     1140  }
     1141#else
    10921142  hrd->setBitRateScale( 4 );                                       // in units of 2^( 6 + 4 ) = 1,024 bps
    10931143  hrd->setCpbSizeScale( 6 );                                       // in units of 2^( 4 + 6 ) = 1,024 bit
     1144#endif
     1145
    10941146  hrd->setDuCpbSizeScale( 6 );                                     // in units of 2^( 4 + 6 ) = 1,024 bit
    10951147
     
    11231175    bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) );      // bitRate is in bits, so it needs to be scaled down
    11241176    // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale )
     1177#if U0132_TARGET_BITS_SATURATION
     1178    cpbSizeValue = cpbSize / (1 << (4 + hrd->getCpbSizeScale()) );      // using bitRate results in 1 second CPB size
     1179#else
    11251180    cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) );      // using bitRate results in 1 second CPB size
     1181#endif
     1182
    11261183
    11271184    // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know
Note: See TracChangeset for help on using the changeset viewer.