Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 5 files). Show all
Unified · Split
| @@ -128,10 +128,9 @@ void UpdateMbListNeighborParallel (SDqLayer* pCurDq, · 127 unmodified lines | ||
| 128 | 128 | } while (iIdx <= kiEndMbInSlice); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | −void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq) { | |
| 131 | +void CalcSliceComplexRatio (SDqLayer* pCurDq) { | |
| 132 | 132 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; |
| 133 | 133 | SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer; |
| 134 | − int32_t* pRatioList = (int32_t*)pRatio; | |
| 135 | 134 | int32_t iSumAv = 0; |
| 136 | 135 | int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice; |
| 137 | 136 | const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame; |
| @@ -150,7 +149,7 @@ void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq) { · 12 unmodified lines | ||
| 150 | 149 | ++ iSliceIdx; |
| 151 | 150 | } |
| 152 | 151 | while (-- iSliceIdx >= 0) { |
| 153 | − pRatioList[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv); | |
| 152 | + pSliceInLayer[iSliceIdx].iSliceComplexRatio = WELS_DIV_ROUND (INT_MULTIPLY * iAvI[iSliceIdx], iSumAv); | |
| 154 | 153 | } |
| 155 | 154 | } |
| 156 | 155 | |
| @@ -205,15 +204,14 @@ int32_t NeedDynamicAdjust (SSlice* pSliceInLayer, const int32_t iSliceNum) { · 48 unmodified lines | ||
| 205 | 204 | |
| 206 | 205 | void DynamicAdjustSlicing (sWelsEncCtx* pCtx, |
| 207 | 206 | SDqLayer* pCurDqLayer, |
| 208 | − void* pComplexRatio, | |
| 209 | 207 | int32_t iCurDid) { |
| 210 | − SSliceCtx* pSliceCtx = &pCurDqLayer->sSliceEncCtx; | |
| 208 | + SSliceCtx* pSliceCtx = &pCurDqLayer->sSliceEncCtx; | |
| 209 | + SSlice* pSliceInLayer = pCurDqLayer->sLayerInfo.pSliceInLayer; | |
| 211 | 210 | const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame; |
| 212 | 211 | const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame; |
| 213 | 212 | int32_t iMinimalMbNum = |
| 214 | 213 | pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required |
| 215 | 214 | int32_t iMaximalMbNum = 0; // dynamically assign later |
| 216 | − int32_t* pSliceComplexRatio = (int32_t*)pComplexRatio; | |
| 217 | 215 | int32_t iMbNumLeft = kiCountNumMb; |
| 218 | 216 | int32_t iRunLen[MAX_THREADS_NUM] = {0}; |
| 219 | 217 | int32_t iSliceIdx = 0; |
| @@ -249,7 +247,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 29 unmodified lines | ||
| 249 | 247 | |
| 250 | 248 | iSliceIdx = 0; |
| 251 | 249 | while (iSliceIdx + 1 < kiCountSliceNum) { |
| 252 | − int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceComplexRatio[iSliceIdx], INT_MULTIPLY); | |
| 250 | + int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceInLayer[iSliceIdx].iSliceComplexRatio, INT_MULTIPLY); | |
| 253 | 251 | |
| 254 | 252 | // GOM boundary aligned |
| 255 | 253 | if (pCtx->pSvcParam->iRCMode != RC_OFF_MODE) { |
| @@ -271,16 +269,18 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 15 unmodified lines | ||
| 271 | 269 | } |
| 272 | 270 | iRunLen[iSliceIdx] = iNumMbAssigning; |
| 273 | 271 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, |
| 274 | − "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", | |
| 275 | − iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], | |
| 272 | + "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", | |
| 273 | + iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY, | |
| 274 | + pSliceCtx->pCountMbNumInSlice[iSliceIdx], | |
| 276 | 275 | iNumMbAssigning); |
| 277 | 276 | ++ iSliceIdx; |
| 278 | 277 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts |
| 279 | 278 | } |
| 280 | 279 | iRunLen[iSliceIdx] = iMbNumLeft; |
| 281 | 280 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, |
| 282 | − "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", | |
| 283 | − iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft); | |
| 281 | + "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, iSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", | |
| 282 | + iSliceIdx, pSliceInLayer[iSliceIdx].iSliceComplexRatio * 1.0f / INT_MULTIPLY, | |
| 283 | + pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft); | |
| 284 | 284 | |
| 285 | 285 | |
| 286 | 286 | if (DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen) == 0) { |
| @@ -367,18 +367,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 80 unmodified lines | ||
| 367 | 367 | iIdx = 0; |
| 368 | 368 | while (iIdx < iNumSpatialLayers) { |
| 369 | 369 | SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[iIdx].sSliceArgument; |
| 370 | − const int32_t kiSliceNum = pSliceArgument->uiSliceNum; | |
| 371 | − if ((pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE) | |
| 372 | − && (pPara->bUseLoadBalancing) | |
| 373 | − && (pPara->iMultipleThreadIdc > 1) | |
| 374 | − && (pPara->iMultipleThreadIdc >= kiSliceNum)) { | |
| 375 | − pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]"); | |
| 376 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) | |
| 377 | − } else { | |
| 378 | − pSmt->pSliceComplexRatio[iIdx] = NULL; | |
| 379 | − } | |
| 380 | − | |
| 381 | − if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) { | |
| 370 | + if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE) { | |
| 382 | 371 | bWillUseTaskManage = true; |
| 383 | 372 | } |
| 384 | 373 | ++ iIdx; |
| @@ -474,7 +463,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 89 unmodified lines | ||
| 474 | 463 | |
| 475 | 464 | void ReleaseMtResource (sWelsEncCtx** ppCtx) { |
| 476 | 465 | SWelsSliceBs* pSliceB = NULL; |
| 477 | − SWelsSvcCodingParam* pCodingParam = NULL; | |
| 478 | 466 | SSliceThreading* pSmt = NULL; |
| 479 | 467 | CMemoryAlign* pMa = NULL; |
| 480 | 468 | int32_t iIdx = 0; |
| @@ -485,7 +473,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 4 unmodified lines | ||
| 485 | 473 | return; |
| 486 | 474 | |
| 487 | 475 | pMa = (*ppCtx)->pMemAlign; |
| 488 | − pCodingParam = (*ppCtx)->pSvcParam; | |
| 489 | 476 | uiSliceNum = (*ppCtx)->iMaxSliceCount; |
| 490 | 477 | iThreadNum = (*ppCtx)->pSvcParam->iCountThreadsNum; |
| 491 | 478 | pSmt = (*ppCtx)->pSliceThreading; |
| @@ -550,15 +537,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 58 unmodified lines | ||
| 550 | 537 | (*ppCtx)->pTaskManage = NULL; |
| 551 | 538 | } |
| 552 | 539 | |
| 553 | − iIdx = 0; | |
| 554 | − while (iIdx < pCodingParam->iSpatialLayerNum) { | |
| 555 | − if (pSmt->pSliceComplexRatio[iIdx] != NULL) { | |
| 556 | − pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]"); | |
| 557 | − pSmt->pSliceComplexRatio[iIdx] = NULL; | |
| 558 | − } | |
| 559 | − ++ iIdx; | |
| 560 | − } | |
| 561 | − | |
| 562 | 540 | #ifdef MT_DEBUG |
| 563 | 541 | // file handle for debug |
| 564 | 542 | if (pSmt->pFSliceDiff) { |
| @@ -1067,7 +1045,6 @@ int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { · 502 unmodified lines | ||
| 1067 | 1045 | if (iNeedAdj) |
| 1068 | 1046 | DynamicAdjustSlicing (pCtx, |
| 1069 | 1047 | pCurDq, |
| 1070 | − pCtx->pSliceThreading->pSliceComplexRatio[0], | |
| 1071 | 1048 | 0); |
| 1072 | 1049 | #ifdef MT_DEBUG |
| 1073 | 1050 | iT0 = WelsTime() - iT0; |
| @@ -1101,7 +1078,6 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 27 unmodified lines | ||
| 1101 | 1078 | if (iNeedAdj) |
| 1102 | 1079 | DynamicAdjustSlicing (pCtx, |
| 1103 | 1080 | pCtx->pCurDqLayer, |
| 1104 | − pCtx->pSliceThreading->pSliceComplexRatio[iCurDid - 1], | |
| 1105 | 1081 | iCurDid |
| 1106 | 1082 | ); |
| 1107 | 1083 | } else { // use temporal layer for complexity estimation |
| @@ -1111,7 +1087,6 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 3 unmodified lines | ||
| 1111 | 1087 | if (iNeedAdj) |
| 1112 | 1088 | DynamicAdjustSlicing (pCtx, |
| 1113 | 1089 | pCtx->pCurDqLayer, |
| 1114 | − pCtx->pSliceThreading->pSliceComplexRatio[iCurDid], | |
| 1115 | 1090 | iCurDid |
| 1116 | 1091 | ); |
| 1117 | 1092 | } |
| @@ -1133,11 +1108,12 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 15 unmodified lines | ||
| 1133 | 1108 | #if defined(MT_DEBUG) |
| 1134 | 1109 | void TrackSliceComplexities (sWelsEncCtx* pCtx, const int32_t iCurDid) { |
| 1135 | 1110 | const int32_t kiCountSliceNum = pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame; |
| 1111 | + SSlice* pSliceInLayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer; | |
| 1136 | 1112 | if (kiCountSliceNum > 0) { |
| 1137 | 1113 | int32_t iSliceIdx = 0; |
| 1138 | 1114 | do { |
| 1139 | 1115 | fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6.3f complexity pRatio at iDid %d pSlice %d\n", |
| 1140 | − pCtx->pSliceThreading->pSliceComplexRatio[iCurDid][iSliceIdx], iCurDid, iSliceIdx); | |
| 1116 | + pSliceInLayer[iSliceIdx].iSliceComplexRatio, iCurDid, iSliceIdx); | |
| 1141 | 1117 | ++ iSliceIdx; |
| 1142 | 1118 | } while (iSliceIdx < kiCountSliceNum); |
| 1143 | 1119 | } |