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 | 99 | int32_t iSliceIdx = 0; |
| 100 | 100 | int32_t iAvI[MAX_SLICES_NUM]; |
| 101 | 101 | |
| 102 | + assert(kiSliceCount <= MAX_SLICES_NUM); | |
| 102 | 103 | WelsEmms(); |
| 103 | 104 | |
| 104 | 105 | while (iSliceIdx < kiSliceCount) { |
| @@ -354,9 +355,14 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 249 unmodified lines | ||
| 354 | 355 | WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx])) |
| 355 | 356 | } |
| 356 | 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 | 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 | 366 | iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError); |
| 361 | 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 | 412 | WelsMutexDestroy (&pSmt->mutexSliceNumUpdate); |
| 407 | 413 | WelsMutexDestroy (&pSmt->mutexThreadBsBufferUsage); |
| 414 | + WelsMutexDestroy (&pSmt->mutexThreadSlcBuffReallocate); | |
| 408 | 415 | WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError)); |
| 409 | 416 | WelsMutexDestroy (&pSmt->mutexEvent); |
| 410 | 417 | if (pSmt->pThreadPEncCtx != NULL) { |
| @@ -436,75 +443,36 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 25 unmodified lines | ||
| 436 | 443 | } |
| 437 | 444 | |
| 438 | 445 | int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) { |
| 439 | − SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam; | |
| 440 | − SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId]; | |
| 441 | − SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer; | |
| 442 | − SWelsSliceBs* pSliceBs = NULL; | |
| 443 | − const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE); | |
| 444 | − | |
| 445 | − int32_t iLayerSize = 0; | |
| 446 | − int32_t iNalIdxBase = pLbi->iNalCount; | |
| 447 | − int32_t iSliceIdx = 0; | |
| 448 | − | |
| 449 | − if (!kbIsDynamicSlicingMode) { | |
| 450 | − iNalIdxBase = pLbi->iNalCount = 0; | |
| 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; | |
| 446 | + SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer; | |
| 447 | + SWelsSliceBs* pSliceBs = NULL; | |
| 448 | + int32_t iLayerSize = 0; | |
| 449 | + int32_t iNalIdxBase = pLbi->iNalCount; | |
| 450 | + int32_t iSliceIdx = 0; | |
| 451 | + | |
| 452 | + iNalIdxBase = pLbi->iNalCount = 0; | |
| 453 | + while (iSliceIdx < iSliceCount) { | |
| 454 | + pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs; | |
| 455 | + if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | |
| 456 | + int32_t iNalIdx = 0; | |
| 457 | + const int32_t iCountNal = pSliceBs->iNalIndex; | |
| 456 | 458 | |
| 457 | 459 | #if MT_DEBUG_BS_WR |
| 458 | − assert (pSliceBs->bSliceCodedFlag); | |
| 460 | + assert (pSliceBs->bSliceCodedFlag); | |
| 459 | 461 | #endif//MT_DEBUG_BS_WR |
| 460 | 462 | |
| 461 | − memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | |
| 462 | − pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | |
| 463 | + memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | |
| 464 | + pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | |
| 463 | 465 | |
| 464 | − iLayerSize += pSliceBs->uiBsPos; | |
| 466 | + iLayerSize += pSliceBs->uiBsPos; | |
| 465 | 467 | |
| 466 | − while (iNalIdx < iCountNal) { | |
| 467 | − pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | |
| 468 | − ++ iNalIdx; | |
| 469 | − } | |
| 470 | − pLbi->iNalCount += iCountNal; | |
| 471 | − iNalIdxBase += iCountNal; | |
| 472 | − } | |
| 473 | − ++ iSliceIdx; | |
| 468 | + while (iNalIdx < iCountNal) { | |
| 469 | + pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | |
| 470 | + ++ iNalIdx; | |
| 474 | 471 | } |
| 475 | − } else { // for SM_SIZELIMITED_SLICE | |
| 476 | − const int32_t kiPartitionCnt = iSliceCount; | |
| 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; | |
| 472 | + pLbi->iNalCount += iCountNal; | |
| 473 | + iNalIdxBase += iCountNal; | |
| 507 | 474 | } |
| 475 | + ++ iSliceIdx; | |
| 508 | 476 | } |
| 509 | 477 | |
| 510 | 478 | return iLayerSize; |
| @@ -650,14 +618,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 139 unmodified lines | ||
| 650 | 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 | 621 | assert (iSliceIdx == pSlice->iSliceIdx); |
| 662 | 622 | iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType); |
| 663 | 623 | if (ENC_RETURN_SUCCESS != iReturn) { |
| @@ -677,7 +637,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 13 unmodified lines | ||
| 677 | 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 | 642 | if (bDsaFlag) { |
| 683 | 643 | pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - iSliceStart); |
| @@ -710,16 +670,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 26 unmodified lines | ||
| 710 | 670 | } else { // for SM_SIZELIMITED_SLICE parallelization |
| 711 | 671 | const int32_t kiPartitionId = iThreadIdx; |
| 712 | 672 | const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum; |
| 713 | − const int32_t kiFirstMbInPartition = pCurDq->pFirstMbIdxOfPartition[kiPartitionId]; | |
| 714 | − const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId]; | |
| 673 | + const int32_t kiFirstMbInPartition = pCurDq->FirstMbIdxOfPartition[kiPartitionId]; | |
| 674 | + const int32_t kiEndMbIdxInPartition = pCurDq->EndMbIdxOfPartition[kiPartitionId]; | |
| 715 | 675 | int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1; |
| 716 | 676 | SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid]; |
| 717 | 677 | iSliceIdx = pPrivateData->iSliceIndex; |
| 718 | 678 | SSlice* pStartSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx]; |
| 719 | 679 | pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; |
| 720 | − pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; | |
| 721 | − pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | |
| 722 | − | |
| 723 | 680 | while (iAnyMbLeftInPartition > 0) { |
| 724 | 681 | if (iSliceIdx >= pCurDq->iMaxSliceNum) { |
| 725 | 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 | 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 | 740 | #if defined(SLICE_INFO_OUTPUT) |
| 784 | 741 | fprintf (stderr, |
| @@ -791,12 +748,12 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 6 unmodified lines | ||
| 791 | 748 | #endif//SLICE_INFO_OUTPUT |
| 792 | 749 | |
| 793 | 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 | 752 | pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, |
| 796 | 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 | 757 | iSliceIdx += kiSliceIdxStep; |
| 801 | 758 | } |
| 802 | 759 | |