History

enhance max-br checking logic

Sijia Chen committed 11 years ago

Commit d74234d1 parent 66645931 file · +37 −25Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+37−25
@@ -76,34 +76,46 @@ int32_t WelsBitRateVerification (SLogContext* pLogCtx, SSpatialLayerConfig* pLay · 75 unmodified lines
7676 pLayerParam->iSpatialBitrate);
7777 return ENC_RETURN_UNSUPPORTED_PARA;
7878 }
79− int32_t iLevelMaxBitrate = g_ksLevelLimits[pLayerParam->uiLevelIdc - 1].uiMaxBR * CpbBrNalFactor;
80− if (pLayerParam->iMaxSpatialBitrate == UNSPECIFIED_BIT_RATE) {
81− pLayerParam->iMaxSpatialBitrate = iLevelMaxBitrate;
82− WelsLog (pLogCtx, WELS_LOG_INFO, "Current MaxSpatialBitrate is zero,Get this value from level limitation(%d)",
79+
80+ // deal with LEVEL_MAX_BR and MAX_BR setting
81+ const int32_t iLevelMaxBitrate = (pLayerParam->uiLevelIdc != LEVEL_UNKNOWN) ? (g_ksLevelLimits[pLayerParam->uiLevelIdc -
82+ 1].uiMaxBR * CpbBrNalFactor) : UNSPECIFIED_BIT_RATE;
83+ const int32_t iLevel52MaxBitrate = g_ksLevelLimits[LEVEL_NUMBER - 1].uiMaxBR * CpbBrNalFactor;
84+ if (UNSPECIFIED_BIT_RATE != iLevelMaxBitrate) {
85+ if ((pLayerParam->iMaxSpatialBitrate == UNSPECIFIED_BIT_RATE)
86+ || (pLayerParam->iMaxSpatialBitrate > iLevel52MaxBitrate)) {
87+ pLayerParam->iMaxSpatialBitrate = iLevelMaxBitrate;
88+ WelsLog (pLogCtx, WELS_LOG_INFO,
89+ "Current MaxSpatialBitrate is invalid (UNSPECIFIED_BIT_RATE or larger than LEVEL5_2) but level setting is valid, set iMaxSpatialBitrate to %d from level (%d)",
90+ pLayerParam->iMaxSpatialBitrate, pLayerParam->uiLevelIdc);
91+ } else if (pLayerParam->iMaxSpatialBitrate > iLevelMaxBitrate) {
92+ ELevelIdc iCurLevel = pLayerParam->uiLevelIdc;
93+ WelsAdjustLevel (pLayerParam);
94+ WelsLog (pLogCtx, WELS_LOG_INFO,
95+ "LevelIdc is changed from (%d) to (%d) according to the iMaxSpatialBitrate(%d)",
96+ iCurLevel, pLayerParam->uiLevelIdc, pLayerParam->iMaxSpatialBitrate);
97+ }
98+ } else if ((pLayerParam->iMaxSpatialBitrate != UNSPECIFIED_BIT_RATE)
99+ && (pLayerParam->iMaxSpatialBitrate > iLevel52MaxBitrate)) {
100+ // no level limitation, just need to check if iMaxSpatialBitrate is too big from reasonable
101+ WelsLog (pLogCtx, WELS_LOG_WARNING,
102+ "No LevelIdc setting and iMaxSpatialBitrate (%d) is considered too big to be valid, changed to UNSPECIFIED_BIT_RATE",
83103 pLayerParam->iMaxSpatialBitrate);
104+ pLayerParam->iMaxSpatialBitrate = UNSPECIFIED_BIT_RATE;
84105 }
85− if (pLayerParam->iMaxSpatialBitrate > iLevelMaxBitrate) {
86− ELevelIdc iCurLevel = pLayerParam->uiLevelIdc;
87− if (WelsAdjustLevel (pLayerParam)) {
88− int32_t iLevel52MaxBitrate = g_ksLevelLimits[LEVEL_NUMBER - 1].uiMaxBR * CpbBrNalFactor;
89− WelsLog (pLogCtx, WELS_LOG_WARNING,
90− "MaxSpatialBitrate (%d) is larger that the limitation LEVEL_5_2, the setting will be invalid, and will use max-br (%d) of LEVEL_5_2",
91− pLayerParam->iMaxSpatialBitrate, iLevel52MaxBitrate);
92− pLayerParam->iMaxSpatialBitrate = iLevel52MaxBitrate;
106+
107+ // deal with iSpatialBitrate and iMaxSpatialBitrate setting
108+ if (pLayerParam->iMaxSpatialBitrate != UNSPECIFIED_BIT_RATE) {
109+ if (pLayerParam->iMaxSpatialBitrate == pLayerParam->iSpatialBitrate) {
110+ WelsLog (pLogCtx, WELS_LOG_INFO,
111+ "Setting MaxSpatialBitrate (%d) the same at SpatialBitrate (%d) will make the actual bit rate lower than SpatialBitrate",
112+ pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
113+ } else if (pLayerParam->iMaxSpatialBitrate < pLayerParam->iSpatialBitrate) {
114+ WelsLog (pLogCtx, WELS_LOG_ERROR,
115+ "MaxSpatialBitrate (%d) should be larger than SpatialBitrate (%d), considering it as error setting",
116+ pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
117+ return ENC_RETURN_UNSUPPORTED_PARA;
93118 }
94− WelsLog (pLogCtx, WELS_LOG_INFO,
95− "Level is changed from (%d) to (%d) according to the maxbitrate",
96− iCurLevel, pLayerParam->uiLevelIdc);
97− }
98− if (pLayerParam->iMaxSpatialBitrate == pLayerParam->iSpatialBitrate) {
99− WelsLog (pLogCtx, WELS_LOG_INFO,
100− "Setting MaxSpatialBitrate (%d) the same at SpatialBitrate (%d) will make the actual bit rate lower than SpatialBitrate",
101− pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
102− } else if (pLayerParam->iMaxSpatialBitrate < pLayerParam->iSpatialBitrate) {
103− WelsLog (pLogCtx, WELS_LOG_ERROR,
104− "MaxSpatialBitrate (%d) should be larger than SpatialBitrate (%d), considering it as error setting",
105− pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
106− return ENC_RETURN_UNSUPPORTED_PARA;
107119 }
108120 return ENC_RETURN_SUCCESS;
109121 }

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