diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index 996ea995c2..d133159498 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -144,12 +144,6 @@ const int MINIMUM_RTT = 100; // 0.1 seconds const int MAXIMUM_RTT = 60000; // 60 seconds const int DEFAULT_RTT_ESTIMATE_HALF_TIME_MS = 500; - -// Computes our estimate of the RTT given the current estimate. -inline int ConservativeRTTEstimate(int rtt) { - return rtc::SafeClamp(2 * rtt, MINIMUM_RTT, MAXIMUM_RTT); -} - // Weighting of the old rtt value to new data. const int RTT_RATIO = 3; // 3 : 1 @@ -919,7 +913,8 @@ void Connection::UpdateState(int64_t now) { if (!port_) return; - int rtt = ConservativeRTTEstimate(rtt_); + // Computes our estimate of the RTT given the current estimate. + int rtt = rtc::SafeClamp(2 * rtt_, MINIMUM_RTT, MAXIMUM_RTT); if (RTC_LOG_CHECK_LEVEL(LS_VERBOSE)) { std::string pings; @@ -1183,8 +1178,10 @@ void Connection::ReceivedPingResponse( UpdateReceiving(last_ping_response_received_); set_write_state(STATE_WRITABLE); set_state(IceCandidatePairState::SUCCEEDED); + + // Smooth the RTT estimate using a moving average. if (rtt_samples_ > 0) { - rtt_ = rtc::GetNextMovingAverage(rtt_, rtt, RTT_RATIO); + rtt_ = (RTT_RATIO * rtt_ + rtt) / (RTT_RATIO + 1); } else { rtt_ = rtt; } diff --git a/rtc_base/helpers.cc b/rtc_base/helpers.cc index 84cbe5fba1..5aca40c7aa 100644 --- a/rtc_base/helpers.cc +++ b/rtc_base/helpers.cc @@ -224,8 +224,4 @@ double CreateRandomDouble() { std::numeric_limits::epsilon()); } -double GetNextMovingAverage(double prev_average, double cur, double ratio) { - return (ratio * prev_average + cur) / (ratio + 1); -} - } // namespace rtc diff --git a/rtc_base/helpers.h b/rtc_base/helpers.h index 51ca672ab5..095a645e28 100644 --- a/rtc_base/helpers.h +++ b/rtc_base/helpers.h @@ -83,10 +83,6 @@ uint32_t CreateRandomNonZeroId(); // Generates a random double between 0.0 (inclusive) and 1.0 (exclusive). double CreateRandomDouble(); -// Compute moving average with the given ratio between the previous average -// value and the current value. -double GetNextMovingAverage(double prev_average, double cur, double ratio); - } // namespace rtc #endif // RTC_BASE_HELPERS_H_