History

Merge pull request #1802 from sijchen/savc50

[Encoder] fix for in-middle changing simulcast avc setting

ruil2 committed 11 years ago

Commit 296ab4d2 parents 7d055ca bc1b28b4 files · +100 −70Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+58−56
@@ -141,7 +141,7 @@ void CheckLevelSetting (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32 · 140 unmodified lines
141141 SSpatialLayerConfig* pLayerInfo = &pParam->sSpatialLayers[iLayer];
142142 pLayerInfo->uiLevelIdc = uiLevelIdc;
143143 if (uiLevelIdc > LEVEL_5_2) {
144− WelsLog (pLogCtx, WELS_LOG_INFO, "change unexpected levelidc(%d) setting to LEVEL_UNKNOWN", pLayerInfo->uiLevelIdc );
144+ WelsLog (pLogCtx, WELS_LOG_INFO, "change unexpected levelidc(%d) setting to LEVEL_UNKNOWN", pLayerInfo->uiLevelIdc);
145145 pLayerInfo->uiLevelIdc = LEVEL_UNKNOWN;
146146 }
147147 }
@@ -337,12 +337,14 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa · 189 unmodified lines
337337 // eSpsPpsIdStrategy checkings
338338 if (pCodingParam->iSpatialLayerNum > 1 && (SPS_LISTING & pCodingParam->eSpsPpsIdStrategy)) {
339339 WelsLog (pLogCtx, WELS_LOG_WARNING,
340− "ParamValidationExt(), eSpsPpsIdStrategy setting (%d) with multiple SpatialLayers (%d) not supported! eSpsPpsIdStrategy adjusted to CONSTANT_ID", pCodingParam->eSpsPpsIdStrategy, pCodingParam->iSpatialLayerNum);
340+ "ParamValidationExt(), eSpsPpsIdStrategy setting (%d) with multiple SpatialLayers (%d) not supported! eSpsPpsIdStrategy adjusted to CONSTANT_ID",
341+ pCodingParam->eSpsPpsIdStrategy, pCodingParam->iSpatialLayerNum);
341342 pCodingParam->eSpsPpsIdStrategy = CONSTANT_ID;
342343 }
343344 if (pCodingParam->iUsageType == SCREEN_CONTENT_REAL_TIME && (SPS_LISTING & pCodingParam->eSpsPpsIdStrategy)) {
344345 WelsLog (pLogCtx, WELS_LOG_WARNING,
345− "ParamValidationExt(), eSpsPpsIdStrategy setting (%d) with iUsageType (%d) not supported! eSpsPpsIdStrategy adjusted to CONSTANT_ID", pCodingParam->eSpsPpsIdStrategy, pCodingParam->iUsageType);
346+ "ParamValidationExt(), eSpsPpsIdStrategy setting (%d) with iUsageType (%d) not supported! eSpsPpsIdStrategy adjusted to CONSTANT_ID",
347+ pCodingParam->eSpsPpsIdStrategy, pCodingParam->iUsageType);
346348 pCodingParam->eSpsPpsIdStrategy = CONSTANT_ID;
347349 }
348350
@@ -502,7 +504,8 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa · 153 unmodified lines
502504 iMbHeight = (kiPicHeight + 15) >> 4;
503505 iMaxSliceNum = MAX_SLICES_NUM;
504506 if (iMbHeight > iMaxSliceNum) {
505− WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX(%d)!", iMbHeight, MAX_SLICES_NUM);
507+ WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX(%d)!",
508+ iMbHeight, MAX_SLICES_NUM);
506509 return ENC_RETURN_UNSUPPORTED_PARA;
507510 }
508511 pSpatialLayer->sSliceCfg.sSliceArgument.uiSliceNum = iMbHeight;
@@ -698,9 +701,9 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 189 unmodified lines
698701 // count parasets
699702 iCountNumNals += 1 + iNumDependencyLayers + (iCountNumLayers << 1) +
700703 iCountNumLayers // plus iCountNumLayers for reserved application
701− + ((SPS_LISTING & pParam->eSpsPpsIdStrategy) ? MAX_SPS_COUNT : 0) //for Sps
702− + (((SPS_LISTING & pParam->eSpsPpsIdStrategy) && (iNumDependencyLayers > 1)) ? MAX_SPS_COUNT : 0) //for SubsetSps
703− + ((SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) ? MAX_PPS_COUNT : 0);
704+ + (*ppCtx)->GetNeededSpsNum()
705+ + (*ppCtx)->GetNeededSubsetSpsNum()
706+ + (*ppCtx)->GetNeededPpsNum();
704707
705708 // to check number of layers / nals / slices dependencies, 12/8/2010
706709 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
@@ -1026,7 +1029,6 @@ int32_t FindExistingPps (SWelsSPS* pSps, SSubsetSps* pSubsetSps, const bool kbUs · 319 unmodified lines
10261029 return INVALID_ID;
10271030 }
10281031
1029−
10301032 /*!
10311033 * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available
10321034 * \pParam pCtx sWelsEncCtx*
@@ -1195,54 +1197,41 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 162 unmodified lines
11951197 }
11961198
11971199 // for dynamically malloc for parameter sets memory instead of maximal items for standard to reduce size, 3/18/2010
1198− // SPS
1199− if (!pParam->bSimulcastAVC) {
1200− if (! (SPS_LISTING & pParam->eSpsPpsIdStrategy)) {
1201− (*ppCtx)->pSpsArray = (SWelsSPS*)pMa->WelsMalloc (sizeof (SWelsSPS), "pSpsArray");
1202− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSpsArray), FreeMemorySvc (ppCtx))
1203− if (iDlayerCount > 1) {
1204− (*ppCtx)->pSubsetArray = (SSubsetSps*)pMa->WelsMalloc ((iDlayerCount - 1) * sizeof (SSubsetSps), "pSubsetArray");
1205− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSubsetArray), FreeMemorySvc (ppCtx))
1206− }
1207− } else {
1208− // pParam->eSpsPpsIdStrategy == SPS_LISTING_AND_PPS_INCREASING
1209− // new memory
1210− (*ppCtx)->pSpsArray = (SWelsSPS*)pMa->WelsMalloc (MAX_SPS_COUNT * sizeof (SWelsSPS), "pSpsArray");
1211− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSpsArray), FreeMemorySvc (ppCtx))
1212−
1213− (*ppCtx)->pSubsetArray = (SSubsetSps*)pMa->WelsMalloc (MAX_SPS_COUNT * sizeof (SSubsetSps), "pSubsetArray");
1214− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSubsetArray), FreeMemorySvc (ppCtx))
1215−
1216− // copy from existing if the pointer exists
1217− if (NULL != pExistingParasetList) {
1218− (*ppCtx)->sPSOVector.uiInUseSpsNum = pExistingParasetList->uiInUseSpsNum;
1219− (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = pExistingParasetList->uiInUseSubsetSpsNum;
1220− memcpy ((*ppCtx)->pSpsArray, pExistingParasetList->sSps, MAX_SPS_COUNT * sizeof (SWelsSPS));
1221− memcpy ((*ppCtx)->pSubsetArray, pExistingParasetList->sSubsetSps, MAX_SPS_COUNT * sizeof (SSubsetSps));
1222− }
1223− }
1200+ const int32_t kiNeededSpsNum = (*ppCtx)->GetNeededSpsNum();
1201+ const int32_t kiNeededSubsetSpsNum = (*ppCtx)->GetNeededSubsetSpsNum();
1202+ (*ppCtx)->pSpsArray = (SWelsSPS*)pMa->WelsMalloc (kiNeededSpsNum * sizeof (SWelsSPS), "pSpsArray");
1203+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSpsArray), FreeMemorySvc (ppCtx))
1204+ if (kiNeededSubsetSpsNum > 0) {
1205+ (*ppCtx)->pSubsetArray = (SSubsetSps*)pMa->WelsMalloc (kiNeededSubsetSpsNum * sizeof (SSubsetSps), "pSubsetArray");
1206+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSubsetArray), FreeMemorySvc (ppCtx))
12241207 } else {
1225− //bSimulcastAVC
1226− (*ppCtx)->pSpsArray = (SWelsSPS*)pMa->WelsMalloc (iDlayerCount * sizeof (SWelsSPS), "pSpsArray");
1227− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSpsArray), FreeMemorySvc (ppCtx))
12281208 (*ppCtx)->pSubsetArray = NULL;
12291209 }
1230− // PPS
1231− if (! (SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy)) {
1232− (*ppCtx)->pPPSArray = (SWelsPPS*)pMa->WelsMalloc (iDlayerCount * sizeof (SWelsPPS), "pPPSArray");
1233− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pPPSArray), FreeMemorySvc (ppCtx))
1234− } else {
1235− (*ppCtx)->pPPSArray = (SWelsPPS*)pMa->WelsMalloc (MAX_PPS_COUNT * sizeof (SWelsPPS), "pPPSArray");
1236− WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pPPSArray), FreeMemorySvc (ppCtx))
12371210
1211+ if ((SPS_LISTING & pParam->eSpsPpsIdStrategy) && (NULL != pExistingParasetList)) {
1212+ (*ppCtx)->sPSOVector.uiInUseSpsNum = pExistingParasetList->uiInUseSpsNum;
1213+ memcpy ((*ppCtx)->pSpsArray, pExistingParasetList->sSps, MAX_SPS_COUNT * sizeof (SWelsSPS));
12381214
1239− // copy from existing if the pointer exists
1240− if (NULL != pExistingParasetList) {
1241− (*ppCtx)->sPSOVector.uiInUsePpsNum = pExistingParasetList->uiInUsePpsNum;
1242− memcpy ((*ppCtx)->pPPSArray, pExistingParasetList->sPps, MAX_PPS_COUNT * sizeof (SWelsPPS));
1215+ if (kiNeededSubsetSpsNum > 0) {
1216+ (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = pExistingParasetList->uiInUseSubsetSpsNum;
1217+ memcpy ((*ppCtx)->pSubsetArray, pExistingParasetList->sSubsetSps, MAX_SPS_COUNT * sizeof (SSubsetSps));
1218+ } else {
1219+ (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = 0;
12431220 }
12441221 }
12451222
1223+ // PPS
1224+ const int32_t kiNeededPpsNum = (*ppCtx)->GetNeededPpsNum();
1225+ (*ppCtx)->pPPSArray = (SWelsPPS*)pMa->WelsMalloc (kiNeededPpsNum * sizeof (SWelsPPS), "pPPSArray");
1226+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pPPSArray), FreeMemorySvc (ppCtx))
1227+
1228+ // copy from existing if the pointer exists
1229+ if ((SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) && (NULL != pExistingParasetList)) {
1230+ (*ppCtx)->sPSOVector.uiInUsePpsNum = pExistingParasetList->uiInUsePpsNum;
1231+ memcpy ((*ppCtx)->pPPSArray, pExistingParasetList->sPps, MAX_PPS_COUNT * sizeof (SWelsPPS));
1232+ }
1233+
1234+
12461235 if (INCREASING_ID & pParam->eSpsPpsIdStrategy) {
12471236 (*ppCtx)->pPSOVector = & ((*ppCtx)->sPSOVector);
12481237 } else {
@@ -1728,8 +1717,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 479 unmodified lines
17281717 return 1;
17291718 }
17301719
1731− const int32_t kiSpsSize = (pParam->eSpsPpsIdStrategy & SPS_LISTING) ? (MAX_SPS_COUNT * SPS_BUFFER_SIZE): (pParam->iSpatialLayerNum * SPS_BUFFER_SIZE);
1732− const int32_t kiPpsSize = (pParam->eSpsPpsIdStrategy & SPS_PPS_LISTING) ? (MAX_PPS_COUNT * SPS_BUFFER_SIZE) : ((1 + pParam->iSpatialLayerNum) * PPS_BUFFER_SIZE);
1720+ const int32_t kiSpsSize = (*ppCtx)->GetNeededSpsNum() * SPS_BUFFER_SIZE;
1721+ const int32_t kiPpsSize = (*ppCtx)->GetNeededPpsNum() * PPS_BUFFER_SIZE;
17331722 iNonVclLayersBsSizeCount = SSEI_BUFFER_SIZE + kiSpsSize + kiPpsSize;
17341723
17351724 int32_t iLayerBsSize = 0;
@@ -3469,7 +3458,8 @@ int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum, · 1733 unmodified lines
34693458
34703459 // write SPS
34713460 iNonVclSize = 0;
3472− assert (kiSpatialNum == pCtx->iSpsNum);
3461+
3462+ assert ((kiSpatialNum == pCtx->iSpsNum) || (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy));
34733463
34743464 for (int32_t iIdx = 0; iIdx < pCtx->iSpsNum; iIdx++) {
34753465 //writing one NAL
@@ -4252,13 +4242,16 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 776 unmodified lines
42524242 pOldParam = (*ppCtx)->pSvcParam;
42534243
42544244 if (pOldParam->iUsageType != pNewParam->iUsageType) {
4255− WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR, "WelsEncoderParamAdjust(), does not expect in-middle change of iUsgaeType from %d to %d", pOldParam->iUsageType, pNewParam->iUsageType);
4245+ WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR,
4246+ "WelsEncoderParamAdjust(), does not expect in-middle change of iUsgaeType from %d to %d", pOldParam->iUsageType,
4247+ pNewParam->iUsageType);
42564248 return ENC_RETURN_UNSUPPORTED_PARA;
42574249 }
42584250
42594251 /* Decide whether need reset for IDR frame based on adjusting prarameters changed */
42604252 /* Temporal levels, spatial settings and/ or quality settings changed need update parameter sets related. */
42614253 bNeedReset = (pOldParam == NULL) ||
4254+ (pOldParam->bSimulcastAVC != pNewParam->bSimulcastAVC) ||
42624255 (pOldParam->iSpatialLayerNum != pNewParam->iSpatialLayerNum) ||
42634256 (pOldParam->iPicWidth != pNewParam->iPicWidth
42644257 || pOldParam->iPicHeight != pNewParam->iPicHeight) ||
@@ -4339,21 +4332,30 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 74 unmodified lines
43394332 && (SPS_LISTING & pNewParam->eSpsPpsIdStrategy)) {
43404333 pExistingParasetList = &sExistingParasetList;
43414334 sExistingParasetList.uiInUseSpsNum = (*ppCtx)->sPSOVector.uiInUseSpsNum;
4342− sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
43434335 memcpy (sExistingParasetList.sSps, (*ppCtx)->pSpsArray, MAX_SPS_COUNT * sizeof (SWelsSPS));
4344− memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
4336+ if (NULL != (*ppCtx)->pSubsetArray) {
4337+ sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
4338+ memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
4339+ } else {
4340+ sExistingParasetList.uiInUseSubsetSpsNum = 0;
4341+ }
43454342 }
43464343
43474344 if ((SPS_PPS_LISTING == iOldSpsPpsIdStrategy)
43484345 && (SPS_PPS_LISTING == pNewParam->eSpsPpsIdStrategy)) {
43494346 pExistingParasetList = &sExistingParasetList;
43504347 sExistingParasetList.uiInUseSpsNum = (*ppCtx)->sPSOVector.uiInUseSpsNum;
4351− sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
43524348 sExistingParasetList.uiInUsePpsNum = (*ppCtx)->sPSOVector.uiInUsePpsNum;
43534349 memcpy (sExistingParasetList.sSps, (*ppCtx)->pSpsArray, MAX_SPS_COUNT * sizeof (SWelsSPS));
4354− memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
43554350 memcpy (sExistingParasetList.sPps, (*ppCtx)->pPps, MAX_PPS_COUNT * sizeof (SWelsPPS));
43564351
4352+ if (NULL != (*ppCtx)->pSubsetArray) {
4353+ sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
4354+ memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
4355+ } else {
4356+ sExistingParasetList.uiInUseSubsetSpsNum = 0;
4357+ }
4358+
43574359 memcpy (iTmpPpsIdList, ((*ppCtx)->sPSOVector.iPpsIdList), MAX_DQ_LAYER_NUM * MAX_PPS_COUNT * sizeof (int32_t));
43584360 }
43594361 }

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