From 7b087121b5aaa83eb683bf33be6cffa69d90adb2 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Thu, 23 May 2024 10:29:36 -0700 Subject: [PATCH] Move moving average helper out of ssl target to the only place where it is used. BUG=webrtc:339300437 Change-Id: I0d4124b95d19a11578efaf7e8e0a1ff1d39eb59b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/351581 Reviewed-by: Harald Alvestrand Reviewed-by: Mirko Bonadei Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/main@{#42383} --- p2p/base/connection.cc | 13 +++++-------- rtc_base/helpers.cc | 4 ---- rtc_base/helpers.h | 4 ---- 3 files changed, 5 insertions(+), 16 deletions(-) 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_