OLD | NEW |
---|---|
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" |
philipel
2016/07/06 13:36:36
Move to top
stefan-webrtc
2016/07/06 14:53:24
I don't think it should be at the top since this i
philipel
2016/07/07 08:11:38
Right, my bad.
| |
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 class TestDelayBasedBwe : public ::testing::Test, public RemoteBitrateObserver { |
20 public: | 21 public: |
21 static constexpr int kArrivalTimeClockOffsetMs = 60000; | 22 static constexpr int kArrivalTimeClockOffsetMs = 60000; |
22 static constexpr int kNumProbes = 5; | 23 static constexpr int kNumProbes = 5; |
philipel
2016/07/06 13:36:36
Move both constexpr to namespace {...} and drop st
stefan-webrtc
2016/07/06 14:53:24
Done.
| |
23 | 24 |
24 TestDelayBasedBwe() | 25 TestDelayBasedBwe() |
25 : bwe_(this), clock_(0), bitrate_updated_(false), latest_bitrate_(0) {} | 26 : clock_(0), |
27 bwe_(this, &clock_), | |
28 bitrate_updated_(false), | |
29 latest_bitrate_(0) {} | |
26 | 30 |
27 uint32_t AbsSendTime(int64_t t, int64_t denom) { | 31 uint32_t AbsSendTime(int64_t t, int64_t denom) { |
philipel
2016/07/06 13:36:36
Remove, since it's not used anymore.
stefan-webrtc
2016/07/06 14:53:24
Done.
| |
28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 32 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
29 } | 33 } |
30 | 34 |
31 void IncomingPacket(uint32_t ssrc, | 35 void IncomingPacket(int64_t arrival_time, |
philipel
2016/07/06 13:36:36
Rename to AddPacketInfo or IncomingFeedback or som
stefan-webrtc
2016/07/06 14:53:24
Done.
| |
36 int64_t send_time_ms, | |
philipel
2016/07/06 13:36:36
|arrival_time| -> |arrival_time_ms|
Nit: don't yo
stefan-webrtc
2016/07/06 14:53:24
Done.
| |
37 uint16_t sequence_number, | |
32 size_t payload_size, | 38 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) { | 39 int probe_cluster_id) { |
37 RTPHeader header; | 40 std::vector<PacketInfo> packets; |
38 memset(&header, 0, sizeof(header)); | 41 packets.push_back(PacketInfo(arrival_time + kArrivalTimeClockOffsetMs, |
39 header.ssrc = ssrc; | 42 send_time_ms, sequence_number, payload_size, |
philipel
2016/07/06 13:36:36
Sequence number is not used by delay_based_bwe, se
stefan-webrtc
2016/07/06 14:53:24
I don't know, it seems like a good idea to pass in
philipel
2016/07/07 08:11:38
That makes sense.
| |
40 header.timestamp = rtp_timestamp; | 43 probe_cluster_id)); |
41 header.extension.hasAbsoluteSendTime = true; | 44 bwe_.IncomingPacketFeedbackVector(packets); |
42 header.extension.absoluteSendTime = absolute_send_time; | |
43 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size, | |
44 header, probe_cluster_id); | |
45 } | 45 } |
46 | 46 |
47 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, | 47 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
48 uint32_t bitrate) { | 48 uint32_t bitrate) { |
49 bitrate_updated_ = true; | 49 bitrate_updated_ = true; |
50 latest_bitrate_ = bitrate; | 50 latest_bitrate_ = bitrate; |
51 } | 51 } |
52 | 52 |
53 bool bitrate_updated() { | 53 bool bitrate_updated() { |
54 bool res = bitrate_updated_; | 54 bool res = bitrate_updated_; |
55 bitrate_updated_ = false; | 55 bitrate_updated_ = false; |
56 return res; | 56 return res; |
57 } | 57 } |
58 | 58 |
59 int latest_bitrate() { return latest_bitrate_; } | 59 int latest_bitrate() { return latest_bitrate_; } |
60 | 60 |
61 protected: | |
62 SimulatedClock clock_; | |
61 DelayBasedBwe bwe_; | 63 DelayBasedBwe bwe_; |
62 SimulatedClock clock_; | |
63 | 64 |
64 private: | 65 private: |
65 bool bitrate_updated_; | 66 bool bitrate_updated_; |
66 int latest_bitrate_; | 67 int latest_bitrate_; |
67 }; | 68 }; |
68 | 69 |
69 TEST_F(TestDelayBasedBwe, ProbeDetection) { | 70 TEST_F(TestDelayBasedBwe, ProbeDetection) { |
70 int64_t now_ms = clock_.TimeInMilliseconds(); | 71 int64_t now_ms = clock_.TimeInMilliseconds(); |
72 uint16_t seq_num = 0; | |
71 | 73 |
72 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 74 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
73 for (int i = 0; i < kNumProbes; ++i) { | 75 for (int i = 0; i < kNumProbes; ++i) { |
74 clock_.AdvanceTimeMilliseconds(10); | 76 clock_.AdvanceTimeMilliseconds(10); |
75 now_ms = clock_.TimeInMilliseconds(); | 77 now_ms = clock_.TimeInMilliseconds(); |
76 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); | 78 IncomingPacket(now_ms, now_ms, seq_num++, 1000, 1); |
philipel
2016/07/06 13:36:36
Note: 0 is a valid probe cluster id.
stefan-webrtc
2016/07/06 14:53:24
Yes, I happened to change it because I thought it
| |
77 } | 79 } |
78 EXPECT_TRUE(bitrate_updated()); | 80 EXPECT_TRUE(bitrate_updated()); |
79 | 81 |
80 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. | 82 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. |
81 for (int i = 0; i < kNumProbes; ++i) { | 83 for (int i = 0; i < kNumProbes; ++i) { |
82 clock_.AdvanceTimeMilliseconds(5); | 84 clock_.AdvanceTimeMilliseconds(5); |
83 now_ms = clock_.TimeInMilliseconds(); | 85 now_ms = clock_.TimeInMilliseconds(); |
84 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); | 86 IncomingPacket(now_ms, now_ms, seq_num++, 1000, 2); |
85 } | 87 } |
86 | 88 |
87 EXPECT_TRUE(bitrate_updated()); | 89 EXPECT_TRUE(bitrate_updated()); |
88 EXPECT_GT(latest_bitrate(), 1500000); | 90 EXPECT_GT(latest_bitrate(), 1500000); |
89 } | 91 } |
90 | 92 |
91 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { | 93 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { |
92 int64_t now_ms = clock_.TimeInMilliseconds(); | 94 int64_t now_ms = clock_.TimeInMilliseconds(); |
95 uint16_t seq_num = 0; | |
93 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet | 96 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet |
94 // not being paced which could mess things up. | 97 // not being paced which could mess things up. |
95 for (int i = 0; i < kNumProbes; ++i) { | 98 for (int i = 0; i < kNumProbes; ++i) { |
96 clock_.AdvanceTimeMilliseconds(5); | 99 clock_.AdvanceTimeMilliseconds(5); |
97 now_ms = clock_.TimeInMilliseconds(); | 100 now_ms = clock_.TimeInMilliseconds(); |
98 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); | 101 IncomingPacket(now_ms, now_ms, seq_num++, 1000, 1); |
99 // Non-paced packet, arriving 5 ms after. | 102 // Non-paced packet, arriving 5 ms after. |
100 clock_.AdvanceTimeMilliseconds(5); | 103 clock_.AdvanceTimeMilliseconds(5); |
101 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, | 104 IncomingPacket(now_ms, now_ms, seq_num++, |
102 AbsSendTime(now_ms, 1000), PacketInfo::kNotAProbe); | 105 PacedSender::kMinProbePacketSize + 1, |
106 PacketInfo::kNotAProbe); | |
103 } | 107 } |
104 | 108 |
105 EXPECT_TRUE(bitrate_updated()); | 109 EXPECT_TRUE(bitrate_updated()); |
106 EXPECT_GT(latest_bitrate(), 800000); | 110 EXPECT_GT(latest_bitrate(), 800000); |
107 } | 111 } |
108 | 112 |
109 // Packets will require 5 ms to be transmitted to the receiver, causing packets | 113 // Packets will require 5 ms to be transmitted to the receiver, causing packets |
110 // of the second probe to be dispersed. | 114 // of the second probe to be dispersed. |
111 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { | 115 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { |
112 int64_t now_ms = clock_.TimeInMilliseconds(); | 116 int64_t now_ms = clock_.TimeInMilliseconds(); |
113 int64_t send_time_ms = 0; | 117 int64_t send_time_ms = 0; |
118 uint16_t seq_num = 0; | |
114 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 119 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
115 for (int i = 0; i < kNumProbes; ++i) { | 120 for (int i = 0; i < kNumProbes; ++i) { |
116 clock_.AdvanceTimeMilliseconds(10); | 121 clock_.AdvanceTimeMilliseconds(10); |
117 now_ms = clock_.TimeInMilliseconds(); | 122 now_ms = clock_.TimeInMilliseconds(); |
118 send_time_ms += 10; | 123 send_time_ms += 10; |
119 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 124 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 1); |
120 AbsSendTime(send_time_ms, 1000), 0); | |
121 } | 125 } |
122 | 126 |
123 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = | 127 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = |
124 // 1000 kbps. | 128 // 1000 kbps. |
125 for (int i = 0; i < kNumProbes; ++i) { | 129 for (int i = 0; i < kNumProbes; ++i) { |
126 clock_.AdvanceTimeMilliseconds(8); | 130 clock_.AdvanceTimeMilliseconds(8); |
127 now_ms = clock_.TimeInMilliseconds(); | 131 now_ms = clock_.TimeInMilliseconds(); |
128 send_time_ms += 5; | 132 send_time_ms += 5; |
129 IncomingPacket(0, 1000, now_ms, send_time_ms, | 133 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 2); |
130 AbsSendTime(send_time_ms, 1000), 1); | |
131 } | 134 } |
132 | 135 |
133 EXPECT_TRUE(bitrate_updated()); | 136 EXPECT_TRUE(bitrate_updated()); |
134 EXPECT_NEAR(latest_bitrate(), 800000, 10000); | 137 EXPECT_NEAR(latest_bitrate(), 800000, 10000); |
135 } | 138 } |
136 | 139 |
137 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { | 140 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { |
138 int64_t now_ms = clock_.TimeInMilliseconds(); | 141 int64_t now_ms = clock_.TimeInMilliseconds(); |
142 uint16_t seq_num = 0; | |
139 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 143 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
140 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 144 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
141 int64_t send_time_ms = 0; | 145 int64_t send_time_ms = 0; |
142 for (int i = 0; i < kNumProbes; ++i) { | 146 for (int i = 0; i < kNumProbes; ++i) { |
143 clock_.AdvanceTimeMilliseconds(5); | 147 clock_.AdvanceTimeMilliseconds(5); |
144 send_time_ms += 10; | 148 send_time_ms += 10; |
145 now_ms = clock_.TimeInMilliseconds(); | 149 now_ms = clock_.TimeInMilliseconds(); |
146 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 150 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 23); |
147 AbsSendTime(send_time_ms, 1000), 23); | |
148 } | 151 } |
149 | 152 |
150 EXPECT_TRUE(bitrate_updated()); | 153 EXPECT_TRUE(bitrate_updated()); |
151 EXPECT_GT(latest_bitrate(), 800000); | 154 EXPECT_GT(latest_bitrate(), 800000); |
152 } | 155 } |
153 | 156 |
154 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { | 157 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { |
155 int64_t now_ms = clock_.TimeInMilliseconds(); | 158 int64_t now_ms = clock_.TimeInMilliseconds(); |
159 uint16_t seq_num = 0; | |
156 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 160 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
157 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 161 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
158 int64_t send_time_ms = 0; | 162 int64_t send_time_ms = 0; |
159 for (int i = 0; i < kNumProbes; ++i) { | 163 for (int i = 0; i < kNumProbes; ++i) { |
160 clock_.AdvanceTimeMilliseconds(1); | 164 clock_.AdvanceTimeMilliseconds(1); |
161 send_time_ms += 10; | 165 send_time_ms += 10; |
162 now_ms = clock_.TimeInMilliseconds(); | 166 now_ms = clock_.TimeInMilliseconds(); |
163 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 167 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 1); |
164 AbsSendTime(send_time_ms, 1000), 0); | |
165 } | 168 } |
166 | 169 |
167 EXPECT_FALSE(bitrate_updated()); | 170 EXPECT_FALSE(bitrate_updated()); |
168 } | 171 } |
169 | 172 |
170 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { | 173 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { |
171 int64_t now_ms = clock_.TimeInMilliseconds(); | 174 int64_t now_ms = clock_.TimeInMilliseconds(); |
175 uint16_t seq_num = 0; | |
172 // First burst sent at 8 * 1000 / 5 = 1600 kbps. | 176 // First burst sent at 8 * 1000 / 5 = 1600 kbps. |
173 // Arriving at 8 * 1000 / 7 = 1142 kbps. | 177 // Arriving at 8 * 1000 / 7 = 1142 kbps. |
174 int64_t send_time_ms = 0; | 178 int64_t send_time_ms = 0; |
175 for (int i = 0; i < kNumProbes; ++i) { | 179 for (int i = 0; i < kNumProbes; ++i) { |
176 clock_.AdvanceTimeMilliseconds(7); | 180 clock_.AdvanceTimeMilliseconds(7); |
177 send_time_ms += 5; | 181 send_time_ms += 5; |
178 now_ms = clock_.TimeInMilliseconds(); | 182 now_ms = clock_.TimeInMilliseconds(); |
179 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 183 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 1); |
180 AbsSendTime(send_time_ms, 1000), 1); | |
181 } | 184 } |
182 | 185 |
183 EXPECT_TRUE(bitrate_updated()); | 186 EXPECT_TRUE(bitrate_updated()); |
184 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); | 187 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); |
185 } | 188 } |
186 | 189 |
187 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { | 190 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { |
188 int64_t now_ms = clock_.TimeInMilliseconds(); | 191 int64_t now_ms = clock_.TimeInMilliseconds(); |
192 uint16_t seq_num = 0; | |
189 // Burst sent at 8 * 1000 / 1 = 8000 kbps. | 193 // Burst sent at 8 * 1000 / 1 = 8000 kbps. |
190 // Arriving at 8 * 1000 / 2 = 4000 kbps. | 194 // Arriving at 8 * 1000 / 2 = 4000 kbps. |
191 int64_t send_time_ms = 0; | 195 int64_t send_time_ms = 0; |
192 for (int i = 0; i < kNumProbes; ++i) { | 196 for (int i = 0; i < kNumProbes; ++i) { |
193 clock_.AdvanceTimeMilliseconds(2); | 197 clock_.AdvanceTimeMilliseconds(2); |
194 send_time_ms += 1; | 198 send_time_ms += 1; |
195 now_ms = clock_.TimeInMilliseconds(); | 199 now_ms = clock_.TimeInMilliseconds(); |
196 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 200 IncomingPacket(now_ms, send_time_ms, seq_num++, 1000, 1); |
197 AbsSendTime(send_time_ms, 1000), 1); | |
198 } | 201 } |
199 | 202 |
200 EXPECT_TRUE(bitrate_updated()); | 203 EXPECT_TRUE(bitrate_updated()); |
201 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); | 204 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); |
202 } | 205 } |
203 | 206 |
204 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { | 207 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { |
205 int64_t now_ms = clock_.TimeInMilliseconds(); | 208 int64_t now_ms = clock_.TimeInMilliseconds(); |
209 uint16_t seq_num = 0; | |
206 // Probing with 200 bytes every 10 ms, should be ignored by the probe | 210 // Probing with 200 bytes every 10 ms, should be ignored by the probe |
207 // detection. | 211 // detection. |
208 for (int i = 0; i < kNumProbes; ++i) { | 212 for (int i = 0; i < kNumProbes; ++i) { |
209 clock_.AdvanceTimeMilliseconds(10); | 213 clock_.AdvanceTimeMilliseconds(10); |
210 now_ms = clock_.TimeInMilliseconds(); | 214 now_ms = clock_.TimeInMilliseconds(); |
211 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, | 215 IncomingPacket(now_ms, now_ms, seq_num++, PacedSender::kMinProbePacketSize, |
212 AbsSendTime(now_ms, 1000), 1); | 216 1); |
213 } | 217 } |
214 | 218 |
215 EXPECT_FALSE(bitrate_updated()); | 219 EXPECT_FALSE(bitrate_updated()); |
216 | 220 |
217 // Followed by a probe with 1000 bytes packets, should be detected as a | 221 // Followed by a probe with 1000 bytes packets, should be detected as a |
218 // probe. | 222 // probe. |
219 for (int i = 0; i < kNumProbes; ++i) { | 223 for (int i = 0; i < kNumProbes; ++i) { |
220 clock_.AdvanceTimeMilliseconds(10); | 224 clock_.AdvanceTimeMilliseconds(10); |
221 now_ms = clock_.TimeInMilliseconds(); | 225 now_ms = clock_.TimeInMilliseconds(); |
222 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); | 226 IncomingPacket(now_ms, now_ms, seq_num++, 1000, 1); |
223 } | 227 } |
224 | 228 |
225 // Wait long enough so that we can call Process again. | 229 // Wait long enough so that we can call Process again. |
226 clock_.AdvanceTimeMilliseconds(1000); | 230 clock_.AdvanceTimeMilliseconds(1000); |
227 | 231 |
228 EXPECT_TRUE(bitrate_updated()); | 232 EXPECT_TRUE(bitrate_updated()); |
229 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); | 233 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); |
230 } | 234 } |
235 | |
236 TEST_F(DelayBasedBweTest, InitialBehavior) { | |
237 InitialBehaviorTestHelper(674840); | |
238 } | |
239 | |
240 TEST_F(DelayBasedBweTest, RateIncreaseReordering) { | |
241 RateIncreaseReorderingTestHelper(674840); | |
242 } | |
243 | |
244 TEST_F(DelayBasedBweTest, RateIncreaseRtpTimestamps) { | |
245 RateIncreaseRtpTimestampsTestHelper(1240); | |
246 } | |
247 | |
248 TEST_F(DelayBasedBweTest, CapacityDropOneStream) { | |
249 CapacityDropTestHelper(1, false, 633, 0); | |
250 } | |
251 | |
252 TEST_F(DelayBasedBweTest, CapacityDropPosOffsetChange) { | |
253 CapacityDropTestHelper(1, false, 200, 30000); | |
254 } | |
255 | |
256 TEST_F(DelayBasedBweTest, CapacityDropNegOffsetChange) { | |
257 CapacityDropTestHelper(1, false, 733, -30000); | |
258 } | |
259 | |
260 TEST_F(DelayBasedBweTest, CapacityDropOneStreamWrap) { | |
261 CapacityDropTestHelper(1, true, 633, 0); | |
262 } | |
263 | |
264 TEST_F(DelayBasedBweTest, CapacityDropTwoStreamsWrap) { | |
265 CapacityDropTestHelper(2, true, 567, 0); | |
266 } | |
267 | |
268 TEST_F(DelayBasedBweTest, CapacityDropThreeStreamsWrap) { | |
269 CapacityDropTestHelper(3, true, 633, 0); | |
270 } | |
271 | |
272 TEST_F(DelayBasedBweTest, CapacityDropThirteenStreamsWrap) { | |
273 CapacityDropTestHelper(13, true, 733, 0); | |
274 } | |
275 | |
276 TEST_F(DelayBasedBweTest, CapacityDropNineteenStreamsWrap) { | |
277 CapacityDropTestHelper(19, true, 667, 0); | |
278 } | |
279 | |
280 TEST_F(DelayBasedBweTest, CapacityDropThirtyStreamsWrap) { | |
281 CapacityDropTestHelper(30, true, 667, 0); | |
282 } | |
283 | |
284 TEST_F(DelayBasedBweTest, TestTimestampGrouping) { | |
285 TestTimestampGroupingTestHelper(); | |
286 } | |
287 | |
288 TEST_F(DelayBasedBweTest, TestShortTimeoutAndWrap) { | |
289 // Simulate a client leaving and rejoining the call after 35 seconds. This | |
290 // will make abs send time wrap, so if streams aren't timed out properly | |
291 // the next 30 seconds of packets will be out of order. | |
292 TestWrappingHelper(35); | |
293 } | |
294 | |
295 TEST_F(DelayBasedBweTest, TestLongTimeoutAndWrap) { | |
296 // Simulate a client leaving and rejoining the call after some multiple of | |
297 // 64 seconds later. This will cause a zero difference in abs send times due | |
298 // to the wrap, but a big difference in arrival time, if streams aren't | |
299 // properly timed out. | |
300 TestWrappingHelper(10 * 64); | |
301 } | |
302 | |
303 TEST_F(DelayBasedBweTest, TestProcessAfterTimeout) { | |
304 // This time constant must be equal to the ones defined for the | |
305 // RemoteBitrateEstimator. | |
306 const int64_t kStreamTimeOutMs = 2000; | |
307 const int64_t kProcessIntervalMs = 1000; | |
308 IncomingPacket(1000, clock_.TimeInMilliseconds(), 0, 0); | |
309 clock_.AdvanceTimeMilliseconds(kStreamTimeOutMs + 1); | |
310 // Trigger timeout. | |
311 bitrate_estimator_->Process(); | |
312 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); | |
313 // This shouldn't crash. | |
314 bitrate_estimator_->Process(); | |
315 } | |
316 | |
317 TEST_F(DelayBasedBweTest, TestProbeDetection) { | |
318 const int kProbeLength = 5; | |
319 int64_t now_ms = clock_.TimeInMilliseconds(); | |
320 uint16_t sequence_number = 0; | |
321 // First burst sent at 8 * 1000 / 10 = 800 kbps. | |
322 for (int i = 0; i < kProbeLength; ++i) { | |
323 clock_.AdvanceTimeMilliseconds(10); | |
324 now_ms = clock_.TimeInMilliseconds(); | |
325 IncomingPacket(1000, now_ms, now_ms, sequence_number++, 1); | |
326 } | |
327 | |
328 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. | |
329 for (int i = 0; i < kProbeLength; ++i) { | |
330 clock_.AdvanceTimeMilliseconds(5); | |
331 now_ms = clock_.TimeInMilliseconds(); | |
332 IncomingPacket(1000, now_ms, now_ms, sequence_number++, 2); | |
333 } | |
334 | |
335 bitrate_estimator_->Process(); | |
336 EXPECT_TRUE(bitrate_observer_->updated()); | |
337 EXPECT_GT(bitrate_observer_->latest_bitrate(), 1500000u); | |
338 } | |
339 | |
340 TEST_F(DelayBasedBweTest, TestProbeDetectionNonPacedPackets) { | |
341 const int kProbeLength = 5; | |
342 int64_t now_ms = clock_.TimeInMilliseconds(); | |
343 uint16_t sequence_number = 0; | |
344 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet | |
345 // not being paced which could mess things up. | |
346 for (int i = 0; i < kProbeLength; ++i) { | |
347 clock_.AdvanceTimeMilliseconds(5); | |
348 now_ms = clock_.TimeInMilliseconds(); | |
349 IncomingPacket(1000, now_ms, now_ms, sequence_number++, 1); | |
350 // Non-paced packet, arriving 5 ms after. | |
351 clock_.AdvanceTimeMilliseconds(5); | |
352 IncomingPacket(100, now_ms, now_ms, sequence_number++, | |
353 PacketInfo::kNotAProbe); | |
354 } | |
355 | |
356 bitrate_estimator_->Process(); | |
357 EXPECT_TRUE(bitrate_observer_->updated()); | |
358 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); | |
359 } | |
360 | |
361 // Packets will require 5 ms to be transmitted to the receiver, causing packets | |
362 // of the second probe to be dispersed. | |
363 TEST_F(DelayBasedBweTest, TestProbeDetectionTooHighBitrate) { | |
364 const int kProbeLength = 5; | |
365 int64_t now_ms = clock_.TimeInMilliseconds(); | |
366 int64_t send_time_ms = 0; | |
367 uint16_t sequence_number = 0; | |
368 // First burst sent at 8 * 1000 / 10 = 800 kbps. | |
369 for (int i = 0; i < kProbeLength; ++i) { | |
370 clock_.AdvanceTimeMilliseconds(10); | |
371 now_ms = clock_.TimeInMilliseconds(); | |
372 send_time_ms += 10; | |
373 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 1); | |
374 } | |
375 | |
376 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = | |
377 // 1000 kbps. | |
378 for (int i = 0; i < kProbeLength; ++i) { | |
379 clock_.AdvanceTimeMilliseconds(8); | |
380 now_ms = clock_.TimeInMilliseconds(); | |
381 send_time_ms += 5; | |
382 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 2); | |
383 } | |
384 | |
385 bitrate_estimator_->Process(); | |
386 EXPECT_TRUE(bitrate_observer_->updated()); | |
387 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); | |
388 } | |
389 | |
390 TEST_F(DelayBasedBweTest, TestProbeDetectionSlightlyFasterArrival) { | |
391 const int kProbeLength = 5; | |
392 int64_t now_ms = clock_.TimeInMilliseconds(); | |
393 uint16_t sequence_number = 0; | |
394 // First burst sent at 8 * 1000 / 10 = 800 kbps. | |
395 // Arriving at 8 * 1000 / 5 = 1600 kbps. | |
396 int64_t send_time_ms = 0; | |
397 for (int i = 0; i < kProbeLength; ++i) { | |
398 clock_.AdvanceTimeMilliseconds(5); | |
399 send_time_ms += 10; | |
400 now_ms = clock_.TimeInMilliseconds(); | |
401 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 1); | |
402 } | |
403 | |
404 bitrate_estimator_->Process(); | |
405 EXPECT_TRUE(bitrate_observer_->updated()); | |
406 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); | |
407 } | |
408 | |
409 TEST_F(DelayBasedBweTest, TestProbeDetectionFasterArrival) { | |
410 const int kProbeLength = 5; | |
411 int64_t now_ms = clock_.TimeInMilliseconds(); | |
412 uint16_t sequence_number = 0; | |
413 // First burst sent at 8 * 1000 / 10 = 800 kbps. | |
414 // Arriving at 8 * 1000 / 5 = 1600 kbps. | |
415 int64_t send_time_ms = 0; | |
416 for (int i = 0; i < kProbeLength; ++i) { | |
417 clock_.AdvanceTimeMilliseconds(1); | |
418 send_time_ms += 10; | |
419 now_ms = clock_.TimeInMilliseconds(); | |
420 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 1); | |
421 } | |
422 | |
423 bitrate_estimator_->Process(); | |
424 EXPECT_FALSE(bitrate_observer_->updated()); | |
425 } | |
426 | |
427 TEST_F(DelayBasedBweTest, TestProbeDetectionSlowerArrival) { | |
428 const int kProbeLength = 5; | |
429 int64_t now_ms = clock_.TimeInMilliseconds(); | |
430 uint16_t sequence_number = 0; | |
431 // First burst sent at 8 * 1000 / 5 = 1600 kbps. | |
432 // Arriving at 8 * 1000 / 7 = 1142 kbps. | |
433 int64_t send_time_ms = 0; | |
434 for (int i = 0; i < kProbeLength; ++i) { | |
435 clock_.AdvanceTimeMilliseconds(7); | |
436 send_time_ms += 5; | |
437 now_ms = clock_.TimeInMilliseconds(); | |
438 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 1); | |
439 } | |
440 | |
441 bitrate_estimator_->Process(); | |
442 EXPECT_TRUE(bitrate_observer_->updated()); | |
443 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 1140000, 10000); | |
444 } | |
445 | |
446 TEST_F(DelayBasedBweTest, TestProbeDetectionSlowerArrivalHighBitrate) { | |
447 const int kProbeLength = 5; | |
448 int64_t now_ms = clock_.TimeInMilliseconds(); | |
449 uint16_t sequence_number = 0; | |
450 // Burst sent at 8 * 1000 / 1 = 8000 kbps. | |
451 // Arriving at 8 * 1000 / 2 = 4000 kbps. | |
452 int64_t send_time_ms = 0; | |
453 for (int i = 0; i < kProbeLength; ++i) { | |
454 clock_.AdvanceTimeMilliseconds(2); | |
455 send_time_ms += 1; | |
456 now_ms = clock_.TimeInMilliseconds(); | |
457 IncomingPacket(1000, now_ms, send_time_ms, sequence_number++, 1); | |
458 } | |
459 | |
460 bitrate_estimator_->Process(); | |
461 EXPECT_TRUE(bitrate_observer_->updated()); | |
462 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 4000000u, 10000); | |
463 } | |
464 | |
465 TEST_F(DelayBasedBweTest, ProbingIgnoresSmallPackets) { | |
466 const int kProbeLength = 5; | |
467 int64_t now_ms = clock_.TimeInMilliseconds(); | |
468 uint16_t sequence_number = 0; | |
469 // Probing with 200 bytes every 10 ms, should be ignored by the probe | |
470 // detection. | |
471 for (int i = 0; i < kProbeLength; ++i) { | |
472 clock_.AdvanceTimeMilliseconds(10); | |
473 now_ms = clock_.TimeInMilliseconds(); | |
474 IncomingPacket(200, now_ms, now_ms, sequence_number++, 1); | |
475 } | |
476 | |
477 bitrate_estimator_->Process(); | |
478 EXPECT_FALSE(bitrate_observer_->updated()); | |
479 | |
480 // Followed by a probe with 1000 bytes packets, should be detected as a | |
481 // probe. | |
482 for (int i = 0; i < kProbeLength; ++i) { | |
483 clock_.AdvanceTimeMilliseconds(10); | |
484 now_ms = clock_.TimeInMilliseconds(); | |
485 IncomingPacket(1000, now_ms, now_ms, sequence_number++, 2); | |
486 } | |
487 | |
488 // Wait long enough so that we can call Process again. | |
489 clock_.AdvanceTimeMilliseconds(1000); | |
490 | |
491 bitrate_estimator_->Process(); | |
492 EXPECT_TRUE(bitrate_observer_->updated()); | |
493 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); | |
494 } | |
231 } // namespace webrtc | 495 } // namespace webrtc |
OLD | NEW |