shithub: openh264

Download patch

ref: 5ff55a6ec245d7e8d0c01082d9c71aa0c83f83dc
parent: 44e4531897657f977acaf2e3dbbccf32cd542d97
parent: 5ba9e409baca00fe83274e19233ae1859b68d5a3
author: sijchen <sijchen@cisco.com>
date: Thu Dec 11 08:46:07 EST 2014

Merge pull request #1608 from ruil2/bits_update

    update maxbitrate to control bitrate vary range

--- a/codec/encoder/core/inc/extern.h
+++ b/codec/encoder/core/inc/extern.h
@@ -109,6 +109,7 @@
 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);
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -533,6 +533,20 @@
   }
   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*
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -1044,7 +1044,8 @@
   break;
   case ENCODER_OPTION_BITS_VARY_PERCENTAGE: {
     int32_t iValue = * (static_cast<int32_t*> (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);
   }