add maxbitrate parameter
Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 6 files). Show all
Unified · Split
| @@ -376,7 +376,7 @@ void WelsEncoderApplyFrameRate(SWelsSvcCodingParam* pParam) · 375 unmodified lines | ||
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
| 379 | −void WelsEncoderApplyBitRate(SWelsSvcCodingParam* pParam) | |
| 379 | +void WelsEncoderApplyBitRate(SWelsSvcCodingParam* pParam,int iLayer) | |
| 380 | 380 | { |
| 381 | 381 | //TODO (Sijia): this is a temporary solution which keep the ratio between layers |
| 382 | 382 | //but it is also possible to fulfill the bitrate of lower layer first |
| @@ -384,16 +384,30 @@ void WelsEncoderApplyBitRate(SWelsSvcCodingParam* pParam) · 1 unmodified line | ||
| 384 | 384 | SDLayerParam* pLayerParam; |
| 385 | 385 | const int32_t iNumLayers = pParam->iSpatialLayerNum; |
| 386 | 386 | int32_t i, iOrigTotalBitrate=0; |
| 387 | − //read old BR | |
| 388 | − for (i=0;i<iNumLayers;i++) { | |
| 389 | − iOrigTotalBitrate += pParam->sDependencyLayers[i].iSpatialBitrate; | |
| 390 | − } | |
| 391 | − //write new BR | |
| 392 | − float fRatio = 0.0; | |
| 393 | − for (i=0;i<iNumLayers;i++) { | |
| 394 | − pLayerParam = &(pParam->sDependencyLayers[i]); | |
| 395 | − fRatio = pLayerParam->iSpatialBitrate/(static_cast<float>(iOrigTotalBitrate)); | |
| 396 | − pLayerParam->iSpatialBitrate = static_cast<int32_t>(pParam->iTargetBitrate*fRatio); | |
| 387 | + if(iLayer == SPATIAL_LAYER_ALL){ | |
| 388 | + if(pParam->iMaxBitrate <pParam->iTargetBitrate){ | |
| 389 | + WelsLog (NULL, WELS_LOG_WARNING,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,overall settting,TargetBitrate = %d,iMaxBitrate = %d\n", | |
| 390 | + pParam->iTargetBitrate,pParam->iMaxBitrate); | |
| 391 | + pParam->iMaxBitrate = pParam->iTargetBitrate; | |
| 392 | + } | |
| 393 | + //read old BR | |
| 394 | + for (i=0;i<iNumLayers;i++) { | |
| 395 | + iOrigTotalBitrate += pParam->sDependencyLayers[i].iSpatialBitrate; | |
| 396 | + } | |
| 397 | + //write new BR | |
| 398 | + float fRatio = 0.0; | |
| 399 | + for (i=0;i<iNumLayers;i++) { | |
| 400 | + pLayerParam = &(pParam->sDependencyLayers[i]); | |
| 401 | + fRatio = pLayerParam->iSpatialBitrate/(static_cast<float>(iOrigTotalBitrate)); | |
| 402 | + pLayerParam->iSpatialBitrate = static_cast<int32_t>(pParam->iTargetBitrate*fRatio); | |
| 403 | + } | |
| 404 | + }else{ | |
| 405 | + if(pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate <pParam->sSpatialLayers[iLayer].iSpatialBitrate){ | |
| 406 | + WelsLog (NULL, WELS_LOG_WARNING,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d,iTargetBitrate = %d,iMaxBitrate = %d\n", | |
| 407 | + iLayer,pParam->sSpatialLayers[iLayer].iSpatialBitrate,pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate); | |
| 408 | + pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate = pParam->sSpatialLayers[iLayer].iSpatialBitrate; | |
| 409 | + } | |
| 410 | + | |
| 397 | 411 | } |
| 398 | 412 | } |
| 399 | 413 | /*! |