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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.h

Issue 2990163002: Almost full implementation of BBR's core. (Closed)
Patch Set: Fixed a small bug. Created 3 years, 4 months 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
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.
terelius 2017/08/08 17:32:40 Is this the same as sequence_number_ below?
gnish1 2017/08/09 10:05:53 Done.
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_,
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;
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.
terelius 2017/08/08 17:32:40 nit: I think we generally capitalize RTT in commen
gnish1 2017/08/09 10:05:53 Done.
99 int64_t sum_of_rtts_ms;
100 // Number of rtt samples over the round.
terelius 2017/08/08 17:32:40 RTT
gnish1 2017/08/09 10:05:53 Done.
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.
terelius 2017/08/08 17:32:40 What happens in case of reordering on the network?
gnish1 2017/08/09 10:05:53 I would assume current implementation will not han
terelius 2017/08/11 09:31:36 Can you check if there is a "ReorderingFilter" or
gnish1 2017/08/12 11:57:31 I couldn't find anything similar, will check with
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_;
93 167
94 // Time we entered PROBE_RTT mode. 168 // Time we entered PROBE_RTT mode.
95 int64_t probe_rtt_start_time_ms_; 169 int64_t probe_rtt_start_time_ms_;
96 170
97 // First moment of time when data inflight decreased below 171 // First moment of time when data inflight decreased below
98 // kMinimumCongestionWindow in PROBE_RTT mode. 172 // kMinimumCongestionWindow in PROBE_RTT mode.
99 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_; 173 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_;
100 174
101 // First round when data inflight decreased below kMinimumCongestionWindow in 175 // First round when data inflight decreased below kMinimumCongestionWindow in
102 // PROBE_RTT mode. 176 // PROBE_RTT mode.
103 int64_t minimum_congestion_window_start_round_; 177 int64_t minimum_congestion_window_start_round_;
178 size_t bytes_sent_;
179 uint16_t last_packet_sent_sequence_number_;
180 uint16_t last_packet_acked_sequence_number_;
181 int64_t last_packet_ack_time_;
182 int64_t last_packet_send_time_;
183 int64_t pacing_rate_bps_;
184
185 // Send time of a packet sent first during high gain phase. Also serves as a
186 // flag, holding value means that we are already in high gain.
187 rtc::Optional<int64_t> first_packet_send_time_during_high_gain_ms_;
188
189 // Send time of a packet sent last during high gain phase.
190 int64_t last_packet_send_time_during_high_gain_ms_;
191
192 // Amount of data sent, before first packet was sent during high gain phase.
193 int64_t data_sent_before_high_gain_started_bytes_;
194
195 // Amount of data sent, before last packet was sent during high gain phase.
196 int64_t data_sent_before_high_gain_ended_bytes_;
197
198 // Ack time of a packet acked first during high gain phase.
199 int64_t first_packet_ack_time_during_high_gain_ms_;
200
201 // Ack time of a packet acked last during high gain phase.
202 int64_t last_packet_ack_time_during_high_gain_ms_;
203
204 // Amount of data acked, before the first packet was acked during high gain
205 // phase.
206 int64_t data_acked_before_high_gain_started_bytes_;
207
208 // Amount of data acked, before the last packet was acked during high gain
209 // phase.
210 int64_t data_acked_before_high_gain_ended_bytes_;
211
212 // Sequence number of the first packet sent during high gain phase.
213 uint16_t first_packet_seq_num_during_high_gain_;
214
215 // Sequence number of the last packet sent during high gain phase.
216 uint16_t last_packet_seq_num_during_high_gain_;
217 bool high_gain_over_;
218 std::map<int64_t, PacketStats> packet_stats_;
219 std::list<AverageRtt> past_rtts_;
104 }; 220 };
105 221
106 class BbrBweReceiver : public BweReceiver { 222 class BbrBweReceiver : public BweReceiver {
107 public: 223 public:
108 explicit BbrBweReceiver(int flow_id); 224 explicit BbrBweReceiver(int flow_id);
109 virtual ~BbrBweReceiver(); 225 virtual ~BbrBweReceiver();
110 void ReceivePacket(int64_t arrival_time_ms, 226 void ReceivePacket(int64_t arrival_time_ms,
111 const MediaPacket& media_packet) override; 227 const MediaPacket& media_packet) override;
112 FeedbackPacket* GetFeedback(int64_t now_ms) override; 228 FeedbackPacket* GetFeedback(int64_t now_ms) override;
113 229
114 private: 230 private:
115 SimulatedClock clock_; 231 SimulatedClock clock_;
232 std::vector<uint64_t> packet_feedbacks_;
116 }; 233 };
117 } // namespace bwe 234 } // namespace bwe
118 } // namespace testing 235 } // namespace testing
119 } // namespace webrtc 236 } // namespace webrtc
120 237
121 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ 238 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698