Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Unified Diff: webrtc/modules/congestion_controller/trendline_estimator.cc

Issue 2582513002: Revert of Avoid precision loss in TrendlineEstimator from int64_t -> double conversion (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/congestion_controller/trendline_estimator.cc
diff --git a/webrtc/modules/congestion_controller/trendline_estimator.cc b/webrtc/modules/congestion_controller/trendline_estimator.cc
index ad05a64e1e0262c480d202331d91f5a3cc0ba9d5..a086f6aaa1bae4055caddaa77fa3d48962f7bcdf 100644
--- a/webrtc/modules/congestion_controller/trendline_estimator.cc
+++ b/webrtc/modules/congestion_controller/trendline_estimator.cc
@@ -13,14 +13,12 @@
#include <algorithm>
#include "webrtc/base/checks.h"
-#include "webrtc/base/optional.h"
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
namespace webrtc {
namespace {
-rtc::Optional<double> LinearFitSlope(
- const std::list<std::pair<double, double>> points) {
+double LinearFitSlope(const std::list<std::pair<double, double>> points) {
RTC_DCHECK(points.size() >= 2);
// Compute the "center of mass".
double sum_x = 0;
@@ -38,9 +36,7 @@
numerator += (point.first - x_avg) * (point.second - y_avg);
denominator += (point.first - x_avg) * (point.first - x_avg);
}
- if (denominator == 0)
- return rtc::Optional<double>();
- return rtc::Optional<double>(numerator / denominator);
+ return numerator / denominator;
}
} // namespace
@@ -53,7 +49,6 @@
smoothing_coef_(smoothing_coef),
threshold_gain_(threshold_gain),
num_of_deltas_(0),
- first_arrival_time_ms(-1),
accumulated_delay_(0),
smoothed_delay_(0),
delay_hist_(),
@@ -63,35 +58,30 @@
void TrendlineEstimator::Update(double recv_delta_ms,
double send_delta_ms,
- int64_t arrival_time_ms) {
+ double now_ms) {
const double delta_ms = recv_delta_ms - send_delta_ms;
++num_of_deltas_;
- if (num_of_deltas_ > kDeltaCounterMax)
+ if (num_of_deltas_ > kDeltaCounterMax) {
num_of_deltas_ = kDeltaCounterMax;
- if (first_arrival_time_ms == -1)
- first_arrival_time_ms = arrival_time_ms;
+ }
// Exponential backoff filter.
accumulated_delay_ += delta_ms;
- BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", arrival_time_ms,
- accumulated_delay_);
+ BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", now_ms, accumulated_delay_);
smoothed_delay_ = smoothing_coef_ * smoothed_delay_ +
(1 - smoothing_coef_) * accumulated_delay_;
- BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", arrival_time_ms,
- smoothed_delay_);
+ BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", now_ms, smoothed_delay_);
// Simple linear regression.
- delay_hist_.push_back(std::make_pair(
- static_cast<double>(arrival_time_ms - first_arrival_time_ms),
- smoothed_delay_));
- if (delay_hist_.size() > window_size_)
+ delay_hist_.push_back(std::make_pair(now_ms, smoothed_delay_));
+ if (delay_hist_.size() > window_size_) {
delay_hist_.pop_front();
+ }
if (delay_hist_.size() == window_size_) {
- // Only update trendline_ if it is possible to fit a line to the data.
- trendline_ = LinearFitSlope(delay_hist_).value_or(trendline_);
+ trendline_ = LinearFitSlope(delay_hist_);
}
- BWE_TEST_LOGGING_PLOT(1, "trendline_slope", arrival_time_ms, trendline_);
+ BWE_TEST_LOGGING_PLOT(1, "trendline_slope", now_ms, trendline_);
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698