Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 2 files). Show all
Unified · Split
| @@ -2495,6 +2495,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 2494 unmodified lines | |||
| 2495 | pLastThreadCtx->iPicBuffIdx); | 2495 | pLastThreadCtx->iPicBuffIdx); |
| 2496 | } | 2496 | } |
| 2497 | } | 2497 | } |
| 2498 | int32_t iThreadCount = GetThreadCount (pCtx); | ||
| 2498 | int32_t iPpsId = 0; | 2499 | int32_t iPpsId = 0; |
| 2499 | int32_t iRet = ERR_NONE; | 2500 | int32_t iRet = ERR_NONE; |
| 2500 | 2501 | ||
| @@ -2542,7 +2543,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 41 unmodified lines | |||
| 2542 | } | 2543 | } |
| 2543 | } | 2544 | } |
| 2544 | bool isNewFrame = true; | 2545 | bool isNewFrame = true; |
| 2545 | if (GetThreadCount (pCtx) > 1) { | 2546 | if (iThreadCount > 1) { |
| 2546 | isNewFrame = pCtx->pDec == NULL; | 2547 | isNewFrame = pCtx->pDec == NULL; |
| 2547 | } | 2548 | } |
| 2548 | if (pCtx->pDec == NULL) { | 2549 | if (pCtx->pDec == NULL) { |
| @@ -2578,7 +2579,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 29 unmodified lines | |||
| 2578 | if (pThreadCtx != NULL) { | 2579 | if (pThreadCtx != NULL) { |
| 2579 | pCtx->pDec->bIsUngroupedMultiSlice = false; | 2580 | pCtx->pDec->bIsUngroupedMultiSlice = false; |
| 2580 | pThreadCtx->pDec = pCtx->pDec; | 2581 | pThreadCtx->pDec = pCtx->pDec; |
| 2581 | if (GetThreadCount (pCtx) > 1) ++pCtx->pDec->iRefCount; | 2582 | if (iThreadCount > 1) ++pCtx->pDec->iRefCount; |
| 2582 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; | 2583 | uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4; |
| 2583 | for (uint32_t i = 0; i < uiMbHeight; ++i) { | 2584 | for (uint32_t i = 0; i < uiMbHeight; ++i) { |
| 2584 | RESET_EVENT (&pCtx->pDec->pReadyEvent[i]); | 2585 | RESET_EVENT (&pCtx->pDec->pReadyEvent[i]); |
| @@ -2729,7 +2730,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 144 unmodified lines | |||
| 2729 | if (pSh->eSliceType == B_SLICE && !pSh->iDirectSpatialMvPredFlag) | 2730 | if (pSh->eSliceType == B_SLICE && !pSh->iDirectSpatialMvPredFlag) |
| 2730 | ComputeColocatedTemporalScaling (pCtx); | 2731 | ComputeColocatedTemporalScaling (pCtx); |
| 2731 | 2732 | ||
| 2732 | if (GetThreadCount (pCtx) > 1) { | 2733 | if (iThreadCount > 1) { |
| 2733 | memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t)); | 2734 | memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t)); |
| 2734 | SET_EVENT (&pThreadCtx->sSliceDecodeStart); | 2735 | SET_EVENT (&pThreadCtx->sSliceDecodeStart); |
| 2735 | iRet = WelsDecodeAndConstructSlice (pCtx); | 2736 | iRet = WelsDecodeAndConstructSlice (pCtx); |
| @@ -2751,14 +2752,14 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 15 unmodified lines | |||
| 2751 | } | 2752 | } |
| 2752 | } | 2753 | } |
| 2753 | 2754 | ||
| 2754 | if (GetThreadCount (pCtx) <= 1 && bReconstructSlice) { | 2755 | if (iThreadCount <= 1 && bReconstructSlice) { |
| 2755 | if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) { | 2756 | if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) { |
| 2756 | pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false | 2757 | pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false |
| 2757 | return iRet; | 2758 | return iRet; |
| 2758 | } | 2759 | } |
| 2759 | } | 2760 | } |
| 2760 | if (bAllRefComplete && pCtx->eSliceType != I_SLICE) { | 2761 | if (bAllRefComplete && pCtx->eSliceType != I_SLICE) { |
| 2761 | if (GetThreadCount (pCtx) <= 1) { | 2762 | if (iThreadCount <= 1) { |
| 2762 | if (pCtx->sRefPic.uiRefCount[LIST_0] > 0) { | 2763 | if (pCtx->sRefPic.uiRefCount[LIST_0] > 0) { |
| 2763 | bAllRefComplete &= CheckRefPicturesComplete (pCtx); | 2764 | bAllRefComplete &= CheckRefPicturesComplete (pCtx); |
| 2764 | } else { | 2765 | } else { |
| @@ -2815,18 +2816,22 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 50 unmodified lines | |||
| 2815 | } | 2816 | } |
| 2816 | } | 2817 | } |
| 2817 | 2818 | ||
| 2818 | if (GetThreadCount (pCtx) > 1 && pCtx->uiDecodingTimeStamp > 1 && pCtx->pLastDecPicInfo->uiDecodingTimeStamp > 0) { | 2819 | if (iThreadCount >= 1) { |
| 2819 | while (pCtx->uiDecodingTimeStamp > pCtx->pLastDecPicInfo->uiDecodingTimeStamp + 1) { | 2820 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; |
| 2820 | WelsSleep (1); | 2821 | for (int32_t i = 0; i < iThreadCount; ++i) { |
| 2822 | if (i != id) { | ||
| 2823 | if (pThreadCtx[i - id].sSliceDecodeStart.isSignaled) { | ||
| 2824 | while (pThreadCtx[i - id].pCtx->uiDecodingTimeStamp < pCtx->uiDecodingTimeStamp) { | ||
| 2825 | WelsSleep (1); | ||
| 2826 | } | ||
| 2827 | } | ||
| 2828 | } | ||
| 2821 | } | 2829 | } |
| 2822 | } | ||
| 2823 | |||
| 2824 | if (GetThreadCount (pCtx) >= 1) { | ||
| 2825 | pCtx->pLastDecPicInfo->uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp; | 2830 | pCtx->pLastDecPicInfo->uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp; |
| 2826 | } | 2831 | } |
| 2827 | iRet = DecodeFrameConstruction (pCtx, ppDst, pDstInfo); | 2832 | iRet = DecodeFrameConstruction (pCtx, ppDst, pDstInfo); |
| 2828 | if (iRet) { | 2833 | if (iRet) { |
| 2829 | if (GetThreadCount (pCtx) > 1) { | 2834 | if (iThreadCount > 1) { |
| 2830 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); | 2835 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); |
| 2831 | } | 2836 | } |
| 2832 | return iRet; | 2837 | return iRet; |
| @@ -2834,7 +2839,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 1 unmodified line | |||
| 2834 | 2839 | ||
| 2835 | pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb = pCtx->pDec; //store latest decoded picture for EC | 2840 | pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb = pCtx->pDec; //store latest decoded picture for EC |
| 2836 | pCtx->bUsedAsRef = pCtx->uiNalRefIdc > 0; | 2841 | pCtx->bUsedAsRef = pCtx->uiNalRefIdc > 0; |
| 2837 | if (GetThreadCount (pCtx) <= 1) { | 2842 | if (iThreadCount <= 1) { |
| 2838 | if (pCtx->bUsedAsRef) { | 2843 | if (pCtx->bUsedAsRef) { |
| 2839 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | 2844 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { |
| 2840 | uint32_t i = 0; | 2845 | uint32_t i = 0; |
| @@ -2857,7 +2862,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 16 unmodified lines | |||
| 2857 | pCtx->pDec->iLinesize, | 2862 | pCtx->pDec->iLinesize, |
| 2858 | pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); | 2863 | pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); |
| 2859 | } | 2864 | } |
| 2860 | } else if (GetThreadCount (pCtx) > 1) { | 2865 | } else if (iThreadCount > 1) { |
| 2861 | SET_EVENT (&pThreadCtx->sImageReady); | 2866 | SET_EVENT (&pThreadCtx->sImageReady); |
| 2862 | } | 2867 | } |
| 2863 | pCtx->pDec = NULL; //after frame decoding, always set to NULL | 2868 | pCtx->pDec = NULL; //after frame decoding, always set to NULL |
| @@ -2868,10 +2873,9 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 4 unmodified lines | |||
| 2868 | pCtx->pLastDecPicInfo->iPrevFrameNum = pSh->iFrameNum; | 2873 | pCtx->pLastDecPicInfo->iPrevFrameNum = pSh->iFrameNum; |
| 2869 | if (pCtx->pLastDecPicInfo->bLastHasMmco5) | 2874 | if (pCtx->pLastDecPicInfo->bLastHasMmco5) |
| 2870 | pCtx->pLastDecPicInfo->iPrevFrameNum = 0; | 2875 | pCtx->pLastDecPicInfo->iPrevFrameNum = 0; |
| 2871 | if (GetThreadCount (pCtx) > 1) { | 2876 | if (iThreadCount > 1) { |
| 2872 | int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum; | ||
| 2873 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; | 2877 | int32_t id = pThreadCtx->sThreadInfo.uiThrNum; |
| 2874 | for (int32_t i = 0; i < threadCount; ++i) { | 2878 | for (int32_t i = 0; i < iThreadCount; ++i) { |
| 2875 | if (pThreadCtx[i - id].pCtx != NULL) { | 2879 | if (pThreadCtx[i - id].pCtx != NULL) { |
| 2876 | unsigned long long uiTimeStamp = pThreadCtx[i - id].pCtx->uiTimeStamp; | 2880 | unsigned long long uiTimeStamp = pThreadCtx[i - id].pCtx->uiTimeStamp; |
| 2877 | if (uiTimeStamp > 0 && pThreadCtx[i - id].pCtx->sSpsPpsCtx.iSeqId > pCtx->sSpsPpsCtx.iSeqId) { | 2881 | if (uiTimeStamp > 0 && pThreadCtx[i - id].pCtx->sSpsPpsCtx.iSeqId > pCtx->sSpsPpsCtx.iSeqId) { |
| @@ -2886,7 +2890,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 8 unmodified lines | |||
| 2886 | } | 2890 | } |
| 2887 | } | 2891 | } |
| 2888 | } | 2892 | } |
| 2889 | if (GetThreadCount (pCtx) > 1) { | 2893 | if (iThreadCount > 1) { |
| 2890 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); | 2894 | SET_EVENT (&pThreadCtx->sSliceDecodeFinsh); |
| 2891 | } | 2895 | } |
| 2892 | return ERR_NONE; | 2896 | return ERR_NONE; |