History

refine the workflow for encode one frame

Karina committed 10 years ago

Commit 7e144001 parent c423a803 files · +119 −95Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+108−85
@@ -3750,7 +3750,84 @@ void ClearFrameBsInfo (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi) { · 3749 unmodified lines
37503750 pFbi->iLayerNum = 0;
37513751 pFbi->iFrameSizeInBytes = 0;
37523752 }
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+ }
37533827
3828+
3829+ return eFrameType;
3830+}
37543831 /*!
37553832 * \brief core svc encoding process
37563833 *
@@ -3788,7 +3865,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 31 unmodified lines
37883865 int32_t iCurTid = 0;
37893866 bool bAvcBased = false;
37903867 SLogContext* pLogCtx = & (pCtx->sLogCtx);
3791− bool bFinishedWriteHeader = false;
37923868 #if defined(ENABLE_PSNR_CALC)
37933869 float fSnrY = .0f, fSnrU = .0f, fSnrV = .0f;
37943870 #endif//ENABLE_PSNR_CALC
@@ -3816,19 +3892,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 21 unmodified lines
38163892 SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iDidIdx];
38173893 pParamInternal->iCodingIndex ++;
38183894 }
3895+ pFbi->eFrameType = videoFrameTypeSkip;
38193896 pLayerBsInfo->eFrameType = videoFrameTypeSkip;
38203897 WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG,
38213898 "[Rc] Frame timestamp = %lld, skip one frame due to preprocessing return (temporal layer settings or else), continual skipped %d frames",
38223899 pSrcPic->uiTimeStamp, pCtx->iContinualSkipFrames);
38233900 return ENC_RETURN_SUCCESS;
38243901 }
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− }
38323902
38333903 InitBitStream (pCtx);
38343904 pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
@@ -3836,88 +3906,41 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line
38363906
38373907 pCtx->pCurDqLayer = pCtx->ppDqLayerList[pSpatialIndexMap->iDid];
38383908 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+ }
38393919
38403920 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;
38473927 //skip this spatial layer
38483928 if (GetTemporalLevel (pParamInternal, pParamInternal->iCodingIndex, pSvcParam->uiGopSize) == INVALID_TEMPORAL_ID) {
38493929 ++iSpatialIdx;
38503930 pParamInternal->iCodingIndex ++;
38513931 continue;
38523932 }
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) {
38833937 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;
39163940 }
3917− WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
39183941 }
3919−
3920− pCtx->pVpp->AnalyzeSpatialPic (pCtx, iDidIdx);
3942+ InitFrameCoding (pCtx, eFrameType, iCurDid);
3943+ pCtx->pVpp->AnalyzeSpatialPic (pCtx, iCurDid);
39213944
39223945 pCtx->pEncPic = pEncPic = (pSpatialIndexMap + iSpatialIdx)->pSrc;
39233946 pCtx->pEncPic->iPictureType = pCtx->eSliceType;
@@ -4237,8 +4260,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 313 unmodified lines
42374260 if (
42384261 (!pCtx->pCurDqLayer->bDeblockingParallelFlag) &&
42394262 #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)) &&
42424265 #endif//!ENABLE_FRAME_DUMP
42434266 true
42444267 ) {
@@ -4247,7 +4270,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
42474270
42484271 pCtx->pFuncList->pfRc.pfWelsRcPictureInfoUpdate (pCtx, iLayerSize);
42494272 RcTraceFrameBits (pCtx, pFbi->uiTimeStamp);
4250− pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc[iDidIdx].iAverageFrameQp;
4273+ pCtx->pDecPic->iFrameAverageQp = pCtx->pWelsSvcRc[iCurDid].iAverageFrameQp;
42514274
42524275 //update scc related
42534276 pCtx->pFuncList->pfUpdateFMESwitch (pCtx->pCurDqLayer);
@@ -4405,7 +4428,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 151 unmodified lines
44054428 #endif//#if defined(MT_DEBUG)
44064429 }
44074430
4408− pCtx->eLastNalPriority[iDidIdx] = eNalRefIdc;
4431+ pCtx->eLastNalPriority[iCurDid] = eNalRefIdc;
44094432 ++ iSpatialIdx;
44104433
44114434 if (iCurDid + 1 < pSvcParam->iSpatialLayerNum) {
@@ -4413,7 +4436,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line
44134436 WelsSwapDqLayers (pCtx, (pSpatialIndexMap + iSpatialIdx)->iDid);
44144437 }
44154438
4416− if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx) != 0) {
4439+ if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iCurDid) != 0) {
44174440 ForceCodingIDR (pCtx);
44184441 WelsLog (pLogCtx, WELS_LOG_WARNING,
44194442 "WelsEncoderEncodeExt(), Logic Error Found in Preprocess updating. ForceCodingIDR!");
@@ -4425,7 +4448,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 5 unmodified lines
44254448
44264449 if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag
44274450 && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) {
4428− pCtx->bRefOfCurTidIsLtr[iDidIdx][iCurTid] = true;
4451+ pCtx->bRefOfCurTidIsLtr[iCurDid][iCurTid] = true;
44294452 }
44304453 ++ pParamInternal->iCodingIndex;
44314454 }//end of (iSpatialIdx/iSpatialNum)

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