Chromium Code Reviews| 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" |
| 20 #include "webrtc/rtc_base/optional.h" | 21 #include "webrtc/rtc_base/optional.h" |
| 21 #include "webrtc/rtc_base/random.h" | 22 #include "webrtc/rtc_base/random.h" |
| 22 | 23 |
| 23 namespace webrtc { | 24 namespace webrtc { |
| 24 namespace testing { | 25 namespace testing { |
| 25 namespace bwe { | 26 namespace bwe { |
| 26 class MaxBandwidthFilter; | 27 class MaxBandwidthFilter; |
| 27 class MinRttFilter; | 28 class MinRttFilter; |
| 28 class CongestionWindow; | 29 class CongestionWindow; |
| 29 class BbrBweSender : public BweSender { | 30 class BbrBweSender : public BweSender { |
| 30 public: | 31 public: |
| 31 explicit BbrBweSender(Clock* clock); | 32 explicit BbrBweSender(Clock* clock); |
| 32 virtual ~BbrBweSender(); | 33 virtual ~BbrBweSender(); |
| 33 enum Mode { | 34 enum Mode { |
| 34 // Startup phase. | 35 // Startup phase. |
| 35 STARTUP, | 36 STARTUP, |
| 36 // Queue draining phase, which where created during startup. | 37 // Queue draining phase, which where created during startup. |
| 37 DRAIN, | 38 DRAIN, |
| 38 // Cruising, probing new bandwidth. | 39 // Cruising, probing new bandwidth. |
| 39 PROBE_BW, | 40 PROBE_BW, |
| 40 // Temporarily limiting congestion window size in order to measure | 41 // Temporarily limiting congestion window size in order to measure |
| 41 // minimum RTT. | 42 // minimum RTT. |
| 42 PROBE_RTT | 43 PROBE_RTT, |
| 44 // Temporarily reducing pacing rate and congestion window, in order to | |
| 45 // ensure no queues are built. | |
| 46 RECOVERY | |
| 43 }; | 47 }; |
| 44 struct PacketStats { | 48 struct PacketStats { |
| 45 PacketStats() {} | 49 PacketStats() {} |
| 46 PacketStats(int64_t send_time_, size_t payload_size_) | 50 PacketStats(int64_t sequence_number_, |
| 47 : send_time(send_time_), payload_size(payload_size_) {} | 51 int64_t send_time_, |
| 48 | 52 int64_t send_time_before_, |
| 53 int64_t ack_time_, | |
| 54 int64_t ack_time_before_, | |
| 55 size_t payload_size_, | |
| 56 size_t data_sent_, | |
| 57 size_t data_sent_before_, | |
| 58 size_t data_acked_, | |
| 59 size_t data_acked_before_) | |
| 60 : sequence_number(sequence_number_), | |
| 61 send_time(send_time_), | |
| 62 send_time_before(send_time_before_), | |
| 63 ack_time(ack_time_), | |
| 64 ack_time_before(ack_time_before_), | |
| 65 payload_size(payload_size_), | |
| 66 data_sent(data_sent_), | |
| 67 data_sent_before(data_sent_before_), | |
| 68 data_acked(data_acked_), | |
| 69 data_acked_before(data_acked_before_) {} | |
| 70 uint64_t sequence_number; | |
| 71 // Send time of the packet which was sent, when current packet got acked. | |
|
philipel
2017/08/04 12:08:07
I don't quite understand this comment.
gnish1
2017/08/07 10:34:28
Done.
| |
| 49 int64_t send_time; | 72 int64_t send_time; |
| 73 // The actual send time of the packet. | |
|
philipel
2017/08/04 12:08:07
Also not that clear, maybe explaining the differen
gnish1
2017/08/07 10:34:28
Done.
| |
| 74 int64_t send_time_before; | |
| 75 // Ack time of the packet. | |
| 76 int64_t ack_time; | |
| 77 // Ack time of the packet, which was acked when current packet got sent. | |
| 78 int64_t ack_time_before; | |
| 50 size_t payload_size; | 79 size_t payload_size; |
| 80 size_t data_sent; | |
| 81 size_t data_sent_before; | |
| 82 size_t data_acked; | |
| 83 size_t data_acked_before; | |
|
philipel
2017/08/04 12:08:07
Please add comments for all the member variables.
gnish1
2017/08/07 10:34:29
Done.
philipel
2017/08/08 11:54:54
If it's hard to find good names for the members th
| |
| 84 }; | |
| 85 struct AverageRtt { | |
| 86 AverageRtt() {} | |
| 87 AverageRtt(int64_t sum_of_rtts_, int64_t quantity_, uint64_t round_) | |
| 88 : sum_of_rtts(sum_of_rtts_), quantity(quantity_), round(round_) {} | |
| 89 // Sum of rtts over the round. | |
| 90 int64_t sum_of_rtts; | |
|
philipel
2017/08/04 12:08:08
miliseconds? microseconds? please add _ms
gnish1
2017/08/07 10:34:28
Done.
| |
| 91 // Number of rtt samples over the round. | |
| 92 int64_t quantity; | |
|
philipel
2017/08/04 12:08:07
num_samples
gnish1
2017/08/07 10:34:29
Done.
| |
| 93 // The number of the round average rtt is recorded for. | |
| 94 uint64_t round; | |
| 51 }; | 95 }; |
| 52 void OnPacketsSent(const Packets& packets) override; | 96 void OnPacketsSent(const Packets& packets) override; |
| 53 int GetFeedbackIntervalMs() const override; | 97 int GetFeedbackIntervalMs() const override; |
| 54 void GiveFeedback(const FeedbackPacket& feedback) override; | 98 void GiveFeedback(const FeedbackPacket& feedback) override; |
| 55 int64_t TimeUntilNextProcess() override; | 99 int64_t TimeUntilNextProcess() override; |
| 56 void Process() override; | 100 void Process() override; |
| 57 | 101 |
| 58 private: | 102 private: |
| 59 void EnterStartup(); | 103 void EnterStartup(); |
| 60 bool UpdateBandwidthAndMinRtt(); | 104 bool UpdateBandwidthAndMinRtt(int64_t now, |
| 105 const std::vector<uint64_t>& feedback_vector, | |
| 106 int64_t bytes_acked); | |
| 61 void TryExitingStartup(); | 107 void TryExitingStartup(); |
| 62 void TryExitingDrain(int64_t now_ms); | 108 void TryExitingDrain(int64_t now_ms); |
| 63 void EnterProbeBw(int64_t now_ms); | 109 void EnterProbeBw(int64_t now_ms); |
| 64 void TryUpdatingCyclePhase(int64_t now_ms); | 110 void TryUpdatingCyclePhase(int64_t now_ms); |
| 65 void TryEnteringProbeRtt(int64_t now_ms); | 111 void TryEnteringProbeRtt(int64_t now_ms, bool min_rtt_expired); |
| 66 void TryExitingProbeRtt(int64_t now_ms, int64_t round); | 112 void TryExitingProbeRtt(int64_t now_ms, int64_t round, bool min_rtt_expired); |
| 113 void TryEnteringRecovery(); | |
| 114 void TryExitingRecovery(); | |
| 67 size_t TargetCongestionWindow(float gain); | 115 size_t TargetCongestionWindow(float gain); |
| 116 void CalculatePacingRate(); | |
| 117 | |
| 118 // Calculates and returns bandwidth sample as minimum between send rate and | |
| 119 // ack rate, returns nothing if sample cannot be calculated. | |
| 120 rtc::Optional<int64_t> CalculateBandwidthSample(size_t data_sent, | |
| 121 int64_t time_elapsed_1, | |
|
philipel
2017/08/04 12:08:07
Is this the delta send time?
gnish1
2017/08/07 10:34:28
Done.
| |
| 122 size_t data_acked, | |
| 123 int64_t time_elapsed_2); | |
|
philipel
2017/08/04 12:08:07
and this the delta receive time?
gnish1
2017/08/07 10:34:29
Done.
| |
| 124 | |
| 125 // Calculate and add bandwidth sample only for packets' sent during high gain | |
| 126 // phase. Motivation of having a seperate bucket for high gain phase is to | |
| 127 // achieve quicker ramp up. Slight overestimations may happen due to window | |
| 128 // not being as large as usual. | |
| 129 void AddSampleForHighGain(); | |
| 130 | |
| 131 // Declares lost packets as acked. Implements simple logic by looking at the | |
| 132 // gap between sequence numbers. | |
| 133 void HandleLoss(uint64_t last_acked_packet, uint64_t recently_acked_packet); | |
| 134 void AddToPastRtts(int64_t rtt_sample_ms); | |
| 68 Clock* const clock_; | 135 Clock* const clock_; |
| 69 Mode mode_; | 136 Mode mode_; |
| 70 std::unique_ptr<MaxBandwidthFilter> max_bandwidth_filter_; | 137 std::unique_ptr<MaxBandwidthFilter> max_bandwidth_filter_; |
| 71 std::unique_ptr<MinRttFilter> min_rtt_filter_; | 138 std::unique_ptr<MinRttFilter> min_rtt_filter_; |
| 72 std::unique_ptr<CongestionWindow> congestion_window_; | 139 std::unique_ptr<CongestionWindow> congestion_window_; |
| 73 std::unique_ptr<Random> rand_; | 140 std::unique_ptr<Random> rand_; |
| 74 uint64_t round_count_; | 141 uint64_t round_count_; |
| 75 uint64_t last_packet_sent_; | |
| 76 uint64_t round_trip_end_; | 142 uint64_t round_trip_end_; |
| 77 float pacing_gain_; | 143 float pacing_gain_; |
| 78 float congestion_window_gain_; | 144 float congestion_window_gain_; |
| 79 | 145 |
| 80 // If optimal bandwidth has been discovered and reached, (for example after | 146 // If optimal bandwidth has been discovered and reached, (for example after |
| 81 // Startup mode) set this variable to true. | 147 // Startup mode) set this variable to true. |
| 82 bool full_bandwidth_reached_; | 148 bool full_bandwidth_reached_; |
| 83 | 149 |
| 84 // Entering time for PROBE_BW mode's cycle phase. | 150 // Entering time for PROBE_BW mode's cycle phase. |
| 85 int64_t cycle_start_time_ms_; | 151 int64_t cycle_start_time_ms_; |
| 86 | 152 |
| 87 // Index number of the currently used gain value in PROBE_BW mode, from 0 to | 153 // Index number of the currently used gain value in PROBE_BW mode, from 0 to |
| 88 // kGainCycleLength - 1. | 154 // kGainCycleLength - 1. |
| 89 int64_t cycle_index_; | 155 int64_t cycle_index_; |
| 90 | 156 size_t bytes_acked_; |
| 91 // Data inflight prior to the moment when last feedback was received. | |
| 92 size_t prior_in_flight_; | 157 size_t prior_in_flight_; |
| 93 | 158 |
| 94 // Time we entered PROBE_RTT mode. | 159 // Time we entered PROBE_RTT mode. |
| 95 int64_t probe_rtt_start_time_ms_; | 160 int64_t probe_rtt_start_time_ms_; |
| 96 | 161 |
| 97 // First moment of time when data inflight decreased below | 162 // First moment of time when data inflight decreased below |
| 98 // kMinimumCongestionWindow in PROBE_RTT mode. | 163 // kMinimumCongestionWindow in PROBE_RTT mode. |
| 99 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_; | 164 rtc::Optional<int64_t> minimum_congestion_window_start_time_ms_; |
| 100 | 165 |
| 101 // First round when data inflight decreased below kMinimumCongestionWindow in | 166 // First round when data inflight decreased below kMinimumCongestionWindow in |
| 102 // PROBE_RTT mode. | 167 // PROBE_RTT mode. |
| 103 int64_t minimum_congestion_window_start_round_; | 168 int64_t minimum_congestion_window_start_round_; |
| 169 size_t bytes_sent_; | |
| 170 uint64_t last_packet_sent_sequence_number_; | |
| 171 uint64_t last_packet_acked_sequence_number_; | |
| 172 int64_t last_packet_ack_time_; | |
| 173 int64_t last_packet_send_time_; | |
| 174 int64_t pacing_rate_; | |
|
philipel
2017/08/04 12:08:07
bps?
gnish1
2017/08/07 10:34:28
Done.
| |
| 175 | |
| 176 // Send time of a packet sent first during high gain phase. Also serves as a | |
| 177 // flag, holding value means that we are already in high gain. | |
| 178 rtc::Optional<int64_t> first_high_gain_send_time_; | |
|
philipel
2017/08/04 12:08:07
Maybe |high_gain_start_ms_|? WDYT?
Please also ta
gnish1
2017/08/07 10:34:28
Done.
| |
| 179 | |
| 180 // Send time of a packet sent last during high gain phase. | |
| 181 int64_t last_high_gain_send_time_; | |
| 182 | |
| 183 // Amount of data sent, before first packet was sent during high gain phase. | |
| 184 int64_t first_high_gain_sent_before_; | |
| 185 | |
| 186 // Amount of data sent, before last packet was sent during high gain phase. | |
| 187 int64_t last_high_gain_sent_before_; | |
| 188 | |
| 189 // Ack time of a packet acked first during high gain phase. | |
| 190 int64_t first_high_gain_ack_time_; | |
| 191 | |
| 192 // Ack time of a packet acked last during high gain phase. | |
| 193 int64_t last_high_gain_ack_time_; | |
| 194 | |
| 195 // Amount of data acked, before first packet was acked during high gain phase. | |
| 196 int64_t first_high_gain_acked_before_; | |
| 197 | |
| 198 // Amount of data acked, before last packet was acked during high gain phase. | |
| 199 int64_t last_high_gain_acked_before_; | |
| 200 | |
| 201 // Sequence number of the first packet sent during high gain phase. | |
| 202 uint64_t first_high_gain_seq_num_; | |
| 203 | |
| 204 // Sequence number of the last packet sent during high gain phase. | |
| 205 uint64_t last_high_gain_seq_num_; | |
| 206 bool high_gain_over_; | |
| 207 std::map<int64_t, PacketStats> packet_stats_; | |
| 208 std::list<AverageRtt> past_rtts_; | |
| 104 }; | 209 }; |
| 105 | 210 |
| 106 class BbrBweReceiver : public BweReceiver { | 211 class BbrBweReceiver : public BweReceiver { |
| 107 public: | 212 public: |
| 108 explicit BbrBweReceiver(int flow_id); | 213 explicit BbrBweReceiver(int flow_id); |
| 109 virtual ~BbrBweReceiver(); | 214 virtual ~BbrBweReceiver(); |
| 110 void ReceivePacket(int64_t arrival_time_ms, | 215 void ReceivePacket(int64_t arrival_time_ms, |
| 111 const MediaPacket& media_packet) override; | 216 const MediaPacket& media_packet) override; |
| 112 FeedbackPacket* GetFeedback(int64_t now_ms) override; | 217 FeedbackPacket* GetFeedback(int64_t now_ms) override; |
| 113 | 218 |
| 114 private: | 219 private: |
| 115 SimulatedClock clock_; | 220 SimulatedClock clock_; |
| 221 std::vector<uint64_t> packet_feedbacks_; | |
| 222 // int64_t last_feedback_ms_; | |
|
philipel
2017/08/04 12:08:07
Remove unused member.
gnish1
2017/08/07 10:34:29
Done.
| |
| 116 }; | 223 }; |
| 117 } // namespace bwe | 224 } // namespace bwe |
| 118 } // namespace testing | 225 } // namespace testing |
| 119 } // namespace webrtc | 226 } // namespace webrtc |
| 120 | 227 |
| 121 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ | 228 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_BBR_H_ |
| OLD | NEW |