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