| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cfddb3fd754a02cea83fec5a633a50791bf6f52b
|
| --- /dev/null
|
| +++ b/webrtc/modules/congestion_controller/trendline_estimator.cc
|
| @@ -0,0 +1,82 @@
|
| +/*
|
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include "webrtc/modules/congestion_controller/trendline_estimator.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "webrtc/base/logging.h"
|
| +#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
|
| +#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +enum { kDeltaCounterMax = 1000 };
|
| +
|
| +TrendlineEstimator::TrendlineEstimator(size_t window_size,
|
| + double smoothing_coef,
|
| + double threshold_gain)
|
| + : window_size_(window_size),
|
| + smoothing_coef_(smoothing_coef),
|
| + threshold_gain_(threshold_gain),
|
| + num_of_deltas_(0),
|
| + accumulated_delay_(0),
|
| + smoothed_delay_(0),
|
| + last_smoothed_delay_(0),
|
| + accumulated_delay_hist_(),
|
| + sum_x_(0),
|
| + sum_y_(0),
|
| + sum_xy_(0),
|
| + sum_x2_(0),
|
| + trendline_(0) {}
|
| +
|
| +TrendlineEstimator::~TrendlineEstimator() {}
|
| +
|
| +void TrendlineEstimator::Update(double recv_delta_ms,
|
| + double send_delta_ms,
|
| + int64_t now_ms) {
|
| + const double delta_ms = recv_delta_ms - send_delta_ms;
|
| + ++num_of_deltas_;
|
| + if (num_of_deltas_ > kDeltaCounterMax) {
|
| + num_of_deltas_ = kDeltaCounterMax;
|
| + }
|
| +
|
| + // Exponential backoff filter.
|
| + accumulated_delay_ += delta_ms;
|
| + BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", now_ms, accumulated_delay_);
|
| + last_smoothed_delay_ = smoothed_delay_;
|
| + smoothed_delay_ = smoothing_coef_ * smoothed_delay_ +
|
| + (1 - smoothing_coef_) * accumulated_delay_;
|
| + BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", now_ms, smoothed_delay_);
|
| +
|
| + // Simple linear regression.
|
| + accumulated_delay_hist_.push_back(std::make_pair(now_ms, smoothed_delay_));
|
| + sum_x_ += now_ms;
|
| + sum_y_ += smoothed_delay_;
|
| + sum_xy_ += static_cast<double>(now_ms) * static_cast<double>(smoothed_delay_);
|
| + sum_x2_ += static_cast<double>(now_ms) * static_cast<double>(now_ms);
|
| + if (accumulated_delay_hist_.size() > window_size_) {
|
| + sum_x_ -= accumulated_delay_hist_.front().first;
|
| + sum_y_ -= accumulated_delay_hist_.front().second;
|
| + sum_xy_ -= static_cast<double>(accumulated_delay_hist_.front().first) *
|
| + static_cast<double>(accumulated_delay_hist_.front().second);
|
| + sum_x2_ -= static_cast<double>(accumulated_delay_hist_.front().first) *
|
| + static_cast<double>(accumulated_delay_hist_.front().first);
|
| + accumulated_delay_hist_.pop_front();
|
| + }
|
| + if (accumulated_delay_hist_.size() == window_size_) {
|
| + trendline_ = (window_size_ * sum_xy_ - sum_x_ * sum_y_) /
|
| + (window_size_ * sum_x2_ - sum_x_ * sum_x_);
|
| + }
|
| +
|
| + BWE_TEST_LOGGING_PLOT(1, "trendline_slope", now_ms, trendline_);
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|