From f3fcde36c2593ce98d7f2d98a1b72f4932863b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Terelius?= Date: Tue, 19 Nov 2019 16:22:47 +0100 Subject: [PATCH] Store delay measurements as struct instead of std::pair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: None Change-Id: I60f375cda4f910550a86d2238acf39d429e2a17b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160004 Commit-Queue: Björn Terelius Reviewed-by: Philip Eliasson Cr-Commit-Position: refs/heads/master@{#29837} --- .../goog_cc/trendline_estimator.cc | 26 ++++++++++--------- .../goog_cc/trendline_estimator.h | 11 ++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/congestion_controller/goog_cc/trendline_estimator.cc b/modules/congestion_controller/goog_cc/trendline_estimator.cc index d8d984ead9..8f4f13382b 100644 --- a/modules/congestion_controller/goog_cc/trendline_estimator.cc +++ b/modules/congestion_controller/goog_cc/trendline_estimator.cc @@ -52,23 +52,25 @@ size_t ReadTrendlineFilterWindowSize( } absl::optional LinearFitSlope( - const std::deque>& points) { - RTC_DCHECK(points.size() >= 2); + const std::deque& packets) { + RTC_DCHECK(packets.size() >= 2); // Compute the "center of mass". double sum_x = 0; double sum_y = 0; - for (const auto& point : points) { - sum_x += point.first; - sum_y += point.second; + for (const auto& packet : packets) { + sum_x += packet.arrival_time_ms; + sum_y += packet.smoothed_delay_ms; } - double x_avg = sum_x / points.size(); - double y_avg = sum_y / points.size(); + double x_avg = sum_x / packets.size(); + double y_avg = sum_y / packets.size(); // Compute the slope k = \sum (x_i-x_avg)(y_i-y_avg) / \sum (x_i-x_avg)^2 double numerator = 0; double denominator = 0; - for (const auto& point : points) { - numerator += (point.first - x_avg) * (point.second - y_avg); - denominator += (point.first - x_avg) * (point.first - x_avg); + for (const auto& packet : packets) { + double x = packet.arrival_time_ms; + double y = packet.smoothed_delay_ms; + numerator += (x - x_avg) * (y - y_avg); + denominator += (x - x_avg) * (x - x_avg); } if (denominator == 0) return absl::nullopt; @@ -138,9 +140,9 @@ void TrendlineEstimator::UpdateTrendline(double recv_delta_ms, smoothed_delay_); // Simple linear regression. - delay_hist_.push_back(std::make_pair( + delay_hist_.emplace_back( static_cast(arrival_time_ms - first_arrival_time_ms_), - smoothed_delay_)); + smoothed_delay_); if (delay_hist_.size() > window_size_) delay_hist_.pop_front(); double trend = prev_trend_; diff --git a/modules/congestion_controller/goog_cc/trendline_estimator.h b/modules/congestion_controller/goog_cc/trendline_estimator.h index 0f70943fe5..5bec23b1d8 100644 --- a/modules/congestion_controller/goog_cc/trendline_estimator.h +++ b/modules/congestion_controller/goog_cc/trendline_estimator.h @@ -49,9 +49,16 @@ class TrendlineEstimator : public DelayIncreaseDetectorInterface { BandwidthUsage State() const override; + struct PacketTiming { + PacketTiming(double arrival_time_ms, double smoothed_delay_ms) + : arrival_time_ms(arrival_time_ms), + smoothed_delay_ms(smoothed_delay_ms) {} + double arrival_time_ms; + double smoothed_delay_ms; + }; + private: friend class GoogCcStatePrinter; - void Detect(double trend, double ts_delta, int64_t now_ms); void UpdateThreshold(double modified_offset, int64_t now_ms); @@ -68,7 +75,7 @@ class TrendlineEstimator : public DelayIncreaseDetectorInterface { double accumulated_delay_; double smoothed_delay_; // Linear least squares regression. - std::deque> delay_hist_; + std::deque delay_hist_; const double k_up_; const double k_down_;