diff --git a/modules/congestion_controller/goog_cc/BUILD.gn b/modules/congestion_controller/goog_cc/BUILD.gn index 90af511451..fa95bc186c 100644 --- a/modules/congestion_controller/goog_cc/BUILD.gn +++ b/modules/congestion_controller/goog_cc/BUILD.gn @@ -113,8 +113,6 @@ rtc_library("estimators") { "bitrate_estimator.cc", "bitrate_estimator.h", "delay_increase_detector_interface.h", - "median_slope_estimator.cc", - "median_slope_estimator.h", "probe_bitrate_estimator.cc", "probe_bitrate_estimator.h", "robust_throughput_estimator.cc", @@ -256,7 +254,6 @@ if (rtc_include_tests) { "delay_based_bwe_unittest_helper.cc", "delay_based_bwe_unittest_helper.h", "goog_cc_network_control_unittest.cc", - "median_slope_estimator_unittest.cc", "probe_bitrate_estimator_unittest.cc", "probe_controller_unittest.cc", "robust_throughput_estimator_unittest.cc", diff --git a/modules/congestion_controller/goog_cc/median_slope_estimator.cc b/modules/congestion_controller/goog_cc/median_slope_estimator.cc deleted file mode 100644 index 45d2fe3211..0000000000 --- a/modules/congestion_controller/goog_cc/median_slope_estimator.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 "modules/congestion_controller/goog_cc/median_slope_estimator.h" - -#include - -#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" -#include "rtc_base/checks.h" - -namespace webrtc { - -constexpr unsigned int kDeltaCounterMax = 1000; - -MedianSlopeEstimator::MedianSlopeEstimator(size_t window_size, - double threshold_gain) - : window_size_(window_size), - threshold_gain_(threshold_gain), - num_of_deltas_(0), - accumulated_delay_(0), - delay_hist_(), - median_filter_(0.5), - trendline_(0) {} - -MedianSlopeEstimator::~MedianSlopeEstimator() {} - -MedianSlopeEstimator::DelayInfo::DelayInfo(int64_t time, - double delay, - size_t slope_count) - : time(time), delay(delay) { - slopes.reserve(slope_count); -} - -MedianSlopeEstimator::DelayInfo::~DelayInfo() = default; - -void MedianSlopeEstimator::Update(double recv_delta_ms, - double send_delta_ms, - int64_t arrival_time_ms) { - const double delta_ms = recv_delta_ms - send_delta_ms; - ++num_of_deltas_; - if (num_of_deltas_ > kDeltaCounterMax) - num_of_deltas_ = kDeltaCounterMax; - - accumulated_delay_ += delta_ms; - BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", arrival_time_ms, - accumulated_delay_); - - // If the window is full, remove the |window_size_| - 1 slopes that belong to - // the oldest point. - if (delay_hist_.size() == window_size_) { - for (double slope : delay_hist_.front().slopes) { - const bool success = median_filter_.Erase(slope); - RTC_CHECK(success); - } - delay_hist_.pop_front(); - } - // Add |window_size_| - 1 new slopes. - for (auto& old_delay : delay_hist_) { - if (arrival_time_ms - old_delay.time != 0) { - // The C99 standard explicitly states that casts and assignments must - // perform the associated conversions. This means that |slope| will be - // a 64-bit double even if the division is computed using, e.g., 80-bit - // extended precision. I believe this also holds in C++ even though the - // C++11 standard isn't as explicit. Furthermore, there are good reasons - // to believe that compilers couldn't perform optimizations that break - // this assumption even if they wanted to. - double slope = (accumulated_delay_ - old_delay.delay) / - static_cast(arrival_time_ms - old_delay.time); - median_filter_.Insert(slope); - // We want to avoid issues with different rounding mode / precision - // which we might get if we recomputed the slope when we remove it. - old_delay.slopes.push_back(slope); - } - } - delay_hist_.emplace_back(arrival_time_ms, accumulated_delay_, - window_size_ - 1); - // Recompute the median slope. - if (delay_hist_.size() == window_size_) - trendline_ = median_filter_.GetPercentileValue(); - - BWE_TEST_LOGGING_PLOT(1, "trendline_slope", arrival_time_ms, trendline_); -} - -} // namespace webrtc diff --git a/modules/congestion_controller/goog_cc/median_slope_estimator.h b/modules/congestion_controller/goog_cc/median_slope_estimator.h deleted file mode 100644 index 3f1e3f5063..0000000000 --- a/modules/congestion_controller/goog_cc/median_slope_estimator.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ -#ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_MEDIAN_SLOPE_ESTIMATOR_H_ -#define MODULES_CONGESTION_CONTROLLER_GOOG_CC_MEDIAN_SLOPE_ESTIMATOR_H_ - -#include -#include - -#include -#include - -#include "rtc_base/constructor_magic.h" -#include "rtc_base/numerics/percentile_filter.h" - -namespace webrtc { - -class MedianSlopeEstimator { - public: - // |window_size| is the number of points required to compute a trend line. - // |threshold_gain| is used to scale the trendline slope for comparison to - // the old threshold. Once the old estimator has been removed (or the - // thresholds been merged into the estimators), we can just set the - // threshold instead of setting a gain. - MedianSlopeEstimator(size_t window_size, double threshold_gain); - ~MedianSlopeEstimator(); - - // Update the estimator with a new sample. The deltas should represent deltas - // between timestamp groups as defined by the InterArrival class. - void Update(double recv_delta_ms, - double send_delta_ms, - int64_t arrival_time_ms); - - // Returns the estimated trend k multiplied by some gain. - // 0 < k < 1 -> the delay increases, queues are filling up - // k == 0 -> the delay does not change - // k < 0 -> the delay decreases, queues are being emptied - double trendline_slope() const { return trendline_ * threshold_gain_; } - - // Returns the number of deltas which the current estimator state is based on. - unsigned int num_of_deltas() const { return num_of_deltas_; } - - private: - struct DelayInfo { - DelayInfo(int64_t time, double delay, size_t slope_count); - ~DelayInfo(); - int64_t time; - double delay; - std::vector slopes; - }; - // Parameters. - const size_t window_size_; - const double threshold_gain_; - // Used by the existing threshold. - unsigned int num_of_deltas_; - // Theil-Sen robust line fitting - double accumulated_delay_; - std::deque delay_hist_; - PercentileFilter median_filter_; - double trendline_; - - RTC_DISALLOW_COPY_AND_ASSIGN(MedianSlopeEstimator); -}; - -} // namespace webrtc - -#endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_MEDIAN_SLOPE_ESTIMATOR_H_ diff --git a/modules/congestion_controller/goog_cc/median_slope_estimator_unittest.cc b/modules/congestion_controller/goog_cc/median_slope_estimator_unittest.cc deleted file mode 100644 index a0df9fd835..0000000000 --- a/modules/congestion_controller/goog_cc/median_slope_estimator_unittest.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 "modules/congestion_controller/goog_cc/median_slope_estimator.h" - -#include "rtc_base/random.h" -#include "test/gtest.h" - -namespace webrtc { - -namespace { -constexpr size_t kWindowSize = 20; -constexpr double kGain = 1; -constexpr int64_t kAvgTimeBetweenPackets = 10; -constexpr size_t kPacketCount = 2 * kWindowSize + 1; - -void TestEstimator(double slope, double jitter_stddev, double tolerance) { - MedianSlopeEstimator estimator(kWindowSize, kGain); - Random random(0x1234567); - int64_t send_times[kPacketCount]; - int64_t recv_times[kPacketCount]; - int64_t send_start_time = random.Rand(1000000); - int64_t recv_start_time = random.Rand(1000000); - for (size_t i = 0; i < kPacketCount; ++i) { - send_times[i] = send_start_time + i * kAvgTimeBetweenPackets; - double latency = i * kAvgTimeBetweenPackets / (1 - slope); - double jitter = random.Gaussian(0, jitter_stddev); - recv_times[i] = recv_start_time + latency + jitter; - } - for (size_t i = 1; i < kPacketCount; ++i) { - double recv_delta = recv_times[i] - recv_times[i - 1]; - double send_delta = send_times[i] - send_times[i - 1]; - estimator.Update(recv_delta, send_delta, recv_times[i]); - if (i < kWindowSize) - EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); - else - EXPECT_NEAR(estimator.trendline_slope(), slope, tolerance); - } -} -} // namespace - -TEST(MedianSlopeEstimator, PerfectLineSlopeOneHalf) { - TestEstimator(0.5, 0, 0.001); -} - -TEST(MedianSlopeEstimator, PerfectLineSlopeMinusOne) { - TestEstimator(-1, 0, 0.001); -} - -TEST(MedianSlopeEstimator, PerfectLineSlopeZero) { - TestEstimator(0, 0, 0.001); -} - -TEST(MedianSlopeEstimator, JitteryLineSlopeOneHalf) { - TestEstimator(0.5, kAvgTimeBetweenPackets / 3.0, 0.01); -} - -TEST(MedianSlopeEstimator, JitteryLineSlopeMinusOne) { - TestEstimator(-1, kAvgTimeBetweenPackets / 3.0, 0.05); -} - -TEST(MedianSlopeEstimator, JitteryLineSlopeZero) { - TestEstimator(0, kAvgTimeBetweenPackets / 3.0, 0.02); -} - -} // namespace webrtc