diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp index 4e033dd0aed2530a6175e66bcd9b7ae2fb3ccb3d..1ceffd2c2fe46f8eda7f06d5e842a1789dfd7b9a 100644 --- a/source/App/EncoderApp/EncApp.cpp +++ b/source/App/EncoderApp/EncApp.cpp @@ -1227,11 +1227,9 @@ void EncApp::xInitLibCfg() m_cEncLib.setUseLCUSeparateModel ( m_RCUseLCUSeparateModel ); m_cEncLib.setInitialQP ( m_RCInitialQP ); m_cEncLib.setForceIntraQP ( m_RCForceIntraQP ); -#if U0132_TARGET_BITS_SATURATION m_cEncLib.setCpbSaturationEnabled ( m_RCCpbSaturationEnabled ); m_cEncLib.setCpbSize ( m_RCCpbSize ); m_cEncLib.setInitialCpbFullness ( m_RCInitialCpbFullness ); -#endif m_cEncLib.setCostMode ( m_costMode ); m_cEncLib.setTSRCdisableLL ( m_TSRCdisableLL ); m_cEncLib.setUseRecalculateQPAccordingToLambda ( m_recalculateQPAccordingToLambda ); diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp index 40aac478dd5b475eb77cda0cbc72eb5c4d8438b1..9564ee41a67f57d9d39f32f5cd622f70d96da040 100644 --- a/source/App/EncoderApp/EncAppCfg.cpp +++ b/source/App/EncoderApp/EncAppCfg.cpp @@ -264,14 +264,12 @@ strToLevel[] = {"15.5", Level::LEVEL15_5}, }; -#if U0132_TARGET_BITS_SATURATION uint32_t g_uiMaxCpbSize[2][28] = { // LEVEL1, LEVEL2, LEVEL2_1, LEVEL3, LEVEL3_1, LEVEL4, LEVEL4_1, LEVEL5, LEVEL5_1, LEVEL5_2, LEVEL6, LEVEL6_1, LEVEL6_2 LEVEL6_3 { 0, 0, 0, 0, 350000, 0, 0, 0, 1500000, 3000000, 0, 0, 6000000, 10000000, 0, 0, 12000000, 20000000, 0, 0, 25000000, 40000000, 60000000, 0, 80000000, 120000000, 240000000, 240000000 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30000000, 50000000, 0, 0, 100000000, 160000000, 240000000, 0, 240000000, 480000000, 800000000, 1600000000 } }; -#endif static const struct MapStrToCostMode { @@ -1277,11 +1275,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] ) ( "RCLCUSeparateModel", m_RCUseLCUSeparateModel, true, "Rate control: use CTU level separate R-lambda model" ) ( "InitialQP", m_RCInitialQP, 0, "Rate control: initial QP" ) ( "RCForceIntraQP", m_RCForceIntraQP, false, "Rate control: force intra QP to be equal to initial QP" ) -#if U0132_TARGET_BITS_SATURATION ( "RCCpbSaturation", m_RCCpbSaturationEnabled, false, "Rate control: enable target bits saturation to avoid CPB overflow and underflow" ) ( "RCCpbSize", m_RCCpbSize, 0u, "Rate control: CPB size" ) ( "RCInitialCpbFullness", m_RCInitialCpbFullness, 0.9, "Rate control: initial CPB fullness" ) -#endif ("CostMode", m_costMode, COST_STANDARD_LOSSY, "Use alternative cost functions: choose between 'lossy', 'sequence_level_lossless', 'lossless' (which forces QP to " MACRO_TO_STRING(LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP) ") and 'mixed_lossless_lossy' (which used QP'=" MACRO_TO_STRING(LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME) " for pre-estimates of transquant-bypass blocks).") ("TSRCdisableLL", m_TSRCdisableLL, true, "Disable TSRC for lossless coding" ) ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case") @@ -4508,21 +4504,17 @@ bool EncAppCfg::xCheckParameter() } } xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" ); -#if U0132_TARGET_BITS_SATURATION if ((m_RCCpbSaturationEnabled) && (m_level!=Level::NONE) && (m_profile!=Profile::NONE)) { uint32_t uiLevelIdx = (m_level / 16) * 4 + (uint32_t)((m_level % 16) / 3); xConfirmPara(m_RCCpbSize > g_uiMaxCpbSize[m_levelTier][uiLevelIdx], "RCCpbSize should be smaller than or equal to Max CPB size according to tier and level"); xConfirmPara(m_RCInitialCpbFullness > 1, "RCInitialCpbFullness should be smaller than or equal to 1"); } -#endif } -#if U0132_TARGET_BITS_SATURATION else { xConfirmPara( m_RCCpbSaturationEnabled != 0, "Target bits saturation cannot be processed without Rate control" ); } -#endif if (m_framePackingSEIEnabled) { @@ -4914,14 +4906,12 @@ void EncAppCfg::xPrintParameter() msg( DETAILS, "UseLCUSeparateModel : %d\n", m_RCUseLCUSeparateModel ); msg( DETAILS, "InitialQP : %d\n", m_RCInitialQP ); msg( DETAILS, "ForceIntraQP : %d\n", m_RCForceIntraQP ); -#if U0132_TARGET_BITS_SATURATION msg( DETAILS, "CpbSaturation : %d\n", m_RCCpbSaturationEnabled ); if (m_RCCpbSaturationEnabled) { msg( DETAILS, "CpbSize : %d\n", m_RCCpbSize); msg( DETAILS, "InitalCpbFullness : %.2f\n", m_RCInitialCpbFullness); } -#endif } #if GDR_ENABLED diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h index 920bf6fae356433b7c5edfd0f3bdf84531d7d0df..a9692419ac4fa5092d815e1901746d7946e6e4d1 100644 --- a/source/App/EncoderApp/EncAppCfg.h +++ b/source/App/EncoderApp/EncAppCfg.h @@ -817,11 +817,9 @@ protected: bool m_RCUseLCUSeparateModel; ///< use separate R-lambda model at LCU level NOTE: code-tidy - rename to m_RCUseCtuSeparateModel int m_RCInitialQP; ///< inital QP for rate control bool m_RCForceIntraQP; ///< force all intra picture to use initial QP or not -#if U0132_TARGET_BITS_SATURATION bool m_RCCpbSaturationEnabled; ///< enable target bits saturation to avoid CPB overflow and underflow uint32_t m_RCCpbSize; ///< CPB size double m_RCInitialCpbFullness; ///< initial CPB fullness -#endif ScalingListMode m_useScalingListId; ///< using quantization matrix std::string m_scalingListFileName; ///< quantization matrix file name bool m_disableScalingMatrixForLfnstBlks; diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 8a1630d88c59312bc99cc0def4243f4d94254f8c..3e10c890b2864b85aabcec04ccbc7b1cc878f6c6 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -205,10 +205,7 @@ typedef std::pair<int, int> TrCost; #define RDOQ_CHROMA_LAMBDA 1 ///< F386: weighting of chroma for RDOQ -#define U0132_TARGET_BITS_SATURATION 1 ///< Rate control with target bits saturation method -#ifdef U0132_TARGET_BITS_SATURATION #define V0078_ADAPTIVE_LOWER_BOUND 1 ///< Target bits saturation with adaptive lower bound -#endif #define W0038_DB_OPT 1 ///< adaptive DB parameter selection, LoopFilterOffsetInPPS and LoopFilterDisable are set to 0 and DeblockingFilterMetric=2; #define W0038_CQP_ADJ 1 ///< chroma QP adjustment based on TL, CQPTLAdjustEnabled is set to 1; diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h index ac32af0760122e6aecf5ccabfc1860bb60f59caf..4757f0d6431ff1e4921178126429bd72853d1aec 100644 --- a/source/Lib/EncoderLib/EncCfg.h +++ b/source/Lib/EncoderLib/EncCfg.h @@ -877,11 +877,9 @@ protected: bool m_RCUseLCUSeparateModel; int m_RCInitialQP; bool m_RCForceIntraQP; -#if U0132_TARGET_BITS_SATURATION bool m_RCCpbSaturationEnabled; uint32_t m_RCCpbSize; double m_RCInitialCpbFullness; -#endif CostMode m_costMode; ///< The cost function to use, primarily when considering lossless coding. bool m_TSRCdisableLL; ///< Disable TSRC for lossless @@ -2395,14 +2393,12 @@ public: void setInitialQP ( int QP ) { m_RCInitialQP = QP; } bool getForceIntraQP () { return m_RCForceIntraQP; } void setForceIntraQP ( bool b ) { m_RCForceIntraQP = b; } -#if U0132_TARGET_BITS_SATURATION bool getCpbSaturationEnabled() { return m_RCCpbSaturationEnabled;} void setCpbSaturationEnabled( bool b ) { m_RCCpbSaturationEnabled = b; } uint32_t getCpbSize () { return m_RCCpbSize;} void setCpbSize ( uint32_t ui ) { m_RCCpbSize = ui; } double getInitialCpbFullness () { return m_RCInitialCpbFullness; } void setInitialCpbFullness (double f) { m_RCInitialCpbFullness = f; } -#endif CostMode getCostMode( ) const { return m_costMode; } void setCostMode(CostMode m ) { m_costMode = m; } bool getTSRCdisableLL () { return m_TSRCdisableLL; } diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index 8bafa1fff47454316284cc14a1ce9af42f2d37f4..a69dd7d962024cbb5c853f48654c58b007a58a2d 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -1939,7 +1939,6 @@ void EncGOP::xPicInitRateControl(int &estimatedBits, int gopId, double &lambda, m_pcRateCtrl->initRCPic( frameLevel ); estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); -#if U0132_TARGET_BITS_SATURATION if (m_pcRateCtrl->getCpbSaturationEnabled() && frameLevel != 0) { int estimatedCpbFullness = m_pcRateCtrl->getCpbState() + m_pcRateCtrl->getBufferingRate(); @@ -1966,7 +1965,6 @@ void EncGOP::xPicInitRateControl(int &estimatedBits, int gopId, double &lambda, m_pcRateCtrl->getRCPic()->setTargetBits(estimatedBits); } -#endif int sliceQP = m_pcCfg->getInitialQP(); if ( ( slice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified @@ -1988,7 +1986,6 @@ void EncGOP::xPicInitRateControl(int &estimatedBits, int gopId, double &lambda, int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); -#if U0132_TARGET_BITS_SATURATION if (m_pcRateCtrl->getCpbSaturationEnabled() ) { int estimatedCpbFullness = m_pcRateCtrl->getCpbState() + m_pcRateCtrl->getBufferingRate(); @@ -2013,7 +2010,6 @@ void EncGOP::xPicInitRateControl(int &estimatedBits, int gopId, double &lambda, } #endif } -#endif if ( bits < 200 ) { @@ -4177,13 +4173,11 @@ void EncGOP::compressGOP(int pocLast, int numPicRcvd, PicList &rcListPic, std::l { m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); } - #if U0132_TARGET_BITS_SATURATION if (m_pcRateCtrl->getCpbSaturationEnabled()) { m_pcRateCtrl->updateCpbState(actualTotalBits); msg( NOTICE, " [CPB %6d bits]", m_pcRateCtrl->getCpbState() ); } - #endif } xCreateFrameFieldInfoSEI( leadingSeiMessages, pcSlice, isField ); xCreatePictureTimingSEI( m_pcCfg->getEfficientFieldIRAPEnabled() ? effFieldIRAPMap.GetIRAPGOPid() : 0, leadingSeiMessages, nestedSeiMessages, duInfoSeiMessages, pcSlice, isField, duData ); diff --git a/source/Lib/EncoderLib/EncHRD.cpp b/source/Lib/EncoderLib/EncHRD.cpp index b7f10092e18a5291560ba9e095686e03bdfdbdd5..a13bc5158b450ff371c2beb00bbc3e697ac9d333 100644 --- a/source/Lib/EncoderLib/EncHRD.cpp +++ b/source/Lib/EncoderLib/EncHRD.cpp @@ -33,7 +33,6 @@ #include "EncHRD.h" -#if U0132_TARGET_BITS_SATURATION // calculate scale value of bitrate and initial delay int EncHRD::xCalcScale(int x) @@ -53,19 +52,14 @@ int EncHRD::xCalcScale(int x) return scaleValue; } -#endif void EncHRD::initHRDParameters(EncCfg* encCfg) { bool useSubCpbParams = encCfg->getNoPicPartitionFlag() == false; int bitRate = encCfg->getTargetBitrate(); -# if U0132_TARGET_BITS_SATURATION int cpbSize = encCfg->getCpbSize(); CHECK(!(cpbSize != 0), "Unspecified error"); // CPB size may not be equal to zero. ToDo: have a better default and check for level constraints if (!encCfg->getHrdParametersPresentFlag() && !encCfg->getCpbSaturationEnabled()) -#else - if (!encCfg->getHrdParametersPresentFlag()) -#endif { return; } @@ -118,7 +112,6 @@ void EncHRD::initHRDParameters(EncCfg* encCfg) m_generalHrdParams.setTickDivisorMinus2(100 - 2); } -#if U0132_TARGET_BITS_SATURATION if (xCalcScale(bitRate) <= 6) { m_generalHrdParams.setBitRateScale(0); @@ -136,10 +129,6 @@ void EncHRD::initHRDParameters(EncCfg* encCfg) { m_generalHrdParams.setCpbSizeScale(xCalcScale(cpbSize) - 4); } -#else - m_generalHrdParams.setBitRateScale(4); // in units of 2^( 6 + 4 ) = 1,024 bps - m_generalHrdParams.setCpbSizeScale(6); // in units of 2^( 4 + 6 ) = 1,024 bit -#endif m_generalHrdParams.setCpbSizeDuScale(6); // in units of 2^( 4 + 6 ) = 1,024 bit m_generalHrdParams.setHrdCpbCntMinus1(0); @@ -163,11 +152,7 @@ void EncHRD::initHRDParameters(EncCfg* encCfg) // BitRate[ i ] = ( bit_rate_value_minus1[ i ] + 1 ) * 2^( 6 + bit_rate_scale ) bitrateValue = bitRate / (1 << (6 + m_generalHrdParams.getBitRateScale())); // bitRate is in bits, so it needs to be scaled down // CpbSize[ i ] = ( cpb_size_value_minus1[ i ] + 1 ) * 2^( 4 + cpb_size_scale ) -#if U0132_TARGET_BITS_SATURATION cpbSizeValue = cpbSize / (1 << (4 + m_generalHrdParams.getCpbSizeScale())); // using bitRate results in 1 second CPB size -#else - cpbSizeValue = bitRate / (1 << (4 + m_generalHrdParams.getCpbSizeScale())); // using bitRate results in 1 second CPB size -#endif // DU CPB size could be smaller (i.e. bitrateValue / number of DUs), but we don't know diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp index 85014b613c7013757c5523174d74a88c16704194..fe5544555b0e3a8f04fc2d7bbb263a21d2141574 100644 --- a/source/Lib/EncoderLib/EncLib.cpp +++ b/source/Lib/EncoderLib/EncLib.cpp @@ -176,12 +176,10 @@ void EncLib::init(AUWriterIf *auWriterIf) sps0.setLongTermRefsPresent(true); } -#if U0132_TARGET_BITS_SATURATION if (m_RCCpbSaturationEnabled) { m_cRateCtrl.initHrdParam(sps0.getGeneralHrdParameters(), sps0.getOlsHrdParameters(), m_iFrameRate, m_RCInitialCpbFullness); } -#endif m_cRdCost.setCostMode ( m_costMode ); // initialize PPS @@ -1391,11 +1389,7 @@ void EncLib::xInitSPS( SPS& sps ) sps.setChromaQpMappingTableFromParams(m_chromaQpMappingTableParams, sps.getQpBDOffset(CHANNEL_TYPE_CHROMA)); sps.derivedChromaQPMappingTables(); -#if U0132_TARGET_BITS_SATURATION if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() || getCpbSaturationEnabled() ) -#else - if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() ) -#endif { xInitHrdParameters(sps); } diff --git a/source/Lib/EncoderLib/RateCtrl.cpp b/source/Lib/EncoderLib/RateCtrl.cpp index 8093c15347cd09bd1a6aef1d9e8699f0739f8320..78f76f1819d63a3e36570251cdc6c4d925827e04 100644 --- a/source/Lib/EncoderLib/RateCtrl.cpp +++ b/source/Lib/EncoderLib/RateCtrl.cpp @@ -1897,12 +1897,10 @@ void RateCtrl::init(int totalFrames, int targetBitrate, int frameRate, int GOPSi { m_encRCSeq->initLCUPara(); } -#if U0132_TARGET_BITS_SATURATION m_CpbSaturationEnabled = false; m_cpbSize = targetBitrate; m_cpbState = (uint32_t)(m_cpbSize*0.5f); m_bufferingRate = (int)(targetBitrate / frameRate); -#endif delete[] bitsRatio; delete[] GOPID2Level; @@ -1921,7 +1919,6 @@ void RateCtrl::initRCGOP( int numberOfPictures ) m_encRCGOP->create(m_encRCSeq, numberOfPictures, useAdaptiveBitsRatio); } -#if U0132_TARGET_BITS_SATURATION int RateCtrl::updateCpbState(int actualBits) { int cpbState = 1; @@ -1949,7 +1946,6 @@ void RateCtrl::initHrdParam(const GeneralHrdParams* generalHrd, const OlsHrdPara m_bufferingRate = (uint32_t)(((olsHrd->getBitRateValueMinus1(0, 0) + 1) << (6 + generalHrd->getBitRateScale())) / iFrameRate); msg(NOTICE, "\nHRD - [Initial CPB state %6d] [CPB Size %6d] [Buffering Rate %6d]\n", m_cpbState, m_cpbSize, m_bufferingRate); } -#endif void RateCtrl::destroyRCGOP() { diff --git a/source/Lib/EncoderLib/RateCtrl.h b/source/Lib/EncoderLib/RateCtrl.h index fcf5d8646e98e90dc2ca239ec4d6878ec9f0c789..a357044618418cab75dbaf22ca8638f7c8053113 100644 --- a/source/Lib/EncoderLib/RateCtrl.h +++ b/source/Lib/EncoderLib/RateCtrl.h @@ -282,9 +282,7 @@ public: TRCLCU* getLCU() { return m_LCUs; } TRCLCU& getLCU( int LCUIdx ) { return m_LCUs[LCUIdx]; } int getPicActualHeaderBits() { return m_picActualHeaderBits; } -#if U0132_TARGET_BITS_SATURATION void setBitLeft(int bits) { m_bitsLeft = bits; } -#endif void setTargetBits( int bits ) { m_targetBits = bits; m_bitsLeft = bits;} void setTotalIntraCost(double cost) { m_totalCostIntra = cost; } void getLCUInitTargetBits(); @@ -361,14 +359,12 @@ public: return m_encRCPic; } std::list<EncRCPic *> &getPicList() { return m_listRCPictures; } -#if U0132_TARGET_BITS_SATURATION bool getCpbSaturationEnabled() { return m_CpbSaturationEnabled; } uint32_t getCpbState() { return m_cpbState; } uint32_t getCpbSize() { return m_cpbSize; } uint32_t getBufferingRate() { return m_bufferingRate; } int updateCpbState(int actualBits); void initHrdParam(const GeneralHrdParams* generalHrd, const OlsHrdParams* olsHrd, int iFrameRate, double fInitialCpbFullness); -#endif private: EncRCSeq* m_encRCSeq; @@ -376,12 +372,10 @@ private: EncRCPic* m_encRCPic; std::list<EncRCPic *> m_listRCPictures; int m_RCQP; -#if U0132_TARGET_BITS_SATURATION bool m_CpbSaturationEnabled; // Enable target bits saturation to avoid CPB overflow and underflow int m_cpbState; // CPB State uint32_t m_cpbSize; // CPB size uint32_t m_bufferingRate; // Buffering rate -#endif }; #endif