Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 14 files). Show all
Unified · Split
| @@ -99,6 +99,7 @@ void CalcSliceComplexRatio (SDqLayer* pCurDq) { · 98 unmodified lines | |||
| 99 | int32_t iSliceIdx = 0; | 99 | int32_t iSliceIdx = 0; |
| 100 | int32_t iAvI[MAX_SLICES_NUM]; | 100 | int32_t iAvI[MAX_SLICES_NUM]; |
| 101 | 101 | ||
| 102 | assert(kiSliceCount <= MAX_SLICES_NUM); | ||
| 102 | WelsEmms(); | 103 | WelsEmms(); |
| 103 | 104 | ||
| 104 | while (iSliceIdx < kiSliceCount) { | 105 | while (iSliceIdx < kiSliceCount) { |
| @@ -354,9 +355,14 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 249 unmodified lines | |||
| 354 | WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx])) | 355 | WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx])) |
| 355 | } | 356 | } |
| 356 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); | 357 | iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage); |
| 357 | WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | 358 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) |
| 359 | |||
| 358 | iReturn = WelsMutexInit (&pSmt->mutexEvent); | 360 | iReturn = WelsMutexInit (&pSmt->mutexEvent); |
| 359 | WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | 361 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)); |
| 362 | |||
| 363 | iReturn = WelsMutexInit (&pSmt->mutexThreadSlcBuffReallocate); | ||
| 364 | WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx)) | ||
| 365 | |||
| 360 | iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError); | 366 | iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError); |
| 361 | WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) | 367 | WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn)) |
| 362 | 368 | ||
| @@ -405,6 +411,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 42 unmodified lines | |||
| 405 | 411 | ||
| 406 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); | 412 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 407 | WelsMutexDestroy (&pSmt->mutexThreadBsBufferUsage); | 413 | WelsMutexDestroy (&pSmt->mutexThreadBsBufferUsage); |
| 414 | WelsMutexDestroy (&pSmt->mutexThreadSlcBuffReallocate); | ||
| 408 | WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError)); | 415 | WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError)); |
| 409 | WelsMutexDestroy (&pSmt->mutexEvent); | 416 | WelsMutexDestroy (&pSmt->mutexEvent); |
| 410 | if (pSmt->pThreadPEncCtx != NULL) { | 417 | if (pSmt->pThreadPEncCtx != NULL) { |
| @@ -436,75 +443,36 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 25 unmodified lines | |||
| 436 | } | 443 | } |
| 437 | 444 | ||
| 438 | int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) { | 445 | int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) { |
| 439 | SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam; | 446 | SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer; |
| 440 | SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId]; | 447 | SWelsSliceBs* pSliceBs = NULL; |
| 441 | SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer; | 448 | int32_t iLayerSize = 0; |
| 442 | SWelsSliceBs* pSliceBs = NULL; | 449 | int32_t iNalIdxBase = pLbi->iNalCount; |
| 443 | const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE); | 450 | int32_t iSliceIdx = 0; |
| 444 | 451 | ||
| 445 | int32_t iLayerSize = 0; | 452 | iNalIdxBase = pLbi->iNalCount = 0; |
| 446 | int32_t iNalIdxBase = pLbi->iNalCount; | 453 | while (iSliceIdx < iSliceCount) { |
| 447 | int32_t iSliceIdx = 0; | 454 | pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs; |
| 448 | 455 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | |
| 449 | if (!kbIsDynamicSlicingMode) { | 456 | int32_t iNalIdx = 0; |
| 450 | iNalIdxBase = pLbi->iNalCount = 0; | 457 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| 451 | while (iSliceIdx < iSliceCount) { | ||
| 452 | pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs; | ||
| 453 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | ||
| 454 | int32_t iNalIdx = 0; | ||
| 455 | const int32_t iCountNal = pSliceBs->iNalIndex; | ||
| 456 | 458 | ||
| 457 | #if MT_DEBUG_BS_WR | 459 | #if MT_DEBUG_BS_WR |
| 458 | assert (pSliceBs->bSliceCodedFlag); | 460 | assert (pSliceBs->bSliceCodedFlag); |
| 459 | #endif//MT_DEBUG_BS_WR | 461 | #endif//MT_DEBUG_BS_WR |
| 460 | 462 | ||
| 461 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | 463 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage |
| 462 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | 464 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; |
| 463 | 465 | ||
| 464 | iLayerSize += pSliceBs->uiBsPos; | 466 | iLayerSize += pSliceBs->uiBsPos; |
| 465 | 467 | ||
| 466 | while (iNalIdx < iCountNal) { | 468 | while (iNalIdx < iCountNal) { |
| 467 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | 469 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 468 | ++ iNalIdx; | 470 | ++ iNalIdx; |
| 469 | } | ||
| 470 | pLbi->iNalCount += iCountNal; | ||
| 471 | iNalIdxBase += iCountNal; | ||
| 472 | } | ||
| 473 | ++ iSliceIdx; | ||
| 474 | } | 471 | } |
| 475 | } else { // for SM_SIZELIMITED_SLICE | 472 | pLbi->iNalCount += iCountNal; |
| 476 | const int32_t kiPartitionCnt = iSliceCount; | 473 | iNalIdxBase += iCountNal; |
| 477 | int32_t iPartitionIdx = 0; | ||
| 478 | |||
| 479 | // due partition_0 has been written to pFrameBsBuffer | ||
| 480 | // so iLayerSize need add it | ||
| 481 | while (iPartitionIdx < kiPartitionCnt) { | ||
| 482 | const int32_t kiCountSlicesCoded = pCtx->pCurDqLayer->pNumSliceCodedOfPartition[iPartitionIdx]; | ||
| 483 | int32_t iIdx = 0; | ||
| 484 | |||
| 485 | iSliceIdx = iPartitionIdx; | ||
| 486 | while (iIdx < kiCountSlicesCoded) { | ||
| 487 | pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs; | ||
| 488 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | ||
| 489 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | ||
| 490 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | ||
| 491 | |||
| 492 | const int32_t iCountNal = pSliceBs->iNalIndex; | ||
| 493 | iLayerSize += pSliceBs->uiBsPos; | ||
| 494 | int32_t iNalIdx = 0; | ||
| 495 | while (iNalIdx < iCountNal) { | ||
| 496 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | ||
| 497 | ++ iNalIdx; | ||
| 498 | } | ||
| 499 | pLbi->iNalCount += iCountNal; | ||
| 500 | iNalIdxBase += iCountNal; | ||
| 501 | } | ||
| 502 | |||
| 503 | iSliceIdx += kiPartitionCnt; | ||
| 504 | ++ iIdx; | ||
| 505 | } | ||
| 506 | ++ iPartitionIdx; | ||
| 507 | } | 474 | } |
| 475 | ++ iSliceIdx; | ||
| 508 | } | 476 | } |
| 509 | 477 | ||
| 510 | return iLayerSize; | 478 | return iLayerSize; |
| @@ -650,14 +618,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 139 unmodified lines | |||
| 650 | iEventIdx); | 618 | iEventIdx); |
| 651 | } | 619 | } |
| 652 | 620 | ||
| 653 | iReturn = SetSliceBoundaryInfo(pEncPEncCtx->pCurDqLayer, pSlice, iSliceIdx); | ||
| 654 | if (ENC_RETURN_SUCCESS != iReturn) { | ||
| 655 | uiThrdRet = iReturn; | ||
| 656 | WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | ||
| 657 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | ||
| 658 | iEventIdx); | ||
| 659 | } | ||
| 660 | |||
| 661 | assert (iSliceIdx == pSlice->iSliceIdx); | 621 | assert (iSliceIdx == pSlice->iSliceIdx); |
| 662 | iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType); | 622 | iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType); |
| 663 | if (ENC_RETURN_SUCCESS != iReturn) { | 623 | if (ENC_RETURN_SUCCESS != iReturn) { |
| @@ -677,7 +637,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 13 unmodified lines | |||
| 677 | iEventIdx); | 637 | iEventIdx); |
| 678 | } | 638 | } |
| 679 | 639 | ||
| 680 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); | 640 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, pSlice); |
| 681 | 641 | ||
| 682 | if (bDsaFlag) { | 642 | if (bDsaFlag) { |
| 683 | pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - iSliceStart); | 643 | pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - iSliceStart); |
| @@ -710,16 +670,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 26 unmodified lines | |||
| 710 | } else { // for SM_SIZELIMITED_SLICE parallelization | 670 | } else { // for SM_SIZELIMITED_SLICE parallelization |
| 711 | const int32_t kiPartitionId = iThreadIdx; | 671 | const int32_t kiPartitionId = iThreadIdx; |
| 712 | const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; | 672 | const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; |
| 713 | const int32_t kiFirstMbInPartition = pCurDq->pFirstMbIdxOfPartition[kiPartitionId]; | 673 | const int32_t kiFirstMbInPartition = pCurDq->FirstMbIdxOfPartition[kiPartitionId]; |
| 714 | const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId]; | 674 | const int32_t kiEndMbIdxInPartition = pCurDq->EndMbIdxOfPartition[kiPartitionId]; |
| 715 | int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1; | 675 | int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1; |
| 716 | SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid]; | 676 | SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid]; |
| 717 | iSliceIdx = pPrivateData->iSliceIndex; | 677 | iSliceIdx = pPrivateData->iSliceIndex; |
| 718 | SSlice* pStartSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx]; | 678 | SSlice* pStartSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx]; |
| 719 | pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; | 679 | pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; |
| 720 | pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; | ||
| 721 | pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | ||
| 722 | |||
| 723 | while (iAnyMbLeftInPartition > 0) { | 680 | while (iAnyMbLeftInPartition > 0) { |
| 724 | if (iSliceIdx >= pCurDq->iMaxSliceNum) { | 681 | if (iSliceIdx >= pCurDq->iMaxSliceNum) { |
| 725 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage | 682 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage |
| @@ -778,7 +735,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 52 unmodified lines | |||
| 778 | iEventIdx); | 735 | iEventIdx); |
| 779 | } | 736 | } |
| 780 | 737 | ||
| 781 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); | 738 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, pSlice); |
| 782 | 739 | ||
| 783 | #if defined(SLICE_INFO_OUTPUT) | 740 | #if defined(SLICE_INFO_OUTPUT) |
| 784 | fprintf (stderr, | 741 | fprintf (stderr, |
| @@ -791,12 +748,12 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 6 unmodified lines | |||
| 791 | #endif//SLICE_INFO_OUTPUT | 748 | #endif//SLICE_INFO_OUTPUT |
| 792 | 749 | ||
| 793 | MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO, | 750 | MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO, |
| 794 | "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, iSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n", | 751 | "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, iSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->LastCodedMbIdxOfPartition[%d] %d\n", |
| 795 | pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, | 752 | pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, |
| 796 | pSlice->iCountMbNumInSlice, | 753 | pSlice->iCountMbNumInSlice, |
| 797 | kiEndMbIdxInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]); | 754 | kiEndMbIdxInPartition, kiPartitionId, pCurDq->LastCodedMbIdxOfPartition[kiPartitionId]); |
| 798 | 755 | ||
| 799 | iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]; | 756 | iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->LastCodedMbIdxOfPartition[kiPartitionId]; |
| 800 | iSliceIdx += kiSliceIdxStep; | 757 | iSliceIdx += kiSliceIdxStep; |
| 801 | } | 758 | } |
| 802 | 759 | ||