History

remove pSliceConsumeTime in SSliceCtx and pSliceThreading

huade committed 10 years ago

Commit b0017851 parent 2d3071e8 files · +36 −72Browse files

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

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+29−38
@@ -128,23 +128,23 @@ void UpdateMbListNeighborParallel (SDqLayer* pCurDq, · 127 unmodified lines
128128 } while (iIdx <= kiEndMbInSlice);
129129 }
130130
131−void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq, uint32_t* pSliceConsume) {
131+void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq) {
132132 SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx;
133+ SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer;
133134 int32_t* pRatioList = (int32_t*)pRatio;
134− int32_t iAvI[MAX_SLICES_NUM];
135135 int32_t iSumAv = 0;
136− uint32_t* pSliceTime = (uint32_t*)pSliceConsume;
137136 int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice;
138137 const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame;
139138 int32_t iSliceIdx = 0;
139+ int32_t iAvI[MAX_SLICES_NUM];
140140
141141 WelsEmms();
142142
143143 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",
146146 iSliceIdx,
147− pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
147+ pSliceInLayer[iSliceIdx].uiSliceConsumeTime, pCountMbInSlice[iSliceIdx]);
148148 iSumAv += iAvI[iSliceIdx];
149149
150150 ++ iSliceIdx;
@@ -154,8 +154,10 @@ void CalcSliceComplexRatio (void* pRatio, SDqLayer* pCurDq, uint32_t* pSliceCons · 3 unmodified lines
154154 }
155155 }
156156
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+
159161 uint32_t uiTotalConsume = 0;
160162 int32_t iSliceIdx = 0;
161163 int32_t iNeedAdj = false;
@@ -163,7 +165,7 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 1 unmodified line
163165 WelsEmms();
164166
165167 while (iSliceIdx < iSliceNum) {
166− uiTotalConsume += pSliceConsume[iSliceIdx];
168+ uiTotalConsume += pSliceInLayer[iSliceIdx].uiSliceConsumeTime;
167169 iSliceIdx ++;
168170 }
169171 if (uiTotalConsume == 0) {
@@ -178,7 +180,7 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 8 unmodified lines
178180 float fRmse = .0f; // root mean square error of pSlice consume ratios
179181 const float kfMeanRatio = 1.0f / iSliceNum;
180182 do {
181− const float fRatio = 1.0f * pSliceConsume[iSliceIdx] / uiTotalConsume;
183+ const float fRatio = 1.0f * pSliceInLayer[iSliceIdx].uiSliceConsumeTime / uiTotalConsume;
182184 const float fDiffRatio = fRatio - kfMeanRatio;
183185 fRmse += (fDiffRatio * fDiffRatio);
184186 ++ iSliceIdx;
@@ -370,12 +372,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 185 unmodified lines
370372 && (pPara->bUseLoadBalancing)
371373 && (pPara->iMultipleThreadIdc > 1)
372374 && (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))
375375 pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]");
376376 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx))
377377 } else {
378− pSmt->pSliceConsumeTime[iIdx] = NULL;
379378 pSmt->pSliceComplexRatio[iIdx] = NULL;
380379 }
381380
@@ -384,7 +383,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines
384383 }
385384 ++ iIdx;
386385 }
387− // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS
388386
389387 #ifdef MT_DEBUG
390388 // file handle for MT debug
@@ -554,11 +552,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 163 unmodified lines
554552
555553 iIdx = 0;
556554 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) {
562556 pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]");
563557 pSmt->pSliceComplexRatio[iIdx] = NULL;
564558 }
@@ -814,12 +808,12 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 249 unmodified lines
814808 pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
815809
816810 if (bDsaFlag) {
817− pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) (
811+ pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime = (uint32_t) (
818812 WelsTime() - iSliceStart);
819813 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",
821815 pEncPEncCtx->iCodingIndex, iSliceIdx,
822− pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize,
816+ pEncPEncCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].uiSliceConsumeTime, iSliceSize,
823817 pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
824818 pCurDq->sSliceEncCtx.pCountMbNumInSlice[iSliceIdx]);
825819 }
@@ -1067,10 +1061,9 @@ int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { · 241 unmodified lines
10671061 #endif//MT_DEBUG
10681062
10691063 pCtx->pCurDqLayer = pCurDq;
1070− memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[0]), (pCurDq->sSliceEncCtx.pSliceConsumeTime),
1071− pCurDq->sSliceEncCtx.iSliceNumInFrame * sizeof (uint32_t));
1064+
10721065 // 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);
10741067 if (iNeedAdj)
10751068 DynamicAdjustSlicing (pCtx,
10761069 pCurDq,
@@ -1100,12 +1093,10 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 23 unmodified lines
11001093 && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE
11011094 && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid -
11021095 1].sSliceArgument.uiSliceNum);
1103− memcpy ((pCtx->pSliceThreading->pSliceConsumeTime[iCurDid]), (pCtx->pCurDqLayer->sSliceEncCtx.pSliceConsumeTime),
1104− pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame * sizeof (uint32_t));
11051096
11061097 if (kbModelingFromSpatial) { // using spatial base layer for complexity estimation
11071098 // 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,
11091100 pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame);
11101101 if (iNeedAdj)
11111102 DynamicAdjustSlicing (pCtx,
@@ -1115,7 +1106,7 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 3 unmodified lines
11151106 );
11161107 } else { // use temporal layer for complexity estimation
11171108 // 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,
11191110 pCtx->pCurDqLayer->sSliceEncCtx.iSliceNumInFrame);
11201111 if (iNeedAdj)
11211112 DynamicAdjustSlicing (pCtx,
@@ -1163,11 +1154,11 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 41 unmodified lines
11631154
11641155 pPara = pCtx->pSvcParam;
11651156 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;
11711162 const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame;
11721163 if (pCtx->pSliceThreading) {
11731164 if (pCtx->pSliceThreading->pFSliceDiff
@@ -1178,11 +1169,11 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 4 unmodified lines
11781169 uint32_t uiMaxT = 0;
11791170 int32_t iMaxI = 0;
11801171 while (i < kuiCountSliceNum) {
1181− if (pCtx->pSliceThreading->pSliceConsumeTime[kiDid] != NULL)
1172+ if (pSliceInLayer[i] != NULL)
11821173 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;
11861177 iMaxI = i;
11871178 }
11881179 ++ i;

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