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

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

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Rebase onto cleanup change Created 4 years, 11 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 packet_->payload(), packet_->payload_length_bytes()), 419 packet_->payload(), packet_->payload_length_bytes()),
420 static_cast<uint32_t>(packet_->time_ms() * 420 static_cast<uint32_t>(packet_->time_ms() *
421 (output_sample_rate_ / 1000)))); 421 (output_sample_rate_ / 1000))));
422 } 422 }
423 // Get next packet. 423 // Get next packet.
424 packet_.reset(rtp_source_->NextPacket()); 424 packet_.reset(rtp_source_->NextPacket());
425 } 425 }
426 426
427 // Get audio from NetEq. 427 // Get audio from NetEq.
428 NetEqOutputType type; 428 NetEqOutputType type;
429 int num_channels; 429 size_t num_channels;
430 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, 430 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len,
431 &num_channels, &type)); 431 &num_channels, &type));
432 ASSERT_TRUE((*out_len == kBlockSize8kHz) || 432 ASSERT_TRUE((*out_len == kBlockSize8kHz) ||
433 (*out_len == kBlockSize16kHz) || 433 (*out_len == kBlockSize16kHz) ||
434 (*out_len == kBlockSize32kHz) || 434 (*out_len == kBlockSize32kHz) ||
435 (*out_len == kBlockSize48kHz)); 435 (*out_len == kBlockSize48kHz));
436 output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000); 436 output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000);
437 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); 437 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz());
438 438
439 // Increase time. 439 // Increase time.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 rtp_info.header.sequenceNumber = i; 602 rtp_info.header.sequenceNumber = i;
603 rtp_info.header.timestamp = i * kSamples; 603 rtp_info.header.timestamp = i * kSamples;
604 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. 604 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC.
605 rtp_info.header.payloadType = 94; // PCM16b WB codec. 605 rtp_info.header.payloadType = 94; // PCM16b WB codec.
606 rtp_info.header.markerBit = 0; 606 rtp_info.header.markerBit = 0;
607 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 607 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
608 } 608 }
609 // Pull out all data. 609 // Pull out all data.
610 for (size_t i = 0; i < num_frames; ++i) { 610 for (size_t i = 0; i < num_frames; ++i) {
611 size_t out_len; 611 size_t out_len;
612 int num_channels; 612 size_t num_channels;
613 NetEqOutputType type; 613 NetEqOutputType type;
614 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, 614 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len,
615 &num_channels, &type)); 615 &num_channels, &type));
616 ASSERT_EQ(kBlockSize16kHz, out_len); 616 ASSERT_EQ(kBlockSize16kHz, out_len);
617 } 617 }
618 618
619 NetEqNetworkStatistics stats; 619 NetEqNetworkStatistics stats;
620 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); 620 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats));
621 // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms 621 // 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 622 // spacing (per definition), we expect the delay to increase with 10 ms for
(...skipping 24 matching lines...) Expand all
647 for (int n = 0; n < num_packets; ++n) { 647 for (int n = 0; n < num_packets; ++n) {
648 uint8_t payload[kPayloadBytes] = {0}; 648 uint8_t payload[kPayloadBytes] = {0};
649 WebRtcRTPHeader rtp_info; 649 WebRtcRTPHeader rtp_info;
650 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); 650 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
651 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 651 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
652 ++frame_index; 652 ++frame_index;
653 } 653 }
654 654
655 // Pull out data once. 655 // Pull out data once.
656 size_t out_len; 656 size_t out_len;
657 int num_channels; 657 size_t num_channels;
658 NetEqOutputType type; 658 NetEqOutputType type;
659 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, 659 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len,
660 &num_channels, &type)); 660 &num_channels, &type));
661 ASSERT_EQ(kBlockSize16kHz, out_len); 661 ASSERT_EQ(kBlockSize16kHz, out_len);
662 } 662 }
663 663
664 NetEqNetworkStatistics network_stats; 664 NetEqNetworkStatistics network_stats;
665 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); 665 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats));
666 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); 666 EXPECT_EQ(-103196, network_stats.clockdrift_ppm);
667 } 667 }
(...skipping 10 matching lines...) Expand all
678 for (int n = 0; n < num_packets; ++n) { 678 for (int n = 0; n < num_packets; ++n) {
679 uint8_t payload[kPayloadBytes] = {0}; 679 uint8_t payload[kPayloadBytes] = {0};
680 WebRtcRTPHeader rtp_info; 680 WebRtcRTPHeader rtp_info;
681 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); 681 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
682 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 682 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
683 ++frame_index; 683 ++frame_index;
684 } 684 }
685 685
686 // Pull out data once. 686 // Pull out data once.
687 size_t out_len; 687 size_t out_len;
688 int num_channels; 688 size_t num_channels;
689 NetEqOutputType type; 689 NetEqOutputType type;
690 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, 690 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len,
691 &num_channels, &type)); 691 &num_channels, &type));
692 ASSERT_EQ(kBlockSize16kHz, out_len); 692 ASSERT_EQ(kBlockSize16kHz, out_len);
693 } 693 }
694 694
695 NetEqNetworkStatistics network_stats; 695 NetEqNetworkStatistics network_stats;
696 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); 696 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats));
697 EXPECT_EQ(110946, network_stats.clockdrift_ppm); 697 EXPECT_EQ(110946, network_stats.clockdrift_ppm);
698 } 698 }
699 699
700 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, 700 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
701 double network_freeze_ms, 701 double network_freeze_ms,
702 bool pull_audio_during_freeze, 702 bool pull_audio_during_freeze,
703 int delay_tolerance_ms, 703 int delay_tolerance_ms,
704 int max_time_to_speech_ms) { 704 int max_time_to_speech_ms) {
705 uint16_t seq_no = 0; 705 uint16_t seq_no = 0;
706 uint32_t timestamp = 0; 706 uint32_t timestamp = 0;
707 const int kFrameSizeMs = 30; 707 const int kFrameSizeMs = 30;
708 const size_t kSamples = kFrameSizeMs * 16; 708 const size_t kSamples = kFrameSizeMs * 16;
709 const size_t kPayloadBytes = kSamples * 2; 709 const size_t kPayloadBytes = kSamples * 2;
710 double next_input_time_ms = 0.0; 710 double next_input_time_ms = 0.0;
711 double t_ms; 711 double t_ms;
712 size_t out_len; 712 size_t out_len;
713 int num_channels; 713 size_t num_channels;
714 NetEqOutputType type; 714 NetEqOutputType type;
715 715
716 // Insert speech for 5 seconds. 716 // Insert speech for 5 seconds.
717 const int kSpeechDurationMs = 5000; 717 const int kSpeechDurationMs = 5000;
718 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { 718 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) {
719 // Each turn in this for loop is 10 ms. 719 // Each turn in this for loop is 10 ms.
720 while (next_input_time_ms <= t_ms) { 720 while (next_input_time_ms <= t_ms) {
721 // Insert one 30 ms speech frame. 721 // Insert one 30 ms speech frame.
722 uint8_t payload[kPayloadBytes] = {0}; 722 uint8_t payload[kPayloadBytes] = {0};
723 WebRtcRTPHeader rtp_info; 723 WebRtcRTPHeader rtp_info;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 WebRtcRTPHeader rtp_info; 942 WebRtcRTPHeader rtp_info;
943 PopulateRtpInfo(0, 0, &rtp_info); 943 PopulateRtpInfo(0, 0, &rtp_info);
944 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. 944 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid.
945 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 945 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
946 NetEqOutputType type; 946 NetEqOutputType type;
947 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 947 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
948 // to GetAudio. 948 // to GetAudio.
949 for (size_t i = 0; i < kMaxBlockSize; ++i) { 949 for (size_t i = 0; i < kMaxBlockSize; ++i) {
950 out_data_[i] = 1; 950 out_data_[i] = 1;
951 } 951 }
952 int num_channels; 952 size_t num_channels;
953 size_t samples_per_channel; 953 size_t samples_per_channel;
954 EXPECT_EQ(NetEq::kFail, 954 EXPECT_EQ(NetEq::kFail,
955 neteq_->GetAudio(kMaxBlockSize, out_data_, 955 neteq_->GetAudio(kMaxBlockSize, out_data_,
956 &samples_per_channel, &num_channels, &type)); 956 &samples_per_channel, &num_channels, &type));
957 // Verify that there is a decoder error to check. 957 // Verify that there is a decoder error to check.
958 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); 958 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError());
959 // Code 6730 is an iSAC error code. 959 // Code 6730 is an iSAC error code.
960 EXPECT_EQ(6730, neteq_->LastDecoderError()); 960 EXPECT_EQ(6730, neteq_->LastDecoderError());
961 // Verify that the first 160 samples are set to 0, and that the remaining 961 // Verify that the first 160 samples are set to 0, and that the remaining
962 // samples are left unmodified. 962 // samples are left unmodified.
(...skipping 12 matching lines...) Expand all
975 } 975 }
976 } 976 }
977 977
978 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { 978 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) {
979 NetEqOutputType type; 979 NetEqOutputType type;
980 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 980 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
981 // to GetAudio. 981 // to GetAudio.
982 for (size_t i = 0; i < kMaxBlockSize; ++i) { 982 for (size_t i = 0; i < kMaxBlockSize; ++i) {
983 out_data_[i] = 1; 983 out_data_[i] = 1;
984 } 984 }
985 int num_channels; 985 size_t num_channels;
986 size_t samples_per_channel; 986 size_t samples_per_channel;
987 EXPECT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, 987 EXPECT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_,
988 &samples_per_channel, 988 &samples_per_channel,
989 &num_channels, &type)); 989 &num_channels, &type));
990 // Verify that the first block of samples is set to 0. 990 // Verify that the first block of samples is set to 0.
991 static const int kExpectedOutputLength = 991 static const int kExpectedOutputLength =
992 kInitSampleRateHz / 100; // 10 ms at initial sample rate. 992 kInitSampleRateHz / 100; // 10 ms at initial sample rate.
993 for (int i = 0; i < kExpectedOutputLength; ++i) { 993 for (int i = 0; i < kExpectedOutputLength; ++i) {
994 std::ostringstream ss; 994 std::ostringstream ss;
995 ss << "i = " << i; 995 ss << "i = " << i;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 1031 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
1032 10 * sampling_rate_hz, // Max 10 seconds loop length. 1032 10 * sampling_rate_hz, // Max 10 seconds loop length.
1033 expected_samples_per_channel)); 1033 expected_samples_per_channel));
1034 1034
1035 // Payload of 10 ms of PCM16 32 kHz. 1035 // Payload of 10 ms of PCM16 32 kHz.
1036 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; 1036 uint8_t payload[kBlockSize32kHz * sizeof(int16_t)];
1037 WebRtcRTPHeader rtp_info; 1037 WebRtcRTPHeader rtp_info;
1038 PopulateRtpInfo(0, 0, &rtp_info); 1038 PopulateRtpInfo(0, 0, &rtp_info);
1039 rtp_info.header.payloadType = payload_type; 1039 rtp_info.header.payloadType = payload_type;
1040 1040
1041 int number_channels = 0; 1041 size_t number_channels = 0;
1042 size_t samples_per_channel = 0; 1042 size_t samples_per_channel = 0;
1043 1043
1044 uint32_t receive_timestamp = 0; 1044 uint32_t receive_timestamp = 0;
1045 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. 1045 for (int n = 0; n < 10; ++n) { // Insert few packets and get audio.
1046 auto block = input.GetNextBlock(); 1046 auto block = input.GetNextBlock();
1047 ASSERT_EQ(expected_samples_per_channel, block.size()); 1047 ASSERT_EQ(expected_samples_per_channel, block.size());
1048 size_t enc_len_bytes = 1048 size_t enc_len_bytes =
1049 WebRtcPcm16b_Encode(block.data(), block.size(), payload); 1049 WebRtcPcm16b_Encode(block.data(), block.size(), payload);
1050 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); 1050 ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2);
1051 1051
1052 number_channels = 0; 1052 number_channels = 0;
1053 samples_per_channel = 0; 1053 samples_per_channel = 0;
1054 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>( 1054 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>(
1055 payload, enc_len_bytes), 1055 payload, enc_len_bytes),
1056 receive_timestamp)); 1056 receive_timestamp));
1057 ASSERT_EQ(0, 1057 ASSERT_EQ(0,
1058 neteq_->GetAudio(kBlockSize32kHz, 1058 neteq_->GetAudio(kBlockSize32kHz,
1059 output, 1059 output,
1060 &samples_per_channel, 1060 &samples_per_channel,
1061 &number_channels, 1061 &number_channels,
1062 &type)); 1062 &type));
1063 ASSERT_EQ(1, number_channels); 1063 ASSERT_EQ(1u, number_channels);
1064 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); 1064 ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
1065 ASSERT_EQ(kOutputNormal, type); 1065 ASSERT_EQ(kOutputNormal, type);
1066 1066
1067 // Next packet. 1067 // Next packet.
1068 rtp_info.header.timestamp += expected_samples_per_channel; 1068 rtp_info.header.timestamp += expected_samples_per_channel;
1069 rtp_info.header.sequenceNumber++; 1069 rtp_info.header.sequenceNumber++;
1070 receive_timestamp += expected_samples_per_channel; 1070 receive_timestamp += expected_samples_per_channel;
1071 } 1071 }
1072 1072
1073 number_channels = 0; 1073 number_channels = 0;
1074 samples_per_channel = 0; 1074 samples_per_channel = 0;
1075 1075
1076 // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull 1076 // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull
1077 // one frame without checking speech-type. This is the first frame pulled 1077 // one frame without checking speech-type. This is the first frame pulled
1078 // without inserting any packet, and might not be labeled as PLC. 1078 // without inserting any packet, and might not be labeled as PLC.
1079 ASSERT_EQ(0, 1079 ASSERT_EQ(0,
1080 neteq_->GetAudio(kBlockSize32kHz, 1080 neteq_->GetAudio(kBlockSize32kHz,
1081 output, 1081 output,
1082 &samples_per_channel, 1082 &samples_per_channel,
1083 &number_channels, 1083 &number_channels,
1084 &type)); 1084 &type));
1085 ASSERT_EQ(1, number_channels); 1085 ASSERT_EQ(1u, number_channels);
1086 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); 1086 ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
1087 1087
1088 // To be able to test the fading of background noise we need at lease to 1088 // To be able to test the fading of background noise we need at lease to
1089 // pull 611 frames. 1089 // pull 611 frames.
1090 const int kFadingThreshold = 611; 1090 const int kFadingThreshold = 611;
1091 1091
1092 // Test several CNG-to-PLC packet for the expected behavior. The number 20 1092 // Test several CNG-to-PLC packet for the expected behavior. The number 20
1093 // is arbitrary, but sufficiently large to test enough number of frames. 1093 // is arbitrary, but sufficiently large to test enough number of frames.
1094 const int kNumPlcToCngTestFrames = 20; 1094 const int kNumPlcToCngTestFrames = 20;
1095 bool plc_to_cng = false; 1095 bool plc_to_cng = false;
1096 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { 1096 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) {
1097 number_channels = 0; 1097 number_channels = 0;
1098 samples_per_channel = 0; 1098 samples_per_channel = 0;
1099 memset(output, 1, sizeof(output)); // Set to non-zero. 1099 memset(output, 1, sizeof(output)); // Set to non-zero.
1100 ASSERT_EQ(0, 1100 ASSERT_EQ(0,
1101 neteq_->GetAudio(kBlockSize32kHz, 1101 neteq_->GetAudio(kBlockSize32kHz,
1102 output, 1102 output,
1103 &samples_per_channel, 1103 &samples_per_channel,
1104 &number_channels, 1104 &number_channels,
1105 &type)); 1105 &type));
1106 ASSERT_EQ(1, number_channels); 1106 ASSERT_EQ(1u, number_channels);
1107 ASSERT_EQ(expected_samples_per_channel, samples_per_channel); 1107 ASSERT_EQ(expected_samples_per_channel, samples_per_channel);
1108 if (type == kOutputPLCtoCNG) { 1108 if (type == kOutputPLCtoCNG) {
1109 plc_to_cng = true; 1109 plc_to_cng = true;
1110 double sum_squared = 0; 1110 double sum_squared = 0;
1111 for (size_t k = 0; k < number_channels * samples_per_channel; ++k) 1111 for (size_t k = 0; k < number_channels * samples_per_channel; ++k)
1112 sum_squared += output[k] * output[k]; 1112 sum_squared += output[k] * output[k];
1113 TestCondition(sum_squared, n > kFadingThreshold); 1113 TestCondition(sum_squared, n > kFadingThreshold);
1114 } else { 1114 } else {
1115 EXPECT_EQ(kOutputPLC, type); 1115 EXPECT_EQ(kOutputPLC, type);
1116 } 1116 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); 1263 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
1264 uint8_t payload[kPayloadBytes]; 1264 uint8_t payload[kPayloadBytes];
1265 int16_t decoded[kBlockSize16kHz]; 1265 int16_t decoded[kBlockSize16kHz];
1266 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; 1266 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
1267 for (size_t n = 0; n < kPayloadBytes; ++n) { 1267 for (size_t n = 0; n < kPayloadBytes; ++n) {
1268 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. 1268 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
1269 } 1269 }
1270 // Insert some packets which decode to noise. We are not interested in 1270 // Insert some packets which decode to noise. We are not interested in
1271 // actual decoded values. 1271 // actual decoded values.
1272 NetEqOutputType output_type; 1272 NetEqOutputType output_type;
1273 int num_channels; 1273 size_t num_channels;
1274 size_t samples_per_channel; 1274 size_t samples_per_channel;
1275 uint32_t receive_timestamp = 0; 1275 uint32_t receive_timestamp = 0;
1276 for (int n = 0; n < 100; ++n) { 1276 for (int n = 0; n < 100; ++n) {
1277 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1277 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1278 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, 1278 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
1279 &samples_per_channel, &num_channels, 1279 &samples_per_channel, &num_channels,
1280 &output_type)); 1280 &output_type));
1281 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); 1281 ASSERT_EQ(kBlockSize16kHz, samples_per_channel);
1282 ASSERT_EQ(1, num_channels); 1282 ASSERT_EQ(1u, num_channels);
1283 1283
1284 rtp_info.header.sequenceNumber++; 1284 rtp_info.header.sequenceNumber++;
1285 rtp_info.header.timestamp += kBlockSize16kHz; 1285 rtp_info.header.timestamp += kBlockSize16kHz;
1286 receive_timestamp += kBlockSize16kHz; 1286 receive_timestamp += kBlockSize16kHz;
1287 } 1287 }
1288 const int kNumSyncPackets = 10; 1288 const int kNumSyncPackets = 10;
1289 1289
1290 // Make sure sufficient number of sync packets are inserted that we can 1290 // Make sure sufficient number of sync packets are inserted that we can
1291 // conduct a test. 1291 // conduct a test.
1292 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay); 1292 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay);
1293 // Insert sync-packets, the decoded sequence should be all-zero. 1293 // Insert sync-packets, the decoded sequence should be all-zero.
1294 for (int n = 0; n < kNumSyncPackets; ++n) { 1294 for (int n = 0; n < kNumSyncPackets; ++n) {
1295 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); 1295 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp));
1296 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, 1296 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
1297 &samples_per_channel, &num_channels, 1297 &samples_per_channel, &num_channels,
1298 &output_type)); 1298 &output_type));
1299 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); 1299 ASSERT_EQ(kBlockSize16kHz, samples_per_channel);
1300 ASSERT_EQ(1, num_channels); 1300 ASSERT_EQ(1u, num_channels);
1301 if (n > algorithmic_frame_delay) { 1301 if (n > algorithmic_frame_delay) {
1302 EXPECT_TRUE(IsAllZero(decoded, samples_per_channel * num_channels)); 1302 EXPECT_TRUE(IsAllZero(decoded, samples_per_channel * num_channels));
1303 } 1303 }
1304 rtp_info.header.sequenceNumber++; 1304 rtp_info.header.sequenceNumber++;
1305 rtp_info.header.timestamp += kBlockSize16kHz; 1305 rtp_info.header.timestamp += kBlockSize16kHz;
1306 receive_timestamp += kBlockSize16kHz; 1306 receive_timestamp += kBlockSize16kHz;
1307 } 1307 }
1308 1308
1309 // We insert regular packets, if sync packet are not correctly buffered then 1309 // We insert regular packets, if sync packet are not correctly buffered then
1310 // network statistics would show some packet loss. 1310 // network statistics would show some packet loss.
(...skipping 28 matching lines...) Expand all
1339 PopulateRtpInfo(0, 0, &rtp_info); 1339 PopulateRtpInfo(0, 0, &rtp_info);
1340 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); 1340 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
1341 uint8_t payload[kPayloadBytes]; 1341 uint8_t payload[kPayloadBytes];
1342 int16_t decoded[kBlockSize16kHz]; 1342 int16_t decoded[kBlockSize16kHz];
1343 for (size_t n = 0; n < kPayloadBytes; ++n) { 1343 for (size_t n = 0; n < kPayloadBytes; ++n) {
1344 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. 1344 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
1345 } 1345 }
1346 // Insert some packets which decode to noise. We are not interested in 1346 // Insert some packets which decode to noise. We are not interested in
1347 // actual decoded values. 1347 // actual decoded values.
1348 NetEqOutputType output_type; 1348 NetEqOutputType output_type;
1349 int num_channels; 1349 size_t num_channels;
1350 size_t samples_per_channel; 1350 size_t samples_per_channel;
1351 uint32_t receive_timestamp = 0; 1351 uint32_t receive_timestamp = 0;
1352 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; 1352 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
1353 for (int n = 0; n < algorithmic_frame_delay; ++n) { 1353 for (int n = 0; n < algorithmic_frame_delay; ++n) {
1354 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); 1354 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
1355 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, 1355 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
1356 &samples_per_channel, &num_channels, 1356 &samples_per_channel, &num_channels,
1357 &output_type)); 1357 &output_type));
1358 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); 1358 ASSERT_EQ(kBlockSize16kHz, samples_per_channel);
1359 ASSERT_EQ(1, num_channels); 1359 ASSERT_EQ(1u, num_channels);
1360 rtp_info.header.sequenceNumber++; 1360 rtp_info.header.sequenceNumber++;
1361 rtp_info.header.timestamp += kBlockSize16kHz; 1361 rtp_info.header.timestamp += kBlockSize16kHz;
1362 receive_timestamp += kBlockSize16kHz; 1362 receive_timestamp += kBlockSize16kHz;
1363 } 1363 }
1364 const int kNumSyncPackets = 10; 1364 const int kNumSyncPackets = 10;
1365 1365
1366 WebRtcRTPHeader first_sync_packet_rtp_info; 1366 WebRtcRTPHeader first_sync_packet_rtp_info;
1367 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info)); 1367 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info));
1368 1368
1369 // Insert sync-packets, but no decoding. 1369 // Insert sync-packets, but no decoding.
(...skipping 18 matching lines...) Expand all
1388 rtp_info.header.timestamp += kBlockSize16kHz; 1388 rtp_info.header.timestamp += kBlockSize16kHz;
1389 receive_timestamp += kBlockSize16kHz; 1389 receive_timestamp += kBlockSize16kHz;
1390 } 1390 }
1391 1391
1392 // Decode. 1392 // Decode.
1393 for (int n = 0; n < kNumSyncPackets; ++n) { 1393 for (int n = 0; n < kNumSyncPackets; ++n) {
1394 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, 1394 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
1395 &samples_per_channel, &num_channels, 1395 &samples_per_channel, &num_channels,
1396 &output_type)); 1396 &output_type));
1397 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); 1397 ASSERT_EQ(kBlockSize16kHz, samples_per_channel);
1398 ASSERT_EQ(1, num_channels); 1398 ASSERT_EQ(1u, num_channels);
1399 EXPECT_TRUE(IsAllNonZero(decoded, samples_per_channel * num_channels)); 1399 EXPECT_TRUE(IsAllNonZero(decoded, samples_per_channel * num_channels));
1400 } 1400 }
1401 } 1401 }
1402 1402
1403 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, 1403 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no,
1404 uint32_t start_timestamp, 1404 uint32_t start_timestamp,
1405 const std::set<uint16_t>& drop_seq_numbers, 1405 const std::set<uint16_t>& drop_seq_numbers,
1406 bool expect_seq_no_wrap, 1406 bool expect_seq_no_wrap,
1407 bool expect_timestamp_wrap) { 1407 bool expect_timestamp_wrap) {
1408 uint16_t seq_no = start_seq_no; 1408 uint16_t seq_no = start_seq_no;
1409 uint32_t timestamp = start_timestamp; 1409 uint32_t timestamp = start_timestamp;
1410 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. 1410 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame.
1411 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; 1411 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs;
1412 const int kSamples = kBlockSize16kHz * kBlocksPerFrame; 1412 const int kSamples = kBlockSize16kHz * kBlocksPerFrame;
1413 const size_t kPayloadBytes = kSamples * sizeof(int16_t); 1413 const size_t kPayloadBytes = kSamples * sizeof(int16_t);
1414 double next_input_time_ms = 0.0; 1414 double next_input_time_ms = 0.0;
1415 int16_t decoded[kBlockSize16kHz]; 1415 int16_t decoded[kBlockSize16kHz];
1416 int num_channels; 1416 size_t num_channels;
1417 size_t samples_per_channel; 1417 size_t samples_per_channel;
1418 NetEqOutputType output_type; 1418 NetEqOutputType output_type;
1419 uint32_t receive_timestamp = 0; 1419 uint32_t receive_timestamp = 0;
1420 1420
1421 // Insert speech for 2 seconds. 1421 // Insert speech for 2 seconds.
1422 const int kSpeechDurationMs = 2000; 1422 const int kSpeechDurationMs = 2000;
1423 int packets_inserted = 0; 1423 int packets_inserted = 0;
1424 uint16_t last_seq_no; 1424 uint16_t last_seq_no;
1425 uint32_t last_timestamp; 1425 uint32_t last_timestamp;
1426 bool timestamp_wrapped = false; 1426 bool timestamp_wrapped = false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 next_input_time_ms += static_cast<double>(kFrameSizeMs); 1459 next_input_time_ms += static_cast<double>(kFrameSizeMs);
1460 1460
1461 seq_no_wrapped |= seq_no < last_seq_no; 1461 seq_no_wrapped |= seq_no < last_seq_no;
1462 timestamp_wrapped |= timestamp < last_timestamp; 1462 timestamp_wrapped |= timestamp < last_timestamp;
1463 } 1463 }
1464 // Pull out data once. 1464 // Pull out data once.
1465 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, 1465 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
1466 &samples_per_channel, &num_channels, 1466 &samples_per_channel, &num_channels,
1467 &output_type)); 1467 &output_type));
1468 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); 1468 ASSERT_EQ(kBlockSize16kHz, samples_per_channel);
1469 ASSERT_EQ(1, num_channels); 1469 ASSERT_EQ(1u, num_channels);
1470 1470
1471 // Expect delay (in samples) to be less than 2 packets. 1471 // Expect delay (in samples) to be less than 2 packets.
1472 EXPECT_LE(timestamp - PlayoutTimestamp(), 1472 EXPECT_LE(timestamp - PlayoutTimestamp(),
1473 static_cast<uint32_t>(kSamples * 2)); 1473 static_cast<uint32_t>(kSamples * 2));
1474 } 1474 }
1475 // Make sure we have actually tested wrap-around. 1475 // Make sure we have actually tested wrap-around.
1476 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); 1476 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped);
1477 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); 1477 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped);
1478 } 1478 }
1479 1479
(...skipping 30 matching lines...) Expand all
1510 const int kFrameSizeMs = 10; 1510 const int kFrameSizeMs = 10;
1511 const int kSampleRateKhz = 16; 1511 const int kSampleRateKhz = 16;
1512 const int kSamples = kFrameSizeMs * kSampleRateKhz; 1512 const int kSamples = kFrameSizeMs * kSampleRateKhz;
1513 const size_t kPayloadBytes = kSamples * 2; 1513 const size_t kPayloadBytes = kSamples * 2;
1514 1514
1515 const int algorithmic_delay_samples = std::max( 1515 const int algorithmic_delay_samples = std::max(
1516 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); 1516 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8);
1517 // Insert three speech packets. Three are needed to get the frame length 1517 // Insert three speech packets. Three are needed to get the frame length
1518 // correct. 1518 // correct.
1519 size_t out_len; 1519 size_t out_len;
1520 int num_channels; 1520 size_t num_channels;
1521 NetEqOutputType type; 1521 NetEqOutputType type;
1522 uint8_t payload[kPayloadBytes] = {0}; 1522 uint8_t payload[kPayloadBytes] = {0};
1523 WebRtcRTPHeader rtp_info; 1523 WebRtcRTPHeader rtp_info;
1524 for (int i = 0; i < 3; ++i) { 1524 for (int i = 0; i < 3; ++i) {
1525 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1525 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1526 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1526 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1527 ++seq_no; 1527 ++seq_no;
1528 timestamp += kSamples; 1528 timestamp += kSamples;
1529 1529
1530 // Pull audio once. 1530 // Pull audio once.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); 1613 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
1614 ASSERT_EQ( 1614 ASSERT_EQ(
1615 NetEq::kOK, 1615 NetEq::kOK,
1616 neteq_->InsertPacket( 1616 neteq_->InsertPacket(
1617 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); 1617 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
1618 ++seq_no; 1618 ++seq_no;
1619 timestamp += kCngPeriodSamples; 1619 timestamp += kCngPeriodSamples;
1620 1620
1621 // Pull audio once and make sure CNG is played. 1621 // Pull audio once and make sure CNG is played.
1622 size_t out_len; 1622 size_t out_len;
1623 int num_channels; 1623 size_t num_channels;
1624 NetEqOutputType type; 1624 NetEqOutputType type;
1625 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, 1625 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len,
1626 &num_channels, &type)); 1626 &num_channels, &type));
1627 ASSERT_EQ(kBlockSize16kHz, out_len); 1627 ASSERT_EQ(kBlockSize16kHz, out_len);
1628 EXPECT_EQ(kOutputCNG, type); 1628 EXPECT_EQ(kOutputCNG, type);
1629 1629
1630 // Insert some speech packets. 1630 // Insert some speech packets.
1631 for (int i = 0; i < 3; ++i) { 1631 for (int i = 0; i < 3; ++i) {
1632 PopulateRtpInfo(seq_no, timestamp, &rtp_info); 1632 PopulateRtpInfo(seq_no, timestamp, &rtp_info);
1633 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 1633 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
1634 ++seq_no; 1634 ++seq_no;
1635 timestamp += kSamples; 1635 timestamp += kSamples;
1636 1636
1637 // Pull audio once. 1637 // Pull audio once.
1638 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, 1638 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len,
1639 &num_channels, &type)); 1639 &num_channels, &type));
1640 ASSERT_EQ(kBlockSize16kHz, out_len); 1640 ASSERT_EQ(kBlockSize16kHz, out_len);
1641 } 1641 }
1642 // Verify speech output. 1642 // Verify speech output.
1643 EXPECT_EQ(kOutputNormal, type); 1643 EXPECT_EQ(kOutputNormal, type);
1644 } 1644 }
1645 1645
1646 } // namespace webrtc 1646 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698