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

Side by Side Diff: webrtc/modules/congestion_controller/median_slope_estimator.h

Issue 2512693002: Implement Theil-Sen's method for fitting a line to noisy data (used in bandwidth estimation). (Closed)
Patch Set: Remove PercentileFilter::Clear since no longer used. 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_MEDIAN_SLOPE_ESTIMATOR_H_
11 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_MEDIAN_SLOPE_ESTIMATOR_H_
12
13 #include <list>
14 #include <utility>
15 #include <vector>
16
17 #include "webrtc/base/analytics/percentile_filter.h"
18 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/common_types.h"
20
21 namespace webrtc {
22
23 class MedianSlopeEstimator {
24 public:
25 // |window_size| is the number of points required to compute a trend line.
26 // |threshold_gain| is used to scale the trendline slope for comparison to
27 // the old threshold. Once the old estimator has been removed (or the
28 // thresholds been merged into the estimators), we can just set the
29 // threshold instead of setting a gain.
30 MedianSlopeEstimator(size_t window_size, double threshold_gain);
31 ~MedianSlopeEstimator();
32
33 // Update the estimator with a new sample. The deltas should represent deltas
34 // between timestamp groups as defined by the InterArrival class.
35 void Update(double recv_delta_ms, double send_delta_ms, double now_ms);
36
37 // Returns the estimated trend k multiplied by some gain.
38 // 0 < k < 1 -> the delay increases, queues are filling up
39 // k == 0 -> the delay does not change
40 // k < 0 -> the delay decreases, queues are being emptied
41 double trendline_slope() const { return trendline_ * threshold_gain_; }
42
43 // Returns the number of deltas which the current estimator state is based on.
44 unsigned int num_of_deltas() const { return num_of_deltas_; }
45
46 private:
47 struct DelayInfo {
48 DelayInfo(double time, double delay, size_t slope_count)
49 : time(time), delay(delay) {
50 slopes.reserve(slope_count);
51 }
52 double time;
53 double delay;
54 std::vector<double> slopes;
55 };
56 // Parameters.
57 const size_t window_size_;
58 const double threshold_gain_;
59 // Used by the existing threshold.
60 unsigned int num_of_deltas_;
61 // Theil-Sen robust line fitting
62 double accumulated_delay_;
63 std::list<DelayInfo> delay_hist_;
64 PercentileFilter<double> median_filter_;
65 double trendline_;
66
67 RTC_DISALLOW_COPY_AND_ASSIGN(MedianSlopeEstimator);
68 };
69 } // namespace webrtc
70
71 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_MEDIAN_SLOPE_ESTIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698