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
140140 ++ i;
141141 } while (i < kuiRefNumInTemporal);
142142
143− if(pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
143+ if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME)
144144 m_uiSpatialLayersInTemporal[iDlayerIndex] = 1;
145145 else
146146 m_uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
@@ -210,20 +210,20 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD · 63 unmodified lines
210210 SPicture* pCurPic = m_pSpatialPic[kiDidx][iCurTemporalIdx];
211211 bool bCalculateVar = (pSvcParam->iRCMode >= RC_BITRATE_MODE && pCtx->eSliceType == I_SLICE);
212212
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];
217217
218− VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD);
218+ VaaCalculation (pCtx->pVaa, pCurPic, pRefPic, false, bCalculateVar, bCalculateBGD);
219219
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+ }
223223
224− if (bNeededMbAq) {
225− AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
226− }
224+ if (bNeededMbAq) {
225+ AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
226+ }
227227 } else {
228228 SPicture* pRefPic = m_pSpatialPic[kiDidx][iRefTemporalIdx];
229229 SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
@@ -242,21 +242,16 @@ int32_t CWelsPreProcess::AnalyzeSpatialPic (sWelsEncCtx* pCtx, const int32_t kiD · 12 unmodified lines
242242
243243 AdaptiveQuantCalculation (pCtx->pVaa, pCurPic, pRefPic);
244244 }
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]);
252247 }
253248 return 0;
254249 }
255250
256251 int32_t CWelsPreProcess::UpdateSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam,
257252 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;
260255 if (iCurTid < m_uiSpatialLayersInTemporal[d_idx] - 1 || pParam->iDecompStages == 0) {
261256 if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (m_uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
262257 InitLastSpatialPictures (pCtx);
@@ -723,39 +718,35 @@ void CWelsPreProcess::SetRefMbType (sWelsEncCtx* pCtx, uint32_t** pRefMbTypeArra · 460 unmodified lines
723718 void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCurPicture, SPicture* pRefPicture,
724719 const int32_t kiDependencyId, const bool bCalculateBGD) {
725720 SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam;
726− SVAAFrameInfo* pVaaInfo = pCtx->pVaa;
727−
728− SComplexityAnalysisParam* sComplexityAnalysisParam = & (pVaaInfo->sComplexityAnalysisParam);
729− SWelsSvcRc* SWelsSvcRc = &pCtx->pWelsSvcRc[kiDependencyId];
730721 int32_t iComplexityAnalysisMode = 0;
731722
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)
739724 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;
748736
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));
752739
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;
756748
757− {
758− int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS;
749+ const int32_t iMethodIdx = METHOD_COMPLEXITY_ANALYSIS_SCREEN;
759750 SPixMap sSrcPixMap;
760751 SPixMap sRefPixMap;
761752 memset (&sSrcPixMap, 0, sizeof (SPixMap));
@@ -769,17 +760,76 @@ void CWelsPreProcess::AnalyzePictureComplexity (sWelsEncCtx* pCtx, SPicture* pCu · 7 unmodified lines
769760 sSrcPixMap.sRect.iRectHeight = pCurPicture->iHeightInPixel;
770761 sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
771762
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+ }
778771
779772 iRet = m_pInterfaceVp->Set (iMethodIdx, (void*)sComplexityAnalysisParam);
780773 iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sRefPixMap);
781774 if (iRet == 0)
782775 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+ }
783833 }
784834 }
785835
@@ -1007,12 +1057,11 @@ ESceneChangeIdc CWelsPreProcess::DetectSceneChangeScreen (sWelsEncCtx* pCtx, SPi · 221 unmodified lines
10071057 return static_cast<ESceneChangeIdc> (iVaaFrameSceneChangeIdc);
10081058 }
10091059
1010−int32_t CWelsPreProcess::GetRefCandidateLtrIndex(int32_t iRefIdx)
1011−{
1060+int32_t CWelsPreProcess::GetRefCandidateLtrIndex (int32_t iRefIdx) {
10121061 const int32_t iTargetDid = m_pEncCtx->pSvcParam->iSpatialLayerNum - 1;
10131062 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;
10161065 return iLtrRefIdx;
10171066 }
10181067 void 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