History

Merge pull request #290 from volvet/develop_b

Refactor CWelsPreProcess

ruil2 committed 12 years ago

Commit dd93aa92 parents e79769f bb58c5c4 files · +108 −101Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+12−78
@@ -564,63 +564,12 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 563 unmodified lines
564564 #endif//!MT_ENABLED
565565
566566 if (NULL != pCountLayers)
567− *pCountLayers = iCountNumLayers;
567+ *pCountLayers = iCountNumLayers;
568568 if (NULL != pCountNals)
569− *pCountNals = iCountNumNals;
569+ *pCountNals = iCountNumNals;
570570 return 0;
571571 }
572572
573−/*!
574− * \brief alloc spatial layers pictures (I420 based source pictures)
575− */
576−int32_t AllocSpatialPictures (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam) {
577− CMemoryAlign* pMa = pCtx->pMemAlign;
578− const int32_t kiDlayerCount = pParam->iSpatialLayerNum;
579− int32_t iDlayerIndex = 0;
580−
581− // spatial pictures
582− iDlayerIndex = 0;
583− do {
584− const int32_t kiPicWidth = pParam->sDependencyLayers[iDlayerIndex].iFrameWidth;
585− const int32_t kiPicHeight = pParam->sDependencyLayers[iDlayerIndex].iFrameHeight;
586− const uint8_t kuiLayerInTemporal = 2 + WELS_MAX (pParam->sDependencyLayers[iDlayerIndex].iHighestTemporalId, 1);
587− const uint8_t kuiRefNumInTemporal = kuiLayerInTemporal + pParam->iLTRRefNum;
588− uint8_t i = 0;
589−
590− do {
591− SPicture* pPic = AllocPicture (pMa, kiPicWidth, kiPicHeight, false);
592− WELS_VERIFY_RETURN_IF(1, (NULL == pPic))
593− pCtx->pSpatialPic[iDlayerIndex][i] = pPic;
594− ++ i;
595− } while (i < kuiRefNumInTemporal);
596−
597− pCtx->uiSpatialLayersInTemporal[iDlayerIndex] = kuiLayerInTemporal;
598− pCtx->uiSpatialPicNum[iDlayerIndex] = kuiRefNumInTemporal;
599− ++ iDlayerIndex;
600− } while (iDlayerIndex < kiDlayerCount);
601−
602− return 0;
603−}
604−
605−void FreeSpatialPictures (sWelsEncCtx* pCtx) {
606− CMemoryAlign* pMa = pCtx->pMemAlign;
607− int32_t j = 0;
608− while (j < pCtx->pSvcParam->iSpatialLayerNum) {
609− uint8_t i = 0;
610− uint8_t uiRefNumInTemporal = pCtx->uiSpatialPicNum[j];
611−
612− while (i < uiRefNumInTemporal) {
613− if (NULL != pCtx->pSpatialPic[j][i]) {
614− FreePicture (pMa, &pCtx->pSpatialPic[j][i]);
615− }
616− ++ i;
617− }
618− pCtx->uiSpatialLayersInTemporal[j] = 0;
619− ++ j;
620− }
621−
622−}
623−
624573 static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, const int32_t kiDlayerId,
625574 const int32_t kiMaxMbNum) {
626575 int32_t iMbWidth = pLayer->iMbWidth;
@@ -846,12 +795,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 219 unmodified lines
846795 ++ iDlayerIndex;
847796 }
848797
849− // for I420 based source spatial pictures
850− if (AllocSpatialPictures (*ppCtx, pParam)) {
851− FreeMemorySvc (ppCtx);
852− return 1;
853− }
854−
855798 iDlayerIndex = 0;
856799 while (iDlayerIndex < iDlayerCount) {
857800 SDqLayer* pDqLayer = NULL;
@@ -1703,8 +1646,6 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 845 unmodified lines
17031646 pMa->WelsFree (pCtx->ppDqLayerList, "ppDqLayerList");
17041647 pCtx->ppDqLayerList = NULL;
17051648 }
1706− FreeSpatialPictures (pCtx);
1707−
17081649 // reference picture list extension
17091650 if (NULL != pCtx->ppRefPicListExt && pParam != NULL) {
17101651 ilayer = 0;
@@ -2126,10 +2067,16 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 415 unmodified lines
21262067
21272068 pCtx->pVpp = new CWelsPreProcess (pCtx);
21282069 if (pCtx->pVpp == NULL) {
2070+ iRet = 1;
21292071 WelsLog (pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().\n");
21302072 FreeMemorySvc (&pCtx);
21312073 return iRet;
21322074 }
2075+ if( (iRet = pCtx->pVpp->AllocSpatialPictures(pCtx, pCtx->pSvcParam)) != 0 ){
2076+ WelsLog( pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pVPP alloc spatial pictures failed\n");
2077+ FreeMemorySvc(&pCtx);
2078+ return iRet;
2079+ }
21332080
21342081 #if defined(MEMORY_MONITOR)
21352082 WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n",
@@ -2286,6 +2233,7 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 150 unmodified lines
22862233 #endif//MT_ENABLED
22872234
22882235 if ((*ppCtx)->pVpp) {
2236+ (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx);
22892237 delete (*ppCtx)->pVpp;
22902238 (*ppCtx)->pVpp = NULL;
22912239 }
@@ -3747,23 +3695,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 1455 unmodified lines
37473695 pCtx->bLongTermRefFlag[d_idx][0] = true;
37483696 }
37493697
3750− if (iCurTid < pCtx->uiSpatialLayersInTemporal[d_idx] - 1 || pSvcParam->iDecompStages == 0) {
3751− if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (pCtx->uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) {
3752− ForceCodingIDR (pCtx); // some logic error
3753− return -1;
3754− }
3755−
3756− if (pSvcParam->bEnableLongTermReference && pCtx->bLongTermRefFlag[d_idx][iCurTid]) {
3757− SPicture* tmp = pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx];
3758− pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] + pCtx->pVaa->uiMarkLongTermPicIdx] =
3759− pCtx->pSpatialPic[d_idx][iCurTid];
3760− pCtx->pSpatialPic[d_idx][iCurTid] = pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1];
3761− pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1] = tmp;
3762− pCtx->bLongTermRefFlag[d_idx][iCurTid] = false;
3763− } else {
3764− WelsExchangeSpatialPictures (&pCtx->pSpatialPic[d_idx][pCtx->uiSpatialLayersInTemporal[d_idx] - 1],
3765− &pCtx->pSpatialPic[d_idx][iCurTid]);
3766− }
3698+ if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){
3699+ ForceCodingIDR(pCtx);
3700+ return -1;
37673701 }
37683702
37693703 if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag

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