From d557578be323707cf3eaf68662d6ff3b790bf5d1 Mon Sep 17 00:00:00 2001 From: Sijia Chen Date: Tue, 27 Jan 2015 10:12:51 +0800 Subject: [PATCH] fix statistics: updating should be independent with log interval --- codec/api/svc/codec_app_def.h | 5 ++- codec/encoder/plus/src/welsEncoderExt.cpp | 42 +++++++++++++---------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/codec/api/svc/codec_app_def.h b/codec/api/svc/codec_app_def.h index 35401371..030b80bc 100644 --- a/codec/api/svc/codec_app_def.h +++ b/codec/api/svc/codec_app_def.h @@ -432,7 +432,8 @@ typedef struct TagEncParamExt { ECOMPLEXITY_MODE iComplexityMode; unsigned int uiIntraPeriod; ///< period of Intra frame int iNumRefFrame; ///< number of reference frame used - EParameterSetStrategy eSpsPpsIdStrategy; ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional + EParameterSetStrategy + eSpsPpsIdStrategy; ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additional bool bPrefixNalAddingCtrl; ///< false:not use Prefix NAL; true: use Prefix NAL bool bEnableSSEI; ///< false:not use SSEI; true: use SSEI -- TODO: planning to remove the interface of SSEI bool bSimulcastAVC; ///< (when encoding more than 1 spatial layer) false: use SVC syntax for higher layers; true: use Simulcast AVC -- coming soon @@ -631,6 +632,8 @@ typedef struct TagVideoEncoderStatistics { unsigned int uiIDRReqNum; ///< number of IDR requests unsigned int uiIDRSentNum; ///< number of actual IDRs sent unsigned int uiLTRSentNum; ///< number of LTR sent/marked + + long long iStatisticsTs; ///< Timestamp of updating the statistics } SEncoderStatistics; // in building, coming soon /** diff --git a/codec/encoder/plus/src/welsEncoderExt.cpp b/codec/encoder/plus/src/welsEncoderExt.cpp index 8b1cafee..4d1ddbad 100644 --- a/codec/encoder/plus/src/welsEncoderExt.cpp +++ b/codec/encoder/plus/src/welsEncoderExt.cpp @@ -583,24 +583,31 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid pStatistics->uiLTRSentNum ++; } - m_pEncContext->iTotalEncodedBits += (kiCurrentFrameSize<<3); + m_pEncContext->iTotalEncodedBits += (kiCurrentFrameSize << 3); + const int32_t kiDeltaFrames = static_cast (pStatistics->uiInputFrameCount - + m_pEncContext->iLastStatisticsFrameCount); + if (kiDeltaFrames > m_pEncContext->pSvcParam->fMaxFrameRate) { + const int64_t kiTimeDiff = kiCurrentFrameTs - pStatistics->iStatisticsTs; + if (kiTimeDiff) { + pStatistics->fLatestFrameRate = static_cast ((pStatistics->uiInputFrameCount - + m_pEncContext->iLastStatisticsFrameCount) * 1000 / + kiTimeDiff); + pStatistics->uiBitRate = static_cast ((m_pEncContext->iTotalEncodedBits - + m_pEncContext->iLastStatisticsBits) * 1000 / kiTimeDiff); + } + + // update variables + pStatistics->iStatisticsTs = kiCurrentFrameTs; + m_pEncContext->iLastStatisticsBits = m_pEncContext->iTotalEncodedBits; + m_pEncContext->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount; + + //TODO: the following statistics will be calculated and added later + //pStatistics->uiLTRSentNum + } if (m_pEncContext->iStatisticsLogInterval > 0) { - int64_t iTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; - if ((iTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { - if (iTimeDiff) { - pStatistics->fLatestFrameRate = static_cast ((pStatistics->uiInputFrameCount - - m_pEncContext->iLastStatisticsFrameCount) * 1000 / - iTimeDiff); - pStatistics->uiBitRate = static_cast ((m_pEncContext->iTotalEncodedBits - - m_pEncContext->iLastStatisticsBits) * 1000 / iTimeDiff); - } - - // update variables - m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; - m_pEncContext->iLastStatisticsBits = m_pEncContext->iTotalEncodedBits; - m_pEncContext->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount; - + const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; + if ((kiTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "EncoderStatistics: %dx%d, SpeedInMs: %f, fAverageFrameRate=%f, \ LastFrameRate=%f, LatestBitRate=%d, LastFrameQP=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, \ @@ -610,8 +617,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid pStatistics->fLatestFrameRate, pStatistics->uiBitRate, pStatistics->uiAverageFrameQP, pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount, pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRReqNum, pStatistics->uiIDRSentNum); - //TODO: the following statistics will be calculated and added later - //pStatistics->uiLTRSentNum + m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; } }