From 82cc0535ae2735804fdbeae75c4a98c13d2808f7 Mon Sep 17 00:00:00 2001 From: Sijia Chen Date: Wed, 30 Sep 2015 17:26:50 -0700 Subject: [PATCH] Add fix for simulcast if frame rate in the middle spatial layer is smaller --- codec/encoder/core/src/encoder_ext.cpp | 15 +++++++------ test/api/encode_decode_api_test.cpp | 29 ++++++++++++++------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/codec/encoder/core/src/encoder_ext.cpp b/codec/encoder/core/src/encoder_ext.cpp index a617e4e0..4065d6e3 100644 --- a/codec/encoder/core/src/encoder_ext.cpp +++ b/codec/encoder/core/src/encoder_ext.cpp @@ -3114,11 +3114,8 @@ void PreprocessSliceCoding (sWelsEncCtx* pCtx) { * \brief swap pDq layers between current pDq layer and reference pDq layer */ -static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx) { +static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqIdx) { // swap and assign reference - const int32_t kiDid = pCtx->uiDependencyId; - const int32_t kiNextDqIdx = 1 + kiDid; - SDqLayer* pTmpLayer = pCtx->ppDqLayerList[kiNextDqIdx]; SDqLayer* pRefLayer = pCtx->pCurDqLayer; pCtx->pCurDqLayer = pTmpLayer; @@ -4384,7 +4381,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour ++ iSpatialIdx; if (iCurDid + 1 < pSvcParam->iSpatialLayerNum) { - WelsSwapDqLayers (pCtx); + //for next layer, note that iSpatialIdx has been ++ so it is pointer to next layer + WelsSwapDqLayers (pCtx, (pSpatialIndexMap + iSpatialIdx)->iDid); } if (pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, iDidIdx) != 0) { @@ -4400,7 +4398,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) { pCtx->bRefOfCurTidIsLtr[iDidIdx][iCurTid] = true; } - } + }//end of (iSpatialIdx/iSpatialNum) if (ENC_RETURN_CORRECTED == pCtx->iEncoderError) { pCtx->pVpp->UpdateSpatialPictures (pCtx, pSvcParam, iCurTid, (pSpatialIndexMap + iSpatialIdx)->iDid); @@ -4448,8 +4446,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour iLayerNum, pFbi->iSubSeqId, iFrameSize); for (int32_t i = 0; i < iLayerNum; i++) - WelsLog (pLogCtx, WELS_LOG_DEBUG, "WelsEncoderEncodeExt() OutputInfo iLayerId = %d,iNalType = %d,iNalCount = %d", i, - pFbi->sLayerInfo[i].uiLayerType, pFbi->sLayerInfo[i].iNalCount); + WelsLog (pLogCtx, WELS_LOG_DEBUG, + "WelsEncoderEncodeExt() OutputInfo iLayerId = %d,iNalType = %d,iNalCount = %d, first Nal Length=%d", i, + pFbi->sLayerInfo[i].uiLayerType, pFbi->sLayerInfo[i].iNalCount, pFbi->sLayerInfo[i].pNalLengthInByte[0]); WelsEmms(); pFbi->eFrameType = eFrameType; diff --git a/test/api/encode_decode_api_test.cpp b/test/api/encode_decode_api_test.cpp index 6cadc1dd..6cb1c5c1 100644 --- a/test/api/encode_decode_api_test.cpp +++ b/test/api/encode_decode_api_test.cpp @@ -3596,7 +3596,7 @@ TEST_P (EncodeTestAPI, SetEncOptionSize) { TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { -//#define DEBUG_FILE_SAVE3 +//#define DEBUG_FILE_SAVE_SimulcastAVCDiffFps int iSpatialLayerNum = WelsClip3 ((rand() % MAX_SPATIAL_LAYER_NUM), 2, MAX_SPATIAL_LAYER_NUM); int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH); int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT); @@ -3608,10 +3608,7 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { //set flag of bSimulcastAVC param_.bSimulcastAVC = true; - param_.iTemporalLayerNum = 3; - - int rv = encoder_->InitializeExt (¶m_); - ASSERT_TRUE (rv == cmResultSuccess); + param_.iTemporalLayerNum = (rand() % 2) ? 3 : 4; unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM]; int aLen[MAX_SPATIAL_LAYER_NUM] = {0}; @@ -3648,10 +3645,10 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { ASSERT_EQ (0, rv); } -#define PATTERN_NUM (16) +#define PATTERN_NUM (18) const int32_t iTemporalPattern[PATTERN_NUM][MAX_SPATIAL_LAYER_NUM] = { {2, 1, 1, 1}, {2, 2, 2, 1}, {4, 1, 1, 1}, {4, 2, 1, 1}, - {1, 2, 1, 1}, {1, 1, 2, 1}, {1, 4, 1, 1}, {2, 4, 2, 1}, {1, 4, 2, 1}, - {1, 2, 2, 1}, {1, 2, 4, 1}, + {1, 2, 1, 1}, {1, 1, 2, 1}, {1, 4, 1, 1}, {2, 4, 2, 1}, {1, 4, 2, 1}, {1, 4, 4, 1}, + {1, 2, 2, 1}, {2, 1, 2, 1}, {1, 2, 4, 1}, {1, 1, 1, 2}, {1, 2, 2, 2}, {1, 2, 2, 4}, {1, 2, 4, 2}, {1, 4, 4, 4}, }; for (int iPatternIdx = 0; iPatternIdx < PATTERN_NUM; iPatternIdx++) { @@ -3659,7 +3656,11 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { param_.sSpatialLayers[i].fFrameRate = (fFrameRate / iTemporalPattern[iPatternIdx][i]); } + int rv = encoder_->InitializeExt (¶m_); + ASSERT_TRUE (rv == cmResultSuccess); + iEncFrameNum = 10; + int iInsertIdr = rand() % iEncFrameNum; for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { int iResult; int iLayerLen = 0; @@ -3668,7 +3669,11 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { InitialEncDec (param_.iPicWidth, param_.iPicHeight); EncodeOneFrame (0); - // init + if (iInsertIdr == iFrame) { + encoder_->ForceIntraFrame (true); + } + + // init aLen for the current frame for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { aLen[iIdx] = 0; } @@ -3700,7 +3705,7 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx; iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); - EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx; + EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx << iPatternIdx; EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx; } } @@ -3716,12 +3721,10 @@ TEST_F (EncodeDecodeTestAPI, SimulcastAVCDiffFps) { } } #ifdef DEBUG_FILE_SAVE_SimulcastAVCDiffFps - for (int i = 0; i <)MAX_SPATIAL_LAYER_NUM; - i++) { + for (int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++) { fclose (fEnc[i]); } #endif } -