History

Merge pull request #1530 from sijchen/after_review

[Encoder] add total length in encoder output and complete statistics

ruil2 committed 12 years ago

Commit 703bbef2 parents aed7b23 b56b8726 files · +69 −13Browse files

Unified · Split

6 files
  1. codec/api/svc/codec_app_def.h +1 −0
  2. codec/encoder/core/inc/encoder_context.h +3 −0
  3. codec/encoder/core/src/encoder_ext.cpp +12 −3
  4. codec/encoder/plus/inc/welsEncoderExt.h +1 −1
  5. codec/encoder/plus/src/welsEncoderExt.cpp +24 −9
  6. test/encoder/EncUT_EncoderExt.cpp +28 −0
codec/api/svc/codec_app_def.h+1−0
@@ -404,6 +404,7 @@ typedef struct { · 403 unmodified lines
404404 SLayerBSInfo sLayerInfo[MAX_LAYER_NUM_OF_FRAME];
405405
406406 EVideoFrameType eFrameType;
407+ int iFrameSizeInBytes;
407408 long long uiTimeStamp;
408409 } SFrameBSInfo, *PFrameBSInfo;
409410
codec/encoder/core/inc/encoder_context.h+3−0
@@ -221,6 +221,9 @@ typedef struct TagWelsEncCtx { · 220 unmodified lines
221221 SEncoderStatistics sEncoderStatistics;
222222 int32_t iStatisticsLogInterval;
223223 int64_t iLastStatisticsLogTs;
224+ int64_t iTotalEncodedBits;
225+ int64_t iLastStatisticsBits;
226+ int64_t iLastStatisticsFrameCount;
224227
225228 int32_t iEncoderError;
226229 WELS_MUTEX mutexEncoderError;
codec/encoder/core/src/encoder_ext.cpp+12−3
@@ -2736,7 +2736,7 @@ void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, · 2735 unmodified lines
27362736 * \brief write all parameter sets introduced in SVC extension
27372737 * \return writing results, success or error
27382738 */
2739−int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal) {
2739+int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal, int32_t* pTotalLength) {
27402740 int32_t iSize = 0;
27412741 int32_t iNal = 0;
27422742 int32_t iIdx = 0;
@@ -2748,6 +2748,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 5 unmodified lines
27482748 if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal)
27492749 return ENC_RETURN_UNEXPECTED;
27502750
2751+ *pTotalLength = 0;
27512752 /* write all SPS */
27522753 iIdx = 0;
27532754 while (iIdx < pCtx->iSpsNum) {
@@ -2834,6 +2835,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 80 unmodified lines
28342835 }
28352836
28362837 *pNumNal = iCountNal;
2838+ *pTotalLength = iSize;
28372839
28382840 return ENC_RETURN_SUCCESS;
28392841 }
@@ -2944,13 +2946,14 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 104 unmodified lines
29442946 SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst;
29452947 SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0];
29462948 int32_t iCountNal = 0;
2949+ int32_t iTotalLength = 0;
29472950
29482951 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
29492952 pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
29502953 InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
29512954
29522955 pCtx->iPosBsBuffer = 0;
2953− int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
2956+ int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal, &iTotalLength);
29542957 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
29552958
29562959 pLayerBsInfo->uiSpatialId = 0;
@@ -3094,7 +3097,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 137 unmodified lines
30943097 //if ( pSvcParam->bEnableSSEI )
30953098
30963099 // write parameter sets bitstream here
3097− pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
3100+ int32_t iNonVclSize = 0;
3101+ pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal, &iNonVclSize);
30983102 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
30993103
31003104 pLayerBsInfo->uiSpatialId = 0;
@@ -3107,6 +3111,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 6 unmodified lines
31073111 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
31083112 pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
31093113 ++ iLayerNum;
3114+
3115+ iFrameSize += iNonVclSize;
31103116 }
31113117
31123118 pCtx->pCurDqLayer = pCtx->ppDqLayerList[pSpatialIndexMap->iDid];
@@ -3605,6 +3611,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 492 unmodified lines
36053611 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
36063612 pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1;
36073613 ++ iLayerNum;
3614+
3615+ iFrameSize += iPaddingNalSize;
36083616 }
36093617
36103618 if ((pParam->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE || pParam->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)
@@ -3677,6 +3685,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 66 unmodified lines
36773685 WelsEmms();
36783686
36793687 pFbi->eFrameType = eFrameType;
3688+ pFbi->iFrameSizeInBytes = iFrameSize;
36803689 return ENC_RETURN_SUCCESS;
36813690 }
36823691
codec/encoder/plus/inc/welsEncoderExt.h+1−1
@@ -102,7 +102,7 @@ class CWelsH264SVCEncoder : public ISVCEncoder { · 101 unmodified lines
102102 void CheckLevelSetting (int32_t iLayer, ELevelIdc uiLevelIdc);
103103 void CheckReferenceNumSetting (int32_t iNumRef);
104104 void TraceParamInfo(SEncParamExt *pParam);
105− void UpdateStatistics(const int64_t kiCurrentFrameTs, EVideoFrameType eFrameType, const int64_t kiCurrentFrameMs);
105+ void UpdateStatistics(const int64_t kiCurrentFrameTs, EVideoFrameType eFrameType, const int32_t kiCurrentFrameSize, const int64_t kiCurrentFrameMs);
106106
107107 sWelsEncCtx* m_pEncContext;
108108
codec/encoder/plus/src/welsEncoderExt.cpp+24−9
@@ -431,7 +431,7 @@ int CWelsH264SVCEncoder ::EncodeFrameInternal (const SSourcePicture* pSrcPic, S · 430 unmodified lines
431431 return cmUnkonwReason;
432432 }
433433
434− UpdateStatistics (pSrcPic->uiTimeStamp, pBsInfo->eFrameType, kiCurrentFrameMs);
434+ UpdateStatistics (pSrcPic->uiTimeStamp, pBsInfo->eFrameType, pBsInfo->iFrameSizeInBytes, kiCurrentFrameMs);
435435
436436 ///////////////////for test
437437 #ifdef OUTPUT_BIT_STREAM
@@ -504,6 +504,8 @@ int CWelsH264SVCEncoder::ForceIntraFrame (bool bIDR) { · 66 unmodified lines
504504
505505 ForceCodingIDR (m_pEncContext);
506506
507+ m_pEncContext->sEncoderStatistics.uiIDRReqNum++;
508+
507509 return 0;
508510 }
509511 void CWelsH264SVCEncoder::CheckProfileSetting (int32_t iLayer, EProfileIdc uiProfileIdc) {
@@ -594,7 +596,7 @@ void CWelsH264SVCEncoder::TraceParamInfo (SEncParamExt* pParam) { · 84 unmodified lines
594596 }
595597
596598 void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVideoFrameType eFrameType,
597− const int64_t kiCurrentFrameMs) {
599+ const int32_t kiCurrentFrameSize, const int64_t kiCurrentFrameMs) {
598600 SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics);
599601
600602 int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1;
@@ -633,20 +635,33 @@ void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVid · 32 unmodified lines
633635 if (m_pEncContext->pLtr->bLTRMarkingFlag) {
634636 pStatistics->uiLTRSentNum ++;
635637 }
636− //TODO: update uiIDRReqNum in forceIDR
638+
639+ m_pEncContext->iTotalEncodedBits += kiCurrentFrameSize;
637640
638641 if (m_pEncContext->iStatisticsLogInterval > 0) {
639− if (WELS_ABS (kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs) > m_pEncContext->iStatisticsLogInterval) {
642+ int64_t iTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs;
643+ if (iTimeDiff > m_pEncContext->iStatisticsLogInterval) {
644+ pStatistics->fLatestFrameRate = (pStatistics->uiInputFrameCount - m_pEncContext->iLastStatisticsFrameCount) * 1000 /
645+ iTimeDiff;
646+ pStatistics->uiBitRate = static_cast<unsigned int> ((m_pEncContext->iTotalEncodedBits -
647+ m_pEncContext->iLastStatisticsBits) * 1000 / iTimeDiff);
648+
649+ // update variables
650+ m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
651+ m_pEncContext->iLastStatisticsBits = m_pEncContext->iTotalEncodedBits;
652+ m_pEncContext->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount;
653+
640654 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
641− "EncoderStatistics: %dx%d, SpeedInMs: %f, AverFrameRate=%f, LastFrameRate=NA, LatestBitRate=NA, uiInputFrameCount=%d, uiSkippedFrameCount=%d, uiResolutionChangeTimes=%d, uIDRReqNum=%d, uIDRSentNum=%d, uLTRSentNum=NA",
655+ "EncoderStatistics: %dx%d, SpeedInMs: %f, fAverageFrameRate=%f, \
656+ LastFrameRate=%f, LatestBitRate=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, \
657+ uiResolutionChangeTimes=%d, uIDRReqNum=%d, uIDRSentNum=%d, uLTRSentNum=NA",
642658 pStatistics->uiWidth, pStatistics->uiHeight,
643659 pStatistics->fAverageFrameSpeedInMs, pStatistics->fAverageFrameRate,
660+ pStatistics->fLatestFrameRate, pStatistics->uiBitRate,
644661 pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount,
645− pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRSentNum, pStatistics->uiLTRSentNum);
662+ pStatistics->uiResolutionChangeTimes, pStatistics->uiIDRReqNum, pStatistics->uiIDRSentNum);
646663 //TODO: the following statistics will be calculated and added later
647− //pStatistics->fLatestFrameRate, pStatistics->uiBitRate,
648− //pStatistics->uiIDRReqNum,
649− m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs;
664+ //pStatistics->uiLTRSentNum
650665 }
651666 }
652667
test/encoder/EncUT_EncoderExt.cpp+28−0
@@ -770,3 +770,31 @@ TEST_F (EncoderInterfaceTest, GetStatistics) { · 769 unmodified lines
770770 // finish
771771 pPtrEnc->Uninitialize();
772772 }
773+
774+TEST_F (EncoderInterfaceTest, FrameSizeCheck) {
775+ SEncParamBase sEncParamBase;
776+ GetValidEncParamBase (&sEncParamBase);
777+
778+ int iResult = pPtrEnc->Initialize (&sEncParamBase);
779+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
780+ if (iResult != cmResultSuccess) {
781+ fprintf (stderr, "Unexpected ParamBase? \
782+ iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n",
783+ sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight,
784+ sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate);
785+ }
786+
787+ PrepareOneSrcFrame();
788+ iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
789+
790+ uint32_t length = 0;
791+ for (int i = 0; i < sFbi.iLayerNum; ++i) {
792+ for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) {
793+ length += sFbi.sLayerInfo[i].pNalLengthInByte[j];
794+ }
795+ }
796+ EXPECT_EQ (length, sFbi.iFrameSizeInBytes);
797+
798+ // finish
799+ pPtrEnc->Uninitialize();
800+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t