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
2421 2421
2422int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) {2422int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) {
2423 int32_t iRet = ERR_NONE;2423 int32_t iRet = ERR_NONE;
2424 if (GetThreadCount (pCtx) > 1 && pCtx->bNewSeqBegin) {
2425 WelsResetRefPic (pCtx);
2426 }
2427 if (pCtx->eSliceType == B_SLICE) {2424 if (pCtx->eSliceType == B_SLICE) {
2428 iRet = WelsInitBSliceRefList (pCtx, iPoc);2425 iRet = WelsInitBSliceRefList (pCtx, iPoc);
2429 CreateImplicitWeightTable (pCtx);2426 CreateImplicitWeightTable (pCtx);
@@ -2525,37 +2522,20 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 95 unmodified lines
2525 SLayerInfo pLayerInfo;2522 SLayerInfo pLayerInfo;
2526 PSliceHeaderExt pShExt = NULL;2523 PSliceHeaderExt pShExt = NULL;
2527 PSliceHeader pSh = NULL;2524 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 }
2548 bool isNewFrame = true;2525 bool isNewFrame = true;
2549 if (iThreadCount > 1) {2526 if (iThreadCount > 1) {
2550 isNewFrame = pCtx->pDec == NULL;2527 isNewFrame = pCtx->pDec == NULL;
2551 }2528 }
2552 if (pCtx->pDec == NULL) {2529 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) {
2554 pLastThreadCtx->pDec->bUsedAsRef = pLastThreadCtx->pCtx->uiNalRefIdc > 0;2534 pLastThreadCtx->pDec->bUsedAsRef = pLastThreadCtx->pCtx->uiNalRefIdc > 0;
2555 if (pLastThreadCtx->pDec->bUsedAsRef) {2535 if (pLastThreadCtx->pDec->bUsedAsRef) {
2556 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {2536 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
2557 uint32_t i = 0;2537 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]) {
2559 pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i];2539 pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i];
2560 ++i;2540 ++i;
2561 }2541 }
@@ -2567,7 +2547,11 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 5 unmodified lines
2567 pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic;2547 pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic;
2568 }2548 }
2569 }2549 }
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 }
2571 if (pCtx->iTotalNumMbRec != 0)2555 if (pCtx->iTotalNumMbRec != 0)
2572 pCtx->iTotalNumMbRec = 0;2556 pCtx->iTotalNumMbRec = 0;
2573 2557
@@ -2580,7 +2564,6 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 6 unmodified lines
2580 return ERR_INFO_REF_COUNT_OVERFLOW;2564 return ERR_INFO_REF_COUNT_OVERFLOW;
2581 }2565 }
2582 if (pThreadCtx != NULL) {2566 if (pThreadCtx != NULL) {
2583 pCtx->pDec->bIsUngroupedMultiSlice = false;
2584 pThreadCtx->pDec = pCtx->pDec;2567 pThreadCtx->pDec = pCtx->pDec;
2585 if (iThreadCount > 1) ++pCtx->pDec->iRefCount;2568 if (iThreadCount > 1) ++pCtx->pDec->iRefCount;
2586 uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;2569 uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;
@@ -2683,25 +2666,8 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 96 unmodified lines
2683 // Subclause 8.2.5.2 Decoding process for gaps in frame_num2666 // Subclause 8.2.5.2 Decoding process for gaps in frame_num
2684 int32_t iPrevFrameNum = pCtx->pLastDecPicInfo->iPrevFrameNum;2667 int32_t iPrevFrameNum = pCtx->pLastDecPicInfo->iPrevFrameNum;
2685 if (pLastThreadCtx != NULL) {2668 if (pLastThreadCtx != NULL) {
2686 if (pCtx->bNewSeqBegin) {2669 //call GetPrevFrameNum() to get correct iPrevFrameNum to prevent frame gap warning
2687 iPrevFrameNum = 0;2670 iPrevFrameNum = pCtx->bNewSeqBegin ? 0 : GetPrevFrameNum (pCtx);
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 }
2705 }2671 }
2706 if (!kbIdrFlag &&2672 if (!kbIdrFlag &&
2707 pSh->iFrameNum != iPrevFrameNum &&2673 pSh->iFrameNum != iPrevFrameNum &&
@@ -2727,6 +2693,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 19 unmodified lines
2727 2693
2728 if (iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID && isNewFrame) {2694 if (iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID && isNewFrame) {
2729 iRet = InitRefPicList (pCtx, pCtx->uiNalRefIdc, pSh->iPicOrderCntLsb);2695 iRet = InitRefPicList (pCtx, pCtx->uiNalRefIdc, pSh->iPicOrderCntLsb);
2696 if (iThreadCount > 1) isNewFrame = false;
2730 if (iRet) {2697 if (iRet) {
2731 pCtx->bRPLRError = true;2698 pCtx->bRPLRError = true;
2732 bAllRefComplete = false; // RPLR error, set ref pictures complete flag false2699 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