Changeset 1433 in SHVCSoftware for branches/SHM-dev/source/Lib
- Timestamp:
- 11 Aug 2015, 20:22:28 (10 years ago)
- Location:
- branches/SHM-dev/source/Lib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
r1407 r1433 200 200 #endif 201 201 202 #define U0132_TARGET_BITS_SATURATION 1 ///< Rate control with target bits saturation method 202 203 203 204 // ==================================================================================================================== -
branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
r1432 r1433 3575 3575 READ_UVLC( uiChromaInputBitDepthM8 , "cm_input_chroma_bit_depth_minus8" ); 3576 3576 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" ); 3578 3578 READ_CODE( 2, uiResQaunBit, "cm_res_quant_bit" ); 3579 3579 … … 3681 3681 for( Int nVertexIdx = 0; nVertexIdx < 4; nVertexIdx++ ) 3682 3682 { 3683 pc3DAsymLUT->setCuboidVertexResTree( yIdx + y, uIdx + 3683 pc3DAsymLUT->setCuboidVertexResTree( yIdx + y, uIdx + u, vIdx + v, nVertexIdx, 0, 0, 0 ); 3684 3684 #if R0164_CGS_LUT_BUGFIX_CHECK 3685 3685 pc3DAsymLUT->xSetFilled( yIdx + y, uIdx + u, vIdx + v ); -
branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
r1432 r1433 339 339 Int m_RCInitialQP; 340 340 Bool m_RCForceIntraQP; 341 #if U0132_TARGET_BITS_SATURATION 342 Bool m_RCCpbSaturationEnabled; 343 UInt m_RCCpbSize; 344 Double m_RCInitialCpbFullness; 345 #endif 341 346 Bool m_TransquantBypassEnableFlag; ///< transquant_bypass_enable_flag setting in PPS. 342 347 Bool m_CUTransquantBypassFlagForce; ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true. … … 936 941 Bool getForceIntraQP () { return m_RCForceIntraQP; } 937 942 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 938 951 Bool getTransquantBypassEnableFlag() { return m_TransquantBypassEnableFlag; } 939 952 Void setTransquantBypassEnableFlag(Bool flag) { m_TransquantBypassEnableFlag = flag; } -
branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
r1432 r1433 2432 2432 estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); 2433 2433 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 2434 2456 Int sliceQP = m_pcCfg->getInitialQP(); 2435 2457 #if SVC_EXTENSION … … 2455 2477 Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); 2456 2478 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 2457 2500 if ( bits < 200 ) 2458 2501 { … … 2846 2889 m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); 2847 2890 } 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 2848 2898 } 2849 2899 … … 4256 4306 #endif 4257 4307 #endif 4258 Void TEncGOP::xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height 1, Int width1, BitDepths& bitDepth, ComponentID comp )4308 Void TEncGOP::xFilterImg( Pel *src, Int iSrcStride, Pel *dst, Int iDstStride, Int height, Int width, BitDepths& bitDepth, ComponentID comp ) 4259 4309 { 4260 4310 Int height2, width2; … … 4264 4314 Int length = m_cgsFilterLength; 4265 4315 Int shift = bitDepth.recon[CHANNEL_TYPE_LUMA] - bitDepth.recon[CHANNEL_TYPE_CHROMA]; 4266 Int shift2 = 2*7 +shift;4316 Int shift2 = 2*7 + shift; 4267 4317 Int roundingOffset = (1 << (shift2 - 1)); 4268 4318 Int maxVal = (1<<(bitDepth.recon[toChannelType(comp)]-shift))-1; 4269 height2 = (height 1* m_cgsFilterPhases) / m_iN;4270 width2 = (width 1* m_cgsFilterPhases) / m_iN;4319 height2 = (height * m_cgsFilterPhases) / m_iN; 4320 width2 = (width * m_cgsFilterPhases) / m_iN; 4271 4321 4272 4322 m_phaseFilter = comp == COMPONENT_Y ? m_phaseFilterLuma : m_phaseFilterChroma; 4273 4323 4274 4324 // horizontal filtering 4275 for( Int j1 = 0; j1 < height 1; j1++ )4325 for( Int j1 = 0; j1 < height; j1++ ) 4276 4326 { 4277 4327 Int i0 = -m_iN; … … 4302 4352 } 4303 4353 4304 for( Int k = height 1; k < (height1+ (length>>1)); k++)4354 for( Int k = height; k < (height + (length>>1)); k++) 4305 4355 { 4306 4356 memcpy(m_temp[k], m_temp[k-1], (width2) * sizeof(Int)); -
branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.h
r1432 r1433 292 292 inline Short xClip( Short x, Int bitdepth ); 293 293 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 height 1, 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 ); 295 295 296 296 Int xCreate2DArray(Int ***array2D, Int dim0, Int dim1, Int iPadY, Int iPadX); -
branches/SHM-dev/source/Lib/TLibEncoder/TEncRateCtrl.cpp
r1259 r1433 1379 1379 m_encRCSeq->initLCUPara(); 1380 1380 } 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 1381 1387 1382 1388 delete[] bitsRatio; … … 1396 1402 } 1397 1403 1404 #if U0132_TARGET_BITS_SATURATION 1405 Int 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 1424 Void 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 1398 1434 Void TEncRateCtrl::destroyRCGOP() 1399 1435 { -
branches/SHM-dev/source/Lib/TLibEncoder/TEncRateCtrl.h
r1259 r1433 265 265 TRCLCU& getLCU( Int LCUIdx ) { return m_LCUs[LCUIdx]; } 266 266 Int getPicActualHeaderBits() { return m_picActualHeaderBits; } 267 #if U0132_TARGET_BITS_SATURATION 268 Void setBitLeft(Int bits) { m_bitsLeft = bits; } 269 #endif 267 270 Void setTargetBits( Int bits ) { m_targetBits = bits; m_bitsLeft = bits;} 268 271 Void setTotalIntraCost(Double cost) { m_totalCostIntra = cost; } … … 322 325 TEncRCPic* getRCPic() { assert ( m_encRCPic != NULL ); return m_encRCPic; } 323 326 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 324 335 325 336 private: … … 329 340 list<TEncRCPic*> m_listRCPictures; 330 341 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 333 347 #endif 334 335 348 }; 349 350 #endif 351 352 -
branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp
r1406 r1433 228 228 xInitVPS(); 229 229 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 230 236 m_cRdCost.setCostMode(m_costMode); 231 237 … … 1002 1008 m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0); 1003 1009 } 1010 1011 #if U0132_TARGET_BITS_SATURATION 1012 if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() || getCpbSaturationEnabled() ) 1013 #else 1004 1014 if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) 1015 #endif 1005 1016 { 1006 1017 xInitHrdParameters(); … … 1025 1036 } 1026 1037 1038 #if U0132_TARGET_BITS_SATURATION 1039 // calculate scale value of bitrate and initial delay 1040 Int 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 1027 1054 Void TEncTop::xInitHrdParameters() 1028 1055 { … … 1030 1057 Int bitRate = getTargetBitrate(); 1031 1058 Bool isRandomAccess = getIntraPeriod() > 0; 1032 1059 # if U0132_TARGET_BITS_SATURATION 1060 Int cpbSize = getCpbSize(); 1061 1062 if( !getVuiParametersPresentFlag() && !getCpbSaturationEnabled() ) 1063 #else 1033 1064 if( !getVuiParametersPresentFlag() ) 1065 #endif 1034 1066 { 1035 1067 return; … … 1075 1107 hrd->setNalHrdParametersPresentFlag( rateCnt ); 1076 1108 hrd->setVclHrdParametersPresentFlag( rateCnt ); 1077 1078 1109 hrd->setSubPicCpbParamsPresentFlag( useSubCpbParams ); 1079 1110 … … 1090 1121 } 1091 1122 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 1092 1142 hrd->setBitRateScale( 4 ); // in units of 2^( 6 + 4 ) = 1,024 bps 1093 1143 hrd->setCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit 1144 #endif 1145 1094 1146 hrd->setDuCpbSizeScale( 6 ); // in units of 2^( 4 + 6 ) = 1,024 bit 1095 1147 … … 1123 1175 bitrateValue = bitRate / (1 << (6 + hrd->getBitRateScale()) ); // bitRate is in bits, so it needs to be scaled down 1124 1176 // 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 1125 1180 cpbSizeValue = bitRate / (1 << (4 + hrd->getCpbSizeScale()) ); // using bitRate results in 1 second CPB size 1181 #endif 1182 1126 1183 1127 1184 // 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.