History

add complexity calculation in workflow

ruil2 committed 12 years ago

Commit 6b707ff1 parent 2f8c5394 files · +115 −61Browse files

Showing the changes to codec/encoder/core/src/wels_preprocess.cpp (1 of 4 files). Show all

Unified · Split

codec/encoder/core/src/wels_preprocess.cpp+107−58
@@ -140,7 +140,7 @@ int32_t CWelsPreProcess::AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCoding · 139 unmodified lines
140 ++ i;140 ++ i;
141 } while (i < kuiRefNumInTemporal);141 } while (i < kuiRefNumInTemporal);
142 142
143 if(pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)143 if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
144 m_uiSpatialLayersInTemporal[iDlayerIndex] = 1;144 m_uiSpatialLayersInTemporal[iDlayerIndex] = 1;
145 else145 else
146 m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;146 m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
@@ -210,20 +210,20 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD · 63 unmodified lines
210 SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];210 SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
211 bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);211 bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
212 212
213 if(pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME){213 if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
214 SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);214 SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
215 SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[0]);215 SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[0]);
216 SPicture *pRefPic= m_pSpatialPic[0][BestRefCandidateParam->iSrcListIdx];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) {220 if (pSvcParam->bEnableBackgroundDetection) {
221 BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);221 BackgroundDetection (pCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
222 }222 }
223 223
224 if (bNeededMbAq) {224 if (bNeededMbAq) {
225 AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);225 AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
226 }226 }
227 } else {227 } else {
228 SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];228 SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
229 SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];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 AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);243 AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
244 }244 }
245 245 AnalyzePictureComplexity (pCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
246 if(pSvcParam->iUsageType != SCREEN_CONTENT_REAL_TIME){246 WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);
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 }
252 }247 }
253 return 0;248 return 0;
254}249}
255 250
256int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam,251int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam,
257 const int8_t iCurTid, const int32_t d_idx) {252 const int8_t iCurTid, const int32_t d_idx) {
258 if(pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)253 if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
259 return 0;254 return 0;
260 if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) {255 if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) {
261 if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {256 if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
262 InitLastSpatialPictures (pCtx);257 InitLastSpatialPictures (pCtx);
@@ -723,39 +718,35 @@ void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArra · 460 unmodified lines
723void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,718void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
724 const int32_t kiDependencyId, const bool bCalculateBGD) {719 const int32_t kiDependencyId, const bool bCalculateBGD) {
725 SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;720 SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
726 SVAAFrameInfo* pVaaInfo = pCtx->pVaa;
727
728 SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam);
729 SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
730 int32_t iComplexityAnalysisMode = 0;721 int32_t iComplexityAnalysisMode = 0;
731 722
732 if (pSvcParam->iRCMode == RC_QUALITY_MODE && pCtx->eSliceType == P_SLICE) {723 if (pSvcParam->iRCMode == RC_OFF_MODE)
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 {
739 return;724 return;
740 }725 if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
741 726 SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (pCtx->pVaa);
742 sComplexityAnalysisParam->iComplexityAnalysisMode = iComplexityAnalysisMode;727 SComplexityAnalysisScreenParam* sComplexityAnalysisParam = &pVaaExt->sComplexityScreenParam;
743 sComplexityAnalysisParam->pCalcResult = & (pVaaInfo->sVaaCalcInfo);728 SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
744 sComplexityAnalysisParam->pBackgroundMbFlag = pVaaInfo->pVaaBackgroundMbFlag;729
745 SetRefMbType (pCtx, & (sComplexityAnalysisParam->uiRefMbType), pRefPicture->iPictureType);730 if (pCtx->eSliceType == P_SLICE)
746 sComplexityAnalysisParam->iCalcBgd = bCalculateBGD;731 iComplexityAnalysisMode = GOM_SAD;
747 sComplexityAnalysisParam->iFrameComplexity = 0;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));737 memset (pWelsSvcRc->pGomForegroundBlockNum, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
750 if (iComplexityAnalysisMode != FRAME_SAD)738 memset (pWelsSvcRc->pCurrentFrameGomSad, 0, pWelsSvcRc->iGomSize * sizeof (int32_t));
751 memset (SWelsSvcRc->pCurrentFrameGomSad, 0, SWelsSvcRc->iGomSize * sizeof (int32_t));
752 739
753 sComplexityAnalysisParam->pGomComplexity = SWelsSvcRc->pCurrentFrameGomSad;740 sComplexityAnalysisParam->iFrameComplexity = 0;
754 sComplexityAnalysisParam->pGomForegroundBlockNum = SWelsSvcRc->pGomForegroundBlockNum;741 sComplexityAnalysisParam->pGomComplexity = pWelsSvcRc->pCurrentFrameGomSad;
755 sComplexityAnalysisParam->iMbNumInGom = SWelsSvcRc->iNumberMbGom;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 {749 const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN;
758 int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS;
759 SPixMap sSrcPixMap;750 SPixMap sSrcPixMap;
760 SPixMap sRefPixMap;751 SPixMap sRefPixMap;
761 memset (&sSrcPixMap, 0, sizeof (SPixMap));752 memset (&sSrcPixMap, 0, sizeof (SPixMap));
@@ -769,17 +760,76 @@ void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCu · 7 unmodified lines
769 sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;760 sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
770 sSrcPixMap.eFormat = VIDEO_FORMAT_I420;761 sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
771 762
772 sRefPixMap.pPixel[0] = pRefPicture->pData[0];763 if (pRefPicture != NULL) {
773 sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;764 sRefPixMap.pPixel[0] = pRefPicture->pData[0];
774 sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];765 sRefPixMap.iSizeInBits = g_kiPixMapSizeInBits;
775 sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;766 sRefPixMap.iStride[0] = pRefPicture->iLineSize[0];
776 sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;767 sRefPixMap.sRect.iRectWidth = pRefPicture->iWidthInPixel;
777 sRefPixMap.eFormat = VIDEO_FORMAT_I420;768 sRefPixMap.sRect.iRectHeight = pRefPicture->iHeightInPixel;
769 sRefPixMap.eFormat = VIDEO_FORMAT_I420;
770 }
778 771
779 iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);772 iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
780 iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);773 iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
781 if (iRet == 0)774 if (iRet == 0)
782 m_pInterfaceVp->Get (iMethodIdx, (void*)sComplexityAnalysisParam);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 return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);1057 return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);
1008}1058}
1009 1059
1010int32_t CWelsPreProcess::GetRefCandidateLtrIndex(int32_t iRefIdx)1060int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) {
1011{
1012 const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;1061 const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
1013 SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);1062 SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (m_pEncCtx->pVaa);
1014 SRefInfoParam* BestRefCandidateParam =&(pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);1063 SRefInfoParam* BestRefCandidateParam = & (pVaaExt->sVaaStrBestRefCandidate[iRefIdx]);
1015 int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum;1064 int32_t iLtrRefIdx = m_pSpatialPic[iTargetDid][BestRefCandidateParam->iSrcListIdx]->iLongTermPicNum;
1016 return iLtrRefIdx;1065 return iLtrRefIdx;
1017}1066}
1018void CWelsPreProcess::Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV,1067void CWelsPreProcess::Padding (uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iStrideY, int32_t iStrideUV,

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