OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 | 87 |
88 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProcessAfterTimeout) { | 88 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProcessAfterTimeout) { |
89 // This time constant must be equal to the ones defined for the | 89 // This time constant must be equal to the ones defined for the |
90 // RemoteBitrateEstimator. | 90 // RemoteBitrateEstimator. |
91 const int64_t kStreamTimeOutMs = 2000; | 91 const int64_t kStreamTimeOutMs = 2000; |
92 const int64_t kProcessIntervalMs = 1000; | 92 const int64_t kProcessIntervalMs = 1000; |
93 IncomingPacket(0, 1000, clock_.TimeInMilliseconds(), 0, 0, true); | 93 IncomingPacket(0, 1000, clock_.TimeInMilliseconds(), 0, 0, true); |
94 clock_.AdvanceTimeMilliseconds(kStreamTimeOutMs + 1); | 94 clock_.AdvanceTimeMilliseconds(kStreamTimeOutMs + 1); |
95 // Trigger timeout. | 95 // Trigger timeout. |
96 EXPECT_EQ(0, bitrate_estimator_->Process()); | 96 bitrate_estimator_->Process(); |
97 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); | 97 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); |
98 // This shouldn't crash. | 98 // This shouldn't crash. |
99 EXPECT_EQ(0, bitrate_estimator_->Process()); | 99 bitrate_estimator_->Process(); |
100 } | 100 } |
101 | 101 |
102 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetection) { | 102 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetection) { |
103 const int kProbeLength = 5; | 103 const int kProbeLength = 5; |
104 int64_t now_ms = clock_.TimeInMilliseconds(); | 104 int64_t now_ms = clock_.TimeInMilliseconds(); |
105 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 105 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
106 for (int i = 0; i < kProbeLength; ++i) { | 106 for (int i = 0; i < kProbeLength; ++i) { |
107 clock_.AdvanceTimeMilliseconds(10); | 107 clock_.AdvanceTimeMilliseconds(10); |
108 now_ms = clock_.TimeInMilliseconds(); | 108 now_ms = clock_.TimeInMilliseconds(); |
109 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 109 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
110 true); | 110 true); |
111 } | 111 } |
112 | 112 |
113 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. | 113 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. |
114 for (int i = 0; i < kProbeLength; ++i) { | 114 for (int i = 0; i < kProbeLength; ++i) { |
115 clock_.AdvanceTimeMilliseconds(5); | 115 clock_.AdvanceTimeMilliseconds(5); |
116 now_ms = clock_.TimeInMilliseconds(); | 116 now_ms = clock_.TimeInMilliseconds(); |
117 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 117 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
118 true); | 118 true); |
119 } | 119 } |
120 | 120 |
121 EXPECT_EQ(0, bitrate_estimator_->Process()); | 121 bitrate_estimator_->Process(); |
122 EXPECT_TRUE(bitrate_observer_->updated()); | 122 EXPECT_TRUE(bitrate_observer_->updated()); |
123 EXPECT_GT(bitrate_observer_->latest_bitrate(), 1500000u); | 123 EXPECT_GT(bitrate_observer_->latest_bitrate(), 1500000u); |
124 } | 124 } |
125 | 125 |
126 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, | 126 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, |
127 TestProbeDetectionNonPacedPackets) { | 127 TestProbeDetectionNonPacedPackets) { |
128 const int kProbeLength = 5; | 128 const int kProbeLength = 5; |
129 int64_t now_ms = clock_.TimeInMilliseconds(); | 129 int64_t now_ms = clock_.TimeInMilliseconds(); |
130 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet | 130 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet |
131 // not being paced which could mess things up. | 131 // not being paced which could mess things up. |
132 for (int i = 0; i < kProbeLength; ++i) { | 132 for (int i = 0; i < kProbeLength; ++i) { |
133 clock_.AdvanceTimeMilliseconds(5); | 133 clock_.AdvanceTimeMilliseconds(5); |
134 now_ms = clock_.TimeInMilliseconds(); | 134 now_ms = clock_.TimeInMilliseconds(); |
135 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 135 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
136 true); | 136 true); |
137 // Non-paced packet, arriving 5 ms after. | 137 // Non-paced packet, arriving 5 ms after. |
138 clock_.AdvanceTimeMilliseconds(5); | 138 clock_.AdvanceTimeMilliseconds(5); |
139 IncomingPacket(0, 100, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 139 IncomingPacket(0, 100, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
140 false); | 140 false); |
141 } | 141 } |
142 | 142 |
143 EXPECT_EQ(0, bitrate_estimator_->Process()); | 143 bitrate_estimator_->Process(); |
144 EXPECT_TRUE(bitrate_observer_->updated()); | 144 EXPECT_TRUE(bitrate_observer_->updated()); |
145 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); | 145 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); |
146 } | 146 } |
147 | 147 |
148 // Packets will require 5 ms to be transmitted to the receiver, causing packets | 148 // Packets will require 5 ms to be transmitted to the receiver, causing packets |
149 // of the second probe to be dispersed. | 149 // of the second probe to be dispersed. |
150 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, | 150 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, |
151 TestProbeDetectionTooHighBitrate) { | 151 TestProbeDetectionTooHighBitrate) { |
152 const int kProbeLength = 5; | 152 const int kProbeLength = 5; |
153 int64_t now_ms = clock_.TimeInMilliseconds(); | 153 int64_t now_ms = clock_.TimeInMilliseconds(); |
(...skipping 10 matching lines...) Expand all Loading... |
164 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = | 164 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = |
165 // 1000 kbps. | 165 // 1000 kbps. |
166 for (int i = 0; i < kProbeLength; ++i) { | 166 for (int i = 0; i < kProbeLength; ++i) { |
167 clock_.AdvanceTimeMilliseconds(8); | 167 clock_.AdvanceTimeMilliseconds(8); |
168 now_ms = clock_.TimeInMilliseconds(); | 168 now_ms = clock_.TimeInMilliseconds(); |
169 send_time_ms += 5; | 169 send_time_ms += 5; |
170 IncomingPacket(0, 1000, now_ms, send_time_ms, | 170 IncomingPacket(0, 1000, now_ms, send_time_ms, |
171 AbsSendTime(send_time_ms, 1000), true); | 171 AbsSendTime(send_time_ms, 1000), true); |
172 } | 172 } |
173 | 173 |
174 EXPECT_EQ(0, bitrate_estimator_->Process()); | 174 bitrate_estimator_->Process(); |
175 EXPECT_TRUE(bitrate_observer_->updated()); | 175 EXPECT_TRUE(bitrate_observer_->updated()); |
176 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); | 176 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); |
177 } | 177 } |
178 | 178 |
179 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, | 179 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, |
180 TestProbeDetectionSlightlyFasterArrival) { | 180 TestProbeDetectionSlightlyFasterArrival) { |
181 const int kProbeLength = 5; | 181 const int kProbeLength = 5; |
182 int64_t now_ms = clock_.TimeInMilliseconds(); | 182 int64_t now_ms = clock_.TimeInMilliseconds(); |
183 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 183 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
184 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 184 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
185 int64_t send_time_ms = 0; | 185 int64_t send_time_ms = 0; |
186 for (int i = 0; i < kProbeLength; ++i) { | 186 for (int i = 0; i < kProbeLength; ++i) { |
187 clock_.AdvanceTimeMilliseconds(5); | 187 clock_.AdvanceTimeMilliseconds(5); |
188 send_time_ms += 10; | 188 send_time_ms += 10; |
189 now_ms = clock_.TimeInMilliseconds(); | 189 now_ms = clock_.TimeInMilliseconds(); |
190 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 190 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
191 AbsSendTime(send_time_ms, 1000), true); | 191 AbsSendTime(send_time_ms, 1000), true); |
192 } | 192 } |
193 | 193 |
194 EXPECT_EQ(0, bitrate_estimator_->Process()); | 194 bitrate_estimator_->Process(); |
195 EXPECT_TRUE(bitrate_observer_->updated()); | 195 EXPECT_TRUE(bitrate_observer_->updated()); |
196 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); | 196 EXPECT_GT(bitrate_observer_->latest_bitrate(), 800000u); |
197 } | 197 } |
198 | 198 |
199 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetectionFasterArrival) { | 199 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetectionFasterArrival) { |
200 const int kProbeLength = 5; | 200 const int kProbeLength = 5; |
201 int64_t now_ms = clock_.TimeInMilliseconds(); | 201 int64_t now_ms = clock_.TimeInMilliseconds(); |
202 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 202 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
203 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 203 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
204 int64_t send_time_ms = 0; | 204 int64_t send_time_ms = 0; |
205 for (int i = 0; i < kProbeLength; ++i) { | 205 for (int i = 0; i < kProbeLength; ++i) { |
206 clock_.AdvanceTimeMilliseconds(1); | 206 clock_.AdvanceTimeMilliseconds(1); |
207 send_time_ms += 10; | 207 send_time_ms += 10; |
208 now_ms = clock_.TimeInMilliseconds(); | 208 now_ms = clock_.TimeInMilliseconds(); |
209 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 209 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
210 AbsSendTime(send_time_ms, 1000), true); | 210 AbsSendTime(send_time_ms, 1000), true); |
211 } | 211 } |
212 | 212 |
213 EXPECT_EQ(0, bitrate_estimator_->Process()); | 213 bitrate_estimator_->Process(); |
214 EXPECT_FALSE(bitrate_observer_->updated()); | 214 EXPECT_FALSE(bitrate_observer_->updated()); |
215 } | 215 } |
216 | 216 |
217 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetectionSlowerArrival) { | 217 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, TestProbeDetectionSlowerArrival) { |
218 const int kProbeLength = 5; | 218 const int kProbeLength = 5; |
219 int64_t now_ms = clock_.TimeInMilliseconds(); | 219 int64_t now_ms = clock_.TimeInMilliseconds(); |
220 // First burst sent at 8 * 1000 / 5 = 1600 kbps. | 220 // First burst sent at 8 * 1000 / 5 = 1600 kbps. |
221 // Arriving at 8 * 1000 / 7 = 1142 kbps. | 221 // Arriving at 8 * 1000 / 7 = 1142 kbps. |
222 int64_t send_time_ms = 0; | 222 int64_t send_time_ms = 0; |
223 for (int i = 0; i < kProbeLength; ++i) { | 223 for (int i = 0; i < kProbeLength; ++i) { |
224 clock_.AdvanceTimeMilliseconds(7); | 224 clock_.AdvanceTimeMilliseconds(7); |
225 send_time_ms += 5; | 225 send_time_ms += 5; |
226 now_ms = clock_.TimeInMilliseconds(); | 226 now_ms = clock_.TimeInMilliseconds(); |
227 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 227 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
228 AbsSendTime(send_time_ms, 1000), true); | 228 AbsSendTime(send_time_ms, 1000), true); |
229 } | 229 } |
230 | 230 |
231 EXPECT_EQ(0, bitrate_estimator_->Process()); | 231 bitrate_estimator_->Process(); |
232 EXPECT_TRUE(bitrate_observer_->updated()); | 232 EXPECT_TRUE(bitrate_observer_->updated()); |
233 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 1140000, 10000); | 233 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 1140000, 10000); |
234 } | 234 } |
235 | 235 |
236 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, | 236 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, |
237 TestProbeDetectionSlowerArrivalHighBitrate) { | 237 TestProbeDetectionSlowerArrivalHighBitrate) { |
238 const int kProbeLength = 5; | 238 const int kProbeLength = 5; |
239 int64_t now_ms = clock_.TimeInMilliseconds(); | 239 int64_t now_ms = clock_.TimeInMilliseconds(); |
240 // Burst sent at 8 * 1000 / 1 = 8000 kbps. | 240 // Burst sent at 8 * 1000 / 1 = 8000 kbps. |
241 // Arriving at 8 * 1000 / 2 = 4000 kbps. | 241 // Arriving at 8 * 1000 / 2 = 4000 kbps. |
242 int64_t send_time_ms = 0; | 242 int64_t send_time_ms = 0; |
243 for (int i = 0; i < kProbeLength; ++i) { | 243 for (int i = 0; i < kProbeLength; ++i) { |
244 clock_.AdvanceTimeMilliseconds(2); | 244 clock_.AdvanceTimeMilliseconds(2); |
245 send_time_ms += 1; | 245 send_time_ms += 1; |
246 now_ms = clock_.TimeInMilliseconds(); | 246 now_ms = clock_.TimeInMilliseconds(); |
247 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 247 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
248 AbsSendTime(send_time_ms, 1000), true); | 248 AbsSendTime(send_time_ms, 1000), true); |
249 } | 249 } |
250 | 250 |
251 EXPECT_EQ(0, bitrate_estimator_->Process()); | 251 bitrate_estimator_->Process(); |
252 EXPECT_TRUE(bitrate_observer_->updated()); | 252 EXPECT_TRUE(bitrate_observer_->updated()); |
253 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 4000000u, 10000); | 253 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 4000000u, 10000); |
254 } | 254 } |
255 | 255 |
256 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, ProbingIgnoresSmallPackets) { | 256 TEST_F(RemoteBitrateEstimatorAbsSendTimeTest, ProbingIgnoresSmallPackets) { |
257 const int kProbeLength = 5; | 257 const int kProbeLength = 5; |
258 int64_t now_ms = clock_.TimeInMilliseconds(); | 258 int64_t now_ms = clock_.TimeInMilliseconds(); |
259 // Probing with 200 bytes every 10 ms, should be ignored by the probe | 259 // Probing with 200 bytes every 10 ms, should be ignored by the probe |
260 // detection. | 260 // detection. |
261 for (int i = 0; i < kProbeLength; ++i) { | 261 for (int i = 0; i < kProbeLength; ++i) { |
262 clock_.AdvanceTimeMilliseconds(10); | 262 clock_.AdvanceTimeMilliseconds(10); |
263 now_ms = clock_.TimeInMilliseconds(); | 263 now_ms = clock_.TimeInMilliseconds(); |
264 IncomingPacket(0, 200, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 264 IncomingPacket(0, 200, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
265 true); | 265 true); |
266 } | 266 } |
267 | 267 |
268 EXPECT_EQ(0, bitrate_estimator_->Process()); | 268 bitrate_estimator_->Process(); |
269 EXPECT_FALSE(bitrate_observer_->updated()); | 269 EXPECT_FALSE(bitrate_observer_->updated()); |
270 | 270 |
271 // Followed by a probe with 1000 bytes packets, should be detected as a | 271 // Followed by a probe with 1000 bytes packets, should be detected as a |
272 // probe. | 272 // probe. |
273 for (int i = 0; i < kProbeLength; ++i) { | 273 for (int i = 0; i < kProbeLength; ++i) { |
274 clock_.AdvanceTimeMilliseconds(10); | 274 clock_.AdvanceTimeMilliseconds(10); |
275 now_ms = clock_.TimeInMilliseconds(); | 275 now_ms = clock_.TimeInMilliseconds(); |
276 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), | 276 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
277 true); | 277 true); |
278 } | 278 } |
279 | 279 |
280 // Wait long enough so that we can call Process again. | 280 // Wait long enough so that we can call Process again. |
281 clock_.AdvanceTimeMilliseconds(1000); | 281 clock_.AdvanceTimeMilliseconds(1000); |
282 | 282 |
283 EXPECT_EQ(0, bitrate_estimator_->Process()); | 283 bitrate_estimator_->Process(); |
284 EXPECT_TRUE(bitrate_observer_->updated()); | 284 EXPECT_TRUE(bitrate_observer_->updated()); |
285 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); | 285 EXPECT_NEAR(bitrate_observer_->latest_bitrate(), 800000u, 10000); |
286 } | 286 } |
287 } // namespace webrtc | 287 } // namespace webrtc |
OLD | NEW |