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