Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 3 files). Show all
Unified · Split
| @@ -3750,7 +3750,84 @@ void ClearFrameBsInfo (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi) { · 3749 unmodified lines | ||
| 3750 | 3750 | pFbi->iLayerNum = 0; |
| 3751 | 3751 | pFbi->iFrameSizeInBytes = 0; |
| 3752 | 3752 | } |
| 3753 | +EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsInfo, int32_t iSpatialNum , | |
| 3754 | + int8_t& iCurDid, int32_t& iCurTid, | |
| 3755 | + int32_t& iLayerNum, int32_t& iFrameSize, long long uiTimeStamp) { | |
| 3756 | + SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam; | |
| 3757 | + SSpatialPicIndex* pSpatialIndexMap = &pCtx->sSpatialIndexMap[0]; | |
| 3758 | + | |
| 3759 | + if (!pSvcParam->bSimulcastAVC) { | |
| 3760 | + pCtx->iSkipFrameFlag = false; | |
| 3761 | + for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) { | |
| 3762 | + if (pCtx->pSvcParam->sDependencyLayers[ (pSpatialIndexMap + iDid)->iDid].iSkipFrameFlag) | |
| 3763 | + pCtx->iSkipFrameFlag = 1; | |
| 3764 | + } | |
| 3765 | + } | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid); | |
| 3769 | + | |
| 3770 | + if (eFrameType == videoFrameTypeSkip) { | |
| 3771 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 3772 | + "[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames", | |
| 3773 | + uiTimeStamp, pCtx->iContinualSkipFrames); | |
| 3774 | + if (pSvcParam->bSimulcastAVC) { | |
| 3775 | + if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) | |
| 3776 | + pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iCurDid); | |
| 3777 | + } | |
| 3778 | + | |
| 3779 | + else { | |
| 3780 | + if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) { | |
| 3781 | + for (int32_t i = 0; i < iSpatialNum; i++) { | |
| 3782 | + pCtx->pSvcParam->sDependencyLayers[i].iSkipFrameFlag = false; | |
| 3783 | + pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, (pSpatialIndexMap + i)->iDid); | |
| 3784 | + } | |
| 3785 | + } | |
| 3786 | + } | |
| 3787 | + | |
| 3788 | + } else { | |
| 3789 | + if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) { | |
| 3790 | + bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType, | |
| 3791 | + (uint32_t)uiTimeStamp); | |
| 3792 | + if (bSkip) { | |
| 3793 | + eFrameType = videoFrameTypeSkip; | |
| 3794 | + pLayerBsInfo->eFrameType = videoFrameTypeSkip; | |
| 3795 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 3796 | + "[Rc] Frame timestamp = %lld, skip one frame due to max_br, continual skipped %d frames", | |
| 3797 | + uiTimeStamp, pCtx->iContinualSkipFrames); | |
| 3798 | + } | |
| 3799 | + } | |
| 3800 | + } | |
| 3801 | + | |
| 3802 | + if (eFrameType != videoFrameTypeSkip) { | |
| 3803 | + SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid]; | |
| 3804 | + pCtx->iContinualSkipFrames = 0; | |
| 3805 | + iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iCurDid], pParamInternal->iCodingIndex, | |
| 3806 | + pSvcParam->uiGopSize); | |
| 3807 | + pCtx->uiTemporalId = iCurTid; | |
| 3808 | + if (eFrameType == videoFrameTypeIDR) { | |
| 3809 | + // write parameter sets bitstream or SEI/SSEI (if any) here | |
| 3810 | + // TODO: use function pointer instead | |
| 3811 | + if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) { | |
| 3812 | + if (pSvcParam->bSimulcastAVC) { | |
| 3813 | + pCtx->iEncoderError = WriteSavcParaset (pCtx, iCurDid, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3814 | + ++ pCtx->uiIdrPicId; | |
| 3815 | + } else { | |
| 3816 | + pCtx->iEncoderError = WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3817 | + ++ pCtx->uiIdrPicId; | |
| 3818 | + } | |
| 3819 | + } else { | |
| 3820 | + pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3821 | + | |
| 3822 | + ++ pCtx->uiIdrPicId; | |
| 3823 | + } | |
| 3824 | + } | |
| 3825 | + | |
| 3826 | + } | |
| 3753 | 3827 | |
| 3828 | + | |
| 3829 | + return eFrameType; | |
| 3830 | +} | |
| 3754 | 3831 | /*! |
| 3755 | 3832 | * \brief core svc encoding process |
| 3756 | 3833 | * |
| @@ -3788,7 +3865,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 31 unmodified lines | ||
| 3788 | 3865 | int32_t iCurTid = 0; |
| 3789 | 3866 | bool bAvcBased = false; |
| 3790 | 3867 | SLogContext* pLogCtx = & (pCtx->sLogCtx); |
| 3791 | − bool bFinishedWriteHeader = false; | |
| 3792 | 3868 | #if defined(ENABLE_PSNR_CALC) |
| 3793 | 3869 | float fSnrY = .0f, fSnrU = .0f, fSnrV = .0f; |
| 3794 | 3870 | #endif//ENABLE_PSNR_CALC |
| @@ -3816,19 +3892,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 21 unmodified lines | ||
| 3816 | 3892 | SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iDidIdx]; |
| 3817 | 3893 | pParamInternal->iCodingIndex ++; |
| 3818 | 3894 | } |
| 3895 | + pFbi->eFrameType = videoFrameTypeSkip; | |
| 3819 | 3896 | pLayerBsInfo->eFrameType = videoFrameTypeSkip; |
| 3820 | 3897 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, |
| 3821 | 3898 | "[Rc] Frame timestamp = %lld, skip one frame due to preprocessing return (temporal layer settings or else), continual skipped %d frames", |
| 3822 | 3899 | pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames); |
| 3823 | 3900 | return ENC_RETURN_SUCCESS; |
| 3824 | 3901 | } |
| 3825 | − if (!pSvcParam->bSimulcastAVC) { | |
| 3826 | − pCtx->iSkipFrameFlag = false; | |
| 3827 | − for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) { | |
| 3828 | − if (pCtx->pSvcParam->sDependencyLayers[iDid].iSkipFrameFlag) | |
| 3829 | − pCtx->iSkipFrameFlag = 1; | |
| 3830 | − } | |
| 3831 | − } | |
| 3832 | 3902 | |
| 3833 | 3903 | InitBitStream (pCtx); |
| 3834 | 3904 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; |
| @@ -3836,88 +3906,41 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line | ||
| 3836 | 3906 | |
| 3837 | 3907 | pCtx->pCurDqLayer = pCtx->ppDqLayerList[pSpatialIndexMap->iDid]; |
| 3838 | 3908 | pCtx->pCurDqLayer->pRefLayer = NULL; |
| 3909 | + if (!pSvcParam->bSimulcastAVC) { | |
| 3910 | + eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize, | |
| 3911 | + pFbi->uiTimeStamp); | |
| 3912 | + if (eFrameType == videoFrameTypeSkip) { | |
| 3913 | + pFbi->eFrameType = videoFrameTypeSkip; | |
| 3914 | + pLayerBsInfo->eFrameType = videoFrameTypeSkip; | |
| 3915 | + | |
| 3916 | + return ENC_RETURN_SUCCESS; | |
| 3917 | + } | |
| 3918 | + } | |
| 3839 | 3919 | |
| 3840 | 3920 | while (iSpatialIdx < pSvcParam->iSpatialLayerNum) { |
| 3841 | − const int32_t iDidIdx = (pSpatialIndexMap + iSpatialIdx)->iDid; | |
| 3842 | − SSpatialLayerConfig* pParam = &pSvcParam->sSpatialLayers[iDidIdx]; | |
| 3843 | − SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iDidIdx]; | |
| 3844 | − int32_t iDecompositionStages = pSvcParam->sDependencyLayers[iDidIdx].iDecompositionStages; | |
| 3845 | − pCtx->pCurDqLayer = pCtx->ppDqLayerList[iDidIdx]; | |
| 3846 | − pCtx->uiDependencyId = iCurDid = (int8_t)iDidIdx; | |
| 3921 | + iCurDid = (pSpatialIndexMap + iSpatialIdx)->iDid; | |
| 3922 | + SSpatialLayerConfig* pParam = &pSvcParam->sSpatialLayers[iCurDid]; | |
| 3923 | + SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid]; | |
| 3924 | + int32_t iDecompositionStages = pSvcParam->sDependencyLayers[iCurDid].iDecompositionStages; | |
| 3925 | + pCtx->pCurDqLayer = pCtx->ppDqLayerList[iCurDid]; | |
| 3926 | + pCtx->uiDependencyId = iCurDid; | |
| 3847 | 3927 | //skip this spatial layer |
| 3848 | 3928 | if (GetTemporalLevel (pParamInternal, pParamInternal->iCodingIndex, pSvcParam->uiGopSize) == INVALID_TEMPORAL_ID) { |
| 3849 | 3929 | ++iSpatialIdx; |
| 3850 | 3930 | pParamInternal->iCodingIndex ++; |
| 3851 | 3931 | continue; |
| 3852 | 3932 | } |
| 3853 | − eFrameType = DecideFrameType (pCtx, iSpatialNum, iDidIdx); | |
| 3854 | − if (eFrameType == videoFrameTypeSkip) { | |
| 3855 | − eFrameType = videoFrameTypeSkip; | |
| 3856 | − pLayerBsInfo->eFrameType = eFrameType; | |
| 3857 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 3858 | − "[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames", | |
| 3859 | − pFbi->uiTimeStamp, pCtx->iContinualSkipFrames); | |
| 3860 | − ++ iSpatialIdx; | |
| 3861 | − if (pSvcParam->bSimulcastAVC) { | |
| 3862 | − if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) | |
| 3863 | − pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iDidIdx); | |
| 3864 | − continue; | |
| 3865 | − } | |
| 3866 | − | |
| 3867 | − else { | |
| 3868 | − if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) { | |
| 3869 | − for (int32_t i = 0; i < iSpatialNum; i++) { | |
| 3870 | − pCtx->pSvcParam->sDependencyLayers[i].iSkipFrameFlag = false; | |
| 3871 | − pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, (pSpatialIndexMap + i)->iDid); | |
| 3872 | − } | |
| 3873 | − } | |
| 3874 | − return ENC_RETURN_SUCCESS; | |
| 3875 | − } | |
| 3876 | − } | |
| 3877 | − //loop each layer to check if have skip frame when RC and frame skip enable | |
| 3878 | − if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) { | |
| 3879 | − bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType, | |
| 3880 | − (uint32_t)pFbi->uiTimeStamp); | |
| 3881 | − if (bSkip) { | |
| 3882 | − eFrameType = videoFrameTypeSkip; | |
| 3933 | + if (pSvcParam->bSimulcastAVC) { | |
| 3934 | + eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize, | |
| 3935 | + pFbi->uiTimeStamp); | |
| 3936 | + if (eFrameType == videoFrameTypeSkip) { | |
| 3883 | 3937 | pLayerBsInfo->eFrameType = videoFrameTypeSkip; |
| 3884 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, | |
| 3885 | − "[Rc] Frame timestamp = %lld, skip one frame due to max_br, continual skipped %d frames", | |
| 3886 | − pFbi->uiTimeStamp, pCtx->iContinualSkipFrames); | |
| 3887 | − ++ iSpatialIdx; | |
| 3888 | − if (pSvcParam->bSimulcastAVC) | |
| 3889 | − continue; | |
| 3890 | − else | |
| 3891 | − return ENC_RETURN_SUCCESS; | |
| 3892 | − } | |
| 3893 | − } | |
| 3894 | − pCtx->iContinualSkipFrames = 0; | |
| 3895 | − iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iDidIdx], pParamInternal->iCodingIndex, | |
| 3896 | − pSvcParam->uiGopSize); | |
| 3897 | − pCtx->uiTemporalId = iCurTid; | |
| 3898 | − InitFrameCoding (pCtx, eFrameType, iDidIdx); | |
| 3899 | − | |
| 3900 | − if (eFrameType == videoFrameTypeIDR) { | |
| 3901 | − // write parameter sets bitstream or SEI/SSEI (if any) here | |
| 3902 | − // TODO: use function pointer instead | |
| 3903 | − if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) { | |
| 3904 | − if (pSvcParam->bSimulcastAVC) { | |
| 3905 | − pCtx->iEncoderError = WriteSavcParaset (pCtx, iCurDid, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3906 | − ++ pCtx->uiIdrPicId; | |
| 3907 | − } else if (!bFinishedWriteHeader) { | |
| 3908 | − pCtx->iEncoderError = WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3909 | − ++ pCtx->uiIdrPicId; | |
| 3910 | − bFinishedWriteHeader = true; | |
| 3911 | − } | |
| 3912 | − } else if (!bFinishedWriteHeader) { | |
| 3913 | − pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | |
| 3914 | − bFinishedWriteHeader = true; | |
| 3915 | − ++ pCtx->uiIdrPicId; | |
| 3938 | + ++iSpatialIdx; | |
| 3939 | + continue; | |
| 3916 | 3940 | } |
| 3917 | − WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3918 | 3941 | } |
| 3919 | − | |
| 3920 | − pCtx->pVpp->AnalyzeSpatialPic (pCtx, iDidIdx); | |
| 3942 | + InitFrameCoding (pCtx, eFrameType, iCurDid); | |
| 3943 | + pCtx->pVpp->AnalyzeSpatialPic (pCtx, iCurDid); | |
| 3921 | 3944 | |
| 3922 | 3945 | pCtx->pEncPic = pEncPic = (pSpatialIndexMap + iSpatialIdx)->pSrc; |
| 3923 | 3946 | pCtx->pEncPic->iPictureType = pCtx->eSliceType; |
| @@ -4237,8 +4260,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 313 unmodified lines | ||
| 4237 | 4260 | if ( |
| 4238 | 4261 | (!pCtx->pCurDqLayer->bDeblockingParallelFlag) && |
| 4239 | 4262 | #if !defined(ENABLE_FRAME_DUMP) |
| 4240 | − ((eNalRefIdc != NRI_PRI_LOWEST) && (pSvcParam->sDependencyLayers[iDidIdx].iHighestTemporalId == 0 | |
| 4241 | − || iCurTid < pSvcParam->sDependencyLayers[iDidIdx].iHighestTemporalId)) && | |
| 4263 | + ((eNalRefIdc != NRI_PRI_LOWEST) && (pSvcParam->sDependencyLayers[iCurDid].iHighestTemporalId == 0 | |
| 4264 | + || iCurTid < pSvcParam->sDependencyLayers[iCurDid].iHighestTemporalId)) && | |
| 4242 | 4265 | #endif//!ENABLE_FRAME_DUMP |
| 4243 | 4266 | true |
| 4244 | 4267 | ) { |
| @@ -4247,7 +4270,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 4247 | 4270 | |
| 4248 | 4271 | pCtx->pFuncList->pfRc.pfWelsRcPictureInfoUpdate (pCtx, iLayerSize); |
| 4249 | 4272 | RcTraceFrameBits (pCtx, pFbi->uiTimeStamp); |
| 4250 | − pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc[iDidIdx].iAverageFrameQp; | |
| 4273 | + pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc[iCurDid].iAverageFrameQp; | |
| 4251 | 4274 | |
| 4252 | 4275 | //update scc related |
| 4253 | 4276 | pCtx->pFuncList->pfUpdateFMESwitch (pCtx->pCurDqLayer); |
| @@ -4405,7 +4428,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 151 unmodified lines | ||
| 4405 | 4428 | #endif//#if defined(MT_DEBUG) |
| 4406 | 4429 | } |
| 4407 | 4430 | |
| 4408 | − pCtx->eLastNalPriority[iDidIdx] = eNalRefIdc; | |
| 4431 | + pCtx->eLastNalPriority[iCurDid] = eNalRefIdc; | |
| 4409 | 4432 | ++ iSpatialIdx; |
| 4410 | 4433 | |
| 4411 | 4434 | if (iCurDid + 1 < pSvcParam->iSpatialLayerNum) { |
| @@ -4413,7 +4436,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line | ||
| 4413 | 4436 | WelsSwapDqLayers (pCtx, (pSpatialIndexMap + iSpatialIdx)->iDid); |
| 4414 | 4437 | } |
| 4415 | 4438 | |
| 4416 | − if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx) != 0) { | |
| 4439 | + if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iCurDid) != 0) { | |
| 4417 | 4440 | ForceCodingIDR (pCtx); |
| 4418 | 4441 | WelsLog (pLogCtx, WELS_LOG_WARNING, |
| 4419 | 4442 | "WelsEncoderEncodeExt(), Logic Error Found in Preprocess updating. ForceCodingIDR!"); |
| @@ -4425,7 +4448,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 5 unmodified lines | ||
| 4425 | 4448 | |
| 4426 | 4449 | if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag |
| 4427 | 4450 | && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) { |
| 4428 | − pCtx->bRefOfCurTidIsLtr[iDidIdx][iCurTid] = true; | |
| 4451 | + pCtx->bRefOfCurTidIsLtr[iCurDid][iCurTid] = true; | |
| 4429 | 4452 | } |
| 4430 | 4453 | ++ pParamInternal->iCodingIndex; |
| 4431 | 4454 | }//end of (iSpatialIdx/iSpatialNum) |