Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 7 files). Show all
Unified · Split
| @@ -527,7 +527,7 @@ int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encodin · 526 unmodified lines | ||
| 527 | 527 | int32_t iNextMbIdx = kiSliceFirstMbXY; |
| 528 | 528 | const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight; |
| 529 | 529 | int32_t iCurMbIdx = 0, iNumMbCoded = 0; |
| 530 | − const int32_t kiSliceIdx = pSlice->uiSliceIdx; | |
| 530 | + const int32_t kiSliceIdx = pSlice->iSliceIdx; | |
| 531 | 531 | const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset; |
| 532 | 532 | |
| 533 | 533 | SWelsMD sMd; |
| @@ -595,7 +595,7 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + · 61 unmodified lines | ||
| 595 | 595 | int32_t iNextMbIdx = kiSliceFirstMbXY; |
| 596 | 596 | const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight; |
| 597 | 597 | int32_t iCurMbIdx = 0, iNumMbCoded = 0; |
| 598 | − const int32_t kiSliceIdx = pSlice->uiSliceIdx; | |
| 598 | + const int32_t kiSliceIdx = pSlice->iSliceIdx; | |
| 599 | 599 | const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum); |
| 600 | 600 | const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset; |
| 601 | 601 | int32_t iEncReturn = ENC_RETURN_SUCCESS; |
| @@ -953,8 +953,8 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 351 unmodified lines | ||
| 953 | 953 | return ENC_RETURN_MEMALLOCERR; |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | − pSlice->uiSliceIdx = iSliceIdx; | |
| 957 | − pSlice->uiThreadIdx = 0; | |
| 956 | + pSlice->iSliceIdx = iSliceIdx; | |
| 957 | + pSlice->uiThreadIdx = 0; | |
| 958 | 958 | pSlice->iCountMbNumInSlice = 0; |
| 959 | 959 | pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0; |
| 960 | 960 | |
| @@ -976,36 +976,6 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 15 unmodified lines | ||
| 976 | 976 | } |
| 977 | 977 | return ENC_RETURN_SUCCESS; |
| 978 | 978 | } |
| 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 | −*/ | |
| 1009 | 979 | |
| 1010 | 980 | int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, |
| 1011 | 981 | SDqLayer* pDqLayer, |
| @@ -1045,7 +1015,7 @@ int32_t InitSliceThreadInfo (sWelsEncCtx* pCtx, · 33 unmodified lines | ||
| 1045 | 1015 | } |
| 1046 | 1016 | |
| 1047 | 1017 | for (; iIdx < MAX_THREADS_NUM; iIdx++) { |
| 1048 | − pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread; | |
| 1018 | + pSliceThreadInfo->iMaxSliceNumInThread[iIdx] = 0; | |
| 1049 | 1019 | pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0; |
| 1050 | 1020 | pSliceThreadInfo->pSliceInThread[iIdx] = NULL; |
| 1051 | 1021 | } |
| @@ -1185,7 +1155,7 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 133 unmodified lines | ||
| 1185 | 1155 | return ENC_RETURN_MEMALLOCERR; |
| 1186 | 1156 | } |
| 1187 | 1157 | |
| 1188 | − pSlice->uiSliceIdx = iSliceIdx; | |
| 1158 | + pSlice->iSliceIdx = iSliceIdx; | |
| 1189 | 1159 | pSlice->uiThreadIdx = 0; |
| 1190 | 1160 | pSlice->iCountMbNumInSlice = 0; |
| 1191 | 1161 | pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0; |
| @@ -1244,41 +1214,6 @@ int32_t CalculateNewSliceNum (SDqLayer* pDqLayer, · 52 unmodified lines | ||
| 1244 | 1214 | return ENC_RETURN_SUCCESS; |
| 1245 | 1215 | } |
| 1246 | 1216 | |
| 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 | − | |
| 1282 | 1217 | int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { |
| 1283 | 1218 | |
| 1284 | 1219 | CMemoryAlign* pMA = pCtx->pMemAlign; |
| @@ -1356,7 +1291,7 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 71 unmodified lines | ||
| 1356 | 1291 | pCurLayer->iMaxSliceNum = iMaxSliceNumNew; |
| 1357 | 1292 | return ENC_RETURN_SUCCESS; |
| 1358 | 1293 | } |
| 1359 | −/* | |
| 1294 | + | |
| 1360 | 1295 | int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, |
| 1361 | 1296 | const int32_t kiThreadNum, |
| 1362 | 1297 | const int32_t kiPartitionNum) { |
| @@ -1385,8 +1320,8 @@ int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, · 22 unmodified lines | ||
| 1385 | 1320 | return ENC_RETURN_UNEXPECTED; |
| 1386 | 1321 | } |
| 1387 | 1322 | |
| 1388 | − iPartitionID = pSliceInThread->uiSliceIdx % kiPartitionNum; | |
| 1389 | − iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->uiSliceIdx / kiPartitionNum; | |
| 1323 | + iPartitionID = pSliceInThread->iSliceIdx % kiPartitionNum; | |
| 1324 | + iActualSliceIdx = aiPartitionOffset[iPartitionID] + pSliceInThread->iSliceIdx / kiPartitionNum; | |
| 1390 | 1325 | pCurLayer->ppSliceInLayer[iActualSliceIdx] = pSliceInThread; |
| 1391 | 1326 | } |
| 1392 | 1327 | } |
| @@ -1401,7 +1336,7 @@ static inline int32_t CheckAllSliceBuffer(SDqLayer* pCurLayer, const int32_t kiC · 8 unmodified lines | ||
| 1401 | 1336 | return ENC_RETURN_UNEXPECTED; |
| 1402 | 1337 | } |
| 1403 | 1338 | |
| 1404 | − if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->uiSliceIdx) { | |
| 1339 | + if ( iSliceIdx != pCurLayer->ppSliceInLayer[iSliceIdx]->iSliceIdx) { | |
| 1405 | 1340 | return ENC_RETURN_UNEXPECTED; |
| 1406 | 1341 | } |
| 1407 | 1342 | } |
| @@ -1417,10 +1352,11 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 9 unmodified lines | ||
| 1417 | 1352 | int32_t iCodedSliceNum = 0; |
| 1418 | 1353 | int32_t iThreadIdx = 0; |
| 1419 | 1354 | int32_t iRet = 0; |
| 1355 | + int32_t iThreadNum = 1; //TODO: should be equal to pCurLayer->iMaxSliceNum; | |
| 1420 | 1356 | SSliceArgument* pSliceArgument = & pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument; |
| 1421 | 1357 | int32_t iPartitionNum = (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) ? pCtx->iActiveThreadsNum : 1; |
| 1422 | 1358 | |
| 1423 | − for ( ; iThreadIdx < pCtx->iActiveThreadsNum; iThreadIdx++) { | |
| 1359 | + for ( ; iThreadIdx < iThreadNum; iThreadIdx++) { | |
| 1424 | 1360 | iCodedSliceNum += pCurLayer->sSliceThreadInfo.iMaxSliceNumInThread[iThreadIdx]; |
| 1425 | 1361 | } |
| 1426 | 1362 | |
| @@ -1442,7 +1378,7 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 15 unmodified lines | ||
| 1442 | 1378 | } |
| 1443 | 1379 | |
| 1444 | 1380 | //update ppSliceInLayer based on pSliceInThread, reordering based on slice index |
| 1445 | − iRet = ReOrderSliceInLayer (pCurLayer, pCtx->iActiveThreadsNum, iPartitionNum); | |
| 1381 | + iRet = ReOrderSliceInLayer (pCurLayer, iThreadNum, iPartitionNum); | |
| 1446 | 1382 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1447 | 1383 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, |
| 1448 | 1384 | "CWelsH264SVCEncoder::SliceLayerInfoUpdate: ReOrderSliceInLayer failed"); |
| @@ -1458,7 +1394,6 @@ int32_t SliceLayerInfoUpdate (sWelsEncCtx* pCtx, const int32_t kiDlayerIndex) { · 9 unmodified lines | ||
| 1458 | 1394 | |
| 1459 | 1395 | return ENC_RETURN_SUCCESS; |
| 1460 | 1396 | } |
| 1461 | −*/ | |
| 1462 | 1397 | |
| 1463 | 1398 | int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, const int32_t kiNalType) { |
| 1464 | 1399 | SDqLayer* pCurLayer = pEncCtx->pCurDqLayer; |
| @@ -1559,7 +1494,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 94 unmodified lines | ||
| 1559 | 1494 | uint32_t uiLen = 0; |
| 1560 | 1495 | int32_t iPosBitOffset = 0; |
| 1561 | 1496 | const int32_t kiActiveThreadsNum = pEncCtx->iActiveThreadsNum; |
| 1562 | − const int32_t kiPartitaionId = pCurSlice->uiSliceIdx % kiActiveThreadsNum; | |
| 1497 | + const int32_t kiPartitaionId = pCurSlice->iSliceIdx % kiActiveThreadsNum; | |
| 1563 | 1498 | const int32_t kiEndMbIdxOfPartition = pEncCtx->pCurDqLayer->pEndMbIdxOfPartition[kiPartitaionId]; |
| 1564 | 1499 | |
| 1565 | 1500 | const bool kbCurMbNotFirstMbOfCurSlice = ((iCurMbIdx > 0) && (pSliceCtx->pOverallMbMap[iCurMbIdx] == |
| @@ -1580,8 +1515,8 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 14 unmodified lines | ||
| 1580 | 1515 | && kbCurMbNotLastMbOfCurPartition) { //decide to add new pSlice |
| 1581 | 1516 | |
| 1582 | 1517 | 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); | |
| 1585 | 1520 | |
| 1586 | 1521 | if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { |
| 1587 | 1522 | WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); |
| @@ -1594,7 +1529,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 6 unmodified lines | ||
| 1594 | 1529 | // and will also extend when reallocated, |
| 1595 | 1530 | // tmp change is: iMaxSliceNumConstraint is alway set to be MAXSLICENUM, will not change even reallocate |
| 1596 | 1531 | 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; | |
| 1598 | 1533 | const bool kbSliceNumReachConstraint = (pSliceCtx->iSliceNumInFrame == pEncCtx->pCurDqLayer->iMaxSliceNum); |
| 1599 | 1534 | |
| 1600 | 1535 | //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 | ||
| 1654 | 1589 | const int32_t kiTotalNumMb = pCurLayer->iMbWidth * pCurLayer->iMbHeight; |
| 1655 | 1590 | const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride; |
| 1656 | 1591 | uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize]; |
| 1657 | − const int32_t kiSliceIdx = pSlice->uiSliceIdx; | |
| 1592 | + const int32_t kiSliceIdx = pSlice->iSliceIdx; | |
| 1658 | 1593 | const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset; |
| 1659 | 1594 | int32_t iEncReturn = ENC_RETURN_SUCCESS; |
| 1660 | 1595 | SDynamicSlicingStack sDss; |
| @@ -1750,7 +1685,7 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, · 89 unmodified lines | ||
| 1750 | 1685 | int32_t iCurMbIdx = -1; |
| 1751 | 1686 | const int32_t kiMvdInterTableStride = pEncCtx->iMvdCostTableStride; |
| 1752 | 1687 | uint16_t* pMvdCostTable = &pEncCtx->pMvdCostTable[pEncCtx->iMvdCostTableSize]; |
| 1753 | − const int32_t kiSliceIdx = pSlice->uiSliceIdx; | |
| 1688 | + const int32_t kiSliceIdx = pSlice->iSliceIdx; | |
| 1754 | 1689 | const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum); |
| 1755 | 1690 | const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset; |
| 1756 | 1691 | int32_t iEncReturn = ENC_RETURN_SUCCESS; |