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

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_unittest.cc

Issue 1861303002: NetEq::GetPlayoutTimestamp returns empty during CNG (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@neteq-set-audio-frame-ts
Patch Set: Created 4 years, 8 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) 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 bool expect_seq_no_wrap, bool expect_timestamp_wrap); 309 bool expect_seq_no_wrap, bool expect_timestamp_wrap);
310 310
311 void LongCngWithClockDrift(double drift_factor, 311 void LongCngWithClockDrift(double drift_factor,
312 double network_freeze_ms, 312 double network_freeze_ms,
313 bool pull_audio_during_freeze, 313 bool pull_audio_during_freeze,
314 int delay_tolerance_ms, 314 int delay_tolerance_ms,
315 int max_time_to_speech_ms); 315 int max_time_to_speech_ms);
316 316
317 void DuplicateCng(); 317 void DuplicateCng();
318 318
319 uint32_t PlayoutTimestamp(); 319 rtc::Optional<uint32_t> PlayoutTimestamp();
320 320
321 NetEq* neteq_; 321 NetEq* neteq_;
322 NetEq::Config config_; 322 NetEq::Config config_;
323 std::unique_ptr<test::RtpFileSource> rtp_source_; 323 std::unique_ptr<test::RtpFileSource> rtp_source_;
324 std::unique_ptr<test::Packet> packet_; 324 std::unique_ptr<test::Packet> packet_;
325 unsigned int sim_clock_; 325 unsigned int sim_clock_;
326 AudioFrame out_frame_; 326 AudioFrame out_frame_;
327 int output_sample_rate_; 327 int output_sample_rate_;
328 int algorithmic_delay_ms_; 328 int algorithmic_delay_ms_;
329 }; 329 };
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 ++seq_no; 713 ++seq_no;
714 timestamp += kSamples; 714 timestamp += kSamples;
715 next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; 715 next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor;
716 } 716 }
717 // Pull out data once. 717 // Pull out data once.
718 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 718 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
719 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 719 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
720 } 720 }
721 721
722 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); 722 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
723 int32_t delay_before = timestamp - PlayoutTimestamp(); 723 rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
724 ASSERT_TRUE(playout_timestamp);
725 int32_t delay_before = timestamp - *playout_timestamp;
724 726
725 // Insert CNG for 1 minute (= 60000 ms). 727 // Insert CNG for 1 minute (= 60000 ms).
726 const int kCngPeriodMs = 100; 728 const int kCngPeriodMs = 100;
727 const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples. 729 const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples.
728 const int kCngDurationMs = 60000; 730 const int kCngDurationMs = 60000;
729 for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) { 731 for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) {
730 // Each turn in this for loop is 10 ms. 732 // Each turn in this for loop is 10 ms.
731 while (next_input_time_ms <= t_ms) { 733 while (next_input_time_ms <= t_ms) {
732 // Insert one CNG frame each 100 ms. 734 // Insert one CNG frame each 100 ms.
733 uint8_t payload[kPayloadBytes]; 735 uint8_t payload[kPayloadBytes];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // Pull out data once. 805 // Pull out data once.
804 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 806 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
805 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 807 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
806 // Increase clock. 808 // Increase clock.
807 t_ms += 10; 809 t_ms += 10;
808 } 810 }
809 811
810 // Check that the speech starts again within reasonable time. 812 // Check that the speech starts again within reasonable time.
811 double time_until_speech_returns_ms = t_ms - speech_restart_time_ms; 813 double time_until_speech_returns_ms = t_ms - speech_restart_time_ms;
812 EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms); 814 EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms);
813 int32_t delay_after = timestamp - PlayoutTimestamp(); 815 playout_timestamp = PlayoutTimestamp();
816 ASSERT_TRUE(playout_timestamp);
817 int32_t delay_after = timestamp - *playout_timestamp;
814 // Compare delay before and after, and make sure it differs less than 20 ms. 818 // Compare delay before and after, and make sure it differs less than 20 ms.
815 EXPECT_LE(delay_after, delay_before + delay_tolerance_ms * 16); 819 EXPECT_LE(delay_after, delay_before + delay_tolerance_ms * 16);
816 EXPECT_GE(delay_after, delay_before - delay_tolerance_ms * 16); 820 EXPECT_GE(delay_after, delay_before - delay_tolerance_ms * 16);
817 } 821 }
818 822
819 TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) { 823 TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) {
820 // Apply a clock drift of -25 ms / s (sender faster than receiver). 824 // Apply a clock drift of -25 ms / s (sender faster than receiver).
821 const double kDriftFactor = 1000.0 / (1000.0 + 25.0); 825 const double kDriftFactor = 1000.0 / (1000.0 + 25.0);
822 const double kNetworkFreezeTimeMs = 0.0; 826 const double kNetworkFreezeTimeMs = 0.0;
823 const bool kGetAudioDuringFreezeRecovery = false; 827 const bool kGetAudioDuringFreezeRecovery = false;
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 seq_no_wrapped |= seq_no < last_seq_no; 1410 seq_no_wrapped |= seq_no < last_seq_no;
1407 timestamp_wrapped |= timestamp < last_timestamp; 1411 timestamp_wrapped |= timestamp < last_timestamp;
1408 } 1412 }
1409 // Pull out data once. 1413 // Pull out data once.
1410 AudioFrame output; 1414 AudioFrame output;
1411 ASSERT_EQ(0, neteq_->GetAudio(&output)); 1415 ASSERT_EQ(0, neteq_->GetAudio(&output));
1412 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1416 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1413 ASSERT_EQ(1u, output.num_channels_); 1417 ASSERT_EQ(1u, output.num_channels_);
1414 1418
1415 // Expect delay (in samples) to be less than 2 packets. 1419 // Expect delay (in samples) to be less than 2 packets.
1416 EXPECT_LE(timestamp - PlayoutTimestamp(), 1420 rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
1421 ASSERT_TRUE(playout_timestamp);
1422 EXPECT_LE(timestamp - *playout_timestamp,
1417 static_cast<uint32_t>(kSamples * 2)); 1423 static_cast<uint32_t>(kSamples * 2));
1418 } 1424 }
1419 // Make sure we have actually tested wrap-around. 1425 // Make sure we have actually tested wrap-around.
1420 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); 1426 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped);
1421 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); 1427 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped);
1422 } 1428 }
1423 1429
1424 TEST_F(NetEqDecodingTest, SequenceNumberWrap) { 1430 TEST_F(NetEqDecodingTest, SequenceNumberWrap) {
1425 // Start with a sequence number that will soon wrap. 1431 // Start with a sequence number that will soon wrap.
1426 std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. 1432 std::set<uint16_t> drop_seq_numbers; // Don't drop any packets.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 1488 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
1483 // This is the first time this CNG packet is inserted. 1489 // This is the first time this CNG packet is inserted.
1484 ASSERT_EQ( 1490 ASSERT_EQ(
1485 0, neteq_->InsertPacket( 1491 0, neteq_->InsertPacket(
1486 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1492 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1487 1493
1488 // Pull audio once and make sure CNG is played. 1494 // Pull audio once and make sure CNG is played.
1489 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 1495 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1490 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1496 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1491 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); 1497 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
1492 EXPECT_EQ(timestamp - algorithmic_delay_samples, PlayoutTimestamp()); 1498 EXPECT_FALSE(PlayoutTimestamp()); // Returns empty value during CNG.
1499 EXPECT_EQ(timestamp - algorithmic_delay_samples,
1500 out_frame_.timestamp_ + out_frame_.samples_per_channel_);
minyue-webrtc 2016/04/06 13:39:42 Curious. Is it important that out_frame_.timestamp
hlundin-webrtc 2016/04/06 15:27:56 Since AudioFrame::timestamp_ is not an rtc::Option
minyue-webrtc 2016/04/06 18:13:07 Should it not updated during CNG? What Is that ti
hlundin-webrtc 2016/04/06 18:21:39 It is currently not used at all (iirc), but since
1493 1501
1494 // Insert the same CNG packet again. Note that at this point it is old, since 1502 // Insert the same CNG packet again. Note that at this point it is old, since
1495 // we have already decoded the first copy of it. 1503 // we have already decoded the first copy of it.
1496 ASSERT_EQ( 1504 ASSERT_EQ(
1497 0, neteq_->InsertPacket( 1505 0, neteq_->InsertPacket(
1498 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1506 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1499 1507
1500 // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since 1508 // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since
1501 // we have already pulled out CNG once. 1509 // we have already pulled out CNG once.
1502 for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) { 1510 for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) {
1503 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 1511 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1504 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1512 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1505 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); 1513 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
1514 EXPECT_FALSE(PlayoutTimestamp()); // Returns empty value during CNG.
1506 EXPECT_EQ(timestamp - algorithmic_delay_samples, 1515 EXPECT_EQ(timestamp - algorithmic_delay_samples,
1507 PlayoutTimestamp()); 1516 out_frame_.timestamp_ + out_frame_.samples_per_channel_);
1508 } 1517 }
1509 1518
1510 // Insert speech again. 1519 // Insert speech again.
1511 ++seq_no; 1520 ++seq_no;
1512 timestamp += kCngPeriodSamples; 1521 timestamp += kCngPeriodSamples;
1513 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1522 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1514 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1523 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1515 1524
1516 // Pull audio once and verify that the output is speech again. 1525 // Pull audio once and verify that the output is speech again.
1517 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 1526 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1518 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1527 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1519 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); 1528 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
1529 rtc::Optional<uint32_t> playout_timestamp = PlayoutTimestamp();
1530 ASSERT_TRUE(playout_timestamp);
1520 EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples, 1531 EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples,
1521 PlayoutTimestamp()); 1532 *playout_timestamp);
1522 } 1533 }
1523 1534
1524 uint32_t NetEqDecodingTest::PlayoutTimestamp() { 1535 rtc::Optional<uint32_t> NetEqDecodingTest::PlayoutTimestamp() {
1525 rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); 1536 return neteq_->GetPlayoutTimestamp();
1526 EXPECT_TRUE(playout_timestamp);
1527 return playout_timestamp.value_or(0);
1528 } 1537 }
1529 1538
1530 TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { DuplicateCng(); } 1539 TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { DuplicateCng(); }
1531 1540
1532 TEST_F(NetEqDecodingTest, CngFirst) { 1541 TEST_F(NetEqDecodingTest, CngFirst) {
1533 uint16_t seq_no = 0; 1542 uint16_t seq_no = 0;
1534 uint32_t timestamp = 0; 1543 uint32_t timestamp = 0;
1535 const int kFrameSizeMs = 10; 1544 const int kFrameSizeMs = 10;
1536 const int kSampleRateKhz = 16; 1545 const int kSampleRateKhz = 16;
1537 const int kSamples = kFrameSizeMs * kSampleRateKhz; 1546 const int kSamples = kFrameSizeMs * kSampleRateKhz;
(...skipping 26 matching lines...) Expand all
1564 timestamp += kSamples; 1573 timestamp += kSamples;
1565 1574
1566 // Pull audio once. 1575 // Pull audio once.
1567 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_)); 1576 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1568 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1577 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1569 } 1578 }
1570 // Verify speech output. 1579 // Verify speech output.
1571 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); 1580 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
1572 } 1581 }
1573 } // namespace webrtc 1582 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698