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

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

Issue 1769883002: Remove the type parameter to NetEq::GetAudio (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@acm-rec-delete-vad
Patch Set: After review Created 4 years, 9 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 rtc::ArrayView<const uint8_t>( 419 rtc::ArrayView<const uint8_t>(
420 packet_->payload(), packet_->payload_length_bytes()), 420 packet_->payload(), packet_->payload_length_bytes()),
421 static_cast<uint32_t>(packet_->time_ms() * 421 static_cast<uint32_t>(packet_->time_ms() *
422 (output_sample_rate_ / 1000)))); 422 (output_sample_rate_ / 1000))));
423 } 423 }
424 // Get next packet. 424 // Get next packet.
425 packet_.reset(rtp_source_->NextPacket()); 425 packet_.reset(rtp_source_->NextPacket());
426 } 426 }
427 427
428 // Get audio from NetEq. 428 // Get audio from NetEq.
429 NetEqOutputType type; 429 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
430 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type));
431 ASSERT_TRUE((out_frame_.samples_per_channel_ == kBlockSize8kHz) || 430 ASSERT_TRUE((out_frame_.samples_per_channel_ == kBlockSize8kHz) ||
432 (out_frame_.samples_per_channel_ == kBlockSize16kHz) || 431 (out_frame_.samples_per_channel_ == kBlockSize16kHz) ||
433 (out_frame_.samples_per_channel_ == kBlockSize32kHz) || 432 (out_frame_.samples_per_channel_ == kBlockSize32kHz) ||
434 (out_frame_.samples_per_channel_ == kBlockSize48kHz)); 433 (out_frame_.samples_per_channel_ == kBlockSize48kHz));
435 output_sample_rate_ = out_frame_.sample_rate_hz_; 434 output_sample_rate_ = out_frame_.sample_rate_hz_;
436 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); 435 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz());
437 436
438 // Increase time. 437 // Increase time.
439 sim_clock_ += kTimeStepMs; 438 sim_clock_ += kTimeStepMs;
440 } 439 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 WebRtcRTPHeader rtp_info; 603 WebRtcRTPHeader rtp_info;
605 rtp_info.header.sequenceNumber = i; 604 rtp_info.header.sequenceNumber = i;
606 rtp_info.header.timestamp = i * kSamples; 605 rtp_info.header.timestamp = i * kSamples;
607 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. 606 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC.
608 rtp_info.header.payloadType = 94; // PCM16b WB codec. 607 rtp_info.header.payloadType = 94; // PCM16b WB codec.
609 rtp_info.header.markerBit = 0; 608 rtp_info.header.markerBit = 0;
610 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 609 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
611 } 610 }
612 // Pull out all data. 611 // Pull out all data.
613 for (size_t i = 0; i < num_frames; ++i) { 612 for (size_t i = 0; i < num_frames; ++i) {
614 NetEqOutputType type; 613 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
615 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type));
616 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 614 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
617 } 615 }
618 616
619 NetEqNetworkStatistics stats; 617 NetEqNetworkStatistics stats;
620 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); 618 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats));
621 // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms 619 // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms
622 // spacing (per definition), we expect the delay to increase with 10 ms for 620 // spacing (per definition), we expect the delay to increase with 10 ms for
623 // each packet. Thus, we are calculating the statistics for a series from 10 621 // each packet. Thus, we are calculating the statistics for a series from 10
624 // to 300, in steps of 10 ms. 622 // to 300, in steps of 10 ms.
625 EXPECT_EQ(155, stats.mean_waiting_time_ms); 623 EXPECT_EQ(155, stats.mean_waiting_time_ms);
(...skipping 20 matching lines...) Expand all
646 int num_packets = (frame_index % 10 == 0 ? 2 : 1); 644 int num_packets = (frame_index % 10 == 0 ? 2 : 1);
647 for (int n = 0; n < num_packets; ++n) { 645 for (int n = 0; n < num_packets; ++n) {
648 uint8_t payload[kPayloadBytes] = {0}; 646 uint8_t payload[kPayloadBytes] = {0};
649 WebRtcRTPHeader rtp_info; 647 WebRtcRTPHeader rtp_info;
650 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); 648 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
651 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 649 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
652 ++frame_index; 650 ++frame_index;
653 } 651 }
654 652
655 // Pull out data once. 653 // Pull out data once.
656 NetEqOutputType type; 654 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
657 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type));
658 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 655 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
659 } 656 }
660 657
661 NetEqNetworkStatistics network_stats; 658 NetEqNetworkStatistics network_stats;
662 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); 659 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats));
663 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); 660 EXPECT_EQ(-103196, network_stats.clockdrift_ppm);
664 } 661 }
665 662
666 TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimePositive) { 663 TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimePositive) {
667 const int kNumFrames = 5000; // Needed for convergence. 664 const int kNumFrames = 5000; // Needed for convergence.
668 int frame_index = 0; 665 int frame_index = 0;
669 const size_t kSamples = 10 * 16; 666 const size_t kSamples = 10 * 16;
670 const size_t kPayloadBytes = kSamples * 2; 667 const size_t kPayloadBytes = kSamples * 2;
671 for (int i = 0; i < kNumFrames; ++i) { 668 for (int i = 0; i < kNumFrames; ++i) {
672 // Insert one packet each time, except every 10th time where we don't insert 669 // Insert one packet each time, except every 10th time where we don't insert
673 // any packet. This will create a positive clock-drift of approx. 11%. 670 // any packet. This will create a positive clock-drift of approx. 11%.
674 int num_packets = (i % 10 == 9 ? 0 : 1); 671 int num_packets = (i % 10 == 9 ? 0 : 1);
675 for (int n = 0; n < num_packets; ++n) { 672 for (int n = 0; n < num_packets; ++n) {
676 uint8_t payload[kPayloadBytes] = {0}; 673 uint8_t payload[kPayloadBytes] = {0};
677 WebRtcRTPHeader rtp_info; 674 WebRtcRTPHeader rtp_info;
678 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); 675 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
679 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 676 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
680 ++frame_index; 677 ++frame_index;
681 } 678 }
682 679
683 // Pull out data once. 680 // Pull out data once.
684 NetEqOutputType type; 681 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
685 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type));
686 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 682 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
687 } 683 }
688 684
689 NetEqNetworkStatistics network_stats; 685 NetEqNetworkStatistics network_stats;
690 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); 686 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats));
691 EXPECT_EQ(110946, network_stats.clockdrift_ppm); 687 EXPECT_EQ(110946, network_stats.clockdrift_ppm);
692 } 688 }
693 689
694 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, 690 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
695 double network_freeze_ms, 691 double network_freeze_ms,
696 bool pull_audio_during_freeze, 692 bool pull_audio_during_freeze,
697 int delay_tolerance_ms, 693 int delay_tolerance_ms,
698 int max_time_to_speech_ms) { 694 int max_time_to_speech_ms) {
699 uint16_t seq_no = 0; 695 uint16_t seq_no = 0;
700 uint32_t timestamp = 0; 696 uint32_t timestamp = 0;
701 const int kFrameSizeMs = 30; 697 const int kFrameSizeMs = 30;
702 const size_t kSamples = kFrameSizeMs * 16; 698 const size_t kSamples = kFrameSizeMs * 16;
703 const size_t kPayloadBytes = kSamples * 2; 699 const size_t kPayloadBytes = kSamples * 2;
704 double next_input_time_ms = 0.0; 700 double next_input_time_ms = 0.0;
705 double t_ms; 701 double t_ms;
706 NetEqOutputType type;
707 702
708 // Insert speech for 5 seconds. 703 // Insert speech for 5 seconds.
709 const int kSpeechDurationMs = 5000; 704 const int kSpeechDurationMs = 5000;
710 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { 705 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) {
711 // Each turn in this for loop is 10 ms. 706 // Each turn in this for loop is 10 ms.
712 while (next_input_time_ms <= t_ms) { 707 while (next_input_time_ms <= t_ms) {
713 // Insert one 30 ms speech frame. 708 // Insert one 30 ms speech frame.
714 uint8_t payload[kPayloadBytes] = {0}; 709 uint8_t payload[kPayloadBytes] = {0};
715 WebRtcRTPHeader rtp_info; 710 WebRtcRTPHeader rtp_info;
716 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 711 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
717 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 712 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
718 ++seq_no; 713 ++seq_no;
719 timestamp += kSamples; 714 timestamp += kSamples;
720 next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; 715 next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor;
721 } 716 }
722 // Pull out data once. 717 // Pull out data once.
723 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 718 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
724 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 719 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
725 } 720 }
726 721
727 EXPECT_EQ(kOutputNormal, type); 722 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
728 int32_t delay_before = timestamp - PlayoutTimestamp(); 723 int32_t delay_before = timestamp - PlayoutTimestamp();
729 724
730 // Insert CNG for 1 minute (= 60000 ms). 725 // Insert CNG for 1 minute (= 60000 ms).
731 const int kCngPeriodMs = 100; 726 const int kCngPeriodMs = 100;
732 const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples. 727 const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples.
733 const int kCngDurationMs = 60000; 728 const int kCngDurationMs = 60000;
734 for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) { 729 for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) {
735 // Each turn in this for loop is 10 ms. 730 // Each turn in this for loop is 10 ms.
736 while (next_input_time_ms <= t_ms) { 731 while (next_input_time_ms <= t_ms) {
737 // Insert one CNG frame each 100 ms. 732 // Insert one CNG frame each 100 ms.
738 uint8_t payload[kPayloadBytes]; 733 uint8_t payload[kPayloadBytes];
739 size_t payload_len; 734 size_t payload_len;
740 WebRtcRTPHeader rtp_info; 735 WebRtcRTPHeader rtp_info;
741 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 736 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
742 ASSERT_EQ(0, neteq_->InsertPacket( 737 ASSERT_EQ(0, neteq_->InsertPacket(
743 rtp_info, 738 rtp_info,
744 rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 739 rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
745 ++seq_no; 740 ++seq_no;
746 timestamp += kCngPeriodSamples; 741 timestamp += kCngPeriodSamples;
747 next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor; 742 next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor;
748 } 743 }
749 // Pull out data once. 744 // Pull out data once.
750 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 745 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
751 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 746 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
752 } 747 }
753 748
754 EXPECT_EQ(kOutputCNG, type); 749 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
755 750
756 if (network_freeze_ms > 0) { 751 if (network_freeze_ms > 0) {
757 // First keep pulling audio for |network_freeze_ms| without inserting 752 // First keep pulling audio for |network_freeze_ms| without inserting
758 // any data, then insert CNG data corresponding to |network_freeze_ms| 753 // any data, then insert CNG data corresponding to |network_freeze_ms|
759 // without pulling any output audio. 754 // without pulling any output audio.
760 const double loop_end_time = t_ms + network_freeze_ms; 755 const double loop_end_time = t_ms + network_freeze_ms;
761 for (; t_ms < loop_end_time; t_ms += 10) { 756 for (; t_ms < loop_end_time; t_ms += 10) {
762 // Pull out data once. 757 // Pull out data once.
763 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 758 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
764 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 759 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
765 EXPECT_EQ(kOutputCNG, type); 760 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
766 } 761 }
767 bool pull_once = pull_audio_during_freeze; 762 bool pull_once = pull_audio_during_freeze;
768 // If |pull_once| is true, GetAudio will be called once half-way through 763 // If |pull_once| is true, GetAudio will be called once half-way through
769 // the network recovery period. 764 // the network recovery period.
770 double pull_time_ms = (t_ms + next_input_time_ms) / 2; 765 double pull_time_ms = (t_ms + next_input_time_ms) / 2;
771 while (next_input_time_ms <= t_ms) { 766 while (next_input_time_ms <= t_ms) {
772 if (pull_once && next_input_time_ms >= pull_time_ms) { 767 if (pull_once && next_input_time_ms >= pull_time_ms) {
773 pull_once = false; 768 pull_once = false;
774 // Pull out data once. 769 // Pull out data once.
775 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 770 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
776 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 771 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
777 EXPECT_EQ(kOutputCNG, type); 772 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
778 t_ms += 10; 773 t_ms += 10;
779 } 774 }
780 // Insert one CNG frame each 100 ms. 775 // Insert one CNG frame each 100 ms.
781 uint8_t payload[kPayloadBytes]; 776 uint8_t payload[kPayloadBytes];
782 size_t payload_len; 777 size_t payload_len;
783 WebRtcRTPHeader rtp_info; 778 WebRtcRTPHeader rtp_info;
784 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 779 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
785 ASSERT_EQ(0, neteq_->InsertPacket( 780 ASSERT_EQ(0, neteq_->InsertPacket(
786 rtp_info, 781 rtp_info,
787 rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 782 rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
788 ++seq_no; 783 ++seq_no;
789 timestamp += kCngPeriodSamples; 784 timestamp += kCngPeriodSamples;
790 next_input_time_ms += kCngPeriodMs * drift_factor; 785 next_input_time_ms += kCngPeriodMs * drift_factor;
791 } 786 }
792 } 787 }
793 788
794 // Insert speech again until output type is speech. 789 // Insert speech again until output type is speech.
795 double speech_restart_time_ms = t_ms; 790 double speech_restart_time_ms = t_ms;
796 while (type != kOutputNormal) { 791 while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) {
797 // Each turn in this for loop is 10 ms. 792 // Each turn in this for loop is 10 ms.
798 while (next_input_time_ms <= t_ms) { 793 while (next_input_time_ms <= t_ms) {
799 // Insert one 30 ms speech frame. 794 // Insert one 30 ms speech frame.
800 uint8_t payload[kPayloadBytes] = {0}; 795 uint8_t payload[kPayloadBytes] = {0};
801 WebRtcRTPHeader rtp_info; 796 WebRtcRTPHeader rtp_info;
802 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 797 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
803 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 798 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
804 ++seq_no; 799 ++seq_no;
805 timestamp += kSamples; 800 timestamp += kSamples;
806 next_input_time_ms += kFrameSizeMs * drift_factor; 801 next_input_time_ms += kFrameSizeMs * drift_factor;
807 } 802 }
808 // Pull out data once. 803 // Pull out data once.
809 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 804 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
810 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 805 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
811 // Increase clock. 806 // Increase clock.
812 t_ms += 10; 807 t_ms += 10;
813 } 808 }
814 809
815 // Check that the speech starts again within reasonable time. 810 // Check that the speech starts again within reasonable time.
816 double time_until_speech_returns_ms = t_ms - speech_restart_time_ms; 811 double time_until_speech_returns_ms = t_ms - speech_restart_time_ms;
817 EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms); 812 EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms);
818 int32_t delay_after = timestamp - PlayoutTimestamp(); 813 int32_t delay_after = timestamp - PlayoutTimestamp();
819 // Compare delay before and after, and make sure it differs less than 20 ms. 814 // Compare delay before and after, and make sure it differs less than 20 ms.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 #define MAYBE_DecoderError DISABLED_DecoderError 915 #define MAYBE_DecoderError DISABLED_DecoderError
921 #endif 916 #endif
922 917
923 TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { 918 TEST_F(NetEqDecodingTest, MAYBE_DecoderError) {
924 const size_t kPayloadBytes = 100; 919 const size_t kPayloadBytes = 100;
925 uint8_t payload[kPayloadBytes] = {0}; 920 uint8_t payload[kPayloadBytes] = {0};
926 WebRtcRTPHeader rtp_info; 921 WebRtcRTPHeader rtp_info;
927 PopulateRtpInfo(0, 0, &rtp_info); 922 PopulateRtpInfo(0, 0, &rtp_info);
928 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. 923 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid.
929 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 924 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
930 NetEqOutputType type;
931 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 925 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
932 // to GetAudio. 926 // to GetAudio.
933 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { 927 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) {
934 out_frame_.data_[i] = 1; 928 out_frame_.data_[i] = 1;
935 } 929 }
936 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &type)); 930 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_));
937 // Verify that there is a decoder error to check. 931 // Verify that there is a decoder error to check.
938 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); 932 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError());
939 933
940 enum NetEqDecoderError { 934 enum NetEqDecoderError {
941 ISAC_LENGTH_MISMATCH = 6730, 935 ISAC_LENGTH_MISMATCH = 6730,
942 ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH = 6640 936 ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH = 6640
943 }; 937 };
944 #if defined(WEBRTC_CODEC_ISAC) 938 #if defined(WEBRTC_CODEC_ISAC)
945 EXPECT_EQ(ISAC_LENGTH_MISMATCH, neteq_->LastDecoderError()); 939 EXPECT_EQ(ISAC_LENGTH_MISMATCH, neteq_->LastDecoderError());
946 #elif defined(WEBRTC_CODEC_ISACFX) 940 #elif defined(WEBRTC_CODEC_ISACFX)
(...skipping 11 matching lines...) Expand all
958 for (size_t i = kExpectedOutputLength; i < AudioFrame::kMaxDataSizeSamples; 952 for (size_t i = kExpectedOutputLength; i < AudioFrame::kMaxDataSizeSamples;
959 ++i) { 953 ++i) {
960 std::ostringstream ss; 954 std::ostringstream ss;
961 ss << "i = " << i; 955 ss << "i = " << i;
962 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 956 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
963 EXPECT_EQ(1, out_frame_.data_[i]); 957 EXPECT_EQ(1, out_frame_.data_[i]);
964 } 958 }
965 } 959 }
966 960
967 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { 961 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) {
968 NetEqOutputType type;
969 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 962 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
970 // to GetAudio. 963 // to GetAudio.
971 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { 964 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) {
972 out_frame_.data_[i] = 1; 965 out_frame_.data_[i] = 1;
973 } 966 }
974 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 967 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_));
975 // Verify that the first block of samples is set to 0. 968 // Verify that the first block of samples is set to 0.
976 static const int kExpectedOutputLength = 969 static const int kExpectedOutputLength =
977 kInitSampleRateHz / 100; // 10 ms at initial sample rate. 970 kInitSampleRateHz / 100; // 10 ms at initial sample rate.
978 for (int i = 0; i < kExpectedOutputLength; ++i) { 971 for (int i = 0; i < kExpectedOutputLength; ++i) {
979 std::ostringstream ss; 972 std::ostringstream ss;
980 ss << "i = " << i; 973 ss << "i = " << i;
981 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 974 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
982 EXPECT_EQ(0, out_frame_.data_[i]); 975 EXPECT_EQ(0, out_frame_.data_[i]);
983 } 976 }
984 // Verify that the sample rate did not change from the initial configuration. 977 // Verify that the sample rate did not change from the initial configuration.
(...skipping 14 matching lines...) Expand all
999 } else if (sampling_rate_hz == 16000) { 992 } else if (sampling_rate_hz == 16000) {
1000 expected_samples_per_channel = kBlockSize16kHz; 993 expected_samples_per_channel = kBlockSize16kHz;
1001 payload_type = 94; // PCM 16, 16 kHZ. 994 payload_type = 94; // PCM 16, 16 kHZ.
1002 } else if (sampling_rate_hz == 32000) { 995 } else if (sampling_rate_hz == 32000) {
1003 expected_samples_per_channel = kBlockSize32kHz; 996 expected_samples_per_channel = kBlockSize32kHz;
1004 payload_type = 95; // PCM 16, 32 kHz. 997 payload_type = 95; // PCM 16, 32 kHz.
1005 } else { 998 } else {
1006 ASSERT_TRUE(false); // Unsupported test case. 999 ASSERT_TRUE(false); // Unsupported test case.
1007 } 1000 }
1008 1001
1009 NetEqOutputType type;
1010 AudioFrame output; 1002 AudioFrame output;
1011 test::AudioLoop input; 1003 test::AudioLoop input;
1012 // We are using the same 32 kHz input file for all tests, regardless of 1004 // We are using the same 32 kHz input file for all tests, regardless of
1013 // |sampling_rate_hz|. The output may sound weird, but the test is still 1005 // |sampling_rate_hz|. The output may sound weird, but the test is still
1014 // valid. 1006 // valid.
1015 ASSERT_TRUE(input.Init( 1007 ASSERT_TRUE(input.Init(
1016 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 1008 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
1017 10 * sampling_rate_hz, // Max 10 seconds loop length. 1009 10 * sampling_rate_hz, // Max 10 seconds loop length.
1018 expected_samples_per_channel)); 1010 expected_samples_per_channel));
1019 1011
1020 // Payload of 10 ms of PCM16 32 kHz. 1012 // Payload of 10 ms of PCM16 32 kHz.
1021 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; 1013 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)];
1022 WebRtcRTPHeader rtp_info; 1014 WebRtcRTPHeader rtp_info;
1023 PopulateRtpInfo(0, 0, &rtp_info); 1015 PopulateRtpInfo(0, 0, &rtp_info);
1024 rtp_info.header.payloadType = payload_type; 1016 rtp_info.header.payloadType = payload_type;
1025 1017
1026 uint32_t receive_timestamp = 0; 1018 uint32_t receive_timestamp = 0;
1027 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. 1019 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio.
1028 auto block = input.GetNextBlock(); 1020 auto block = input.GetNextBlock();
1029 ASSERT_EQ(expected_samples_per_channel, block.size()); 1021 ASSERT_EQ(expected_samples_per_channel, block.size());
1030 size_t enc_len_bytes = 1022 size_t enc_len_bytes =
1031 WebRtcPcm16b_Encode(block.data(), block.size(), payload); 1023 WebRtcPcm16b_Encode(block.data(), block.size(), payload);
1032 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); 1024 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2);
1033 1025
1034 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( 1026 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>(
1035 payload, enc_len_bytes), 1027 payload, enc_len_bytes),
1036 receive_timestamp)); 1028 receive_timestamp));
1037 output.Reset(); 1029 output.Reset();
1038 ASSERT_EQ(0, neteq_->GetAudio(&output, &type)); 1030 ASSERT_EQ(0, neteq_->GetAudio(&output));
1039 ASSERT_EQ(1u, output.num_channels_); 1031 ASSERT_EQ(1u, output.num_channels_);
1040 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); 1032 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_);
1041 ASSERT_EQ(kOutputNormal, type); 1033 ASSERT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
1042 1034
1043 // Next packet. 1035 // Next packet.
1044 rtp_info.header.timestamp += expected_samples_per_channel; 1036 rtp_info.header.timestamp += expected_samples_per_channel;
1045 rtp_info.header.sequenceNumber++; 1037 rtp_info.header.sequenceNumber++;
1046 receive_timestamp += expected_samples_per_channel; 1038 receive_timestamp += expected_samples_per_channel;
1047 } 1039 }
1048 1040
1049 output.Reset(); 1041 output.Reset();
1050 1042
1051 // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull 1043 // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull
1052 // one frame without checking speech-type. This is the first frame pulled 1044 // one frame without checking speech-type. This is the first frame pulled
1053 // without inserting any packet, and might not be labeled as PLC. 1045 // without inserting any packet, and might not be labeled as PLC.
1054 ASSERT_EQ(0, neteq_->GetAudio(&output, &type)); 1046 ASSERT_EQ(0, neteq_->GetAudio(&output));
1055 ASSERT_EQ(1u, output.num_channels_); 1047 ASSERT_EQ(1u, output.num_channels_);
1056 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); 1048 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_);
1057 1049
1058 // To be able to test the fading of background noise we need at lease to 1050 // To be able to test the fading of background noise we need at lease to
1059 // pull 611 frames. 1051 // pull 611 frames.
1060 const int kFadingThreshold = 611; 1052 const int kFadingThreshold = 611;
1061 1053
1062 // Test several CNG-to-PLC packet for the expected behavior. The number 20 1054 // Test several CNG-to-PLC packet for the expected behavior. The number 20
1063 // is arbitrary, but sufficiently large to test enough number of frames. 1055 // is arbitrary, but sufficiently large to test enough number of frames.
1064 const int kNumPlcToCngTestFrames = 20; 1056 const int kNumPlcToCngTestFrames = 20;
1065 bool plc_to_cng = false; 1057 bool plc_to_cng = false;
1066 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { 1058 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) {
1067 output.Reset(); 1059 output.Reset();
1068 memset(output.data_, 1, sizeof(output.data_)); // Set to non-zero. 1060 memset(output.data_, 1, sizeof(output.data_)); // Set to non-zero.
1069 ASSERT_EQ(0, neteq_->GetAudio(&output, &type)); 1061 ASSERT_EQ(0, neteq_->GetAudio(&output));
1070 ASSERT_EQ(1u, output.num_channels_); 1062 ASSERT_EQ(1u, output.num_channels_);
1071 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); 1063 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_);
1072 if (type == kOutputPLCtoCNG) { 1064 if (output.speech_type_ == AudioFrame::kPLCCNG) {
1073 plc_to_cng = true; 1065 plc_to_cng = true;
1074 double sum_squared = 0; 1066 double sum_squared = 0;
1075 for (size_t k = 0; 1067 for (size_t k = 0;
1076 k < output.num_channels_ * output.samples_per_channel_; ++k) 1068 k < output.num_channels_ * output.samples_per_channel_; ++k)
1077 sum_squared += output.data_[k] * output.data_[k]; 1069 sum_squared += output.data_[k] * output.data_[k];
1078 TestCondition(sum_squared, n > kFadingThreshold); 1070 TestCondition(sum_squared, n > kFadingThreshold);
1079 } else { 1071 } else {
1080 EXPECT_EQ(kOutputPLC, type); 1072 EXPECT_EQ(AudioFrame::kPLC, output.speech_type_);
1081 } 1073 }
1082 } 1074 }
1083 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. 1075 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred.
1084 } 1076 }
1085 }; 1077 };
1086 1078
1087 class NetEqBgnTestOn : public NetEqBgnTest { 1079 class NetEqBgnTestOn : public NetEqBgnTest {
1088 protected: 1080 protected:
1089 NetEqBgnTestOn() : NetEqBgnTest() { 1081 NetEqBgnTestOn() : NetEqBgnTest() {
1090 config_.background_noise_mode = NetEq::kBgnOn; 1082 config_.background_noise_mode = NetEq::kBgnOn;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 PopulateRtpInfo(0, 0, &rtp_info); 1224 PopulateRtpInfo(0, 0, &rtp_info);
1233 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); 1225 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
1234 uint8_t payload[kPayloadBytes]; 1226 uint8_t payload[kPayloadBytes];
1235 AudioFrame output; 1227 AudioFrame output;
1236 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; 1228 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
1237 for (size_t n = 0; n < kPayloadBytes; ++n) { 1229 for (size_t n = 0; n < kPayloadBytes; ++n) {
1238 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. 1230 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
1239 } 1231 }
1240 // Insert some packets which decode to noise. We are not interested in 1232 // Insert some packets which decode to noise. We are not interested in
1241 // actual decoded values. 1233 // actual decoded values.
1242 NetEqOutputType output_type;
1243 uint32_t receive_timestamp = 0; 1234 uint32_t receive_timestamp = 0;
1244 for (int n = 0; n < 100; ++n) { 1235 for (int n = 0; n < 100; ++n) {
1245 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1236 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1246 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type)); 1237 ASSERT_EQ(0, neteq_->GetAudio(&output));
1247 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1238 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1248 ASSERT_EQ(1u, output.num_channels_); 1239 ASSERT_EQ(1u, output.num_channels_);
1249 1240
1250 rtp_info.header.sequenceNumber++; 1241 rtp_info.header.sequenceNumber++;
1251 rtp_info.header.timestamp += kBlockSize16kHz; 1242 rtp_info.header.timestamp += kBlockSize16kHz;
1252 receive_timestamp += kBlockSize16kHz; 1243 receive_timestamp += kBlockSize16kHz;
1253 } 1244 }
1254 const int kNumSyncPackets = 10; 1245 const int kNumSyncPackets = 10;
1255 1246
1256 // Make sure sufficient number of sync packets are inserted that we can 1247 // Make sure sufficient number of sync packets are inserted that we can
1257 // conduct a test. 1248 // conduct a test.
1258 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay); 1249 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay);
1259 // Insert sync-packets, the decoded sequence should be all-zero. 1250 // Insert sync-packets, the decoded sequence should be all-zero.
1260 for (int n = 0; n < kNumSyncPackets; ++n) { 1251 for (int n = 0; n < kNumSyncPackets; ++n) {
1261 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); 1252 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp));
1262 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type)); 1253 ASSERT_EQ(0, neteq_->GetAudio(&output));
1263 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1254 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1264 ASSERT_EQ(1u, output.num_channels_); 1255 ASSERT_EQ(1u, output.num_channels_);
1265 if (n > algorithmic_frame_delay) { 1256 if (n > algorithmic_frame_delay) {
1266 EXPECT_TRUE(IsAllZero( 1257 EXPECT_TRUE(IsAllZero(
1267 output.data_, output.samples_per_channel_ * output.num_channels_)); 1258 output.data_, output.samples_per_channel_ * output.num_channels_));
1268 } 1259 }
1269 rtp_info.header.sequenceNumber++; 1260 rtp_info.header.sequenceNumber++;
1270 rtp_info.header.timestamp += kBlockSize16kHz; 1261 rtp_info.header.timestamp += kBlockSize16kHz;
1271 receive_timestamp += kBlockSize16kHz; 1262 receive_timestamp += kBlockSize16kHz;
1272 } 1263 }
1273 1264
1274 // We insert regular packets, if sync packet are not correctly buffered then 1265 // We insert regular packets, if sync packet are not correctly buffered then
1275 // network statistics would show some packet loss. 1266 // network statistics would show some packet loss.
1276 for (int n = 0; n <= algorithmic_frame_delay + 10; ++n) { 1267 for (int n = 0; n <= algorithmic_frame_delay + 10; ++n) {
1277 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1268 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1278 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type)); 1269 ASSERT_EQ(0, neteq_->GetAudio(&output));
1279 if (n >= algorithmic_frame_delay + 1) { 1270 if (n >= algorithmic_frame_delay + 1) {
1280 // Expect that this frame contain samples from regular RTP. 1271 // Expect that this frame contain samples from regular RTP.
1281 EXPECT_TRUE(IsAllNonZero( 1272 EXPECT_TRUE(IsAllNonZero(
1282 output.data_, output.samples_per_channel_ * output.num_channels_)); 1273 output.data_, output.samples_per_channel_ * output.num_channels_));
1283 } 1274 }
1284 rtp_info.header.sequenceNumber++; 1275 rtp_info.header.sequenceNumber++;
1285 rtp_info.header.timestamp += kBlockSize16kHz; 1276 rtp_info.header.timestamp += kBlockSize16kHz;
1286 receive_timestamp += kBlockSize16kHz; 1277 receive_timestamp += kBlockSize16kHz;
1287 } 1278 }
1288 NetEqNetworkStatistics network_stats; 1279 NetEqNetworkStatistics network_stats;
(...skipping 13 matching lines...) Expand all
1302 WebRtcRTPHeader rtp_info; 1293 WebRtcRTPHeader rtp_info;
1303 PopulateRtpInfo(0, 0, &rtp_info); 1294 PopulateRtpInfo(0, 0, &rtp_info);
1304 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); 1295 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
1305 uint8_t payload[kPayloadBytes]; 1296 uint8_t payload[kPayloadBytes];
1306 AudioFrame output; 1297 AudioFrame output;
1307 for (size_t n = 0; n < kPayloadBytes; ++n) { 1298 for (size_t n = 0; n < kPayloadBytes; ++n) {
1308 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. 1299 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
1309 } 1300 }
1310 // Insert some packets which decode to noise. We are not interested in 1301 // Insert some packets which decode to noise. We are not interested in
1311 // actual decoded values. 1302 // actual decoded values.
1312 NetEqOutputType output_type;
1313 uint32_t receive_timestamp = 0; 1303 uint32_t receive_timestamp = 0;
1314 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; 1304 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
1315 for (int n = 0; n < algorithmic_frame_delay; ++n) { 1305 for (int n = 0; n < algorithmic_frame_delay; ++n) {
1316 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1306 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1317 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type)); 1307 ASSERT_EQ(0, neteq_->GetAudio(&output));
1318 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1308 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1319 ASSERT_EQ(1u, output.num_channels_); 1309 ASSERT_EQ(1u, output.num_channels_);
1320 rtp_info.header.sequenceNumber++; 1310 rtp_info.header.sequenceNumber++;
1321 rtp_info.header.timestamp += kBlockSize16kHz; 1311 rtp_info.header.timestamp += kBlockSize16kHz;
1322 receive_timestamp += kBlockSize16kHz; 1312 receive_timestamp += kBlockSize16kHz;
1323 } 1313 }
1324 const int kNumSyncPackets = 10; 1314 const int kNumSyncPackets = 10;
1325 1315
1326 WebRtcRTPHeader first_sync_packet_rtp_info; 1316 WebRtcRTPHeader first_sync_packet_rtp_info;
1327 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info)); 1317 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info));
(...skipping 16 matching lines...) Expand all
1344 // Insert. 1334 // Insert.
1345 for (int n = 0; n < kNumSyncPackets; ++n) { 1335 for (int n = 0; n < kNumSyncPackets; ++n) {
1346 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1336 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1347 rtp_info.header.sequenceNumber++; 1337 rtp_info.header.sequenceNumber++;
1348 rtp_info.header.timestamp += kBlockSize16kHz; 1338 rtp_info.header.timestamp += kBlockSize16kHz;
1349 receive_timestamp += kBlockSize16kHz; 1339 receive_timestamp += kBlockSize16kHz;
1350 } 1340 }
1351 1341
1352 // Decode. 1342 // Decode.
1353 for (int n = 0; n < kNumSyncPackets; ++n) { 1343 for (int n = 0; n < kNumSyncPackets; ++n) {
1354 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type)); 1344 ASSERT_EQ(0, neteq_->GetAudio(&output));
1355 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1345 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1356 ASSERT_EQ(1u, output.num_channels_); 1346 ASSERT_EQ(1u, output.num_channels_);
1357 EXPECT_TRUE(IsAllNonZero( 1347 EXPECT_TRUE(IsAllNonZero(
1358 output.data_, output.samples_per_channel_ * output.num_channels_)); 1348 output.data_, output.samples_per_channel_ * output.num_channels_));
1359 } 1349 }
1360 } 1350 }
1361 1351
1362 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, 1352 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no,
1363 uint32_t start_timestamp, 1353 uint32_t start_timestamp,
1364 const std::set<uint16_t>& drop_seq_numbers, 1354 const std::set<uint16_t>& drop_seq_numbers,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 ++seq_no; 1401 ++seq_no;
1412 timestamp += kSamples; 1402 timestamp += kSamples;
1413 receive_timestamp += kSamples; 1403 receive_timestamp += kSamples;
1414 next_input_time_ms += static_cast<double>(kFrameSizeMs); 1404 next_input_time_ms += static_cast<double>(kFrameSizeMs);
1415 1405
1416 seq_no_wrapped |= seq_no < last_seq_no; 1406 seq_no_wrapped |= seq_no < last_seq_no;
1417 timestamp_wrapped |= timestamp < last_timestamp; 1407 timestamp_wrapped |= timestamp < last_timestamp;
1418 } 1408 }
1419 // Pull out data once. 1409 // Pull out data once.
1420 AudioFrame output; 1410 AudioFrame output;
1421 NetEqOutputType output_type; 1411 ASSERT_EQ(0, neteq_->GetAudio(&output));
1422 ASSERT_EQ(0, neteq_->GetAudio(&output, &output_type));
1423 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); 1412 ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_);
1424 ASSERT_EQ(1u, output.num_channels_); 1413 ASSERT_EQ(1u, output.num_channels_);
1425 1414
1426 // Expect delay (in samples) to be less than 2 packets. 1415 // Expect delay (in samples) to be less than 2 packets.
1427 EXPECT_LE(timestamp - PlayoutTimestamp(), 1416 EXPECT_LE(timestamp - PlayoutTimestamp(),
1428 static_cast<uint32_t>(kSamples * 2)); 1417 static_cast<uint32_t>(kSamples * 2));
1429 } 1418 }
1430 // Make sure we have actually tested wrap-around. 1419 // Make sure we have actually tested wrap-around.
1431 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); 1420 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped);
1432 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); 1421 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 uint32_t timestamp = 0; 1453 uint32_t timestamp = 0;
1465 const int kFrameSizeMs = 10; 1454 const int kFrameSizeMs = 10;
1466 const int kSampleRateKhz = 16; 1455 const int kSampleRateKhz = 16;
1467 const int kSamples = kFrameSizeMs * kSampleRateKhz; 1456 const int kSamples = kFrameSizeMs * kSampleRateKhz;
1468 const size_t kPayloadBytes = kSamples * 2; 1457 const size_t kPayloadBytes = kSamples * 2;
1469 1458
1470 const int algorithmic_delay_samples = std::max( 1459 const int algorithmic_delay_samples = std::max(
1471 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); 1460 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8);
1472 // Insert three speech packets. Three are needed to get the frame length 1461 // Insert three speech packets. Three are needed to get the frame length
1473 // correct. 1462 // correct.
1474 NetEqOutputType type;
1475 uint8_t payload[kPayloadBytes] = {0}; 1463 uint8_t payload[kPayloadBytes] = {0};
1476 WebRtcRTPHeader rtp_info; 1464 WebRtcRTPHeader rtp_info;
1477 for (int i = 0; i < 3; ++i) { 1465 for (int i = 0; i < 3; ++i) {
1478 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1466 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1479 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1467 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1480 ++seq_no; 1468 ++seq_no;
1481 timestamp += kSamples; 1469 timestamp += kSamples;
1482 1470
1483 // Pull audio once. 1471 // Pull audio once.
1484 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 1472 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1485 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1473 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1486 } 1474 }
1487 // Verify speech output. 1475 // Verify speech output.
1488 EXPECT_EQ(kOutputNormal, type); 1476 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
1489 1477
1490 // Insert same CNG packet twice. 1478 // Insert same CNG packet twice.
1491 const int kCngPeriodMs = 100; 1479 const int kCngPeriodMs = 100;
1492 const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; 1480 const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz;
1493 size_t payload_len; 1481 size_t payload_len;
1494 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 1482 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
1495 // This is the first time this CNG packet is inserted. 1483 // This is the first time this CNG packet is inserted.
1496 ASSERT_EQ( 1484 ASSERT_EQ(
1497 0, neteq_->InsertPacket( 1485 0, neteq_->InsertPacket(
1498 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1486 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1499 1487
1500 // Pull audio once and make sure CNG is played. 1488 // Pull audio once and make sure CNG is played.
1501 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 1489 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1502 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1490 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1503 EXPECT_EQ(kOutputCNG, type); 1491 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
1504 EXPECT_EQ(timestamp - algorithmic_delay_samples, PlayoutTimestamp()); 1492 EXPECT_EQ(timestamp - algorithmic_delay_samples, PlayoutTimestamp());
1505 1493
1506 // Insert the same CNG packet again. Note that at this point it is old, since 1494 // Insert the same CNG packet again. Note that at this point it is old, since
1507 // we have already decoded the first copy of it. 1495 // we have already decoded the first copy of it.
1508 ASSERT_EQ( 1496 ASSERT_EQ(
1509 0, neteq_->InsertPacket( 1497 0, neteq_->InsertPacket(
1510 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1498 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1511 1499
1512 // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since 1500 // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since
1513 // we have already pulled out CNG once. 1501 // we have already pulled out CNG once.
1514 for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) { 1502 for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) {
1515 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 1503 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1516 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1504 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1517 EXPECT_EQ(kOutputCNG, type); 1505 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
1518 EXPECT_EQ(timestamp - algorithmic_delay_samples, 1506 EXPECT_EQ(timestamp - algorithmic_delay_samples,
1519 PlayoutTimestamp()); 1507 PlayoutTimestamp());
1520 } 1508 }
1521 1509
1522 // Insert speech again. 1510 // Insert speech again.
1523 ++seq_no; 1511 ++seq_no;
1524 timestamp += kCngPeriodSamples; 1512 timestamp += kCngPeriodSamples;
1525 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1513 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1526 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1514 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1527 1515
1528 // Pull audio once and verify that the output is speech again. 1516 // Pull audio once and verify that the output is speech again.
1529 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 1517 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1530 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1518 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1531 EXPECT_EQ(kOutputNormal, type); 1519 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
1532 EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples, 1520 EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples,
1533 PlayoutTimestamp()); 1521 PlayoutTimestamp());
1534 } 1522 }
1535 1523
1536 uint32_t NetEqDecodingTest::PlayoutTimestamp() { 1524 uint32_t NetEqDecodingTest::PlayoutTimestamp() {
1537 uint32_t playout_timestamp = 0; 1525 uint32_t playout_timestamp = 0;
1538 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&playout_timestamp)); 1526 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&playout_timestamp));
1539 return playout_timestamp; 1527 return playout_timestamp;
1540 } 1528 }
1541 1529
(...skipping 15 matching lines...) Expand all
1557 1545
1558 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 1546 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
1559 ASSERT_EQ( 1547 ASSERT_EQ(
1560 NetEq::kOK, 1548 NetEq::kOK,
1561 neteq_->InsertPacket( 1549 neteq_->InsertPacket(
1562 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1550 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1563 ++seq_no; 1551 ++seq_no;
1564 timestamp += kCngPeriodSamples; 1552 timestamp += kCngPeriodSamples;
1565 1553
1566 // Pull audio once and make sure CNG is played. 1554 // Pull audio once and make sure CNG is played.
1567 NetEqOutputType type; 1555 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1568 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type));
1569 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1556 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1570 EXPECT_EQ(kOutputCNG, type); 1557 EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_);
1571 1558
1572 // Insert some speech packets. 1559 // Insert some speech packets.
1573 for (int i = 0; i < 3; ++i) { 1560 for (int i = 0; i < 3; ++i) {
1574 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1561 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1575 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1562 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1576 ++seq_no; 1563 ++seq_no;
1577 timestamp += kSamples; 1564 timestamp += kSamples;
1578 1565
1579 // Pull audio once. 1566 // Pull audio once.
1580 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &type)); 1567 ASSERT_EQ(0, neteq_->GetAudio(&out_frame_));
1581 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); 1568 ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_);
1582 } 1569 }
1583 // Verify speech output. 1570 // Verify speech output.
1584 EXPECT_EQ(kOutputNormal, type); 1571 EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_);
1585 } 1572 }
1586 1573
1587 } // namespace webrtc 1574 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698