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

Side by Side Diff: webrtc/modules/congestion_controller/delay_based_bwe_unittest.cc

Issue 2126793002: Reset InterArrival if arrival time clock makes a jump. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a few test issues. Created 4 years, 5 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/base/constructormagic.h"
13 #include "webrtc/modules/pacing/paced_sender.h"
11 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" 14 #include "webrtc/modules/congestion_controller/delay_based_bwe.h"
12 15 #include "webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h "
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/pacing/paced_sender.h"
15 #include "webrtc/system_wrappers/include/clock.h" 16 #include "webrtc/system_wrappers/include/clock.h"
16 17
17 namespace webrtc { 18 namespace webrtc {
18 19
19 class TestDelayBasedBwe : public ::testing::Test, public RemoteBitrateObserver { 20 namespace {
20 public:
21 static constexpr int kArrivalTimeClockOffsetMs = 60000;
22 static constexpr int kNumProbes = 5;
23 21
24 TestDelayBasedBwe() 22 constexpr int kNumProbes = 5;
25 : bwe_(this), clock_(0), bitrate_updated_(false), latest_bitrate_(0) {} 23 } // namespace
26 24
27 uint32_t AbsSendTime(int64_t t, int64_t denom) { 25 TEST_F(DelayBasedBweTest, ProbeDetection) {
28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful;
29 }
30
31 void IncomingPacket(uint32_t ssrc,
32 size_t payload_size,
33 int64_t arrival_time,
34 uint32_t rtp_timestamp,
35 uint32_t absolute_send_time,
36 int probe_cluster_id) {
37 RTPHeader header;
38 memset(&header, 0, sizeof(header));
39 header.ssrc = ssrc;
40 header.timestamp = rtp_timestamp;
41 header.extension.hasAbsoluteSendTime = true;
42 header.extension.absoluteSendTime = absolute_send_time;
43 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size,
44 header, probe_cluster_id);
45 }
46
47 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
48 uint32_t bitrate) {
49 bitrate_updated_ = true;
50 latest_bitrate_ = bitrate;
51 }
52
53 bool bitrate_updated() {
54 bool res = bitrate_updated_;
55 bitrate_updated_ = false;
56 return res;
57 }
58
59 int latest_bitrate() { return latest_bitrate_; }
60
61 DelayBasedBwe bwe_;
62 SimulatedClock clock_;
63
64 private:
65 bool bitrate_updated_;
66 int latest_bitrate_;
67 };
68
69 TEST_F(TestDelayBasedBwe, ProbeDetection) {
70 int64_t now_ms = clock_.TimeInMilliseconds(); 26 int64_t now_ms = clock_.TimeInMilliseconds();
27 uint16_t seq_num = 0;
71 28
72 // First burst sent at 8 * 1000 / 10 = 800 kbps. 29 // First burst sent at 8 * 1000 / 10 = 800 kbps.
73 for (int i = 0; i < kNumProbes; ++i) { 30 for (int i = 0; i < kNumProbes; ++i) {
74 clock_.AdvanceTimeMilliseconds(10); 31 clock_.AdvanceTimeMilliseconds(10);
75 now_ms = clock_.TimeInMilliseconds(); 32 now_ms = clock_.TimeInMilliseconds();
76 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); 33 IncomingFeedback(now_ms, now_ms, seq_num++, 1000, 0);
77 } 34 }
78 EXPECT_TRUE(bitrate_updated()); 35 EXPECT_TRUE(bitrate_observer_->updated());
79 36
80 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. 37 // Second burst sent at 8 * 1000 / 5 = 1600 kbps.
81 for (int i = 0; i < kNumProbes; ++i) { 38 for (int i = 0; i < kNumProbes; ++i) {
82 clock_.AdvanceTimeMilliseconds(5); 39 clock_.AdvanceTimeMilliseconds(5);
83 now_ms = clock_.TimeInMilliseconds(); 40 now_ms = clock_.TimeInMilliseconds();
84 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); 41 IncomingFeedback(now_ms, now_ms, seq_num++, 1000, 1);
85 } 42 }
86 43
87 EXPECT_TRUE(bitrate_updated()); 44 EXPECT_TRUE(bitrate_observer_->updated());
88 EXPECT_GT(latest_bitrate(), 1500000); 45 EXPECT_GT(bitrate_observer_->latest_bitrate(), 1500000u);
89 } 46 }
90 47
91 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { 48 TEST_F(DelayBasedBweTest, ProbeDetectionNonPacedPackets) {
92 int64_t now_ms = clock_.TimeInMilliseconds(); 49 int64_t now_ms = clock_.TimeInMilliseconds();
50 uint16_t seq_num = 0;
93 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet 51 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet
94 // not being paced which could mess things up. 52 // not being paced which could mess things up.
95 for (int i = 0; i < kNumProbes; ++i) { 53 for (int i = 0; i < kNumProbes; ++i) {
96 clock_.AdvanceTimeMilliseconds(5); 54 clock_.AdvanceTimeMilliseconds(5);
97 now_ms = clock_.TimeInMilliseconds(); 55 now_ms = clock_.TimeInMilliseconds();
98 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); 56 IncomingFeedback(now_ms, now_ms, seq_num++, 1000, 0);
99 // Non-paced packet, arriving 5 ms after. 57 // Non-paced packet, arriving 5 ms after.
100 clock_.AdvanceTimeMilliseconds(5); 58 clock_.AdvanceTimeMilliseconds(5);
101 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, 59 IncomingFeedback(now_ms, now_ms, seq_num++,
102 AbsSendTime(now_ms, 1000), PacketInfo::kNotAProbe); 60 PacedSender::kMinProbePacketSize + 1,
61 PacketInfo::kNotAProbe);
103 } 62 }
104 63
105 EXPECT_TRUE(bitrate_updated()); 64 EXPECT_TRUE(bitrate_observer_->updated());
106 EXPECT_GT(latest_bitrate(), 800000); 65 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u);
107 } 66 }
108 67
109 // Packets will require 5 ms to be transmitted to the receiver, causing packets 68 // Packets will require 5 ms to be transmitted to the receiver, causing packets
110 // of the second probe to be dispersed. 69 // of the second probe to be dispersed.
111 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { 70 TEST_F(DelayBasedBweTest, ProbeDetectionTooHighBitrate) {
112 int64_t now_ms = clock_.TimeInMilliseconds(); 71 int64_t now_ms = clock_.TimeInMilliseconds();
113 int64_t send_time_ms = 0; 72 int64_t send_time_ms = 0;
73 uint16_t seq_num = 0;
114 // First burst sent at 8 * 1000 / 10 = 800 kbps. 74 // First burst sent at 8 * 1000 / 10 = 800 kbps.
115 for (int i = 0; i < kNumProbes; ++i) { 75 for (int i = 0; i < kNumProbes; ++i) {
116 clock_.AdvanceTimeMilliseconds(10); 76 clock_.AdvanceTimeMilliseconds(10);
117 now_ms = clock_.TimeInMilliseconds(); 77 now_ms = clock_.TimeInMilliseconds();
118 send_time_ms += 10; 78 send_time_ms += 10;
119 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, 79 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 0);
120 AbsSendTime(send_time_ms, 1000), 0);
121 } 80 }
122 81
123 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = 82 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 =
124 // 1000 kbps. 83 // 1000 kbps.
125 for (int i = 0; i < kNumProbes; ++i) { 84 for (int i = 0; i < kNumProbes; ++i) {
126 clock_.AdvanceTimeMilliseconds(8); 85 clock_.AdvanceTimeMilliseconds(8);
127 now_ms = clock_.TimeInMilliseconds(); 86 now_ms = clock_.TimeInMilliseconds();
128 send_time_ms += 5; 87 send_time_ms += 5;
129 IncomingPacket(0, 1000, now_ms, send_time_ms, 88 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 1);
130 AbsSendTime(send_time_ms, 1000), 1);
131 } 89 }
132 90
133 EXPECT_TRUE(bitrate_updated()); 91 EXPECT_TRUE(bitrate_observer_->updated());
134 EXPECT_NEAR(latest_bitrate(), 800000, 10000); 92 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000u);
135 } 93 }
136 94
137 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { 95 TEST_F(DelayBasedBweTest, ProbeDetectionSlightlyFasterArrival) {
138 int64_t now_ms = clock_.TimeInMilliseconds(); 96 int64_t now_ms = clock_.TimeInMilliseconds();
97 uint16_t seq_num = 0;
139 // First burst sent at 8 * 1000 / 10 = 800 kbps. 98 // First burst sent at 8 * 1000 / 10 = 800 kbps.
140 // Arriving at 8 * 1000 / 5 = 1600 kbps. 99 // Arriving at 8 * 1000 / 5 = 1600 kbps.
141 int64_t send_time_ms = 0; 100 int64_t send_time_ms = 0;
142 for (int i = 0; i < kNumProbes; ++i) { 101 for (int i = 0; i < kNumProbes; ++i) {
143 clock_.AdvanceTimeMilliseconds(5); 102 clock_.AdvanceTimeMilliseconds(5);
144 send_time_ms += 10; 103 send_time_ms += 10;
145 now_ms = clock_.TimeInMilliseconds(); 104 now_ms = clock_.TimeInMilliseconds();
146 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, 105 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 23);
147 AbsSendTime(send_time_ms, 1000), 23);
148 } 106 }
149 107
150 EXPECT_TRUE(bitrate_updated()); 108 EXPECT_TRUE(bitrate_observer_->updated());
151 EXPECT_GT(latest_bitrate(), 800000); 109 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u);
152 } 110 }
153 111
154 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { 112 TEST_F(DelayBasedBweTest, ProbeDetectionFasterArrival) {
155 int64_t now_ms = clock_.TimeInMilliseconds(); 113 int64_t now_ms = clock_.TimeInMilliseconds();
114 uint16_t seq_num = 0;
156 // First burst sent at 8 * 1000 / 10 = 800 kbps. 115 // First burst sent at 8 * 1000 / 10 = 800 kbps.
157 // Arriving at 8 * 1000 / 5 = 1600 kbps. 116 // Arriving at 8 * 1000 / 5 = 1600 kbps.
158 int64_t send_time_ms = 0; 117 int64_t send_time_ms = 0;
159 for (int i = 0; i < kNumProbes; ++i) { 118 for (int i = 0; i < kNumProbes; ++i) {
160 clock_.AdvanceTimeMilliseconds(1); 119 clock_.AdvanceTimeMilliseconds(1);
161 send_time_ms += 10; 120 send_time_ms += 10;
162 now_ms = clock_.TimeInMilliseconds(); 121 now_ms = clock_.TimeInMilliseconds();
163 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, 122 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 0);
164 AbsSendTime(send_time_ms, 1000), 0);
165 } 123 }
166 124
167 EXPECT_FALSE(bitrate_updated()); 125 EXPECT_FALSE(bitrate_observer_->updated());
168 } 126 }
169 127
170 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { 128 TEST_F(DelayBasedBweTest, ProbeDetectionSlowerArrival) {
171 int64_t now_ms = clock_.TimeInMilliseconds(); 129 int64_t now_ms = clock_.TimeInMilliseconds();
130 uint16_t seq_num = 0;
172 // First burst sent at 8 * 1000 / 5 = 1600 kbps. 131 // First burst sent at 8 * 1000 / 5 = 1600 kbps.
173 // Arriving at 8 * 1000 / 7 = 1142 kbps. 132 // Arriving at 8 * 1000 / 7 = 1142 kbps.
174 int64_t send_time_ms = 0; 133 int64_t send_time_ms = 0;
175 for (int i = 0; i < kNumProbes; ++i) { 134 for (int i = 0; i < kNumProbes; ++i) {
176 clock_.AdvanceTimeMilliseconds(7); 135 clock_.AdvanceTimeMilliseconds(7);
177 send_time_ms += 5; 136 send_time_ms += 5;
178 now_ms = clock_.TimeInMilliseconds(); 137 now_ms = clock_.TimeInMilliseconds();
179 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, 138 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 1);
180 AbsSendTime(send_time_ms, 1000), 1);
181 } 139 }
182 140
183 EXPECT_TRUE(bitrate_updated()); 141 EXPECT_TRUE(bitrate_observer_->updated());
184 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); 142 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 1140000u, 10000u);
185 } 143 }
186 144
187 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { 145 TEST_F(DelayBasedBweTest, ProbeDetectionSlowerArrivalHighBitrate) {
188 int64_t now_ms = clock_.TimeInMilliseconds(); 146 int64_t now_ms = clock_.TimeInMilliseconds();
147 uint16_t seq_num = 0;
189 // Burst sent at 8 * 1000 / 1 = 8000 kbps. 148 // Burst sent at 8 * 1000 / 1 = 8000 kbps.
190 // Arriving at 8 * 1000 / 2 = 4000 kbps. 149 // Arriving at 8 * 1000 / 2 = 4000 kbps.
191 int64_t send_time_ms = 0; 150 int64_t send_time_ms = 0;
192 for (int i = 0; i < kNumProbes; ++i) { 151 for (int i = 0; i < kNumProbes; ++i) {
193 clock_.AdvanceTimeMilliseconds(2); 152 clock_.AdvanceTimeMilliseconds(2);
194 send_time_ms += 1; 153 send_time_ms += 1;
195 now_ms = clock_.TimeInMilliseconds(); 154 now_ms = clock_.TimeInMilliseconds();
196 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, 155 IncomingFeedback(now_ms, send_time_ms, seq_num++, 1000, 1);
197 AbsSendTime(send_time_ms, 1000), 1);
198 } 156 }
199 157
200 EXPECT_TRUE(bitrate_updated()); 158 EXPECT_TRUE(bitrate_observer_->updated());
201 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); 159 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 4000000u, 10000u);
202 } 160 }
203 161
204 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { 162 TEST_F(DelayBasedBweTest, ProbingIgnoresSmallPackets) {
205 int64_t now_ms = clock_.TimeInMilliseconds(); 163 int64_t now_ms = clock_.TimeInMilliseconds();
164 uint16_t seq_num = 0;
206 // Probing with 200 bytes every 10 ms, should be ignored by the probe 165 // Probing with 200 bytes every 10 ms, should be ignored by the probe
207 // detection. 166 // detection.
208 for (int i = 0; i < kNumProbes; ++i) { 167 for (int i = 0; i < kNumProbes; ++i) {
209 clock_.AdvanceTimeMilliseconds(10); 168 clock_.AdvanceTimeMilliseconds(10);
210 now_ms = clock_.TimeInMilliseconds(); 169 now_ms = clock_.TimeInMilliseconds();
211 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, 170 IncomingFeedback(now_ms, now_ms, seq_num++,
212 AbsSendTime(now_ms, 1000), 1); 171 PacedSender::kMinProbePacketSize, 1);
213 } 172 }
214 173
215 EXPECT_FALSE(bitrate_updated()); 174 EXPECT_FALSE(bitrate_observer_->updated());
216 175
217 // Followed by a probe with 1000 bytes packets, should be detected as a 176 // Followed by a probe with 1000 bytes packets, should be detected as a
218 // probe. 177 // probe.
219 for (int i = 0; i < kNumProbes; ++i) { 178 for (int i = 0; i < kNumProbes; ++i) {
220 clock_.AdvanceTimeMilliseconds(10); 179 clock_.AdvanceTimeMilliseconds(10);
221 now_ms = clock_.TimeInMilliseconds(); 180 now_ms = clock_.TimeInMilliseconds();
222 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); 181 IncomingFeedback(now_ms, now_ms, seq_num++, 1000, 1);
223 } 182 }
224 183
225 // Wait long enough so that we can call Process again. 184 // Wait long enough so that we can call Process again.
226 clock_.AdvanceTimeMilliseconds(1000); 185 clock_.AdvanceTimeMilliseconds(1000);
227 186
228 EXPECT_TRUE(bitrate_updated()); 187 EXPECT_TRUE(bitrate_observer_->updated());
229 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); 188 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000u);
189 }
190
191 TEST_F(DelayBasedBweTest, InitialBehavior) {
192 InitialBehaviorTestHelper(674840);
193 }
194
195 TEST_F(DelayBasedBweTest, RateIncreaseReordering) {
196 RateIncreaseReorderingTestHelper(674840);
197 }
198
199 TEST_F(DelayBasedBweTest, RateIncreaseRtpTimestamps) {
200 RateIncreaseRtpTimestampsTestHelper(1240);
201 }
202
203 TEST_F(DelayBasedBweTest, CapacityDropOneStream) {
204 CapacityDropTestHelper(1, false, 633, 0);
205 }
206
207 TEST_F(DelayBasedBweTest, CapacityDropPosOffsetChange) {
208 CapacityDropTestHelper(1, false, 200, 30000);
209 }
210
211 TEST_F(DelayBasedBweTest, CapacityDropNegOffsetChange) {
212 CapacityDropTestHelper(1, false, 733, -30000);
213 }
214
215 TEST_F(DelayBasedBweTest, CapacityDropOneStreamWrap) {
216 CapacityDropTestHelper(1, true, 633, 0);
217 }
218
219 TEST_F(DelayBasedBweTest, CapacityDropTwoStreamsWrap) {
220 CapacityDropTestHelper(2, true, 567, 0);
221 }
222
223 TEST_F(DelayBasedBweTest, CapacityDropThreeStreamsWrap) {
224 CapacityDropTestHelper(3, true, 633, 0);
225 }
226
227 TEST_F(DelayBasedBweTest, CapacityDropThirteenStreamsWrap) {
228 CapacityDropTestHelper(13, true, 733, 0);
229 }
230
231 TEST_F(DelayBasedBweTest, CapacityDropNineteenStreamsWrap) {
232 CapacityDropTestHelper(19, true, 667, 0);
233 }
234
235 TEST_F(DelayBasedBweTest, CapacityDropThirtyStreamsWrap) {
236 CapacityDropTestHelper(30, true, 667, 0);
237 }
238
239 TEST_F(DelayBasedBweTest, TestTimestampGrouping) {
240 TestTimestampGroupingTestHelper();
241 }
242
243 TEST_F(DelayBasedBweTest, TestShortTimeoutAndWrap) {
244 // Simulate a client leaving and rejoining the call after 35 seconds. This
245 // will make abs send time wrap, so if streams aren't timed out properly
246 // the next 30 seconds of packets will be out of order.
247 TestWrappingHelper(35);
248 }
249
250 TEST_F(DelayBasedBweTest, TestLongTimeoutAndWrap) {
251 // Simulate a client leaving and rejoining the call after some multiple of
252 // 64 seconds later. This will cause a zero difference in abs send times due
253 // to the wrap, but a big difference in arrival time, if streams aren't
254 // properly timed out.
255 TestWrappingHelper(10 * 64);
230 } 256 }
231 } // namespace webrtc 257 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698