Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 3 files). Show all
Unified · Split
| @@ -568,9 +568,12 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 567 unmodified lines | ||
| 568 | 568 | const int64_t kiCurrentFrameMs) { |
| 569 | 569 | |
| 570 | 570 | const int64_t kiCurrentFrameTs = m_pEncContext->uiLastTimestamp = pBsInfo->uiTimeStamp; |
| 571 | + const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; | |
| 571 | 572 | |
| 572 | 573 | int32_t iMaxDid = m_pEncContext->pSvcParam->iSpatialLayerNum - 1; |
| 573 | 574 | SLayerBSInfo* pLayerInfo = &pBsInfo->sLayerInfo[0]; |
| 575 | + uint32_t iMaxInputFrame = 0; | |
| 576 | + float iMaxFrameRate = 0; | |
| 574 | 577 | for (int32_t iDid = 0; iDid <= iMaxDid; iDid++) { |
| 575 | 578 | EVideoFrameType eFrameType = videoFrameTypeSkip; |
| 576 | 579 | int32_t kiCurrentFrameSize = 0; |
| @@ -584,19 +587,20 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | ||
| 584 | 587 | } |
| 585 | 588 | } |
| 586 | 589 | SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics[iDid]); |
| 587 | − | |
| 590 | + SSpatialLayerInternal* pSpatialLayerInternalParam = & (m_pEncContext->pSvcParam->sDependencyLayers[iDid]); | |
| 588 | 591 | |
| 589 | 592 | if ((0 != pStatistics->uiWidth && 0 != pStatistics->uiHeight) |
| 590 | − && (pStatistics->uiWidth != (unsigned int) m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualWidth | |
| 591 | − || pStatistics->uiHeight != (unsigned int) m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualHeight)) { | |
| 593 | + && (pStatistics->uiWidth != (unsigned int) pSpatialLayerInternalParam->iActualWidth | |
| 594 | + || pStatistics->uiHeight != (unsigned int) pSpatialLayerInternalParam->iActualHeight)) { | |
| 592 | 595 | pStatistics->uiResolutionChangeTimes ++; |
| 593 | 596 | } |
| 594 | − pStatistics->uiWidth = m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualWidth; | |
| 595 | − pStatistics->uiHeight = m_pEncContext->pSvcParam->sDependencyLayers[iDid].iActualHeight; | |
| 597 | + pStatistics->uiWidth = pSpatialLayerInternalParam->iActualWidth; | |
| 598 | + pStatistics->uiHeight = pSpatialLayerInternalParam->iActualHeight; | |
| 596 | 599 | |
| 597 | 600 | const bool kbCurrentFrameSkipped = (videoFrameTypeSkip == eFrameType); |
| 598 | 601 | pStatistics->uiInputFrameCount ++; |
| 599 | 602 | pStatistics->uiSkippedFrameCount += (kbCurrentFrameSkipped ? 1 : 0); |
| 603 | + iMaxInputFrame = WELS_MAX (pStatistics->uiInputFrameCount, iMaxInputFrame); | |
| 600 | 604 | int32_t iProcessedFrameCount = pStatistics->uiInputFrameCount - pStatistics->uiSkippedFrameCount; |
| 601 | 605 | if (!kbCurrentFrameSkipped && iProcessedFrameCount != 0) { |
| 602 | 606 | pStatistics->fAverageFrameSpeedInMs += (kiCurrentFrameMs - pStatistics->fAverageFrameSpeedInMs) / iProcessedFrameCount; |
| @@ -610,6 +614,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | ||
| 610 | 614 | } else { |
| 611 | 615 | m_pEncContext->uiStartTimestamp = kiCurrentFrameTs; |
| 612 | 616 | } |
| 617 | + iMaxFrameRate = WELS_MAX (iMaxFrameRate, pStatistics->fAverageFrameRate); | |
| 613 | 618 | //pStatistics->fLatestFrameRate = m_pEncContext->pWelsSvcRc->fLatestFrameRate; //TODO: finish the calculation in RC |
| 614 | 619 | //pStatistics->uiBitRate = m_pEncContext->pWelsSvcRc->iActualBitRate; //TODO: finish the calculation in RC |
| 615 | 620 | pStatistics->uiAverageFrameQP = m_pEncContext->pWelsSvcRc[iDid].iAverageFrameQp; |
| @@ -626,8 +631,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 10 unmodified lines | ||
| 626 | 631 | const int32_t kiDeltaFrames = static_cast<int32_t> (pStatistics->uiInputFrameCount - |
| 627 | 632 | pStatistics->iLastStatisticsFrameCount); |
| 628 | 633 | if (kiDeltaFrames > (m_pEncContext->pSvcParam->fMaxFrameRate * 2)) { |
| 629 | − const int64_t kiTimeDiff = kiCurrentFrameTs - pStatistics->iStatisticsTs; | |
| 630 | − if (kiTimeDiff) { | |
| 634 | + if (kiTimeDiff > m_pEncContext->iStatisticsLogInterval) { | |
| 631 | 635 | pStatistics->fLatestFrameRate = static_cast<float> ((pStatistics->uiInputFrameCount - |
| 632 | 636 | pStatistics->iLastStatisticsFrameCount) * 1000 / |
| 633 | 637 | kiTimeDiff); |
| @@ -639,7 +643,7 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 5 unmodified lines | ||
| 639 | 643 | "Actual input fLatestFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), cur_Ts = %" |
| 640 | 644 | PRId64 " start_Ts = %" PRId64, |
| 641 | 645 | pStatistics->fLatestFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, kiCurrentFrameTs, |
| 642 | − static_cast<int64_t> (pStatistics->iStatisticsTs)); | |
| 646 | + static_cast<int64_t> (m_pEncContext->iLastStatisticsLogTs)); | |
| 643 | 647 | } |
| 644 | 648 | |
| 645 | 649 | if (m_pEncContext->pSvcParam->iRCMode == RC_QUALITY_MODE || m_pEncContext->pSvcParam->iRCMode == RC_BITRATE_MODE) { |
| @@ -653,7 +657,6 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 7 unmodified lines | ||
| 653 | 657 | } |
| 654 | 658 | |
| 655 | 659 | // update variables |
| 656 | − pStatistics->iStatisticsTs = kiCurrentFrameTs; | |
| 657 | 660 | pStatistics->iLastStatisticsBytes = pStatistics->iTotalEncodedBytes; |
| 658 | 661 | pStatistics->iLastStatisticsFrameCount = pStatistics->uiInputFrameCount; |
| 659 | 662 | |
| @@ -661,20 +664,18 @@ void CWelsH264SVCEncoder::UpdateStatistics (SFrameBSInfo* pBsInfo, · 1 unmodified line | ||
| 661 | 664 | //pStatistics->uiLTRSentNum |
| 662 | 665 | } |
| 663 | 666 | } |
| 664 | − if (m_pEncContext->iStatisticsLogInterval > 0) { | |
| 665 | − SEncoderStatistics* pStatistics = & (m_pEncContext->sEncoderStatistics[0]); | |
| 666 | − const int64_t kiTimeDiff = kiCurrentFrameTs - m_pEncContext->iLastStatisticsLogTs; | |
| 667 | − if ((kiTimeDiff > m_pEncContext->iStatisticsLogInterval) || (0 == pStatistics->uiInputFrameCount % 300)) { | |
| 668 | − if (WELS_ABS (pStatistics->fAverageFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) { | |
| 669 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 670 | − "Actual input framerate fAverageFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), start_Ts = %" | |
| 671 | − PRId64, | |
| 672 | − pStatistics->fAverageFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, m_pEncContext->uiStartTimestamp); | |
| 673 | − } | |
| 667 | + if (((m_pEncContext->iStatisticsLogInterval > 0) && (kiTimeDiff > m_pEncContext->iStatisticsLogInterval)) | |
| 668 | + || (0 == iMaxInputFrame % 300)) { | |
| 674 | 669 | |
| 675 | − LogStatistics (kiCurrentFrameTs, iMaxDid); | |
| 676 | − m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; | |
| 670 | + if ((iMaxFrameRate > 0) && WELS_ABS (iMaxFrameRate - m_pEncContext->pSvcParam->fMaxFrameRate) > 30) { | |
| 671 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 672 | + "Actual input framerate fAverageFrameRate = %f is quite different from framerate in setting %f, please check setting or timestamp unit (ms), start_Ts = %" | |
| 673 | + PRId64, | |
| 674 | + iMaxFrameRate, m_pEncContext->pSvcParam->fMaxFrameRate, m_pEncContext->uiStartTimestamp); | |
| 677 | 675 | } |
| 676 | + | |
| 677 | + LogStatistics (kiCurrentFrameTs, iMaxDid); | |
| 678 | + m_pEncContext->iLastStatisticsLogTs = kiCurrentFrameTs; | |
| 678 | 679 | } |
| 679 | 680 | |
| 680 | 681 | } |