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

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

Issue 2577463002: Avoid precision loss in TrendlineEstimator from int64_t -> double conversion (Closed)
Patch Set: Move test function to anonymous namespace 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
« no previous file with comments | « no previous file | webrtc/modules/congestion_controller/trendline_estimator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_ 10 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_
11 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_ 11 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_
12 12
13 #include <stddef.h>
14 #include <stdint.h>
15
13 #include <list> 16 #include <list>
14 #include <utility> 17 #include <utility>
15 18
16 #include "webrtc/base/constructormagic.h" 19 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/common_types.h"
18 20
19 namespace webrtc { 21 namespace webrtc {
20 22
21 class TrendlineEstimator { 23 class TrendlineEstimator {
22 public: 24 public:
23 // |window_size| is the number of points required to compute a trend line. 25 // |window_size| is the number of points required to compute a trend line.
24 // |smoothing_coef| controls how much we smooth out the delay before fitting 26 // |smoothing_coef| controls how much we smooth out the delay before fitting
25 // the trend line. |threshold_gain| is used to scale the trendline slope for 27 // the trend line. |threshold_gain| is used to scale the trendline slope for
26 // comparison to the old threshold. Once the old estimator has been removed 28 // comparison to the old threshold. Once the old estimator has been removed
27 // (or the thresholds been merged into the estimators), we can just set the 29 // (or the thresholds been merged into the estimators), we can just set the
28 // threshold instead of setting a gain. 30 // threshold instead of setting a gain.
29 TrendlineEstimator(size_t window_size, 31 TrendlineEstimator(size_t window_size,
30 double smoothing_coef, 32 double smoothing_coef,
31 double threshold_gain); 33 double threshold_gain);
32 ~TrendlineEstimator(); 34 ~TrendlineEstimator();
33 35
34 // Update the estimator with a new sample. The deltas should represent deltas 36 // Update the estimator with a new sample. The deltas should represent deltas
35 // between timestamp groups as defined by the InterArrival class. 37 // between timestamp groups as defined by the InterArrival class.
36 void Update(double recv_delta_ms, double send_delta_ms, double now_ms); 38 void Update(double recv_delta_ms,
39 double send_delta_ms,
40 int64_t arrival_time_ms);
37 41
38 // Returns the estimated trend k multiplied by some gain. 42 // Returns the estimated trend k multiplied by some gain.
39 // 0 < k < 1 -> the delay increases, queues are filling up 43 // 0 < k < 1 -> the delay increases, queues are filling up
40 // k == 0 -> the delay does not change 44 // k == 0 -> the delay does not change
41 // k < 0 -> the delay decreases, queues are being emptied 45 // k < 0 -> the delay decreases, queues are being emptied
42 double trendline_slope() const { return trendline_ * threshold_gain_; } 46 double trendline_slope() const { return trendline_ * threshold_gain_; }
43 47
44 // Returns the number of deltas which the current estimator state is based on. 48 // Returns the number of deltas which the current estimator state is based on.
45 unsigned int num_of_deltas() const { return num_of_deltas_; } 49 unsigned int num_of_deltas() const { return num_of_deltas_; }
46 50
47 private: 51 private:
48 // Parameters. 52 // Parameters.
49 const size_t window_size_; 53 const size_t window_size_;
50 const double smoothing_coef_; 54 const double smoothing_coef_;
51 const double threshold_gain_; 55 const double threshold_gain_;
52 // Used by the existing threshold. 56 // Used by the existing threshold.
53 unsigned int num_of_deltas_; 57 unsigned int num_of_deltas_;
58 // Keep the arrival times small by using the change from the first packet.
59 int64_t first_arrival_time_ms;
54 // Exponential backoff filtering. 60 // Exponential backoff filtering.
55 double accumulated_delay_; 61 double accumulated_delay_;
56 double smoothed_delay_; 62 double smoothed_delay_;
57 // Linear least squares regression. 63 // Linear least squares regression.
58 std::list<std::pair<double, double>> delay_hist_; 64 std::list<std::pair<double, double>> delay_hist_;
59 double trendline_; 65 double trendline_;
60 66
61 RTC_DISALLOW_COPY_AND_ASSIGN(TrendlineEstimator); 67 RTC_DISALLOW_COPY_AND_ASSIGN(TrendlineEstimator);
62 }; 68 };
63 } // namespace webrtc 69 } // namespace webrtc
64 70
65 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_ 71 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_TRENDLINE_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/congestion_controller/trendline_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698