Refactor CWelsPreProcess
Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 4 files). Show all
Unified · Split
| @@ -564,63 +564,12 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 563 unmodified lines | |||
| 564 | #endif//!MT_ENABLED | 564 | #endif//!MT_ENABLED |
| 565 | 565 | ||
| 566 | if (NULL != pCountLayers) | 566 | if (NULL != pCountLayers) |
| 567 | *pCountLayers = iCountNumLayers; | 567 | *pCountLayers = iCountNumLayers; |
| 568 | if (NULL != pCountNals) | 568 | if (NULL != pCountNals) |
| 569 | *pCountNals = iCountNumNals; | 569 | *pCountNals = iCountNumNals; |
| 570 | return 0; | 570 | return 0; |
| 571 | } | 571 | } |
| 572 | 572 | ||
| 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 | |||
| 624 | static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, const int32_t kiDlayerId, | 573 | static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, const int32_t kiDlayerId, |
| 625 | const int32_t kiMaxMbNum) { | 574 | const int32_t kiMaxMbNum) { |
| 626 | int32_t iMbWidth = pLayer->iMbWidth; | 575 | int32_t iMbWidth = pLayer->iMbWidth; |
| @@ -846,12 +795,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 219 unmodified lines | |||
| 846 | ++ iDlayerIndex; | 795 | ++ iDlayerIndex; |
| 847 | } | 796 | } |
| 848 | 797 | ||
| 849 | // for I420 based source spatial pictures | ||
| 850 | if (AllocSpatialPictures (*ppCtx, pParam)) { | ||
| 851 | FreeMemorySvc (ppCtx); | ||
| 852 | return 1; | ||
| 853 | } | ||
| 854 | |||
| 855 | iDlayerIndex = 0; | 798 | iDlayerIndex = 0; |
| 856 | while (iDlayerIndex < iDlayerCount) { | 799 | while (iDlayerIndex < iDlayerCount) { |
| 857 | SDqLayer* pDqLayer = NULL; | 800 | SDqLayer* pDqLayer = NULL; |
| @@ -1703,8 +1646,6 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 845 unmodified lines | |||
| 1703 | pMa->WelsFree (pCtx->ppDqLayerList, "ppDqLayerList"); | 1646 | pMa->WelsFree (pCtx->ppDqLayerList, "ppDqLayerList"); |
| 1704 | pCtx->ppDqLayerList = NULL; | 1647 | pCtx->ppDqLayerList = NULL; |
| 1705 | } | 1648 | } |
| 1706 | FreeSpatialPictures (pCtx); | ||
| 1707 | |||
| 1708 | // reference picture list extension | 1649 | // reference picture list extension |
| 1709 | if (NULL != pCtx->ppRefPicListExt && pParam != NULL) { | 1650 | if (NULL != pCtx->ppRefPicListExt && pParam != NULL) { |
| 1710 | ilayer = 0; | 1651 | ilayer = 0; |
| @@ -2126,10 +2067,16 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 415 unmodified lines | |||
| 2126 | 2067 | ||
| 2127 | pCtx->pVpp = new CWelsPreProcess (pCtx); | 2068 | pCtx->pVpp = new CWelsPreProcess (pCtx); |
| 2128 | if (pCtx->pVpp == NULL) { | 2069 | if (pCtx->pVpp == NULL) { |
| 2070 | iRet = 1; | ||
| 2129 | WelsLog (pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().\n"); | 2071 | WelsLog (pCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().\n"); |
| 2130 | FreeMemorySvc (&pCtx); | 2072 | FreeMemorySvc (&pCtx); |
| 2131 | return iRet; | 2073 | return iRet; |
| 2132 | } | 2074 | } |
| 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 | } | ||
| 2133 | 2080 | ||
| 2134 | #if defined(MEMORY_MONITOR) | 2081 | #if defined(MEMORY_MONITOR) |
| 2135 | WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n", | 2082 | WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n", |
| @@ -2286,6 +2233,7 @@ void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) { · 150 unmodified lines | |||
| 2286 | #endif//MT_ENABLED | 2233 | #endif//MT_ENABLED |
| 2287 | 2234 | ||
| 2288 | if ((*ppCtx)->pVpp) { | 2235 | if ((*ppCtx)->pVpp) { |
| 2236 | (*ppCtx)->pVpp->FreeSpatialPictures(*ppCtx); | ||
| 2289 | delete (*ppCtx)->pVpp; | 2237 | delete (*ppCtx)->pVpp; |
| 2290 | (*ppCtx)->pVpp = NULL; | 2238 | (*ppCtx)->pVpp = NULL; |
| 2291 | } | 2239 | } |
| @@ -3747,23 +3695,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 1455 unmodified lines | |||
| 3747 | pCtx->bLongTermRefFlag[d_idx][0] = true; | 3695 | pCtx->bLongTermRefFlag[d_idx][0] = true; |
| 3748 | } | 3696 | } |
| 3749 | 3697 | ||
| 3750 | if (iCurTid < pCtx->uiSpatialLayersInTemporal[d_idx] - 1 || pSvcParam->iDecompStages == 0) { | 3698 | if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){ |
| 3751 | if ((iCurTid >= MAX_TEMPORAL_LEVEL) || (pCtx->uiSpatialLayersInTemporal[d_idx] - 1 > MAX_TEMPORAL_LEVEL)) { | 3699 | ForceCodingIDR(pCtx); |
| 3752 | ForceCodingIDR (pCtx); // some logic error | 3700 | return -1; |
| 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 | } | ||
| 3767 | } | 3701 | } |
| 3768 | 3702 | ||
| 3769 | if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag | 3703 | if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag |