[Encoder] refactor multi-thread logic and add error-dealing
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 2 files). Show all
Unified · Split
| @@ -604,23 +604,19 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 603 unmodified lines | |||
| 604 | pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | 604 | pSliceBs = &pCtx->pSliceBs[iSliceIdx]; |
| 605 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | 605 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 606 | if (iSliceIdx > 0) { | 606 | if (iSliceIdx > 0) { |
| 607 | int32_t iNalIdx = 0; | ||
| 608 | const int32_t iCountNal = pSliceBs->iNalIndex; | ||
| 609 | |||
| 610 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | 607 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage |
| 611 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | 608 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; |
| 609 | } | ||
| 612 | 610 | ||
| 613 | iLayerSize += pSliceBs->uiBsPos; | 611 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| 614 | 612 | iLayerSize += pSliceBs->uiBsPos; | |
| 615 | while (iNalIdx < iCountNal) { | 613 | int32_t iNalIdx = 0; |
| 616 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | 614 | while (iNalIdx < iCountNal) { |
| 617 | ++ iNalIdx; | 615 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 618 | } | 616 | ++ iNalIdx; |
| 619 | pLbi->iNalCount += iCountNal; | ||
| 620 | iNalIdxBase += iCountNal; | ||
| 621 | } else { | ||
| 622 | iLayerSize += pSliceBs->uiBsPos; | ||
| 623 | } | 617 | } |
| 618 | pLbi->iNalCount += iCountNal; | ||
| 619 | iNalIdxBase += iCountNal; | ||
| 624 | } | 620 | } |
| 625 | 621 | ||
| 626 | iSliceIdx += kiPartitionCnt; | 622 | iSliceIdx += kiPartitionCnt; |
| @@ -707,9 +703,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 80 unmodified lines | |||
| 707 | &pEventsList[0], | 703 | &pEventsList[0], |
| 708 | &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled | 704 | &pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled |
| 709 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited | 705 | if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited |
| 710 | int iLayerIndex = pEncPEncCtx->pOut->iLayerBsIndex; | 706 | //int iLayerIndex = pEncPEncCtx->pOut->iLayerBsIndex; |
| 711 | SFrameBSInfo* pFrameBsInfo = pPrivateData->pFrameBsInfo; | 707 | //SFrameBSInfo* pFrameBsInfo = pPrivateData->pFrameBsInfo; |
| 712 | SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo [iLayerIndex]; | 708 | //SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo [iLayerIndex]; |
| 713 | 709 | ||
| 714 | const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; | 710 | const int32_t kiCurDid = pEncPEncCtx->uiDependencyId; |
| 715 | SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam; | 711 | SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam; |
| @@ -874,29 +870,18 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 158 unmodified lines | |||
| 874 | 870 | ||
| 875 | WelsUnloadNalForSlice (pSliceBs); | 871 | WelsUnloadNalForSlice (pSliceBs); |
| 876 | 872 | ||
| 877 | if (0 == iSliceIdx) { | 873 | int32_t iLeftBufferSize = (iSliceIdx > 0) ? (pSliceBs->uiSize - pSliceBs->uiBsPos) : (pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer); |
| 878 | iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf, | 874 | iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0], |
| 879 | &pLbi->pNalLengthInByte[pLbi->iNalCount], | 875 | iLeftBufferSize, |
| 880 | pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer, | ||
| 881 | iSliceIdx, iSliceSize); | 876 | iSliceIdx, iSliceSize); |
| 882 | pLbi->iNalCount += pSliceBs->iNalIndex; | 877 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 883 | if (ENC_RETURN_SUCCESS != iReturn) { | 878 | uiThrdRet = iReturn; |
| 884 | uiThrdRet = iReturn; | 879 | WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, |
| 885 | WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | 880 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, |
| 886 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | 881 | iEventIdx); |
| 887 | iEventIdx); | 882 | } |
| 888 | } | 883 | if (0 == iSliceIdx) { |
| 889 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | 884 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 890 | } else { | ||
| 891 | iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0], | ||
| 892 | pSliceBs->uiSize - pSliceBs->uiBsPos, | ||
| 893 | iSliceIdx, iSliceSize); | ||
| 894 | if (ENC_RETURN_SUCCESS != iReturn) { | ||
| 895 | uiThrdRet = iReturn; | ||
| 896 | WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | ||
| 897 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | ||
| 898 | iEventIdx); | ||
| 899 | } | ||
| 900 | } | 885 | } |
| 901 | 886 | ||
| 902 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); | 887 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |