Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 120 files). Show all
Unified · Split
| @@ -711,8 +711,8 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 710 unmodified lines | ||
| 711 | 711 | const int32_t kiFeatureStrategyIndex = FME_DEFAULT_FEATURE_INDEX; |
| 712 | 712 | const int32_t kiMe16x16 = ME_DIA_CROSS; |
| 713 | 713 | const int32_t kiMe8x8 = ME_DIA_CROSS_FME; |
| 714 | − const int32_t kiNeedFeatureStorage = (pParam->iUsageType != SCREEN_CONTENT_REAL_TIME)?0: | |
| 715 | − ((kiFeatureStrategyIndex<<16) + ((kiMe16x16 & 0x00FF)<<8) + (kiMe8x8 & 0x00FF)); | |
| 714 | + const int32_t kiNeedFeatureStorage = (pParam->iUsageType != SCREEN_CONTENT_REAL_TIME) ? 0 : | |
| 715 | + ((kiFeatureStrategyIndex << 16) + ((kiMe16x16 & 0x00FF) << 8) + (kiMe8x8 & 0x00FF)); | |
| 716 | 716 | |
| 717 | 717 | iDlayerIndex = 0; |
| 718 | 718 | while (iDlayerIndex < iDlayerCount) { |
| @@ -733,7 +733,8 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 14 unmodified lines | ||
| 733 | 733 | pRefList = (SRefList*)pMa->WelsMallocz (sizeof (SRefList), "pRefList"); |
| 734 | 734 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList), FreeMemorySvc (ppCtx)) |
| 735 | 735 | do { |
| 736 | − pRefList->pRef[i] = AllocPicture (pMa, kiWidth, kiHeight, true, (iDlayerIndex == iDlayerCount-1)?kiNeedFeatureStorage:0); // to use actual size of current layer | |
| 736 | + pRefList->pRef[i] = AllocPicture (pMa, kiWidth, kiHeight, true, | |
| 737 | + (iDlayerIndex == iDlayerCount - 1) ? kiNeedFeatureStorage : 0); // to use actual size of current layer | |
| 737 | 738 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pRefList->pRef[i]), FreeMemorySvc (ppCtx)) |
| 738 | 739 | ++ i; |
| 739 | 740 | } while (i < 1 + iNumRef); |
| @@ -831,13 +832,14 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx) { · 91 unmodified lines | ||
| 831 | 832 | } |
| 832 | 833 | |
| 833 | 834 | // |
| 834 | − if (kiNeedFeatureStorage && iDlayerIndex==iDlayerCount-1) | |
| 835 | − { | |
| 836 | − pDqLayer->pFeatureSearchPreparation = static_cast<SFeatureSearchPreparation*> (pMa->WelsMallocz (sizeof (SFeatureSearchPreparation), "pFeatureSearchPreparation")); | |
| 837 | − WELS_VERIFY_RETURN_PROC_IF (1, NULL==pDqLayer->pFeatureSearchPreparation, FreeMemorySvc (ppCtx)); | |
| 838 | − int32_t iReturn = RequestFeatureSearchPreparation(pMa, pDlayer->iFrameWidth, pDlayer->iFrameHeight, kiNeedFeatureStorage, | |
| 839 | − pDqLayer->pFeatureSearchPreparation); | |
| 840 | − WELS_VERIFY_RETURN_PROC_IF (1, ENC_RETURN_SUCCESS!=iReturn, FreeMemorySvc (ppCtx)); | |
| 835 | + if (kiNeedFeatureStorage && iDlayerIndex == iDlayerCount - 1) { | |
| 836 | + pDqLayer->pFeatureSearchPreparation = static_cast<SFeatureSearchPreparation*> (pMa->WelsMallocz (sizeof ( | |
| 837 | + SFeatureSearchPreparation), "pFeatureSearchPreparation")); | |
| 838 | + WELS_VERIFY_RETURN_PROC_IF (1, NULL == pDqLayer->pFeatureSearchPreparation, FreeMemorySvc (ppCtx)); | |
| 839 | + int32_t iReturn = RequestFeatureSearchPreparation (pMa, pDlayer->iFrameWidth, pDlayer->iFrameHeight, | |
| 840 | + kiNeedFeatureStorage, | |
| 841 | + pDqLayer->pFeatureSearchPreparation); | |
| 842 | + WELS_VERIFY_RETURN_PROC_IF (1, ENC_RETURN_SUCCESS != iReturn, FreeMemorySvc (ppCtx)); | |
| 841 | 843 | } else { |
| 842 | 844 | pDqLayer->pFeatureSearchPreparation = NULL; |
| 843 | 845 | } |
| @@ -1363,19 +1365,19 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 519 unmodified lines | ||
| 1363 | 1365 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pWelsSvcRc), FreeMemorySvc (ppCtx)) |
| 1364 | 1366 | //End of Rate control module memory allocation |
| 1365 | 1367 | |
| 1366 | − //pVaa memory allocation | |
| 1367 | − if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { | |
| 1368 | − (*ppCtx)->pVaa = (SVAAFrameInfoExt*)pMa->WelsMallocz (sizeof (SVAAFrameInfoExt), "pVaa"); | |
| 1369 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx)) | |
| 1370 | − if(RequestMemoryVaaScreen ((*ppCtx)->pVaa, pMa, (*ppCtx)->pSvcParam->iNumRefFrame, iCountMaxMbNum << 2)){ | |
| 1371 | − WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMemoryVaaScreen failed!"); | |
| 1372 | − FreeMemorySvc (ppCtx); | |
| 1373 | − return 1; | |
| 1374 | − } | |
| 1375 | − } else { | |
| 1376 | − (*ppCtx)->pVaa = (SVAAFrameInfo*)pMa->WelsMallocz (sizeof (SVAAFrameInfo), "pVaa"); | |
| 1377 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx)) | |
| 1368 | + //pVaa memory allocation | |
| 1369 | + if (pParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { | |
| 1370 | + (*ppCtx)->pVaa = (SVAAFrameInfoExt*)pMa->WelsMallocz (sizeof (SVAAFrameInfoExt), "pVaa"); | |
| 1371 | + WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx)) | |
| 1372 | + if (RequestMemoryVaaScreen ((*ppCtx)->pVaa, pMa, (*ppCtx)->pSvcParam->iNumRefFrame, iCountMaxMbNum << 2)) { | |
| 1373 | + WelsLog (*ppCtx, WELS_LOG_WARNING, "RequestMemorySvc(), RequestMemoryVaaScreen failed!"); | |
| 1374 | + FreeMemorySvc (ppCtx); | |
| 1375 | + return 1; | |
| 1378 | 1376 | } |
| 1377 | + } else { | |
| 1378 | + (*ppCtx)->pVaa = (SVAAFrameInfo*)pMa->WelsMallocz (sizeof (SVAAFrameInfo), "pVaa"); | |
| 1379 | + WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pVaa), FreeMemorySvc (ppCtx)) | |
| 1380 | + } | |
| 1379 | 1381 | |
| 1380 | 1382 | if ((*ppCtx)->pSvcParam->bEnableAdaptiveQuant) { //malloc mem |
| 1381 | 1383 | (*ppCtx)->pVaa->sAdaptiveQuantParam.pMotionTextureUnit = static_cast<SMotionTextureUnit*> |
| @@ -1585,7 +1587,7 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 203 unmodified lines | ||
| 1585 | 1587 | } |
| 1586 | 1588 | |
| 1587 | 1589 | if (pDq->pFeatureSearchPreparation) { |
| 1588 | − ReleaseFeatureSearchPreparation(pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock); | |
| 1590 | + ReleaseFeatureSearchPreparation (pMa, pDq->pFeatureSearchPreparation->pFeatureOfBlock); | |
| 1589 | 1591 | pMa->WelsFree (pDq->pFeatureSearchPreparation, "pFeatureSearchPreparation"); |
| 1590 | 1592 | pDq->pFeatureSearchPreparation = NULL; |
| 1591 | 1593 | } |
| @@ -1663,8 +1665,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 71 unmodified lines | ||
| 1663 | 1665 | pMa->WelsFree (pCtx->pVaa->sVaaCalcInfo.pMad8x8, "pVaa->sVaaCalcInfo.pMad8x8"); |
| 1664 | 1666 | pCtx->pVaa->sVaaCalcInfo.pMad8x8 = NULL; |
| 1665 | 1667 | } |
| 1666 | − if(pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 1667 | − ReleaseMemoryVaaScreen(pCtx->pVaa, pMa,pCtx->pSvcParam->iNumRefFrame); | |
| 1668 | + if (pCtx->pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) | |
| 1669 | + ReleaseMemoryVaaScreen (pCtx->pVaa, pMa, pCtx->pSvcParam->iNumRefFrame); | |
| 1668 | 1670 | pMa->WelsFree (pCtx->pVaa, "pVaa"); |
| 1669 | 1671 | pCtx->pVaa = NULL; |
| 1670 | 1672 | } |
| @@ -2456,19 +2458,20 @@ void PreprocessSliceCoding (sWelsEncCtx* pCtx) { · 785 unmodified lines | ||
| 2456 | 2458 | |
| 2457 | 2459 | if (P_SLICE == pCtx->eSliceType) { |
| 2458 | 2460 | //calculate bFMESwitchFlag |
| 2459 | − SVAAFrameInfoExt *pVaaExt = static_cast<SVAAFrameInfoExt *>(pCtx->pVaa); | |
| 2460 | − const int32_t kiMbSize = pCurLayer->iMbHeight*pCurLayer->iMbWidth; | |
| 2461 | − pFeatureSearchPreparation->bFMESwitchFlag = CalcFMESwitchFlag( pFeatureSearchPreparation->uiFMEGoodFrameCount, | |
| 2462 | − pFeatureSearchPreparation->iHighFreMbCount*100/kiMbSize, pCtx->pVaa->sVaaCalcInfo.iFrameSad/kiMbSize, | |
| 2463 | − pVaaExt->sScrollDetectInfo.bScrollDetectFlag); | |
| 2461 | + SVAAFrameInfoExt* pVaaExt = static_cast<SVAAFrameInfoExt*> (pCtx->pVaa); | |
| 2462 | + const int32_t kiMbSize = pCurLayer->iMbHeight * pCurLayer->iMbWidth; | |
| 2463 | + pFeatureSearchPreparation->bFMESwitchFlag = CalcFMESwitchFlag (pFeatureSearchPreparation->uiFMEGoodFrameCount, | |
| 2464 | + pFeatureSearchPreparation->iHighFreMbCount * 100 / kiMbSize, pCtx->pVaa->sVaaCalcInfo.iFrameSad / kiMbSize, | |
| 2465 | + pVaaExt->sScrollDetectInfo.bScrollDetectFlag); | |
| 2464 | 2466 | |
| 2465 | 2467 | //PerformFMEPreprocess |
| 2466 | 2468 | SScreenBlockFeatureStorage* pScreenBlockFeatureStorage = pCurLayer->pRefPic->pScreenBlockFeatureStorage; |
| 2467 | 2469 | pFeatureSearchPreparation->pRefBlockFeature = pScreenBlockFeatureStorage; |
| 2468 | 2470 | if (pFeatureSearchPreparation->bFMESwitchFlag |
| 2469 | − && !pScreenBlockFeatureStorage->bRefBlockFeatureCalculated) { | |
| 2470 | − //TODO: use ORIGIN of reference when preprocessing is ready | |
| 2471 | − PerformFMEPreprocess( pFuncList, pCurLayer->pRefPic,pFeatureSearchPreparation->pFeatureOfBlock,pScreenBlockFeatureStorage); | |
| 2471 | + && !pScreenBlockFeatureStorage->bRefBlockFeatureCalculated) { | |
| 2472 | + //TODO: use ORIGIN of reference when preprocessing is ready | |
| 2473 | + PerformFMEPreprocess (pFuncList, pCurLayer->pRefPic, pFeatureSearchPreparation->pFeatureOfBlock, | |
| 2474 | + pScreenBlockFeatureStorage); | |
| 2472 | 2475 | } |
| 2473 | 2476 | |
| 2474 | 2477 | //assign ME pointer |
| @@ -3011,9 +3014,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 536 unmodified lines | ||
| 3011 | 3014 | #ifdef LONG_TERM_REF_DUMP |
| 3012 | 3015 | DumpRef (pCtx); |
| 3013 | 3016 | #endif |
| 3014 | − if((pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME)&&(pSvcParam->iRCMode != RC_OFF_MODE)) | |
| 3015 | − pCtx->pVpp->AnalyzePictureComplexity(pCtx,pCtx->pEncPic,((pCtx->eSliceType == P_SLICE)&&(pCtx->iNumRef0>0))?pCtx->pRefList0[0]:NULL, | |
| 3016 | − iCurDid,pSvcParam->bEnableBackgroundDetection); | |
| 3017 | + if ((pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) && (pSvcParam->iRCMode != RC_OFF_MODE)) | |
| 3018 | + pCtx->pVpp->AnalyzePictureComplexity (pCtx, pCtx->pEncPic, ((pCtx->eSliceType == P_SLICE) | |
| 3019 | + && (pCtx->iNumRef0 > 0)) ? pCtx->pRefList0[0] : NULL, | |
| 3020 | + iCurDid, pSvcParam->bEnableBackgroundDetection); | |
| 3017 | 3021 | |
| 3018 | 3022 | WelsUpdateRefSyntax (pCtx, pCtx->iPOC, |
| 3019 | 3023 | eFrameType); //get reordering syntax used for writing slice header and transmit to encoder. |
| @@ -3093,8 +3097,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 73 unmodified lines | ||
| 3093 | 3097 | pCtx->iActiveThreadsNum = iSliceCount; |
| 3094 | 3098 | // to fire slice coding threads |
| 3095 | 3099 | iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0], |
| 3096 | − &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3097 | − pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false); | |
| 3100 | + &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3101 | + pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false); | |
| 3098 | 3102 | if (iRet) { |
| 3099 | 3103 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3100 | 3104 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |
| @@ -3132,8 +3136,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 31 unmodified lines | ||
| 3132 | 3136 | iNumThreadsRunning = iNumThreadsScheduled; |
| 3133 | 3137 | // to fire slice coding threads |
| 3134 | 3138 | iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0], |
| 3135 | − &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3136 | − pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false); | |
| 3139 | + &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3140 | + pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false); | |
| 3137 | 3141 | if (iRet) { |
| 3138 | 3142 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3139 | 3143 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |
| @@ -3178,8 +3182,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 38 unmodified lines | ||
| 3178 | 3182 | |
| 3179 | 3183 | // to fire slice coding threads |
| 3180 | 3184 | iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0], |
| 3181 | − &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3182 | − pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true); | |
| 3185 | + &pCtx->pSliceThreading->pThreadMasterEvent[0], | |
| 3186 | + pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true); | |
| 3183 | 3187 | if (iRet) { |
| 3184 | 3188 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3185 | 3189 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |