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
7070 );
7171
7272
73+int32_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+
73114 /*!
74115 * \brief validate checking in parameter configuration
75116 * \pParam pParam SWelsSvcCodingParam*
@@ -150,22 +191,9 @@ int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) { · 74 unmodified lines
150191 for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
151192 SSpatialLayerConfig* pSpatialLayer = &pCfg->sSpatialLayers[i];
152193 iTotalBitrate += pSpatialLayer->iSpatialBitrate;
153− if (pSpatialLayer->iSpatialBitrate <= 0) {
154− WelsLog (pLogCtx, WELS_LOG_ERROR, "Invalid bitrate settings in layer %d, bitrate= %d", i,
155− pSpatialLayer->iSpatialBitrate);
194+
195+ if (WelsBitRateVerification (pLogCtx, pSpatialLayer, i) != ENC_RETURN_SUCCESS)
156196 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− }
169197 }
170198 if (iTotalBitrate > pCfg->iTargetBitrate) {
171199 WelsLog (pLogCtx, WELS_LOG_ERROR,
@@ -475,8 +503,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam) { · 303 unmodified lines
475503 }
476504 }
477505
478−
479−void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
506+int32_t WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
480507 //TODO (Sijia): this is a temporary solution which keep the ratio between layers
481508 //but it is also possible to fulfill the bitrate of lower layer first
482509
@@ -494,26 +521,15 @@ void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, · 11 unmodified lines
494521 pLayerParam = & (pParam->sSpatialLayers[i]);
495522 fRatio = pLayerParam->iSpatialBitrate / (static_cast<float> (iOrigTotalBitrate));
496523 pLayerParam->iSpatialBitrate = static_cast<int32_t> (pParam->iTargetBitrate * fRatio);
497− if (UNSPECIFIED_BIT_RATE != pLayerParam->iMaxSpatialBitrate
498− && pLayerParam->iSpatialBitrate > pLayerParam->iMaxSpatialBitrate) {
499− WelsLog (pLogCtx, WELS_LOG_WARNING,
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− }
524+
525+ if (WelsBitRateVerification (pLogCtx, pLayerParam, i) != ENC_RETURN_SUCCESS)
526+ return ENC_RETURN_UNSUPPORTED_PARA;
504527 }
505528 } else {
506− SSpatialLayerConfig* pLayerParam = & (pParam->sSpatialLayers[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− }
529+ return WelsBitRateVerification (pLogCtx, & (pParam->sSpatialLayers[iLayer]), iLayer);
514530 }
531+ return ENC_RETURN_SUCCESS;
515532 }
516−
517533 /*!
518534 * \brief acquire count number of layers and NALs based on configurable paramters dependency
519535 * \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