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