shithub: openh264

Download patch

ref: 724c97e817f726e050a2b39d1c3f131d591ad230
parent: c4586a2bed3c2305fab9715f288327aa213e47ff
author: sijchen@cisco.com <sijchen@cisco.com>
date: Tue Oct 10 06:23:30 EDT 2017

refactor EncoderStatistics and update it in resetting logic

--- a/codec/api/svc/codec_app_def.h
+++ b/codec/api/svc/codec_app_def.h
@@ -439,7 +439,7 @@
   ASP_15x11 = 11,
   ASP_64x33 = 12,
   ASP_160x99 = 13,
-  
+
   ASP_EXT_SAR = 255
 } ESampleAspectRatio;
 
@@ -742,7 +742,11 @@
   unsigned int uiLTRSentNum;                   ///< number of LTR sent/marked
 
   long long    iStatisticsTs;                  ///< Timestamp of updating the statistics
-} SEncoderStatistics; // in building, coming soon
+
+  unsigned long iTotalEncodedBytes;
+  unsigned long iLastStatisticsBytes;
+  unsigned long iLastStatisticsFrameCount;
+} SEncoderStatistics;
 
 /**
 * @brief  Structure for decoder statistics
--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -225,9 +225,6 @@
   SEncoderStatistics sEncoderStatistics[MAX_DEPENDENCY_LAYER];
   int32_t            iStatisticsLogInterval;
   int64_t            iLastStatisticsLogTs;
-  int64_t            iTotalEncodedBytes[MAX_DEPENDENCY_LAYER];
-  int64_t            iLastStatisticsBytes[MAX_DEPENDENCY_LAYER];
-  int64_t            iLastStatisticsFrameCount[MAX_DEPENDENCY_LAYER];
 
   int32_t iEncoderError;
   WELS_MUTEX mutexEncoderError;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -4287,8 +4287,13 @@
         uiMaxIdrPicId = pOldParam->sDependencyLayers[iIndexD].uiIdrPicId;
     }
 
+    //for sEncoderStatistics
     SEncoderStatistics sTempEncoderStatistics[MAX_DEPENDENCY_LAYER];
     memcpy (sTempEncoderStatistics, (*ppCtx)->sEncoderStatistics, sizeof (sTempEncoderStatistics));
+    int64_t            uiStartTimestamp = (*ppCtx)->uiStartTimestamp;
+    int32_t            iStatisticsLogInterval = (*ppCtx)->iStatisticsLogInterval;
+    int64_t            iLastStatisticsLogTs = (*ppCtx)->iLastStatisticsLogTs;
+    //for sEncoderStatistics
 
     SExistingParasetList sExistingParasetList;
     SExistingParasetList* pExistingParasetList = NULL;
@@ -4316,6 +4321,11 @@
 
     //for sEncoderStatistics
     memcpy ((*ppCtx)->sEncoderStatistics, sTempEncoderStatistics, sizeof (sTempEncoderStatistics));
+    (*ppCtx)->uiStartTimestamp = uiStartTimestamp;
+    (*ppCtx)->iStatisticsLogInterval = iStatisticsLogInterval;
+    (*ppCtx)->iLastStatisticsLogTs = iLastStatisticsLogTs;
+    //for sEncoderStatistics
+
     //load back the needed structure for eSpsPpsIdStrategy
     if (((CONSTANT_ID != iOldSpsPpsIdStrategy) && (CONSTANT_ID != pNewParam->eSpsPpsIdStrategy))
         || ((SPS_PPS_LISTING == iOldSpsPpsIdStrategy)
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -554,14 +554,13 @@
     WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
              "EncoderStatistics: SpatialId = %d,%dx%d, SpeedInMs: %f, fAverageFrameRate=%f, "
              "LastFrameRate=%f, LatestBitRate=%d, LastFrameQP=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, "
-             "uiResolutionChangeTimes=%d, uIDRReqNum=%d, uIDRSentNum=%d, uLTRSentNum=NA, iTotalEncodedBytes=%" PRId64
-             " at Ts = %" PRId64,
+             "uiResolutionChangeTimes=%d, uIDRReqNum=%d, uIDRSentNum=%d, uLTRSentNum=NA, iTotalEncodedBytes=%lu at Ts = %" PRId64,
              iDid, pStatistics->uiWidth, pStatistics->uiHeight,
              pStatistics->fAverageFrameSpeedInMs, pStatistics->fAverageFrameRate,
              pStatistics->fLatestFrameRate, pStatistics->uiBitRate, pStatistics->uiAverageFrameQP,
              pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount,
              pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRReqNum, pStatistics->uiIDRSentNum,
-             m_pEncContext->iTotalEncodedBytes[iDid], kiCurrentFrameTs);
+             pStatistics->iTotalEncodedBytes, kiCurrentFrameTs);
   }
 }
 
@@ -622,18 +621,18 @@
       pStatistics->uiLTRSentNum ++;
     }
 
-    m_pEncContext->iTotalEncodedBytes[iDid] += kiCurrentFrameSize;
+    pStatistics->iTotalEncodedBytes += kiCurrentFrameSize;
 
     const int32_t kiDeltaFrames = static_cast<int32_t> (pStatistics->uiInputFrameCount -
-                                  m_pEncContext->iLastStatisticsFrameCount[iDid]);
+                                  pStatistics->iLastStatisticsFrameCount);
     if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) {
       const int64_t kiTimeDiff = kiCurrentFrameTs - pStatistics->iStatisticsTs;
       if (kiTimeDiff) {
         pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount -
-                                        m_pEncContext->iLastStatisticsFrameCount[iDid]) * 1000 /
+                                        pStatistics->iLastStatisticsFrameCount) * 1000 /
                                         kiTimeDiff);
-        pStatistics->uiBitRate = static_cast<unsigned int> ((m_pEncContext->iTotalEncodedBytes[iDid] -
-                                 m_pEncContext->iLastStatisticsBytes[iDid]) * 8 * 1000 / kiTimeDiff);
+        pStatistics->uiBitRate = static_cast<unsigned int> ((pStatistics->iTotalEncodedBytes -
+                                 pStatistics->iLastStatisticsBytes) * 8 * 1000 / kiTimeDiff);
 
         if (WELS_ABS (pStatistics->fLatestFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) {
           WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
@@ -655,8 +654,8 @@
 
       // update variables
       pStatistics->iStatisticsTs = kiCurrentFrameTs;
-      m_pEncContext->iLastStatisticsBytes[iDid] = m_pEncContext->iTotalEncodedBytes[iDid];
-      m_pEncContext->iLastStatisticsFrameCount[iDid] = pStatistics->uiInputFrameCount;
+      pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes;
+      pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
 
       //TODO: the following statistics will be calculated and added later
       //pStatistics->uiLTRSentNum