OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 259 |
260 int kMinDelayPackets = kExpectedTarget + 2; | 260 int kMinDelayPackets = kExpectedTarget + 2; |
261 int kMinDelayMs = kMinDelayPackets * kFrameSizeMs; | 261 int kMinDelayMs = kMinDelayPackets * kFrameSizeMs; |
262 dm_->SetMinimumDelay(kMinDelayMs); | 262 dm_->SetMinimumDelay(kMinDelayMs); |
263 IncreaseTime(kTimeIncrement); | 263 IncreaseTime(kTimeIncrement); |
264 InsertNextPacket(); | 264 InsertNextPacket(); |
265 EXPECT_EQ(kExpectedTarget * kFrameSizeMs, dm_->least_required_delay_ms()); | 265 EXPECT_EQ(kExpectedTarget * kFrameSizeMs, dm_->least_required_delay_ms()); |
266 EXPECT_EQ(kMinDelayPackets << 8, dm_->TargetLevel()); | 266 EXPECT_EQ(kMinDelayPackets << 8, dm_->TargetLevel()); |
267 } | 267 } |
268 | 268 |
| 269 // Tests that skipped sequence numbers (simulating empty packets) are handled |
| 270 // correctly. |
| 271 TEST_F(DelayManagerTest, EmptyPacketsReported) { |
| 272 SetPacketAudioLength(kFrameSizeMs); |
| 273 // First packet arrival. |
| 274 InsertNextPacket(); |
| 275 |
| 276 // Advance time by one frame size. |
| 277 IncreaseTime(kFrameSizeMs); |
| 278 |
| 279 // Advance the sequence number by 5, simulating that 5 empty packets were |
| 280 // received, but never inserted. |
| 281 seq_no_ += 10; |
| 282 for (int j = 0; j < 10; ++j) { |
| 283 dm_->RegisterEmptyPacket(); |
| 284 } |
| 285 |
| 286 // Second packet arrival. |
| 287 // Expect detector update method to be called once with inter-arrival time |
| 288 // equal to 1 packet, and (base) target level equal to 1 as well. |
| 289 // Return false to indicate no peaks found. |
| 290 EXPECT_CALL(detector_, Update(1, 1)).WillOnce(Return(false)); |
| 291 InsertNextPacket(); |
| 292 |
| 293 EXPECT_EQ(1 << 8, dm_->TargetLevel()); // In Q8. |
| 294 } |
| 295 |
| 296 // Same as above, but do not call RegisterEmptyPacket. Observe the target level |
| 297 // increase dramatically. |
| 298 TEST_F(DelayManagerTest, EmptyPacketsNotReported) { |
| 299 SetPacketAudioLength(kFrameSizeMs); |
| 300 // First packet arrival. |
| 301 InsertNextPacket(); |
| 302 |
| 303 // Advance time by one frame size. |
| 304 IncreaseTime(kFrameSizeMs); |
| 305 |
| 306 // Advance the sequence number by 5, simulating that 5 empty packets were |
| 307 // received, but never inserted. |
| 308 seq_no_ += 10; |
| 309 |
| 310 // Second packet arrival. |
| 311 // Expect detector update method to be called once with inter-arrival time |
| 312 // equal to 1 packet, and (base) target level equal to 1 as well. |
| 313 // Return false to indicate no peaks found. |
| 314 EXPECT_CALL(detector_, Update(10, 10)).WillOnce(Return(false)); |
| 315 InsertNextPacket(); |
| 316 |
| 317 // Note 10 times higher target value. |
| 318 EXPECT_EQ(10 * 1 << 8, dm_->TargetLevel()); // In Q8. |
| 319 } |
| 320 |
269 TEST_F(DelayManagerTest, Failures) { | 321 TEST_F(DelayManagerTest, Failures) { |
270 // Wrong sample rate. | 322 // Wrong sample rate. |
271 EXPECT_EQ(-1, dm_->Update(0, 0, -1)); | 323 EXPECT_EQ(-1, dm_->Update(0, 0, -1)); |
272 // Wrong packet size. | 324 // Wrong packet size. |
273 EXPECT_EQ(-1, dm_->SetPacketAudioLength(0)); | 325 EXPECT_EQ(-1, dm_->SetPacketAudioLength(0)); |
274 EXPECT_EQ(-1, dm_->SetPacketAudioLength(-1)); | 326 EXPECT_EQ(-1, dm_->SetPacketAudioLength(-1)); |
275 | 327 |
276 // Minimum delay higher than a maximum delay is not accepted. | 328 // Minimum delay higher than a maximum delay is not accepted. |
277 EXPECT_TRUE(dm_->SetMaximumDelay(10)); | 329 EXPECT_TRUE(dm_->SetMaximumDelay(10)); |
278 EXPECT_FALSE(dm_->SetMinimumDelay(20)); | 330 EXPECT_FALSE(dm_->SetMinimumDelay(20)); |
279 | 331 |
280 // Maximum delay less than minimum delay is not accepted. | 332 // Maximum delay less than minimum delay is not accepted. |
281 EXPECT_TRUE(dm_->SetMaximumDelay(100)); | 333 EXPECT_TRUE(dm_->SetMaximumDelay(100)); |
282 EXPECT_TRUE(dm_->SetMinimumDelay(80)); | 334 EXPECT_TRUE(dm_->SetMinimumDelay(80)); |
283 EXPECT_FALSE(dm_->SetMaximumDelay(60)); | 335 EXPECT_FALSE(dm_->SetMaximumDelay(60)); |
284 } | 336 } |
285 | 337 |
286 } // namespace webrtc | 338 } // namespace webrtc |
OLD | NEW |