OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 packet_->payload(), packet_->payload_length_bytes()), | 418 packet_->payload(), packet_->payload_length_bytes()), |
419 static_cast<uint32_t>(packet_->time_ms() * | 419 static_cast<uint32_t>(packet_->time_ms() * |
420 (output_sample_rate_ / 1000)))); | 420 (output_sample_rate_ / 1000)))); |
421 } | 421 } |
422 // Get next packet. | 422 // Get next packet. |
423 packet_.reset(rtp_source_->NextPacket()); | 423 packet_.reset(rtp_source_->NextPacket()); |
424 } | 424 } |
425 | 425 |
426 // Get audio from NetEq. | 426 // Get audio from NetEq. |
427 NetEqOutputType type; | 427 NetEqOutputType type; |
428 int num_channels; | 428 size_t num_channels; |
429 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, | 429 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, |
430 &num_channels, &type)); | 430 &num_channels, &type)); |
431 ASSERT_TRUE((*out_len == kBlockSize8kHz) || | 431 ASSERT_TRUE((*out_len == kBlockSize8kHz) || |
432 (*out_len == kBlockSize16kHz) || | 432 (*out_len == kBlockSize16kHz) || |
433 (*out_len == kBlockSize32kHz) || | 433 (*out_len == kBlockSize32kHz) || |
434 (*out_len == kBlockSize48kHz)); | 434 (*out_len == kBlockSize48kHz)); |
435 output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000); | 435 output_sample_rate_ = static_cast<int>(*out_len / 10 * 1000); |
436 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); | 436 EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); |
437 | 437 |
438 // Increase time. | 438 // Increase time. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 rtp_info.header.sequenceNumber = i; | 601 rtp_info.header.sequenceNumber = i; |
602 rtp_info.header.timestamp = i * kSamples; | 602 rtp_info.header.timestamp = i * kSamples; |
603 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. | 603 rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. |
604 rtp_info.header.payloadType = 94; // PCM16b WB codec. | 604 rtp_info.header.payloadType = 94; // PCM16b WB codec. |
605 rtp_info.header.markerBit = 0; | 605 rtp_info.header.markerBit = 0; |
606 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 606 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
607 } | 607 } |
608 // Pull out all data. | 608 // Pull out all data. |
609 for (size_t i = 0; i < num_frames; ++i) { | 609 for (size_t i = 0; i < num_frames; ++i) { |
610 size_t out_len; | 610 size_t out_len; |
611 int num_channels; | 611 size_t num_channels; |
612 NetEqOutputType type; | 612 NetEqOutputType type; |
613 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 613 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
614 &num_channels, &type)); | 614 &num_channels, &type)); |
615 ASSERT_EQ(kBlockSize16kHz, out_len); | 615 ASSERT_EQ(kBlockSize16kHz, out_len); |
616 } | 616 } |
617 | 617 |
618 NetEqNetworkStatistics stats; | 618 NetEqNetworkStatistics stats; |
619 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); | 619 EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
620 // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms | 620 // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms |
621 // spacing (per definition), we expect the delay to increase with 10 ms for | 621 // spacing (per definition), we expect the delay to increase with 10 ms for |
(...skipping 24 matching lines...) Expand all Loading... |
646 for (int n = 0; n < num_packets; ++n) { | 646 for (int n = 0; n < num_packets; ++n) { |
647 uint8_t payload[kPayloadBytes] = {0}; | 647 uint8_t payload[kPayloadBytes] = {0}; |
648 WebRtcRTPHeader rtp_info; | 648 WebRtcRTPHeader rtp_info; |
649 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); | 649 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
650 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 650 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
651 ++frame_index; | 651 ++frame_index; |
652 } | 652 } |
653 | 653 |
654 // Pull out data once. | 654 // Pull out data once. |
655 size_t out_len; | 655 size_t out_len; |
656 int num_channels; | 656 size_t num_channels; |
657 NetEqOutputType type; | 657 NetEqOutputType type; |
658 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 658 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
659 &num_channels, &type)); | 659 &num_channels, &type)); |
660 ASSERT_EQ(kBlockSize16kHz, out_len); | 660 ASSERT_EQ(kBlockSize16kHz, out_len); |
661 } | 661 } |
662 | 662 |
663 NetEqNetworkStatistics network_stats; | 663 NetEqNetworkStatistics network_stats; |
664 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); | 664 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
665 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); | 665 EXPECT_EQ(-103196, network_stats.clockdrift_ppm); |
666 } | 666 } |
(...skipping 10 matching lines...) Expand all Loading... |
677 for (int n = 0; n < num_packets; ++n) { | 677 for (int n = 0; n < num_packets; ++n) { |
678 uint8_t payload[kPayloadBytes] = {0}; | 678 uint8_t payload[kPayloadBytes] = {0}; |
679 WebRtcRTPHeader rtp_info; | 679 WebRtcRTPHeader rtp_info; |
680 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); | 680 PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
681 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 681 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
682 ++frame_index; | 682 ++frame_index; |
683 } | 683 } |
684 | 684 |
685 // Pull out data once. | 685 // Pull out data once. |
686 size_t out_len; | 686 size_t out_len; |
687 int num_channels; | 687 size_t num_channels; |
688 NetEqOutputType type; | 688 NetEqOutputType type; |
689 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 689 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
690 &num_channels, &type)); | 690 &num_channels, &type)); |
691 ASSERT_EQ(kBlockSize16kHz, out_len); | 691 ASSERT_EQ(kBlockSize16kHz, out_len); |
692 } | 692 } |
693 | 693 |
694 NetEqNetworkStatistics network_stats; | 694 NetEqNetworkStatistics network_stats; |
695 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); | 695 ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
696 EXPECT_EQ(110946, network_stats.clockdrift_ppm); | 696 EXPECT_EQ(110946, network_stats.clockdrift_ppm); |
697 } | 697 } |
698 | 698 |
699 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, | 699 void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, |
700 double network_freeze_ms, | 700 double network_freeze_ms, |
701 bool pull_audio_during_freeze, | 701 bool pull_audio_during_freeze, |
702 int delay_tolerance_ms, | 702 int delay_tolerance_ms, |
703 int max_time_to_speech_ms) { | 703 int max_time_to_speech_ms) { |
704 uint16_t seq_no = 0; | 704 uint16_t seq_no = 0; |
705 uint32_t timestamp = 0; | 705 uint32_t timestamp = 0; |
706 const int kFrameSizeMs = 30; | 706 const int kFrameSizeMs = 30; |
707 const size_t kSamples = kFrameSizeMs * 16; | 707 const size_t kSamples = kFrameSizeMs * 16; |
708 const size_t kPayloadBytes = kSamples * 2; | 708 const size_t kPayloadBytes = kSamples * 2; |
709 double next_input_time_ms = 0.0; | 709 double next_input_time_ms = 0.0; |
710 double t_ms; | 710 double t_ms; |
711 size_t out_len; | 711 size_t out_len; |
712 int num_channels; | 712 size_t num_channels; |
713 NetEqOutputType type; | 713 NetEqOutputType type; |
714 | 714 |
715 // Insert speech for 5 seconds. | 715 // Insert speech for 5 seconds. |
716 const int kSpeechDurationMs = 5000; | 716 const int kSpeechDurationMs = 5000; |
717 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { | 717 for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
718 // Each turn in this for loop is 10 ms. | 718 // Each turn in this for loop is 10 ms. |
719 while (next_input_time_ms <= t_ms) { | 719 while (next_input_time_ms <= t_ms) { |
720 // Insert one 30 ms speech frame. | 720 // Insert one 30 ms speech frame. |
721 uint8_t payload[kPayloadBytes] = {0}; | 721 uint8_t payload[kPayloadBytes] = {0}; |
722 WebRtcRTPHeader rtp_info; | 722 WebRtcRTPHeader rtp_info; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 WebRtcRTPHeader rtp_info; | 941 WebRtcRTPHeader rtp_info; |
942 PopulateRtpInfo(0, 0, &rtp_info); | 942 PopulateRtpInfo(0, 0, &rtp_info); |
943 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. | 943 rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. |
944 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 944 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
945 NetEqOutputType type; | 945 NetEqOutputType type; |
946 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call | 946 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
947 // to GetAudio. | 947 // to GetAudio. |
948 for (size_t i = 0; i < kMaxBlockSize; ++i) { | 948 for (size_t i = 0; i < kMaxBlockSize; ++i) { |
949 out_data_[i] = 1; | 949 out_data_[i] = 1; |
950 } | 950 } |
951 int num_channels; | 951 size_t num_channels; |
952 size_t samples_per_channel; | 952 size_t samples_per_channel; |
953 EXPECT_EQ(NetEq::kFail, | 953 EXPECT_EQ(NetEq::kFail, |
954 neteq_->GetAudio(kMaxBlockSize, out_data_, | 954 neteq_->GetAudio(kMaxBlockSize, out_data_, |
955 &samples_per_channel, &num_channels, &type)); | 955 &samples_per_channel, &num_channels, &type)); |
956 // Verify that there is a decoder error to check. | 956 // Verify that there is a decoder error to check. |
957 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); | 957 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
958 // Code 6730 is an iSAC error code. | 958 // Code 6730 is an iSAC error code. |
959 EXPECT_EQ(6730, neteq_->LastDecoderError()); | 959 EXPECT_EQ(6730, neteq_->LastDecoderError()); |
960 // Verify that the first 160 samples are set to 0, and that the remaining | 960 // Verify that the first 160 samples are set to 0, and that the remaining |
961 // samples are left unmodified. | 961 // samples are left unmodified. |
(...skipping 13 matching lines...) Expand all Loading... |
975 } | 975 } |
976 #endif | 976 #endif |
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 Loading... |
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); | 1265 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
1266 uint8_t payload[kPayloadBytes]; | 1266 uint8_t payload[kPayloadBytes]; |
1267 int16_t decoded[kBlockSize16kHz]; | 1267 int16_t decoded[kBlockSize16kHz]; |
1268 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; | 1268 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; |
1269 for (size_t n = 0; n < kPayloadBytes; ++n) { | 1269 for (size_t n = 0; n < kPayloadBytes; ++n) { |
1270 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. | 1270 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
1271 } | 1271 } |
1272 // Insert some packets which decode to noise. We are not interested in | 1272 // Insert some packets which decode to noise. We are not interested in |
1273 // actual decoded values. | 1273 // actual decoded values. |
1274 NetEqOutputType output_type; | 1274 NetEqOutputType output_type; |
1275 int num_channels; | 1275 size_t num_channels; |
1276 size_t samples_per_channel; | 1276 size_t samples_per_channel; |
1277 uint32_t receive_timestamp = 0; | 1277 uint32_t receive_timestamp = 0; |
1278 for (int n = 0; n < 100; ++n) { | 1278 for (int n = 0; n < 100; ++n) { |
1279 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); | 1279 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); |
1280 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1280 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1281 &samples_per_channel, &num_channels, | 1281 &samples_per_channel, &num_channels, |
1282 &output_type)); | 1282 &output_type)); |
1283 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1283 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1284 ASSERT_EQ(1, num_channels); | 1284 ASSERT_EQ(1u, num_channels); |
1285 | 1285 |
1286 rtp_info.header.sequenceNumber++; | 1286 rtp_info.header.sequenceNumber++; |
1287 rtp_info.header.timestamp += kBlockSize16kHz; | 1287 rtp_info.header.timestamp += kBlockSize16kHz; |
1288 receive_timestamp += kBlockSize16kHz; | 1288 receive_timestamp += kBlockSize16kHz; |
1289 } | 1289 } |
1290 const int kNumSyncPackets = 10; | 1290 const int kNumSyncPackets = 10; |
1291 | 1291 |
1292 // Make sure sufficient number of sync packets are inserted that we can | 1292 // Make sure sufficient number of sync packets are inserted that we can |
1293 // conduct a test. | 1293 // conduct a test. |
1294 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay); | 1294 ASSERT_GT(kNumSyncPackets, algorithmic_frame_delay); |
1295 // Insert sync-packets, the decoded sequence should be all-zero. | 1295 // Insert sync-packets, the decoded sequence should be all-zero. |
1296 for (int n = 0; n < kNumSyncPackets; ++n) { | 1296 for (int n = 0; n < kNumSyncPackets; ++n) { |
1297 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); | 1297 ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
1298 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1298 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1299 &samples_per_channel, &num_channels, | 1299 &samples_per_channel, &num_channels, |
1300 &output_type)); | 1300 &output_type)); |
1301 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1301 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1302 ASSERT_EQ(1, num_channels); | 1302 ASSERT_EQ(1u, num_channels); |
1303 if (n > algorithmic_frame_delay) { | 1303 if (n > algorithmic_frame_delay) { |
1304 EXPECT_TRUE(IsAllZero(decoded, samples_per_channel * num_channels)); | 1304 EXPECT_TRUE(IsAllZero(decoded, samples_per_channel * num_channels)); |
1305 } | 1305 } |
1306 rtp_info.header.sequenceNumber++; | 1306 rtp_info.header.sequenceNumber++; |
1307 rtp_info.header.timestamp += kBlockSize16kHz; | 1307 rtp_info.header.timestamp += kBlockSize16kHz; |
1308 receive_timestamp += kBlockSize16kHz; | 1308 receive_timestamp += kBlockSize16kHz; |
1309 } | 1309 } |
1310 | 1310 |
1311 // We insert regular packets, if sync packet are not correctly buffered then | 1311 // We insert regular packets, if sync packet are not correctly buffered then |
1312 // network statistics would show some packet loss. | 1312 // network statistics would show some packet loss. |
(...skipping 28 matching lines...) Expand all Loading... |
1341 PopulateRtpInfo(0, 0, &rtp_info); | 1341 PopulateRtpInfo(0, 0, &rtp_info); |
1342 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); | 1342 const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
1343 uint8_t payload[kPayloadBytes]; | 1343 uint8_t payload[kPayloadBytes]; |
1344 int16_t decoded[kBlockSize16kHz]; | 1344 int16_t decoded[kBlockSize16kHz]; |
1345 for (size_t n = 0; n < kPayloadBytes; ++n) { | 1345 for (size_t n = 0; n < kPayloadBytes; ++n) { |
1346 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. | 1346 payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
1347 } | 1347 } |
1348 // Insert some packets which decode to noise. We are not interested in | 1348 // Insert some packets which decode to noise. We are not interested in |
1349 // actual decoded values. | 1349 // actual decoded values. |
1350 NetEqOutputType output_type; | 1350 NetEqOutputType output_type; |
1351 int num_channels; | 1351 size_t num_channels; |
1352 size_t samples_per_channel; | 1352 size_t samples_per_channel; |
1353 uint32_t receive_timestamp = 0; | 1353 uint32_t receive_timestamp = 0; |
1354 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; | 1354 int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1; |
1355 for (int n = 0; n < algorithmic_frame_delay; ++n) { | 1355 for (int n = 0; n < algorithmic_frame_delay; ++n) { |
1356 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); | 1356 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); |
1357 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1357 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1358 &samples_per_channel, &num_channels, | 1358 &samples_per_channel, &num_channels, |
1359 &output_type)); | 1359 &output_type)); |
1360 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1360 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1361 ASSERT_EQ(1, num_channels); | 1361 ASSERT_EQ(1u, num_channels); |
1362 rtp_info.header.sequenceNumber++; | 1362 rtp_info.header.sequenceNumber++; |
1363 rtp_info.header.timestamp += kBlockSize16kHz; | 1363 rtp_info.header.timestamp += kBlockSize16kHz; |
1364 receive_timestamp += kBlockSize16kHz; | 1364 receive_timestamp += kBlockSize16kHz; |
1365 } | 1365 } |
1366 const int kNumSyncPackets = 10; | 1366 const int kNumSyncPackets = 10; |
1367 | 1367 |
1368 WebRtcRTPHeader first_sync_packet_rtp_info; | 1368 WebRtcRTPHeader first_sync_packet_rtp_info; |
1369 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info)); | 1369 memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info)); |
1370 | 1370 |
1371 // Insert sync-packets, but no decoding. | 1371 // Insert sync-packets, but no decoding. |
(...skipping 18 matching lines...) Expand all Loading... |
1390 rtp_info.header.timestamp += kBlockSize16kHz; | 1390 rtp_info.header.timestamp += kBlockSize16kHz; |
1391 receive_timestamp += kBlockSize16kHz; | 1391 receive_timestamp += kBlockSize16kHz; |
1392 } | 1392 } |
1393 | 1393 |
1394 // Decode. | 1394 // Decode. |
1395 for (int n = 0; n < kNumSyncPackets; ++n) { | 1395 for (int n = 0; n < kNumSyncPackets; ++n) { |
1396 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1396 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1397 &samples_per_channel, &num_channels, | 1397 &samples_per_channel, &num_channels, |
1398 &output_type)); | 1398 &output_type)); |
1399 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1399 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1400 ASSERT_EQ(1, num_channels); | 1400 ASSERT_EQ(1u, num_channels); |
1401 EXPECT_TRUE(IsAllNonZero(decoded, samples_per_channel * num_channels)); | 1401 EXPECT_TRUE(IsAllNonZero(decoded, samples_per_channel * num_channels)); |
1402 } | 1402 } |
1403 } | 1403 } |
1404 | 1404 |
1405 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, | 1405 void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, |
1406 uint32_t start_timestamp, | 1406 uint32_t start_timestamp, |
1407 const std::set<uint16_t>& drop_seq_numbers, | 1407 const std::set<uint16_t>& drop_seq_numbers, |
1408 bool expect_seq_no_wrap, | 1408 bool expect_seq_no_wrap, |
1409 bool expect_timestamp_wrap) { | 1409 bool expect_timestamp_wrap) { |
1410 uint16_t seq_no = start_seq_no; | 1410 uint16_t seq_no = start_seq_no; |
1411 uint32_t timestamp = start_timestamp; | 1411 uint32_t timestamp = start_timestamp; |
1412 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. | 1412 const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. |
1413 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; | 1413 const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; |
1414 const int kSamples = kBlockSize16kHz * kBlocksPerFrame; | 1414 const int kSamples = kBlockSize16kHz * kBlocksPerFrame; |
1415 const size_t kPayloadBytes = kSamples * sizeof(int16_t); | 1415 const size_t kPayloadBytes = kSamples * sizeof(int16_t); |
1416 double next_input_time_ms = 0.0; | 1416 double next_input_time_ms = 0.0; |
1417 int16_t decoded[kBlockSize16kHz]; | 1417 int16_t decoded[kBlockSize16kHz]; |
1418 int num_channels; | 1418 size_t num_channels; |
1419 size_t samples_per_channel; | 1419 size_t samples_per_channel; |
1420 NetEqOutputType output_type; | 1420 NetEqOutputType output_type; |
1421 uint32_t receive_timestamp = 0; | 1421 uint32_t receive_timestamp = 0; |
1422 | 1422 |
1423 // Insert speech for 2 seconds. | 1423 // Insert speech for 2 seconds. |
1424 const int kSpeechDurationMs = 2000; | 1424 const int kSpeechDurationMs = 2000; |
1425 int packets_inserted = 0; | 1425 int packets_inserted = 0; |
1426 uint16_t last_seq_no; | 1426 uint16_t last_seq_no; |
1427 uint32_t last_timestamp; | 1427 uint32_t last_timestamp; |
1428 bool timestamp_wrapped = false; | 1428 bool timestamp_wrapped = false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 next_input_time_ms += static_cast<double>(kFrameSizeMs); | 1461 next_input_time_ms += static_cast<double>(kFrameSizeMs); |
1462 | 1462 |
1463 seq_no_wrapped |= seq_no < last_seq_no; | 1463 seq_no_wrapped |= seq_no < last_seq_no; |
1464 timestamp_wrapped |= timestamp < last_timestamp; | 1464 timestamp_wrapped |= timestamp < last_timestamp; |
1465 } | 1465 } |
1466 // Pull out data once. | 1466 // Pull out data once. |
1467 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, | 1467 ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
1468 &samples_per_channel, &num_channels, | 1468 &samples_per_channel, &num_channels, |
1469 &output_type)); | 1469 &output_type)); |
1470 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); | 1470 ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
1471 ASSERT_EQ(1, num_channels); | 1471 ASSERT_EQ(1u, num_channels); |
1472 | 1472 |
1473 // Expect delay (in samples) to be less than 2 packets. | 1473 // Expect delay (in samples) to be less than 2 packets. |
1474 EXPECT_LE(timestamp - PlayoutTimestamp(), | 1474 EXPECT_LE(timestamp - PlayoutTimestamp(), |
1475 static_cast<uint32_t>(kSamples * 2)); | 1475 static_cast<uint32_t>(kSamples * 2)); |
1476 } | 1476 } |
1477 // Make sure we have actually tested wrap-around. | 1477 // Make sure we have actually tested wrap-around. |
1478 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); | 1478 ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); |
1479 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); | 1479 ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); |
1480 } | 1480 } |
1481 | 1481 |
(...skipping 30 matching lines...) Expand all Loading... |
1512 const int kFrameSizeMs = 10; | 1512 const int kFrameSizeMs = 10; |
1513 const int kSampleRateKhz = 16; | 1513 const int kSampleRateKhz = 16; |
1514 const int kSamples = kFrameSizeMs * kSampleRateKhz; | 1514 const int kSamples = kFrameSizeMs * kSampleRateKhz; |
1515 const size_t kPayloadBytes = kSamples * 2; | 1515 const size_t kPayloadBytes = kSamples * 2; |
1516 | 1516 |
1517 const int algorithmic_delay_samples = std::max( | 1517 const int algorithmic_delay_samples = std::max( |
1518 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); | 1518 algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); |
1519 // Insert three speech packets. Three are needed to get the frame length | 1519 // Insert three speech packets. Three are needed to get the frame length |
1520 // correct. | 1520 // correct. |
1521 size_t out_len; | 1521 size_t out_len; |
1522 int num_channels; | 1522 size_t num_channels; |
1523 NetEqOutputType type; | 1523 NetEqOutputType type; |
1524 uint8_t payload[kPayloadBytes] = {0}; | 1524 uint8_t payload[kPayloadBytes] = {0}; |
1525 WebRtcRTPHeader rtp_info; | 1525 WebRtcRTPHeader rtp_info; |
1526 for (int i = 0; i < 3; ++i) { | 1526 for (int i = 0; i < 3; ++i) { |
1527 PopulateRtpInfo(seq_no, timestamp, &rtp_info); | 1527 PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
1528 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 1528 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
1529 ++seq_no; | 1529 ++seq_no; |
1530 timestamp += kSamples; | 1530 timestamp += kSamples; |
1531 | 1531 |
1532 // Pull audio once. | 1532 // Pull audio once. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); | 1615 PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
1616 ASSERT_EQ( | 1616 ASSERT_EQ( |
1617 NetEq::kOK, | 1617 NetEq::kOK, |
1618 neteq_->InsertPacket( | 1618 neteq_->InsertPacket( |
1619 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); | 1619 rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
1620 ++seq_no; | 1620 ++seq_no; |
1621 timestamp += kCngPeriodSamples; | 1621 timestamp += kCngPeriodSamples; |
1622 | 1622 |
1623 // Pull audio once and make sure CNG is played. | 1623 // Pull audio once and make sure CNG is played. |
1624 size_t out_len; | 1624 size_t out_len; |
1625 int num_channels; | 1625 size_t num_channels; |
1626 NetEqOutputType type; | 1626 NetEqOutputType type; |
1627 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 1627 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
1628 &num_channels, &type)); | 1628 &num_channels, &type)); |
1629 ASSERT_EQ(kBlockSize16kHz, out_len); | 1629 ASSERT_EQ(kBlockSize16kHz, out_len); |
1630 EXPECT_EQ(kOutputCNG, type); | 1630 EXPECT_EQ(kOutputCNG, type); |
1631 | 1631 |
1632 // Insert some speech packets. | 1632 // Insert some speech packets. |
1633 for (int i = 0; i < 3; ++i) { | 1633 for (int i = 0; i < 3; ++i) { |
1634 PopulateRtpInfo(seq_no, timestamp, &rtp_info); | 1634 PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
1635 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); | 1635 ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
1636 ++seq_no; | 1636 ++seq_no; |
1637 timestamp += kSamples; | 1637 timestamp += kSamples; |
1638 | 1638 |
1639 // Pull audio once. | 1639 // Pull audio once. |
1640 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, | 1640 ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
1641 &num_channels, &type)); | 1641 &num_channels, &type)); |
1642 ASSERT_EQ(kBlockSize16kHz, out_len); | 1642 ASSERT_EQ(kBlockSize16kHz, out_len); |
1643 } | 1643 } |
1644 // Verify speech output. | 1644 // Verify speech output. |
1645 EXPECT_EQ(kOutputNormal, type); | 1645 EXPECT_EQ(kOutputNormal, type); |
1646 } | 1646 } |
1647 | 1647 |
1648 } // namespace webrtc | 1648 } // namespace webrtc |
OLD | NEW |