Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 1 file). Show all
Unified · Split
| @@ -205,7 +205,8 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 204 unmodified lines | ||
| 205 | 205 | SSliceCtx* pSliceCtx = pCurDqLayer->pSliceEncCtx; |
| 206 | 206 | const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame; |
| 207 | 207 | const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame; |
| 208 | − int32_t iMinimalMbNum = pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required | |
| 208 | + int32_t iMinimalMbNum = | |
| 209 | + pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required | |
| 209 | 210 | int32_t iMaximalMbNum = 0; // dynamically assign later |
| 210 | 211 | int32_t* pSliceComplexRatio = (int32_t*)pComplexRatio; |
| 211 | 212 | int32_t iMbNumLeft = kiCountNumMb; |
| @@ -348,7 +349,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 136 unmodified lines | ||
| 348 | 349 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx)) |
| 349 | 350 | (*ppCtx)->pSliceThreading = pSmt; |
| 350 | 351 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, |
| 351 | − "pThreadPEncCtx"); | |
| 352 | + "pThreadPEncCtx"); | |
| 352 | 353 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) |
| 353 | 354 | |
| 354 | 355 | #ifdef _WIN32 |
| @@ -375,7 +376,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 20 unmodified lines | ||
| 375 | 376 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 376 | 377 | } |
| 377 | 378 | |
| 378 | − if ( pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) { | |
| 379 | + if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) { | |
| 379 | 380 | bWillUseTaskManage = true; |
| 380 | 381 | } |
| 381 | 382 | ++ iIdx; |
| @@ -452,11 +453,11 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 70 unmodified lines | ||
| 452 | 453 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 453 | 454 | |
| 454 | 455 | if (bWillUseTaskManage) { |
| 455 | − (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage(*ppCtx, iNumSpatialLayers, bDynamicSlice); | |
| 456 | + (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice); | |
| 456 | 457 | WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx)) |
| 457 | 458 | } |
| 458 | 459 | |
| 459 | − memset(&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof(bool)); | |
| 460 | + memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool)); | |
| 460 | 461 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); |
| 461 | 462 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 462 | 463 | |
| @@ -527,7 +528,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 64 unmodified lines | ||
| 527 | 528 | pSmt->pThreadBsBuffer[i] = NULL; |
| 528 | 529 | } |
| 529 | 530 | } |
| 530 | − memset(&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof(bool)); | |
| 531 | + memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool)); | |
| 531 | 532 | |
| 532 | 533 | pSliceB = (*ppCtx)->pSliceBs; |
| 533 | 534 | iIdx = 0; |
| @@ -752,8 +753,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 218 unmodified lines | ||
| 752 | 753 | pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; |
| 753 | 754 | |
| 754 | 755 | bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) && |
| 755 | − pCodingParam->iMultipleThreadIdc > 1 && | |
| 756 | − pCodingParam->iMultipleThreadIdc >= pParamD->sSliceArgument.uiSliceNum); | |
| 756 | + pCodingParam->iMultipleThreadIdc > 1 && | |
| 757 | + pCodingParam->iMultipleThreadIdc >= pParamD->sSliceArgument.uiSliceNum); | |
| 757 | 758 | if (bDsaFlag) |
| 758 | 759 | iSliceStart = WelsTime(); |
| 759 | 760 | |
| @@ -812,7 +813,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 52 unmodified lines | ||
| 812 | 813 | if (bDsaFlag) { |
| 813 | 814 | pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) ( |
| 814 | 815 | WelsTime() - iSliceStart); |
| 815 | − MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 816 | + MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 816 | 817 | "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d", |
| 817 | 818 | pEncPEncCtx->iCodingIndex, iSliceIdx, |
| 818 | 819 | pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize, |
| @@ -848,7 +849,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 29 unmodified lines | ||
| 848 | 849 | iSliceIdx = pPrivateData->iSliceIndex; |
| 849 | 850 | |
| 850 | 851 | pSliceCtx->pFirstMbInSlice[iSliceIdx] = kiFirstMbInPartition; |
| 851 | − pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; // one pSlice per partition intialized, dynamic slicing inside | |
| 852 | + pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = | |
| 853 | + 1; // one pSlice per partition intialized, dynamic slicing inside | |
| 852 | 854 | pCurDq->pLastMbIdxOfPartition[kiPartitionId] = kiEndMbInPartition - 1; |
| 853 | 855 | |
| 854 | 856 | pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; |
| @@ -858,9 +860,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines | ||
| 858 | 860 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage |
| 859 | 861 | // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure |
| 860 | 862 | uiThrdRet = 1; |
| 861 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 862 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 863 | − iEventIdx); | |
| 863 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 864 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 865 | + iEventIdx); | |
| 864 | 866 | } |
| 865 | 867 | |
| 866 | 868 | SetOneSliceBsBufferUnderMultithread (pEncPEncCtx, kiPartitionId, iSliceIdx); |
| @@ -889,24 +891,24 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 22 unmodified lines | ||
| 889 | 891 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); |
| 890 | 892 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 891 | 893 | uiThrdRet = iReturn; |
| 892 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 893 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 894 | − iEventIdx); | |
| 894 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 895 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 896 | + iEventIdx); | |
| 895 | 897 | } |
| 896 | 898 | |
| 897 | 899 | WelsUnloadNalForSlice (pSliceBs); |
| 898 | 900 | |
| 899 | 901 | if (0 == iSliceIdx) { |
| 900 | 902 | iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf, |
| 901 | − &pLbi->pNalLengthInByte[pLbi->iNalCount], | |
| 902 | − pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer, | |
| 903 | − iSliceIdx, iSliceSize); | |
| 903 | + &pLbi->pNalLengthInByte[pLbi->iNalCount], | |
| 904 | + pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer, | |
| 905 | + iSliceIdx, iSliceSize); | |
| 904 | 906 | pLbi->iNalCount += pSliceBs->iNalIndex; |
| 905 | 907 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 906 | 908 | uiThrdRet = iReturn; |
| 907 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 908 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 909 | − iEventIdx); | |
| 909 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 910 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 911 | + iEventIdx); | |
| 910 | 912 | } |
| 911 | 913 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 912 | 914 | } else { |
| @@ -915,9 +917,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 2 unmodified lines | ||
| 915 | 917 | iSliceIdx, iSliceSize); |
| 916 | 918 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 917 | 919 | uiThrdRet = iReturn; |
| 918 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 919 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 920 | − iEventIdx); | |
| 920 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 921 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 922 | + iEventIdx); | |
| 921 | 923 | } |
| 922 | 924 | } |
| 923 | 925 | |
| @@ -942,11 +944,10 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 18 unmodified lines | ||
| 942 | 944 | iSliceIdx += kiSliceIdxStep; |
| 943 | 945 | } |
| 944 | 946 | |
| 945 | − if (uiThrdRet) // any exception?? | |
| 946 | − { | |
| 947 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 948 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 949 | − iEventIdx); | |
| 947 | + if (uiThrdRet) { // any exception?? | |
| 948 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 949 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 950 | + iEventIdx); | |
| 950 | 951 | } |
| 951 | 952 | |
| 952 | 953 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| @@ -1060,7 +1061,8 @@ int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { · 107 unmodified lines | ||
| 1060 | 1061 | #endif//MT_DEBUG |
| 1061 | 1062 | |
| 1062 | 1063 | pCtx->pCurDqLayer = pCurDq; |
| 1063 | − memcpy((pCtx->pSliceThreading->pSliceConsumeTime[0]), (pCurDq->pSliceEncCtx->pSliceConsumeTime), pCurDq->pSliceEncCtx->iSliceNumInFrame*sizeof(uint32_t)); | |
| 1064 | + memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[0]), (pCurDq->pSliceEncCtx->pSliceConsumeTime), | |
| 1065 | + pCurDq->pSliceEncCtx->iSliceNumInFrame * sizeof (uint32_t)); | |
| 1064 | 1066 | // do not need adjust due to not different at both slices of consumed time |
| 1065 | 1067 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->pSliceEncCtx->iSliceNumInFrame); |
| 1066 | 1068 | if (iNeedAdj) |
| @@ -1089,10 +1091,11 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 22 unmodified lines | ||
| 1089 | 1091 | // if using spatial base layer for complexity estimation |
| 1090 | 1092 | |
| 1091 | 1093 | const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0) |
| 1092 | − && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE | |
| 1093 | − && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid - | |
| 1094 | − 1].sSliceArgument.uiSliceNum); | |
| 1095 | − memcpy((pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]), (pCtx->pCurDqLayer->pSliceEncCtx->pSliceConsumeTime), pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame*sizeof(uint32_t)); | |
| 1094 | + && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE | |
| 1095 | + && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid - | |
| 1096 | + 1].sSliceArgument.uiSliceNum); | |
| 1097 | + memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]), (pCtx->pCurDqLayer->pSliceEncCtx->pSliceConsumeTime), | |
| 1098 | + pCtx->pCurDqLayer->pSliceEncCtx->iSliceNumInFrame * sizeof (uint32_t)); | |
| 1096 | 1099 | |
| 1097 | 1100 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation |
| 1098 | 1101 | // do not need adjust due to not different at both slices of consumed time |