Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 54 files). Show all
Unified · Split
| @@ -131,7 +131,7 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 130 unmodified lines | |||
| 131 | WelsEmms(); | 131 | WelsEmms(); |
| 132 | 132 | ||
| 133 | while (iSliceIdx < kiSliceCount) { | 133 | while (iSliceIdx < kiSliceCount) { |
| 134 | iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pCountMbInSlice[iSliceIdx], pSliceTime[iSliceIdx]); | 134 | iAvI[iSliceIdx] = WELS_DIV_ROUND (INT_MULTIPLY * pCountMbInSlice[iSliceIdx], pSliceTime[iSliceIdx]); |
| 135 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d", | 135 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d", |
| 136 | iSliceIdx, | 136 | iSliceIdx, |
| 137 | pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); | 137 | pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]); |
| @@ -183,7 +183,7 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 45 unmodified lines | |||
| 183 | } else | 183 | } else |
| 184 | fThr = 1.0f; | 184 | fThr = 1.0f; |
| 185 | if (fRmse > fThr) | 185 | if (fRmse > fThr) |
| 186 | iNeedAdj = true; | 186 | iNeedAdj = true; |
| 187 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, | 187 | MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, |
| 188 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d", | 188 | "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d", |
| 189 | iNeedAdj, fRmse, fThr, iSliceNum); | 189 | iNeedAdj, fRmse, fThr, iSliceNum); |
| @@ -222,19 +222,19 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 32 unmodified lines | |||
| 222 | if (iNumMbInEachGom * kiCountSliceNum >= kiCountNumMb) { | 222 | if (iNumMbInEachGom * kiCountSliceNum >= kiCountNumMb) { |
| 223 | return; | 223 | return; |
| 224 | } | 224 | } |
| 225 | iMinimalMbNum = iNumMbInEachGom; | 225 | iMinimalMbNum = iNumMbInEachGom; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | if (kiCountSliceNum < 2 || (kiCountSliceNum & 0x01)) // we need suppose uiSliceNum is even for multiple threading | 228 | if (kiCountSliceNum < 2 || (kiCountSliceNum & 0x01)) // we need suppose uiSliceNum is even for multiple threading |
| 229 | return; | 229 | return; |
| 230 | 230 | ||
| 231 | iMaximalMbNum = kiCountNumMb - (kiCountSliceNum - 1) * iMinimalMbNum; | 231 | iMaximalMbNum = kiCountNumMb - (kiCountSliceNum - 1) * iMinimalMbNum; |
| 232 | 232 | ||
| 233 | WelsEmms(); | 233 | WelsEmms(); |
| 234 | 234 | ||
| 235 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d", iCurDid, kiCountNumMb); | 235 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d", iCurDid, kiCountNumMb); |
| 236 | 236 | ||
| 237 | iSliceIdx = 0; | 237 | iSliceIdx = 0; |
| 238 | while (iSliceIdx + 1 < kiCountSliceNum) { | 238 | while (iSliceIdx + 1 < kiCountSliceNum) { |
| 239 | int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceComplexRatio[iSliceIdx], INT_MULTIPLY); | 239 | int32_t iNumMbAssigning = WELS_DIV_ROUND (kiCountNumMb * pSliceComplexRatio[iSliceIdx], INT_MULTIPLY); |
| 240 | 240 | ||
| @@ -245,9 +245,9 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 4 unmodified lines | |||
| 245 | 245 | ||
| 246 | // make sure one GOM at least in each pSlice for safe | 246 | // make sure one GOM at least in each pSlice for safe |
| 247 | if (iNumMbAssigning < iMinimalMbNum) | 247 | if (iNumMbAssigning < iMinimalMbNum) |
| 248 | iNumMbAssigning = iMinimalMbNum; | 248 | iNumMbAssigning = iMinimalMbNum; |
| 249 | else if (iNumMbAssigning > iMaximalMbNum) | 249 | else if (iNumMbAssigning > iMaximalMbNum) |
| 250 | iNumMbAssigning = iMaximalMbNum; | 250 | iNumMbAssigning = iMaximalMbNum; |
| 251 | 251 | ||
| 252 | assert (iNumMbAssigning > 0); | 252 | assert (iNumMbAssigning > 0); |
| 253 | 253 | ||
| @@ -256,13 +256,13 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 2 unmodified lines | |||
| 256 | assert (0); | 256 | assert (0); |
| 257 | return; | 257 | return; |
| 258 | } | 258 | } |
| 259 | iRunLen[iSliceIdx] = iNumMbAssigning; | 259 | iRunLen[iSliceIdx] = iNumMbAssigning; |
| 260 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, | 260 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, |
| 261 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", | 261 | "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d", |
| 262 | iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], | 262 | iSliceIdx, pSliceComplexRatio[iSliceIdx] * 1.0f / INT_MULTIPLY, pSliceCtx->pCountMbNumInSlice[iSliceIdx], |
| 263 | iNumMbAssigning); | 263 | iNumMbAssigning); |
| 264 | ++ iSliceIdx; | 264 | ++ iSliceIdx; |
| 265 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts | 265 | iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts |
| 266 | } | 266 | } |
| 267 | iRunLen[iSliceIdx] = iMbNumLeft; | 267 | iRunLen[iSliceIdx] = iMbNumLeft; |
| 268 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, | 268 | MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, |
| @@ -301,16 +301,16 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 32 unmodified lines | |||
| 301 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) | 301 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) |
| 302 | return 1; | 302 | return 1; |
| 303 | 303 | ||
| 304 | pMa = (*ppCtx)->pMemAlign; | 304 | pMa = (*ppCtx)->pMemAlign; |
| 305 | pPara = pCodingParam; | 305 | pPara = pCodingParam; |
| 306 | iNumSpatialLayers = pPara->iSpatialLayerNum; | 306 | iNumSpatialLayers = pPara->iSpatialLayerNum; |
| 307 | iThreadNum = pPara->iCountThreadsNum; | 307 | iThreadNum = pPara->iCountThreadsNum; |
| 308 | iMaxSliceNum = (*ppCtx)->iMaxSliceCount; | 308 | iMaxSliceNum = (*ppCtx)->iMaxSliceCount; |
| 309 | 309 | ||
| 310 | pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading"); | 310 | pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading"); |
| 311 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx)) | 311 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx)) |
| 312 | (*ppCtx)->pSliceThreading = pSmt; | 312 | (*ppCtx)->pSliceThreading = pSmt; |
| 313 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, | 313 | pSmt->pThreadPEncCtx = (SSliceThreadPrivateData*)pMa->WelsMalloc (sizeof (SSliceThreadPrivateData) * iThreadNum, |
| 314 | "pThreadPEncCtx"); | 314 | "pThreadPEncCtx"); |
| 315 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) | 315 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadPEncCtx), FreeMemorySvc (ppCtx)) |
| 316 | 316 | ||
| @@ -323,14 +323,14 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 6 unmodified lines | |||
| 323 | 323 | ||
| 324 | iIdx = 0; | 324 | iIdx = 0; |
| 325 | while (iIdx < iNumSpatialLayers) { | 325 | while (iIdx < iNumSpatialLayers) { |
| 326 | SSliceConfig* pMso = &pPara->sSpatialLayers[iIdx].sSliceCfg; | 326 | SSliceConfig* pMso = &pPara->sSpatialLayers[iIdx].sSliceCfg; |
| 327 | const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum; | 327 | const int32_t kiSliceNum = pMso->sSliceArgument.uiSliceNum; |
| 328 | if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE)) | 328 | if (((pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE) || (pMso->uiSliceMode == SM_AUTO_SLICE)) |
| 329 | && pPara->iMultipleThreadIdc > 1 | 329 | && pPara->iMultipleThreadIdc > 1 |
| 330 | && pPara->iMultipleThreadIdc >= kiSliceNum) { | 330 | && pPara->iMultipleThreadIdc >= kiSliceNum) { |
| 331 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); | 331 | pSmt->pSliceConsumeTime[iIdx] = (uint32_t*)pMa->WelsMallocz (kiSliceNum * sizeof (uint32_t), "pSliceConsumeTime[]"); |
| 332 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) | 332 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceConsumeTime[iIdx]), FreeMemorySvc (ppCtx)) |
| 333 | pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]"); | 333 | pSmt->pSliceComplexRatio[iIdx] = (int32_t*)pMa->WelsMalloc (kiSliceNum * sizeof (int32_t), "pSliceComplexRatio[]"); |
| 334 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) | 334 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceComplexRatio[iIdx]), FreeMemorySvc (ppCtx)) |
| 335 | } else { | 335 | } else { |
| 336 | pSmt->pSliceConsumeTime[iIdx] = NULL; | 336 | pSmt->pSliceConsumeTime[iIdx] = NULL; |
| @@ -348,7 +348,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 11 unmodified lines | |||
| 348 | fclose (pSmt->pFSliceDiff); | 348 | fclose (pSmt->pFSliceDiff); |
| 349 | pSmt->pFSliceDiff = NULL; | 349 | pSmt->pFSliceDiff = NULL; |
| 350 | } | 350 | } |
| 351 | pSmt->pFSliceDiff = fopen ("slice_time.txt", "wt+"); | 351 | pSmt->pFSliceDiff = fopen ("slice_time.txt", "wt+"); |
| 352 | #endif//MT_DEBUG | 352 | #endif//MT_DEBUG |
| 353 | 353 | ||
| 354 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "encpEncCtx= 0x%p", (void*) *ppCtx); | 354 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "encpEncCtx= 0x%p", (void*) *ppCtx); |
| @@ -392,7 +392,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 37 unmodified lines | |||
| 392 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); | 392 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); |
| 393 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); | 393 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); |
| 394 | 394 | ||
| 395 | (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs"); | 395 | (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs"); |
| 396 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceBs), FreeMemorySvc (ppCtx)) | 396 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSliceBs), FreeMemorySvc (ppCtx)) |
| 397 | 397 | ||
| 398 | pBsBase = (*ppCtx)->pFrameBs + iCountBsLen; | 398 | pBsBase = (*ppCtx)->pFrameBs + iCountBsLen; |
| @@ -403,7 +403,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 4 unmodified lines | |||
| 403 | pSliceB->pBsBuffer = (uint8_t*)pMa->WelsMalloc (iSliceBsBufferSize, "pSliceB->pBsBuffer"); | 403 | pSliceB->pBsBuffer = (uint8_t*)pMa->WelsMalloc (iSliceBsBufferSize, "pSliceB->pBsBuffer"); |
| 404 | 404 | ||
| 405 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSliceB->pBsBuffer), FreeMemorySvc (ppCtx)) | 405 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSliceB->pBsBuffer), FreeMemorySvc (ppCtx)) |
| 406 | pSliceB->uiSize = iSliceBsBufferSize; | 406 | pSliceB->uiSize = iSliceBsBufferSize; |
| 407 | 407 | ||
| 408 | if (iIdx > 0) { | 408 | if (iIdx > 0) { |
| 409 | pSliceB->pBs = pBsBase; | 409 | pSliceB->pBs = pBsBase; |
| @@ -537,7 +537,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 127 unmodified lines | |||
| 537 | ++ pSliceBs; | 537 | ++ pSliceBs; |
| 538 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | 538 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 539 | int32_t iNalIdx = 0; | 539 | int32_t iNalIdx = 0; |
| 540 | const int32_t iCountNal = pSliceBs->iNalIndex; | 540 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| 541 | 541 | ||
| 542 | #if MT_DEBUG_BS_WR | 542 | #if MT_DEBUG_BS_WR |
| 543 | assert (pSliceBs->bSliceCodedFlag); | 543 | assert (pSliceBs->bSliceCodedFlag); |
| @@ -549,7 +549,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 5 unmodified lines | |||
| 549 | iLayerSize += pSliceBs->uiBsPos; | 549 | iLayerSize += pSliceBs->uiBsPos; |
| 550 | 550 | ||
| 551 | while (iNalIdx < iCountNal) { | 551 | while (iNalIdx < iCountNal) { |
| 552 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | 552 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 553 | ++ iNalIdx; | 553 | ++ iNalIdx; |
| 554 | } | 554 | } |
| 555 | pLbi->iNalCount += iCountNal; | 555 | pLbi->iNalCount += iCountNal; |
| @@ -567,13 +567,13 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 11 unmodified lines | |||
| 567 | const int32_t kiCountSlicesCoded = pCtx->pCurDqLayer->pNumSliceCodedOfPartition[iPartitionIdx]; | 567 | const int32_t kiCountSlicesCoded = pCtx->pCurDqLayer->pNumSliceCodedOfPartition[iPartitionIdx]; |
| 568 | int32_t iIdx = 0; | 568 | int32_t iIdx = 0; |
| 569 | 569 | ||
| 570 | iSliceIdx = iPartitionIdx; | 570 | iSliceIdx = iPartitionIdx; |
| 571 | while (iIdx < kiCountSlicesCoded) { | 571 | while (iIdx < kiCountSlicesCoded) { |
| 572 | pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | 572 | pSliceBs = &pCtx->pSliceBs[iSliceIdx]; |
| 573 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | 573 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 574 | if (iPartitionIdx > 0) { | 574 | if (iPartitionIdx > 0) { |
| 575 | int32_t iNalIdx = 0; | 575 | int32_t iNalIdx = 0; |
| 576 | const int32_t iCountNal = pSliceBs->iNalIndex; | 576 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| 577 | 577 | ||
| 578 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | 578 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage |
| 579 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | 579 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; |
| @@ -581,13 +581,13 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 1 unmodified line | |||
| 581 | iLayerSize += pSliceBs->uiBsPos; | 581 | iLayerSize += pSliceBs->uiBsPos; |
| 582 | 582 | ||
| 583 | while (iNalIdx < iCountNal) { | 583 | while (iNalIdx < iCountNal) { |
| 584 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | 584 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 585 | ++ iNalIdx; | 585 | ++ iNalIdx; |
| 586 | } | 586 | } |
| 587 | pLbi->iNalCount += iCountNal; | 587 | pLbi->iNalCount += iCountNal; |
| 588 | iNalIdxBase += iCountNal; | 588 | iNalIdxBase += iCountNal; |
| 589 | } else { | 589 | } else { |
| 590 | iLayerSize += pSliceBs->uiBsPos; | 590 | iLayerSize += pSliceBs->uiBsPos; |
| 591 | } | 591 | } |
| 592 | } | 592 | } |
| 593 | 593 | ||
| @@ -622,12 +622,12 @@ int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFr · 28 unmodified lines | |||
| 622 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | 622 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 623 | iSliceSize += iNalSize; | 623 | iSliceSize += iNalSize; |
| 624 | pDst += iNalSize; | 624 | pDst += iNalSize; |
| 625 | pLbi->pNalLengthInByte[iNalBase + iNalIdx] = iNalSize; | 625 | pLbi->pNalLengthInByte[iNalBase + iNalIdx] = iNalSize; |
| 626 | 626 | ||
| 627 | ++ iNalIdx; | 627 | ++ iNalIdx; |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | pSliceBs->uiBsPos = iSliceSize; | 630 | pSliceBs->uiBsPos = iSliceSize; |
| 631 | if (iFirstSlice) { | 631 | if (iFirstSlice) { |
| 632 | // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() | 632 | // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() |
| 633 | pLbi->uiLayerType = VIDEO_CODING_LAYER; | 633 | pLbi->uiLayerType = VIDEO_CODING_LAYER; |
| @@ -653,7 +653,7 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 19 unmodified lines | |||
| 653 | int32_t iReturn = ENC_RETURN_SUCCESS; | 653 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 654 | const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf); | 654 | const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf); |
| 655 | 655 | ||
| 656 | iSliceSize = 0; | 656 | iSliceSize = 0; |
| 657 | assert (kiNalCnt <= 2); | 657 | assert (kiNalCnt <= 2); |
| 658 | if (kiNalCnt > 2) | 658 | if (kiNalCnt > 2) |
| 659 | return 0; | 659 | return 0; |
| @@ -668,7 +668,7 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 8 unmodified lines | |||
| 668 | pDst += iNalSize; | 668 | pDst += iNalSize; |
| 669 | ++ iNalIdx; | 669 | ++ iNalIdx; |
| 670 | } | 670 | } |
| 671 | pSliceBs->uiBsPos = iSliceSize; | 671 | pSliceBs->uiBsPos = iSliceSize; |
| 672 | 672 | ||
| 673 | return iReturn; | 673 | return iReturn; |
| 674 | } | 674 | } |
| @@ -727,7 +727,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 52 unmodified lines | |||
| 727 | bNeedPrefix = pEncPEncCtx->bNeedPrefixNalFlag; | 727 | bNeedPrefix = pEncPEncCtx->bNeedPrefixNalFlag; |
| 728 | 728 | ||
| 729 | if (pParamD->sSliceCfg.uiSliceMode != SM_DYN_SLICE) { | 729 | if (pParamD->sSliceCfg.uiSliceMode != SM_DYN_SLICE) { |
| 730 | int64_t iSliceStart = 0; | 730 | int64_t iSliceStart = 0; |
| 731 | bool bDsaFlag = false; | 731 | bool bDsaFlag = false; |
| 732 | iSliceIdx = pPrivateData->iSliceIndex; | 732 | iSliceIdx = pPrivateData->iSliceIndex; |
| 733 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; | 733 | pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx]; |
| @@ -746,7 +746,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 12 unmodified lines | |||
| 746 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); | 746 | InitBits (&pSliceBs->sBsWrite, pSliceBs->pBsBuffer, pSliceBs->uiSize); |
| 747 | 747 | ||
| 748 | #if MT_DEBUG_BS_WR | 748 | #if MT_DEBUG_BS_WR |
| 749 | pSliceBs->bSliceCodedFlag = false; | 749 | pSliceBs->bSliceCodedFlag = false; |
| 750 | #endif//MT_DEBUG_BS_WR | 750 | #endif//MT_DEBUG_BS_WR |
| 751 | 751 | ||
| 752 | if (bNeedPrefix) { | 752 | if (bNeedPrefix) { |
| @@ -772,7 +772,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 19 unmodified lines | |||
| 772 | WelsUnloadNalForSlice (pSliceBs); | 772 | WelsUnloadNalForSlice (pSliceBs); |
| 773 | 773 | ||
| 774 | if (0 == iSliceIdx) { | 774 | if (0 == iSliceIdx) { |
| 775 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 775 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| 776 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); | 776 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); |
| 777 | if (ENC_RETURN_SUCCESS != iReturn) { | 777 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 778 | uiThrdRet = iReturn; | 778 | uiThrdRet = iReturn; |
| @@ -818,7 +818,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 39 unmodified lines | |||
| 818 | #endif//SLICE_INFO_OUTPUT | 818 | #endif//SLICE_INFO_OUTPUT |
| 819 | 819 | ||
| 820 | #if MT_DEBUG_BS_WR | 820 | #if MT_DEBUG_BS_WR |
| 821 | pSliceBs->bSliceCodedFlag = true; | 821 | pSliceBs->bSliceCodedFlag = true; |
| 822 | #endif//MT_DEBUG_BS_WR | 822 | #endif//MT_DEBUG_BS_WR |
| 823 | 823 | ||
| 824 | WelsEventSignal ( | 824 | WelsEventSignal ( |
| @@ -833,7 +833,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 8 unmodified lines | |||
| 833 | const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive | 833 | const int32_t kiEndMbInPartition = pPrivateData->iEndMbIndex; // exclusive |
| 834 | int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition; | 834 | int32_t iAnyMbLeftInPartition = kiEndMbInPartition - kiFirstMbInPartition; |
| 835 | 835 | ||
| 836 | iSliceIdx = pPrivateData->iSliceIndex; | 836 | iSliceIdx = pPrivateData->iSliceIndex; |
| 837 | 837 | ||
| 838 | pSliceCtx->pFirstMbInSlice[iSliceIdx] = kiFirstMbInPartition; | 838 | pSliceCtx->pFirstMbInSlice[iSliceIdx] = kiFirstMbInPartition; |
| 839 | pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; // one pSlice per partition intialized, dynamic slicing inside | 839 | pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; // one pSlice per partition intialized, dynamic slicing inside |
| @@ -845,7 +845,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 5 unmodified lines | |||
| 845 | if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { | 845 | if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { |
| 846 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage | 846 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage |
| 847 | // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure | 847 | // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure |
| 848 | uiThrdRet = 1; | 848 | uiThrdRet = 1; |
| 849 | break; | 849 | break; |
| 850 | } | 850 | } |
| 851 | 851 | ||
| @@ -880,7 +880,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 28 unmodified lines | |||
| 880 | 880 | ||
| 881 | if (0 == kiPartitionId) { | 881 | if (0 == kiPartitionId) { |
| 882 | if (0 == iSliceIdx) | 882 | if (0 == iSliceIdx) |
| 883 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 883 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; |
| 884 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, | 884 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, |
| 885 | iSliceSize); | 885 | iSliceSize); |
| 886 | if (ENC_RETURN_SUCCESS != iReturn) { | 886 | if (ENC_RETURN_SUCCESS != iReturn) { |
| @@ -931,13 +931,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 44 unmodified lines | |||
| 931 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice | 931 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedEvent[iEventIdx]); // mean finished coding current pSlice |
| 932 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent); | 932 | WelsEventSignal (&pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent); |
| 933 | } | 933 | } |
| 934 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal | 934 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 1 == iWaitRet) { // exit thread signal |
| 935 | uiThrdRet = 0; | 935 | uiThrdRet = 0; |
| 936 | break; | 936 | break; |
| 937 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal | 937 | } else if (WELS_THREAD_ERROR_WAIT_OBJECT_0 + 2 == iWaitRet) { // update pMb list singal |
| 938 | iSliceIdx = | 938 | iSliceIdx = |
| 939 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable | 939 | iEventIdx; // pPrivateData->iSliceIndex; old threads can not be terminated, pPrivateData is not correct for applicable |
| 940 | pCurDq = pEncPEncCtx->pCurDqLayer; | 940 | pCurDq = pEncPEncCtx->pCurDqLayer; |
| 941 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); | 941 | UpdateMbListNeighborParallel (pCurDq->pSliceEncCtx, pCurDq->sMbDataP, iSliceIdx); |
| 942 | WelsEventSignal ( | 942 | WelsEventSignal ( |
| 943 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice | 943 | &pEncPEncCtx->pSliceThreading->pFinUpdateMbListEvent[iEventIdx]); // mean finished update pMb list for this pSlice |
| @@ -945,7 +945,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 1 unmodified line | |||
| 945 | WelsLog (& (pEncPEncCtx->sLogCtx), WELS_LOG_WARNING, | 945 | WelsLog (& (pEncPEncCtx->sLogCtx), WELS_LOG_WARNING, |
| 946 | "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!", iEventIdx, | 946 | "[MT] CodingSliceThreadProc(), waiting pReadySliceCodingEvent[%d] failed(%d) and thread%d terminated!", iEventIdx, |
| 947 | iWaitRet, iThreadIdx); | 947 | iWaitRet, iThreadIdx); |
| 948 | uiThrdRet = 1; | 948 | uiThrdRet = 1; |
| 949 | break; | 949 | break; |
| 950 | } | 950 | } |
| 951 | } while (1); | 951 | } while (1); |
| @@ -991,7 +991,7 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, · 39 unmodified lines | |||
| 991 | 991 | ||
| 992 | //////////////////////////////////////// | 992 | //////////////////////////////////////// |
| 993 | if (bIsDynamicSlicingMode) { | 993 | if (bIsDynamicSlicingMode) { |
| 994 | iEndMbIdx = pSliceCtx->iMbNumInFrame; | 994 | iEndMbIdx = pSliceCtx->iMbNumInFrame; |
| 995 | for (iIdx = kiEventCnt - 1; iIdx >= 0; --iIdx) { | 995 | for (iIdx = kiEventCnt - 1; iIdx >= 0; --iIdx) { |
| 996 | const int32_t iFirstMbIdx = pSliceCtx->pFirstMbInSlice[iIdx]; | 996 | const int32_t iFirstMbIdx = pSliceCtx->pFirstMbInSlice[iIdx]; |
| 997 | pPriData[iIdx].iStartMbIndex = iFirstMbIdx; | 997 | pPriData[iIdx].iStartMbIndex = iFirstMbIdx; |
| @@ -1003,7 +1003,7 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, · 5 unmodified lines | |||
| 1003 | iIdx = 0; | 1003 | iIdx = 0; |
| 1004 | while (iIdx < kiEventCnt) { | 1004 | while (iIdx < kiEventCnt) { |
| 1005 | pPriData[iIdx].pLayerBs = pLbi; | 1005 | pPriData[iIdx].pLayerBs = pLbi; |
| 1006 | pPriData[iIdx].iSliceIndex = iIdx; | 1006 | pPriData[iIdx].iSliceIndex = iIdx; |
| 1007 | if (pEventsList[iIdx]) | 1007 | if (pEventsList[iIdx]) |
| 1008 | WelsEventSignal (&pEventsList[iIdx]); | 1008 | WelsEventSignal (&pEventsList[iIdx]); |
| 1009 | if (pMasterEventsList[iIdx]) | 1009 | if (pMasterEventsList[iIdx]) |
| @@ -1027,10 +1027,10 @@ int32_t AdjustBaseLayer (sWelsEncCtx* pCtx) { · 17 unmodified lines | |||
| 1027 | int64_t iT0 = WelsTime(); | 1027 | int64_t iT0 = WelsTime(); |
| 1028 | #endif//MT_DEBUG | 1028 | #endif//MT_DEBUG |
| 1029 | 1029 | ||
| 1030 | pCtx->pCurDqLayer = pCurDq; | 1030 | pCtx->pCurDqLayer = pCurDq; |
| 1031 | 1031 | ||
| 1032 | // do not need adjust due to not different at both slices of consumed time | 1032 | // do not need adjust due to not different at both slices of consumed time |
| 1033 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->pSliceEncCtx->iSliceNumInFrame); | 1033 | iNeedAdj = NeedDynamicAdjust (pCtx->pSliceThreading->pSliceConsumeTime[0], pCurDq->pSliceEncCtx->iSliceNumInFrame); |
| 1034 | if (iNeedAdj) | 1034 | if (iNeedAdj) |
| 1035 | DynamicAdjustSlicing (pCtx, | 1035 | DynamicAdjustSlicing (pCtx, |
| 1036 | pCurDq, | 1036 | pCurDq, |
| @@ -1056,7 +1056,7 @@ int32_t AdjustEnhanceLayer (sWelsEncCtx* pCtx, int32_t iCurDid) { · 19 unmodified lines | |||
| 1056 | // uiSliceMode of referencing spatial should be SM_FIXEDSLCNUM_SLICE | 1056 | // uiSliceMode of referencing spatial should be SM_FIXEDSLCNUM_SLICE |
| 1057 | // if using spatial base layer for complexity estimation | 1057 | // if using spatial base layer for complexity estimation |
| 1058 | 1058 | ||
| 1059 | const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0) | 1059 | const bool kbModelingFromSpatial = (pCtx->pCurDqLayer->pRefLayer != NULL && iCurDid > 0) |
| 1060 | && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE | 1060 | && (pCtx->pSvcParam->sSpatialLayers[iCurDid - 1].sSliceCfg.uiSliceMode == SM_FIXEDSLCNUM_SLICE |
| 1061 | && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid - | 1061 | && pCtx->pSvcParam->iMultipleThreadIdc >= pCtx->pSvcParam->sSpatialLayers[iCurDid - |
| 1062 | 1].sSliceCfg.sSliceArgument.uiSliceNum); | 1062 | 1].sSliceCfg.sSliceArgument.uiSliceNum); |
| @@ -1119,7 +1119,7 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 56 unmodified lines | |||
| 1119 | if (iSpatialNum > MAX_DEPENDENCY_LAYER) | 1119 | if (iSpatialNum > MAX_DEPENDENCY_LAYER) |
| 1120 | return; | 1120 | return; |
| 1121 | 1121 | ||
| 1122 | pPara = pCtx->pSvcParam; | 1122 | pPara = pCtx->pSvcParam; |
| 1123 | while (iSpatialIdx < iSpatialNum) { | 1123 | while (iSpatialIdx < iSpatialNum) { |
| 1124 | const int32_t kiDid = pDidList[iSpatialIdx]; | 1124 | const int32_t kiDid = pDidList[iSpatialIdx]; |
| 1125 | SSpatialLayerInternal* pDlp = &pPara->sDependencyLayers[kiDid]; | 1125 | SSpatialLayerInternal* pDlp = &pPara->sDependencyLayers[kiDid]; |