philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/congestion_controller/delay_based_bwe.h" |
| 12 | #include "modules/congestion_controller/delay_based_bwe_unittest_helper.h" |
| 13 | #include "modules/pacing/paced_sender.h" |
| 14 | #include "rtc_base/constructormagic.h" |
| 15 | #include "system_wrappers/include/clock.h" |
| 16 | #include "test/field_trial.h" |
| 17 | #include "test/gtest.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 21 | namespace { |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 22 | constexpr int kNumProbesCluster0 = 5; |
| 23 | constexpr int kNumProbesCluster1 = 8; |
| 24 | const PacedPacketInfo kPacingInfo0(0, kNumProbesCluster0, 2000); |
| 25 | const PacedPacketInfo kPacingInfo1(1, kNumProbesCluster1, 4000); |
terelius | 3764730 | 2017-06-27 07:50:31 -0700 | [diff] [blame] | 26 | constexpr float kTargetUtilizationFraction = 0.95f; |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 27 | } // namespace |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 28 | |
stefan | 80fba25 | 2017-04-18 06:45:12 -0700 | [diff] [blame] | 29 | TEST_F(DelayBasedBweTest, NoCrashEmptyFeedback) { |
| 30 | std::vector<PacketFeedback> packet_feedback_vector; |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 31 | bitrate_estimator_->IncomingPacketFeedbackVector(packet_feedback_vector, |
| 32 | rtc::Optional<uint32_t>()); |
stefan | 80fba25 | 2017-04-18 06:45:12 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | TEST_F(DelayBasedBweTest, NoCrashOnlyLostFeedback) { |
| 36 | std::vector<PacketFeedback> packet_feedback_vector; |
| 37 | packet_feedback_vector.push_back( |
| 38 | PacketFeedback(-1, -1, 0, 1500, PacedPacketInfo())); |
| 39 | packet_feedback_vector.push_back( |
| 40 | PacketFeedback(-1, -1, 1, 1500, PacedPacketInfo())); |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 41 | bitrate_estimator_->IncomingPacketFeedbackVector(packet_feedback_vector, |
| 42 | rtc::Optional<uint32_t>()); |
stefan | 80fba25 | 2017-04-18 06:45:12 -0700 | [diff] [blame] | 43 | } |
| 44 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 45 | TEST_F(DelayBasedBweTest, ProbeDetection) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 46 | int64_t now_ms = clock_.TimeInMilliseconds(); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 47 | uint16_t seq_num = 0; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 48 | |
| 49 | // First burst sent at 8 * 1000 / 10 = 800 kbps. |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 50 | for (int i = 0; i < kNumProbesCluster0; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 51 | clock_.AdvanceTimeMilliseconds(10); |
| 52 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 53 | IncomingFeedback(now_ms, now_ms, seq_num++, 1000, kPacingInfo0); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 54 | } |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 55 | EXPECT_TRUE(bitrate_observer_.updated()); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 56 | |
| 57 | // Second burst sent at 8 * 1000 / 5 = 1600 kbps. |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 58 | for (int i = 0; i < kNumProbesCluster1; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 59 | clock_.AdvanceTimeMilliseconds(5); |
| 60 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 61 | IncomingFeedback(now_ms, now_ms, seq_num++, 1000, kPacingInfo1); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 64 | EXPECT_TRUE(bitrate_observer_.updated()); |
| 65 | EXPECT_GT(bitrate_observer_.latest_bitrate(), 1500000u); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 66 | } |
| 67 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 68 | TEST_F(DelayBasedBweTest, ProbeDetectionNonPacedPackets) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 69 | int64_t now_ms = clock_.TimeInMilliseconds(); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 70 | uint16_t seq_num = 0; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 71 | // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet |
| 72 | // not being paced which could mess things up. |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 73 | for (int i = 0; i < kNumProbesCluster0; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 74 | clock_.AdvanceTimeMilliseconds(5); |
| 75 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 76 | IncomingFeedback(now_ms, now_ms, seq_num++, 1000, kPacingInfo0); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 77 | // Non-paced packet, arriving 5 ms after. |
| 78 | clock_.AdvanceTimeMilliseconds(5); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 79 | IncomingFeedback(now_ms, now_ms, seq_num++, 100, PacedPacketInfo()); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 82 | EXPECT_TRUE(bitrate_observer_.updated()); |
| 83 | EXPECT_GT(bitrate_observer_.latest_bitrate(), 800000u); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 84 | } |
| 85 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 86 | TEST_F(DelayBasedBweTest, ProbeDetectionFasterArrival) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 87 | int64_t now_ms = clock_.TimeInMilliseconds(); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 88 | uint16_t seq_num = 0; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 89 | // First burst sent at 8 * 1000 / 10 = 800 kbps. |
| 90 | // Arriving at 8 * 1000 / 5 = 1600 kbps. |
| 91 | int64_t send_time_ms = 0; |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 92 | for (int i = 0; i < kNumProbesCluster0; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 93 | clock_.AdvanceTimeMilliseconds(1); |
| 94 | send_time_ms += 10; |
| 95 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 96 | IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, kPacingInfo0); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 99 | EXPECT_FALSE(bitrate_observer_.updated()); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 100 | } |
| 101 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 102 | TEST_F(DelayBasedBweTest, ProbeDetectionSlowerArrival) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 103 | int64_t now_ms = clock_.TimeInMilliseconds(); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 104 | uint16_t seq_num = 0; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 105 | // First burst sent at 8 * 1000 / 5 = 1600 kbps. |
| 106 | // Arriving at 8 * 1000 / 7 = 1142 kbps. |
terelius | 3764730 | 2017-06-27 07:50:31 -0700 | [diff] [blame] | 107 | // Since the receive rate is significantly below the send rate, we expect to |
| 108 | // use 95% of the estimated capacity. |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 109 | int64_t send_time_ms = 0; |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 110 | for (int i = 0; i < kNumProbesCluster1; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 111 | clock_.AdvanceTimeMilliseconds(7); |
| 112 | send_time_ms += 5; |
| 113 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 114 | IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, kPacingInfo1); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 117 | EXPECT_TRUE(bitrate_observer_.updated()); |
terelius | 3764730 | 2017-06-27 07:50:31 -0700 | [diff] [blame] | 118 | EXPECT_NEAR(bitrate_observer_.latest_bitrate(), |
| 119 | kTargetUtilizationFraction * 1140000u, 10000u); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 120 | } |
| 121 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 122 | TEST_F(DelayBasedBweTest, ProbeDetectionSlowerArrivalHighBitrate) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 123 | int64_t now_ms = clock_.TimeInMilliseconds(); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 124 | uint16_t seq_num = 0; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 125 | // Burst sent at 8 * 1000 / 1 = 8000 kbps. |
| 126 | // Arriving at 8 * 1000 / 2 = 4000 kbps. |
terelius | 3764730 | 2017-06-27 07:50:31 -0700 | [diff] [blame] | 127 | // Since the receive rate is significantly below the send rate, we expect to |
| 128 | // use 95% of the estimated capacity. |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 129 | int64_t send_time_ms = 0; |
philipel | b5feb2e | 2017-03-09 07:01:58 -0800 | [diff] [blame] | 130 | for (int i = 0; i < kNumProbesCluster1; ++i) { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 131 | clock_.AdvanceTimeMilliseconds(2); |
| 132 | send_time_ms += 1; |
| 133 | now_ms = clock_.TimeInMilliseconds(); |
philipel | 8aadd50 | 2017-02-23 02:56:13 -0800 | [diff] [blame] | 134 | IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, kPacingInfo1); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 137 | EXPECT_TRUE(bitrate_observer_.updated()); |
terelius | 3764730 | 2017-06-27 07:50:31 -0700 | [diff] [blame] | 138 | EXPECT_NEAR(bitrate_observer_.latest_bitrate(), |
| 139 | kTargetUtilizationFraction * 4000000u, 10000u); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 140 | } |
| 141 | |
alexnarest | b335e31 | 2017-09-19 12:00:32 -0700 | [diff] [blame] | 142 | TEST_F(DelayBasedBweTest, GetExpectedBwePeriodMs) { |
| 143 | int64_t default_interval_ms = bitrate_estimator_->GetExpectedBwePeriodMs(); |
| 144 | EXPECT_GT(default_interval_ms, 0); |
| 145 | CapacityDropTestHelper(1, true, 333, 0); |
| 146 | int64_t interval_ms = bitrate_estimator_->GetExpectedBwePeriodMs(); |
| 147 | EXPECT_GT(interval_ms, 0); |
| 148 | EXPECT_NE(interval_ms, default_interval_ms); |
| 149 | } |
| 150 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 151 | TEST_F(DelayBasedBweTest, InitialBehavior) { |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 152 | InitialBehaviorTestHelper(730000); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | TEST_F(DelayBasedBweTest, RateIncreaseReordering) { |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 156 | RateIncreaseReorderingTestHelper(730000); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 157 | } |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 158 | TEST_F(DelayBasedBweTest, RateIncreaseRtpTimestamps) { |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 159 | RateIncreaseRtpTimestampsTestHelper(627); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | TEST_F(DelayBasedBweTest, CapacityDropOneStream) { |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 163 | CapacityDropTestHelper(1, false, 300, 0); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | TEST_F(DelayBasedBweTest, CapacityDropPosOffsetChange) { |
stefan | 76d9c9c | 2017-04-01 06:51:09 -0700 | [diff] [blame] | 167 | CapacityDropTestHelper(1, false, 867, 30000); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TEST_F(DelayBasedBweTest, CapacityDropNegOffsetChange) { |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 171 | CapacityDropTestHelper(1, false, 933, -30000); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | TEST_F(DelayBasedBweTest, CapacityDropOneStreamWrap) { |
stefan | 76d9c9c | 2017-04-01 06:51:09 -0700 | [diff] [blame] | 175 | CapacityDropTestHelper(1, true, 333, 0); |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 176 | } |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 177 | |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 178 | TEST_F(DelayBasedBweTest, TestTimestampGrouping) { |
| 179 | TestTimestampGroupingTestHelper(); |
| 180 | } |
| 181 | |
| 182 | TEST_F(DelayBasedBweTest, TestShortTimeoutAndWrap) { |
| 183 | // Simulate a client leaving and rejoining the call after 35 seconds. This |
| 184 | // will make abs send time wrap, so if streams aren't timed out properly |
| 185 | // the next 30 seconds of packets will be out of order. |
| 186 | TestWrappingHelper(35); |
| 187 | } |
| 188 | |
| 189 | TEST_F(DelayBasedBweTest, TestLongTimeoutAndWrap) { |
| 190 | // Simulate a client leaving and rejoining the call after some multiple of |
| 191 | // 64 seconds later. This will cause a zero difference in abs send times due |
| 192 | // to the wrap, but a big difference in arrival time, if streams aren't |
| 193 | // properly timed out. |
| 194 | TestWrappingHelper(10 * 64); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 195 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 196 | |
terelius | a9521e2 | 2017-07-04 04:52:58 -0700 | [diff] [blame] | 197 | TEST_F(DelayBasedBweTest, TestInitialOveruse) { |
| 198 | const uint32_t kStartBitrate = 300e3; |
| 199 | const uint32_t kInitialCapacityBps = 200e3; |
| 200 | const uint32_t kDummySsrc = 0; |
| 201 | // High FPS to ensure that we send a lot of packets in a short time. |
| 202 | const int kFps = 90; |
| 203 | |
| 204 | stream_generator_->AddStream(new test::RtpStream(kFps, kStartBitrate)); |
| 205 | stream_generator_->set_capacity_bps(kInitialCapacityBps); |
| 206 | |
| 207 | // Needed to initialize the AimdRateControl. |
| 208 | bitrate_estimator_->SetStartBitrate(kStartBitrate); |
| 209 | |
| 210 | // Produce 30 frames (in 1/3 second) and give them to the estimator. |
| 211 | uint32_t bitrate_bps = kStartBitrate; |
| 212 | bool seen_overuse = false; |
| 213 | for (int i = 0; i < 30; ++i) { |
| 214 | bool overuse = GenerateAndProcessFrame(kDummySsrc, bitrate_bps); |
| 215 | // The purpose of this test is to ensure that we back down even if we don't |
| 216 | // have any acknowledged bitrate estimate yet. Hence, if the test works |
| 217 | // as expected, we should not have a measured bitrate yet. |
| 218 | EXPECT_FALSE(acknowledged_bitrate_estimator_->bitrate_bps().has_value()); |
| 219 | if (overuse) { |
| 220 | EXPECT_TRUE(bitrate_observer_.updated()); |
| 221 | EXPECT_NEAR(bitrate_observer_.latest_bitrate(), kStartBitrate / 2, 15000); |
| 222 | bitrate_bps = bitrate_observer_.latest_bitrate(); |
| 223 | seen_overuse = true; |
| 224 | break; |
| 225 | } else if (bitrate_observer_.updated()) { |
| 226 | bitrate_bps = bitrate_observer_.latest_bitrate(); |
| 227 | bitrate_observer_.Reset(); |
| 228 | } |
| 229 | } |
| 230 | EXPECT_TRUE(seen_overuse); |
| 231 | EXPECT_NEAR(bitrate_observer_.latest_bitrate(), kStartBitrate / 2, 15000); |
| 232 | } |
| 233 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 234 | } // namespace webrtc |