History

remove pSliceComplexRatio from SliceThreading

huade committed 10 years ago

Commit f263f071 parent aeb55e05 files · +17 −43Browse files

Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 5 files). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t