shithub: openh264

Download patch

ref: 24cd5afa33c8c46a670b90febd1111dfd80e4383
parent: 0fa845ed2739d2e8f84eb607aa01fb3ae1c199c8
author: JuannyWang <hongjwan@cisco.com>
date: Fri Jul 4 14:25:55 EDT 2014

disable delay skip if maxbr=0 which means no maxbr setting from upper layer

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -92,9 +92,9 @@
       return ENC_RETURN_UNSUPPORTED_PARA;
     }
     if (pCfg->bEnableAdaptiveQuant) {
-       WelsLog (pLogCtx, WELS_LOG_WARNING, "ParamValidation(), AdaptiveQuant(%d) is not supported yet for screen content, auto turned off\n",
+      WelsLog (pLogCtx, WELS_LOG_WARNING, "ParamValidation(), AdaptiveQuant(%d) is not supported yet for screen content, auto turned off\n",
                pCfg->bEnableAdaptiveQuant);
-       pCfg->bEnableAdaptiveQuant = false;
+      pCfg->bEnableAdaptiveQuant = false;
     }
   }
   if (pCfg->iSpatialLayerNum > 1) {
@@ -458,12 +458,6 @@
   const int32_t iNumLayers = pParam->iSpatialLayerNum;
   int32_t i, iOrigTotalBitrate = 0;
   if (iLayer == SPATIAL_LAYER_ALL) {
-    if (pParam->iMaxBitrate < pParam->iTargetBitrate) {
-      WelsLog (pLogCtx, WELS_LOG_WARNING,
-               "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,overall settting,TargetBitrate = %d,iMaxBitrate = %d\n",
-               pParam->iTargetBitrate, pParam->iMaxBitrate);
-      pParam->iMaxBitrate  = pParam->iTargetBitrate;
-    }
     //read old BR
     for (i = 0; i < iNumLayers; i++) {
       iOrigTotalBitrate += pParam->sSpatialLayers[i].iSpatialBitrate;
@@ -475,14 +469,6 @@
       fRatio = pLayerParam->iSpatialBitrate / (static_cast<float> (iOrigTotalBitrate));
       pLayerParam->iSpatialBitrate = static_cast<int32_t> (pParam->iTargetBitrate * fRatio);
     }
-  } else {
-    if (pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate < pParam->sSpatialLayers[iLayer].iSpatialBitrate) {
-      WelsLog (pLogCtx, WELS_LOG_WARNING,
-               "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d,iTargetBitrate = %d,iMaxBitrate = %d\n",
-               iLayer, pParam->sSpatialLayers[iLayer].iSpatialBitrate, pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate);
-      pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate = pParam->sSpatialLayers[iLayer].iSpatialBitrate;
-    }
-
   }
 }
 /*!
@@ -2943,6 +2929,28 @@
     iSubSeqId = 3 + MAX_TEMPORAL_LAYER_NUM;
   return iSubSeqId;
 }
+
+//loop each layer to check if have skip frame when RC and frame skip enable (maxbr>0)
+bool CheckFrameSkipBasedMaxbr(sWelsEncCtx* pCtx, int32_t iSpatialNum) {
+  SSpatialPicIndex* pSpatialIndexMap = &pCtx->sSpatialIndexMap[0];
+  bool bSkipMustFlag = false;
+
+  if (RC_OFF_MODE != pCtx->pSvcParam->iRCMode && true == pCtx->pSvcParam->bEnableFrameSkip) {
+    for (int32_t i = 0; i < iSpatialNum; i++) {
+      if(0 == pCtx->pSvcParam->sSpatialLayers[i].iMaxSpatialBitrate) {
+        break;
+      }
+      pCtx->uiDependencyId = (uint8_t) (pSpatialIndexMap + i)->iDid;
+      pCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pCtx);
+      if (true == pCtx->pWelsSvcRc[pCtx->uiDependencyId].bSkipFlag) {
+        bSkipMustFlag = true;
+        break;
+      }
+    }
+  }
+  return bSkipMustFlag;
+}
+
 /*!
  * \brief	core svc encoding process
  *
@@ -3003,21 +3011,10 @@
   }
 
   //loop each layer to check if have skip frame when RC and frame skip enable
-  if (RC_OFF_MODE != pCtx->pSvcParam->iRCMode && true == pCtx->pSvcParam->bEnableFrameSkip) {
-    bool bSkipMustFlag = false;
-    for (int32_t i = 0; i < iSpatialNum; i++) {
-      pCtx->uiDependencyId = (uint8_t) (pSpatialIndexMap + i)->iDid;
-      pCtx->pFuncList->pfRc.pfWelsRcPicDelayJudge (pCtx);
-      if (true == pCtx->pWelsSvcRc[pCtx->uiDependencyId].bSkipFlag) {
-        bSkipMustFlag = true;
-      }
-    }
-    if (true == bSkipMustFlag) {
-      pFbi->eFrameType = videoFrameTypeSkip;
-      return ENC_RETURN_SUCCESS;
-    }
+  if (CheckFrameSkipBasedMaxbr(pCtx, iSpatialNum)) {
+    pFbi->eFrameType = videoFrameTypeSkip;
+    return ENC_RETURN_SUCCESS;
   }
-
 
   InitFrameCoding (pCtx, eFrameType);