OLD | NEW |
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 | 10 |
11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ | 11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ | 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <utility> | 15 #include <utility> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/thread_checker.h" | 20 #include "webrtc/base/thread_checker.h" |
| 21 #include "webrtc/modules/congestion_controller/incoming_bitrate_estimator.h" |
21 #include "webrtc/modules/congestion_controller/median_slope_estimator.h" | 22 #include "webrtc/modules/congestion_controller/median_slope_estimator.h" |
22 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" | 23 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
23 #include "webrtc/modules/congestion_controller/trendline_estimator.h" | 24 #include "webrtc/modules/congestion_controller/trendline_estimator.h" |
24 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | 25 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
25 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
26 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" | 27 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
27 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" | 28 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
28 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" | 29 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
29 | 30 |
30 namespace webrtc { | 31 namespace webrtc { |
31 | 32 |
32 class RtcEventLog; | 33 class RtcEventLog; |
33 | 34 |
34 class DelayBasedBwe { | 35 class DelayBasedBwe { |
35 public: | 36 public: |
36 static const int64_t kStreamTimeOutMs = 2000; | 37 static const int64_t kStreamTimeOutMs = 2000; |
37 | 38 |
38 struct Result { | 39 struct Result { |
39 Result() : updated(false), probe(false), target_bitrate_bps(0) {} | 40 Result() : updated(false), probe(false), target_bitrate_bps(0) {} |
40 Result(bool probe, uint32_t target_bitrate_bps) | 41 Result(bool probe, uint32_t target_bitrate_bps) |
41 : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {} | 42 : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {} |
42 bool updated; | 43 bool updated; |
43 bool probe; | 44 bool probe; |
44 uint32_t target_bitrate_bps; | 45 uint32_t target_bitrate_bps; |
45 }; | 46 }; |
46 | 47 |
47 DelayBasedBwe(RtcEventLog* event_log, const Clock* clock); | 48 DelayBasedBwe(RtcEventLog* event_log, |
| 49 IncomingBitrateEstimator* const receiver_incoming_bitrate, |
| 50 const Clock* clock); |
48 virtual ~DelayBasedBwe(); | 51 virtual ~DelayBasedBwe(); |
49 | 52 |
50 Result IncomingPacketFeedbackVector( | 53 Result IncomingPacketFeedbackVector( |
51 const std::vector<PacketFeedback>& packet_feedback_vector); | 54 const std::vector<PacketFeedback>& packet_feedback_vector); |
52 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms); | 55 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms); |
53 bool LatestEstimate(std::vector<uint32_t>* ssrcs, | 56 bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
54 uint32_t* bitrate_bps) const; | 57 uint32_t* bitrate_bps) const; |
55 void SetStartBitrate(int start_bitrate_bps); | 58 void SetStartBitrate(int start_bitrate_bps); |
56 void SetMinBitrate(int min_bitrate_bps); | 59 void SetMinBitrate(int min_bitrate_bps); |
57 int64_t GetExpectedBwePeriodMs() const; | 60 int64_t GetExpectedBwePeriodMs() const; |
58 | 61 |
59 private: | 62 private: |
60 // Computes a bayesian estimate of the throughput given acks containing | |
61 // the arrival time and payload size. Samples which are far from the current | |
62 // estimate or are based on few packets are given a smaller weight, as they | |
63 // are considered to be more likely to have been caused by, e.g., delay spikes | |
64 // unrelated to congestion. | |
65 class BitrateEstimator { | |
66 public: | |
67 BitrateEstimator(); | |
68 void Update(int64_t now_ms, int bytes); | |
69 rtc::Optional<uint32_t> bitrate_bps() const; | |
70 | |
71 private: | |
72 float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms); | |
73 int sum_; | |
74 int64_t current_win_ms_; | |
75 int64_t prev_time_ms_; | |
76 float bitrate_estimate_; | |
77 float bitrate_estimate_var_; | |
78 }; | |
79 | |
80 void IncomingPacketFeedback(const PacketFeedback& packet_feedback); | 63 void IncomingPacketFeedback(const PacketFeedback& packet_feedback); |
81 Result OnLongFeedbackDelay(int64_t arrival_time_ms); | 64 Result OnLongFeedbackDelay(int64_t arrival_time_ms); |
82 | 65 |
83 Result MaybeUpdateEstimate(bool overusing); | 66 Result MaybeUpdateEstimate(bool overusing); |
84 // Updates the current remote rate estimate and returns true if a valid | 67 // Updates the current remote rate estimate and returns true if a valid |
85 // estimate exists. | 68 // estimate exists. |
86 bool UpdateEstimate(int64_t now_ms, | 69 bool UpdateEstimate(int64_t now_ms, |
87 rtc::Optional<uint32_t> acked_bitrate_bps, | 70 rtc::Optional<uint32_t> acked_bitrate_bps, |
88 bool overusing, | 71 bool overusing, |
89 uint32_t* target_bitrate_bps); | 72 uint32_t* target_bitrate_bps); |
90 | 73 |
91 rtc::ThreadChecker network_thread_; | 74 rtc::ThreadChecker network_thread_; |
92 RtcEventLog* const event_log_; | 75 RtcEventLog* const event_log_; |
93 const Clock* const clock_; | 76 const Clock* const clock_; |
94 std::unique_ptr<InterArrival> inter_arrival_; | 77 std::unique_ptr<InterArrival> inter_arrival_; |
95 std::unique_ptr<TrendlineEstimator> trendline_estimator_; | 78 std::unique_ptr<TrendlineEstimator> trendline_estimator_; |
96 OveruseDetector detector_; | 79 OveruseDetector detector_; |
97 BitrateEstimator receiver_incoming_bitrate_; | 80 IncomingBitrateEstimator* const receiver_incoming_bitrate_; |
98 int64_t last_seen_packet_ms_; | 81 int64_t last_seen_packet_ms_; |
99 bool uma_recorded_; | 82 bool uma_recorded_; |
100 AimdRateControl rate_control_; | 83 AimdRateControl rate_control_; |
101 ProbeBitrateEstimator probe_bitrate_estimator_; | 84 ProbeBitrateEstimator probe_bitrate_estimator_; |
102 size_t trendline_window_size_; | 85 size_t trendline_window_size_; |
103 double trendline_smoothing_coeff_; | 86 double trendline_smoothing_coeff_; |
104 double trendline_threshold_gain_; | 87 double trendline_threshold_gain_; |
105 int consecutive_delayed_feedbacks_; | 88 int consecutive_delayed_feedbacks_; |
106 uint32_t last_logged_bitrate_; | 89 uint32_t last_logged_bitrate_; |
107 BandwidthUsage last_logged_state_; | 90 BandwidthUsage last_logged_state_; |
108 bool in_sparse_update_experiment_; | 91 bool in_sparse_update_experiment_; |
109 | 92 |
110 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); | 93 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
111 }; | 94 }; |
112 | 95 |
113 } // namespace webrtc | 96 } // namespace webrtc |
114 | 97 |
115 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ | 98 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
OLD | NEW |