diff --git a/webrtc/modules/video_coding/media_opt_util.cc b/webrtc/modules/video_coding/media_opt_util.cc index 24acfe9f66..ed926e953b 100644 --- a/webrtc/modules/video_coding/media_opt_util.cc +++ b/webrtc/modules/video_coding/media_opt_util.cc @@ -15,6 +15,7 @@ #include #include +#include #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" @@ -244,7 +245,7 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) { // FEC PROTECTION SETTINGS: varies with packet loss and bitrate // No protection if (filtered) packetLoss is 0 - uint8_t packetLoss = (uint8_t)(255 * parameters->lossPr); + uint8_t packetLoss = static_cast(255 * parameters->lossPr); if (packetLoss == 0) { _protectionFactorK = 0; _protectionFactorD = 0; @@ -255,7 +256,7 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) { // first partition size, thresholds, table pars, spatial resoln fac. // First partition protection: ~ 20% - uint8_t firstPartitionProt = (uint8_t)(255 * 0.20); + uint8_t firstPartitionProt = static_cast(255 * 0.20); // Minimum protection level needed to generate one FEC packet for one // source packet/frame (in RTP sender) @@ -282,10 +283,11 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) { const int bitRatePerFrame = BitsPerFrame(parameters); // Average number of packets per frame (source and fec): - const uint8_t avgTotPackets = - 1 + (uint8_t)(static_cast(bitRatePerFrame) * 1000.0 / - static_cast(8.0 * _maxPayloadSize) + - 0.5); + const uint8_t avgTotPackets = static_cast( + std::min(static_cast(std::numeric_limits::max()), + 1.5f + + static_cast(bitRatePerFrame) * 1000.0f / + static_cast(8.0 * _maxPayloadSize))); // FEC rate parameters: for P and I frame uint8_t codeRateDelta = 0; @@ -296,8 +298,8 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) { // from ~200k to ~8000k, for 30fps const uint16_t effRateFecTable = static_cast(resolnFac * bitRatePerFrame); - uint8_t rateIndexTable = (uint8_t)VCM_MAX( - VCM_MIN((effRateFecTable - ratePar1) / ratePar1, ratePar2), 0); + uint8_t rateIndexTable = static_cast( + VCM_MAX(VCM_MIN((effRateFecTable - ratePar1) / ratePar1, ratePar2), 0)); // Restrict packet loss range to 50: // current tables defined only up to 50% @@ -328,14 +330,15 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) { // Effectively at a higher rate, so we scale/boost the rate // The boost factor may depend on several factors: ratio of packet // number of I to P frames, how much protection placed on P frames, etc. - const uint8_t packetFrameDelta = (uint8_t)(0.5 + parameters->packetsPerFrame); + const uint8_t packetFrameDelta = + static_cast(0.5 + parameters->packetsPerFrame); const uint8_t packetFrameKey = - (uint8_t)(0.5 + parameters->packetsPerFrameKey); + static_cast(0.5 + parameters->packetsPerFrameKey); const uint8_t boostKey = BoostCodeRateKey(packetFrameDelta, packetFrameKey); - rateIndexTable = (uint8_t)VCM_MAX( + rateIndexTable = static_cast(VCM_MAX( VCM_MIN(1 + (boostKey * effRateFecTable - ratePar1) / ratePar1, ratePar2), - 0); + 0)); uint16_t indexTableKey = rateIndexTable * kPacketLossMax + packetLoss; indexTableKey = VCM_MIN(indexTableKey, kSizeCodeRateXORTable);