Showing the changes to codec/encoder/core/src/wels_preprocess.cpp (1 of 4 files). Show all
Unified · Split
| @@ -140,7 +140,7 @@ int32_t CWelsPreProcess::AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCoding · 139 unmodified lines | ||
| 140 | 140 | ++ i; |
| 141 | 141 | } while (i < kuiRefNumInTemporal); |
| 142 | 142 | |
| 143 | − if(pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 143 | + if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 144 | 144 | m_uiSpatialLayersInTemporal[iDlayerIndex] = 1; |
| 145 | 145 | else |
| 146 | 146 | m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal; |
| @@ -210,20 +210,20 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD · 63 unmodified lines | ||
| 210 | 210 | SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx]; |
| 211 | 211 | bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE); |
| 212 | 212 | |
| 213 | − if(pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME){ | |
| 214 | − SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa); | |
| 215 | − SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[0]); | |
| 216 | − SPicture *pRefPic= m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx]; | |
| 213 | + if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { | |
| 214 | + SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa); | |
| 215 | + SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[0]); | |
| 216 | + SPicture* pRefPic = m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx]; | |
| 217 | 217 | |
| 218 | − VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD); | |
| 218 | + VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD); | |
| 219 | 219 | |
| 220 | − if (pSvcParam->bEnableBackgroundDetection) { | |
| 221 | − BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE); | |
| 222 | − } | |
| 220 | + if (pSvcParam->bEnableBackgroundDetection) { | |
| 221 | + BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE); | |
| 222 | + } | |
| 223 | 223 | |
| 224 | − if (bNeededMbAq) { | |
| 225 | − AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic); | |
| 226 | − } | |
| 224 | + if (bNeededMbAq) { | |
| 225 | + AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic); | |
| 226 | + } | |
| 227 | 227 | } else { |
| 228 | 228 | SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx]; |
| 229 | 229 | SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0]; |
| @@ -242,21 +242,16 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD · 12 unmodified lines | ||
| 242 | 242 | |
| 243 | 243 | AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic); |
| 244 | 244 | } |
| 245 | − | |
| 246 | − if(pSvcParam->iUsageType != SCREEN_CONTENT_REAL_TIME){ | |
| 247 | − if (pSvcParam->iRCMode != RC_OFF_MODE) { | |
| 248 | − AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD); | |
| 249 | − } | |
| 250 | − WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]); | |
| 251 | − } | |
| 245 | + AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD); | |
| 246 | + WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]); | |
| 252 | 247 | } |
| 253 | 248 | return 0; |
| 254 | 249 | } |
| 255 | 250 | |
| 256 | 251 | int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam, |
| 257 | 252 | const int8_t iCurTid, const int32_t d_idx) { |
| 258 | − if(pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 259 | − return 0; | |
| 253 | + if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 254 | + return 0; | |
| 260 | 255 | if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) { |
| 261 | 256 | if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) { |
| 262 | 257 | InitLastSpatialPictures (pCtx); |
| @@ -723,39 +718,35 @@ void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArra · 460 unmodified lines | ||
| 723 | 718 | void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture, |
| 724 | 719 | const int32_t kiDependencyId, const bool bCalculateBGD) { |
| 725 | 720 | SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam; |
| 726 | − SVAAFrameInfo* pVaaInfo = pCtx->pVaa; | |
| 727 | − | |
| 728 | − SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam); | |
| 729 | − SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId]; | |
| 730 | 721 | int32_t iComplexityAnalysisMode = 0; |
| 731 | 722 | |
| 732 | − if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) { | |
| 733 | − iComplexityAnalysisMode = FRAME_SAD; | |
| 734 | − } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == P_SLICE) { | |
| 735 | − iComplexityAnalysisMode = GOM_SAD; | |
| 736 | − } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE) { | |
| 737 | − iComplexityAnalysisMode = GOM_VAR; | |
| 738 | − } else { | |
| 723 | + if (pSvcParam->iRCMode == RC_OFF_MODE) | |
| 739 | 724 | return; |
| 740 | − } | |
| 741 | − | |
| 742 | − sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode; | |
| 743 | − sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo); | |
| 744 | − sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag; | |
| 745 | − SetRefMbType (pCtx, & (sComplexityAnalysisParam->uiRefMbType), pRefPicture->iPictureType); | |
| 746 | − sComplexityAnalysisParam->iCalcBgd = bCalculateBGD; | |
| 747 | − sComplexityAnalysisParam->iFrameComplexity = 0; | |
| 725 | + if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { | |
| 726 | + SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (pCtx->pVaa); | |
| 727 | + SComplexityAnalysisScreenParam* sComplexityAnalysisParam = &pVaaExt->sComplexityScreenParam; | |
| 728 | + SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId]; | |
| 729 | + | |
| 730 | + if (pCtx->eSliceType == P_SLICE) | |
| 731 | + iComplexityAnalysisMode = GOM_SAD; | |
| 732 | + else if (pCtx->eSliceType == I_SLICE) | |
| 733 | + iComplexityAnalysisMode = GOM_VAR; | |
| 734 | + else | |
| 735 | + return; | |
| 748 | 736 | |
| 749 | − memset (SWelsSvcRc->pGomForegroundBlockNum, 0, SWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 750 | − if (iComplexityAnalysisMode != FRAME_SAD) | |
| 751 | − memset (SWelsSvcRc->pCurrentFrameGomSad, 0, SWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 737 | + memset (pWelsSvcRc->pGomForegroundBlockNum, 0, pWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 738 | + memset (pWelsSvcRc->pCurrentFrameGomSad, 0, pWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 752 | 739 | |
| 753 | − sComplexityAnalysisParam->pGomComplexity = SWelsSvcRc->pCurrentFrameGomSad; | |
| 754 | − sComplexityAnalysisParam->pGomForegroundBlockNum = SWelsSvcRc->pGomForegroundBlockNum; | |
| 755 | − sComplexityAnalysisParam->iMbNumInGom = SWelsSvcRc->iNumberMbGom; | |
| 740 | + sComplexityAnalysisParam->iFrameComplexity = 0; | |
| 741 | + sComplexityAnalysisParam->pGomComplexity = pWelsSvcRc->pCurrentFrameGomSad; | |
| 742 | + sComplexityAnalysisParam->iGomNumInFrame = pWelsSvcRc->iGomSize; | |
| 743 | + sComplexityAnalysisParam->iIdrFlag = (pCtx->eSliceType == I_SLICE); | |
| 744 | + sComplexityAnalysisParam->iMbRowInGom = GOM_H_SCC; | |
| 745 | + sComplexityAnalysisParam->sScrollResult.bScrollDetectFlag = false; | |
| 746 | + sComplexityAnalysisParam->sScrollResult.iScrollMvX = 0; | |
| 747 | + sComplexityAnalysisParam->sScrollResult.iScrollMvY = 0; | |
| 756 | 748 | |
| 757 | − { | |
| 758 | − int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS; | |
| 749 | + const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN; | |
| 759 | 750 | SPixMap sSrcPixMap; |
| 760 | 751 | SPixMap sRefPixMap; |
| 761 | 752 | memset (&sSrcPixMap, 0, sizeof (SPixMap)); |
| @@ -769,17 +760,76 @@ void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCu · 7 unmodified lines | ||
| 769 | 760 | sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel; |
| 770 | 761 | sSrcPixMap.eFormat = VIDEO_FORMAT_I420; |
| 771 | 762 | |
| 772 | − sRefPixMap.pPixel[0] = pRefPicture->pData[0]; | |
| 773 | − sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits; | |
| 774 | − sRefPixMap.iStride[0] = pRefPicture->iLineSize[0]; | |
| 775 | − sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel; | |
| 776 | − sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel; | |
| 777 | − sRefPixMap.eFormat = VIDEO_FORMAT_I420; | |
| 763 | + if (pRefPicture != NULL) { | |
| 764 | + sRefPixMap.pPixel[0] = pRefPicture->pData[0]; | |
| 765 | + sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits; | |
| 766 | + sRefPixMap.iStride[0] = pRefPicture->iLineSize[0]; | |
| 767 | + sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel; | |
| 768 | + sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel; | |
| 769 | + sRefPixMap.eFormat = VIDEO_FORMAT_I420; | |
| 770 | + } | |
| 778 | 771 | |
| 779 | 772 | iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam); |
| 780 | 773 | iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap); |
| 781 | 774 | if (iRet == 0) |
| 782 | 775 | m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam); |
| 776 | + | |
| 777 | + } else { | |
| 778 | + SVAAFrameInfo* pVaaInfo = pCtx->pVaa; | |
| 779 | + SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam); | |
| 780 | + SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId]; | |
| 781 | + | |
| 782 | + if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) { | |
| 783 | + iComplexityAnalysisMode = FRAME_SAD; | |
| 784 | + } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == P_SLICE) { | |
| 785 | + iComplexityAnalysisMode = GOM_SAD; | |
| 786 | + } else if (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE) { | |
| 787 | + iComplexityAnalysisMode = GOM_VAR; | |
| 788 | + } else { | |
| 789 | + return; | |
| 790 | + } | |
| 791 | + sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode; | |
| 792 | + sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo); | |
| 793 | + sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag; | |
| 794 | + SetRefMbType (pCtx, & (sComplexityAnalysisParam->uiRefMbType), pRefPicture->iPictureType); | |
| 795 | + sComplexityAnalysisParam->iCalcBgd = bCalculateBGD; | |
| 796 | + sComplexityAnalysisParam->iFrameComplexity = 0; | |
| 797 | + | |
| 798 | + memset (SWelsSvcRc->pGomForegroundBlockNum, 0, SWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 799 | + if (iComplexityAnalysisMode != FRAME_SAD) | |
| 800 | + memset (SWelsSvcRc->pCurrentFrameGomSad, 0, SWelsSvcRc->iGomSize * sizeof (int32_t)); | |
| 801 | + | |
| 802 | + sComplexityAnalysisParam->pGomComplexity = SWelsSvcRc->pCurrentFrameGomSad; | |
| 803 | + sComplexityAnalysisParam->pGomForegroundBlockNum = SWelsSvcRc->pGomForegroundBlockNum; | |
| 804 | + sComplexityAnalysisParam->iMbNumInGom = SWelsSvcRc->iNumberMbGom; | |
| 805 | + | |
| 806 | + { | |
| 807 | + int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS; | |
| 808 | + SPixMap sSrcPixMap; | |
| 809 | + SPixMap sRefPixMap; | |
| 810 | + memset (&sSrcPixMap, 0, sizeof (SPixMap)); | |
| 811 | + memset (&sRefPixMap, 0, sizeof (SPixMap)); | |
| 812 | + int32_t iRet = 0; | |
| 813 | + | |
| 814 | + sSrcPixMap.pPixel[0] = pCurPicture->pData[0]; | |
| 815 | + sSrcPixMap.iSizeInBits = g_kiPixMapSizeInBits; | |
| 816 | + sSrcPixMap.iStride[0] = pCurPicture->iLineSize[0]; | |
| 817 | + sSrcPixMap.sRect.iRectWidth = pCurPicture->iWidthInPixel; | |
| 818 | + sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel; | |
| 819 | + sSrcPixMap.eFormat = VIDEO_FORMAT_I420; | |
| 820 | + | |
| 821 | + sRefPixMap.pPixel[0] = pRefPicture->pData[0]; | |
| 822 | + sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits; | |
| 823 | + sRefPixMap.iStride[0] = pRefPicture->iLineSize[0]; | |
| 824 | + sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel; | |
| 825 | + sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel; | |
| 826 | + sRefPixMap.eFormat = VIDEO_FORMAT_I420; | |
| 827 | + | |
| 828 | + iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam); | |
| 829 | + iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap); | |
| 830 | + if (iRet == 0) | |
| 831 | + m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam); | |
| 832 | + } | |
| 783 | 833 | } |
| 784 | 834 | } |
| 785 | 835 | |
| @@ -1007,12 +1057,11 @@ ESceneChangeIdc CWelsPreProcess::DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPi · 221 unmodified lines | ||
| 1007 | 1057 | return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc); |
| 1008 | 1058 | } |
| 1009 | 1059 | |
| 1010 | −int32_t CWelsPreProcess::GetRefCandidateLtrIndex(int32_t iRefIdx) | |
| 1011 | −{ | |
| 1060 | +int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) { | |
| 1012 | 1061 | const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1; |
| 1013 | 1062 | SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa); |
| 1014 | − SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[iRefIdx]); | |
| 1015 | − int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum; | |
| 1063 | + SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[iRefIdx]); | |
| 1064 | + int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum; | |
| 1016 | 1065 | return iLtrRefIdx; |
| 1017 | 1066 | } |
| 1018 | 1067 | void CWelsPreProcess::Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV, |