OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 | 11 |
12 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ | 12 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ |
13 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ | 13 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ |
14 | 14 |
15 #include <list> | |
15 #include <map> | 16 #include <map> |
16 #include <memory> | 17 #include <memory> |
17 #include <vector> | 18 #include <vector> |
18 | 19 |
19 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h" |
21 #include "webrtc/modules/video_coding/sequence_number_util.h" | |
20 #include "webrtc/rtc_base/optional.h" | 22 #include "webrtc/rtc_base/optional.h" |
21 #include "webrtc/rtc_base/random.h" | 23 #include "webrtc/rtc_base/random.h" |
22 | 24 |
23 namespace webrtc { | 25 namespace webrtc { |
24 namespace testing { | 26 namespace testing { |
25 namespace bwe { | 27 namespace bwe { |
26 class MaxBandwidthFilter; | 28 class MaxBandwidthFilter; |
27 class MinRttFilter; | 29 class MinRttFilter; |
28 class CongestionWindow; | 30 class CongestionWindow; |
29 class BbrBweSender : public BweSender { | 31 class BbrBweSender : public BweSender { |
30 public: | 32 public: |
31 explicit BbrBweSender(Clock* clock); | 33 explicit BbrBweSender(Clock* clock); |
32 virtual ~BbrBweSender(); | 34 virtual ~BbrBweSender(); |
33 enum Mode { | 35 enum Mode { |
34 // Startup phase. | 36 // Startup phase. |
35 STARTUP, | 37 STARTUP, |
36 // Queue draining phase, which where created during startup. | 38 // Queue draining phase, which where created during startup. |
37 DRAIN, | 39 DRAIN, |
38 // Cruising, probing new bandwidth. | 40 // Cruising, probing new bandwidth. |
39 PROBE_BW, | 41 PROBE_BW, |
40 // Temporarily limiting congestion window size in order to measure | 42 // Temporarily limiting congestion window size in order to measure |
41 // minimum RTT. | 43 // minimum RTT. |
42 PROBE_RTT | 44 PROBE_RTT, |
45 // Temporarily reducing pacing rate and congestion window, in order to | |
46 // ensure no queues are built. | |
47 RECOVERY | |
43 }; | 48 }; |
49 | |
50 // For better understanding of what member variables stand for, let's name | |
51 // packets as follows: | |
52 // cur_packet - the packet for which PacketStats is stored. | |
53 // last_sent_packet - the last sent packet for the time when cur_packet was | |
54 // acked. | |
55 // last_acked_packet - the last acked packet for the time when cur_packet was | |
56 // sent. | |
44 struct PacketStats { | 57 struct PacketStats { |
45 PacketStats() {} | 58 PacketStats() {} |
46 PacketStats(int64_t send_time_, size_t payload_size_) | 59 PacketStats(uint16_t sequence_number_, |
47 : send_time(send_time_), payload_size(payload_size_) {} | 60 int64_t last_sent_packet_send_time_ms_, |
philipel
2017/08/08 11:54:54
I would suggest |time_last_sent_packet_ms_| or jus
gnish1
2017/08/08 13:19:56
In that case it isn't clear whether we mean send t
| |
48 | 61 int64_t send_time_ms_, |
49 int64_t send_time; | 62 int64_t ack_time_ms_, |
50 size_t payload_size; | 63 int64_t last_acked_packet_ack_time_ms_, |
64 size_t payload_size_bytes_, | |
65 size_t data_sent_bytes_, | |
66 size_t data_sent_before_last_sent_packet_bytes_, | |
67 size_t data_acked_bytes_, | |
68 size_t data_acked_before_last_acked_packet_bytes_) | |
69 : sequence_number(sequence_number_), | |
70 last_sent_packet_send_time_ms(last_sent_packet_send_time_ms_), | |
71 send_time_ms(send_time_ms_), | |
72 ack_time_ms(ack_time_ms_), | |
73 last_acked_packet_ack_time_ms(last_acked_packet_ack_time_ms_), | |
74 payload_size_bytes(payload_size_bytes_), | |
75 data_sent_bytes(data_sent_bytes_), | |
76 data_sent_before_last_sent_packet_bytes( | |
77 data_sent_before_last_sent_packet_bytes_), | |
78 data_acked_bytes(data_acked_bytes_), | |
79 data_acked_before_last_acked_packet_bytes( | |
80 data_acked_before_last_acked_packet_bytes_) {} | |
81 uint16_t sequence_number; | |
philipel
2017/08/08 11:54:54
To me it's still not clear what these member varia
gnish1
2017/08/08 13:19:56
Done.
| |
82 int64_t last_sent_packet_send_time_ms; | |
83 int64_t send_time_ms; | |
84 int64_t ack_time_ms; | |
85 int64_t last_acked_packet_ack_time_ms; | |
86 size_t payload_size_bytes; | |
87 size_t data_sent_bytes; | |
88 size_t data_sent_before_last_sent_packet_bytes; | |
89 size_t data_acked_bytes; | |
90 size_t data_acked_before_last_acked_packet_bytes; | |
91 }; | |
92 struct AverageRtt { | |
93 AverageRtt() {} | |
94 AverageRtt(int64_t sum_of_rtts_ms_, int64_t num_samples_, uint64_t round_) | |
95 : sum_of_rtts_ms(sum_of_rtts_ms_), | |
96 num_samples(num_samples_), | |
97 round(round_) {} | |
98 // Sum of rtts over the round. | |
99 int64_t sum_of_rtts_ms; | |
100 // Number of rtt samples over the round. | |
101 int64_t num_samples; | |
102 // The number of the round average rtt is recorded for. | |
103 uint64_t round; | |
51 }; | 104 }; |
52 void OnPacketsSent(const Packets& packets) override; | 105 void OnPacketsSent(const Packets& packets) override; |
53 int GetFeedbackIntervalMs() const override; | 106 int GetFeedbackIntervalMs() const override; |
54 void GiveFeedback(const FeedbackPacket& feedback) override; | 107 void GiveFeedback(const FeedbackPacket& feedback) override; |
55 int64_t TimeUntilNextProcess() override; | 108 int64_t TimeUntilNextProcess() override; |
56 void Process() override; | 109 void Process() override; |
57 | 110 |
58 private: | 111 private: |
59 void EnterStartup(); | 112 void EnterStartup(); |
60 bool UpdateBandwidthAndMinRtt(); | 113 bool UpdateBandwidthAndMinRtt(int64_t now_ms, |
114 const std::vector<uint64_t>& feedback_vector, | |
115 int64_t bytes_acked); | |
61 void TryExitingStartup(); | 116 void TryExitingStartup(); |
62 void TryExitingDrain(int64_t now_ms); | 117 void TryExitingDrain(int64_t now_ms); |
63 void EnterProbeBw(int64_t now_ms); | 118 void EnterProbeBw(int64_t now_ms); |
64 void TryUpdatingCyclePhase(int64_t now_ms); | 119 void TryUpdatingCyclePhase(int64_t now_ms); |
65 void TryEnteringProbeRtt(int64_t now_ms); | 120 void TryEnteringProbeRtt(int64_t now_ms); |
66 void TryExitingProbeRtt(int64_t now_ms, int64_t round); | 121 void TryExitingProbeRtt(int64_t now_ms, int64_t round); |
122 void TryEnteringRecovery(bool new_round_started); | |
123 void TryExitingRecovery(bool new_round_started); | |
67 size_t TargetCongestionWindow(float gain); | 124 size_t TargetCongestionWindow(float gain); |
125 void CalculatePacingRate(); | |
126 | |
127 // Calculates and returns bandwidth sample as minimum between send rate and | |
128 // ack rate, returns nothing if sample cannot be calculated. | |
129 rtc::Optional<int64_t> CalculateBandwidthSample(size_t data_sent, | |
130 int64_t send_time_delta_ms, | |
131 size_t data_acked, | |
132 int64_t ack_time_delta_ms); | |
133 | |
134 // Calculate and add bandwidth sample only for packets' sent during high gain | |
135 // phase. Motivation of having a seperate bucket for high gain phase is to | |
136 // achieve quicker ramp up. Slight overestimations may happen due to window | |
137 // not being as large as usual. | |
138 void AddSampleForHighGain(); | |
139 | |
140 // Declares lost packets as acked. Implements simple logic by looking at the | |
141 // gap between sequence numbers. If there is a gap between sequence numbers we | |
142 // declare those packets as lost immediately. | |
143 void HandleLoss(uint64_t last_acked_packet, uint64_t recently_acked_packet); | |
144 void AddToPastRtts(int64_t rtt_sample_ms); | |
68 Clock* const clock_; | 145 Clock* const clock_; |
69 Mode mode_; | 146 Mode mode_; |
70 std::unique_ptr<MaxBandwidthFilter> max_bandwidth_filter_; | 147 std::unique_ptr<MaxBandwidthFilter> max_bandwidth_filter_; |
71 std::unique_ptr<MinRttFilter> min_rtt_filter_; | 148 std::unique_ptr<MinRttFilter> min_rtt_filter_; |
72 std::unique_ptr<CongestionWindow> congestion_window_; | 149 std::unique_ptr<CongestionWindow> congestion_window_; |
73 std::unique_ptr<Random> rand_; | 150 std::unique_ptr<Random> rand_; |
74 uint64_t round_count_; | 151 uint64_t round_count_; |
75 uint64_t last_packet_sent_; | |
76 uint64_t round_trip_end_; | 152 uint64_t round_trip_end_; |
77 float pacing_gain_; | 153 float pacing_gain_; |
78 float congestion_window_gain_; | 154 float congestion_window_gain_; |
79 | 155 |
80 // If optimal bandwidth has been discovered and reached, (for example after | 156 // If optimal bandwidth has been discovered and reached, (for example after |
81 // Startup mode) set this variable to true. | 157 // Startup mode) set this variable to true. |
82 bool full_bandwidth_reached_; | 158 bool full_bandwidth_reached_; |
83 | 159 |
84 // Entering time for PROBE_BW mode's cycle phase. | 160 // Entering time for PROBE_BW mode's cycle phase. |
85 int64_t cycle_start_time_ms_; | 161 int64_t cycle_start_time_ms_; |
86 | 162 |
87 // Index number of the currently used gain value in PROBE_BW mode, from 0 to | 163 // Index number of the currently used gain value in PROBE_BW mode, from 0 to |
88 // kGainCycleLength - 1. | 164 // kGainCycleLength - 1. |
89 int64_t cycle_index_; | 165 int64_t cycle_index_; |
90 | 166 size_t bytes_acked_; |
91 // Data inflight prior to the moment when last feedback was received. | |
92 size_t prior_in_flight_; | 167 size_t prior_in_flight_; |
93 | 168 |
94 // Time we entered PROBE_RTT mode. | 169 // Time we entered PROBE_RTT mode. |
95 int64_t probe_rtt_start_time_ms_; | 170 int64_t probe_rtt_start_time_ms_; |
96 | 171 |
97 // First moment of time when data inflight decreased below | 172 // First moment of time when data inflight decreased below |
98 // kMinimumCongestionWindow in PROBE_RTT mode. | 173 // kMinimumCongestionWindow in PROBE_RTT mode. |
99 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_; | 174 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_; |
100 | 175 |
101 // First round when data inflight decreased below kMinimumCongestionWindow in | 176 // First round when data inflight decreased below kMinimumCongestionWindow in |
102 // PROBE_RTT mode. | 177 // PROBE_RTT mode. |
103 int64_t minimum_congestion_window_start_round_; | 178 int64_t minimum_congestion_window_start_round_; |
179 size_t bytes_sent_; | |
180 uint16_t last_packet_sent_sequence_number_; | |
181 uint16_t last_packet_acked_sequence_number_; | |
182 int64_t last_packet_ack_time_; | |
183 int64_t last_packet_send_time_; | |
184 int64_t pacing_rate_bps_; | |
185 | |
186 // Send time of a packet sent first during high gain phase. Also serves as a | |
187 // flag, holding value means that we are already in high gain. | |
188 rtc::Optional<int64_t> first_packet_send_time_during_high_gain_ms_; | |
189 | |
190 // Send time of a packet sent last during high gain phase. | |
191 int64_t last_packet_send_time_during_high_gain_ms_; | |
192 | |
193 // Amount of data sent, before first packet was sent during high gain phase. | |
194 int64_t data_sent_before_high_gain_started_bytes_; | |
195 | |
196 // Amount of data sent, before last packet was sent during high gain phase. | |
197 int64_t data_sent_before_high_gain_ended_bytes_; | |
198 | |
199 // Ack time of a packet acked first during high gain phase. | |
200 int64_t first_packet_ack_time_during_high_gain_ms_; | |
201 | |
202 // Ack time of a packet acked last during high gain phase. | |
203 int64_t last_packet_ack_time_during_high_gain_ms_; | |
204 | |
205 // Amount of data acked, before the first packet was acked during high gain | |
206 // phase. | |
207 int64_t data_acked_before_high_gain_started_bytes_; | |
208 | |
209 // Amount of data acked, before the last packet was acked during high gain | |
210 // phase. | |
211 int64_t data_acked_before_high_gain_ended_bytes_; | |
212 | |
213 // Sequence number of the first packet sent during high gain phase. | |
214 uint16_t first_packet_seq_num_during_high_gain_; | |
215 | |
216 // Sequence number of the last packet sent during high gain phase. | |
217 uint16_t last_packet_seq_num_during_high_gain_; | |
218 bool high_gain_over_; | |
219 std::map<int64_t, PacketStats> packet_stats_; | |
220 std::list<AverageRtt> past_rtts_; | |
104 }; | 221 }; |
105 | 222 |
106 class BbrBweReceiver : public BweReceiver { | 223 class BbrBweReceiver : public BweReceiver { |
107 public: | 224 public: |
108 explicit BbrBweReceiver(int flow_id); | 225 explicit BbrBweReceiver(int flow_id); |
109 virtual ~BbrBweReceiver(); | 226 virtual ~BbrBweReceiver(); |
110 void ReceivePacket(int64_t arrival_time_ms, | 227 void ReceivePacket(int64_t arrival_time_ms, |
111 const MediaPacket& media_packet) override; | 228 const MediaPacket& media_packet) override; |
112 FeedbackPacket* GetFeedback(int64_t now_ms) override; | 229 FeedbackPacket* GetFeedback(int64_t now_ms) override; |
113 | 230 |
114 private: | 231 private: |
115 SimulatedClock clock_; | 232 SimulatedClock clock_; |
233 std::vector<uint64_t> packet_feedbacks_; | |
116 }; | 234 }; |
117 } // namespace bwe | 235 } // namespace bwe |
118 } // namespace testing | 236 } // namespace testing |
119 } // namespace webrtc | 237 } // namespace webrtc |
120 | 238 |
121 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ | 239 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ |
OLD | NEW |