shithub: openh264

Download patch

ref: 515eeb41e4e8ad437c047d96990eaa32543d3326
parent: 7ccc377d55846bc65d65779c3baa898a8faa7603
parent: 87e81a7a407688945d66242506ca9f0369bb003d
author: HaiboZhu <[email protected]>
date: Wed Jun 1 05:03:57 EDT 2016

Merge pull request #2481 from ruil2/maxbitrate1

  fix iContinualSkipFrames calculation

--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -172,7 +172,6 @@
   int32_t           iCheckWindowInterval;
   int32_t           iCheckWindowIntervalShift;
   bool              bCheckWindowShiftResetFlag;
-  int32_t           iContinualSkipFrames;
   int32_t           iGlobalQp;      // global qp
 
 // VAA
--- a/codec/encoder/core/inc/rc.h
+++ b/codec/encoder/core/inc/rc.h
@@ -222,7 +222,7 @@
 int32_t   iPaddingSize;
 int32_t   iPaddingBitrateStat;
 bool      bSkipFlag;
-
+int32_t   iContinualSkipFrames;
 SRCTemporal* pTemporalOverRc;
 
 //for scc
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3455,14 +3455,13 @@
 
   bool bSkipFrameFlag =  WelsRcCheckFrameStatus (pCtx,uiTimeStamp,iSpatialNum,iCurDid);
   EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid, bSkipFrameFlag);
-
   if (eFrameType == videoFrameTypeSkip) {
-    WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
-             "[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames",
-             uiTimeStamp, pCtx->iContinualSkipFrames);
     if (pSvcParam->bSimulcastAVC) {
       if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip)
         pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iCurDid);
+        WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
+                 "[Rc] Frame timestamp = %lld, iDid = %d,skip one frame due to target_br, continual skipped %d frames",
+                 uiTimeStamp, iCurDid, pCtx->pWelsSvcRc[iCurDid].iContinualSkipFrames);
     }
 
     else {
@@ -3471,11 +3470,14 @@
           pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, (pSpatialIndexMap + i)->iDid);
         }
       }
+      WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
+                 "[Rc] Frame timestamp = %lld, iDid = %d,skip one frame due to target_br, continual skipped %d frames",
+                 uiTimeStamp, iCurDid, pCtx->pWelsSvcRc[iCurDid].iContinualSkipFrames);
     }
 
   } else {
     SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid];
-    pCtx->iContinualSkipFrames = 0;
+
     iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iCurDid], pParamInternal->iCodingIndex,
                                 pSvcParam->uiGopSize);
     pCtx->uiTemporalId = iCurTid;
@@ -3500,10 +3502,12 @@
       for (int32_t i = 0; i < pSvcParam->iSpatialLayerNum; i++) {
         SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[i];
         pParamInternal->iCodingIndex ++;
+        pCtx->pWelsSvcRc[i].iContinualSkipFrames = 0;
       }
     } else {
       SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid];
       pParamInternal->iCodingIndex++;
+      pCtx->pWelsSvcRc[iCurDid].iContinualSkipFrames = 0;
     }
   }
   return eFrameType;
@@ -3575,8 +3579,8 @@
     pFbi->eFrameType = videoFrameTypeSkip;
     pLayerBsInfo->eFrameType = videoFrameTypeSkip;
     WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
-             "[Rc] Frame timestamp = %lld, skip one frame due to preprocessing return (temporal layer settings or else), continual skipped %d frames",
-             pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
+             "[Rc] Frame timestamp = %lld, skip one frame due to preprocessing return (temporal layer settings or else)",
+              pSrcPic->uiTimeStamp);
     return ENC_RETURN_SUCCESS;
   }
 
@@ -3935,9 +3939,6 @@
       }
 
       WelsRcPostFrameSkippedUpdate (pCtx, iCurDid);
-      WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO,
-               "[Rc] Frame timestamp = %lld, skip one frame due to post skip, continual skipped %d frames",
-               pFbi->uiTimeStamp, pCtx->iContinualSkipFrames);
       pCtx->iEncoderError = ENC_RETURN_SUCCESS;
       return ENC_RETURN_SUCCESS;
     }
