diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp index aae808bb01d3aa5513d8a4484eadb7130771cabb..b978e839bffe863008234f5fb7edaf131fd1d0b3 100644 --- a/source/App/EncoderApp/EncApp.cpp +++ b/source/App/EncoderApp/EncApp.cpp @@ -1308,18 +1308,18 @@ void EncApp::xInitLibCfg( int layerIdx ) m_cEncLib.setRprRASLtoolSwitch ( m_rprRASLtoolSwitch ); m_cEncLib.setDepQuantEnabledFlag ( m_depQuantEnabledFlag); m_cEncLib.setSignDataHidingEnabledFlag ( m_signDataHidingEnabledFlag); - m_cEncLib.setUseRateCtrl ( m_RCEnableRateControl ); - if (m_RCEnableRateControl) - { - m_cEncLib.setTargetBitrate(m_RCTargetBitrate); - m_cEncLib.setKeepHierBit(m_RCKeepHierarchicalBit); - m_cEncLib.setLCULevelRC(m_RCLCULevelRC); - m_cEncLib.setUseLCUSeparateModel(m_RCUseLCUSeparateModel); - m_cEncLib.setInitialQP(m_RCInitialQP); - m_cEncLib.setForceIntraQP(m_RCForceIntraQP); + m_cEncLib.setUseRateCtrl(m_rcEnableRateControl); + if (m_rcEnableRateControl) + { + m_cEncLib.setTargetBitrate(m_rcTargetBitrate); + m_cEncLib.setKeepHierBit(m_rcKeepHierarchicalBit); + m_cEncLib.setLCULevelRC(m_rcCtuLevelRateControl); + m_cEncLib.setUseLCUSeparateModel(m_rcUseCtuSeparateModel); + m_cEncLib.setInitialQP(m_rcInitialQp); + m_cEncLib.setForceIntraQP(m_rcForceIntraQp); m_cEncLib.setCpbSaturationEnabled(m_rcCpbSaturationEnabled); - m_cEncLib.setCpbSize(m_RCCpbSize); - m_cEncLib.setInitialCpbFullness(m_RCInitialCpbFullness); + m_cEncLib.setCpbSize(m_rcCpbSize); + m_cEncLib.setInitialCpbFullness(m_rcInitialCpbFullness); } m_cEncLib.setCostMode ( m_costMode ); m_cEncLib.setTSRCdisableLL ( m_TSRCdisableLL ); diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp index e60d2f7ccea37ef397f665c2719e99df787c13ed..7f376450f21897a9a5ec2a3fd7324dfc73c57cd2 100644 --- a/source/App/EncoderApp/EncAppCfg.cpp +++ b/source/App/EncoderApp/EncAppCfg.cpp @@ -1304,16 +1304,16 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] ) ("ECU", m_bUseEarlyCU, false, "Early CU setting") ("FDM", m_useFastDecisionForMerge, true, "Fast decision for Merge RD Cost") ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting") - ( "RateControl", m_RCEnableRateControl, false, "Rate control: enable rate control" ) - ( "TargetBitrate", m_RCTargetBitrate, 0, "Rate control: target bit-rate" ) - ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, 0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" ) - ( "LCULevelRateControl", m_RCLCULevelRC, true, "Rate control: true: CTU level RC; false: picture level RC" ) - ( "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" ) + ( "RateControl", m_rcEnableRateControl, false, "Rate control: enable rate control" ) + ( "TargetBitrate", m_rcTargetBitrate, 0, "Rate control: target bit-rate" ) + ( "KeepHierarchicalBit", m_rcKeepHierarchicalBit, 0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" ) + ( "LCULevelRateControl", m_rcCtuLevelRateControl, true, "Rate control: true: CTU level RC; false: picture level RC" ) + ( "RCLCUSeparateModel", m_rcUseCtuSeparateModel, 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" ) ( "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" ) + ( "RCCpbSize", m_rcCpbSize, 0u, "Rate control: CPB size" ) + ( "RCInitialCpbFullness", m_rcInitialCpbFullness, 0.9, "Rate control: initial CPB fullness" ) ("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") @@ -3931,7 +3931,8 @@ bool EncAppCfg::xCheckParameter() m_pictureTimingSEIEnabled = false; } - xConfirmPara( m_bufferingPeriodSEIEnabled == true && m_RCCpbSize == 0, "RCCpbSize must be greater than zero, when buffering period SEI is enabled" ); + xConfirmPara(m_bufferingPeriodSEIEnabled && m_rcCpbSize == 0, + "RCCpbSize must be greater than zero, when buffering period SEI is enabled"); xConfirmPara (m_log2MaxTransformSkipBlockSize < 2, "Transform Skip Log2 Max Size must be at least 2 (4x4)"); @@ -3962,7 +3963,8 @@ bool EncAppCfg::xCheckParameter() #endif #if SHARP_LUMA_DELTA_QP xConfirmPara( m_lumaLevelToDeltaQPMapping.mode && m_uiDeltaQpRD > 0, "Luma-level-based Delta QP cannot be used together with slice level multiple-QP optimization\n" ); - xConfirmPara( m_lumaLevelToDeltaQPMapping.mode && m_RCEnableRateControl, "Luma-level-based Delta QP cannot be used together with rate control\n" ); + xConfirmPara(m_lumaLevelToDeltaQPMapping.mode && m_rcEnableRateControl, + "Luma-level-based Delta QP cannot be used together with rate control\n"); #endif if (m_lumaLevelToDeltaQPMapping.mode && m_lmcsEnabled) { @@ -4932,22 +4934,23 @@ bool EncAppCfg::xCheckParameter() xConfirmPara( m_sariAspectRatioIdc < 0 || m_sariAspectRatioIdc > 255, "SEISARISampleAspectRatioIdc must be in the range of 0 to 255"); - if ( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { - if ( m_RCForceIntraQP ) + if (m_rcForceIntraQp) { - if ( m_RCInitialQP == 0 ) + if (m_rcInitialQp == 0) { msg( WARNING, "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" ); - m_RCForceIntraQP = false; + m_rcForceIntraQp = false; } } xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" ); 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"); + 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"); } } else @@ -5349,22 +5352,22 @@ void EncAppCfg::xPrintParameter() default: msg( DETAILS, "Cost function: : Unknown\n"); break; } - msg( DETAILS, "RateControl : %d\n", m_RCEnableRateControl ); + msg(DETAILS, "RateControl : %d\n", m_rcEnableRateControl); msg( DETAILS, "WeightedPredMethod : %d\n", int(m_weightedPredictionMethod)); - if(m_RCEnableRateControl) + if (m_rcEnableRateControl) { - msg( DETAILS, "TargetBitrate : %d\n", m_RCTargetBitrate ); - msg( DETAILS, "KeepHierarchicalBit : %d\n", m_RCKeepHierarchicalBit ); - msg( DETAILS, "LCULevelRC : %d\n", m_RCLCULevelRC ); - msg( DETAILS, "UseLCUSeparateModel : %d\n", m_RCUseLCUSeparateModel ); - msg( DETAILS, "InitialQP : %d\n", m_RCInitialQP ); - msg( DETAILS, "ForceIntraQP : %d\n", m_RCForceIntraQP ); + msg(DETAILS, "TargetBitrate : %d\n", m_rcTargetBitrate); + msg(DETAILS, "KeepHierarchicalBit : %d\n", m_rcKeepHierarchicalBit); + msg(DETAILS, "LCULevelRC : %d\n", m_rcCtuLevelRateControl); + msg(DETAILS, "UseLCUSeparateModel : %d\n", m_rcUseCtuSeparateModel); + msg(DETAILS, "InitialQP : %d\n", m_rcInitialQp); + msg(DETAILS, "ForceIntraQP : %d\n", m_rcForceIntraQp); msg(DETAILS, "CpbSaturation : %d\n", m_rcCpbSaturationEnabled); if (m_rcCpbSaturationEnabled) { - msg( DETAILS, "CpbSize : %d\n", m_RCCpbSize); - msg( DETAILS, "InitalCpbFullness : %.2f\n", m_RCInitialCpbFullness); + msg(DETAILS, "CpbSize : %d\n", m_rcCpbSize); + msg(DETAILS, "InitalCpbFullness : %.2f\n", m_rcInitialCpbFullness); } } diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h index 884645f42d3ff94b4bad2c52bc6fe92bdbe055f0..4b22b29485e7a0108f8e5bcaa0156e0e9ae22736 100644 --- a/source/App/EncoderApp/EncAppCfg.h +++ b/source/App/EncoderApp/EncAppCfg.h @@ -844,16 +844,19 @@ protected: int m_TMVPModeId; bool m_depQuantEnabledFlag; bool m_signDataHidingEnabledFlag; - bool m_RCEnableRateControl; ///< enable rate control or not - int m_RCTargetBitrate; ///< target bitrate when rate control is enabled - int m_RCKeepHierarchicalBit; ///< 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation - bool m_RCLCULevelRC; ///< true: LCU level rate control; false: picture level rate control NOTE: code-tidy - rename to m_RCCtuLevelRC - 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 - 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 + + // Rate control + bool m_rcEnableRateControl; // enable rate control or not + int m_rcTargetBitrate; // target bitrate when rate control is enabled + int m_rcKeepHierarchicalBit; // 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit + // allocation + bool m_rcCtuLevelRateControl; // true: CTU level rate control; false: picture level rate control + bool m_rcUseCtuSeparateModel; // use separate R-lambda model at CTU level + int m_rcInitialQp; // inital QP for rate control + bool m_rcForceIntraQp; // force all intra picture to use initial QP or not + 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 ScalingListMode m_useScalingListId; ///< using quantization matrix std::string m_scalingListFileName; ///< quantization matrix file name diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h index e338ac5ff3da842f259f37dd3b13a5c184082c66..0ae4e290d7c5c224a004917067315178cfd84c27 100644 --- a/source/Lib/EncoderLib/EncCfg.h +++ b/source/Lib/EncoderLib/EncCfg.h @@ -922,16 +922,16 @@ protected: uint32_t m_PPSMaxNumMergeCandMinusMaxNumGeoCandPlus1; bool m_DepQuantEnabledFlag; bool m_SignDataHidingEnabledFlag; - bool m_RCEnableRateControl; - int m_RCTargetBitrate; - int m_RCKeepHierarchicalBit; - bool m_RCLCULevelRC; - bool m_RCUseLCUSeparateModel; - int m_RCInitialQP; - bool m_RCForceIntraQP; + bool m_rcEnableRateControl = false; + int m_rcTargetBitrate; + int m_rcKeepHierarchicalBit; + bool m_rcCtuLevelRateControl; + bool m_rcUseCtuSeparateModel; + int m_rcInitialQp; + bool m_rcForceIntraQp; bool m_rcCpbSaturationEnabled = false; - uint32_t m_RCCpbSize; - double m_RCInitialCpbFullness; + uint32_t m_rcCpbSize; + double m_rcInitialCpbFullness; CostMode m_costMode; ///< The cost function to use, primarily when considering lossless coding. bool m_TSRCdisableLL; ///< Disable TSRC for lossless @@ -2580,27 +2580,28 @@ public: bool getDepQuantEnabledFlag() { return m_DepQuantEnabledFlag; } void setSignDataHidingEnabledFlag( bool b ) { m_SignDataHidingEnabledFlag = b; } bool getSignDataHidingEnabledFlag() { return m_SignDataHidingEnabledFlag; } - bool getUseRateCtrl () const { return m_RCEnableRateControl; } - void setUseRateCtrl ( bool b ) { m_RCEnableRateControl = b; } - int getTargetBitrate () { return m_RCTargetBitrate; } - void setTargetBitrate ( int bitrate ) { m_RCTargetBitrate = bitrate; } - int getKeepHierBit () { return m_RCKeepHierarchicalBit; } - void setKeepHierBit ( int i ) { m_RCKeepHierarchicalBit = i; } - bool getLCULevelRC () { return m_RCLCULevelRC; } - void setLCULevelRC ( bool b ) { m_RCLCULevelRC = b; } - bool getUseLCUSeparateModel () { return m_RCUseLCUSeparateModel; } - void setUseLCUSeparateModel ( bool b ) { m_RCUseLCUSeparateModel = b; } - int getInitialQP () { return m_RCInitialQP; } - void setInitialQP ( int QP ) { m_RCInitialQP = QP; } - bool getForceIntraQP () { return m_RCForceIntraQP; } - void setForceIntraQP ( bool b ) { m_RCForceIntraQP = b; } + + bool getUseRateCtrl() const { return m_rcEnableRateControl; } + void setUseRateCtrl(bool b) { m_rcEnableRateControl = b; } + int getTargetBitrate() const { return m_rcTargetBitrate; } + void setTargetBitrate(int bitrate) { m_rcTargetBitrate = bitrate; } + int getKeepHierBit() const { return m_rcKeepHierarchicalBit; } + void setKeepHierBit(int i) { m_rcKeepHierarchicalBit = i; } + bool getLCULevelRC() const { return m_rcCtuLevelRateControl; } + void setLCULevelRC(bool b) { m_rcCtuLevelRateControl = b; } + bool getUseLCUSeparateModel() const { return m_rcUseCtuSeparateModel; } + void setUseLCUSeparateModel(bool b) { m_rcUseCtuSeparateModel = b; } + int getInitialQP() const { return m_rcInitialQp; } + void setInitialQP(int QP) { m_rcInitialQp = QP; } + bool getForceIntraQP() const { return m_rcForceIntraQp; } + void setForceIntraQP(bool b) { m_rcForceIntraQp = b; } 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; } + 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; } CostMode getCostMode( ) const { return m_costMode; } void setCostMode(CostMode m ) { m_costMode = m; } bool getTSRCdisableLL () { return m_TSRCdisableLL; } diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp index 1b5d665db0e7d246b0b54f2812051bf78a90a465..332211baaad92b4b46390e5f15fc6c190313b65f 100644 --- a/source/Lib/EncoderLib/EncLib.cpp +++ b/source/Lib/EncoderLib/EncLib.cpp @@ -116,13 +116,13 @@ void EncLib::create( const int layerId ) m_cReshaper.createEnc(getSourceWidth(), getSourceHeight(), m_maxCUWidth, m_maxCUHeight, m_bitDepth[ChannelType::LUMA]); } - if ( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { Fraction frameRate = m_frameRate; frameRate.den *= m_temporalSubsampleRatio; - m_cRateCtrl.init(m_framesToBeEncoded, m_RCTargetBitrate, frameRate, m_gopSize, m_intraPeriod, m_sourceWidth, + m_cRateCtrl.init(m_framesToBeEncoded, m_rcTargetBitrate, frameRate, m_gopSize, m_intraPeriod, m_sourceWidth, m_sourceHeight, m_maxCUWidth, m_maxCUHeight, getBitDepth(ChannelType::LUMA), - m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList); + m_rcKeepHierarchicalBit, m_rcUseCtuSeparateModel, m_GOPList); } } @@ -180,7 +180,7 @@ void EncLib::init(AUWriterIf *auWriterIf) if (m_rcCpbSaturationEnabled) { m_cRateCtrl.initHrdParam(sps0.getGeneralHrdParameters(), sps0.getOlsHrdParameters(), m_frameRate, - m_RCInitialCpbFullness); + m_rcInitialCpbFullness); } m_cRdCost.setCostMode ( m_costMode ); @@ -643,7 +643,7 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv { AQpPreanalyzer::preanalyze( picCurr ); } - if( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { m_cRateCtrl.initRCGOP(m_receivedPicCount); } @@ -658,7 +658,7 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv this->setFeatureCounter(m_cGOPEncoder.getFeatureCounter()); #endif m_cGOPEncoder.setEncodedLTRef( true ); - if( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { m_cRateCtrl.destroyRCGOP(); } @@ -895,7 +895,7 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv return true; } - if( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { m_cRateCtrl.initRCGOP(m_receivedPicCount); } @@ -938,7 +938,7 @@ bool EncLib::encode(const InputColourSpaceConversion snrCSC, std::list<PelUnitBu m_metricTime = m_cGOPEncoder.getMetricTime(); #endif - if( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { m_cRateCtrl.destroyRCGOP(); } @@ -1809,7 +1809,7 @@ void EncLib::xInitPPS(PPS &pps, const SPS &sps) useDeltaQp = false; } - pps.setUseDQP(m_RCEnableRateControl || useDeltaQp); + pps.setUseDQP(m_rcEnableRateControl || useDeltaQp); if ( m_cuChromaQpOffsetList.size() > 0 ) { @@ -2149,7 +2149,7 @@ void EncLib::xInitPicHeader(PicHeader &picHeader, const SPS &sps, const PPS &pps useDeltaQp = false; } - if( m_RCEnableRateControl ) + if (m_rcEnableRateControl) { picHeader.setCuQpDeltaSubdivIntra( 0 ); picHeader.setCuQpDeltaSubdivInter( 0 );