Add additional function PrefetchLastPicForThread and variables for better control of threaded decoding in the case of multi-slice with one slice group contains one slice.
Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 9 files). Show all
Unified · Split
| @@ -393,6 +393,7 @@ void WelsDecoderLastDecPicInfoDefaults (SWelsLastDecPicInfo& sLastDecPicInfo) { · 392 unmodified lines | ||
| 393 | 393 | sLastDecPicInfo.pPreviousDecodedPictureInDpb = NULL; |
| 394 | 394 | sLastDecPicInfo.iPrevFrameNum = -1; |
| 395 | 395 | sLastDecPicInfo.bLastHasMmco5 = false; |
| 396 | + sLastDecPicInfo.uiDecodingTimeStamp = 0; | |
| 396 | 397 | } |
| 397 | 398 | |
| 398 | 399 | /*! |
| @@ -437,6 +438,9 @@ static inline int32_t GetTargetRefListSize (PWelsDecoderContext pCtx) { · 38 unmodified lines | ||
| 437 | 438 | iNumRefFrames = MAX_REF_PIC_COUNT + 2; |
| 438 | 439 | } else { |
| 439 | 440 | iNumRefFrames = pCtx->pSps->iNumRefFrames + 2; |
| 441 | + if (pCtx->pThreadCtx != NULL) { | |
| 442 | + iNumRefFrames = MAX_REF_PIC_COUNT + 1; | |
| 443 | + } | |
| 440 | 444 | } |
| 441 | 445 | |
| 442 | 446 | #ifdef LONG_TERM_REF |
| @@ -478,7 +482,9 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 35 unmodified lines | ||
| 478 | 482 | && kiPicHeight == pCtx->iImgHeightInPixel) && (!bNeedChangePicQueue)) // have same scaled buffer |
| 479 | 483 | |
| 480 | 484 | // sync update pRefList |
| 481 | − WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free | |
| 485 | + if (pCtx->pThreadCtx == NULL) { | |
| 486 | + WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free | |
| 487 | + } | |
| 482 | 488 | |
| 483 | 489 | if (pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel) |
| 484 | 490 | && pCtx->pPicBuff != NULL && pCtx->pPicBuff->iCapacity != iPicQueueSize) { |
| @@ -554,6 +560,17 @@ void WelsFreeDynamicMemory (PWelsDecoderContext pCtx) { · 69 unmodified lines | ||
| 554 | 560 | if (NULL != pPicBuff && NULL != *pPicBuff) { |
| 555 | 561 | DestroyPicBuff (pCtx, pPicBuff, pMa); |
| 556 | 562 | } |
| 563 | + if (pCtx->pThreadCtx != NULL) { | |
| 564 | + //prevent from double destruction of PPicBuff | |
| 565 | + PWelsDecoderThreadCTX pThreadCtx = (PWelsDecoderThreadCTX) (pCtx->pThreadCtx); | |
| 566 | + int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum; | |
| 567 | + int32_t id = pThreadCtx->sThreadInfo.uiThrNum; | |
| 568 | + for (int32_t i = 0; i < threadCount; ++i) { | |
| 569 | + if (pThreadCtx[i - id].pCtx != NULL) { | |
| 570 | + pThreadCtx[i - id].pCtx->pPicBuff = NULL; | |
| 571 | + } | |
| 572 | + } | |
| 573 | + } | |
| 557 | 574 | |
| 558 | 575 | if (pCtx->pTempDec) { |
| 559 | 576 | FreePicture (pCtx->pTempDec, pCtx->pMemAlign); |
| @@ -796,7 +813,11 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 236 unmodified lines | ||
| 796 | 813 | } |
| 797 | 814 | CheckAndFinishLastPic (pCtx, ppDst, pDstBufInfo); |
| 798 | 815 | if (pCtx->bAuReadyFlag && pCtx->pAccessUnitList->uiAvailUnitsNum != 0) { |
| 799 | − ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 816 | + if (pCtx->pThreadCtx == NULL) { | |
| 817 | + ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 818 | + } else { | |
| 819 | + pCtx->pAccessUnitList->uiAvailUnitsNum = 1; | |
| 820 | + } | |
| 800 | 821 | } |
| 801 | 822 | } |
| 802 | 823 | DecodeFinishUpdate (pCtx); |
| @@ -852,9 +873,15 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 49 unmodified lines | ||
| 852 | 873 | if (IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType)) { |
| 853 | 874 | iRet = ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes, pSrcNal - 3, iSrcIdx + 3); |
| 854 | 875 | } |
| 855 | − CheckAndFinishLastPic (pCtx, ppDst, pDstBufInfo); | |
| 876 | + if (pCtx->pThreadCtx == NULL) { | |
| 877 | + CheckAndFinishLastPic (pCtx, ppDst, pDstBufInfo); | |
| 878 | + } | |
| 856 | 879 | if (pCtx->bAuReadyFlag && pCtx->pAccessUnitList->uiAvailUnitsNum != 0) { |
| 857 | − ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 880 | + if (pCtx->pThreadCtx == NULL) { | |
| 881 | + ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 882 | + } else { | |
| 883 | + pCtx->pAccessUnitList->uiAvailUnitsNum = 1; | |
| 884 | + } | |
| 858 | 885 | } |
| 859 | 886 | } |
| 860 | 887 | DecodeFinishUpdate (pCtx); |