--- a/codec/encoder/core/src/ratectl.cpp
+++ b/codec/encoder/core/src/ratectl.cpp
@@ -736,9 +736,9 @@
   3:if in last ODD_TIME_WINDOW the MAX Br is overflowed, make more strict skipping conditions
   4:such as case 3 in the other window
   */
-  bool bJudgeBufferFullSkip = (pEncCtx->iContinualSkipFrames <= iPredSkipFramesTarBr)
+  bool bJudgeBufferFullSkip = (pWelsSvcRc->iContinualSkipFrames <= iPredSkipFramesTarBr)
                               && (pWelsSvcRc->iBufferFullnessSkip > pWelsSvcRc->iBufferSizeSkip);
-  bool bJudgeMaxBRbufferFullSkip = (pEncCtx->iContinualSkipFrames <= iPredSkipFramesMaxBr)
+  bool bJudgeMaxBRbufferFullSkip = (pWelsSvcRc->iContinualSkipFrames <= iPredSkipFramesMaxBr)
                                    && (pEncCtx->iCheckWindowInterval > TIME_CHECK_WINDOW / 2)
                                    && (pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW] + pWelsSvcRc->iPredFrameBit - iAvailableBitsInTimeWindow > 0);
   bJudgeMaxBRbSkip[EVEN_TIME_WINDOW] = (pEncCtx->iCheckWindowInterval > TIME_CHECK_WINDOW / 2)
@@ -797,7 +797,7 @@
     if (bSkipMustFlag) {
       pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
       pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
-      pEncCtx->iContinualSkipFrames++;
+      pEncCtx->pWelsSvcRc[iDidIdx].iContinualSkipFrames++;
       return true;
     }
   } else { //SVC control
@@ -821,7 +821,6 @@
         }
       }
       if (bSkipMustFlag) {
-        pEncCtx->iContinualSkipFrames++;
         break;
       }
     }
@@ -831,6 +830,7 @@
         int32_t iDidIdx = (pSpatialIndexMap + i)->iDid;
         pEncCtx->pWelsSvcRc[iDidIdx].uiLastTimeStamp = uiTimeStamp;
         pEncCtx->pWelsSvcRc[iDidIdx].bSkipFlag = false;
+        pEncCtx->pWelsSvcRc[iDidIdx].iContinualSkipFrames++;
       }
       return true;
     }
@@ -845,8 +845,8 @@
   pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW] -= kiOutputMaxBits;
   pWelsSvcRc->iBufferMaxBRFullness[ODD_TIME_WINDOW] -= kiOutputMaxBits;
   WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG,
-           "[Rc] bits in buffer = %" PRId64 ", bits in Max bitrate buffer = %" PRId64,
-           pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW]);
+           "[Rc] iDid = %d,bits in buffer = %" PRId64 ", bits in Max bitrate buffer = %" PRId64,
+           iCurDid,pWelsSvcRc->iBufferFullnessSkip, pWelsSvcRc->iBufferMaxBRFullness[EVEN_TIME_WINDOW]);
 
   pWelsSvcRc->iBufferFullnessSkip = WELS_MAX (pWelsSvcRc->iBufferFullnessSkip, 0);
 
@@ -854,12 +854,11 @@
   pWelsSvcRc->iSkipFrameNum++;
   pWelsSvcRc->iSkipFrameInVGop++;
 
-  pEncCtx->iContinualSkipFrames++;
-  if ((pEncCtx->iContinualSkipFrames % 3) == 0) {
+  if ((pWelsSvcRc->iContinualSkipFrames % 3) == 0) {
     //output a warning when iContinualSkipFrames is large enough, which may indicate subjective quality problem
     //note that here iContinualSkipFrames must be >0, so the log output will be 3/6/....
-    WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_WARNING, "[Rc] iContinualSkipFrames(%d) is large",
-             pEncCtx->iContinualSkipFrames);
+    WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_WARNING, "[Rc] iDid = %d,iContinualSkipFrames(%d) is large",
+             iCurDid,pWelsSvcRc->iContinualSkipFrames);
   }
 }
 void UpdateMaxBrCheckWindowStatus (sWelsEncCtx* pEncCtx, int32_t iSpatialNum, const long long uiTimeStamp) {