History

1. fix readPicture in h264dec.cpp for multi-slice parser and add support for nal_deliminator. 2. Fix thread-decoding hanging due to incorrect call order of PrefetchPic and reference list update. 3. call WelsResetRefPic in right place to fix artifacts existing in a thread unit test case 4. add GetPrevFrameNum function to get correct iPrevFrameNum in thread-decoding mode.

xiaotianshi2 committed 6 years ago

Commit 006d9821 parent f02cf484 files · +47 −49Browse files

Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 4 files). Show all

Unified · Split

codec/decoder/core/src/decoder_core.cpp+13−46
@@ -2421,9 +2421,6 @@ void WelsDqLayerDecodeStart (PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pS · 2420 unmodified lines
24212421
24222422 int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) {
24232423 int32_t iRet = ERR_NONE;
2424− if (GetThreadCount (pCtx) > 1 && pCtx->bNewSeqBegin) {
2425− WelsResetRefPic (pCtx);
2426− }
24272424 if (pCtx->eSliceType == B_SLICE) {
24282425 iRet = WelsInitBSliceRefList (pCtx, iPoc);
24292426 CreateImplicitWeightTable (pCtx);
@@ -2525,37 +2522,20 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 95 unmodified lines
25252522 SLayerInfo pLayerInfo;
25262523 PSliceHeaderExt pShExt = NULL;
25272524 PSliceHeader pSh = NULL;
2528−
2529− if (pLastThreadCtx != NULL) {
2530− pSh = &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;
2531− if (pSh->iFirstMbInSlice == 0) {
2532− if (pLastThreadCtx->pCtx->pDec != NULL && pLastThreadCtx->pCtx->pDec->bIsUngroupedMultiSlice) {
2533− WAIT_EVENT (&pLastThreadCtx->sSliceDecodeFinish, WELS_DEC_THREAD_WAIT_INFINITE);
2534− }
2535− pCtx->pDec = NULL;
2536− pCtx->iTotalNumMbRec = 0;
2537− } else if (pLastThreadCtx->pCtx->pDec != NULL) {
2538− if (pSh->iFrameNum == pLastThreadCtx->pCtx->pDec->iFrameNum
2539− && pSh->iPicOrderCntLsb == pLastThreadCtx->pCtx->pDec->iFramePoc) {
2540− WAIT_EVENT (&pLastThreadCtx->sSliceDecodeFinish, WELS_DEC_THREAD_WAIT_INFINITE);
2541− pCtx->pDec = pLastThreadCtx->pCtx->pDec;
2542− pCtx->pDec->bIsUngroupedMultiSlice = true;
2543− pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic;
2544− pCtx->iTotalNumMbRec = pLastThreadCtx->pCtx->iTotalNumMbRec;
2545− }
2546− }
2547− }
25482525 bool isNewFrame = true;
25492526 if (iThreadCount > 1) {
25502527 isNewFrame = pCtx->pDec == NULL;
25512528 }
25522529 if (pCtx->pDec == NULL) {
2553− if (pLastThreadCtx != NULL && iIdx == 0) {
2530+ //make call PrefetchPic first before updating reference lists in threaded mode
2531+ //this prevents from possible thread-decoding hanging
2532+ pCtx->pDec = PrefetchPic (pCtx->pPicBuff);
2533+ if (pLastThreadCtx != NULL) {
25542534 pLastThreadCtx->pDec->bUsedAsRef = pLastThreadCtx->pCtx->uiNalRefIdc > 0;
25552535 if (pLastThreadCtx->pDec->bUsedAsRef) {
25562536 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
25572537 uint32_t i = 0;
2558− while (i < MAX_DPB_COUNT && pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]) {
2538+ while (i < MAX_REF_PIC_COUNT && pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]) {
25592539 pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i];
25602540 ++i;
25612541 }
@@ -2567,7 +2547,11 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 5 unmodified lines
25672547 pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic;
25682548 }
25692549 }
2570− pCtx->pDec = PrefetchPic (pCtx->pPicBuff);
2550+ //WelsResetRefPic needs to be called when a new sequence is encountered
2551+ //Otherwise artifacts is observed in decoded yuv in couple of unit tests with multiple-slice frame
2552+ if (GetThreadCount (pCtx) > 1 && pCtx->bNewSeqBegin) {
2553+ WelsResetRefPic (pCtx);
2554+ }
25712555 if (pCtx->iTotalNumMbRec != 0)
25722556 pCtx->iTotalNumMbRec = 0;
25732557
@@ -2580,7 +2564,6 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 6 unmodified lines
25802564 return ERR_INFO_REF_COUNT_OVERFLOW;
25812565 }
25822566 if (pThreadCtx != NULL) {
2583− pCtx->pDec->bIsUngroupedMultiSlice = false;
25842567 pThreadCtx->pDec = pCtx->pDec;
25852568 if (iThreadCount > 1) ++pCtx->pDec->iRefCount;
25862569 uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;
@@ -2683,25 +2666,8 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 96 unmodified lines
26832666 // Subclause 8.2.5.2 Decoding process for gaps in frame_num
26842667 int32_t iPrevFrameNum = pCtx->pLastDecPicInfo->iPrevFrameNum;
26852668 if (pLastThreadCtx != NULL) {
2686− if (pCtx->bNewSeqBegin) {
2687− iPrevFrameNum = 0;
2688− } else if (pLastThreadCtx->pDec != NULL) {
2689− if (pLastThreadCtx->pDec->uiTimeStamp == pCtx->uiTimeStamp - 1) {
2690− iPrevFrameNum = pLastThreadCtx->pDec->iFrameNum;
2691− if (iPrevFrameNum == -1) iPrevFrameNum = pLastThreadCtx->pCtx->iFrameNum;
2692− } else {
2693− int32_t id = pThreadCtx->sThreadInfo.uiThrNum;
2694− for (int32_t i = 0; i < iThreadCount; ++i) {
2695− if (pThreadCtx[i - id].pCtx->uiTimeStamp == pCtx->uiTimeStamp - 1) {
2696− if (pThreadCtx[i - id].pDec != NULL) iPrevFrameNum = pThreadCtx[i - id].pDec->iFrameNum;
2697− if (iPrevFrameNum == -1) iPrevFrameNum = pThreadCtx[i - id].pCtx->iFrameNum;
2698− break;
2699− }
2700− }
2701− }
2702− } else {
2703− iPrevFrameNum = pCtx->bNewSeqBegin ? 0 : pLastThreadCtx->pCtx->iFrameNum;
2704− }
2669+ //call GetPrevFrameNum() to get correct iPrevFrameNum to prevent frame gap warning
2670+ iPrevFrameNum = pCtx->bNewSeqBegin ? 0 : GetPrevFrameNum (pCtx);
27052671 }
27062672 if (!kbIdrFlag &&
27072673 pSh->iFrameNum != iPrevFrameNum &&
@@ -2727,6 +2693,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 19 unmodified lines
27272693
27282694 if (iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID && isNewFrame) {
27292695 iRet = InitRefPicList (pCtx, pCtx->uiNalRefIdc, pSh->iPicOrderCntLsb);
2696+ if (iThreadCount > 1) isNewFrame = false;
27302697 if (iRet) {
27312698 pCtx->bRPLRError = true;
27322699 bAllRefComplete = false; // RPLR error, set ref pictures complete flag false

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