diff --git a/codec/encoder/core/inc/extern.h b/codec/encoder/core/inc/extern.h index de5d51a8..e56d709c 100644 --- a/codec/encoder/core/inc/extern.h +++ b/codec/encoder/core/inc/extern.h @@ -109,6 +109,7 @@ int32_t WelsBitRateVerification(SLogContext* pLogCtx,SSpatialLayerConfig* pLayer int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew); void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam); int32_t WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer); +int32_t WelsEncoderApplyBitVaryRang(SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iRang); int32_t WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue); int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest); diff --git a/codec/encoder/core/src/encoder_ext.cpp b/codec/encoder/core/src/encoder_ext.cpp index 5f526a7f..58085172 100644 --- a/codec/encoder/core/src/encoder_ext.cpp +++ b/codec/encoder/core/src/encoder_ext.cpp @@ -533,6 +533,20 @@ int32_t WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pPar } return ENC_RETURN_SUCCESS; } +int32_t WelsEncoderApplyBitVaryRang(SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iRang){ + SSpatialLayerConfig* pLayerParam; + const int32_t iNumLayers = pParam->iSpatialLayerNum; + for (int32_t i = 0; i < iNumLayers; i++) { + pLayerParam = & (pParam->sSpatialLayers[i]); + pLayerParam->iMaxSpatialBitrate = WELS_MIN(pLayerParam->iSpatialBitrate * (1+ iRang/100.0),pLayerParam->iMaxSpatialBitrate); + if (WelsBitRateVerification (pLogCtx, pLayerParam, i) != ENC_RETURN_SUCCESS) + return ENC_RETURN_UNSUPPORTED_PARA; + WelsLog (pLogCtx, WELS_LOG_INFO, + "WelsEncoderApplyBitVaryRang:UpdateMaxBitrate layerId= %d,iMaxSpatialBitrate = %d", i, pLayerParam->iMaxSpatialBitrate); + } + return ENC_RETURN_SUCCESS; +} + /*! * \brief acquire count number of layers and NALs based on configurable paramters dependency * \pParam pCtx sWelsEncCtx* diff --git a/codec/encoder/plus/src/welsEncoderExt.cpp b/codec/encoder/plus/src/welsEncoderExt.cpp index 7f110ec5..49a1cd8c 100644 --- a/codec/encoder/plus/src/welsEncoderExt.cpp +++ b/codec/encoder/plus/src/welsEncoderExt.cpp @@ -1044,7 +1044,8 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { break; case ENCODER_OPTION_BITS_VARY_PERCENTAGE: { int32_t iValue = * (static_cast (pOption)); - m_pEncContext->pSvcParam->iBitsVaryPercentage = iValue; + m_pEncContext->pSvcParam->iBitsVaryPercentage = WELS_CLIP3(iValue,0,100); + WelsEncoderApplyBitVaryRang(&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, m_pEncContext->pSvcParam->iBitsVaryPercentage); WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITS_VARY_PERCENTAGE,iBitsVaryPercentage = %d", iValue); }