History

1, refactor to remove similar function (WriteSliceToFrameBs is removed) 2, use slice-level variable in child-thread function so there can be a better independency in child-thread function 3, add two more test cases

Sijia Chen committed 11 years ago

Commit 9aafb771 parent 6b503843 files · +54 −80Browse files

Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 3 files). Show all

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+47−76
@@ -560,9 +560,9 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 559 unmodified lines
560560 if (!kbIsDynamicSlicingMode) {
561561 pSliceBs = &pCtx->pSliceBs[0];
562562 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;
564565 while (iSliceIdx < iSliceCount) {
565− ++ pSliceBs;
566566 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
567567 int32_t iNalIdx = 0;
568568 const int32_t iCountNal = pSliceBs->iNalIndex;
@@ -571,11 +571,13 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines
571571 assert (pSliceBs->bSliceCodedFlag);
572572 #endif//MT_DEBUG_BS_WR
573573
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;
578578
579+ iLayerSize += pSliceBs->uiBsPos;
580+ }
579581 while (iNalIdx < iCountNal) {
580582 pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
581583 ++ iNalIdx;
@@ -584,6 +586,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines
584586 iNalIdxBase += iCountNal;
585587 }
586588 ++ iSliceIdx;
589+ ++ pSliceBs;
587590 }
588591 } else { // for SM_DYN_SLICE
589592 const int32_t kiPartitionCnt = iSliceCount;
@@ -629,58 +632,18 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 39 unmodified lines
629632 return iLayerSize;
630633 }
631634
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) {
634640 SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx];
635641 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−}
672642
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];
678643 const int32_t kiNalCnt = pSliceBs->iNalIndex;
679644 int32_t iNalIdx = 0;
680645 int32_t iNalSize = 0;
681646 int32_t iReturn = ENC_RETURN_SUCCESS;
682− const int32_t kiWrittenLength = (int32_t) (pSliceBs->sBsWrite.pCurBuf - pSliceBs->sBsWrite.pStartBuf);
683−
684647 iSliceSize = 0;
685648 assert (kiNalCnt <= 2);
686649 if (kiNalCnt > 2)
@@ -688,7 +651,7 @@ int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSl · 1 unmodified line
688651
689652 while (iNalIdx < kiNalCnt) {
690653 iNalSize = 0;
691− iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, pSliceBs->uiSize - kiWrittenLength - iSliceSize,
654+ iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, iTotalLeftLength - iSliceSize,
692655 pDst, &iNalSize);
693656 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
694657 pNalLen[iNalIdx] = iNalSize;
@@ -793,31 +756,28 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 98 unmodified lines
793756 iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
794757 if (ENC_RETURN_SUCCESS != iReturn) {
795758 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);
799762 }
800763
801764 WelsUnloadNalForSlice (pSliceBs);
802765
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+ }
803779 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− }
812780 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− }
821781 }
822782
823783 pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
@@ -909,10 +869,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 85 unmodified lines
909869 WelsUnloadNalForSlice (pSliceBs);
910870
911871 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;
916877 if (ENC_RETURN_SUCCESS != iReturn) {
917878 uiThrdRet = iReturn;
918879 WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
@@ -921,7 +882,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 2 unmodified lines
921882 }
922883 pEncPEncCtx->iPosBsBuffer += iSliceSize;
923884 } 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);
925888 if (ENC_RETURN_SUCCESS != iReturn) {
926889 uiThrdRet = iReturn;
927890 WELS_THREAD_SIGNAL_AND_BREAK(pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
@@ -1030,6 +993,14 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, · 102 unmodified lines
1030993 }
1031994 }
1032995
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+
10331004 iIdx = 0;
10341005 while (iIdx < kiEventCnt) {
10351006 pPriData[iIdx].pLayerBs = pLbi;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t