History

add maxbitrate verification

ruil2 committed 11 years ago

Commit d543ae81 parent 305a24211 files · +5739 −8499Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+49−33
@@ -70,6 +70,47 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 69 unmodified lines
70 );70 );
71 71
72 72
73int32_t WelsBitRateVerification (SLogContext* pLogCtx, SSpatialLayerConfig* pLayerParam, int32_t iLayerId) {
74 if (pLayerParam->iSpatialBitrate <= 0) {
75 WelsLog (pLogCtx, WELS_LOG_ERROR, "Invalid bitrate settings in layer %d, bitrate= %d", iLayerId,
76 pLayerParam->iSpatialBitrate);
77 return ENC_RETURN_UNSUPPORTED_PARA;
78 }
79 if (pLayerParam->iMaxSpatialBitrate == pLayerParam->iSpatialBitrate) {
80 WelsLog (pLogCtx, WELS_LOG_INFO,
81 "Setting MaxSpatialBitrate (%d) the same at SpatialBitrate (%d) will make the actual bit rate lower than SpatialBitrate",
82 pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
83 }
84 int32_t iLevelMaxBitrate = g_ksLevelLimits[pLayerParam->uiLevelIdc - 1].uiMaxBR * CpbBrNalFactor;
85 if (pLayerParam->iMaxSpatialBitrate == UNSPECIFIED_BIT_RATE) {
86 pLayerParam->iMaxSpatialBitrate = iLevelMaxBitrate;
87 WelsLog (pLogCtx, WELS_LOG_INFO, "Current MaxSpatialBitrate is zero,Get this value from level limitation(%d)",
88 pLayerParam->iMaxSpatialBitrate);
89 }
90 if (pLayerParam->iMaxSpatialBitrate > iLevelMaxBitrate) {
91 ELevelIdc iCurLevel = pLayerParam->uiLevelIdc;
92 if (WelsAdjustLevel (pLayerParam)) {
93 WelsLog (pLogCtx, WELS_LOG_ERROR,
94 "MaxSpatialBitrate (%d) is larger that the limitation LEVEL_5_2, considering it as error setting",
95 pLayerParam->iMaxSpatialBitrate);
96 return ENC_RETURN_UNSUPPORTED_PARA;
97 } else {
98 WelsLog (pLogCtx, WELS_LOG_WARNING,
99 "Level is changed from (%d) to (%d) according to the maxbitrate",
100 iCurLevel, pLayerParam->uiLevelIdc);
101 }
102
103 }
104 if (pLayerParam->iMaxSpatialBitrate < pLayerParam->iSpatialBitrate) {
105 WelsLog (pLogCtx, WELS_LOG_ERROR,
106 "MaxSpatialBitrate (%d) should be larger than SpatialBitrate (%d), considering it as error setting",
107 pLayerParam->iMaxSpatialBitrate, pLayerParam->iSpatialBitrate);
108 return ENC_RETURN_UNSUPPORTED_PARA;
109 }
110 return ENC_RETURN_SUCCESS;
111}
112
113
73/*!114/*!
74 * \brief validate checking in parameter configuration115 * \brief validate checking in parameter configuration
75 * \pParam pParam SWelsSvcCodingParam*116 * \pParam pParam SWelsSvcCodingParam*
@@ -150,22 +191,9 @@ int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) { · 74 unmodified lines
150 for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {191 for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
151 SSpatialLayerConfig* pSpatialLayer = &pCfg->sSpatialLayers[i];192 SSpatialLayerConfig* pSpatialLayer = &pCfg->sSpatialLayers[i];
152 iTotalBitrate += pSpatialLayer->iSpatialBitrate;193 iTotalBitrate += pSpatialLayer->iSpatialBitrate;
153 if (pSpatialLayer->iSpatialBitrate <= 0) {194
154 WelsLog (pLogCtx, WELS_LOG_ERROR, "Invalid bitrate settings in layer %d, bitrate= %d", i,195 if (WelsBitRateVerification (pLogCtx, pSpatialLayer, i) != ENC_RETURN_SUCCESS)
155 pSpatialLayer->iSpatialBitrate);
156 return ENC_RETURN_INVALIDINPUT;196 return ENC_RETURN_INVALIDINPUT;
157 }
158 if (pSpatialLayer->iMaxSpatialBitrate == pSpatialLayer->iSpatialBitrate) {
159 WelsLog (pLogCtx, WELS_LOG_INFO,
160 "Setting MaxSpatialBitrate (%d) the same at SpatialBitrate (%d) will make the actual bit rate lower than SpatialBitrate",
161 pSpatialLayer->iMaxSpatialBitrate, pSpatialLayer->iSpatialBitrate);
162 }
163 if (pSpatialLayer->iMaxSpatialBitrate < pSpatialLayer->iSpatialBitrate) {
164 WelsLog (pLogCtx, WELS_LOG_WARNING,
165 "MaxSpatialBitrate (%d) should be lower than SpatialBitrate (%d), considering it as invalid setting, adjust it to be UNSPECIFIED(0)",
166 pSpatialLayer->iMaxSpatialBitrate, pSpatialLayer->iSpatialBitrate);
167 pSpatialLayer->iMaxSpatialBitrate = 0;
168 }
169 }197 }
170 if (iTotalBitrate > pCfg->iTargetBitrate) {198 if (iTotalBitrate > pCfg->iTargetBitrate) {
171 WelsLog (pLogCtx, WELS_LOG_ERROR,199 WelsLog (pLogCtx, WELS_LOG_ERROR,
@@ -475,8 +503,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam) { · 303 unmodified lines
475 }503 }
476}504}
477 505
478 506int32_t WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
479void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
480 //TODO (Sijia): this is a temporary solution which keep the ratio between layers507 //TODO (Sijia): this is a temporary solution which keep the ratio between layers
481 //but it is also possible to fulfill the bitrate of lower layer first508 //but it is also possible to fulfill the bitrate of lower layer first
482 509
@@ -494,26 +521,15 @@ void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, · 11 unmodified lines
494 pLayerParam = & (pParam->sSpatialLayers[i]);521 pLayerParam = & (pParam->sSpatialLayers[i]);
495 fRatio = pLayerParam->iSpatialBitrate / (static_cast<float> (iOrigTotalBitrate));522 fRatio = pLayerParam->iSpatialBitrate / (static_cast<float> (iOrigTotalBitrate));
496 pLayerParam->iSpatialBitrate = static_cast<int32_t> (pParam->iTargetBitrate * fRatio);523 pLayerParam->iSpatialBitrate = static_cast<int32_t> (pParam->iTargetBitrate * fRatio);
497 if (UNSPECIFIED_BIT_RATE != pLayerParam->iMaxSpatialBitrate524
498 && pLayerParam->iSpatialBitrate > pLayerParam->iMaxSpatialBitrate) {525 if (WelsBitRateVerification (pLogCtx, pLayerParam, i) != ENC_RETURN_SUCCESS)
499 WelsLog (pLogCtx, WELS_LOG_WARNING,526 return ENC_RETURN_UNSUPPORTED_PARA;
500 "WelsEncoderApplyBitRate(), iSpatialBitrate(%d) > iMaxSpatialBitrate(%d) at Layer %d, limiting iSpatialBitrate to iMaxSpatialBitrate!",
501 pLayerParam->iSpatialBitrate, pLayerParam->iMaxSpatialBitrate, iLayer);
502 pLayerParam->iSpatialBitrate = pLayerParam->iMaxSpatialBitrate;
503 }
504 }527 }
505 } else {528 } else {
506 SSpatialLayerConfig* pLayerParam = & (pParam->sSpatialLayers[iLayer]);529 return WelsBitRateVerification (pLogCtx, & (pParam->sSpatialLayers[iLayer]), iLayer);
507 if (UNSPECIFIED_BIT_RATE != pLayerParam->iMaxSpatialBitrate
508 && pLayerParam->iSpatialBitrate > pLayerParam->iMaxSpatialBitrate) {
509 WelsLog (pLogCtx, WELS_LOG_WARNING,
510 "WelsEncoderApplyBitRate(), iSpatialBitrate(%d) > iMaxSpatialBitrate(%d) at Layer %d, limiting iSpatialBitrate to iMaxSpatialBitrate!",
511 pLayerParam->iSpatialBitrate, pLayerParam->iMaxSpatialBitrate, iLayer);
512 pLayerParam->iSpatialBitrate = pLayerParam->iMaxSpatialBitrate;
513 }
514 }530 }
531 return ENC_RETURN_SUCCESS;
515}532}
516
517/*!533/*!
518 * \brief acquire count number of layers and NALs based on configurable paramters dependency534 * \brief acquire count number of layers and NALs based on configurable paramters dependency
519 * \pParam pCtx sWelsEncCtx*535 * \pParam pCtx sWelsEncCtx*

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