Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 8 files). Show all
Unified · Split
| @@ -128,23 +128,23 @@ void UpdateMbListNeighborParallel (SDqLayer* pCurDq, · 127 unmodified lines | ||
| 128 | 128 | } while (iIdx <= kiEndMbInSlice); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | −void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq, uint32_t* pSliceConsume) { | |
| 131 | +void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq) { | |
| 132 | 132 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; |
| 133 | + SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer; | |
| 133 | 134 | int32_t* pRatioList = (int32_t*)pRatio; |
| 134 | − int32_t iAvI[MAX_SLICES_NUM]; | |
| 135 | 135 | int32_t iSumAv = 0; |
| 136 | − uint32_t* pSliceTime = (uint32_t*)pSliceConsume; | |
| 137 | 136 | int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice; |
| 138 | 137 | const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame; |
| 139 | 138 | int32_t iSliceIdx = 0; |
| 139 | + int32_t iAvI[MAX_SLICES_NUM]; | |
| 140 | 140 | |
| 141 | 141 | WelsEmms(); |
| 142 | 142 | |
| 143 | 143 | while (iSliceIdx < kiSliceCount) { |
| 144 | − iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pCountMbInSlice[iSliceIdx], pSliceTime[iSliceIdx]); | |
| 145 | − MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d", | |
| 144 | + iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pCountMbInSlice[iSliceIdx], pSliceInLayer[iSliceIdx].uiSliceConsumeTime); | |
| 145 | + MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), uiSliceConsumeTime[%d]= %d us, slice_run= %d", | |
| 146 | 146 | iSliceIdx, |
| 147 | − pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | |
| 147 | + pSliceInLayer[iSliceIdx].uiSliceConsumeTime, pCountMbInSlice[iSliceIdx]); | |
| 148 | 148 | iSumAv += iAvI[iSliceIdx]; |
| 149 | 149 | |
| 150 | 150 | ++ iSliceIdx; |
| @@ -154,8 +154,10 @@ void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq, uint32_t* pSliceCons · 3 unmodified lines | ||
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | −int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { | |
| 158 | − uint32_t* pSliceConsume = (uint32_t*)pConsumeTime; | |
| 157 | +int32_t NeedDynamicAdjust (SSlice* pSliceInLayer, const int32_t iSliceNum) { | |
| 158 | + if ( NULL == pSliceInLayer ) | |
| 159 | + return false; | |
| 160 | + | |
| 159 | 161 | uint32_t uiTotalConsume = 0; |
| 160 | 162 | int32_t iSliceIdx = 0; |
| 161 | 163 | int32_t iNeedAdj = false; |
| @@ -163,7 +165,7 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 1 unmodified line | ||
| 163 | 165 | WelsEmms(); |
| 164 | 166 | |
| 165 | 167 | while (iSliceIdx < iSliceNum) { |
| 166 | − uiTotalConsume += pSliceConsume[iSliceIdx]; | |
| 168 | + uiTotalConsume += pSliceInLayer[iSliceIdx].uiSliceConsumeTime; | |
| 167 | 169 | iSliceIdx ++; |
| 168 | 170 | } |
| 169 | 171 | if (uiTotalConsume == 0) { |
| @@ -178,7 +180,7 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 8 unmodified lines | ||
| 178 | 180 | float fRmse = .0f; // root mean square error of pSlice consume ratios |
| 179 | 181 | const float kfMeanRatio = 1.0f / iSliceNum; |
| 180 | 182 | do { |
| 181 | − const float fRatio = 1.0f * pSliceConsume[iSliceIdx] / uiTotalConsume; | |
| 183 | + const float fRatio = 1.0f * pSliceInLayer[iSliceIdx].uiSliceConsumeTime / uiTotalConsume; | |
| 182 | 184 | const float fDiffRatio = fRatio - kfMeanRatio; |
| 183 | 185 | fRmse += (fDiffRatio * fDiffRatio); |
| 184 | 186 | ++ iSliceIdx; |
| @@ -370,12 +372,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 185 unmodified lines | ||
| 370 | 372 | && (pPara->bUseLoadBalancing) |
| 371 | 373 | && (pPara->iMultipleThreadIdc > 1) |
| 372 | 374 | && (pPara->iMultipleThreadIdc >= kiSliceNum)) { |
| 373 | − pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); | |
| 374 | − WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) | |
| 375 | 375 | pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]"); |
| 376 | 376 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) |
| 377 | 377 | } else { |
| 378 | − pSmt->pSliceConsumeTime[iIdx] = NULL; | |
| 379 | 378 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 380 | 379 | } |
| 381 | 380 | |
| @@ -384,7 +383,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines | ||
| 384 | 383 | } |
| 385 | 384 | ++ iIdx; |
| 386 | 385 | } |
| 387 | − // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS | |
| 388 | 386 | |
| 389 | 387 | #ifdef MT_DEBUG |
| 390 | 388 | // file handle for MT debug |
| @@ -554,11 +552,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 163 unmodified lines | ||
| 554 | 552 | |
| 555 | 553 | iIdx = 0; |
| 556 | 554 | while (iIdx < pCodingParam->iSpatialLayerNum) { |
| 557 | − if (pSmt->pSliceConsumeTime[iIdx]) { | |
| 558 | − pMa->WelsFree (pSmt->pSliceConsumeTime[iIdx], "pSliceConsumeTime[]"); | |
| 559 | − pSmt->pSliceConsumeTime[iIdx] = NULL; | |
| 560 | − } | |
| 561 | − if (pSmt->pSliceComplexRatio[iIdx] != NULL) { | |
| 555 | + if (pSmt->pSliceComplexRatio[iIdx] != NULL) { | |
| 562 | 556 | pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]"); |
| 563 | 557 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 564 | 558 | } |
| @@ -814,12 +808,12 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 249 unmodified lines | ||
| 814 | 808 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |
| 815 | 809 | |
| 816 | 810 | if (bDsaFlag) { |
| 817 | − pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) ( | |
| 811 | + pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime = (uint32_t) ( | |
| 818 | 812 | WelsTime() - iSliceStart); |
| 819 | 813 | MT_TRACE_LOG (& (pEncPEncCtx->sLogCtx), WELS_LOG_INFO, |
| 820 | − "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d", | |
| 814 | + "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, uiSliceConsumeTime %d, iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d", | |
| 821 | 815 | pEncPEncCtx->iCodingIndex, iSliceIdx, |
| 822 | − pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize, | |
| 816 | + pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime, iSliceSize, | |
| 823 | 817 | pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice, |
| 824 | 818 | pCurDq->sSliceEncCtx.pCountMbNumInSlice[iSliceIdx]); |
| 825 | 819 | } |
| @@ -1067,10 +1061,9 @@ int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { · 241 unmodified lines | ||
| 1067 | 1061 | #endif//MT_DEBUG |
| 1068 | 1062 | |
| 1069 | 1063 | pCtx->pCurDqLayer = pCurDq; |
| 1070 | − memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[0]), (pCurDq->sSliceEncCtx.pSliceConsumeTime), | |
| 1071 | − pCurDq->sSliceEncCtx.iSliceNumInFrame * sizeof (uint32_t)); | |
| 1064 | + | |
| 1072 | 1065 | // do not need adjust due to not different at both slices of consumed time |
| 1073 | − iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->sSliceEncCtx.iSliceNumInFrame); | |
| 1066 | + iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[0]->sLayerInfo.pSliceInLayer, pCurDq->sSliceEncCtx.iSliceNumInFrame); | |
| 1074 | 1067 | if (iNeedAdj) |
| 1075 | 1068 | DynamicAdjustSlicing (pCtx, |
| 1076 | 1069 | pCurDq, |
| @@ -1100,12 +1093,10 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 23 unmodified lines | ||
| 1100 | 1093 | && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE |
| 1101 | 1094 | && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid - |
| 1102 | 1095 | 1].sSliceArgument.uiSliceNum); |
| 1103 | − memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]), (pCtx->pCurDqLayer->sSliceEncCtx.pSliceConsumeTime), | |
| 1104 | − pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame * sizeof (uint32_t)); | |
| 1105 | 1096 | |
| 1106 | 1097 | if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation |
| 1107 | 1098 | // do not need adjust due to not different at both slices of consumed time |
| 1108 | − iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid - 1], | |
| 1099 | + iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid - 1]->sLayerInfo.pSliceInLayer, | |
| 1109 | 1100 | pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame); |
| 1110 | 1101 | if (iNeedAdj) |
| 1111 | 1102 | DynamicAdjustSlicing (pCtx, |
| @@ -1115,7 +1106,7 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 3 unmodified lines | ||
| 1115 | 1106 | ); |
| 1116 | 1107 | } else { // use temporal layer for complexity estimation |
| 1117 | 1108 | // do not need adjust due to not different at both slices of consumed time |
| 1118 | − iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[iCurDid], | |
| 1109 | + iNeedAdj = NeedDynamicAdjust (pCtx->ppDqLayerList[iCurDid]->sLayerInfo.pSliceInLayer, | |
| 1119 | 1110 | pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame); |
| 1120 | 1111 | if (iNeedAdj) |
| 1121 | 1112 | DynamicAdjustSlicing (pCtx, |
| @@ -1163,11 +1154,11 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 41 unmodified lines | ||
| 1163 | 1154 | |
| 1164 | 1155 | pPara = pCtx->pSvcParam; |
| 1165 | 1156 | while (iSpatialIdx < iSpatialNum) { |
| 1166 | − const int32_t kiDid = pDidList[iSpatialIdx]; | |
| 1167 | − SSpatialLayerInternal* pDlp = &pPara->sDependencyLayers[kiDid]; | |
| 1168 | − SSliceConfig* pSliceArgument = &pDlp->sSliceArgument; | |
| 1169 | − SDqLayer* pCurDq = pCtx->ppDqLayerList[kiDid]; | |
| 1170 | − SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; | |
| 1157 | + const int32_t kiDid = pDidList[iSpatialIdx]; | |
| 1158 | + SSliceConfig* pSliceArgument = &pPara->sDependencyLayers[kiDid].sSliceArgument; | |
| 1159 | + SDqLayer* pCurDq = pCtx->ppDqLayerList[kiDid]; | |
| 1160 | + SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer; | |
| 1161 | + SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; | |
| 1171 | 1162 | const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame; |
| 1172 | 1163 | if (pCtx->pSliceThreading) { |
| 1173 | 1164 | if (pCtx->pSliceThreading->pFSliceDiff |
| @@ -1178,11 +1169,11 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 4 unmodified lines | ||
| 1178 | 1169 | uint32_t uiMaxT = 0; |
| 1179 | 1170 | int32_t iMaxI = 0; |
| 1180 | 1171 | while (i < kuiCountSliceNum) { |
| 1181 | − if (pCtx->pSliceThreading->pSliceConsumeTime[kiDid] != NULL) | |
| 1172 | + if (pSliceInLayer[i] != NULL) | |
| 1182 | 1173 | fprintf (pCtx->pSliceThreading->pFSliceDiff, "%6d us consume_time coding_idx %d iDid %d pSlice %d\n", |
| 1183 | − pCtx->pSliceThreading->pSliceConsumeTime[kiDid][i], pCtx->iCodingIndex, kiDid, i /*/ 1000*/); | |
| 1184 | − if (pCtx->pSliceThreading->pSliceConsumeTime[kiDid][i] > uiMaxT) { | |
| 1185 | − uiMaxT = pCtx->pSliceThreading->pSliceConsumeTime[kiDid][i]; | |
| 1174 | + pSliceInLayer[i].uiSliceConsumeTime, pCtx->iCodingIndex, kiDid, i /*/ 1000*/); | |
| 1175 | + if (pSliceInLayer[i].uiSliceConsumeTime > uiMaxT) { | |
| 1176 | + uiMaxT = pSliceInLayer[i].uiSliceConsumeTime; | |
| 1186 | 1177 | iMaxI = i; |
| 1187 | 1178 | } |
| 1188 | 1179 | ++ i; |