Store delay measurements as struct instead of std::pair

Bug: None
Change-Id: I60f375cda4f910550a86d2238acf39d429e2a17b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160004
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29837}
diff --git a/modules/congestion_controller/goog_cc/trendline_estimator.cc b/modules/congestion_controller/goog_cc/trendline_estimator.cc
index d8d984e..8f4f133 100644
--- a/modules/congestion_controller/goog_cc/trendline_estimator.cc
+++ b/modules/congestion_controller/goog_cc/trendline_estimator.cc
@@ -52,23 +52,25 @@
 }
 
 absl::optional<double> LinearFitSlope(
-    const std::deque<std::pair<double, double>>& points) {
-  RTC_DCHECK(points.size() >= 2);
+    const std::deque<TrendlineEstimator::PacketTiming>& 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 @@
                         smoothed_delay_);
 
   // Simple linear regression.
-  delay_hist_.push_back(std::make_pair(
+  delay_hist_.emplace_back(
       static_cast<double>(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 0f70943..5bec23b 100644
--- a/modules/congestion_controller/goog_cc/trendline_estimator.h
+++ b/modules/congestion_controller/goog_cc/trendline_estimator.h
@@ -49,9 +49,16 @@
 
   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 @@
   double accumulated_delay_;
   double smoothed_delay_;
   // Linear least squares regression.
-  std::deque<std::pair<double, double>> delay_hist_;
+  std::deque<PacketTiming> delay_hist_;
 
   const double k_up_;
   const double k_down_;