Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 3 files). Show all
Unified · Split
| @@ -560,9 +560,9 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 559 unmodified lines | ||
| 560 | 560 | if (!kbIsDynamicSlicingMode) { |
| 561 | 561 | pSliceBs = &pCtx->pSliceBs[0]; |
| 562 | 562 | iLayerSize = pSliceBs->uiBsPos; // assign with base pSlice first |
| 563 | − iSliceIdx = 1; // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1 | |
| 563 | + iSliceIdx = 0; | |
| 564 | + iNalIdxBase = pLbi->iNalCount = 0; | |
| 564 | 565 | while (iSliceIdx < iSliceCount) { |
| 565 | − ++ pSliceBs; | |
| 566 | 566 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 567 | 567 | int32_t iNalIdx = 0; |
| 568 | 568 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| @@ -571,11 +571,13 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines | ||
| 571 | 571 | assert (pSliceBs->bSliceCodedFlag); |
| 572 | 572 | #endif//MT_DEBUG_BS_WR |
| 573 | 573 | |
| 574 | − memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | |
| 575 | − pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | |
| 576 | − | |
| 577 | − iLayerSize += pSliceBs->uiBsPos; | |
| 574 | + if (iSliceIdx > 0) { | |
| 575 | + // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1 | |
| 576 | + memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | |
| 577 | + pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | |
| 578 | 578 | |
| 579 | + iLayerSize += pSliceBs->uiBsPos; | |
| 580 | + } | |
| 579 | 581 | while (iNalIdx < iCountNal) { |
| 580 | 582 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 581 | 583 | ++ iNalIdx; |
| @@ -584,6 +586,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines | ||
| 584 | 586 | iNalIdxBase += iCountNal; |
| 585 | 587 | } |
| 586 | 588 | ++ iSliceIdx; |
| 589 | + ++ pSliceBs; | |
| 587 | 590 | } |
| 588 | 591 | } else { // for SM_DYN_SLICE |
| 589 | 592 | const int32_t kiPartitionCnt = iSliceCount; |
| @@ -629,58 +632,18 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 39 unmodified lines | ||
| 629 | 632 | return iLayerSize; |
| 630 | 633 | } |
| 631 | 634 | |
| 632 | −int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, | |
| 633 | − int32_t& iSliceSize) { | |
| 635 | +int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pDst, | |
| 636 | + int32_t* pNalLen, | |
| 637 | + int32_t iTotalLeftLength, | |
| 638 | + const int32_t iSliceIdx, | |
| 639 | + int32_t& iSliceSize) { | |
| 634 | 640 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; |
| 635 | 641 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; |
| 636 | − uint8_t* pDst = pFrameBsBuffer; | |
| 637 | − const int32_t kiNalCnt = pSliceBs->iNalIndex; | |
| 638 | − int32_t iNalIdx = 0; | |
| 639 | − int32_t iNalSize = 0; | |
| 640 | − const int32_t iFirstSlice = (iSliceIdx == 0); | |
| 641 | − int32_t iNalBase = iFirstSlice ? 0 : pLbi->iNalCount; | |
| 642 | − int32_t iReturn = ENC_RETURN_SUCCESS; | |
| 643 | − const int32_t kiWrittenLength = pCtx->iPosBsBuffer; | |
| 644 | − iSliceSize = 0; | |
| 645 | − | |
| 646 | − while (iNalIdx < kiNalCnt) { | |
| 647 | − iNalSize = 0; | |
| 648 | − iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pCtx->iFrameBsSize - kiWrittenLength - iSliceSize, | |
| 649 | − pDst, &iNalSize); | |
| 650 | − WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | |
| 651 | − iSliceSize += iNalSize; | |
| 652 | − pDst += iNalSize; | |
| 653 | − pLbi->pNalLengthInByte[iNalBase + iNalIdx] = iNalSize; | |
| 654 | − | |
| 655 | − ++ iNalIdx; | |
| 656 | − } | |
| 657 | − | |
| 658 | − pSliceBs->uiBsPos = iSliceSize; | |
| 659 | − if (iFirstSlice) { | |
| 660 | − // pBsBuffer has been updated at coding_slice_0_in_encoder_mother_thread() | |
| 661 | − pLbi->uiLayerType = VIDEO_CODING_LAYER; | |
| 662 | − pLbi->uiSpatialId = pNalHdrExt->uiDependencyId; | |
| 663 | − pLbi->uiTemporalId = pNalHdrExt->uiTemporalId; | |
| 664 | − pLbi->uiQualityId = 0; | |
| 665 | − pLbi->iNalCount = kiNalCnt; | |
| 666 | − } else { | |
| 667 | − pLbi->iNalCount += kiNalCnt; | |
| 668 | − } | |
| 669 | − | |
| 670 | − return ENC_RETURN_SUCCESS; | |
| 671 | −} | |
| 672 | 642 | |
| 673 | −int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSliceIdx, int32_t& iSliceSize) { | |
| 674 | − SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | |
| 675 | − SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; | |
| 676 | − uint8_t* pDst = pSliceBsBuf; | |
| 677 | − int32_t* pNalLen = &pSliceBs->iNalLen[0]; | |
| 678 | 643 | const int32_t kiNalCnt = pSliceBs->iNalIndex; |
| 679 | 644 | int32_t iNalIdx = 0; |
| 680 | 645 | int32_t iNalSize = 0; |
| 681 | 646 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 682 | − const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf); | |
| 683 | − | |
| 684 | 647 | iSliceSize = 0; |
| 685 | 648 | assert (kiNalCnt <= 2); |
| 686 | 649 | if (kiNalCnt > 2) |
| @@ -688,7 +651,7 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 1 unmodified line | ||
| 688 | 651 | |
| 689 | 652 | while (iNalIdx < kiNalCnt) { |
| 690 | 653 | iNalSize = 0; |
| 691 | − iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize, | |
| 654 | + iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, iTotalLeftLength - iSliceSize, | |
| 692 | 655 | pDst, &iNalSize); |
| 693 | 656 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 694 | 657 | pNalLen[iNalIdx] = iNalSize; |
| @@ -793,31 +756,28 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 98 unmodified lines | ||
| 793 | 756 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); |
| 794 | 757 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 795 | 758 | uiThrdRet = iReturn; |
| 796 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 797 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 798 | − iEventIdx); | |
| 759 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 760 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 761 | + iEventIdx); | |
| 799 | 762 | } |
| 800 | 763 | |
| 801 | 764 | WelsUnloadNalForSlice (pSliceBs); |
| 802 | 765 | |
| 766 | + int32_t iLeftBufferSize = (iSliceIdx > 0) ? | |
| 767 | + (pSliceBs->uiSize - (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf)) | |
| 768 | + : (pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer); | |
| 769 | + iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, | |
| 770 | + &pSliceBs->iNalLen[0], | |
| 771 | + iLeftBufferSize, | |
| 772 | + iSliceIdx, iSliceSize); | |
| 773 | + if (ENC_RETURN_SUCCESS != iReturn) { | |
| 774 | + uiThrdRet = iReturn; | |
| 775 | + WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 776 | + pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 777 | + iEventIdx); | |
| 778 | + } | |
| 803 | 779 | if (0 == iSliceIdx) { |
| 804 | − pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | |
| 805 | − iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pLbi->pBsBuf, iSliceIdx, iSliceSize); | |
| 806 | − if (ENC_RETURN_SUCCESS != iReturn) { | |
| 807 | − uiThrdRet = iReturn; | |
| 808 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 809 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 810 | − iEventIdx); | |
| 811 | − } | |
| 812 | 780 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 813 | − } else { | |
| 814 | − iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); | |
| 815 | − if (ENC_RETURN_SUCCESS != iReturn) { | |
| 816 | − uiThrdRet = iReturn; | |
| 817 | − WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | |
| 818 | − pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | |
| 819 | − iEventIdx); | |
| 820 | − } | |
| 821 | 781 | } |
| 822 | 782 | |
| 823 | 783 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |
| @@ -909,10 +869,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 85 unmodified lines | ||
| 909 | 869 | WelsUnloadNalForSlice (pSliceBs); |
| 910 | 870 | |
| 911 | 871 | if (0 == kiPartitionId) { |
| 912 | − if (0 == iSliceIdx) | |
| 913 | − pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | |
| 914 | − iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, | |
| 915 | − iSliceSize); | |
| 872 | + iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf, | |
| 873 | + &pLbi->pNalLengthInByte[pLbi->iNalCount], | |
| 874 | + pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer, | |
| 875 | + iSliceIdx, iSliceSize); | |
| 876 | + pLbi->iNalCount += pSliceBs->iNalIndex; | |
| 916 | 877 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 917 | 878 | uiThrdRet = iReturn; |
| 918 | 879 | WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, |
| @@ -921,7 +882,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 2 unmodified lines | ||
| 921 | 882 | } |
| 922 | 883 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 923 | 884 | } else { |
| 924 | − iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, iSliceIdx, iSliceSize); | |
| 885 | + iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0], | |
| 886 | + pSliceBs->uiSize - (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf), | |
| 887 | + iSliceIdx, iSliceSize); | |
| 925 | 888 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 926 | 889 | uiThrdRet = iReturn; |
| 927 | 890 | WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, |
| @@ -1030,6 +993,14 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, · 102 unmodified lines | ||
| 1030 | 993 | } |
| 1031 | 994 | } |
| 1032 | 995 | |
| 996 | + pLbi->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; | |
| 997 | + pLbi->uiLayerType = VIDEO_CODING_LAYER; | |
| 998 | + pLbi->uiSpatialId = pCtx->uiDependencyId; | |
| 999 | + pLbi->uiTemporalId = pCtx->uiTemporalId; | |
| 1000 | + pLbi->uiQualityId = 0; | |
| 1001 | + pLbi->iNalCount = 0; | |
| 1002 | + pCtx->pSliceBs[0].pBs = pLbi->pBsBuf; | |
| 1003 | + | |
| 1033 | 1004 | iIdx = 0; |
| 1034 | 1005 | while (iIdx < kiEventCnt) { |
| 1035 | 1006 | pPriData[iIdx].pLayerBs = pLbi; |