Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 8 files). Show all
Unified · Split
| @@ -42,6 +42,7 @@ · 41 unmodified lines | |||
| 42 | #include "ref_list_mgr_svc.h" | 42 | #include "ref_list_mgr_svc.h" |
| 43 | 43 | ||
| 44 | #include <time.h> | 44 | #include <time.h> |
| 45 | #include <measure_time.h> | ||
| 45 | #if defined(_WIN32) /*&& defined(_DEBUG)*/ | 46 | #if defined(_WIN32) /*&& defined(_DEBUG)*/ |
| 46 | 47 | ||
| 47 | #include <windows.h> | 48 | #include <windows.h> |
| @@ -416,8 +417,10 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn · 368 unmodified lines | |||
| 416 | } | 417 | } |
| 417 | 418 | ||
| 418 | 419 | ||
| 419 | int CWelsH264SVCEncoder::EncodeFrameInternal (const SSourcePicture* pSrcPic, SFrameBSInfo* pBsInfo) { | 420 | int CWelsH264SVCEncoder ::EncodeFrameInternal (const SSourcePicture* pSrcPic, SFrameBSInfo* pBsInfo) { |
| 421 | const int64_t kiBeforeFrameUs = WelsTime(); | ||
| 420 | const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic); | 422 | const int32_t kiEncoderReturn = WelsEncoderEncodeExt (m_pEncContext, pBsInfo, pSrcPic); |
| 423 | const int64_t kiCurrentFrameMs = (WelsTime() - kiBeforeFrameUs) / 1000; | ||
| 421 | 424 | ||
| 422 | if (kiEncoderReturn == ENC_RETURN_MEMALLOCERR) { | 425 | if (kiEncoderReturn == ENC_RETURN_MEMALLOCERR) { |
| 423 | WelsUninitEncoderExt (&m_pEncContext); | 426 | WelsUninitEncoderExt (&m_pEncContext); |
| @@ -427,6 +430,9 @@ int CWelsH264SVCEncoder::EncodeFrameInternal (const SSourcePicture* pSrcPic, SF · 3 unmodified lines | |||
| 427 | kiEncoderReturn); | 430 | kiEncoderReturn); |
| 428 | return cmUnkonwReason; | 431 | return cmUnkonwReason; |
| 429 | } | 432 | } |
| 433 | |||
| 434 | UpdateStatistics (pSrcPic->uiTimeStamp, pBsInfo->eFrameType, kiCurrentFrameMs); | ||
| 435 | |||
| 430 | ///////////////////for test | 436 | ///////////////////for test |
| 431 | #ifdef OUTPUT_BIT_STREAM | 437 | #ifdef OUTPUT_BIT_STREAM |
| 432 | if (pBsInfo->eFrameType != videoFrameTypeInvalid && pBsInfo->eFrameType != videoFrameTypeSkip) { | 438 | if (pBsInfo->eFrameType != videoFrameTypeInvalid && pBsInfo->eFrameType != videoFrameTypeSkip) { |
| @@ -586,6 +592,61 @@ void CWelsH264SVCEncoder::TraceParamInfo (SEncParamExt* pParam) { · 153 unmodified lines | |||
| 586 | ++ i; | 592 | ++ i; |
| 587 | } | 593 | } |
| 588 | } | 594 | } |
| 595 | |||
| 596 | void CWelsH264SVCEncoder::UpdateStatistics (const int64_t kiCurrentFrameTs, EVideoFrameType eFrameType, | ||
| 597 | const int64_t kiCurrentFrameMs) { | ||
| 598 | SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics); | ||
| 599 | |||
| 600 | int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1; | ||
| 601 | if ((0 != pStatistics->uWidth && 0 != pStatistics->uHeight) | ||
| 602 | && (pStatistics->uWidth != m_pEncContext->pSvcParam->sDependencyLayers[iMaxDid].iActualWidth | ||
| 603 | || pStatistics->uHeight != m_pEncContext->pSvcParam->sDependencyLayers[iMaxDid].iActualHeight)) { | ||
| 604 | pStatistics->uiResolutionChangeTimes ++; | ||
| 605 | } | ||
| 606 | pStatistics->uWidth = m_pEncContext->pSvcParam->sDependencyLayers[iMaxDid].iActualWidth; | ||
| 607 | pStatistics->uHeight = m_pEncContext->pSvcParam->sDependencyLayers[iMaxDid].iActualHeight; | ||
| 608 | |||
| 609 | int32_t iProcessedFrameCount = pStatistics->uiInputFrameCount - pStatistics->uiSkippedFrameCount; | ||
| 610 | const bool kbCurrentFrameSkipped = (videoFrameTypeSkip == eFrameType); | ||
| 611 | if (!kbCurrentFrameSkipped && (iProcessedFrameCount + 1) != 0) { | ||
| 612 | pStatistics->fAverageFrameSpeedInMs = (iProcessedFrameCount * pStatistics->fAverageFrameSpeedInMs + | ||
| 613 | kiCurrentFrameMs) / (iProcessedFrameCount + 1); | ||
| 614 | } | ||
| 615 | pStatistics->uiInputFrameCount ++; | ||
| 616 | pStatistics->uiSkippedFrameCount += (kbCurrentFrameSkipped ? 1 : 0); | ||
| 617 | |||
| 618 | // rate control related | ||
| 619 | if (0 != m_pEncContext->uiStartTimestamp && kiCurrentFrameTs > m_pEncContext->uiStartTimestamp + 800) { | ||
| 620 | pStatistics->fAverageFrameRate = pStatistics->uiInputFrameCount * 1000 / | ||
| 621 | (kiCurrentFrameTs - m_pEncContext->uiStartTimestamp); | ||
| 622 | } else { | ||
| 623 | m_pEncContext->uiStartTimestamp = kiCurrentFrameTs; | ||
| 624 | } | ||
| 625 | pStatistics->fLatestFrameRate = m_pEncContext->pWelsSvcRc->fLatestFrameRate; //TODO: finish the calculation in RC | ||
| 626 | pStatistics->uiBitRate = m_pEncContext->pWelsSvcRc->iActualBitRate; //TODO: finish the calculation in RC | ||
| 627 | |||
| 628 | if (videoFrameTypeIDR == eFrameType || videoFrameTypeI == eFrameType) { | ||
| 629 | pStatistics->uIDRSentNum ++; | ||
| 630 | } | ||
| 631 | if (m_pEncContext->pLtr->bLTRMarkingFlag) { | ||
| 632 | pStatistics->uLTRSentNum ++; | ||
| 633 | } | ||
| 634 | //TODO: update uIDRSentNum in forceIDR | ||
| 635 | |||
| 636 | if (m_pEncContext->iStatisticsLogInterval > 0) { | ||
| 637 | if (WELS_ABS (kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs) > m_pEncContext->iStatisticsLogInterval) { | ||
| 638 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | ||
| 639 | "EncoderStatistics: %dx%d, SpeedInMs: %f, AverFrameRate=%f, LastFrameRate=%f, LatestBitRate=%d, uiInputFrameCount=%d, uiSkippedFrameCount=%d, uiResolutionChangeTimes=%d, uIDRReqNum=%d, uIDRSentNum=%d, uLTRSentNum=%d", | ||
| 640 | pStatistics->uWidth, pStatistics->uHeight, pStatistics->fAverageFrameSpeedInMs, | ||
| 641 | pStatistics->fAverageFrameRate, pStatistics->fLatestFrameRate, pStatistics->uiBitRate, | ||
| 642 | pStatistics->uiInputFrameCount, pStatistics->uiSkippedFrameCount, | ||
| 643 | pStatistics->uiResolutionChangeTimes, pStatistics->uIDRReqNum, pStatistics->uIDRSentNum, pStatistics->uLTRSentNum); | ||
| 644 | m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; | ||
| 645 | } | ||
| 646 | } | ||
| 647 | |||
| 648 | } | ||
| 649 | |||
| 589 | /************************************************************************ | 650 | /************************************************************************ |
| 590 | * InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,.. | 651 | * InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,.. |
| 591 | ************************************************************************/ | 652 | ************************************************************************/ |
| @@ -919,6 +980,16 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 327 unmodified lines | |||
| 919 | m_pEncContext->pSvcParam->iComplexityMode = (ECOMPLEXITY_MODE)iValue; | 980 | m_pEncContext->pSvcParam->iComplexityMode = (ECOMPLEXITY_MODE)iValue; |
| 920 | } | 981 | } |
| 921 | break; | 982 | break; |
| 983 | case ENCODER_OPTION_GET_STATISTICS: { | ||
| 984 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | ||
| 985 | "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_GET_STATISTICS: this option is get-only!"); | ||
| 986 | } | ||
| 987 | break; | ||
| 988 | case ENCODER_OPTION_STATISTICS_LOG_INTERVAL: { | ||
| 989 | int32_t iValue = * (static_cast<int32_t*> (pOption)); | ||
| 990 | m_pEncContext->iStatisticsLogInterval = iValue; | ||
| 991 | } | ||
| 992 | break; | ||
| 922 | case ENCODER_OPTION_IS_LOSSLESS_LINK: { | 993 | case ENCODER_OPTION_IS_LOSSLESS_LINK: { |
| 923 | bool bValue = * (static_cast<bool*> (pOption)); | 994 | bool bValue = * (static_cast<bool*> (pOption)); |
| 924 | m_pEncContext->pSvcParam->bIsLosslessLink = bValue; | 995 | m_pEncContext->pSvcParam->bIsLosslessLink = bValue; |
| @@ -1026,6 +1097,30 @@ int CWelsH264SVCEncoder::GetOption (ENCODER_OPTION eOptionId, void* pOption) { · 101 unmodified lines | |||
| 1026 | } | 1097 | } |
| 1027 | } | 1098 | } |
| 1028 | break; | 1099 | break; |
| 1100 | case ENCODER_OPTION_GET_STATISTICS: { | ||
| 1101 | SEncoderStatistics* pStatistics = (static_cast<SEncoderStatistics*> (pOption)); | ||
| 1102 | pStatistics->uWidth = m_pEncContext->sEncoderStatistics.uWidth; | ||
| 1103 | pStatistics->uHeight = m_pEncContext->sEncoderStatistics.uHeight; | ||
| 1104 | pStatistics->fAverageFrameSpeedInMs = m_pEncContext->sEncoderStatistics.fAverageFrameSpeedInMs; | ||
| 1105 | |||
| 1106 | // rate control related | ||
| 1107 | pStatistics->fAverageFrameRate = m_pEncContext->sEncoderStatistics.fAverageFrameRate; | ||
| 1108 | pStatistics->fLatestFrameRate = m_pEncContext->sEncoderStatistics.fLatestFrameRate; | ||
| 1109 | pStatistics->uiBitRate = m_pEncContext->sEncoderStatistics.uiBitRate; | ||
| 1110 | |||
| 1111 | pStatistics->uiInputFrameCount = m_pEncContext->sEncoderStatistics.uiInputFrameCount; | ||
| 1112 | pStatistics->uiSkippedFrameCount = m_pEncContext->sEncoderStatistics.uiSkippedFrameCount; | ||
| 1113 | |||
| 1114 | pStatistics->uiResolutionChangeTimes = m_pEncContext->sEncoderStatistics.uiResolutionChangeTimes; | ||
| 1115 | pStatistics->uIDRReqNum = m_pEncContext->sEncoderStatistics.uIDRReqNum; | ||
| 1116 | pStatistics->uIDRSentNum = m_pEncContext->sEncoderStatistics.uIDRSentNum; | ||
| 1117 | pStatistics->uLTRSentNum = m_pEncContext->sEncoderStatistics.uLTRSentNum; | ||
| 1118 | } | ||
| 1119 | break; | ||
| 1120 | case ENCODER_OPTION_STATISTICS_LOG_INTERVAL: { | ||
| 1121 | * ((int32_t*)pOption) = m_pEncContext->iStatisticsLogInterval; | ||
| 1122 | } | ||
| 1123 | break; | ||
| 1029 | case ENCODER_OPTION_COMPLEXITY: { | 1124 | case ENCODER_OPTION_COMPLEXITY: { |
| 1030 | * ((int32_t*)pOption) = m_pEncContext->pSvcParam->iComplexityMode; | 1125 | * ((int32_t*)pOption) = m_pEncContext->pSvcParam->iComplexityMode; |
| 1031 | } | 1126 | } |