History

using independent encoder control logic for SAVC case

Karina committed 10 years ago

Commit 0f0d54e1 parent 7bfb96b13 files · +406 −314Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 13 files). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+184−127
@@ -1206,6 +1206,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 1205 unmodified lines
12061206 while (iDlayerIndex < iDlayerCount) {
12071207 SDqLayer* pDqLayer = NULL;
12081208 SSpatialLayerConfig* pDlayer = &pParam->sSpatialLayers[iDlayerIndex];
1209+ SSpatialLayerInternal* pParamInternal = &pParam->sDependencyLayers[iDlayerIndex];
12091210 const int32_t kiMbW = (pDlayer->iVideoWidth + 0x0f) >> 4;
12101211 const int32_t kiMbH = (pDlayer->iVideoHeight + 0x0f) >> 4;
12111212 int32_t iMaxSliceNum = 1;
@@ -1213,6 +1214,12 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 1 unmodified line
12131214 if (iMaxSliceNum < kiSliceNum)
12141215 iMaxSliceNum = kiSliceNum;
12151216
1217+ pParamInternal->iSkipFrameFlag = 0;
1218+ pParamInternal->iCodingIndex = 0;
1219+ pParamInternal->iFrameIndex = 0;
1220+ pParamInternal->iFrameNum = 0;
1221+ pParamInternal->iPOC = 0;
1222+ pParamInternal->bEncCurFrmAsIdrFlag = true; // make sure first frame is IDR
12161223 // pDq layers list
12171224 pDqLayer = (SDqLayer*)pMa->WelsMallocz (sizeof (SDqLayer), "pDqLayer");
12181225 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pDqLayer), FreeMemorySvc (ppCtx))
@@ -1900,7 +1907,6 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 681 unmodified lines
19001907 (pMa->WelsMallocz (iCountMaxMbNum * sizeof (int32_t), "pSadCostMb"));
19011908 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSadCostMb), FreeMemorySvc (ppCtx))
19021909
1903− (*ppCtx)->bEncCurFrmAsIdrFlag = true; // make sure first frame is IDR
19041910 (*ppCtx)->iGlobalQp = 26; // global qp in default
19051911
19061912 (*ppCtx)->pLtr = (SLTRState*)pMa->WelsMalloc (kiNumDependencyLayers * sizeof (SLTRState), "SLTRState");
@@ -2802,7 +2808,7 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 895 unmodified lines
28022808 SDqIdc* pDqIdc = &pCtx->pDqIdcMap[kiCurDid];
28032809 int32_t iIdx = 0;
28042810 int32_t iSliceCount = 0;
2805−
2811+ SSpatialLayerInternal* pParamInternal = &pParam->sDependencyLayers[kiCurDid];
28062812 if (NULL == pCurDq)
28072813 return;
28082814
@@ -2856,8 +2862,9 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 47 unmodified lines
28562862
28572863 pNalHdExt->uiDependencyId = kiCurDid;
28582864 pNalHdExt->bDiscardableFlag = (pCtx->bNeedPrefixNalFlag) ? (pNalHd->uiNalRefIdc == NRI_PRI_LOWEST) : false;
2859− pNalHdExt->bIdrFlag = (pCtx->iFrameNum == 0) && ((pCtx->eNalType == NAL_UNIT_CODED_SLICE_IDR)
2860− || (pCtx->eSliceType == I_SLICE));
2865+ pNalHdExt->bIdrFlag = (pParamInternal->iFrameNum == 0)
2866+ && ((pCtx->eNalType == NAL_UNIT_CODED_SLICE_IDR)
2867+ || (pCtx->eSliceType == I_SLICE));
28612868 pNalHdExt->uiTemporalId = pCtx->uiTemporalId;
28622869
28632870 // pEncPic pData
@@ -3398,9 +3405,16 @@ int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen, int32_t& iSize) { · 534 unmodified lines
33983405 int32_t ForceCodingIDR (sWelsEncCtx* pCtx) {
33993406 if (NULL == pCtx)
34003407 return 1;
3408+ for (int32_t iDid = 0; iDid < pCtx->pSvcParam->iSpatialLayerNum; iDid++) {
3409+ SSpatialLayerInternal* pParamInternal = &pCtx->pSvcParam->sDependencyLayers[iDid];
3410+ pParamInternal->iCodingIndex = 0;
3411+ pParamInternal->iSkipFrameFlag = 0;
3412+ pParamInternal->iFrameIndex = 0;
3413+ pParamInternal->iFrameNum = 0;
3414+ pParamInternal->iPOC = 0;
3415+ pParamInternal->bEncCurFrmAsIdrFlag = true;
3416+ }
34013417
3402− pCtx->bEncCurFrmAsIdrFlag = true;
3403− pCtx->iCodingIndex = 0;
34043418 pCtx->bCheckWindowStatusRefreshFlag = false;
34053419
34063420 WelsLog (&pCtx->sLogCtx, WELS_LOG_INFO, "ForceCodingIDR at InputFrameCount=%d\n",
@@ -3427,11 +3441,10 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 20 unmodified lines
34273441 pLayerBsInfo->uiQualityId = 0;
34283442 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
34293443 pLayerBsInfo->iNalCount = iCountNal;
3430− pLayerBsInfo->eFrameType = videoFrameTypeIDR;
3444+ pLayerBsInfo->eFrameType = videoFrameTypeInvalid;
34313445 //pCtx->eLastNalPriority = NRI_PRI_HIGHEST;
34323446 pFbi->iLayerNum = 1;
34333447 pFbi->eFrameType = videoFrameTypeInvalid;
3434−
34353448 WelsEmms();
34363449
34373450 return ENC_RETURN_SUCCESS;
@@ -3479,75 +3492,69 @@ int32_t WriteSsvcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum, · 41 unmodified lines
34793492 }
34803493
34813494 // writing parasets for simulcast avc
3482−int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
3495+int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t iIdx,
34833496 SLayerBSInfo*& pLayerBsInfo, int32_t& iLayerNum, int32_t& iFrameSize) {
34843497 int32_t iNonVclSize = 0, iCountNal = 0, iReturn = ENC_RETURN_SUCCESS;
34853498
34863499 // write SPS
34873500 iNonVclSize = 0;
34883501
3489− assert ((kiSpatialNum == pCtx->iSpsNum) || (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy));
3502+ //writing one NAL
3503+ int32_t iNalSize = 0;
3504+ iCountNal = 0;
34903505
3491− for (int32_t iIdx = 0; iIdx < pCtx->iSpsNum; iIdx++) {
3492− //writing one NAL
3493− int32_t iNalSize = 0;
3494− iCountNal = 0;
3495−
3496− iReturn = WelsWriteOneSPS (pCtx, iIdx, iNalSize);
3497− WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
3506+ iReturn = WelsWriteOneSPS (pCtx, iIdx, iNalSize);
3507+ WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
34983508
3499− pLayerBsInfo->pNalLengthInByte[iCountNal] = iNalSize;
3500− iNonVclSize += iNalSize;
3501− iCountNal = 1;
3502− //finish writing one NAL
3509+ pLayerBsInfo->pNalLengthInByte[iCountNal] = iNalSize;
3510+ iNonVclSize += iNalSize;
3511+ iCountNal = 1;
35033512
3504− pLayerBsInfo->uiSpatialId = iIdx;
3505− pLayerBsInfo->uiTemporalId = 0;
3506− pLayerBsInfo->uiQualityId = 0;
3507− pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
3508− pLayerBsInfo->iNalCount = iCountNal;
3509− pLayerBsInfo->eFrameType = videoFrameTypeIDR;
3510− //point to next pLayerBsInfo
3511− ++ pLayerBsInfo;
3512− ++ pCtx->pOut->iLayerBsIndex;
3513− pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3514− pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
3515− //update for external countings
3516− ++ iLayerNum;
3513+ //finish writing one NAL
35173514
3518− }
3515+ pLayerBsInfo->uiSpatialId = iIdx;
3516+ pLayerBsInfo->uiTemporalId = 0;
3517+ pLayerBsInfo->uiQualityId = 0;
3518+ pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
3519+ pLayerBsInfo->iNalCount = iCountNal;
3520+ pLayerBsInfo->eFrameType = videoFrameTypeIDR;
3521+ //point to next pLayerBsInfo
3522+ ++ pLayerBsInfo;
3523+ ++ pCtx->pOut->iLayerBsIndex;
3524+ pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3525+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
3526+ //update for external countings
3527+ ++ iLayerNum;
35193528
35203529 // write PPS
35213530
35223531 //TODO: under new strategy, will PPS be correctly updated?
35233532
3524− for (int32_t iIdx = 0; iIdx < pCtx->iPpsNum; iIdx++) {
3525− //writing one NAL
3526− int32_t iNalSize = 0;
3527− iCountNal = 0;
3533+ //writing one NAL
3534+ iNalSize = 0;
3535+ iCountNal = 0;
35283536
3529− iReturn = WelsWriteOnePPS (pCtx, iIdx, iNalSize);
3530− WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
3537+ iReturn = WelsWriteOnePPS (pCtx, iIdx, iNalSize);
3538+ WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
35313539
3532− pLayerBsInfo->pNalLengthInByte[iCountNal] = iNalSize;
3533− iNonVclSize += iNalSize;
3534− iCountNal = 1;
3535− //finish writing one NAL
3540+ pLayerBsInfo->pNalLengthInByte[iCountNal] = iNalSize;
3541+ iNonVclSize += iNalSize;
3542+ iCountNal = 1;
3543+ //finish writing one NAL
35363544
3537− pLayerBsInfo->uiSpatialId = iIdx;
3538− pLayerBsInfo->uiTemporalId = 0;
3539− pLayerBsInfo->uiQualityId = 0;
3540− pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
3541− pLayerBsInfo->iNalCount = iCountNal;
3542− pLayerBsInfo->eFrameType = videoFrameTypeIDR;
3543− //point to next pLayerBsInfo
3544− ++ pLayerBsInfo;
3545− ++ pCtx->pOut->iLayerBsIndex;
3546− pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3547− pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
3548− //update for external countings
3549− ++ iLayerNum;
3550− }
3545+ pLayerBsInfo->uiSpatialId = iIdx;
3546+ pLayerBsInfo->uiTemporalId = 0;
3547+ pLayerBsInfo->uiQualityId = 0;
3548+ pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
3549+ pLayerBsInfo->iNalCount = iCountNal;
3550+ pLayerBsInfo->eFrameType = videoFrameTypeIDR;
3551+ //point to next pLayerBsInfo
3552+ ++ pLayerBsInfo;
3553+ ++ pCtx->pOut->iLayerBsIndex;
3554+ pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3555+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
3556+ //update for external countings
3557+ ++ iLayerNum;
35513558
35523559 // to check number of layers / nals / slices dependencies
35533560 if (iLayerNum > MAX_LAYER_NUM_OF_FRAME) {
@@ -3645,6 +3652,7 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum, · 91 unmodified lines
36453652
36463653 void StackBackEncoderStatus (sWelsEncCtx* pEncCtx,
36473654 EVideoFrameType keFrameType) {
3655+ SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
36483656 // for bitstream writing
36493657 pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
36503658 pEncCtx->pOut->iNalIndex = 0; // reset NAL index
@@ -3652,14 +3660,15 @@ void StackBackEncoderStatus (sWelsEncCtx* pEncCtx, · 1 unmodified line
36523660
36533661 InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize);
36543662 if ((keFrameType == videoFrameTypeP) || (keFrameType == videoFrameTypeI)) {
3655− pEncCtx->iFrameIndex --;
3656− if (pEncCtx->iPOC != 0) {
3657− pEncCtx->iPOC -= 2;
3663+ pParamInternal->iFrameIndex --;
3664+ if (pParamInternal->iPOC != 0) {
3665+ pParamInternal->iPOC -= 2;
36583666 } else {
3659− pEncCtx->iPOC = (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2;
3667+ pParamInternal->iPOC = (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2;
36603668 }
36613669
3662− LoadBackFrameNum (pEncCtx);
3670+ LoadBackFrameNum (pEncCtx, pEncCtx->uiDependencyId);
3671+
36633672 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
36643673 pEncCtx->eSliceType = P_SLICE;
36653674 //pEncCtx->eNalPriority = pEncCtx->eLastNalPriority; //not need this since eNalPriority will be updated at the beginning of coding a frame
@@ -3682,10 +3691,10 @@ void ClearFrameBsInfo (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi) { · 16 unmodified lines
36823691
36833692 for (int i = 0; i < pFbi->iLayerNum; i++) {
36843693 pFbi->sLayerInfo[i].iNalCount = 0;
3694+ pFbi->sLayerInfo[i].eFrameType = videoFrameTypeSkip;
36853695 }
36863696 pFbi->iLayerNum = 0;
36873697 pFbi->iFrameSizeInBytes = 0;
3688− pFbi->eFrameType = videoFrameTypeSkip;
36893698 }
36903699
36913700 /*!
@@ -3725,6 +3734,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 33 unmodified lines
37253734 int8_t iCurTid = 0;
37263735 bool bAvcBased = false;
37273736 SLogContext* pLogCtx = & (pCtx->sLogCtx);
3737+ bool bFinishedWriteHeader = false;
37283738 #if defined(ENABLE_PSNR_CALC)
37293739 float fSnrY = .0f, fSnrU = .0f, fSnrV = .0f;
37303740 #endif//ENABLE_PSNR_CALC
@@ -3732,7 +3742,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line
37323742 #if defined(_DEBUG)
37333743 int32_t i = 0, j = 0, k = 0;
37343744 #endif//_DEBUG
3735−
37363745 pCtx->iEncoderError = ENC_RETURN_SUCCESS;
37373746 pCtx->bCurFrameMarkedAsSceneLtr = false;
37383747 pFbi->iLayerNum = 0; // for initialization
@@ -3746,76 +3755,116 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 7 unmodified lines
37463755 pCtx->pFuncList->pfRc.pfWelsUpdateMaxBrWindowStatus (pCtx, iSpatialNum, pSrcPic->uiTimeStamp);
37473756 }
37483757
3749− if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
3750− ++ pCtx->iCodingIndex;
3758+ if (iSpatialNum < 1) {
3759+ // ++ pCtx->iCodingIndex;
3760+ pLayerBsInfo->eFrameType = videoFrameTypeSkip;
37513761 pFbi->eFrameType = videoFrameTypeSkip;
37523762 WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
37533763 "[Rc] Frame timestamp = %lld, skip one frame due to preprocessing return (temporal layer settings or else), continual skipped %d frames",
37543764 pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
37553765 return ENC_RETURN_SUCCESS;
37563766 }
3757−
3758− eFrameType = DecideFrameType (pCtx, iSpatialNum);
3759− if (eFrameType == videoFrameTypeSkip) {
3760− if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip)
3761− pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iSpatialNum);
3762− pFbi->eFrameType = eFrameType;
3763− WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
3764− "[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames",
3765− pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
3766− return ENC_RETURN_SUCCESS;
3767− }
3768−
3769− //loop each layer to check if have skip frame when RC and frame skip enable
3770− if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
3771− bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType,
3772− (uint32_t)pSrcPic->uiTimeStamp);
3773− if (bSkip) {
3774− pFbi->eFrameType = videoFrameTypeSkip;
3775− WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
3776− "[Rc] Frame timestamp = %lld, skip one frame due to max_br, continual skipped %d frames",
3777− pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
3778− return ENC_RETURN_SUCCESS;
3767+ if (!pSvcParam->bSimulcastAVC) {
3768+ pCtx->iSkipFrameFlag = false;
3769+ for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) {
3770+ if (pCtx->pSvcParam->sDependencyLayers[iDid].iSkipFrameFlag)
3771+ pCtx->iSkipFrameFlag = 1;
37793772 }
37803773 }
37813774
3782− pCtx->iContinualSkipFrames = 0;
3783− InitFrameCoding (pCtx, eFrameType);
3784−
3785− iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[pSpatialIndexMap->iDid], pCtx->iCodingIndex,
3786− pSvcParam->uiGopSize);
3787− pCtx->uiTemporalId = iCurTid;
3788−
3775+ InitBitStream (pCtx);
37893776 pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
37903777 pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
37913778
3792− if (eFrameType == videoFrameTypeIDR) {
3793− ++ pCtx->uiIdrPicId;
3794− // write parameter sets bitstream or SEI/SSEI (if any) here
3795− // TODO: use function pointer instead
3796− if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) {
3797− pCtx->iEncoderError = ((!pSvcParam->bSimulcastAVC)
3798− ? (WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize))
3799− : (WriteSavcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize)));
3800− } else {
3801− pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize);
3802− }
3803− WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3804− }
3805−
38063779 pCtx->pCurDqLayer = pCtx->ppDqLayerList[pSpatialIndexMap->iDid];
38073780 pCtx->pCurDqLayer->pRefLayer = NULL;
38083781
38093782 while (iSpatialIdx < iSpatialNum) {
3810− const int32_t iDidIdx = (pSpatialIndexMap + iSpatialIdx)->iDid; // get iDid
3783+ bool bEncoding = pCtx->pVpp->BuildSpatialLayer (pCtx, pSrcPic, iSpatialIdx);
3784+ if (!bEncoding) {
3785+ ++iSpatialIdx;
3786+ continue;
3787+ }
3788+ const int32_t iDidIdx = (pSpatialIndexMap + iSpatialIdx)->iDid;
38113789 SSpatialLayerConfig* pParam = &pSvcParam->sSpatialLayers[iDidIdx];
3790+ SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iDidIdx];
38123791 int32_t iDecompositionStages = pSvcParam->sDependencyLayers[iDidIdx].iDecompositionStages;
3792+ pCtx->pCurDqLayer = pCtx->ppDqLayerList[iDidIdx];
38133793 pCtx->uiDependencyId = iCurDid = (int8_t)iDidIdx;
3794+
3795+ eFrameType = DecideFrameType (pCtx, iSpatialNum, iDidIdx);
3796+ if (eFrameType == videoFrameTypeSkip) {
3797+ eFrameType = videoFrameTypeSkip;
3798+ pLayerBsInfo->eFrameType = eFrameType;
3799+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
3800+ "[Rc] Frame timestamp = %lld, skip one frame due to target_br, continual skipped %d frames",
3801+ pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
3802+ ++ iSpatialIdx;
3803+ if (pSvcParam->bSimulcastAVC) {
3804+ if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip)
3805+ pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, iDidIdx);
3806+ continue;
3807+ }
3808+
3809+ else {
3810+ if (pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip) {
3811+ for (int32_t i = 0; i < iSpatialNum; i++) {
3812+ pCtx->pSvcParam->sDependencyLayers[i].iSkipFrameFlag = false;
3813+ pCtx->pFuncList->pfRc.pfWelsUpdateBufferWhenSkip (pCtx, (pSpatialIndexMap + i)->iDid);
3814+ }
3815+ }
3816+ return ENC_RETURN_SUCCESS;
3817+ }
3818+ }
3819+ //loop each layer to check if have skip frame when RC and frame skip enable
3820+ if (pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr) {
3821+ bool bSkip = pCtx->pFuncList->pfRc.pfWelsCheckSkipBasedMaxbr (pCtx, iSpatialNum, eFrameType,
3822+ (uint32_t)pSrcPic->uiTimeStamp);
3823+ if (bSkip) {
3824+ eFrameType = videoFrameTypeSkip;
3825+ pLayerBsInfo->eFrameType = videoFrameTypeSkip;
3826+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
3827+ "[Rc] Frame timestamp = %lld, skip one frame due to max_br, continual skipped %d frames",
3828+ pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
3829+ ++ iSpatialIdx;
3830+ if (pSvcParam->bSimulcastAVC)
3831+ continue;
3832+ else
3833+ return ENC_RETURN_SUCCESS;
3834+ }
3835+ }
3836+ pCtx->iContinualSkipFrames = 0;
3837+
3838+ InitFrameCoding (pCtx, eFrameType, iDidIdx);
3839+ iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iSpatialIdx], pParamInternal->iCodingIndex,
3840+ pSvcParam->uiGopSize);
3841+ pCtx->uiTemporalId = iCurTid;
3842+
3843+ if (eFrameType == videoFrameTypeIDR) {
3844+ // write parameter sets bitstream or SEI/SSEI (if any) here
3845+ // TODO: use function pointer instead
3846+ if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) {
3847+ if (pSvcParam->bSimulcastAVC) {
3848+ pCtx->iEncoderError = WriteSavcParaset (pCtx, iCurDid, pLayerBsInfo, iLayerNum, iFrameSize);
3849+ ++ pCtx->uiIdrPicId;
3850+ } else if (!bFinishedWriteHeader) {
3851+ pCtx->iEncoderError = WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize);
3852+ ++ pCtx->uiIdrPicId;
3853+ bFinishedWriteHeader = true;
3854+ }
3855+ } else if (!bFinishedWriteHeader) {
3856+ pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize);
3857+ bFinishedWriteHeader = true;
3858+ ++ pCtx->uiIdrPicId;
3859+ }
3860+ WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3861+ }
3862+
38143863 pCtx->pVpp->AnalyzeSpatialPic (pCtx, iDidIdx);
38153864
38163865 pCtx->pEncPic = pEncPic = (pSpatialIndexMap + iSpatialIdx)->pSrc;
38173866 pCtx->pEncPic->iPictureType = pCtx->eSliceType;
3818− pCtx->pEncPic->iFramePoc = pCtx->iPOC;
3867+ pCtx->pEncPic->iFramePoc = pParamInternal->iPOC;
38193868
38203869 iCurWidth = pParam->iVideoWidth;
38213870 iCurHeight = pParam->iVideoHeight;
@@ -3880,12 +3929,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 58 unmodified lines
38803929 fsnr = pCtx->pDecPic;
38813930 #endif//#if defined(ENABLE_FRAME_DUMP) || defined(ENABLE_PSNR_CALC)
38823931 pCtx->pDecPic->iPictureType = pCtx->eSliceType;
3883− pCtx->pDecPic->iFramePoc = pCtx->iPOC;
3932+ pCtx->pDecPic->iFramePoc = pParamInternal->iPOC;
38843933
38853934 WelsInitCurrentLayer (pCtx, iCurWidth, iCurHeight);
38863935
38873936 pCtx->pFuncList->pMarkPic (pCtx);
3888− if (!pCtx->pFuncList->pBuildRefList (pCtx, pCtx->iPOC, 0)) {
3937+ if (!pCtx->pFuncList->pBuildRefList (pCtx, pParamInternal->iPOC, 0)) {
38893938 WelsLog (pLogCtx, WELS_LOG_WARNING,
38903939 "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!",
38913940 pCtx->iNumRef0);
@@ -3904,7 +3953,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 12 unmodified lines
39043953 pCtx->pVpp->AnalyzePictureComplexity (pCtx, pCtx->pEncPic, ((pCtx->eSliceType == P_SLICE)
39053954 && (pCtx->iNumRef0 > 0)) ? pCtx->pRefList0[0] : NULL,
39063955 iCurDid, (pCtx->eSliceType == P_SLICE) && pSvcParam->bEnableBackgroundDetection);
3907− WelsUpdateRefSyntax (pCtx, pCtx->iPOC,
3956+ WelsUpdateRefSyntax (pCtx, pParamInternal->iPOC,
39083957 eFrameType); //get reordering syntax used for writing slice header and transmit to encoder.
39093958 PrefetchReferencePicture (pCtx, eFrameType); // update reference picture for current pDq layer
39103959
@@ -4033,6 +4082,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 122 unmodified lines
40334082 pLbi->uiQualityId = 0;
40344083 pLbi->iNalCount = 0;
40354084 pLbi->eFrameType = eFrameType;
4085+
40364086 int32_t iIdx = 0;
40374087 while (iIdx < kiPartitionCnt) {
40384088 pCtx->pSliceThreading->pThreadPEncCtx[iIdx].pFrameBsInfo = pFbi;
@@ -4252,7 +4302,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 213 unmodified lines
42524302 ++ iLayerNum;
42534303 ++ pLayerBsInfo;
42544304 ++ pCtx->pOut->iLayerBsIndex;
4255−
4305+ WelsLog (pLogCtx, WELS_LOG_DEBUG,
4306+ "WelsEncoderEncodeExt() test iLayerNum = %d,iCountNal = %d,iLayerSize = %d", iLayerNum, iCountNal, iLayerSize);
42564307 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
42574308 pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
42584309
@@ -4321,6 +4372,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 62 unmodified lines
43214372 && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) {
43224373 pCtx->bRefOfCurTidIsLtr[iDidIdx][iCurTid] = true;
43234374 }
4375+ ++ pParamInternal->iCodingIndex;
43244376 }//end of (iSpatialIdx/iSpatialNum)
43254377
43264378 if (ENC_RETURN_CORRECTED == pCtx->iEncoderError) {
@@ -4361,7 +4413,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 34 unmodified lines
43614413 return 1;
43624414 }
43634415
4364− ++ pCtx->iCodingIndex;
4416+
43654417 pFbi->iLayerNum = iLayerNum;
43664418 pFbi->iSubSeqId = GetSubSequenceId (pCtx, eFrameType);
43674419
@@ -4370,13 +4422,19 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
43704422 pFbi->iSubSeqId, iFrameSize);
43714423 for (int32_t i = 0; i < iLayerNum; i++)
43724424 WelsLog (pLogCtx, WELS_LOG_DEBUG,
4373− "WelsEncoderEncodeExt() OutputInfo iLayerId = %d,iNalType = %d,iNalCount = %d, first Nal Length=%d", i,
4374− pFbi->sLayerInfo[i].uiLayerType, pFbi->sLayerInfo[i].iNalCount, pFbi->sLayerInfo[i].pNalLengthInByte[0]);
4425+ "WelsEncoderEncodeExt() OutputInfo iLayerId = %d,iNalType = %d,iNalCount = %d, first Nal Length=%d,uiSpatialId = %d", i,
4426+ pFbi->sLayerInfo[i].uiLayerType, pFbi->sLayerInfo[i].iNalCount, pFbi->sLayerInfo[i].pNalLengthInByte[0],
4427+ pFbi->sLayerInfo[i].uiSpatialId);
43754428 WelsEmms();
43764429
4377− pFbi->eFrameType = eFrameType;
4430+ pLayerBsInfo->eFrameType = eFrameType;
43784431 pFbi->iFrameSizeInBytes = iFrameSize;
4379−
4432+ pFbi->eFrameType = eFrameType;
4433+ for (int32_t k = 0; k < pFbi->iLayerNum; k++) {
4434+ if (pFbi->eFrameType != pFbi->sLayerInfo[k].eFrameType) {
4435+ pFbi->eFrameType = videoFrameTypeIPMixed;
4436+ }
4437+ }
43804438 #ifdef _DEBUG
43814439 if (pFbi->iLayerNum > MAX_LAYER_NUM_OF_FRAME) {
43824440 WelsLog (& pCtx->sLogCtx, WELS_LOG_ERROR, "WelsEncoderEncodeExt(), iLayerNum(%d) > MAX_LAYER_NUM_OF_FRAME(%d)!",
@@ -4402,7 +4460,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 19 unmodified lines
44024460 return ENC_RETURN_UNEXPECTED;
44034461 }
44044462 #endif
4405−
4463+ WelsLog (& pCtx->sLogCtx, WELS_LOG_INFO, "return ENC_RETURN_SUCCESS");
44064464 return ENC_RETURN_SUCCESS;
44074465 }
44084466
@@ -4565,9 +4623,8 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 156 unmodified lines
45654623 // reset the scaled spatial picture size
45664624 (*ppCtx)->pVpp->WelsPreprocessReset (*ppCtx);
45674625 //if WelsInitEncoderExt succeed
4568−
45694626 //for LTR
4570− (*ppCtx)->uiIdrPicId = uiTmpIdrPicId;
4627+ (*ppCtx)->uiIdrPicId = uiTmpIdrPicId ;//this is for LTR!; //this is for LTR!
45714628
45724629 //for sEncoderStatistics
45734630 memcpy ((*ppCtx)->sEncoderStatistics, sTempEncoderStatistics, sizeof (sTempEncoderStatistics));
@@ -4601,7 +4658,8 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 27 unmodified lines
46014658 pOldParam->uiGopSize = pNewParam->uiGopSize;
46024659 if (pOldParam->iTemporalLayerNum != pNewParam->iTemporalLayerNum) {
46034660 pOldParam->iTemporalLayerNum = pNewParam->iTemporalLayerNum;
4604− (*ppCtx)->iCodingIndex = 0;
4661+ for (int32_t iIndexD = 0; iIndexD < MAX_DEPENDENCY_LAYER; iIndexD++)
4662+ pOldParam->sDependencyLayers[iIndexD].iCodingIndex = 0;
46054663 }
46064664 pOldParam->iDecompStages = pNewParam->iDecompStages;
46074665 /* denoise control */
@@ -4663,7 +4721,6 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 55 unmodified lines
46634721
46644722 memcpy (pOldDlpInternal->uiCodingIdx2TemporalId, pNewDlpInternal->uiCodingIdx2TemporalId,
46654723 sizeof (pOldDlpInternal->uiCodingIdx2TemporalId)); // confirmed_safe_unsafe_usage
4666−
46674724 ++ iIndexD;
46684725 } while (iIndexD < pOldParam->iSpatialLayerNum);
46694726 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t