History

Multi-thread-fixed:RBC#1723:change slice idx type from unint32_t to int32_t

huade committed 9 years ago

Commit 7e113c11 parent 71750df7 files · +37 −105Browse files

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

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+19−84
@@ -527,7 +527,7 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 526 unmodified lines
527527 int32_t iNextMbIdx = kiSliceFirstMbXY;
528528 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
529529 int32_t iCurMbIdx = 0, iNumMbCoded = 0;
530− const int32_t kiSliceIdx = pSlice->uiSliceIdx;
530+ const int32_t kiSliceIdx = pSlice->iSliceIdx;
531531 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
532532
533533 SWelsMD sMd;
@@ -595,7 +595,7 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 61 unmodified lines
595595 int32_t iNextMbIdx = kiSliceFirstMbXY;
596596 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
597597 int32_t iCurMbIdx = 0, iNumMbCoded = 0;
598− const int32_t kiSliceIdx = pSlice->uiSliceIdx;
598+ const int32_t kiSliceIdx = pSlice->iSliceIdx;
599599 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);
600600 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
601601 int32_t iEncReturn = ENC_RETURN_SUCCESS;
@@ -953,8 +953,8 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 351 unmodified lines
953953 return ENC_RETURN_MEMALLOCERR;
954954 }
955955
956− pSlice->uiSliceIdx = iSliceIdx;
957− pSlice->uiThreadIdx = 0;
956+ pSlice->iSliceIdx = iSliceIdx;
957+ pSlice->uiThreadIdx = 0;
958958 pSlice->iCountMbNumInSlice = 0;
959959 pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
960960
@@ -976,36 +976,6 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 15 unmodified lines
976976 }
977977 return ENC_RETURN_SUCCESS;
978978 }
979−/*
980−int32_t InitOneSliceInThread (sWelsEncCtx* pCtx,
981− SSlice*& pSlice,
982− const int32_t kiThreadIdx,
983− const int32_t kiDlayerIdx,
984− const int32_t kiSliceIdx) {
985− SDqLayer* pDqLayer = pCtx->pCurDqLayer;
986− SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
987− const int32_t kiMBWidth = pDqLayer->iMbWidth;
988− const int32_t kiMBHeight = pDqLayer->iMbHeight;
989− const int32_t kiCodedNumInThread = pDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[kiThreadIdx];
990− const int32_t kiMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIdx];
991− int32_t iRet = 0;
992−
993− if (kiCodedNumInThread >= kiMaxSliceNumInThread) {
994− iRet = ReallocateSliceInThread(pCtx, pDqLayer, kiDlayerIdx, kiThreadIdx);
995− if (ENC_RETURN_SUCCESS != iRet) {
996− return iRet;
997− }
998− }
999−
1000− pSlice = pDqLayer->sSliceThreadInfo.pSliceInThread [kiThreadIdx] + kiCodedNumInThread;
1001− // Initialize slice bs buffer info
1002− pSlice->sSliceBs.uiBsPos = 0;
1003− pSlice->sSliceBs.iNalIndex = 0;
1004− pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
1005−
1006− return ENC_RETURN_SUCCESS;
1007−}
1008−*/
1009979
1010980 int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx,
1011981 SDqLayer* pDqLayer,
@@ -1045,7 +1015,7 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 33 unmodified lines
10451015 }
10461016
10471017 for (; iIdx < MAX_THREADS_NUM; iIdx++) {
1048− pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
1018+ pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = 0;
10491019 pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0;
10501020 pSliceThreadInfo->pSliceInThread[iIdx] = NULL;
10511021 }
@@ -1185,7 +1155,7 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 133 unmodified lines
11851155 return ENC_RETURN_MEMALLOCERR;
11861156 }
11871157
1188− pSlice->uiSliceIdx = iSliceIdx;
1158+ pSlice->iSliceIdx = iSliceIdx;
11891159 pSlice->uiThreadIdx = 0;
11901160 pSlice->iCountMbNumInSlice = 0;
11911161 pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -1244,41 +1214,6 @@ int32_t CalculateNewSliceNum (SDqLayer* pDqLayer, · 52 unmodified lines
12441214 return ENC_RETURN_SUCCESS;
12451215 }
12461216
1247−/*
1248−int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx,
1249− SDqLayer* pDqLayer,
1250− const int32_t kiDlayerIdx,
1251− const int32_t kiThreadIndex) {
1252−
1253− int32_t iMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIndex];
1254− int32_t iMaxSliceNumUpdate = 0;
1255− int32_t iRet = 0;
1256− SSlice* pLastCodedSlice = pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex] + (iMaxSliceNumInThread - 1);
1257− SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIdx].sSliceArgument;
1258−
1259− iRet = CalculateNewSliceNum (pDqLayer,
1260− pLastCodedSlice,
1261− iMaxSliceNumInThread,
1262− iMaxSliceNumUpdate);
1263−
1264− if (ENC_RETURN_SUCCESS != iRet) {
1265− return iRet;
1266− }
1267−
1268− iRet = ReallocateSliceList (pCtx,
1269− pSliceArgument,
1270− pDqLayer->sSliceThreadInfo.pSliceInThread[kiThreadIndex],
1271− iMaxSliceNumInThread,
1272− iMaxSliceNumUpdate);
1273− if (ENC_RETURN_SUCCESS != iRet) {
1274− return iRet;
1275− }
1276−
1277− return ENC_RETURN_SUCCESS;
1278−}
1279−*/
1280−
1281−
12821217 int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) {
12831218
12841219 CMemoryAlign* pMA = pCtx->pMemAlign;
@@ -1356,7 +1291,7 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 71 unmodified lines
13561291 pCurLayer->iMaxSliceNum = iMaxSliceNumNew;
13571292 return ENC_RETURN_SUCCESS;
13581293 }
1359−/*
1294+
13601295 int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,
13611296 const int32_t kiThreadNum,
13621297 const int32_t kiPartitionNum) {
@@ -1385,8 +1320,8 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 22 unmodified lines
13851320 return ENC_RETURN_UNEXPECTED;
13861321 }
13871322
1388− iPartitionID = pSliceInThread->uiSliceIdx % kiPartitionNum;
1389− iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->uiSliceIdx / kiPartitionNum;
1323+ iPartitionID = pSliceInThread->iSliceIdx % kiPartitionNum;
1324+ iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / kiPartitionNum;
13901325 pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;
13911326 }
13921327 }
@@ -1401,7 +1336,7 @@ static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiC · 8 unmodified lines
14011336 return ENC_RETURN_UNEXPECTED;
14021337 }
14031338
1404− if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->uiSliceIdx) {
1339+ if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) {
14051340 return ENC_RETURN_UNEXPECTED;
14061341 }
14071342 }
@@ -1417,10 +1352,11 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 9 unmodified lines
14171352 int32_t iCodedSliceNum = 0;
14181353 int32_t iThreadIdx = 0;
14191354 int32_t iRet = 0;
1355+ int32_t iThreadNum = 1; //TODO: should be equal to pCurLayer->iMaxSliceNum;
14201356 SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument;
14211357 int32_t iPartitionNum = (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? pCtx->iActiveThreadsNum : 1;
14221358
1423− for ( ; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) {
1359+ for ( ; iThreadIdx < iThreadNum; iThreadIdx++) {
14241360 iCodedSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
14251361 }
14261362
@@ -1442,7 +1378,7 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 15 unmodified lines
14421378 }
14431379
14441380 //update ppSliceInLayer based on pSliceInThread, reordering based on slice index
1445− iRet = ReOrderSliceInLayer (pCurLayer, pCtx->iActiveThreadsNum, iPartitionNum);
1381+ iRet = ReOrderSliceInLayer (pCurLayer, iThreadNum, iPartitionNum);
14461382 if (ENC_RETURN_SUCCESS != iRet) {
14471383 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
14481384 "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed");
@@ -1458,7 +1394,6 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 9 unmodified lines
14581394
14591395 return ENC_RETURN_SUCCESS;
14601396 }
1461−*/
14621397
14631398 int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, const int32_t kiNalType) {
14641399 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
@@ -1559,7 +1494,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 94 unmodified lines
15591494 uint32_t uiLen = 0;
15601495 int32_t iPosBitOffset = 0;
15611496 const int32_t kiActiveThreadsNum = pEncCtx->iActiveThreadsNum;
1562− const int32_t kiPartitaionId = pCurSlice->uiSliceIdx % kiActiveThreadsNum;
1497+ const int32_t kiPartitaionId = pCurSlice->iSliceIdx % kiActiveThreadsNum;
15631498 const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->pEndMbIdxOfPartition[kiPartitaionId];
15641499
15651500 const bool kbCurMbNotFirstMbOfCurSlice = ((iCurMbIdx > 0) && (pSliceCtx->pOverallMbMap[iCurMbIdx] ==
@@ -1580,8 +1515,8 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 14 unmodified lines
15801515 && kbCurMbNotLastMbOfCurPartition) { //decide to add new pSlice
15811516
15821517 WelsLog (&pEncCtx->sLogCtx, WELS_LOG_DETAIL,
1583− "DynSlcJudgeSliceBoundaryStepBack: AddSliceBoundary: iCurMbIdx=%d, uiLen=%d, uiSliceIdx=%d", iCurMbIdx, uiLen,
1584− pCurSlice->uiSliceIdx);
1518+ "DynSlcJudgeSliceBoundaryStepBack: AddSliceBoundary: iCurMbIdx=%d, uiLen=%d, iSliceIdx=%d", iCurMbIdx, uiLen,
1519+ pCurSlice->iSliceIdx);
15851520
15861521 if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) {
15871522 WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
@@ -1594,7 +1529,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 6 unmodified lines
15941529 // and will also extend when reallocated,
15951530 // tmp change is: iMaxSliceNumConstraint is alway set to be MAXSLICENUM, will not change even reallocate
15961531 const bool kbSliceNumNotExceedConstraint = pSliceCtx->iSliceNumInFrame < pEncCtx->pCurDqLayer->iMaxSliceNum;
1597− const bool kbSliceIdxNotExceedConstraint = ((int) pCurSlice->uiSliceIdx + kiActiveThreadsNum) < pEncCtx->pCurDqLayer->iMaxSliceNum;
1532+ const bool kbSliceIdxNotExceedConstraint = ((int) pCurSlice->iSliceIdx + kiActiveThreadsNum) < pEncCtx->pCurDqLayer->iMaxSliceNum;
15981533 const bool kbSliceNumReachConstraint = (pSliceCtx->iSliceNumInFrame == pEncCtx->pCurDqLayer->iMaxSliceNum);
15991534
16001535 //DYNAMIC_SLICING_ONE_THREAD: judge jump_avoiding_pack_exceed
@@ -1654,7 +1589,7 @@ int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, · 53 unmodified lines
16541589 const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight;
16551590 const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride;
16561591 uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize];
1657− const int32_t kiSliceIdx = pSlice->uiSliceIdx;
1592+ const int32_t kiSliceIdx = pSlice->iSliceIdx;
16581593 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
16591594 int32_t iEncReturn = ENC_RETURN_SUCCESS;
16601595 SDynamicSlicingStack sDss;
@@ -1750,7 +1685,7 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 89 unmodified lines
17501685 int32_t iCurMbIdx = -1;
17511686 const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride;
17521687 uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize];
1753− const int32_t kiSliceIdx = pSlice->uiSliceIdx;
1688+ const int32_t kiSliceIdx = pSlice->iSliceIdx;
17541689 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);
17551690 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
17561691 int32_t iEncReturn = ENC_RETURN_SUCCESS;

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