Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 64 files). Show all
Unified · Split
| @@ -73,17 +73,17 @@ namespace WelsEnc { · 72 unmodified lines | ||
| 73 | 73 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, |
| 74 | 74 | SMB* pMbList, |
| 75 | 75 | const int32_t uiSliceIdc) { |
| 76 | − const uint16_t* kpMbMap = pSliceCtx->pOverallMbMap; | |
| 77 | − const int32_t kiMbWidth = pSliceCtx->iMbWidth; | |
| 78 | − int32_t iIdx = pSliceCtx->pFirstMbInSlice[uiSliceIdc]; | |
| 79 | − const int32_t kiEndMbInSlice = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1; | |
| 76 | + const uint16_t* kpMbMap = pSliceCtx->pOverallMbMap; | |
| 77 | + const int32_t kiMbWidth = pSliceCtx->iMbWidth; | |
| 78 | + int32_t iIdx = pSliceCtx->pFirstMbInSlice[uiSliceIdc]; | |
| 79 | + const int32_t kiEndMbInSlice = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1; | |
| 80 | 80 | |
| 81 | 81 | do { |
| 82 | − SMB* pMb = &pMbList[iIdx]; | |
| 83 | − uint32_t uiNeighborAvailFlag = 0; | |
| 84 | − const int32_t kiMbXY = pMb->iMbXY; | |
| 85 | − const int32_t kiMbX = pMb->iMbX; | |
| 86 | − const int32_t kiMbY = pMb->iMbY; | |
| 82 | + SMB* pMb = &pMbList[iIdx]; | |
| 83 | + uint32_t uiNeighborAvailFlag = 0; | |
| 84 | + const int32_t kiMbXY = pMb->iMbXY; | |
| 85 | + const int32_t kiMbX = pMb->iMbX; | |
| 86 | + const int32_t kiMbY = pMb->iMbY; | |
| 87 | 87 | bool bLeft; |
| 88 | 88 | bool bTop; |
| 89 | 89 | bool bLeftTop; |
| @@ -112,21 +112,21 @@ void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, · 22 unmodified lines | ||
| 112 | 112 | if (bRightTop) { |
| 113 | 113 | uiNeighborAvailFlag |= TOPRIGHT_MB_POS; |
| 114 | 114 | } |
| 115 | − pMb->uiNeighborAvail = (uint8_t)uiNeighborAvailFlag; | |
| 116 | − pMb->uiSliceIdc = uiSliceIdc; | |
| 115 | + pMb->uiNeighborAvail = (uint8_t)uiNeighborAvailFlag; | |
| 116 | + pMb->uiSliceIdc = uiSliceIdc; | |
| 117 | 117 | |
| 118 | 118 | ++ iIdx; |
| 119 | 119 | } while (iIdx <= kiEndMbInSlice); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSliceConsume) { |
| 123 | − int32_t* pRatioList = (int32_t*)pRatio; | |
| 123 | + int32_t* pRatioList = (int32_t*)pRatio; | |
| 124 | 124 | int32_t iAvI[MAX_SLICES_NUM]; |
| 125 | − int32_t iSumAv = 0; | |
| 126 | − uint32_t* pSliceTime = (uint32_t*)pSliceConsume; | |
| 127 | − int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice; | |
| 128 | − const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame; | |
| 129 | − int32_t iSliceIdx = 0; | |
| 125 | + int32_t iSumAv = 0; | |
| 126 | + uint32_t* pSliceTime = (uint32_t*)pSliceConsume; | |
| 127 | + int32_t* pCountMbInSlice = (int32_t*)pSliceCtx->pCountMbNumInSlice; | |
| 128 | + const int32_t kiSliceCount = pSliceCtx->iSliceNumInFrame; | |
| 129 | + int32_t iSliceIdx = 0; | |
| 130 | 130 | |
| 131 | 131 | WelsEmms(); |
| 132 | 132 | |
| @@ -145,10 +145,10 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 12 unmodified lines | ||
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { |
| 148 | − uint32_t* pSliceConsume = (uint32_t*)pConsumeTime; | |
| 149 | − uint32_t uiTotalConsume = 0; | |
| 150 | − int32_t iSliceIdx = 0; | |
| 151 | − int32_t iNeedAdj = false; | |
| 148 | + uint32_t* pSliceConsume = (uint32_t*)pConsumeTime; | |
| 149 | + uint32_t uiTotalConsume = 0; | |
| 150 | + int32_t iSliceIdx = 0; | |
| 151 | + int32_t iNeedAdj = false; | |
| 152 | 152 | |
| 153 | 153 | WelsEmms(); |
| 154 | 154 | |
| @@ -164,9 +164,9 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 9 unmodified lines | ||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | iSliceIdx = 0; |
| 167 | − float fThr = EPSN; // threshold for various cores cases | |
| 168 | − float fRmse = .0f; // root mean square error of pSlice consume ratios | |
| 169 | − const float kfMeanRatio = 1.0f / iSliceNum; | |
| 167 | + float fThr = EPSN; // threshold for various cores cases | |
| 168 | + float fRmse = .0f; // root mean square error of pSlice consume ratios | |
| 169 | + const float kfMeanRatio = 1.0f / iSliceNum; | |
| 170 | 170 | do { |
| 171 | 171 | const float fRatio = 1.0f * pSliceConsume[iSliceIdx] / uiTotalConsume; |
| 172 | 172 | const float fDiffRatio = fRatio - kfMeanRatio; |
| @@ -195,15 +195,15 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 22 unmodified lines | ||
| 195 | 195 | SDqLayer* pCurDqLayer, |
| 196 | 196 | void* pComplexRatio, |
| 197 | 197 | int32_t iCurDid) { |
| 198 | − SSliceCtx* pSliceCtx = pCurDqLayer->pSliceEncCtx; | |
| 199 | − const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame; | |
| 200 | − const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame; | |
| 201 | − int32_t iMinimalMbNum = pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required | |
| 202 | − int32_t iMaximalMbNum = 0; // dynamically assign later | |
| 203 | − int32_t* pSliceComplexRatio = (int32_t*)pComplexRatio; | |
| 204 | − int32_t iMbNumLeft = kiCountNumMb; | |
| 205 | − int32_t iRunLen[MAX_THREADS_NUM] = {0}; | |
| 206 | − int32_t iSliceIdx = 0; | |
| 198 | + SSliceCtx* pSliceCtx = pCurDqLayer->pSliceEncCtx; | |
| 199 | + const int32_t kiCountSliceNum = pSliceCtx->iSliceNumInFrame; | |
| 200 | + const int32_t kiCountNumMb = pSliceCtx->iMbNumInFrame; | |
| 201 | + int32_t iMinimalMbNum = pSliceCtx->iMbWidth; // in theory we need only 1 SMB, here let it as one SMB row required | |
| 202 | + int32_t iMaximalMbNum = 0; // dynamically assign later | |
| 203 | + int32_t* pSliceComplexRatio = (int32_t*)pComplexRatio; | |
| 204 | + int32_t iMbNumLeft = kiCountNumMb; | |
| 205 | + int32_t iRunLen[MAX_THREADS_NUM] = {0}; | |
| 206 | + int32_t iSliceIdx = 0; | |
| 207 | 207 | |
| 208 | 208 | int32_t iNumMbInEachGom = 0; |
| 209 | 209 | SWelsSvcRc* pWelsSvcRc = &pCtx->pWelsSvcRc[iCurDid]; |
| @@ -271,8 +271,8 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 61 unmodified lines | ||
| 271 | 271 | |
| 272 | 272 | |
| 273 | 273 | if (DynamicAdjustSlicePEncCtxAll (pSliceCtx, iRunLen) == 0) { |
| 274 | − const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum; | |
| 275 | − int32_t iThreadIdx = 0; | |
| 274 | + const int32_t kiThreadNum = pCtx->pSvcParam->iCountThreadsNum; | |
| 275 | + int32_t iThreadIdx = 0; | |
| 276 | 276 | do { |
| 277 | 277 | WelsEventSignal (&pCtx->pSliceThreading->pUpdateMbListEvent[iThreadIdx]); |
| 278 | 278 | WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iThreadIdx]); |
| @@ -286,16 +286,16 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 7 unmodified lines | ||
| 286 | 286 | |
| 287 | 287 | int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen, |
| 288 | 288 | const int32_t iTargetSpatialBsSize) { |
| 289 | − CMemoryAlign* pMa = NULL; | |
| 289 | + CMemoryAlign* pMa = NULL; | |
| 290 | 290 | SWelsSvcCodingParam* pPara = NULL; |
| 291 | − SSliceThreading* pSmt = NULL; | |
| 292 | − SWelsSliceBs* pSliceB = NULL; | |
| 293 | − uint8_t* pBsBase = NULL; | |
| 294 | − int32_t iNumSpatialLayers = 0; | |
| 295 | − int32_t iThreadNum = 0; | |
| 296 | − int32_t iIdx = 0; | |
| 291 | + SSliceThreading* pSmt = NULL; | |
| 292 | + SWelsSliceBs* pSliceB = NULL; | |
| 293 | + uint8_t* pBsBase = NULL; | |
| 294 | + int32_t iNumSpatialLayers = 0; | |
| 295 | + int32_t iThreadNum = 0; | |
| 296 | + int32_t iIdx = 0; | |
| 297 | 297 | int32_t iSliceBsBufferSize = 0; |
| 298 | − int16_t iMaxSliceNum = 1; | |
| 298 | + int16_t iMaxSliceNum = 1; | |
| 299 | 299 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 300 | 300 | |
| 301 | 301 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) |
| @@ -333,8 +333,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 31 unmodified lines | ||
| 333 | 333 | pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]"); |
| 334 | 334 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) |
| 335 | 335 | } else { |
| 336 | − pSmt->pSliceConsumeTime[iIdx] = NULL; | |
| 337 | − pSmt->pSliceComplexRatio[iIdx] = NULL; | |
| 336 | + pSmt->pSliceConsumeTime[iIdx] = NULL; | |
| 337 | + pSmt->pSliceComplexRatio[iIdx] = NULL; | |
| 338 | 338 | } |
| 339 | 339 | ++ iIdx; |
| 340 | 340 | } |
| @@ -358,10 +358,10 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 17 unmodified lines | ||
| 358 | 358 | |
| 359 | 359 | iIdx = 0; |
| 360 | 360 | while (iIdx < iThreadNum) { |
| 361 | − pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) *ppCtx; | |
| 362 | − pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx; | |
| 363 | − pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; | |
| 364 | − pSmt->pThreadHandles[iIdx] = 0; | |
| 361 | + pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) *ppCtx; | |
| 362 | + pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx; | |
| 363 | + pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx; | |
| 364 | + pSmt->pThreadHandles[iIdx] = 0; | |
| 365 | 365 | |
| 366 | 366 | WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace); |
| 367 | 367 | err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name); |
| @@ -395,9 +395,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 27 unmodified lines | ||
| 395 | 395 | (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs"); |
| 396 | 396 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceBs), FreeMemorySvc (ppCtx)) |
| 397 | 397 | |
| 398 | − pBsBase = (*ppCtx)->pFrameBs + iCountBsLen; | |
| 399 | − pSliceB = (*ppCtx)->pSliceBs; | |
| 400 | − iSliceBsBufferSize = iTargetSpatialBsSize; | |
| 398 | + pBsBase = (*ppCtx)->pFrameBs + iCountBsLen; | |
| 399 | + pSliceB = (*ppCtx)->pSliceBs; | |
| 400 | + iSliceBsBufferSize = iTargetSpatialBsSize; | |
| 401 | 401 | iIdx = 0; |
| 402 | 402 | while (iIdx < iMaxSliceNum) { |
| 403 | 403 | pSliceB->pBsBuffer = (uint8_t*)pMa->WelsMalloc (iSliceBsBufferSize, "pSliceB->pBsBuffer"); |
| @@ -406,12 +406,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines | ||
| 406 | 406 | pSliceB->uiSize = iSliceBsBufferSize; |
| 407 | 407 | |
| 408 | 408 | if (iIdx > 0) { |
| 409 | − pSliceB->pBs = pBsBase; | |
| 410 | − pSliceB->uiBsPos = 0; | |
| 411 | − pBsBase += iSliceBsBufferSize; | |
| 409 | + pSliceB->pBs = pBsBase; | |
| 410 | + pSliceB->uiBsPos = 0; | |
| 411 | + pBsBase += iSliceBsBufferSize; | |
| 412 | 412 | } else { |
| 413 | − pSliceB->pBs = NULL; | |
| 414 | − pSliceB->uiBsPos = 0; | |
| 413 | + pSliceB->pBs = NULL; | |
| 414 | + pSliceB->uiBsPos = 0; | |
| 415 | 415 | } |
| 416 | 416 | ++ pSliceB; |
| 417 | 417 | ++ iIdx; |
| @@ -431,22 +431,22 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 13 unmodified lines | ||
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | void ReleaseMtResource (sWelsEncCtx** ppCtx) { |
| 434 | − SWelsSliceBs* pSliceB = NULL; | |
| 435 | − SWelsSvcCodingParam* pCodingParam = NULL; | |
| 436 | − SSliceThreading* pSmt = NULL; | |
| 437 | − CMemoryAlign* pMa = NULL; | |
| 438 | − int32_t iIdx = 0; | |
| 439 | − int32_t iThreadNum = 0; | |
| 440 | − int16_t uiSliceNum = 0; | |
| 434 | + SWelsSliceBs* pSliceB = NULL; | |
| 435 | + SWelsSvcCodingParam* pCodingParam = NULL; | |
| 436 | + SSliceThreading* pSmt = NULL; | |
| 437 | + CMemoryAlign* pMa = NULL; | |
| 438 | + int32_t iIdx = 0; | |
| 439 | + int32_t iThreadNum = 0; | |
| 440 | + int16_t uiSliceNum = 0; | |
| 441 | 441 | |
| 442 | 442 | if (NULL == ppCtx || NULL == *ppCtx) |
| 443 | 443 | return; |
| 444 | 444 | |
| 445 | − pMa = (*ppCtx)->pMemAlign; | |
| 446 | − pCodingParam = (*ppCtx)->pSvcParam; | |
| 447 | − uiSliceNum = (*ppCtx)->iMaxSliceCount; | |
| 448 | − iThreadNum = (*ppCtx)->pSvcParam->iCountThreadsNum; | |
| 449 | − pSmt = (*ppCtx)->pSliceThreading; | |
| 445 | + pMa = (*ppCtx)->pMemAlign; | |
| 446 | + pCodingParam = (*ppCtx)->pSvcParam; | |
| 447 | + uiSliceNum = (*ppCtx)->iMaxSliceCount; | |
| 448 | + iThreadNum = (*ppCtx)->pSvcParam->iCountThreadsNum; | |
| 449 | + pSmt = (*ppCtx)->pSliceThreading; | |
| 450 | 450 | |
| 451 | 451 | if (NULL == pSmt) |
| 452 | 452 | return; |
| @@ -520,19 +520,19 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 67 unmodified lines | ||
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) { |
| 523 | − SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam; | |
| 524 | − SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId]; | |
| 525 | − SWelsSliceBs* pSliceBs = NULL; | |
| 526 | − const bool kbIsDynamicSlicingMode = (pDlp->sSliceCfg.uiSliceMode == SM_DYN_SLICE); | |
| 523 | + SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam; | |
| 524 | + SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId]; | |
| 525 | + SWelsSliceBs* pSliceBs = NULL; | |
| 526 | + const bool kbIsDynamicSlicingMode = (pDlp->sSliceCfg.uiSliceMode == SM_DYN_SLICE); | |
| 527 | 527 | |
| 528 | − int32_t iLayerSize = 0; | |
| 529 | − int32_t iNalIdxBase = pLbi->iNalCount; | |
| 530 | − int32_t iSliceIdx = 0; | |
| 528 | + int32_t iLayerSize = 0; | |
| 529 | + int32_t iNalIdxBase = pLbi->iNalCount; | |
| 530 | + int32_t iSliceIdx = 0; | |
| 531 | 531 | |
| 532 | 532 | if (!kbIsDynamicSlicingMode) { |
| 533 | − pSliceBs = &pCtx->pSliceBs[0]; | |
| 534 | − iLayerSize = pSliceBs->uiBsPos; // assign with base pSlice first | |
| 535 | − iSliceIdx = 1; // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1 | |
| 533 | + pSliceBs = &pCtx->pSliceBs[0]; | |
| 534 | + iLayerSize = pSliceBs->uiBsPos; // assign with base pSlice first | |
| 535 | + iSliceIdx = 1; // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1 | |
| 536 | 536 | while (iSliceIdx < iSliceCount) { |
| 537 | 537 | ++ pSliceBs; |
| 538 | 538 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| @@ -552,14 +552,14 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 13 unmodified lines | ||
| 552 | 552 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 553 | 553 | ++ iNalIdx; |
| 554 | 554 | } |
| 555 | − pLbi->iNalCount += iCountNal; | |
| 556 | − iNalIdxBase += iCountNal; | |
| 555 | + pLbi->iNalCount += iCountNal; | |
| 556 | + iNalIdxBase += iCountNal; | |
| 557 | 557 | } |
| 558 | 558 | ++ iSliceIdx; |
| 559 | 559 | } |
| 560 | − } else { // for SM_DYN_SLICE | |
| 561 | − const int32_t kiPartitionCnt = iSliceCount; | |
| 562 | − int32_t iPartitionIdx = 0; | |
| 560 | + } else { // for SM_DYN_SLICE | |
| 561 | + const int32_t kiPartitionCnt = iSliceCount; | |
| 562 | + int32_t iPartitionIdx = 0; | |
| 563 | 563 | |
| 564 | 564 | // due partition_0 has been written to pFrameBsBuffer |
| 565 | 565 | // so iLayerSize need add it |
| @@ -584,8 +584,8 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 18 unmodified lines | ||
| 584 | 584 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 585 | 585 | ++ iNalIdx; |
| 586 | 586 | } |
| 587 | − pLbi->iNalCount += iCountNal; | |
| 588 | − iNalIdxBase += iCountNal; | |
| 587 | + pLbi->iNalCount += iCountNal; | |
| 588 | + iNalIdxBase += iCountNal; | |
| 589 | 589 | } else { |
| 590 | 590 | iLayerSize += pSliceBs->uiBsPos; |
| 591 | 591 | } |
| @@ -603,17 +603,17 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 11 unmodified lines | ||
| 603 | 603 | |
| 604 | 604 | int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, |
| 605 | 605 | int32_t& iSliceSize) { |
| 606 | − SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | |
| 606 | + SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | |
| 607 | 607 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; |
| 608 | − uint8_t* pDst = pFrameBsBuffer; | |
| 609 | − const int32_t kiNalCnt = pSliceBs->iNalIndex; | |
| 610 | − int32_t iNalIdx = 0; | |
| 608 | + uint8_t* pDst = pFrameBsBuffer; | |
| 609 | + const int32_t kiNalCnt = pSliceBs->iNalIndex; | |
| 610 | + int32_t iNalIdx = 0; | |
| 611 | 611 | int32_t iNalSize = 0; |
| 612 | − const int32_t iFirstSlice = (iSliceIdx == 0); | |
| 613 | − int32_t iNalBase = iFirstSlice ? 0 : pLbi->iNalCount; | |
| 612 | + const int32_t iFirstSlice = (iSliceIdx == 0); | |
| 613 | + int32_t iNalBase = iFirstSlice ? 0 : pLbi->iNalCount; | |
| 614 | 614 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 615 | 615 | const int32_t kiWrittenLength = pCtx->iPosBsBuffer; |
| 616 | − iSliceSize = 0; | |
| 616 | + iSliceSize = 0; | |
| 617 | 617 | |
| 618 | 618 | while (iNalIdx < kiNalCnt) { |
| 619 | 619 | iNalSize = 0; |
| @@ -630,26 +630,26 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 10 unmodified lines | ||
| 630 | 630 | pSliceBs->uiBsPos = iSliceSize; |
| 631 | 631 | if (iFirstSlice) { |
| 632 | 632 | // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() |
| 633 | − pLbi->uiLayerType = VIDEO_CODING_LAYER; | |
| 634 | − pLbi->uiSpatialId = pNalHdrExt->uiDependencyId; | |
| 635 | − pLbi->uiTemporalId = pNalHdrExt->uiTemporalId; | |
| 636 | − pLbi->uiQualityId = 0; | |
| 637 | − pLbi->iNalCount = kiNalCnt; | |
| 633 | + pLbi->uiLayerType = VIDEO_CODING_LAYER; | |
| 634 | + pLbi->uiSpatialId = pNalHdrExt->uiDependencyId; | |
| 635 | + pLbi->uiTemporalId = pNalHdrExt->uiTemporalId; | |
| 636 | + pLbi->uiQualityId = 0; | |
| 637 | + pLbi->iNalCount = kiNalCnt; | |
| 638 | 638 | } else { |
| 639 | − pLbi->iNalCount += kiNalCnt; | |
| 639 | + pLbi->iNalCount += kiNalCnt; | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | return ENC_RETURN_SUCCESS; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSliceIdx, int32_t& iSliceSize) { |
| 646 | − SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | |
| 646 | + SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | |
| 647 | 647 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; |
| 648 | − uint8_t* pDst = pSliceBsBuf; | |
| 649 | − int32_t* pNalLen = &pSliceBs->iNalLen[0]; | |
| 650 | − const int32_t kiNalCnt = pSliceBs->iNalIndex; | |
| 651 | − int32_t iNalIdx = 0; | |
| 652 | − int32_t iNalSize = 0; | |
| 648 | + uint8_t* pDst = pSliceBsBuf; | |
| 649 | + int32_t* pNalLen = &pSliceBs->iNalLen[0]; | |
| 650 | + const int32_t kiNalCnt = pSliceBs->iNalIndex; | |
| 651 | + int32_t iNalIdx = 0; | |
| 652 | + int32_t iNalSize = 0; | |
| 653 | 653 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 654 | 654 | const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf); |
| 655 | 655 | |
| @@ -675,34 +675,34 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 19 unmodified lines | ||
| 675 | 675 | |
| 676 | 676 | // thread process for coding one pSlice |
| 677 | 677 | WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { |
| 678 | − SSliceThreadPrivateData* pPrivateData = (SSliceThreadPrivateData*)arg; | |
| 679 | − sWelsEncCtx* pEncPEncCtx = NULL; | |
| 680 | − SDqLayer* pCurDq = NULL; | |
| 681 | − SSlice* pSlice = NULL; | |
| 682 | − SWelsSliceBs* pSliceBs = NULL; | |
| 678 | + SSliceThreadPrivateData* pPrivateData = (SSliceThreadPrivateData*)arg; | |
| 679 | + sWelsEncCtx* pEncPEncCtx = NULL; | |
| 680 | + SDqLayer* pCurDq = NULL; | |
| 681 | + SSlice* pSlice = NULL; | |
| 682 | + SWelsSliceBs* pSliceBs = NULL; | |
| 683 | 683 | WELS_EVENT pEventsList[3]; |
| 684 | − int32_t iEventCount = 0; | |
| 685 | − WELS_THREAD_ERROR_CODE iWaitRet = WELS_THREAD_ERROR_GENERAL; | |
| 686 | − uint32_t uiThrdRet = 0; | |
| 687 | − int32_t iSliceSize = 0; | |
| 688 | − int32_t iSliceIdx = -1; | |
| 689 | − int32_t iThreadIdx = -1; | |
| 690 | − int32_t iEventIdx = -1; | |
| 691 | − bool bNeedPrefix = false; | |
| 692 | − EWelsNalUnitType eNalType = NAL_UNIT_UNSPEC_0; | |
| 693 | − EWelsNalRefIdc eNalRefIdc = NRI_PRI_LOWEST; | |
| 684 | + int32_t iEventCount = 0; | |
| 685 | + WELS_THREAD_ERROR_CODE iWaitRet = WELS_THREAD_ERROR_GENERAL; | |
| 686 | + uint32_t uiThrdRet = 0; | |
| 687 | + int32_t iSliceSize = 0; | |
| 688 | + int32_t iSliceIdx = -1; | |
| 689 | + int32_t iThreadIdx = -1; | |
| 690 | + int32_t iEventIdx = -1; | |
| 691 | + bool bNeedPrefix = false; | |
| 692 | + EWelsNalUnitType eNalType = NAL_UNIT_UNSPEC_0; | |
| 693 | + EWelsNalRefIdc eNalRefIdc = NRI_PRI_LOWEST; | |
| 694 | 694 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 695 | 695 | |
| 696 | 696 | if (NULL == pPrivateData) |
| 697 | 697 | WELS_THREAD_ROUTINE_RETURN (1); |
| 698 | 698 | |
| 699 | − pEncPEncCtx = (sWelsEncCtx*)pPrivateData->pWelsPEncCtx; | |
| 699 | + pEncPEncCtx = (sWelsEncCtx*)pPrivateData->pWelsPEncCtx; | |
| 700 | 700 | |
| 701 | − iThreadIdx = pPrivateData->iThreadIndex; | |
| 702 | − iEventIdx = iThreadIdx; | |
| 701 | + iThreadIdx = pPrivateData->iThreadIndex; | |
| 702 | + iEventIdx = iThreadIdx; | |
| 703 | 703 | |
| 704 | − pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]; | |
| 705 | − pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pExitEncodeEvent[iEventIdx]; | |
| 704 | + pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]; | |
| 705 | + pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pExitEncodeEvent[iEventIdx]; | |
| 706 | 706 | pEventsList[iEventCount++] = pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]; |
| 707 | 707 | |
| 708 | 708 | WelsThreadSetName ("OpenH264Enc_CodingSliceThreadProc"); |
| @@ -716,32 +716,32 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 7 unmodified lines | ||
| 716 | 716 | &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled |
| 717 | 717 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| 718 | 718 | SLayerBSInfo* pLbi = pPrivateData->pLayerBs; |
| 719 | − const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; | |
| 720 | − const int32_t kiCurTid = pEncPEncCtx->uiTemporalId; | |
| 721 | − SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam; | |
| 722 | − SSpatialLayerConfig* pParamD = &pCodingParam->sSpatialLayers[kiCurDid]; | |
| 719 | + const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; | |
| 720 | + const int32_t kiCurTid = pEncPEncCtx->uiTemporalId; | |
| 721 | + SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam; | |
| 722 | + SSpatialLayerConfig* pParamD = &pCodingParam->sSpatialLayers[kiCurDid]; | |
| 723 | 723 | |
| 724 | − pCurDq = pEncPEncCtx->pCurDqLayer; | |
| 725 | − eNalType = pEncPEncCtx->eNalType; | |
| 726 | − eNalRefIdc = pEncPEncCtx->eNalPriority; | |
| 727 | − bNeedPrefix = pEncPEncCtx->bNeedPrefixNalFlag; | |
| 724 | + pCurDq = pEncPEncCtx->pCurDqLayer; | |
| 725 | + eNalType = pEncPEncCtx->eNalType; | |
| 726 | + eNalRefIdc = pEncPEncCtx->eNalPriority; | |
| 727 | + bNeedPrefix = pEncPEncCtx->bNeedPrefixNalFlag; | |
| 728 | 728 | |
| 729 | 729 | if (pParamD->sSliceCfg.uiSliceMode != SM_DYN_SLICE) { |
| 730 | 730 | int64_t iSliceStart = 0; |
| 731 | 731 | bool bDsaFlag = false; |
| 732 | − iSliceIdx = pPrivateData->iSliceIndex; | |
| 733 | − pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | |
| 734 | − pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | |
| 732 | + iSliceIdx = pPrivateData->iSliceIndex; | |
| 733 | + pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | |
| 734 | + pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | |
| 735 | 735 | |
| 736 | − bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE) | |
| 736 | + bDsaFlag = (((pParamD->sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE) | |
| 737 | 737 | || (pParamD->sSliceCfg.uiSliceMode == SM_AUTO_SLICE)) && |
| 738 | 738 | pCodingParam->iMultipleThreadIdc > 1 && |
| 739 | 739 | pCodingParam->iMultipleThreadIdc >= pParamD->sSliceCfg.sSliceArgument.uiSliceNum); |
| 740 | 740 | if (bDsaFlag) |
| 741 | 741 | iSliceStart = WelsTime(); |
| 742 | 742 | |
| 743 | − pSliceBs->uiBsPos = 0; | |
| 744 | − pSliceBs->iNalIndex = 0; | |
| 743 | + pSliceBs->uiBsPos = 0; | |
| 744 | + pSliceBs->iNalIndex = 0; | |
| 745 | 745 | assert ((void*) (&pSliceBs->sBsWrite) == (void*)pSlice->pSliceBsa); |
| 746 | 746 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); |
| 747 | 747 | |
| @@ -825,21 +825,21 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 77 unmodified lines | ||
| 825 | 825 | &pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 826 | 826 | WelsEventSignal ( |
| 827 | 827 | &pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent); |
| 828 | − } else { // for SM_DYN_SLICE parallelization | |
| 829 | − SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; | |
| 830 | − const int32_t kiPartitionId = iThreadIdx; | |
| 831 | − const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; | |
| 832 | − const int32_t kiFirstMbInPartition = pPrivateData->iStartMbIndex; // inclusive | |
| 833 | − const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive | |
| 834 | − int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition; | |
| 828 | + } else { // for SM_DYN_SLICE parallelization | |
| 829 | + SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; | |
| 830 | + const int32_t kiPartitionId = iThreadIdx; | |
| 831 | + const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; | |
| 832 | + const int32_t kiFirstMbInPartition = pPrivateData->iStartMbIndex; // inclusive | |
| 833 | + const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive | |
| 834 | + int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition; | |
| 835 | 835 | |
| 836 | 836 | iSliceIdx = pPrivateData->iSliceIndex; |
| 837 | 837 | |
| 838 | − pSliceCtx->pFirstMbInSlice[iSliceIdx] = kiFirstMbInPartition; | |
| 839 | − pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; // one pSlice per partition intialized, dynamic slicing inside | |
| 840 | − pCurDq->pLastMbIdxOfPartition[kiPartitionId] = kiEndMbInPartition - 1; | |
| 838 | + pSliceCtx->pFirstMbInSlice[iSliceIdx] = kiFirstMbInPartition; | |
| 839 | + pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; // one pSlice per partition intialized, dynamic slicing inside | |
| 840 | + pCurDq->pLastMbIdxOfPartition[kiPartitionId] = kiEndMbInPartition - 1; | |
| 841 | 841 | |
| 842 | − pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | |
| 842 | + pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | |
| 843 | 843 | |
| 844 | 844 | while (iAnyMbLeftInPartition > 0) { |
| 845 | 845 | if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { |
| @@ -849,11 +849,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 3 unmodified lines | ||
| 849 | 849 | break; |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | − pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | |
| 853 | − pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | |
| 852 | + pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | |
| 853 | + pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx]; | |
| 854 | 854 | |
| 855 | − pSliceBs->uiBsPos = 0; | |
| 856 | − pSliceBs->iNalIndex = 0; | |
| 855 | + pSliceBs->uiBsPos = 0; | |
| 856 | + pSliceBs->iNalIndex = 0; | |
| 857 | 857 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); |
| 858 | 858 | |
| 859 | 859 | if (bNeedPrefix) { |
| @@ -978,8 +978,8 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 118 unmodified lines | ||
| 978 | 978 | int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, |
| 979 | 979 | WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi, |
| 980 | 980 | const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) { |
| 981 | − int32_t iEndMbIdx = 0; | |
| 982 | − int32_t iIdx = 0; | |
| 981 | + int32_t iEndMbIdx = 0; | |
| 982 | + int32_t iIdx = 0; | |
| 983 | 983 | const int32_t kiEventCnt = uiNumThreads; |
| 984 | 984 | |
| 985 | 985 | if (pPriData == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) { |
| @@ -993,10 +993,10 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, · 7 unmodified lines | ||
| 993 | 993 | if (bIsDynamicSlicingMode) { |
| 994 | 994 | iEndMbIdx = pSliceCtx->iMbNumInFrame; |
| 995 | 995 | for (iIdx = kiEventCnt - 1; iIdx >= 0; --iIdx) { |
| 996 | − const int32_t iFirstMbIdx = pSliceCtx->pFirstMbInSlice[iIdx]; | |
| 997 | − pPriData[iIdx].iStartMbIndex = iFirstMbIdx; | |
| 998 | − pPriData[iIdx].iEndMbIndex = iEndMbIdx; | |
| 999 | − iEndMbIdx = iFirstMbIdx; | |
| 996 | + const int32_t iFirstMbIdx = pSliceCtx->pFirstMbInSlice[iIdx]; | |
| 997 | + pPriData[iIdx].iStartMbIndex = iFirstMbIdx; | |
| 998 | + pPriData[iIdx].iEndMbIndex = iEndMbIdx; | |
| 999 | + iEndMbIdx = iFirstMbIdx; | |
| 1000 | 1000 | } |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| @@ -1021,8 +1021,8 @@ int32_t DynamicDetectCpuCores() { · 18 unmodified lines | ||
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { |
| 1024 | − SDqLayer* pCurDq = pCtx->ppDqLayerList[0]; | |
| 1025 | − int32_t iNeedAdj = 1; | |
| 1024 | + SDqLayer* pCurDq = pCtx->ppDqLayerList[0]; | |
| 1025 | + int32_t iNeedAdj = 1; | |
| 1026 | 1026 | #ifdef MT_DEBUG |
| 1027 | 1027 | int64_t iT0 = WelsTime(); |
| 1028 | 1028 | #endif//MT_DEBUG |
| @@ -1121,10 +1121,10 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 92 unmodified lines | ||
| 1121 | 1121 | |
| 1122 | 1122 | pPara = pCtx->pSvcParam; |
| 1123 | 1123 | while (iSpatialIdx < iSpatialNum) { |
| 1124 | − const int32_t kiDid = pDidList[iSpatialIdx]; | |
| 1125 | − SSpatialLayerInternal* pDlp = &pPara->sDependencyLayers[kiDid]; | |
| 1126 | − SSliceConfig* pMso = &pDlp->sSliceCfg; | |
| 1127 | − SDqLayer* pCurDq = pCtx->ppDqLayerList[kiDid]; | |
| 1124 | + const int32_t kiDid = pDidList[iSpatialIdx]; | |
| 1125 | + SSpatialLayerInternal* pDlp = &pPara->sDependencyLayers[kiDid]; | |
| 1126 | + SSliceConfig* pMso = &pDlp->sSliceCfg; | |
| 1127 | + SDqLayer* pCurDq = pCtx->ppDqLayerList[kiDid]; | |
| 1128 | 1128 | SSliceCtx* pSliceCtx = pCurDq->pSliceEncCtx; |
| 1129 | 1129 | const uint32_t kuiCountSliceNum = pSliceCtx->iSliceNumInFrame; |
| 1130 | 1130 | if (pCtx->pSliceThreading) { |