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 | if (!kbIsDynamicSlicingMode) { | 560 | if (!kbIsDynamicSlicingMode) { |
| 561 | pSliceBs = &pCtx->pSliceBs[0]; | 561 | pSliceBs = &pCtx->pSliceBs[0]; |
| 562 | iLayerSize = pSliceBs->uiBsPos; // assign with base pSlice first | 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 | while (iSliceIdx < iSliceCount) { | 565 | while (iSliceIdx < iSliceCount) { |
| 565 | ++ pSliceBs; | ||
| 566 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { | 566 | if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) { |
| 567 | int32_t iNalIdx = 0; | 567 | int32_t iNalIdx = 0; |
| 568 | const int32_t iCountNal = pSliceBs->iNalIndex; | 568 | const int32_t iCountNal = pSliceBs->iNalIndex; |
| @@ -571,11 +571,13 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines | |||
| 571 | assert (pSliceBs->bSliceCodedFlag); | 571 | assert (pSliceBs->bSliceCodedFlag); |
| 572 | #endif//MT_DEBUG_BS_WR | 572 | #endif//MT_DEBUG_BS_WR |
| 573 | 573 | ||
| 574 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | 574 | if (iSliceIdx > 0) { |
| 575 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; | 575 | // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1 |
| 576 | 576 | memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage | |
| 577 | iLayerSize += pSliceBs->uiBsPos; | 577 | pCtx->iPosBsBuffer += pSliceBs->uiBsPos; |
| 578 | 578 | ||
| 579 | iLayerSize += pSliceBs->uiBsPos; | ||
| 580 | } | ||
| 579 | while (iNalIdx < iCountNal) { | 581 | while (iNalIdx < iCountNal) { |
| 580 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; | 582 | pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx]; |
| 581 | ++ iNalIdx; | 583 | ++ iNalIdx; |
| @@ -584,6 +586,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines | |||
| 584 | iNalIdxBase += iCountNal; | 586 | iNalIdxBase += iCountNal; |
| 585 | } | 587 | } |
| 586 | ++ iSliceIdx; | 588 | ++ iSliceIdx; |
| 589 | ++ pSliceBs; | ||
| 587 | } | 590 | } |
| 588 | } else { // for SM_DYN_SLICE | 591 | } else { // for SM_DYN_SLICE |
| 589 | const int32_t kiPartitionCnt = iSliceCount; | 592 | const int32_t kiPartitionCnt = iSliceCount; |
| @@ -629,58 +632,18 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 39 unmodified lines | |||
| 629 | return iLayerSize; | 632 | return iLayerSize; |
| 630 | } | 633 | } |
| 631 | 634 | ||
| 632 | int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer, const int32_t iSliceIdx, | 635 | int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pDst, |
| 633 | int32_t& iSliceSize) { | 636 | int32_t* pNalLen, |
| 637 | int32_t iTotalLeftLength, | ||
| 638 | const int32_t iSliceIdx, | ||
| 639 | int32_t& iSliceSize) { | ||
| 634 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; | 640 | SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx]; |
| 635 | SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; | 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 | const int32_t kiNalCnt = pSliceBs->iNalIndex; | 643 | const int32_t kiNalCnt = pSliceBs->iNalIndex; |
| 679 | int32_t iNalIdx = 0; | 644 | int32_t iNalIdx = 0; |
| 680 | int32_t iNalSize = 0; | 645 | int32_t iNalSize = 0; |
| 681 | int32_t iReturn = ENC_RETURN_SUCCESS; | 646 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 682 | const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf); | ||
| 683 | |||
| 684 | iSliceSize = 0; | 647 | iSliceSize = 0; |
| 685 | assert (kiNalCnt <= 2); | 648 | assert (kiNalCnt <= 2); |
| 686 | if (kiNalCnt > 2) | 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 | while (iNalIdx < kiNalCnt) { | 652 | while (iNalIdx < kiNalCnt) { |
| 690 | iNalSize = 0; | 653 | iNalSize = 0; |
| 691 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize, | 654 | iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, iTotalLeftLength - iSliceSize, |
| 692 | pDst, &iNalSize); | 655 | pDst, &iNalSize); |
| 693 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | 656 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 694 | pNalLen[iNalIdx] = iNalSize; | 657 | pNalLen[iNalIdx] = iNalSize; |
| @@ -793,31 +756,28 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 98 unmodified lines | |||
| 793 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); | 756 | iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType); |
| 794 | if (ENC_RETURN_SUCCESS != iReturn) { | 757 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 795 | uiThrdRet = iReturn; | 758 | uiThrdRet = iReturn; |
| 796 | WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | 759 | WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent, |
| 797 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, | 760 | pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent, |
| 798 | iEventIdx); | 761 | iEventIdx); |
| 799 | } | 762 | } |
| 800 | 763 | ||
| 801 | WelsUnloadNalForSlice (pSliceBs); | 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 | if (0 == iSliceIdx) { | 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 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | 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 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); | 783 | pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx); |
| @@ -909,10 +869,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 85 unmodified lines | |||
| 909 | WelsUnloadNalForSlice (pSliceBs); | 869 | WelsUnloadNalForSlice (pSliceBs); |
| 910 | 870 | ||
| 911 | if (0 == kiPartitionId) { | 871 | if (0 == kiPartitionId) { |
| 912 | if (0 == iSliceIdx) | 872 | iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf, |
| 913 | pLbi->pBsBuf = pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer; | 873 | &pLbi->pNalLengthInByte[pLbi->iNalCount], |
| 914 | iReturn = WriteSliceToFrameBs (pEncPEncCtx, pLbi, pEncPEncCtx->pFrameBs + pEncPEncCtx->iPosBsBuffer, iSliceIdx, | 874 | pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer, |
| 915 | iSliceSize); | 875 | iSliceIdx, iSliceSize); |
| 876 | pLbi->iNalCount += pSliceBs->iNalIndex; | ||
| 916 | if (ENC_RETURN_SUCCESS != iReturn) { | 877 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 917 | uiThrdRet = iReturn; | 878 | uiThrdRet = iReturn; |
| 918 | WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | 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 | pEncPEncCtx->iPosBsBuffer += iSliceSize; | 883 | pEncPEncCtx->iPosBsBuffer += iSliceSize; |
| 923 | } else { | 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 | if (ENC_RETURN_SUCCESS != iReturn) { | 888 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 926 | uiThrdRet = iReturn; | 889 | uiThrdRet = iReturn; |
| 927 | WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent, | 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 | iIdx = 0; | 1004 | iIdx = 0; |
| 1034 | while (iIdx < kiEventCnt) { | 1005 | while (iIdx < kiEventCnt) { |
| 1035 | pPriData[iIdx].pLayerBs = pLbi; | 1006 | pPriData[iIdx].pLayerBs = pLbi; |