1. Distinguish non-threaded decoding with m_iThreadCount = 0 from one-thread decoding with m_iThreadCount=1. 2. Removed the use of bAvailable of PPicture and replaced by the use of iRefCount to more preciously represent the picture's being-use counts in both threaded and non-threaded mode.
Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 14 files). Show all
Unified · Split
| @@ -221,17 +221,17 @@ static inline int32_t DecodeFrameConstruction (PWelsDecoderContext pCtx, uint8_t · 220 unmodified lines | |||
| 221 | ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; | 221 | ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; |
| 222 | ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; | 222 | ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset; |
| 223 | pDstInfo->iBufferStatus = 1; | 223 | pDstInfo->iBufferStatus = 1; |
| 224 | if (pCtx->pThreadCtx != NULL && pPic->bIsComplete == false) { | 224 | if (GetThreadCount (pCtx) > 1 && pPic->bIsComplete == false) { |
| 225 | pPic->bIsComplete = true; | 225 | pPic->bIsComplete = true; |
| 226 | } | 226 | } |
| 227 | if (pCtx->pThreadCtx != NULL) { | 227 | if (GetThreadCount (pCtx) > 1) { |
| 228 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; | 228 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; |
| 229 | for (uint32_t i = 0; i < uiMbHeight; ++i) { | 229 | for (uint32_t i = 0; i < uiMbHeight; ++i) { |
| 230 | SET_EVENT (&pCtx->pDec->pReadyEvent[i]); | 230 | SET_EVENT (&pCtx->pDec->pReadyEvent[i]); |
| 231 | } | 231 | } |
| 232 | } | 232 | } |
| 233 | bool bOutResChange = false; | 233 | bool bOutResChange = false; |
| 234 | if (pCtx->pThreadCtx == NULL || pCtx->pLastThreadCtx == NULL) { | 234 | if (GetThreadCount (pCtx) <= 1 || pCtx->pLastThreadCtx == NULL) { |
| 235 | bOutResChange = (pCtx->iLastImgWidthInPixel != pDstInfo->UsrData.sSystemBuffer.iWidth) | 235 | bOutResChange = (pCtx->iLastImgWidthInPixel != pDstInfo->UsrData.sSystemBuffer.iWidth) |
| 236 | || (pCtx->iLastImgHeightInPixel != pDstInfo->UsrData.sSystemBuffer.iHeight); | 236 | || (pCtx->iLastImgHeightInPixel != pDstInfo->UsrData.sSystemBuffer.iHeight); |
| 237 | } else { | 237 | } else { |
| @@ -2282,7 +2282,7 @@ int32_t WelsDecodeInitAccessUnitStart (PWelsDecoderContext pCtx, SBufferInfo* pD · 2044 unmodified lines | |||
| 2282 | */ | 2282 | */ |
| 2283 | int32_t AllocPicBuffOnNewSeqBegin (PWelsDecoderContext pCtx) { | 2283 | int32_t AllocPicBuffOnNewSeqBegin (PWelsDecoderContext pCtx) { |
| 2284 | //try to allocate or relocate DPB memory only when new sequence is coming. | 2284 | //try to allocate or relocate DPB memory only when new sequence is coming. |
| 2285 | if (pCtx->pThreadCtx == NULL) { | 2285 | if (GetThreadCount (pCtx) <= 1) { |
| 2286 | WelsResetRefPic (pCtx); //clear ref pPic when IDR NAL | 2286 | WelsResetRefPic (pCtx); //clear ref pPic when IDR NAL |
| 2287 | } | 2287 | } |
| 2288 | int32_t iErr = SyncPictureResolutionExt (pCtx, pCtx->pSps->iMbWidth, pCtx->pSps->iMbHeight); | 2288 | int32_t iErr = SyncPictureResolutionExt (pCtx, pCtx->pSps->iMbWidth, pCtx->pSps->iMbHeight); |
| @@ -2418,7 +2418,7 @@ void WelsDqLayerDecodeStart (PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pS · 129 unmodified lines | |||
| 2418 | 2418 | ||
| 2419 | int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) { | 2419 | int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) { |
| 2420 | int32_t iRet = ERR_NONE; | 2420 | int32_t iRet = ERR_NONE; |
| 2421 | if (pCtx->pThreadCtx != NULL && pCtx->bNewSeqBegin) { | 2421 | if (GetThreadCount (pCtx) > 1 && pCtx->bNewSeqBegin) { |
| 2422 | WelsResetRefPic (pCtx); | 2422 | WelsResetRefPic (pCtx); |
| 2423 | } | 2423 | } |
| 2424 | if (pCtx->eSliceType == B_SLICE) { | 2424 | if (pCtx->eSliceType == B_SLICE) { |
| @@ -2542,7 +2542,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 117 unmodified lines | |||
| 2542 | } | 2542 | } |
| 2543 | } | 2543 | } |
| 2544 | bool isNewFrame = true; | 2544 | bool isNewFrame = true; |
| 2545 | if (pThreadCtx != NULL) { | 2545 | if (GetThreadCount (pCtx) > 1) { |
| 2546 | isNewFrame = pCtx->pDec == NULL; | 2546 | isNewFrame = pCtx->pDec == NULL; |
| 2547 | } | 2547 | } |
| 2548 | if (pCtx->pDec == NULL) { | 2548 | if (pCtx->pDec == NULL) { |
| @@ -2553,7 +2553,6 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 4 unmodified lines | |||
| 2553 | uint32_t i = 0; | 2553 | uint32_t i = 0; |
| 2554 | while (i < MAX_DPB_COUNT && pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]) { | 2554 | while (i < MAX_DPB_COUNT && pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]) { |
| 2555 | pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]; | 2555 | pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]; |
| 2556 | pLastThreadCtx->pDec->pRefPic[listIdx][i]->bAvailableFlag = false; | ||
| 2557 | ++i; | 2556 | ++i; |
| 2558 | } | 2557 | } |
| 2559 | } | 2558 | } |
| @@ -2563,30 +2562,8 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 3 unmodified lines | |||
| 2563 | } else { | 2562 | } else { |
| 2564 | pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic; | 2563 | pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic; |
| 2565 | } | 2564 | } |
| 2566 | //printf ("last uiDecodingTimeStamp = %d\n", pLastThreadCtx->pCtx->uiDecodingTimeStamp); | ||
| 2567 | for (int32_t i = 0; i < pCtx->sRefPic.uiRefCount[LIST_0]; ++i) { | ||
| 2568 | if (pCtx->sRefPic.pRefList[LIST_0][i] != NULL) { | ||
| 2569 | pCtx->sRefPic.pRefList[LIST_0][i]->bAvailableFlag = false; | ||
| 2570 | } | ||
| 2571 | } | ||
| 2572 | for (int32_t i = 0; i < pCtx->sRefPic.uiRefCount[LIST_1]; ++i) { | ||
| 2573 | if (pCtx->sRefPic.pRefList[LIST_1][i] != NULL) { | ||
| 2574 | pCtx->sRefPic.pRefList[LIST_1][i]->bAvailableFlag = false; | ||
| 2575 | } | ||
| 2576 | } | ||
| 2577 | } | 2565 | } |
| 2578 | pCtx->pDec = PrefetchPic (pCtx->pPicBuff); | 2566 | pCtx->pDec = PrefetchPic (pCtx->pPicBuff); |
| 2579 | if (pThreadCtx != NULL) { | ||
| 2580 | if (pCtx->pDec != NULL) { | ||
| 2581 | pCtx->pDec->bAvailableFlag = false; | ||
| 2582 | pCtx->pDec->bIsUngroupedMultiSlice = false; | ||
| 2583 | pThreadCtx->pDec = pCtx->pDec; | ||
| 2584 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; | ||
| 2585 | for (uint32_t i = 0; i < uiMbHeight; ++i) { | ||
| 2586 | RESET_EVENT (&pCtx->pDec->pReadyEvent[i]); | ||
| 2587 | } | ||
| 2588 | } | ||
| 2589 | } | ||
| 2590 | if (pCtx->iTotalNumMbRec != 0) | 2567 | if (pCtx->iTotalNumMbRec != 0) |
| 2591 | pCtx->iTotalNumMbRec = 0; | 2568 | pCtx->iTotalNumMbRec = 0; |
| 2592 | 2569 | ||
| @@ -2598,6 +2575,15 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 5 unmodified lines | |||
| 2598 | pCtx->iErrorCode |= dsOutOfMemory; | 2575 | pCtx->iErrorCode |= dsOutOfMemory; |
| 2599 | return ERR_INFO_REF_COUNT_OVERFLOW; | 2576 | return ERR_INFO_REF_COUNT_OVERFLOW; |
| 2600 | } | 2577 | } |
| 2578 | if (pThreadCtx != NULL) { | ||
| 2579 | pCtx->pDec->bIsUngroupedMultiSlice = false; | ||
| 2580 | pThreadCtx->pDec = pCtx->pDec; | ||
| 2581 | if (GetThreadCount (pCtx) > 1) ++pCtx->pDec->iRefCount; | ||
| 2582 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; | ||
| 2583 | for (uint32_t i = 0; i < uiMbHeight; ++i) { | ||
| 2584 | RESET_EVENT (&pCtx->pDec->pReadyEvent[i]); | ||
| 2585 | } | ||
| 2586 | } | ||
| 2601 | pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding | 2587 | pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding |
| 2602 | } else if (pCtx->iTotalNumMbRec == 0) { //pDec != NULL, already start | 2588 | } else if (pCtx->iTotalNumMbRec == 0) { //pDec != NULL, already start |
| 2603 | pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding | 2589 | pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding |
| @@ -2743,7 +2729,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 139 unmodified lines | |||
| 2743 | if (pSh->eSliceType == B_SLICE && !pSh->iDirectSpatialMvPredFlag) | 2729 | if (pSh->eSliceType == B_SLICE && !pSh->iDirectSpatialMvPredFlag) |
| 2744 | ComputeColocatedTemporalScaling (pCtx); | 2730 | ComputeColocatedTemporalScaling (pCtx); |
| 2745 | 2731 | ||
| 2746 | if (pThreadCtx != NULL) { | 2732 | if (GetThreadCount (pCtx) > 1) { |
| 2747 | memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t)); | 2733 | memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t)); |
| 2748 | SET_EVENT (&pThreadCtx->sSliceDecodeStart); | 2734 | SET_EVENT (&pThreadCtx->sSliceDecodeStart); |
| 2749 | iRet = WelsDecodeAndConstructSlice (pCtx); | 2735 | iRet = WelsDecodeAndConstructSlice (pCtx); |
| @@ -2765,14 +2751,14 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 15 unmodified lines | |||
| 2765 | } | 2751 | } |
| 2766 | } | 2752 | } |
| 2767 | 2753 | ||
| 2768 | if (pThreadCtx == NULL && bReconstructSlice) { | 2754 | if (GetThreadCount (pCtx) <= 1 && bReconstructSlice) { |
| 2769 | if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) { | 2755 | if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) { |
| 2770 | pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false | 2756 | pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false |
| 2771 | return iRet; | 2757 | return iRet; |
| 2772 | } | 2758 | } |
| 2773 | } | 2759 | } |
| 2774 | if (bAllRefComplete && pCtx->eSliceType != I_SLICE) { | 2760 | if (bAllRefComplete && pCtx->eSliceType != I_SLICE) { |
| 2775 | if (pCtx->pThreadCtx == NULL) { | 2761 | if (GetThreadCount (pCtx) <= 1) { |
| 2776 | if (pCtx->sRefPic.uiRefCount[LIST_0] > 0) { | 2762 | if (pCtx->sRefPic.uiRefCount[LIST_0] > 0) { |
| 2777 | bAllRefComplete &= CheckRefPicturesComplete (pCtx); | 2763 | bAllRefComplete &= CheckRefPicturesComplete (pCtx); |
| 2778 | } else { | 2764 | } else { |
| @@ -2829,17 +2815,18 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 50 unmodified lines | |||
| 2829 | } | 2815 | } |
| 2830 | } | 2816 | } |
| 2831 | 2817 | ||
| 2832 | if (pThreadCtx != NULL && pCtx->uiDecodingTimeStamp > 1 && pCtx->pLastDecPicInfo->uiDecodingTimeStamp > 0) { | 2818 | if (GetThreadCount (pCtx) > 1 && pCtx->uiDecodingTimeStamp > 1 && pCtx->pLastDecPicInfo->uiDecodingTimeStamp > 0) { |
| 2833 | while (pCtx->uiDecodingTimeStamp > pCtx->pLastDecPicInfo->uiDecodingTimeStamp + 1) { | 2819 | while (pCtx->uiDecodingTimeStamp > pCtx->pLastDecPicInfo->uiDecodingTimeStamp + 1) { |
| 2834 | WelsSleep (1); | 2820 | WelsSleep (1); |
| 2835 | } | 2821 | } |
| 2836 | } | 2822 | } |
| 2837 | if (pThreadCtx != NULL) { | 2823 | |
| 2824 | if (GetThreadCount (pCtx) >= 1) { | ||
| 2838 | pCtx->pLastDecPicInfo->uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp; | 2825 | pCtx->pLastDecPicInfo->uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp; |
| 2839 | } | 2826 | } |
| 2840 | iRet = DecodeFrameConstruction (pCtx, ppDst, pDstInfo); | 2827 | iRet = DecodeFrameConstruction (pCtx, ppDst, pDstInfo); |
| 2841 | if (iRet) { | 2828 | if (iRet) { |
| 2842 | if (pThreadCtx != NULL) { | 2829 | if (GetThreadCount (pCtx) > 1) { |
| 2843 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); | 2830 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); |
| 2844 | } | 2831 | } |
| 2845 | return iRet; | 2832 | return iRet; |
| @@ -2847,7 +2834,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 1 unmodified line | |||
| 2847 | 2834 | ||
| 2848 | pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb = pCtx->pDec; //store latest decoded picture for EC | 2835 | pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb = pCtx->pDec; //store latest decoded picture for EC |
| 2849 | pCtx->bUsedAsRef = pCtx->uiNalRefIdc > 0; | 2836 | pCtx->bUsedAsRef = pCtx->uiNalRefIdc > 0; |
| 2850 | if (pCtx->pThreadCtx == NULL) { | 2837 | if (GetThreadCount (pCtx) <= 1) { |
| 2851 | if (pCtx->bUsedAsRef) { | 2838 | if (pCtx->bUsedAsRef) { |
| 2852 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | 2839 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { |
| 2853 | uint32_t i = 0; | 2840 | uint32_t i = 0; |
| @@ -2870,7 +2857,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 16 unmodified lines | |||
| 2870 | pCtx->pDec->iLinesize, | 2857 | pCtx->pDec->iLinesize, |
| 2871 | pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); | 2858 | pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); |
| 2872 | } | 2859 | } |
| 2873 | } else { | 2860 | } else if (GetThreadCount (pCtx) > 1) { |
| 2874 | SET_EVENT (&pThreadCtx->sImageReady); | 2861 | SET_EVENT (&pThreadCtx->sImageReady); |
| 2875 | } | 2862 | } |
| 2876 | pCtx->pDec = NULL; //after frame decoding, always set to NULL | 2863 | pCtx->pDec = NULL; //after frame decoding, always set to NULL |
| @@ -2881,7 +2868,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 4 unmodified lines | |||
| 2881 | pCtx->pLastDecPicInfo->iPrevFrameNum = pSh->iFrameNum; | 2868 | pCtx->pLastDecPicInfo->iPrevFrameNum = pSh->iFrameNum; |
| 2882 | if (pCtx->pLastDecPicInfo->bLastHasMmco5) | 2869 | if (pCtx->pLastDecPicInfo->bLastHasMmco5) |
| 2883 | pCtx->pLastDecPicInfo->iPrevFrameNum = 0; | 2870 | pCtx->pLastDecPicInfo->iPrevFrameNum = 0; |
| 2884 | if (pThreadCtx != NULL) { | 2871 | if (GetThreadCount (pCtx) > 1) { |
| 2885 | int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum; | 2872 | int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum; |
| 2886 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; | 2873 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; |
| 2887 | for (int32_t i = 0; i < threadCount; ++i) { | 2874 | for (int32_t i = 0; i < threadCount; ++i) { |
| @@ -2899,7 +2886,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 11 unmodified lines | |||
| 2899 | } | 2886 | } |
| 2900 | } | 2887 | } |
| 2901 | } | 2888 | } |
| 2902 | if (pThreadCtx != NULL) { | 2889 | if (GetThreadCount (pCtx) > 1) { |
| 2903 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); | 2890 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); |
| 2904 | } | 2891 | } |
| 2905 | return ERR_NONE; | 2892 | return ERR_NONE; |