diff --git a/src/common_types.h b/src/common_types.h index 122c7ee13..0d71f3fb3 100644 --- a/src/common_types.h +++ b/src/common_types.h @@ -590,7 +590,7 @@ struct OverUseDetectorOptions { initial_e(), initial_process_noise(), initial_avg_noise(0.0), - initial_var_noise(500), + initial_var_noise(50), initial_threshold(25.0) { initial_e[0][0] = 100; initial_e[1][1] = 1e-1; diff --git a/src/modules/remote_bitrate_estimator/bitrate_estimator.cc b/src/modules/remote_bitrate_estimator/bitrate_estimator.cc index 84c287cf7..2e5befad5 100644 --- a/src/modules/remote_bitrate_estimator/bitrate_estimator.cc +++ b/src/modules/remote_bitrate_estimator/bitrate_estimator.cc @@ -12,7 +12,7 @@ namespace webrtc { -enum { kBitrateAverageWindow = 2000 }; +const float kBitrateAverageWindow = 500.0f; BitRateStats::BitRateStats() :_dataSamples(), _accumulatedBytes(0) @@ -76,16 +76,8 @@ WebRtc_UWord32 BitRateStats::BitRate(WebRtc_Word64 nowMs) { timeOldest = _dataSamples.front()->_timeCompleteMs; } - // Update average bit rate - float denom = static_cast(nowMs - timeOldest); - if (nowMs == timeOldest) - { - // Calculate with a one second window when we haven't - // received more than one packet. - denom = 1000.0; - } return static_cast(_accumulatedBytes * 8.0f * 1000.0f / - denom + 0.5f); + kBitrateAverageWindow + 0.5f); } } // namespace webrtc diff --git a/src/modules/remote_bitrate_estimator/bitrate_estimator_unittest.cc b/src/modules/remote_bitrate_estimator/bitrate_estimator_unittest.cc index b42798a09..2a3a22510 100644 --- a/src/modules/remote_bitrate_estimator/bitrate_estimator_unittest.cc +++ b/src/modules/remote_bitrate_estimator/bitrate_estimator_unittest.cc @@ -34,8 +34,8 @@ TEST_F(BitRateStatsTest, TestStrictMode) // Should be initialized to 0. EXPECT_EQ(0u, bitRate.BitRate(nowMs)); bitRate.Update(1500, nowMs); - // Expecting 12 kbps given a 1000 window with one 1500 bytes packet. - EXPECT_EQ(12000u, bitRate.BitRate(nowMs)); + // Expecting 24 kbps given a 500 ms window with one 1500 bytes packet. + EXPECT_EQ(24000u, bitRate.BitRate(nowMs)); bitRate.Init(); // Expecting 0 after init. EXPECT_EQ(0u, bitRate.BitRate(nowMs)); @@ -45,11 +45,11 @@ TEST_F(BitRateStatsTest, TestStrictMode) bitRate.Update(1500, nowMs); // Approximately 1200 kbps expected. Not exact since when packets // are removed we will jump 10 ms to the next packet. - if (nowMs > 0 && nowMs % 2000 == 0) - EXPECT_NEAR(1200000u, bitRate.BitRate(nowMs), 6000u); + if (nowMs > 0 && nowMs % 500 == 0) + EXPECT_NEAR(1200000u, bitRate.BitRate(nowMs), 24000u); nowMs += 1; } - nowMs += 2000; + nowMs += 500; // The window is 2 seconds. If nothing has been received for that time // the estimate should be 0. EXPECT_EQ(0u, bitRate.BitRate(nowMs)); diff --git a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc index 2f16ab8a4..9cd65f152 100644 --- a/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc +++ b/src/modules/remote_bitrate_estimator/remote_bitrate_estimator_unittest.cc @@ -220,10 +220,15 @@ TEST_F(RemoteBitrateEstimatorTest, TestInitialBehavior) { EXPECT_FALSE(bitrate_observer_->updated()); bitrate_observer_->Reset(); // Waiting more than one second gives us a valid estimate. - time_now += 1001; + // We need at least two packets for the incoming bitrate to be > 0 since the + // window is 500 ms. + time_now += 499; + bitrate_estimator_->IncomingPacket(ssrc, kMtu, time_now, + timestamp, -1); + time_now += 2; bitrate_estimator_->UpdateEstimate(ssrc, time_now); EXPECT_TRUE(bitrate_estimator_->LatestEstimate(ssrc, &bitrate_bps)); - EXPECT_EQ(bitrate_bps, 10734u); + EXPECT_EQ(20607u, bitrate_bps); EXPECT_TRUE(bitrate_observer_->updated()); bitrate_observer_->Reset(); EXPECT_EQ(bitrate_observer_->latest_bitrate(), bitrate_bps); @@ -231,7 +236,7 @@ TEST_F(RemoteBitrateEstimatorTest, TestInitialBehavior) { // Make sure we initially increase the bitrate as expected. TEST_F(RemoteBitrateEstimatorTest, TestRateIncreaseRtpTimestamps) { - const int kExpectedIterations = 323; + const int kExpectedIterations = 277; unsigned int bitrate_bps = 30000; unsigned int ssrc = 0; int iterations = 0; diff --git a/src/modules/remote_bitrate_estimator/remote_rate_control.cc b/src/modules/remote_bitrate_estimator/remote_rate_control.cc index cb542a47b..ea15e21f8 100644 --- a/src/modules/remote_bitrate_estimator/remote_rate_control.cc +++ b/src/modules/remote_bitrate_estimator/remote_rate_control.cc @@ -143,7 +143,8 @@ RateControlRegion RemoteRateControl::Update(const RateControlInput* input, } #endif - // Set the initial bit rate value to what we're receiving the first second + // Set the initial bit rate value to what we're receiving the first half + // second. if (!_initializedBitRate) { if (_timeFirstIncomingEstimate < 0) @@ -153,7 +154,7 @@ RateControlRegion RemoteRateControl::Update(const RateControlInput* input, _timeFirstIncomingEstimate = nowMS; } } - else if (nowMS - _timeFirstIncomingEstimate > 1000 && + else if (nowMS - _timeFirstIncomingEstimate > 500 && input->_incomingBitRate > 0) { _currentBitRate = input->_incomingBitRate;