Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 4 files). Show all
Unified · Split
| @@ -3655,6 +3655,57 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum, · 3654 unmodified lines | ||
| 3655 | 3655 | return iReturn; |
| 3656 | 3656 | } |
| 3657 | 3657 | |
| 3658 | +void StackBackEncoderStatus (sWelsEncCtx* pEncCtx, | |
| 3659 | + EVideoFrameType keFrameType) { | |
| 3660 | + // for bitstream writing | |
| 3661 | + pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position | |
| 3662 | + pEncCtx->pOut->iNalIndex = 0; // reset NAL index | |
| 3663 | + | |
| 3664 | + InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize); | |
| 3665 | + if ((keFrameType == videoFrameTypeP) || (keFrameType == videoFrameTypeI)) { | |
| 3666 | + pEncCtx->iFrameIndex --; | |
| 3667 | + if (pEncCtx->iPOC != 0) { | |
| 3668 | + pEncCtx->iPOC -= 2; | |
| 3669 | + } else { | |
| 3670 | + pEncCtx->iPOC = (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2; | |
| 3671 | + } | |
| 3672 | + | |
| 3673 | + if (pEncCtx->eLastNalPriority != 0) { | |
| 3674 | + if (pEncCtx->iFrameNum != 0) { | |
| 3675 | + pEncCtx->iFrameNum --; | |
| 3676 | + } else { | |
| 3677 | + pEncCtx->iFrameNum = (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1; | |
| 3678 | + } | |
| 3679 | + } | |
| 3680 | + | |
| 3681 | + pEncCtx->eNalType = NAL_UNIT_CODED_SLICE; | |
| 3682 | + pEncCtx->eSliceType = P_SLICE; | |
| 3683 | + pEncCtx->eNalPriority = pEncCtx->eLastNalPriority; | |
| 3684 | + } else if (keFrameType == videoFrameTypeIDR) { | |
| 3685 | + pEncCtx->uiIdrPicId --; | |
| 3686 | + | |
| 3687 | + //set the next frame to be IDR | |
| 3688 | + ForceCodingIDR (pEncCtx); | |
| 3689 | + } else { // B pictures are not supported now, any else? | |
| 3690 | + assert (0); | |
| 3691 | + } | |
| 3692 | + | |
| 3693 | + // no need to stack back RC info since the info is still useful for later RQ model calculation | |
| 3694 | + // no need to stack back MB slicing info for dynamic balancing, since the info is still refer-able | |
| 3695 | +} | |
| 3696 | + | |
| 3697 | +void ClearFrameBsInfo (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi) { | |
| 3698 | + pFbi->sLayerInfo[0].pBsBuf = pCtx->pFrameBs; | |
| 3699 | + pFbi->sLayerInfo[0].pNalLengthInByte = pCtx->pOut->pNalLen; | |
| 3700 | + | |
| 3701 | + for (int i = 0; i < pFbi->iLayerNum; i++) { | |
| 3702 | + pFbi->sLayerInfo[i].iNalCount = 0; | |
| 3703 | + } | |
| 3704 | + pFbi->iLayerNum = 0; | |
| 3705 | + pFbi->iFrameSizeInBytes = 0; | |
| 3706 | + pFbi->eFrameType = videoFrameTypeSkip; | |
| 3707 | +} | |
| 3708 | + | |
| 3658 | 3709 | /*! |
| 3659 | 3710 | * \brief core svc encoding process |
| 3660 | 3711 | * |
| @@ -4100,6 +4151,28 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 439 unmodified lines | ||
| 4100 | 4151 | } |
| 4101 | 4152 | } |
| 4102 | 4153 | |
| 4154 | + if (NULL != pCtx->pFuncList->pfRc.pfWelsRcPostFrameSkipping | |
| 4155 | + && pCtx->pFuncList->pfRc.pfWelsRcPostFrameSkipping (pCtx, iCurDid, pSrcPic->uiTimeStamp)) { | |
| 4156 | + | |
| 4157 | + StackBackEncoderStatus (pCtx, eFrameType); | |
| 4158 | + ClearFrameBsInfo (pCtx, pFbi); | |
| 4159 | + | |
| 4160 | + iFrameSize = 0; | |
| 4161 | + iLayerSize = 0; | |
| 4162 | + iLayerNum = 0; | |
| 4163 | + | |
| 4164 | + if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) { | |
| 4165 | + pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iSpatialNum); | |
| 4166 | + } | |
| 4167 | + | |
| 4168 | + WelsRcPostFrameSkippedUpdate(pCtx, iCurDid); | |
| 4169 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, | |
| 4170 | + "[Rc] Frame timestamp = %lld, skip one frame due to post skip, continual skipped %d frames", | |
| 4171 | + pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames); | |
| 4172 | + pCtx->iEncoderError = ENC_RETURN_SUCCESS; | |
| 4173 | + return ENC_RETURN_SUCCESS; | |
| 4174 | + } | |
| 4175 | + | |
| 4103 | 4176 | // deblocking filter |
| 4104 | 4177 | if ( |
| 4105 | 4178 | (!pCtx->pCurDqLayer->bDeblockingParallelFlag) && |