History

Refactoring: Wrap all the operations related to eSpsPpsIdStrategy to class, to improve code readability

sijchen committed 10 years ago

Commit ffb85041 parent c30cc4114 files · +1126 −494Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+56−405
@@ -767,12 +767,15 @@ static inline int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingPara · 766 unmodified lines
767767 ++ iDIndex;
768768 } while (iDIndex < iNumDependencyLayers);
769769
770+ if (NULL == (*ppCtx)->pFuncList || NULL == (*ppCtx)->pFuncList->pParametersetStrategy) {
771+ WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR,
772+ "AcquireLayersNals(), pFuncList and pParametersetStrategy needed to be initialized first!");
773+ return 1;
774+ }
770775 // count parasets
771776 iCountNumNals += 1 + iNumDependencyLayers + (iCountNumLayers << 1) +
772777 iCountNumLayers // plus iCountNumLayers for reserved application
773− + (*ppCtx)->GetNeededSpsNum()
774− + (*ppCtx)->GetNeededSubsetSpsNum()
775− + (*ppCtx)->GetNeededPpsNum();
778+ + (*ppCtx)->pFuncList->pParametersetStrategy->GetAllNeededParasetNum();
776779
777780 // to check number of layers / nals / slices dependencies, 12/8/2010
778781 if (iCountNumLayers > MAX_LAYER_NUM_OF_FRAME) {
@@ -956,152 +959,7 @@ void FreeRefList (SRefList*& pRefList, CMemoryAlign* pMa, const int iMaxNumRefF · 177 unmodified lines
956959 pRefList = NULL;
957960 }
958961
959−static int32_t WelsGenerateNewSps (sWelsEncCtx* pCtx, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
960− const int32_t iDlayerCount, const int32_t kiSpsId,
961− SWelsSPS*& pSps, SSubsetSps*& pSubsetSps, bool bSVCBaselayer) {
962− int32_t iRet = 0;
963−
964− if (!kbUseSubsetSps) {
965− pSps = & (pCtx->pSpsArray[kiSpsId]);
966− } else {
967− pSubsetSps = & (pCtx->pSubsetArray[kiSpsId]);
968− pSps = &pSubsetSps->pSps;
969− }
970−
971− SWelsSvcCodingParam* pParam = pCtx->pSvcParam;
972− SSpatialLayerConfig* pDlayerParam = &pParam->sSpatialLayers[iDlayerIndex];
973− // Need port pSps/pPps initialization due to spatial scalability changed
974− if (!kbUseSubsetSps) {
975− iRet = WelsInitSps (pSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
976− pParam->iMaxNumRefFrame,
977− kiSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE, iDlayerCount,
978− bSVCBaselayer);
979− } else {
980− iRet = WelsInitSubsetSps (pSubsetSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
981− pParam->iMaxNumRefFrame,
982− kiSpsId, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE, iDlayerCount);
983− }
984− return iRet;
985−}
986−
987−static bool CheckMatchedSps (SWelsSPS* const pSps1, SWelsSPS* const pSps2) {
988−
989− if ((pSps1->iMbWidth != pSps2->iMbWidth)
990− || (pSps1->iMbHeight != pSps2->iMbHeight)) {
991− return false;
992− }
993−
994− if ((pSps1->uiLog2MaxFrameNum != pSps2->uiLog2MaxFrameNum)
995− || (pSps1->iLog2MaxPocLsb != pSps2->iLog2MaxPocLsb)) {
996− return false;
997− }
998−
999− if (pSps1->iNumRefFrames != pSps2->iNumRefFrames) {
1000− return false;
1001− }
1002−
1003− if ((pSps1->bFrameCroppingFlag != pSps2->bFrameCroppingFlag)
1004− || (pSps1->sFrameCrop.iCropLeft != pSps2->sFrameCrop.iCropLeft)
1005− || (pSps1->sFrameCrop.iCropRight != pSps2->sFrameCrop.iCropRight)
1006− || (pSps1->sFrameCrop.iCropTop != pSps2->sFrameCrop.iCropTop)
1007− || (pSps1->sFrameCrop.iCropBottom != pSps2->sFrameCrop.iCropBottom)
1008− ) {
1009− return false;
1010− }
1011−
1012− if ((pSps1->uiProfileIdc != pSps2->uiProfileIdc)
1013− || (pSps1->bConstraintSet0Flag != pSps2->bConstraintSet0Flag)
1014− || (pSps1->bConstraintSet1Flag != pSps2->bConstraintSet1Flag)
1015− || (pSps1->bConstraintSet2Flag != pSps2->bConstraintSet2Flag)
1016− || (pSps1->bConstraintSet3Flag != pSps2->bConstraintSet3Flag)
1017− || (pSps1->iLevelIdc != pSps2->iLevelIdc)) {
1018− return false;
1019− }
1020−
1021− return true;
1022−}
1023962
1024−static bool CheckMatchedSubsetSps (SSubsetSps* const pSubsetSps1, SSubsetSps* const pSubsetSps2) {
1025− if (!CheckMatchedSps (&pSubsetSps1->pSps, &pSubsetSps2->pSps)) {
1026− return false;
1027− }
1028−
1029− if ((pSubsetSps1->sSpsSvcExt.iExtendedSpatialScalability != pSubsetSps2->sSpsSvcExt.iExtendedSpatialScalability)
1030− || (pSubsetSps1->sSpsSvcExt.bAdaptiveTcoeffLevelPredFlag != pSubsetSps2->sSpsSvcExt.bAdaptiveTcoeffLevelPredFlag)
1031− || (pSubsetSps1->sSpsSvcExt.bSeqTcoeffLevelPredFlag != pSubsetSps2->sSpsSvcExt.bSeqTcoeffLevelPredFlag)
1032− || (pSubsetSps1->sSpsSvcExt.bSliceHeaderRestrictionFlag != pSubsetSps2->sSpsSvcExt.bSliceHeaderRestrictionFlag)) {
1033− return false;
1034− }
1035−
1036− return true;
1037−}
1038−
1039−int32_t FindExistingSps (SWelsSvcCodingParam* pParam, const bool kbUseSubsetSps, const int32_t iDlayerIndex,
1040− const int32_t iDlayerCount, const int32_t iSpsNumInUse,
1041− SWelsSPS* pSpsArray,
1042− SSubsetSps* pSubsetArray, bool bSVCBaseLayer) {
1043− SSpatialLayerConfig* pDlayerParam = &pParam->sSpatialLayers[iDlayerIndex];
1044−
1045− assert (iSpsNumInUse <= MAX_SPS_COUNT);
1046− if (!kbUseSubsetSps) {
1047− SWelsSPS sTmpSps;
1048− WelsInitSps (&sTmpSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
1049− pParam->iMaxNumRefFrame,
1050− 0, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE, iDlayerCount,
1051− bSVCBaseLayer);
1052− for (int32_t iId = 0; iId < iSpsNumInUse; iId++) {
1053− if (CheckMatchedSps (&sTmpSps, &pSpsArray[iId])) {
1054− return iId;
1055− }
1056− }
1057− } else {
1058− SSubsetSps sTmpSubsetSps;
1059− WelsInitSubsetSps (&sTmpSubsetSps, pDlayerParam, &pParam->sDependencyLayers[iDlayerIndex], pParam->uiIntraPeriod,
1060− pParam->iMaxNumRefFrame,
1061− 0, pParam->bEnableFrameCroppingFlag, pParam->iRCMode != RC_OFF_MODE, iDlayerCount);
1062−
1063− for (int32_t iId = 0; iId < iSpsNumInUse; iId++) {
1064− if (CheckMatchedSubsetSps (&sTmpSubsetSps, &pSubsetArray[iId])) {
1065− return iId;
1066− }
1067− }
1068− }
1069−
1070− return INVALID_ID;
1071−}
1072−
1073−int32_t FindExistingPps (SWelsSPS* pSps, SSubsetSps* pSubsetSps, const bool kbUseSubsetSps, const int32_t iSpsId,
1074− const bool kbEntropyCodingFlag, const int32_t iPpsNumInUse,
1075− SWelsPPS* pPpsArray) {
1076−#if !defined(DISABLE_FMO_FEATURE)
1077− // feature not supported yet
1078− return INVALID_ID;
1079−#endif//!DISABLE_FMO_FEATURE
1080−
1081− SWelsPPS sTmpPps;
1082− WelsInitPps (&sTmpPps,
1083− pSps,
1084− pSubsetSps,
1085− 0,
1086− true,
1087− kbUseSubsetSps,
1088− kbEntropyCodingFlag);
1089−
1090− assert (iPpsNumInUse <= MAX_PPS_COUNT);
1091− for (int32_t iId = 0; iId < iPpsNumInUse; iId++) {
1092− if ((sTmpPps.iSpsId == pPpsArray[iId].iSpsId)
1093− && (sTmpPps.bEntropyCodingModeFlag == pPpsArray[iId].bEntropyCodingModeFlag)
1094− && (sTmpPps.iPicInitQp == pPpsArray[iId].iPicInitQp)
1095− && (sTmpPps.iPicInitQs == pPpsArray[iId].iPicInitQs)
1096− && (sTmpPps.uiChromaQpIndexOffset == pPpsArray[iId].uiChromaQpIndexOffset)
1097− && (sTmpPps.bDeblockingFilterControlPresentFlag == pPpsArray[iId].bDeblockingFilterControlPresentFlag)
1098− ) {
1099− return iId;
1100− }
1101− }
1102−
1103− return INVALID_ID;
1104−}
1105963
1106964 static inline int32_t InitSliceList (sWelsEncCtx** ppCtx,
1107965 SDqLayer* pDqLayer,
@@ -1248,7 +1106,7 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 140 unmodified lines
12481106 CMemoryAlign* pMa = NULL;
12491107 int32_t iDlayerCount = 0;
12501108 int32_t iDlayerIndex = 0;
1251− uint32_t iSpsId = 0;
1109+ int32_t iSpsId = 0;
12521110 uint32_t iPpsId = 0;
12531111 uint32_t iNumRef = 0;
12541112 int32_t iResult = 0;
@@ -1388,8 +1246,10 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 133 unmodified lines
13881246 }
13891247
13901248 // for dynamically malloc for parameter sets memory instead of maximal items for standard to reduce size, 3/18/2010
1391− const int32_t kiNeededSpsNum = (*ppCtx)->GetNeededSpsNum();
1392− const int32_t kiNeededSubsetSpsNum = (*ppCtx)->GetNeededSubsetSpsNum();
1249+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFuncList), FreeMemorySvc (ppCtx))
1250+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFuncList->pParametersetStrategy), FreeMemorySvc (ppCtx))
1251+ const int32_t kiNeededSpsNum = (*ppCtx)->pFuncList->pParametersetStrategy->GetNeededSpsNum();
1252+ const int32_t kiNeededSubsetSpsNum = (*ppCtx)->pFuncList->pParametersetStrategy->GetNeededSubsetSpsNum();
13931253 (*ppCtx)->pSpsArray = (SWelsSPS*)pMa->WelsMallocz (kiNeededSpsNum * sizeof (SWelsSPS), "pSpsArray");
13941254 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pSpsArray), FreeMemorySvc (ppCtx))
13951255 if (kiNeededSubsetSpsNum > 0) {
@@ -1399,36 +1259,15 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 3 unmodified lines
13991259 (*ppCtx)->pSubsetArray = NULL;
14001260 }
14011261
1402− if ((SPS_LISTING & pParam->eSpsPpsIdStrategy) && (NULL != pExistingParasetList)) {
1403− (*ppCtx)->sPSOVector.uiInUseSpsNum = pExistingParasetList->uiInUseSpsNum;
1404− memcpy ((*ppCtx)->pSpsArray, pExistingParasetList->sSps, MAX_SPS_COUNT * sizeof (SWelsSPS));
1405−
1406− if (kiNeededSubsetSpsNum > 0) {
1407− (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = pExistingParasetList->uiInUseSubsetSpsNum;
1408− memcpy ((*ppCtx)->pSubsetArray, pExistingParasetList->sSubsetSps, MAX_SPS_COUNT * sizeof (SSubsetSps));
1409− } else {
1410− (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = 0;
1411− }
1412− }
1413−
14141262 // PPS
1415− const int32_t kiNeededPpsNum = (*ppCtx)->GetNeededPpsNum();
1263+ const int32_t kiNeededPpsNum = (*ppCtx)->pFuncList->pParametersetStrategy->GetNeededPpsNum();
14161264 (*ppCtx)->pPPSArray = (SWelsPPS*)pMa->WelsMallocz (kiNeededPpsNum * sizeof (SWelsPPS), "pPPSArray");
14171265 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pPPSArray), FreeMemorySvc (ppCtx))
14181266
1419− // copy from existing if the pointer exists
1420− if ((SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) && (NULL != pExistingParasetList)) {
1421− (*ppCtx)->sPSOVector.uiInUsePpsNum = pExistingParasetList->uiInUsePpsNum;
1422− memcpy ((*ppCtx)->pPPSArray, pExistingParasetList->sPps, MAX_PPS_COUNT * sizeof (SWelsPPS));
1423− }
1267+ (*ppCtx)->pFuncList->pParametersetStrategy->LoadPrevious (pExistingParasetList, (*ppCtx)->pSpsArray,
1268+ (*ppCtx)->pSubsetArray, (*ppCtx)->pPPSArray);
14241269
14251270
1426− if (INCREASING_ID & pParam->eSpsPpsIdStrategy) {
1427− (*ppCtx)->pPSOVector = & ((*ppCtx)->sPSOVector);
1428− } else {
1429− (*ppCtx)->pPSOVector = NULL;
1430− }
1431−
14321271 (*ppCtx)->pDqIdcMap = (SDqIdc*)pMa->WelsMallocz (iDlayerCount * sizeof (SDqIdc), "pDqIdcMap");
14331272 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pDqIdcMap), FreeMemorySvc (ppCtx))
14341273
@@ -1441,79 +1280,18 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 6 unmodified lines
14411280 && (iDlayerIndex == BASE_DEPENDENCY_ID);
14421281 pDqIdc->uiSpatialId = iDlayerIndex;
14431282
1444− if (! (SPS_LISTING & pParam->eSpsPpsIdStrategy)) {
1445− WelsGenerateNewSps (*ppCtx, bUseSubsetSps, iDlayerIndex,
1446− iDlayerCount, iSpsId, pSps, pSubsetSps, bSvcBaselayer);
1283+ iSpsId = (*ppCtx)->pFuncList->pParametersetStrategy->GenerateNewSps (*ppCtx, bUseSubsetSps, iDlayerIndex,
1284+ iDlayerCount, iSpsId, pSps, pSubsetSps, bSvcBaselayer);
1285+ WELS_VERIFY_RETURN_IF (ENC_RETURN_UNSUPPORTED_PARA, (0 > iSpsId))
1286+ if (!bUseSubsetSps) {
1287+ pSps = & ((*ppCtx)->pSpsArray[iSpsId]);
14471288 } else {
1448− //SPS_LISTING_AND_PPS_INCREASING == pParam->eSpsPpsIdStrategy
1449− //check if the current param can fit in an existing SPS
1450− const int32_t kiFoundSpsId = FindExistingSps ((*ppCtx)->pSvcParam, bUseSubsetSps, iDlayerIndex, iDlayerCount,
1451− bUseSubsetSps ? ((*ppCtx)->sPSOVector.uiInUseSubsetSpsNum) : ((*ppCtx)->sPSOVector.uiInUseSpsNum),
1452− (*ppCtx)->pSpsArray,
1453− (*ppCtx)->pSubsetArray, bSvcBaselayer);
1454−
1455−
1456− if (INVALID_ID != kiFoundSpsId) {
1457− //if yes, set pSps or pSubsetSps to it
1458− iSpsId = kiFoundSpsId;
1459− if (!bUseSubsetSps) {
1460− pSps = & ((*ppCtx)->pSpsArray[kiFoundSpsId]);
1461− } else {
1462− pSubsetSps = & ((*ppCtx)->pSubsetArray[kiFoundSpsId]);
1463− }
1464− } else {
1465− //if no, generate a new SPS as usual
1466− if ((SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) && (MAX_PPS_COUNT <= (*ppCtx)->sPSOVector.uiInUsePpsNum)) {
1467− //check if we can generate new SPS or not
1468− WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR,
1469− "InitDqLayers(), cannot generate new SPS under the SPS_PPS_LISTING mode!");
1470− return ENC_RETURN_UNSUPPORTED_PARA;
1471− }
1472−
1473− iSpsId = (!bUseSubsetSps) ? ((*ppCtx)->sPSOVector.uiInUseSpsNum++) : ((*ppCtx)->sPSOVector.uiInUseSubsetSpsNum++);
1474− if (iSpsId >= MAX_SPS_COUNT) {
1475− if (SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) {
1476− WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_ERROR,
1477− "InitDqLayers(), cannot generate new SPS under the SPS_PPS_LISTING mode!");
1478− return ENC_RETURN_UNSUPPORTED_PARA;
1479− }
1480− // reset current list
1481− if (!bUseSubsetSps) {
1482− (*ppCtx)->sPSOVector.uiInUseSpsNum = 1;
1483− memset ((*ppCtx)->pSpsArray, 0, MAX_SPS_COUNT * sizeof (SWelsSPS));
1484− } else {
1485− (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum = 1;
1486− memset ((*ppCtx)->pSubsetArray, 0, MAX_SPS_COUNT * sizeof (SSubsetSps));
1487− }
1488− iSpsId = 0;
1489− }
1490−
1491− WelsGenerateNewSps (*ppCtx, bUseSubsetSps, iDlayerIndex,
1492− iDlayerCount, iSpsId, pSps, pSubsetSps, bSvcBaselayer);
1493− }
1289+ pSubsetSps = & ((*ppCtx)->pSubsetArray[iSpsId]);
14941290 }
14951291
1496− if (! (SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy)) {
1497− pPps = & (*ppCtx)->pPPSArray[iPpsId];
1498− // initialize pPps
1499− WelsInitPps (pPps, pSps, pSubsetSps, iPpsId, true, bUseSubsetSps, pParam->iEntropyCodingModeFlag != 0);
1500− } else {
1501− const int32_t kiFoundPpsId = FindExistingPps (pSps, pSubsetSps, bUseSubsetSps, iSpsId,
1502− pParam->iEntropyCodingModeFlag != 0,
1503− (*ppCtx)->sPSOVector.uiInUsePpsNum,
1504− (*ppCtx)->pPPSArray);
1505−
1506−
1507− if (INVALID_ID != kiFoundPpsId) {
1508− //if yes, set pPps to it
1509− iPpsId = kiFoundPpsId;
1510− pPps = & ((*ppCtx)->pPPSArray[kiFoundPpsId]);
1511− } else {
1512− iPpsId = ((*ppCtx)->sPSOVector.uiInUsePpsNum++);
1513− pPps = & (*ppCtx)->pPPSArray[iPpsId];
1514− WelsInitPps (pPps, pSps, pSubsetSps, iPpsId, true, bUseSubsetSps, pParam->iEntropyCodingModeFlag != 0);
1515− }
1516− }
1292+ iPpsId = (*ppCtx)->pFuncList->pParametersetStrategy->InitPps ((*ppCtx), iSpsId, pSps, pSubsetSps, iPpsId, true,
1293+ bUseSubsetSps, pParam->iEntropyCodingModeFlag != 0);
1294+ pPps = & ((*ppCtx)->pPPSArray[iPpsId]);
15171295
15181296 // Not using FMO in SVC coding so far, come back if need FMO
15191297 {
@@ -1533,8 +1311,6 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 13 unmodified lines
15331311 pDqIdc->iSpsId = iSpsId;
15341312 pDqIdc->iPpsId = iPpsId;
15351313
1536− (*ppCtx)->sPSOVector.bPpsIdMappingIntoSubsetsps[iPpsId] = bUseSubsetSps;
1537−
15381314 if ((pParam->bSimulcastAVC) || (bUseSubsetSps))
15391315 ++ iSpsId;
15401316 ++ iPpsId;
@@ -1547,13 +1323,8 @@ static inline int32_t InitDqLayers (sWelsEncCtx** ppCtx, SExistingParasetList* p · 6 unmodified lines
15471323
15481324 ++ iDlayerIndex;
15491325 }
1550− if (SPS_LISTING & pParam->eSpsPpsIdStrategy) {
1551− (*ppCtx)->iSpsNum = (*ppCtx)->sPSOVector.uiInUseSpsNum;
1552− (*ppCtx)->iSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
1553− }
1554− if (SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) {
1555− (*ppCtx)->iPpsNum = (*ppCtx)->sPSOVector.uiInUsePpsNum;
1556− }
1326+
1327+ (*ppCtx)->pFuncList->pParametersetStrategy->UpdateParaSetNum ((*ppCtx));
15571328 return ENC_RETURN_SUCCESS;
15581329 }
15591330
@@ -1908,8 +1679,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 348 unmodified lines
19081679 return 1;
19091680 }
19101681
1911− const int32_t kiSpsSize = (*ppCtx)->GetNeededSpsNum() * SPS_BUFFER_SIZE;
1912− const int32_t kiPpsSize = (*ppCtx)->GetNeededPpsNum() * PPS_BUFFER_SIZE;
1682+ const int32_t kiSpsSize = (*ppCtx)->pFuncList->pParametersetStrategy->GetNeededSpsNum() * SPS_BUFFER_SIZE;
1683+ const int32_t kiPpsSize = (*ppCtx)->pFuncList->pParametersetStrategy->GetNeededPpsNum() * PPS_BUFFER_SIZE;
19131684 iNonVclLayersBsSizeCount = SSEI_BUFFER_SIZE + kiSpsSize + kiPpsSize;
19141685
19151686 bool bDynamicSlice = false;
@@ -2309,6 +2080,10 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 393 unmodified lines
23092080
23102081 FreeCodingParam (&pCtx->pSvcParam, pMa);
23112082 if (NULL != pCtx->pFuncList) {
2083+ if (NULL != pCtx->pFuncList->pParametersetStrategy) {
2084+ WELS_DELETE_OP (pCtx->pFuncList->pParametersetStrategy);
2085+ }
2086+
23122087 pMa->WelsFree (pCtx->pFuncList, "SWelsFuncPtrList");
23132088 pCtx->pFuncList = NULL;
23142089 }
@@ -2860,9 +2635,8 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 545 unmodified lines
28602635 int32_t iCurPpsId = pDqIdc->iPpsId;
28612636 int32_t iCurSpsId = pDqIdc->iSpsId;
28622637
2863− if (SPS_PPS_LISTING == pParam->eSpsPpsIdStrategy) {
2864− iCurPpsId = pCtx->sPSOVector.iPpsIdList[pDqIdc->iPpsId][WELS_ABS (pCtx->uiIdrPicId - 1) % MAX_PPS_COUNT];
2865− }
2638+ iCurPpsId = pCtx->pFuncList->pParametersetStrategy->GetCurrentPpsId (iCurPpsId,
2639+ WELS_ABS (pCtx->uiIdrPicId - 1) % MAX_PPS_COUNT);
28662640
28672641 pBaseSlice->sSliceHeaderExt.sSliceHeader.iPpsId = iCurPpsId;
28682642 pCurDq->sLayerInfo.pPpsP =
@@ -3141,45 +2915,12 @@ static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFram · 272 unmodified lines
31412915 }
31422916 }
31432917
3144−
3145−void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, const int32_t kiCurEncoderParaSetId,
3146− const uint32_t kuiMaxIdInBs) { //paraset_type = 0: SPS; =1: PPS
3147− //SPS_ID in avc_sps and pSubsetSps will be different using this
3148− //SPS_ID case example:
3149− //1st enter: next_spsid_in_bs == 0; spsid == 0; delta==0; //actual spsid_in_bs == 0
3150− //1st finish: next_spsid_in_bs == 1;
3151− //2nd enter: next_spsid_in_bs == 1; spsid == 0; delta==1; //actual spsid_in_bs == 1
3152− //2nd finish: next_spsid_in_bs == 2;
3153− //31st enter: next_spsid_in_bs == 31; spsid == 0~2; delta==31~29; //actual spsid_in_bs == 31
3154− //31st finish:next_spsid_in_bs == 0;
3155− //31st enter: next_spsid_in_bs == 0; spsid == 0~2; delta==-2~0; //actual spsid_in_bs == 0
3156− //31st finish:next_spsid_in_bs == 1;
3157−
3158− const int32_t kiEncId = kiCurEncoderParaSetId;
3159− uint32_t uiNextIdInBs = sParaSetOffsetVariable->uiNextParaSetIdToUseInBs;
3160−
3161− //update current layer's pCodingParam
3162− sParaSetOffsetVariable->iParaSetIdDelta[kiEncId] = uiNextIdInBs -
3163− kiEncId; //for current parameter set, change its id_delta
3164− //write pso pData for next update:
3165− sParaSetOffsetVariable->bUsedParaSetIdInBs[uiNextIdInBs] = true; // update current used_id
3166−
3167− //prepare for next update:
3168− // find the next avaibable iId
3169− ++uiNextIdInBs;
3170− if (uiNextIdInBs >= kuiMaxIdInBs) {
3171− uiNextIdInBs = 0;//ensure the SPS_ID wound not exceed MAX_SPS_COUNT
3172− }
3173− // update next_id
3174− sParaSetOffsetVariable->uiNextParaSetIdToUseInBs = uiNextIdInBs;
3175−}
3176−
31772918 int32_t WelsWriteOneSPS (sWelsEncCtx* pCtx, const int32_t kiSpsIdx, int32_t& iNalSize) {
31782919 int iNal = pCtx->pOut->iNalIndex;
31792920 WelsLoadNal (pCtx->pOut, NAL_UNIT_SPS, NRI_PRI_HIGHEST);
31802921
31812922 WelsWriteSpsNal (&pCtx->pSpsArray[kiSpsIdx], &pCtx->pOut->sBsWrite,
3182− & (pCtx->sPSOVector.sParaSetOffsetVariable[PARA_SET_TYPE_AVCSPS].iParaSetIdDelta[0]));
2923+ pCtx->pFuncList->pParametersetStrategy->GetSpsIdOffsetList (PARA_SET_TYPE_AVCSPS));
31832924 WelsUnloadNal (pCtx->pOut);
31842925
31852926 int32_t iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL,
@@ -3197,8 +2938,9 @@ int32_t WelsWriteOnePPS (sWelsEncCtx* pCtx, const int32_t kiPpsIdx, int32_t& iNa · 11 unmodified lines
31972938 int32_t iNal = pCtx->pOut->iNalIndex;
31982939 /* generate picture parameter set */
31992940 WelsLoadNal (pCtx->pOut, NAL_UNIT_PPS, NRI_PRI_HIGHEST);
2941+
32002942 WelsWritePpsSyntax (&pCtx->pPPSArray[kiPpsIdx], &pCtx->pOut->sBsWrite,
3201− ((SPS_PPS_LISTING != pCtx->pSvcParam->eSpsPpsIdStrategy)) ? (& (pCtx->sPSOVector)) : NULL);
2943+ pCtx->pFuncList->pParametersetStrategy);
32022944 WelsUnloadNal (pCtx->pOut);
32032945
32042946 int32_t iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL,
@@ -3211,43 +2953,6 @@ int32_t WelsWriteOnePPS (sWelsEncCtx* pCtx, const int32_t kiPpsIdx, int32_t& iNa · 6 unmodified lines
32112953 return ENC_RETURN_SUCCESS;
32122954 }
32132955
3214−void UpdatePpsList (sWelsEncCtx* pCtx) {
3215− assert (pCtx->iPpsNum <= MAX_DQ_LAYER_NUM);
3216−
3217− //Generate PPS LIST
3218− int32_t iPpsId = 0, iUsePpsNum = pCtx->iPpsNum;
3219−
3220− for (int32_t iIdrRound = 0; iIdrRound < MAX_PPS_COUNT; iIdrRound++) {
3221− for (iPpsId = 0; iPpsId < pCtx->iPpsNum; iPpsId++) {
3222− pCtx->sPSOVector.iPpsIdList[iPpsId][iIdrRound] = ((iIdrRound * iUsePpsNum + iPpsId) % MAX_PPS_COUNT);
3223− }
3224− }
3225−
3226− for (iPpsId = iUsePpsNum; iPpsId < MAX_PPS_COUNT; iPpsId++) {
3227− memcpy (& (pCtx->pPPSArray[iPpsId]), & (pCtx->pPPSArray[iPpsId % iUsePpsNum]), sizeof (SWelsPPS));
3228− pCtx->pPPSArray[iPpsId].iPpsId = iPpsId;
3229− pCtx->iPpsNum++;
3230− }
3231−
3232− assert (pCtx->iPpsNum == MAX_PPS_COUNT);
3233− pCtx->sPSOVector.uiInUsePpsNum = pCtx->iPpsNum;
3234−
3235−}
3236−
3237−void UpdateSpsPpsIdStrategyWithIncreasingId (SParaSetOffset* pPSOVector, const uint32_t kuiId, const int iParasetType) {
3238−#if _DEBUG
3239− pPSOVector->eSpsPpsIdStrategy = INCREASING_ID;
3240− assert (kuiId < MAX_DQ_LAYER_NUM);
3241−#endif
3242−
3243− ParasetIdAdditionIdAdjust (& (pPSOVector->sParaSetOffsetVariable[iParasetType]),
3244− kuiId,
3245− (iParasetType != PARA_SET_TYPE_PPS) ? MAX_SPS_COUNT : MAX_PPS_COUNT);
3246−}
3247−
3248−void UpdateSpsPpsIdStrategyWithConstantId (SParaSetOffset* pPSOVector, const uint32_t kuiId, const int iParasetType) {
3249− memset (pPSOVector, 0, sizeof (SParaSetOffset));
3250−}
32512956
32522957 /*!
32532958 * \brief write all parameter sets introduced in SVC extension
@@ -3262,22 +2967,16 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 8 unmodified lines
32622967 int32_t iNalLength = 0;
32632968 int32_t iReturn = ENC_RETURN_SUCCESS;
32642969
3265− if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal)
2970+ if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal || NULL == pCtx->pFuncList->pParametersetStrategy)
32662971 return ENC_RETURN_UNEXPECTED;
32672972
32682973 *pTotalLength = 0;
32692974 /* write all SPS */
32702975 iIdx = 0;
32712976 while (iIdx < pCtx->iSpsNum) {
3272− // TODO (Sijia) wrap different operation of eSpsPpsIdStrategy to classes to hide the details
3273− if (INCREASING_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3274− UpdateSpsPpsIdStrategyWithIncreasingId (& (pCtx->sPSOVector), pCtx->pSpsArray[0].uiSpsId, PARA_SET_TYPE_AVCSPS);
3275− } else if (CONSTANT_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3276− UpdateSpsPpsIdStrategyWithConstantId (& (pCtx->sPSOVector), pCtx->pSpsArray[0].uiSpsId, PARA_SET_TYPE_AVCSPS);
3277− }
3278−
2977+ pCtx->pFuncList->pParametersetStrategy->Update (pCtx->pSpsArray[iIdx].uiSpsId, PARA_SET_TYPE_AVCSPS);
32792978 /* generate sequence parameters set */
3280− iId = (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy) ? iIdx : 0;
2979+ iId = pCtx->pFuncList->pParametersetStrategy->GetSpsIdx (iIdx);
32812980
32822981 WelsWriteOneSPS (pCtx, iId, iNalLength);
32832982
@@ -3293,11 +2992,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 9 unmodified lines
32932992 while (iIdx < pCtx->iSubsetSpsNum) {
32942993 iNal = pCtx->pOut->iNalIndex;
32952994
3296− if (INCREASING_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3297− UpdateSpsPpsIdStrategyWithIncreasingId (& (pCtx->sPSOVector), pCtx->pSubsetArray[iIdx].pSps.uiSpsId,
3298− PARA_SET_TYPE_SUBSETSPS);
3299− }
3300−
2995+ pCtx->pFuncList->pParametersetStrategy->Update (pCtx->pSubsetArray[iIdx].pSps.uiSpsId, PARA_SET_TYPE_SUBSETSPS);
33012996
33022997 iId = iIdx;
33032998
@@ -3305,7 +3000,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line
33053000 WelsLoadNal (pCtx->pOut, NAL_UNIT_SUBSET_SPS, NRI_PRI_HIGHEST);
33063001
33073002 WelsWriteSubsetSpsSyntax (&pCtx->pSubsetArray[iId], &pCtx->pOut->sBsWrite,
3308− & (pCtx->sPSOVector.sParaSetOffsetVariable[PARA_SET_TYPE_SUBSETSPS].iParaSetIdDelta[0]));
3003+ pCtx->pFuncList->pParametersetStrategy->GetSpsIdOffsetList (PARA_SET_TYPE_SUBSETSPS));
33093004 WelsUnloadNal (pCtx->pOut);
33103005
33113006 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL,
@@ -3322,16 +3017,11 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 10 unmodified lines
33223017 ++ iCountNal;
33233018 }
33243019
3325− /* write all PPS */
3326− if ((SPS_PPS_LISTING == pCtx->pSvcParam->eSpsPpsIdStrategy) && (pCtx->iPpsNum < MAX_PPS_COUNT)) {
3327− UpdatePpsList (pCtx);
3328− }
3020+ pCtx->pFuncList->pParametersetStrategy->UpdatePpsList (pCtx);
33293021
33303022 iIdx = 0;
33313023 while (iIdx < pCtx->iPpsNum) {
3332− if ((INCREASING_ID & pCtx->pSvcParam->eSpsPpsIdStrategy)) {
3333− UpdateSpsPpsIdStrategyWithIncreasingId (& (pCtx->sPSOVector), pCtx->pPPSArray[iIdx].iPpsId, PARA_SET_TYPE_PPS);
3334− }
3024+ pCtx->pFuncList->pParametersetStrategy->Update (pCtx->pPPSArray[iIdx].iPpsId, PARA_SET_TYPE_PPS);
33353025
33363026 WelsWriteOnePPS (pCtx, iIdx, iNalLength);
33373027
@@ -3545,10 +3235,9 @@ int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t iIdx, · 207 unmodified lines
35453235 int32_t iNalSize = 0;
35463236 iCountNal = 0;
35473237
3548− if (INCREASING_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3549− UpdateSpsPpsIdStrategyWithIncreasingId (& (pCtx->sPSOVector), pCtx->pSpsArray[iIdx].uiSpsId, PARA_SET_TYPE_AVCSPS);
3550− } else if (CONSTANT_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3551− UpdateSpsPpsIdStrategyWithConstantId (& (pCtx->sPSOVector), pCtx->pSpsArray[iIdx].uiSpsId, PARA_SET_TYPE_AVCSPS);
3238+
3239+ if (pCtx->pFuncList->pParametersetStrategy) {
3240+ pCtx->pFuncList->pParametersetStrategy->Update (pCtx->pSpsArray[iIdx].uiSpsId, PARA_SET_TYPE_AVCSPS);
35523241 }
35533242
35543243 iReturn = WelsWriteOneSPS (pCtx, iIdx, iNalSize);
@@ -3582,10 +3271,8 @@ int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t iIdx, · 27 unmodified lines
35823271 iNalSize = 0;
35833272 iCountNal = 0;
35843273
3585− if (INCREASING_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3586− UpdateSpsPpsIdStrategyWithIncreasingId (& (pCtx->sPSOVector), pCtx->pPPSArray[iIdx].iPpsId, PARA_SET_TYPE_PPS);
3587− } else if (CONSTANT_ID == pCtx->pSvcParam->eSpsPpsIdStrategy) {
3588− UpdateSpsPpsIdStrategyWithConstantId (& (pCtx->sPSOVector), pCtx->pPPSArray[iIdx].iPpsId, PARA_SET_TYPE_PPS);
3274+ if (pCtx->pFuncList->pParametersetStrategy) {
3275+ pCtx->pFuncList->pParametersetStrategy->Update (pCtx->pPPSArray[iIdx].iPpsId, PARA_SET_TYPE_PPS);
35893276 }
35903277
35913278 iReturn = WelsWriteOnePPS (pCtx, iIdx, iNalSize);
@@ -3659,9 +3346,7 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum, · 67 unmodified lines
36593346 }
36603347
36613348 // write PPS
3662− if ((SPS_PPS_LISTING == pCtx->pSvcParam->eSpsPpsIdStrategy) && (pCtx->iPpsNum < MAX_PPS_COUNT)) {
3663− UpdatePpsList (pCtx);
3664− }
3349+ pCtx->pFuncList->pParametersetStrategy->UpdatePpsList (pCtx);
36653350
36663351 //TODO: under new strategy, will PPS be correctly updated?
36673352 for (int32_t iSpatialId = 0; iSpatialId < kiSpatialNum; iSpatialId++) {
@@ -4652,46 +4337,16 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 984 unmodified lines
46524337 SExistingParasetList sExistingParasetList;
46534338 SExistingParasetList* pExistingParasetList = NULL;
46544339
4655− if ((CONSTANT_ID != iOldSpsPpsIdStrategy) && (CONSTANT_ID != pNewParam->eSpsPpsIdStrategy)) {
4656− for (int32_t k = 0; k < PARA_SET_TYPE; k++) {
4657− memset (((*ppCtx)->sPSOVector.sParaSetOffsetVariable[k].bUsedParaSetIdInBs), 0, MAX_PPS_COUNT * sizeof (bool));
4658− }
4659− memcpy (sTmpPsoVariable, (*ppCtx)->sPSOVector.sParaSetOffsetVariable,
4660− (PARA_SET_TYPE)*sizeof (SParaSetOffsetVariable)); // confirmed_safe_unsafe_usage
4340+ if (((CONSTANT_ID != iOldSpsPpsIdStrategy) && (CONSTANT_ID != pNewParam->eSpsPpsIdStrategy))) {
4341+ (*ppCtx)->pFuncList->pParametersetStrategy->OutputCurrentStructure (sTmpPsoVariable, iTmpPpsIdList, (*ppCtx),
4342+ &sExistingParasetList);
46614343
46624344 if ((SPS_LISTING & iOldSpsPpsIdStrategy)
46634345 && (SPS_LISTING & pNewParam->eSpsPpsIdStrategy)) {
46644346 pExistingParasetList = &sExistingParasetList;
4665− sExistingParasetList.uiInUseSpsNum = (*ppCtx)->sPSOVector.uiInUseSpsNum;
4666− memcpy (sExistingParasetList.sSps, (*ppCtx)->pSpsArray, MAX_SPS_COUNT * sizeof (SWelsSPS));
4667− if (NULL != (*ppCtx)->pSubsetArray) {
4668− sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
4669− memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
4670− } else {
4671− sExistingParasetList.uiInUseSubsetSpsNum = 0;
4672− }
4673− }
4674−
4675− if ((SPS_PPS_LISTING == iOldSpsPpsIdStrategy)
4676− && (SPS_PPS_LISTING == pNewParam->eSpsPpsIdStrategy)) {
4677− pExistingParasetList = &sExistingParasetList;
4678− sExistingParasetList.uiInUseSpsNum = (*ppCtx)->sPSOVector.uiInUseSpsNum;
4679− sExistingParasetList.uiInUsePpsNum = (*ppCtx)->sPSOVector.uiInUsePpsNum;
4680− memcpy (sExistingParasetList.sSps, (*ppCtx)->pSpsArray, MAX_SPS_COUNT * sizeof (SWelsSPS));
4681− memcpy (sExistingParasetList.sPps, (*ppCtx)->pPps, MAX_PPS_COUNT * sizeof (SWelsPPS));
4682−
4683− if (NULL != (*ppCtx)->pSubsetArray) {
4684− sExistingParasetList.uiInUseSubsetSpsNum = (*ppCtx)->sPSOVector.uiInUseSubsetSpsNum;
4685− memcpy (sExistingParasetList.sSubsetSps, (*ppCtx)->pSubsetArray, MAX_SPS_COUNT * sizeof (SSubsetSps));
4686− } else {
4687− sExistingParasetList.uiInUseSubsetSpsNum = 0;
4688− }
4689−
4690− memcpy (iTmpPpsIdList, ((*ppCtx)->sPSOVector.iPpsIdList), MAX_DQ_LAYER_NUM * MAX_PPS_COUNT * sizeof (int32_t));
46914347 }
46924348 }
46934349
4694−
46954350 WelsUninitEncoderExt (ppCtx);
46964351
46974352 /* Update new parameters */
@@ -4704,14 +4359,10 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 6 unmodified lines
47044359 //for sEncoderStatistics
47054360 memcpy ((*ppCtx)->sEncoderStatistics, sTempEncoderStatistics, sizeof (sTempEncoderStatistics));
47064361 //load back the needed structure for eSpsPpsIdStrategy
4707− if ((CONSTANT_ID != iOldSpsPpsIdStrategy) && (CONSTANT_ID != pNewParam->eSpsPpsIdStrategy)) {
4708− memcpy ((*ppCtx)->sPSOVector.sParaSetOffsetVariable, sTmpPsoVariable,
4709− (PARA_SET_TYPE)*sizeof (SParaSetOffsetVariable)); // confirmed_safe_unsafe_usage
4710− }
4711−
4712− if ((SPS_PPS_LISTING == iOldSpsPpsIdStrategy)
4713− && (SPS_PPS_LISTING == pNewParam->eSpsPpsIdStrategy)) {
4714− memcpy (((*ppCtx)->sPSOVector.iPpsIdList), iTmpPpsIdList, MAX_DQ_LAYER_NUM * MAX_PPS_COUNT * sizeof (int32_t));
4362+ if (((CONSTANT_ID != iOldSpsPpsIdStrategy) && (CONSTANT_ID != pNewParam->eSpsPpsIdStrategy))
4363+ || ((SPS_PPS_LISTING == iOldSpsPpsIdStrategy)
4364+ && (SPS_PPS_LISTING == pNewParam->eSpsPpsIdStrategy))) {
4365+ (*ppCtx)->pFuncList->pParametersetStrategy->LoadPreviousStructure (sTmpPsoVariable, iTmpPpsIdList);
47154366 }
47164367 } else {
47174368 /* maybe adjustment introduced in bitrate or little settings adjustment and so on.. */

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