OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 static constexpr size_t kSamples = 10 * 16; | 1308 static constexpr size_t kSamples = 10 * 16; |
1309 static constexpr size_t kPayloadBytes = kSamples * 2; | 1309 static constexpr size_t kPayloadBytes = kSamples * 2; |
1310 | 1310 |
1311 void InsertPacket(uint32_t rtp_timestamp) { | 1311 void InsertPacket(uint32_t rtp_timestamp) { |
1312 uint8_t payload[kPayloadBytes] = {0}; | 1312 uint8_t payload[kPayloadBytes] = {0}; |
1313 WebRtcRTPHeader rtp_info; | 1313 WebRtcRTPHeader rtp_info; |
1314 PopulateRtpInfo(0, rtp_timestamp, &rtp_info); | 1314 PopulateRtpInfo(0, rtp_timestamp, &rtp_info); |
1315 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 1315 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
1316 } | 1316 } |
1317 | 1317 |
| 1318 void InsertCngPacket(uint32_t rtp_timestamp) { |
| 1319 uint8_t payload[kPayloadBytes] = {0}; |
| 1320 WebRtcRTPHeader rtp_info; |
| 1321 size_t payload_len; |
| 1322 PopulateCng(0, rtp_timestamp, &rtp_info, payload, &payload_len); |
| 1323 EXPECT_EQ( |
| 1324 NetEq::kOK, |
| 1325 neteq_->InsertPacket( |
| 1326 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
| 1327 } |
| 1328 |
1318 bool GetAudioReturnMuted() { | 1329 bool GetAudioReturnMuted() { |
1319 bool muted; | 1330 bool muted; |
1320 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); | 1331 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
1321 return muted; | 1332 return muted; |
1322 } | 1333 } |
1323 | 1334 |
1324 void GetAudioUntilMuted() { | 1335 void GetAudioUntilMuted() { |
1325 while (!GetAudioReturnMuted()) { | 1336 while (!GetAudioReturnMuted()) { |
1326 ASSERT_LT(counter_++, 1000) << "Test timed out"; | 1337 ASSERT_LT(counter_++, 1000) << "Test timed out"; |
1327 } | 1338 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 // Pull data until faded out. | 1433 // Pull data until faded out. |
1423 GetAudioUntilMuted(); | 1434 GetAudioUntilMuted(); |
1424 | 1435 |
1425 EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); | 1436 EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
1426 // Insert packet which is older than the first packet. | 1437 // Insert packet which is older than the first packet. |
1427 InsertPacket(kSamples * (counter_ - 1000)); | 1438 InsertPacket(kSamples * (counter_ - 1000)); |
1428 EXPECT_FALSE(GetAudioReturnMuted()); | 1439 EXPECT_FALSE(GetAudioReturnMuted()); |
1429 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); | 1440 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
1430 } | 1441 } |
1431 | 1442 |
| 1443 // Verifies that NetEq doesn't enter muted state when CNG mode is active and the |
| 1444 // packet stream is suspended for a long time. |
| 1445 TEST_F(NetEqDecodingTestWithMutedState, DoNotMuteExtendedCngWithoutPackets) { |
| 1446 // Insert one CNG packet. |
| 1447 InsertCngPacket(0); |
| 1448 |
| 1449 // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1450 for (int i = 0; i < 1000; ++i) { |
| 1451 bool muted; |
| 1452 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1453 ASSERT_FALSE(muted); |
| 1454 } |
| 1455 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
| 1456 } |
| 1457 |
| 1458 // Verifies that NetEq goes back to normal after a long CNG period with the |
| 1459 // packet stream suspended. |
| 1460 TEST_F(NetEqDecodingTestWithMutedState, RecoverAfterExtendedCngWithoutPackets) { |
| 1461 // Insert one CNG packet. |
| 1462 InsertCngPacket(0); |
| 1463 |
| 1464 // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1465 for (int i = 0; i < 1000; ++i) { |
| 1466 bool muted; |
| 1467 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1468 } |
| 1469 |
| 1470 // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1471 // packet. Verify that normal operation resumes. |
| 1472 InsertPacket(kSamples * counter_); |
| 1473 GetAudioUntilNormal(); |
| 1474 } |
| 1475 |
1432 class NetEqDecodingTestTwoInstances : public NetEqDecodingTest { | 1476 class NetEqDecodingTestTwoInstances : public NetEqDecodingTest { |
1433 public: | 1477 public: |
1434 NetEqDecodingTestTwoInstances() : NetEqDecodingTest() {} | 1478 NetEqDecodingTestTwoInstances() : NetEqDecodingTest() {} |
1435 | 1479 |
1436 void SetUp() override { | 1480 void SetUp() override { |
1437 NetEqDecodingTest::SetUp(); | 1481 NetEqDecodingTest::SetUp(); |
1438 config2_ = config_; | 1482 config2_ = config_; |
1439 } | 1483 } |
1440 | 1484 |
1441 void CreateSecondInstance() { | 1485 void CreateSecondInstance() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 if (muted) { | 1586 if (muted) { |
1543 EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); | 1587 EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
1544 } else { | 1588 } else { |
1545 EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); | 1589 EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
1546 } | 1590 } |
1547 } | 1591 } |
1548 EXPECT_FALSE(muted); | 1592 EXPECT_FALSE(muted); |
1549 } | 1593 } |
1550 | 1594 |
1551 } // namespace webrtc | 1595 } // namespace webrtc |
OLD | NEW |