History

Multi-thread-fixed:RBC#1751:Dynamic slice mode under multiThread reallocate feature enable

huade committed 9 years ago

Commit 095f0b61 parent 623599014 files · +325 −336Browse files

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

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+151−109
@@ -640,9 +640,9 @@ TRY_REENCODING: · 639 unmodified lines
640640
641641 if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) { //islice
642642 pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
643− pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
644− 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
645− ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];
643+ pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
644+ 1; // update LastCodedMbIdxOfPartition, need to -1 due to stepping back
645+ ++ pCurLayer->NumSliceCodedOfPartition[kiPartitionId];
646646
647647 break;
648648 }
@@ -661,9 +661,10 @@ TRY_REENCODING: · 12 unmodified lines
661661 iNextMbIdx = WelsGetNextMbOfSlice (pCurLayer, iCurMbIdx);
662662 //whether all of MB in current pSlice encoded or not
663663 if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {
664− pSlice->iCountMbNumInSlice = iCurMbIdx - pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId];
665− pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] =
666− iCurMbIdx; // update pLastCodedMbIdxOfPartition, finish coding, use iCurMbIdx directly
664+ pSlice->iCountMbNumInSlice = iCurMbIdx - pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId];
665+ pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx;
666+ ++ pCurLayer->NumSliceCodedOfPartition[kiPartitionId];
667+
667668 break;
668669 }
669670 }
@@ -754,10 +755,11 @@ static const PWelsSliceHeaderWriteFunc g_pWelsWriteSliceHeader[2] = { // 0: for · 84 unmodified lines
754755
755756 //Allocate slice's MB cache buffer
756757 int32_t AllocMbCacheAligned (SMbCache* pMbCache, CMemoryAlign* pMa) {
757− pMbCache->pCoeffLevel = (int16_t*)pMa->WelsMallocz (MB_COEFF_LIST_SIZE * sizeof (int16_t), "pMbCache->pCoeffLevel");
758− WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pCoeffLevel));
759758 pMbCache->pMemPredMb = (uint8_t*)pMa->WelsMallocz (2 * 256 * sizeof (uint8_t), "pMbCache->pMemPredMb");
760759 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pMemPredMb));
760+
761+ pMbCache->pCoeffLevel = (int16_t*)pMa->WelsMallocz (MB_COEFF_LIST_SIZE * sizeof (int16_t), "pMbCache->pCoeffLevel");
762+ WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pCoeffLevel));
761763 pMbCache->pSkipMb = (uint8_t*)pMa->WelsMallocz (384 * sizeof (uint8_t), "pMbCache->pSkipMb");
762764 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pSkipMb));
763765 pMbCache->pMemPredBlk4 = (uint8_t*)pMa->WelsMallocz (2 * 16 * sizeof (uint8_t), "pMbCache->pMemPredBlk4");
@@ -895,7 +897,7 @@ int32_t InitSliceBsBuffer (SSlice* pSlice, · 131 unmodified lines
895897
896898 if (bIndependenceBsBuffer) {
897899 pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite;
898− pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "SliceBs");
900+ pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "sSliceBs.pBs");
899901 if (NULL == pSlice->sSliceBs.pBs) {
900902 return ENC_RETURN_MEMALLOCERR;
901903 }
@@ -979,15 +981,20 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 77 unmodified lines
979981 }
980982
981983 int32_t InitAllSlicesInThread (sWelsEncCtx* pCtx) {
982− SDqLayer* pDqLayer = pCtx->pCurDqLayer;
983− int32_t iSliceIdx = 0;
984+ SDqLayer* pCurDqLayer = pCtx->pCurDqLayer;
985+ int32_t iSliceIdx = 0;
986+ int32_t iTheadIdx = 0;
984987
985− for( ; iSliceIdx < pDqLayer->iMaxSliceNum; iSliceIdx++) {
986− if(NULL == pDqLayer->ppSliceInLayer[iSliceIdx]) {
988+ for( ; iSliceIdx < pCurDqLayer->iMaxSliceNum; iSliceIdx++) {
989+ if(NULL == pCurDqLayer->ppSliceInLayer[iSliceIdx]) {
987990 return ENC_RETURN_UNEXPECTED;
988991 }
989992
990− pDqLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx = -1;
993+ pCurDqLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx = -1;
994+ }
995+
996+ for( ; iTheadIdx < pCtx->iActiveThreadsNum; iTheadIdx++ ) {
997+ pCurDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[iTheadIdx] = 0;
991998 }
992999
9931000 return ENC_RETURN_SUCCESS;
@@ -1000,17 +1007,13 @@ int32_t InitOneSliceInThread (sWelsEncCtx* pCtx, · 6 unmodified lines
10001007 const int32_t kiSliceIdx) {
10011008 SDqLayer* pDqLayer = pCtx->pCurDqLayer;
10021009 const int32_t kiCodedNumInThread = pDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[kiThreadIdx];
1003− const int32_t kiMaxSliceNumInThread = pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIdx];
1004− int32_t iRet = 0;
10051010
1006− if (kiCodedNumInThread >= kiMaxSliceNumInThread) {
1007− iRet = ReallocateSliceInThread(pCtx, pDqLayer, kiDlayerIdx, kiThreadIdx);
1008− if (ENC_RETURN_SUCCESS != iRet) {
1009− return iRet;
1010− }
1011− }
1011+ assert(kiCodedNumInThread < pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIdx] -1 );
1012+
1013+ pSlice = &pDqLayer->sSliceThreadInfo.pSliceInThread [kiThreadIdx][kiCodedNumInThread];
1014+ pSlice->iSliceIdx = kiSliceIdx;
1015+ pSlice->uiThreadIdx = kiThreadIdx;
10121016
1013− pSlice = pDqLayer->sSliceThreadInfo.pSliceInThread [kiThreadIdx] + kiCodedNumInThread;
10141017 // Initialize slice bs buffer info
10151018 pSlice->sSliceBs.uiBsPos = 0;
10161019 pSlice->sSliceBs.iNalIndex = 0;
@@ -1030,6 +1033,7 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 13 unmodified lines
10301033 int32_t iIdx = 0;
10311034 int32_t iRet = 0;
10321035
1036+ assert (iThreadNum > 0);
10331037 iMaxSliceNumInThread = pDqLayer->iMaxSliceNum;
10341038 while (iIdx < iThreadNum) {
10351039 pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
@@ -1078,7 +1082,10 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 42 unmodified lines
10781082 return ENC_RETURN_MEMALLOCERR;
10791083 }
10801084
1081− pDqLayer->iMaxSliceNum = iMaxSliceNum * pCtx->iActiveThreadsNum;
1085+ pDqLayer->iMaxSliceNum = 0;
1086+ for(iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++ ) {
1087+ pDqLayer->iMaxSliceNum += pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
1088+ }
10821089
10831090 pDqLayer->ppSliceInLayer = (SSlice**)pMa->WelsMallocz (sizeof (SSlice*) * pDqLayer->iMaxSliceNum, "ppSliceInLayer");
10841091 if (NULL == pDqLayer->ppSliceInLayer) {
@@ -1120,14 +1127,14 @@ void InitSliceHeadWithBase (SSlice* pSlice, SSlice* pBaseSlice) { · 35 unmodified lines
11201127 return;
11211128 }
11221129
1123− SSliceHeaderExt* pBaseSHExt = &pBaseSlice->sSliceHeaderExt;
1124− SSliceHeaderExt* pSHExt = &pSlice->sSliceHeaderExt;
1130+ SSliceHeaderExt* pBaseSHExt = &pBaseSlice->sSliceHeaderExt;
1131+ SSliceHeaderExt* pSHExt = &pSlice->sSliceHeaderExt;
11251132
1126− pSlice->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag;
1127− pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId;
1128− pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps;
1129− pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId;
1130− pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps;
1133+ pSlice->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag;
1134+ pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId;
1135+ pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps;
1136+ pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId;
1137+ pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps;
11311138 }
11321139
11331140 void InitSliceRefInfoWithBase (SSlice* pSlice, SSlice* pBaseSlice, const uint8_t kuiRefCount) {
@@ -1181,28 +1188,41 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 47 unmodified lines
11811188 return ENC_RETURN_INVALIDINPUT;
11821189 }
11831190
1184− pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "Slice");
1191+ pNewSliceList = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * kiMaxSliceNumNew, "pSliceInThread");
11851192 if (NULL == pNewSliceList) {
11861193 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ReallocateSliceList: pNewSliceList is NULL");
11871194 return ENC_RETURN_MEMALLOCERR;
11881195 }
11891196
11901197 memcpy (pNewSliceList, pSliceList, sizeof (SSlice) * kiMaxSliceNumOld);
1191− iSliceIdx = kiMaxSliceNumOld;
1192− pBaseSlice = &pSliceList[0];
1198+
1199+ //update Bs writer
1200+ for (iSliceIdx = 0; iSliceIdx < kiMaxSliceNumOld; iSliceIdx++) {
1201+ pSlice = pNewSliceList + iSliceIdx;
1202+ if (NULL == pSlice) {
1203+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
1204+ return ENC_RETURN_MEMALLOCERR;
1205+ }
1206+
1207+ if (bIndependenceBsBuffer) {
1208+ pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite;
1209+ }
1210+ }
1211+
1212+ pBaseSlice = &pSliceList[0];
11931213 if (NULL == pBaseSlice) {
11941214 FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
11951215 return ENC_RETURN_MEMALLOCERR;
11961216 }
11971217
1198− for (; iSliceIdx < kiMaxSliceNumNew; iSliceIdx++) {
1218+ for (iSliceIdx = kiMaxSliceNumOld; iSliceIdx < kiMaxSliceNumNew; iSliceIdx++) {
11991219 pSlice = pNewSliceList + iSliceIdx;
12001220 if (NULL == pSlice) {
1201− FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
1221+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
12021222 return ENC_RETURN_MEMALLOCERR;
12031223 }
12041224
1205− pSlice->iSliceIdx = iSliceIdx;
1225+ pSlice->iSliceIdx = -1;
12061226 pSlice->uiThreadIdx = 0;
12071227 pSlice->iCountMbNumInSlice = 0;
12081228 pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0;
@@ -1213,13 +1233,13 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 4 unmodified lines
12131233 iMaxSliceBufferSize,
12141234 pMA);
12151235 if (ENC_RETURN_SUCCESS != iRet) {
1216− FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
1236+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
12171237 return iRet;
12181238 }
12191239
12201240 iRet = AllocateSliceMBBuffer (pSlice, pMA);
12211241 if (ENC_RETURN_SUCCESS != iRet) {
1222− FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
1242+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
12231243 return iRet;
12241244 }
12251245
@@ -1228,12 +1248,12 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 2 unmodified lines
12281248
12291249 iRet = InitSliceRC (pSlice, pCtx->iGlobalQp);
12301250 if (ENC_RETURN_SUCCESS != iRet) {
1231− FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()");
1251+ FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "pSliceInThread");
12321252 return iRet;
12331253 }
12341254 }
12351255
1236− pMA->WelsFree (pSliceList, "Slice");
1256+ pMA->WelsFree (pSliceList, "pSliceInThread");
12371257 pSliceList = pNewSliceList;
12381258
12391259 return ENC_RETURN_SUCCESS;
@@ -1290,6 +1310,8 @@ int32_t ReallocateSliceInThread (sWelsEncCtx* pCtx, · 50 unmodified lines
12901310 return iRet;
12911311 }
12921312
1313+ pDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[kiThreadIndex] = iMaxSliceNumUpdate;
1314+
12931315 return ENC_RETURN_SUCCESS;
12941316 }
12951317
@@ -1299,11 +1321,11 @@ int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx, · 3 unmodified lines
12991321 CMemoryAlign* pMA = pCtx->pMemAlign;
13001322 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
13011323 SSlice** ppSlice = NULL;
1302− int32_t* pFirstMbIdxofSlice = NULL;
1324+ int32_t* pFirstMbIdxOfSlice = NULL;
13031325 int32_t* pCountMbNumInSlice = NULL;
13041326
13051327 // update for ppsliceInlayer
1306− ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * kiMaxSliceNumNew, "ppSlice");
1328+ ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * kiMaxSliceNumNew, "ppSliceInLayer");
13071329 if (NULL == ppSlice) {
13081330 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: ppSlice is NULL");
13091331 return ENC_RETURN_MEMALLOCERR;
@@ -1312,15 +1334,15 @@ int32_t ExtendLayerBuffer(sWelsEncCtx* pCtx, · 2 unmodified lines
13121334 pCurLayer->ppSliceInLayer = ppSlice;
13131335
13141336 // update for pFirstMbIdxInSlice
1315− pFirstMbIdxofSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * kiMaxSliceNumNew, "pFirstMbIdxofSlice");
1316− if (NULL == pFirstMbIdxofSlice) {
1317− WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pFirstMbIdxofSlice is NULL");
1337+ pFirstMbIdxOfSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * kiMaxSliceNumNew, "pFirstMbIdxOfSlice");
1338+ if (NULL == pFirstMbIdxOfSlice) {
1339+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::ExtendLayerBuffer: pFirstMbIdxOfSlice is NULL");
13181340 return ENC_RETURN_MEMALLOCERR;
13191341 }
1320− memset (pFirstMbIdxofSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew);
1321− memcpy (pFirstMbIdxofSlice, pCurLayer->pFirstMbIdxOfSlice, sizeof (int32_t) * kiMaxSliceNumOld);
1322− pMA->WelsFree (pCurLayer->pFirstMbIdxOfSlice, "pFirstMbIdxofSlice");
1323− pCurLayer->pFirstMbIdxOfSlice = pFirstMbIdxofSlice;
1342+ memset (pFirstMbIdxOfSlice, 0, sizeof(int32_t) * kiMaxSliceNumNew);
1343+ memcpy (pFirstMbIdxOfSlice, pCurLayer->pFirstMbIdxOfSlice, sizeof (int32_t) * kiMaxSliceNumOld);
1344+ pMA->WelsFree (pCurLayer->pFirstMbIdxOfSlice, "pFirstMbIdxOfSlice");
1345+ pCurLayer->pFirstMbIdxOfSlice = pFirstMbIdxOfSlice;
13241346
13251347 // update for pCountMbNumInSlice
13261348 pCountMbNumInSlice = (int32_t*)pMA->WelsMallocz (sizeof (int32_t*) * kiMaxSliceNumNew, "pCountMbNumInSlice");
@@ -1405,10 +1427,10 @@ static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiC · 78 unmodified lines
14051427 return ENC_RETURN_SUCCESS;
14061428 }
14071429
1408−
1409−int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer,
1410− const int32_t kiThreadNum,
1411− const int32_t kiPartitionNum) {
1430+int32_t ReOrderSliceInLayer (sWelsEncCtx* pCtx,
1431+ const SliceModeEnum kuiSliceMode,
1432+ const int32_t kiThreadNum) {
1433+ SDqLayer* pCurLayer = pCtx->pCurDqLayer;
14121434 SSlice* pSliceInThread = NULL;
14131435 int32_t iThreadIdx = 0;
14141436 int32_t iPartitionIdx = 0;
@@ -1419,12 +1441,19 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 4 unmodified lines
14191441 int32_t iActualSliceIdx = 0;
14201442 int32_t iNonUsedBufferNum = 0;
14211443 int32_t iUsedSliceNum = 0;
1444+
1445+ int32_t iPartitionNum = 0;
14221446 int32_t aiPartitionOffset[MAX_THREADS_NUM] = {0};
14231447
1424− //for non-dynamic slice mode, kiPartitionNum = 1, iPartitionOffset = 0
1425− for(iPartitionIdx = 0; iPartitionIdx < kiPartitionNum; iPartitionIdx++) {
1448+ //for non-dynamic slice mode, iPartitionNum = 1, iPartitionOffset = 0
1449+ iPartitionNum = (SM_SIZELIMITED_SLICE == kuiSliceMode) ? kiThreadNum : 1;
1450+ for(iPartitionIdx = 0; iPartitionIdx < iPartitionNum; iPartitionIdx++) {
14261451 aiPartitionOffset[iPartitionIdx] = iEncodeSliceNum;
1427− iEncodeSliceNum += pCurLayer->pNumSliceCodedOfPartition[iPartitionIdx];
1452+ if ( SM_SIZELIMITED_SLICE == kuiSliceMode) {
1453+ iEncodeSliceNum += pCurLayer->NumSliceCodedOfPartition[iPartitionIdx];
1454+ } else {
1455+ iEncodeSliceNum = pCurLayer->sSliceEncCtx.iSliceNumInFrame;
1456+ }
14281457 }
14291458
14301459 if( iEncodeSliceNum != pCurLayer->sSliceEncCtx.iSliceNumInFrame) {
@@ -1443,8 +1472,9 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 12 unmodified lines
14431472 }
14441473
14451474 if( -1 != pSliceInThread->iSliceIdx) {
1446− iPartitionID = pSliceInThread->iSliceIdx % kiPartitionNum;
1447− iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / kiPartitionNum;
1475+ iPartitionID = pSliceInThread->iSliceIdx % iPartitionNum;
1476+ iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / iPartitionNum;
1477+ pSliceInThread->iSliceIdx = iActualSliceIdx;
14481478 pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread;
14491479 iUsedSliceNum ++;
14501480 } else {
@@ -1466,6 +1496,29 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 15 unmodified lines
14661496 return ENC_RETURN_SUCCESS;
14671497 }
14681498
1499+int32_t GetCurLayerNalCount(const SDqLayer* pCurDq, const int32_t kiCodedSliceNum) {
1500+ int32_t iTotalNalCount = 0;
1501+ int32_t iSliceIdx = 0;
1502+ SWelsSliceBs* pSliceBs = NULL;
1503+ for ( ; iSliceIdx < kiCodedSliceNum; iSliceIdx++ ) {
1504+ pSliceBs = &pCurDq->ppSliceInLayer[iSliceIdx]->sSliceBs;
1505+ if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
1506+ iTotalNalCount += pSliceBs->iNalIndex;
1507+ }
1508+ }
1509+
1510+ return iTotalNalCount;
1511+}
1512+
1513+int32_t GetTotalCodedNalCount(SFrameBSInfo* pFbi) {
1514+ int32_t iTotalCodedNalCount = 0;
1515+ for (int32_t iNalIdx = 0; iNalIdx < MAX_LAYER_NUM_OF_FRAME; iNalIdx++) {
1516+ iTotalCodedNalCount += pFbi->sLayerInfo[iNalIdx].iNalCount;
1517+ }
1518+
1519+ return iTotalCodedNalCount;
1520+}
1521+
14691522 int32_t FrameBsRealloc (sWelsEncCtx* pCtx,
14701523 SFrameBSInfo* pFrameBsInfo,
14711524 SLayerBSInfo* pLayerBsInfo,
@@ -1508,39 +1561,45 @@ int32_t FrameBsRealloc (sWelsEncCtx* pCtx, · 36 unmodified lines
15081561 int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx,
15091562 SFrameBSInfo* pFrameBsInfo,
15101563 SLayerBSInfo* pLayerBsInfo,
1511− const int32_t kiPartitionNum) {
1512− SDqLayer* pCurLayer = pCtx->pCurDqLayer;
1513− int32_t iMaxSliceNum = 0;
1514− int32_t iThreadIdx = 0;
1515− int32_t iRet = 0;
1516− int32_t iThreadNum = 1; //TODO: should be equal to pCurLayer->iMaxSliceNum;
1564+ const SliceModeEnum kuiSliceMode) {
1565+ int32_t iMaxSliceNum = 0;
1566+ int32_t iCodedSliceNum = 0;
1567+ int32_t iCodedNalCount = 0;
1568+ int32_t iRet = 0;
15171569
1518− for ( ; iThreadIdx < iThreadNum; iThreadIdx++) {
1519− iMaxSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
1570+ for ( int32_t iThreadIdx = 0; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) {
1571+ iMaxSliceNum += pCtx->pCurDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx];
15201572 }
15211573
15221574 //reallocate ppSliceInLayer if total encoded slice num exceed max slice num
1523− if (iMaxSliceNum > pCurLayer->iMaxSliceNum) {
1524− iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo, pCtx->pCurDqLayer->iMaxSliceNum);
1525− if(ENC_RETURN_SUCCESS != iRet) {
1526− return iRet;
1527− }
1528−
1575+ if (iMaxSliceNum > pCtx->pCurDqLayer->iMaxSliceNum) {
15291576 iRet = ExtendLayerBuffer(pCtx, pCtx->pCurDqLayer->iMaxSliceNum, iMaxSliceNum);
15301577 if (ENC_RETURN_SUCCESS != iRet) {
15311578 return iRet;
15321579 }
1533− pCurLayer->iMaxSliceNum = iMaxSliceNum;
1580+ pCtx->pCurDqLayer->iMaxSliceNum = iMaxSliceNum;
15341581 }
15351582
15361583 //update ppSliceInLayer based on pSliceInThread, reordering based on slice index
1537− iRet = ReOrderSliceInLayer (pCurLayer, iThreadNum, kiPartitionNum);
1584+ iRet = ReOrderSliceInLayer (pCtx, kuiSliceMode, pCtx->iActiveThreadsNum);
15381585 if (ENC_RETURN_SUCCESS != iRet) {
15391586 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
15401587 "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed");
15411588 return iRet;
15421589 }
15431590
1591+ //Extend NalList buffer if exceed
1592+ iCodedSliceNum = GetCurrentSliceNum (pCtx->pCurDqLayer);
1593+ pLayerBsInfo->iNalCount = GetCurLayerNalCount(pCtx->pCurDqLayer, iCodedSliceNum);
1594+ iCodedNalCount = GetTotalCodedNalCount(pFrameBsInfo);
1595+
1596+ if( iCodedNalCount > pCtx->pOut->iCountNals) {
1597+ iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo, pCtx->pCurDqLayer->iMaxSliceNum);
1598+ if(ENC_RETURN_SUCCESS != iRet) {
1599+ return iRet;
1600+ }
1601+ }
1602+
15441603 return ENC_RETURN_SUCCESS;
15451604 }
15461605
@@ -1602,7 +1661,8 @@ void UpdateMbNeighbourInfoForNextSlice (SDqLayer* pCurDq, · 55 unmodified lines
16021661 void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSliceCtx, SMB* pCurMb,
16031662 int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) {
16041663 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
1605− SSlice* pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[0];
1664+ SSlice* pSliceInThread = pCurLayer->sSliceThreadInfo.pSliceInThread[pCurSlice->uiThreadIdx];
1665+ int32_t iCodedSliceNum = pCurLayer->sSliceThreadInfo.iEncodedSliceNumInThread[pCurSlice->uiThreadIdx];
16061666 int32_t iCurMbIdx = pCurMb->iMbXY;
16071667 uint16_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ];
16081668 const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum;
@@ -1615,7 +1675,11 @@ void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSlic · 6 unmodified lines
16151675 pCurSlice->sSliceHeaderExt.uiNumMbsInSlice = 1 + iCurMbIdx - pCurSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
16161676
16171677 //pNextSlice pointer/initialization
1618− pNextSlice = &pSliceInThread[ iNextSliceIdc ];
1678+ if(pEncCtx->iActiveThreadsNum > 1) {
1679+ pNextSlice = &pSliceInThread[ iCodedSliceNum + 1 ];
1680+ } else {
1681+ pNextSlice = &pSliceInThread[ iNextSliceIdc ];
1682+ }
16191683
16201684 #if _DEBUG
16211685 assert (NULL != pNextSlice);
@@ -1643,7 +1707,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 21 unmodified lines
16431707 int32_t iPosBitOffset = 0;
16441708 const int32_t kiActiveThreadsNum = pEncCtx->iActiveThreadsNum;
16451709 const int32_t kiPartitaionId = pCurSlice->iSliceIdx % kiActiveThreadsNum;
1646− const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->pEndMbIdxOfPartition[kiPartitaionId];
1710+ const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->EndMbIdxOfPartition[kiPartitaionId];
16471711 const int32_t kiMaxSliceNum = pEncCtx->pCurDqLayer->sSliceThreadInfo.iMaxSliceNumInThread[pCurSlice->uiThreadIdx];
16481712 const bool kbCurMbNotFirstMbOfCurSlice = ((iCurMbIdx > 0) && (pSliceCtx->pOverallMbMap[iCurMbIdx] ==
16491713 pSliceCtx->pOverallMbMap[iCurMbIdx - 1]));
@@ -1676,37 +1740,14 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 26 unmodified lines
16761740 // as iMaxSliceNum is always equal to iMaxSliceNumConstraint in origin design
16771741 // and will also extend when reallocated,
16781742 // tmp change is: iMaxSliceNumConstraint is alway set to be MAXSLICENUM, will not change even reallocate
1679− const bool kbSliceNumNotExceedConstraint = pSliceCtx->iSliceNumInFrame < kiMaxSliceNum;
1680− const bool kbSliceIdxNotExceedConstraint = ((int) pCurSlice->iSliceIdx + kiActiveThreadsNum) < kiMaxSliceNum;
1681− const bool kbSliceNumReachConstraint = (pSliceCtx->iSliceNumInFrame == kiMaxSliceNum);
1682−
1683− //DYNAMIC_SLICING_ONE_THREAD: judge jump_avoiding_pack_exceed
1684− if (kbSliceNumNotExceedConstraint && kbSliceIdxNotExceedConstraint) {//able to add new pSlice
1743+ AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiEndMbIdxOfPartition);
1744+ ++ pSliceCtx->iSliceNumInFrame;
16851745
1686− AddSliceBoundary (pEncCtx, pCurSlice, pSliceCtx, pCurMb, iCurMbIdx, kiEndMbIdxOfPartition);
1687−
1688− ++ pSliceCtx->iSliceNumInFrame;
1689−
1690− if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) {
1691− WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
1692− }
1693−
1694− return true;
1695− }
16961746 if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) {
16971747 WelsMutexUnlock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate);
16981748 }
16991749
1700− if ((kbSliceNumReachConstraint || !kbSliceIdxNotExceedConstraint)
1701− && kbCurMbNotLastMbOfCurPartition
1702− && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx,
1703− pSliceCtx->uiSliceSizeConstraint - ((kiEndMbIdxOfPartition - iCurMbIdx) <<
1704− (pCurSlice->uiAssumeLog2BytePerMb) //assume each MB consumes these byte under largest QP
1705− ))
1706− ) {
1707− // to minimize the impact under the risk of exceeding the size constraint when pSlice num reaches constraint
1708− pCurSlice->bDynamicSlicingSliceSizeCtrlFlag = true;
1709− }
1750+ return true;
17101751 }
17111752
17121753 return false;
@@ -1903,9 +1944,9 @@ TRY_REENCODING: · 190 unmodified lines
19031944 sDss.iCurrentPos = pEncCtx->pFuncList->pfGetBsPosition (pSlice);
19041945 if (DynSlcJudgeSliceBoundaryStepBack (pEncCtx, pSlice, pSliceCtx, pCurMb, &sDss)) {
19051946 pSlice->iMbSkipRun = pEncCtx->pFuncList->pfStashPopMBStatus (&sDss, pSlice);
1906− pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
1907− 1; // update pLastCodedMbIdxOfPartition, need to -1 due to stepping back
1908− ++ pCurLayer->pNumSliceCodedOfPartition[kiPartitionId];
1947+ pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx -
1948+ 1; // update LastCodedMbIdxOfPartition, need to -1 due to stepping back
1949+ ++ pCurLayer->NumSliceCodedOfPartition[kiPartitionId];
19091950
19101951 break;
19111952 }
@@ -1926,8 +1967,9 @@ TRY_REENCODING: · 14 unmodified lines
19261967 iNextMbIdx = WelsGetNextMbOfSlice (pCurLayer, iCurMbIdx);
19271968 //whether all of MB in current pSlice encoded or not
19281969 if (iNextMbIdx == -1 || iNextMbIdx >= kiTotalNumMb || iNumMbCoded >= kiTotalNumMb) {
1929− pCurLayer->pLastCodedMbIdxOfPartition[kiPartitionId] =
1930− iCurMbIdx; // update pLastCodedMbIdxOfPartition, finish coding, use pCurMb_idx directly
1970+ pCurLayer->LastCodedMbIdxOfPartition[kiPartitionId] = iCurMbIdx;
1971+ ++ pCurLayer->NumSliceCodedOfPartition[kiPartitionId];
1972+
19311973 break;
19321974 }
19331975 }

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