henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/neteq/include/neteq.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 3ecc162 | 2014-03-07 15:23:34 +0000 | [diff] [blame] | 13 | #include <math.h> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
| 15 | #include <string.h> // memset |
| 16 | |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 17 | #include <algorithm> |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 18 | #include <memory> |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 19 | #include <set> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 24 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" |
| 26 | #include "modules/audio_coding/neteq/tools/audio_loop.h" |
| 27 | #include "modules/audio_coding/neteq/tools/rtp_file_source.h" |
| 28 | #include "modules/include/module_common_types.h" |
| 29 | #include "rtc_base/flags.h" |
| 30 | #include "rtc_base/ignore_wundef.h" |
Joachim Bauch | 4e90919 | 2017-12-19 22:27:51 +0100 | [diff] [blame^] | 31 | #include "rtc_base/messagedigest.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 32 | #include "rtc_base/numerics/safe_conversions.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "rtc_base/protobuf_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "rtc_base/stringencode.h" |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 35 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "test/gtest.h" |
| 37 | #include "test/testsupport/fileutils.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 38 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 39 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 40 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 41 | RTC_PUSH_IGNORING_WUNDEF() |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 42 | #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 43 | #include "external/webrtc/webrtc/modules/audio_coding/neteq/neteq_unittest.pb.h" |
| 44 | #else |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 45 | #include "modules/audio_coding/neteq/neteq_unittest.pb.h" |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 46 | #endif |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 47 | RTC_POP_IGNORING_WUNDEF() |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 48 | #endif |
| 49 | |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 50 | DEFINE_bool(gen_ref, false, "Generate reference files."); |
| 51 | |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 52 | namespace webrtc { |
| 53 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 54 | namespace { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 55 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 56 | const std::string& PlatformChecksum(const std::string& checksum_general, |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 57 | const std::string& checksum_android_32, |
| 58 | const std::string& checksum_android_64, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 59 | const std::string& checksum_win_32, |
| 60 | const std::string& checksum_win_64) { |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 61 | #if defined(WEBRTC_ANDROID) |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 62 | #ifdef WEBRTC_ARCH_64_BITS |
| 63 | return checksum_android_64; |
| 64 | #else |
| 65 | return checksum_android_32; |
| 66 | #endif // WEBRTC_ARCH_64_BITS |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 67 | #elif defined(WEBRTC_WIN) |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 68 | #ifdef WEBRTC_ARCH_64_BITS |
| 69 | return checksum_win_64; |
| 70 | #else |
| 71 | return checksum_win_32; |
| 72 | #endif // WEBRTC_ARCH_64_BITS |
| 73 | #else |
| 74 | return checksum_general; |
| 75 | #endif // WEBRTC_WIN |
| 76 | } |
| 77 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 78 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
| 79 | void Convert(const webrtc::NetEqNetworkStatistics& stats_raw, |
| 80 | webrtc::neteq_unittest::NetEqNetworkStatistics* stats) { |
| 81 | stats->set_current_buffer_size_ms(stats_raw.current_buffer_size_ms); |
| 82 | stats->set_preferred_buffer_size_ms(stats_raw.preferred_buffer_size_ms); |
| 83 | stats->set_jitter_peaks_found(stats_raw.jitter_peaks_found); |
| 84 | stats->set_packet_loss_rate(stats_raw.packet_loss_rate); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 85 | stats->set_expand_rate(stats_raw.expand_rate); |
| 86 | stats->set_speech_expand_rate(stats_raw.speech_expand_rate); |
| 87 | stats->set_preemptive_rate(stats_raw.preemptive_rate); |
| 88 | stats->set_accelerate_rate(stats_raw.accelerate_rate); |
| 89 | stats->set_secondary_decoded_rate(stats_raw.secondary_decoded_rate); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 90 | stats->set_secondary_discarded_rate(stats_raw.secondary_discarded_rate); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 91 | stats->set_clockdrift_ppm(stats_raw.clockdrift_ppm); |
| 92 | stats->set_added_zero_samples(stats_raw.added_zero_samples); |
| 93 | stats->set_mean_waiting_time_ms(stats_raw.mean_waiting_time_ms); |
| 94 | stats->set_median_waiting_time_ms(stats_raw.median_waiting_time_ms); |
| 95 | stats->set_min_waiting_time_ms(stats_raw.min_waiting_time_ms); |
| 96 | stats->set_max_waiting_time_ms(stats_raw.max_waiting_time_ms); |
| 97 | } |
| 98 | |
| 99 | void Convert(const webrtc::RtcpStatistics& stats_raw, |
| 100 | webrtc::neteq_unittest::RtcpStatistics* stats) { |
| 101 | stats->set_fraction_lost(stats_raw.fraction_lost); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 102 | stats->set_cumulative_lost(stats_raw.packets_lost); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 103 | stats->set_extended_max_sequence_number( |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 104 | stats_raw.extended_highest_sequence_number); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 105 | stats->set_jitter(stats_raw.jitter); |
| 106 | } |
| 107 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 108 | void AddMessage(FILE* file, rtc::MessageDigest* digest, |
| 109 | const std::string& message) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 110 | int32_t size = message.length(); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 111 | if (file) |
| 112 | ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); |
| 113 | digest->Update(&size, sizeof(size)); |
| 114 | |
| 115 | if (file) |
| 116 | ASSERT_EQ(static_cast<size_t>(size), |
| 117 | fwrite(message.data(), sizeof(char), size, file)); |
| 118 | digest->Update(message.data(), sizeof(char) * size); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 119 | } |
| 120 | |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 121 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
| 122 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 123 | void LoadDecoders(webrtc::NetEq* neteq) { |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 124 | ASSERT_EQ(true, |
| 125 | neteq->RegisterPayloadType(0, SdpAudioFormat("pcmu", 8000, 1))); |
| 126 | // Use non-SdpAudioFormat argument when registering PCMa, so that we get test |
| 127 | // coverage for that as well. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 128 | ASSERT_EQ(0, neteq->RegisterPayloadType(webrtc::NetEqDecoder::kDecoderPCMa, |
| 129 | "pcma", 8)); |
| 130 | #ifdef WEBRTC_CODEC_ILBC |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 131 | ASSERT_EQ(true, |
| 132 | neteq->RegisterPayloadType(102, SdpAudioFormat("ilbc", 8000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 133 | #endif |
| 134 | #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 135 | ASSERT_EQ(true, |
| 136 | neteq->RegisterPayloadType(103, SdpAudioFormat("isac", 16000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 137 | #endif |
| 138 | #ifdef WEBRTC_CODEC_ISAC |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 139 | ASSERT_EQ(true, |
| 140 | neteq->RegisterPayloadType(104, SdpAudioFormat("isac", 32000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 141 | #endif |
| 142 | #ifdef WEBRTC_CODEC_OPUS |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 143 | ASSERT_EQ(true, |
| 144 | neteq->RegisterPayloadType( |
| 145 | 111, SdpAudioFormat("opus", 48000, 2, {{"stereo", "0"}}))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 146 | #endif |
kwiberg | 5adaf73 | 2016-10-04 09:33:27 -0700 | [diff] [blame] | 147 | ASSERT_EQ(true, |
| 148 | neteq->RegisterPayloadType(93, SdpAudioFormat("L16", 8000, 1))); |
| 149 | ASSERT_EQ(true, |
| 150 | neteq->RegisterPayloadType(94, SdpAudioFormat("L16", 16000, 1))); |
| 151 | ASSERT_EQ(true, |
| 152 | neteq->RegisterPayloadType(95, SdpAudioFormat("L16", 32000, 1))); |
| 153 | ASSERT_EQ(true, |
| 154 | neteq->RegisterPayloadType(13, SdpAudioFormat("cn", 8000, 1))); |
| 155 | ASSERT_EQ(true, |
| 156 | neteq->RegisterPayloadType(98, SdpAudioFormat("cn", 16000, 1))); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 157 | } |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 158 | } // namespace |
| 159 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 160 | class ResultSink { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 161 | public: |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 162 | explicit ResultSink(const std::string& output_file); |
| 163 | ~ResultSink(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 164 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 165 | template<typename T> void AddResult(const T* test_results, size_t length); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 166 | |
| 167 | void AddResult(const NetEqNetworkStatistics& stats); |
| 168 | void AddResult(const RtcpStatistics& stats); |
| 169 | |
| 170 | void VerifyChecksum(const std::string& ref_check_sum); |
| 171 | |
| 172 | private: |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 173 | FILE* output_fp_; |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 174 | std::unique_ptr<rtc::MessageDigest> digest_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
Joachim Bauch | 4e90919 | 2017-12-19 22:27:51 +0100 | [diff] [blame^] | 177 | ResultSink::ResultSink(const std::string& output_file) |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 178 | : output_fp_(nullptr), |
Joachim Bauch | 4e90919 | 2017-12-19 22:27:51 +0100 | [diff] [blame^] | 179 | digest_(rtc::MessageDigestFactory::Create(rtc::DIGEST_SHA_1)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 180 | if (!output_file.empty()) { |
| 181 | output_fp_ = fopen(output_file.c_str(), "wb"); |
| 182 | EXPECT_TRUE(output_fp_ != NULL); |
| 183 | } |
| 184 | } |
| 185 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 186 | ResultSink::~ResultSink() { |
| 187 | if (output_fp_) |
| 188 | fclose(output_fp_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 189 | } |
| 190 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 191 | template<typename T> |
| 192 | void ResultSink::AddResult(const T* test_results, size_t length) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 193 | if (output_fp_) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 194 | ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 195 | } |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 196 | digest_->Update(test_results, sizeof(T) * length); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 197 | } |
| 198 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 199 | void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 200 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 201 | neteq_unittest::NetEqNetworkStatistics stats; |
| 202 | Convert(stats_raw, &stats); |
| 203 | |
mbonadei | 7c2c843 | 2017-04-07 00:59:12 -0700 | [diff] [blame] | 204 | ProtoString stats_string; |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 205 | ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 206 | AddMessage(output_fp_, digest_.get(), stats_string); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 207 | #else |
| 208 | FAIL() << "Writing to reference file requires Proto Buffer."; |
| 209 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 210 | } |
| 211 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 212 | void ResultSink::AddResult(const RtcpStatistics& stats_raw) { |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 213 | #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 214 | neteq_unittest::RtcpStatistics stats; |
| 215 | Convert(stats_raw, &stats); |
| 216 | |
mbonadei | 7c2c843 | 2017-04-07 00:59:12 -0700 | [diff] [blame] | 217 | ProtoString stats_string; |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 218 | ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 219 | AddMessage(output_fp_, digest_.get(), stats_string); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 220 | #else |
| 221 | FAIL() << "Writing to reference file requires Proto Buffer."; |
| 222 | #endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 223 | } |
| 224 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 225 | void ResultSink::VerifyChecksum(const std::string& checksum) { |
| 226 | std::vector<char> buffer; |
| 227 | buffer.resize(digest_->Size()); |
| 228 | digest_->Finish(&buffer[0], buffer.size()); |
| 229 | const std::string result = rtc::hex_encode(&buffer[0], digest_->Size()); |
| 230 | EXPECT_EQ(checksum, result); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | class NetEqDecodingTest : public ::testing::Test { |
| 234 | protected: |
| 235 | // NetEQ must be polled for data once every 10 ms. Thus, neither of the |
| 236 | // constants below can be changed. |
| 237 | static const int kTimeStepMs = 10; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 238 | static const size_t kBlockSize8kHz = kTimeStepMs * 8; |
| 239 | static const size_t kBlockSize16kHz = kTimeStepMs * 16; |
| 240 | static const size_t kBlockSize32kHz = kTimeStepMs * 32; |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 241 | static const size_t kBlockSize48kHz = kTimeStepMs * 48; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 242 | static const int kInitSampleRateHz = 8000; |
| 243 | |
| 244 | NetEqDecodingTest(); |
| 245 | virtual void SetUp(); |
| 246 | virtual void TearDown(); |
| 247 | void SelectDecoders(NetEqDecoder* used_codec); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 248 | void OpenInputFile(const std::string &rtp_file); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 249 | void Process(); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 250 | |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 251 | void DecodeAndCompare(const std::string& rtp_file, |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 252 | const std::string& output_checksum, |
| 253 | const std::string& network_stats_checksum, |
| 254 | const std::string& rtcp_stats_checksum, |
| 255 | bool gen_ref); |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 256 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 257 | static void PopulateRtpInfo(int frame_index, |
| 258 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 259 | RTPHeader* rtp_info); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 260 | static void PopulateCng(int frame_index, |
| 261 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 262 | RTPHeader* rtp_info, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 263 | uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 264 | size_t* payload_len); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 265 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 266 | void WrapTest(uint16_t start_seq_no, uint32_t start_timestamp, |
| 267 | const std::set<uint16_t>& drop_seq_numbers, |
| 268 | bool expect_seq_no_wrap, bool expect_timestamp_wrap); |
| 269 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 270 | void LongCngWithClockDrift(double drift_factor, |
| 271 | double network_freeze_ms, |
| 272 | bool pull_audio_during_freeze, |
| 273 | int delay_tolerance_ms, |
| 274 | int max_time_to_speech_ms); |
| 275 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 276 | void DuplicateCng(); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 277 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 278 | NetEq* neteq_; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 279 | NetEq::Config config_; |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 280 | std::unique_ptr<test::RtpFileSource> rtp_source_; |
| 281 | std::unique_ptr<test::Packet> packet_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 282 | unsigned int sim_clock_; |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 283 | AudioFrame out_frame_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 284 | int output_sample_rate_; |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 285 | int algorithmic_delay_ms_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | // Allocating the static const so that it can be passed by reference. |
| 289 | const int NetEqDecodingTest::kTimeStepMs; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 290 | const size_t NetEqDecodingTest::kBlockSize8kHz; |
| 291 | const size_t NetEqDecodingTest::kBlockSize16kHz; |
| 292 | const size_t NetEqDecodingTest::kBlockSize32kHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 293 | const int NetEqDecodingTest::kInitSampleRateHz; |
| 294 | |
| 295 | NetEqDecodingTest::NetEqDecodingTest() |
| 296 | : neteq_(NULL), |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 297 | config_(), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 298 | sim_clock_(0), |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 299 | output_sample_rate_(kInitSampleRateHz), |
| 300 | algorithmic_delay_ms_(0) { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 301 | config_.sample_rate_hz = kInitSampleRateHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void NetEqDecodingTest::SetUp() { |
ossu | e352578 | 2016-05-25 07:37:43 -0700 | [diff] [blame] | 305 | neteq_ = NetEq::Create(config_, CreateBuiltinAudioDecoderFactory()); |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 306 | NetEqNetworkStatistics stat; |
| 307 | ASSERT_EQ(0, neteq_->NetworkStatistics(&stat)); |
| 308 | algorithmic_delay_ms_ = stat.current_buffer_size_ms; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 309 | ASSERT_TRUE(neteq_); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 310 | LoadDecoders(neteq_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void NetEqDecodingTest::TearDown() { |
| 314 | delete neteq_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 315 | } |
| 316 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 317 | void NetEqDecodingTest::OpenInputFile(const std::string &rtp_file) { |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 318 | rtp_source_.reset(test::RtpFileSource::Create(rtp_file)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 319 | } |
| 320 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 321 | void NetEqDecodingTest::Process() { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 322 | // Check if time to receive. |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 323 | while (packet_ && sim_clock_ >= packet_->time_ms()) { |
| 324 | if (packet_->payload_length_bytes() > 0) { |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 325 | #ifndef WEBRTC_CODEC_ISAC |
| 326 | // Ignore payload type 104 (iSAC-swb) if ISAC is not supported. |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 327 | if (packet_->header().payloadType != 104) |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 328 | #endif |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 329 | ASSERT_EQ(0, |
| 330 | neteq_->InsertPacket( |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 331 | packet_->header(), |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 332 | rtc::ArrayView<const uint8_t>( |
| 333 | packet_->payload(), packet_->payload_length_bytes()), |
| 334 | static_cast<uint32_t>(packet_->time_ms() * |
| 335 | (output_sample_rate_ / 1000)))); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 336 | } |
| 337 | // Get next packet. |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 338 | packet_ = rtp_source_->NextPacket(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 339 | } |
| 340 | |
henrik.lundin@webrtc.org | e1d468c | 2013-01-30 07:37:20 +0000 | [diff] [blame] | 341 | // Get audio from NetEq. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 342 | bool muted; |
| 343 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 344 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 345 | ASSERT_TRUE((out_frame_.samples_per_channel_ == kBlockSize8kHz) || |
| 346 | (out_frame_.samples_per_channel_ == kBlockSize16kHz) || |
| 347 | (out_frame_.samples_per_channel_ == kBlockSize32kHz) || |
| 348 | (out_frame_.samples_per_channel_ == kBlockSize48kHz)); |
| 349 | output_sample_rate_ = out_frame_.sample_rate_hz_; |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 350 | EXPECT_EQ(output_sample_rate_, neteq_->last_output_sample_rate_hz()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 351 | |
| 352 | // Increase time. |
| 353 | sim_clock_ += kTimeStepMs; |
| 354 | } |
| 355 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 356 | void NetEqDecodingTest::DecodeAndCompare( |
| 357 | const std::string& rtp_file, |
| 358 | const std::string& output_checksum, |
| 359 | const std::string& network_stats_checksum, |
| 360 | const std::string& rtcp_stats_checksum, |
| 361 | bool gen_ref) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 362 | OpenInputFile(rtp_file); |
| 363 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 364 | std::string ref_out_file = |
| 365 | gen_ref ? webrtc::test::OutputPath() + "neteq_universal_ref.pcm" : ""; |
| 366 | ResultSink output(ref_out_file); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 367 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 368 | std::string stat_out_file = |
| 369 | gen_ref ? webrtc::test::OutputPath() + "neteq_network_stats.dat" : ""; |
| 370 | ResultSink network_stats(stat_out_file); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 371 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 372 | std::string rtcp_out_file = |
| 373 | gen_ref ? webrtc::test::OutputPath() + "neteq_rtcp_stats.dat" : ""; |
| 374 | ResultSink rtcp_stats(rtcp_out_file); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 375 | |
henrik.lundin | 46ba49c | 2016-05-24 22:50:47 -0700 | [diff] [blame] | 376 | packet_ = rtp_source_->NextPacket(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 377 | int i = 0; |
Henrik Lundin | ac0a503 | 2017-09-25 12:22:46 +0200 | [diff] [blame] | 378 | uint64_t last_concealed_samples = 0; |
| 379 | uint64_t last_total_samples_received = 0; |
henrik.lundin@webrtc.org | 966a708 | 2014-11-17 09:08:38 +0000 | [diff] [blame] | 380 | while (packet_) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 381 | std::ostringstream ss; |
| 382 | ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; |
| 383 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 384 | ASSERT_NO_FATAL_FAILURE(Process()); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 385 | ASSERT_NO_FATAL_FAILURE(output.AddResult( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 386 | out_frame_.data(), out_frame_.samples_per_channel_)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 387 | |
| 388 | // Query the network statistics API once per second |
| 389 | if (sim_clock_ % 1000 == 0) { |
| 390 | // Process NetworkStatistics. |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 391 | NetEqNetworkStatistics current_network_stats; |
| 392 | ASSERT_EQ(0, neteq_->NetworkStatistics(¤t_network_stats)); |
| 393 | ASSERT_NO_FATAL_FAILURE(network_stats.AddResult(current_network_stats)); |
| 394 | |
henrik.lundin | 9c3efd0 | 2015-08-27 13:12:22 -0700 | [diff] [blame] | 395 | // Compare with CurrentDelay, which should be identical. |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 396 | EXPECT_EQ(current_network_stats.current_buffer_size_ms, |
| 397 | neteq_->CurrentDelayMs()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 398 | |
Henrik Lundin | ac0a503 | 2017-09-25 12:22:46 +0200 | [diff] [blame] | 399 | // Verify that liftime stats and network stats report similar loss |
| 400 | // concealment rates. |
| 401 | auto lifetime_stats = neteq_->GetLifetimeStatistics(); |
| 402 | const uint64_t delta_concealed_samples = |
| 403 | lifetime_stats.concealed_samples - last_concealed_samples; |
| 404 | last_concealed_samples = lifetime_stats.concealed_samples; |
| 405 | const uint64_t delta_total_samples_received = |
| 406 | lifetime_stats.total_samples_received - last_total_samples_received; |
| 407 | last_total_samples_received = lifetime_stats.total_samples_received; |
| 408 | // The tolerance is 1% but expressed in Q14. |
| 409 | EXPECT_NEAR( |
| 410 | (delta_concealed_samples << 14) / delta_total_samples_received, |
| 411 | current_network_stats.expand_rate, (2 << 14) / 100.0); |
| 412 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 413 | // Process RTCPstat. |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 414 | RtcpStatistics current_rtcp_stats; |
| 415 | neteq_->GetRtcpStatistics(¤t_rtcp_stats); |
| 416 | ASSERT_NO_FATAL_FAILURE(rtcp_stats.AddResult(current_rtcp_stats)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 417 | } |
| 418 | } |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 419 | |
| 420 | SCOPED_TRACE("Check output audio."); |
| 421 | output.VerifyChecksum(output_checksum); |
| 422 | SCOPED_TRACE("Check network stats."); |
| 423 | network_stats.VerifyChecksum(network_stats_checksum); |
| 424 | SCOPED_TRACE("Check rtcp stats."); |
| 425 | rtcp_stats.VerifyChecksum(rtcp_stats_checksum); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void NetEqDecodingTest::PopulateRtpInfo(int frame_index, |
| 429 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 430 | RTPHeader* rtp_info) { |
| 431 | rtp_info->sequenceNumber = frame_index; |
| 432 | rtp_info->timestamp = timestamp; |
| 433 | rtp_info->ssrc = 0x1234; // Just an arbitrary SSRC. |
| 434 | rtp_info->payloadType = 94; // PCM16b WB codec. |
| 435 | rtp_info->markerBit = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void NetEqDecodingTest::PopulateCng(int frame_index, |
| 439 | int timestamp, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 440 | RTPHeader* rtp_info, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 441 | uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 442 | size_t* payload_len) { |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 443 | rtp_info->sequenceNumber = frame_index; |
| 444 | rtp_info->timestamp = timestamp; |
| 445 | rtp_info->ssrc = 0x1234; // Just an arbitrary SSRC. |
| 446 | rtp_info->payloadType = 98; // WB CNG. |
| 447 | rtp_info->markerBit = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 448 | payload[0] = 64; // Noise level -64 dBov, quite arbitrarily chosen. |
| 449 | *payload_len = 1; // Only noise level, no spectral parameters. |
| 450 | } |
| 451 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 452 | #if !defined(WEBRTC_IOS) && defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
| 453 | (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ |
Karl Wiberg | eb254b4 | 2017-11-01 15:08:12 +0100 | [diff] [blame] | 454 | defined(WEBRTC_CODEC_ILBC) && !defined(WEBRTC_ARCH_ARM64) |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 455 | #define MAYBE_TestBitExactness TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 456 | #else |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 457 | #define MAYBE_TestBitExactness DISABLED_TestBitExactness |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 458 | #endif |
minyue | 5f026d0 | 2015-12-16 07:36:04 -0800 | [diff] [blame] | 459 | TEST_F(NetEqDecodingTest, MAYBE_TestBitExactness) { |
minyue | 49c454e | 2016-01-08 11:30:14 -0800 | [diff] [blame] | 460 | const std::string input_rtp_file = |
| 461 | webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"); |
henrik.lundin@webrtc.org | 4e4b098 | 2014-08-11 14:48:49 +0000 | [diff] [blame] | 462 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 463 | const std::string output_checksum = PlatformChecksum( |
soren | 9f2c18e | 2017-04-10 02:22:46 -0700 | [diff] [blame] | 464 | "09fa7646e2ad032a0b156177b95f09012430f81f", |
| 465 | "1c64eb8b55ce8878676c6a1e6ddd78f48de0668b", |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 466 | "not used", |
soren | 9f2c18e | 2017-04-10 02:22:46 -0700 | [diff] [blame] | 467 | "09fa7646e2ad032a0b156177b95f09012430f81f", |
| 468 | "759fef89a5de52bd17e733dc255c671ce86be909"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 469 | |
henrik.lundin | 2979f55 | 2017-05-05 05:04:16 -0700 | [diff] [blame] | 470 | const std::string network_stats_checksum = |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 471 | PlatformChecksum("5b4262ca328e5f066af5d34f3380521583dd20de", |
| 472 | "80235b6d727281203acb63b98f9a9e85d95f7ec0", |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 473 | "not used", |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 474 | "5b4262ca328e5f066af5d34f3380521583dd20de", |
| 475 | "5b4262ca328e5f066af5d34f3380521583dd20de"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 476 | |
| 477 | const std::string rtcp_stats_checksum = PlatformChecksum( |
| 478 | "b8880bf9fed2487efbddcb8d94b9937a29ae521d", |
| 479 | "f3f7b3d3e71d7e635240b5373b57df6a7e4ce9d4", |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 480 | "not used", |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 481 | "b8880bf9fed2487efbddcb8d94b9937a29ae521d", |
| 482 | "b8880bf9fed2487efbddcb8d94b9937a29ae521d"); |
| 483 | |
| 484 | DecodeAndCompare(input_rtp_file, |
| 485 | output_checksum, |
| 486 | network_stats_checksum, |
| 487 | rtcp_stats_checksum, |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 488 | FLAG_gen_ref); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 491 | #if !defined(WEBRTC_IOS) && \ |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 492 | defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
minyue-webrtc | 516711c | 2017-07-27 17:45:49 +0200 | [diff] [blame] | 493 | defined(WEBRTC_CODEC_OPUS) |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 494 | #define MAYBE_TestOpusBitExactness TestOpusBitExactness |
| 495 | #else |
| 496 | #define MAYBE_TestOpusBitExactness DISABLED_TestOpusBitExactness |
| 497 | #endif |
minyue-webrtc | adb58b8 | 2017-07-26 17:59:59 +0200 | [diff] [blame] | 498 | TEST_F(NetEqDecodingTest, MAYBE_TestOpusBitExactness) { |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 499 | const std::string input_rtp_file = |
| 500 | webrtc::test::ResourcePath("audio_coding/neteq_opus", "rtp"); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 501 | |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 502 | const std::string output_checksum = PlatformChecksum( |
Ivo Creusen | fd7c0a5 | 2017-10-20 12:35:04 +0200 | [diff] [blame] | 503 | "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48", |
| 504 | "5b1e691ab1c4465c742d6d944bc71e3b1c0e4c0e", |
| 505 | "b096114dd8c233eaf2b0ce9802ac95af13933772", |
| 506 | "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48", |
| 507 | "7ea28d7edf9395f4ac8e8d8dd3a9e5c620b1bf48"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 508 | |
henrik.lundin | 2979f55 | 2017-05-05 05:04:16 -0700 | [diff] [blame] | 509 | const std::string network_stats_checksum = |
Ivo Creusen | fd7c0a5 | 2017-10-20 12:35:04 +0200 | [diff] [blame] | 510 | PlatformChecksum("9e72233c78baf685e500dd6c94212b30a4c5f27d", |
| 511 | "9a37270e4242fbd31e80bb47dc5e7ab82cf2d557", |
| 512 | "4f1e9734bc80a290faaf9d611efcb8d7802dbc4f", |
| 513 | "9e72233c78baf685e500dd6c94212b30a4c5f27d", |
| 514 | "9e72233c78baf685e500dd6c94212b30a4c5f27d"); |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 515 | |
| 516 | const std::string rtcp_stats_checksum = PlatformChecksum( |
| 517 | "e37c797e3de6a64dda88c9ade7a013d022a2e1e0", |
| 518 | "e37c797e3de6a64dda88c9ade7a013d022a2e1e0", |
| 519 | "e37c797e3de6a64dda88c9ade7a013d022a2e1e0", |
Henrik Lundin | 8cd750d | 2017-10-12 13:07:11 +0200 | [diff] [blame] | 520 | "e37c797e3de6a64dda88c9ade7a013d022a2e1e0", |
minyue | 4f90677 | 2016-04-29 11:05:14 -0700 | [diff] [blame] | 521 | "e37c797e3de6a64dda88c9ade7a013d022a2e1e0"); |
| 522 | |
| 523 | DecodeAndCompare(input_rtp_file, |
| 524 | output_checksum, |
| 525 | network_stats_checksum, |
| 526 | rtcp_stats_checksum, |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 527 | FLAG_gen_ref); |
minyue | 93c08b7 | 2015-12-22 09:57:41 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Henrik Lundin | e9619f8 | 2017-11-27 14:05:27 +0100 | [diff] [blame] | 530 | // This test fixture is identical to NetEqDecodingTest, except that it enables |
| 531 | // the WebRTC-NetEqOpusDtxDelayFix field trial. |
| 532 | // TODO(bugs.webrtc.org/8488): When the field trial is over and the feature is |
| 533 | // default enabled, remove this fixture class and let the |
| 534 | // TestOpusDtxBitExactness test build directly on NetEqDecodingTest. |
| 535 | class NetEqDecodingTestWithOpusDtxFieldTrial : public NetEqDecodingTest { |
| 536 | public: |
| 537 | NetEqDecodingTestWithOpusDtxFieldTrial() |
| 538 | : override_field_trials_("WebRTC-NetEqOpusDtxDelayFix/Enabled/") {} |
| 539 | |
| 540 | private: |
| 541 | test::ScopedFieldTrials override_field_trials_; |
| 542 | }; |
| 543 | |
| 544 | #if !defined(WEBRTC_IOS) && \ |
| 545 | defined(WEBRTC_NETEQ_UNITTEST_BITEXACT) && \ |
| 546 | defined(WEBRTC_CODEC_OPUS) |
| 547 | #define MAYBE_TestOpusDtxBitExactness TestOpusDtxBitExactness |
| 548 | #else |
| 549 | #define MAYBE_TestOpusDtxBitExactness DISABLED_TestOpusDtxBitExactness |
| 550 | #endif |
| 551 | TEST_F(NetEqDecodingTestWithOpusDtxFieldTrial, MAYBE_TestOpusDtxBitExactness) { |
| 552 | const std::string input_rtp_file = |
| 553 | webrtc::test::ResourcePath("audio_coding/neteq_opus_dtx", "rtp"); |
| 554 | |
| 555 | const std::string output_checksum = |
| 556 | PlatformChecksum("713af6c92881f5aab1285765ee6680da9d1c06ce", |
| 557 | "3ec991b96872123f1554c03c543ca5d518431e46", |
| 558 | "da9f9a2d94e0c2d67342fad4965d7b91cda50b25", |
| 559 | "713af6c92881f5aab1285765ee6680da9d1c06ce", |
| 560 | "713af6c92881f5aab1285765ee6680da9d1c06ce"); |
| 561 | |
| 562 | const std::string network_stats_checksum = |
| 563 | "bab58dc587d956f326056d7340c96eb9d2d3cc21"; |
| 564 | |
| 565 | const std::string rtcp_stats_checksum = |
| 566 | "ac27a7f305efb58b39bf123dccee25dee5758e63"; |
| 567 | |
| 568 | DecodeAndCompare(input_rtp_file, output_checksum, network_stats_checksum, |
| 569 | rtcp_stats_checksum, FLAG_gen_ref); |
| 570 | } |
| 571 | |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 572 | // Use fax mode to avoid time-scaling. This is to simplify the testing of |
| 573 | // packet waiting times in the packet buffer. |
| 574 | class NetEqDecodingTestFaxMode : public NetEqDecodingTest { |
| 575 | protected: |
| 576 | NetEqDecodingTestFaxMode() : NetEqDecodingTest() { |
| 577 | config_.playout_mode = kPlayoutFax; |
| 578 | } |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 579 | void TestJitterBufferDelay(bool apply_packet_loss); |
henrik.lundin@webrtc.org | 7cbc4f9 | 2014-10-07 06:37:39 +0000 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 583 | // Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio. |
| 584 | size_t num_frames = 30; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 585 | const size_t kSamples = 10 * 16; |
| 586 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 587 | for (size_t i = 0; i < num_frames; ++i) { |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 588 | const uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 589 | RTPHeader rtp_info; |
Mirko Bonadei | a811027 | 2017-10-18 14:22:50 +0200 | [diff] [blame] | 590 | rtp_info.sequenceNumber = rtc::checked_cast<uint16_t>(i); |
| 591 | rtp_info.timestamp = rtc::checked_cast<uint32_t>(i * kSamples); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 592 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 593 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 594 | rtp_info.markerBit = 0; |
| 595 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 596 | } |
| 597 | // Pull out all data. |
| 598 | for (size_t i = 0; i < num_frames; ++i) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 599 | bool muted; |
| 600 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 601 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 604 | NetEqNetworkStatistics stats; |
| 605 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 606 | // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms |
| 607 | // spacing (per definition), we expect the delay to increase with 10 ms for |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 608 | // each packet. Thus, we are calculating the statistics for a series from 10 |
| 609 | // to 300, in steps of 10 ms. |
| 610 | EXPECT_EQ(155, stats.mean_waiting_time_ms); |
| 611 | EXPECT_EQ(155, stats.median_waiting_time_ms); |
| 612 | EXPECT_EQ(10, stats.min_waiting_time_ms); |
| 613 | EXPECT_EQ(300, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 614 | |
| 615 | // Check statistics again and make sure it's been reset. |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 616 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 617 | EXPECT_EQ(-1, stats.mean_waiting_time_ms); |
| 618 | EXPECT_EQ(-1, stats.median_waiting_time_ms); |
| 619 | EXPECT_EQ(-1, stats.min_waiting_time_ms); |
| 620 | EXPECT_EQ(-1, stats.max_waiting_time_ms); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 621 | } |
| 622 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 623 | TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 624 | const int kNumFrames = 3000; // Needed for convergence. |
| 625 | int frame_index = 0; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 626 | const size_t kSamples = 10 * 16; |
| 627 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 628 | while (frame_index < kNumFrames) { |
| 629 | // Insert one packet each time, except every 10th time where we insert two |
| 630 | // packets at once. This will create a negative clock-drift of approx. 10%. |
| 631 | int num_packets = (frame_index % 10 == 0 ? 2 : 1); |
| 632 | for (int n = 0; n < num_packets; ++n) { |
| 633 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 634 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 635 | PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 636 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 637 | ++frame_index; |
| 638 | } |
| 639 | |
| 640 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 641 | bool muted; |
| 642 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 643 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | NetEqNetworkStatistics network_stats; |
| 647 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
henrik.lundin | 0d83857 | 2016-10-13 03:35:55 -0700 | [diff] [blame] | 648 | EXPECT_EQ(-103192, network_stats.clockdrift_ppm); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 649 | } |
| 650 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 651 | TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimePositive) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 652 | const int kNumFrames = 5000; // Needed for convergence. |
| 653 | int frame_index = 0; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 654 | const size_t kSamples = 10 * 16; |
| 655 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 656 | for (int i = 0; i < kNumFrames; ++i) { |
| 657 | // Insert one packet each time, except every 10th time where we don't insert |
| 658 | // any packet. This will create a positive clock-drift of approx. 11%. |
| 659 | int num_packets = (i % 10 == 9 ? 0 : 1); |
| 660 | for (int n = 0; n < num_packets; ++n) { |
| 661 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 662 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 663 | PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 664 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 665 | ++frame_index; |
| 666 | } |
| 667 | |
| 668 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 669 | bool muted; |
| 670 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 671 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | NetEqNetworkStatistics network_stats; |
| 675 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
henrik.lundin | 0d83857 | 2016-10-13 03:35:55 -0700 | [diff] [blame] | 676 | EXPECT_EQ(110953, network_stats.clockdrift_ppm); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 677 | } |
| 678 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 679 | void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor, |
| 680 | double network_freeze_ms, |
| 681 | bool pull_audio_during_freeze, |
| 682 | int delay_tolerance_ms, |
| 683 | int max_time_to_speech_ms) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 684 | uint16_t seq_no = 0; |
| 685 | uint32_t timestamp = 0; |
| 686 | const int kFrameSizeMs = 30; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 687 | const size_t kSamples = kFrameSizeMs * 16; |
| 688 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 689 | double next_input_time_ms = 0.0; |
| 690 | double t_ms; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 691 | bool muted; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 692 | |
| 693 | // Insert speech for 5 seconds. |
| 694 | const int kSpeechDurationMs = 5000; |
| 695 | for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 696 | // Each turn in this for loop is 10 ms. |
| 697 | while (next_input_time_ms <= t_ms) { |
| 698 | // Insert one 30 ms speech frame. |
| 699 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 700 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 701 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 702 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 703 | ++seq_no; |
| 704 | timestamp += kSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 705 | next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 706 | } |
| 707 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 708 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 709 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 710 | } |
| 711 | |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 712 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 713 | rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 714 | ASSERT_TRUE(playout_timestamp); |
| 715 | int32_t delay_before = timestamp - *playout_timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 716 | |
| 717 | // Insert CNG for 1 minute (= 60000 ms). |
| 718 | const int kCngPeriodMs = 100; |
| 719 | const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples. |
| 720 | const int kCngDurationMs = 60000; |
| 721 | for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) { |
| 722 | // Each turn in this for loop is 10 ms. |
| 723 | while (next_input_time_ms <= t_ms) { |
| 724 | // Insert one CNG frame each 100 ms. |
| 725 | uint8_t payload[kPayloadBytes]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 726 | size_t payload_len; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 727 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 728 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 729 | ASSERT_EQ(0, neteq_->InsertPacket( |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 730 | rtp_info, |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 731 | rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 732 | ++seq_no; |
| 733 | timestamp += kCngPeriodSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 734 | next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 735 | } |
| 736 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 737 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 738 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 739 | } |
| 740 | |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 741 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 742 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 743 | if (network_freeze_ms > 0) { |
| 744 | // First keep pulling audio for |network_freeze_ms| without inserting |
| 745 | // any data, then insert CNG data corresponding to |network_freeze_ms| |
| 746 | // without pulling any output audio. |
| 747 | const double loop_end_time = t_ms + network_freeze_ms; |
| 748 | for (; t_ms < loop_end_time; t_ms += 10) { |
| 749 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 750 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 751 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 752 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 753 | } |
| 754 | bool pull_once = pull_audio_during_freeze; |
| 755 | // If |pull_once| is true, GetAudio will be called once half-way through |
| 756 | // the network recovery period. |
| 757 | double pull_time_ms = (t_ms + next_input_time_ms) / 2; |
| 758 | while (next_input_time_ms <= t_ms) { |
| 759 | if (pull_once && next_input_time_ms >= pull_time_ms) { |
| 760 | pull_once = false; |
| 761 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 762 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 763 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 764 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 765 | t_ms += 10; |
| 766 | } |
| 767 | // Insert one CNG frame each 100 ms. |
| 768 | uint8_t payload[kPayloadBytes]; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 769 | size_t payload_len; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 770 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 771 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 772 | ASSERT_EQ(0, neteq_->InsertPacket( |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 773 | rtp_info, |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 774 | rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 775 | ++seq_no; |
| 776 | timestamp += kCngPeriodSamples; |
| 777 | next_input_time_ms += kCngPeriodMs * drift_factor; |
| 778 | } |
| 779 | } |
| 780 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 781 | // Insert speech again until output type is speech. |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 782 | double speech_restart_time_ms = t_ms; |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 783 | while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 784 | // Each turn in this for loop is 10 ms. |
| 785 | while (next_input_time_ms <= t_ms) { |
| 786 | // Insert one 30 ms speech frame. |
| 787 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 788 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 789 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 790 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 791 | ++seq_no; |
| 792 | timestamp += kSamples; |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 793 | next_input_time_ms += kFrameSizeMs * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 794 | } |
| 795 | // Pull out data once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 796 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 797 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 798 | // Increase clock. |
| 799 | t_ms += 10; |
| 800 | } |
| 801 | |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 802 | // Check that the speech starts again within reasonable time. |
| 803 | double time_until_speech_returns_ms = t_ms - speech_restart_time_ms; |
| 804 | EXPECT_LT(time_until_speech_returns_ms, max_time_to_speech_ms); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 805 | playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 806 | ASSERT_TRUE(playout_timestamp); |
| 807 | int32_t delay_after = timestamp - *playout_timestamp; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 808 | // Compare delay before and after, and make sure it differs less than 20 ms. |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 809 | EXPECT_LE(delay_after, delay_before + delay_tolerance_ms * 16); |
| 810 | EXPECT_GE(delay_after, delay_before - delay_tolerance_ms * 16); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 811 | } |
| 812 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 813 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 814 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 815 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 816 | const double kNetworkFreezeTimeMs = 0.0; |
| 817 | const bool kGetAudioDuringFreezeRecovery = false; |
| 818 | const int kDelayToleranceMs = 20; |
| 819 | const int kMaxTimeToSpeechMs = 100; |
| 820 | LongCngWithClockDrift(kDriftFactor, |
| 821 | kNetworkFreezeTimeMs, |
| 822 | kGetAudioDuringFreezeRecovery, |
| 823 | kDelayToleranceMs, |
| 824 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 825 | } |
| 826 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 827 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDrift) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 828 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 829 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 830 | const double kNetworkFreezeTimeMs = 0.0; |
| 831 | const bool kGetAudioDuringFreezeRecovery = false; |
| 832 | const int kDelayToleranceMs = 20; |
| 833 | const int kMaxTimeToSpeechMs = 100; |
| 834 | LongCngWithClockDrift(kDriftFactor, |
| 835 | kNetworkFreezeTimeMs, |
| 836 | kGetAudioDuringFreezeRecovery, |
| 837 | kDelayToleranceMs, |
| 838 | kMaxTimeToSpeechMs); |
| 839 | } |
| 840 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 841 | TEST_F(NetEqDecodingTest, LongCngWithNegativeClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 842 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 843 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
| 844 | const double kNetworkFreezeTimeMs = 5000.0; |
| 845 | const bool kGetAudioDuringFreezeRecovery = false; |
| 846 | const int kDelayToleranceMs = 50; |
| 847 | const int kMaxTimeToSpeechMs = 200; |
| 848 | LongCngWithClockDrift(kDriftFactor, |
| 849 | kNetworkFreezeTimeMs, |
| 850 | kGetAudioDuringFreezeRecovery, |
| 851 | kDelayToleranceMs, |
| 852 | kMaxTimeToSpeechMs); |
| 853 | } |
| 854 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 855 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreeze) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 856 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 857 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 858 | const double kNetworkFreezeTimeMs = 5000.0; |
| 859 | const bool kGetAudioDuringFreezeRecovery = false; |
| 860 | const int kDelayToleranceMs = 20; |
| 861 | const int kMaxTimeToSpeechMs = 100; |
| 862 | LongCngWithClockDrift(kDriftFactor, |
| 863 | kNetworkFreezeTimeMs, |
| 864 | kGetAudioDuringFreezeRecovery, |
| 865 | kDelayToleranceMs, |
| 866 | kMaxTimeToSpeechMs); |
| 867 | } |
| 868 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 869 | TEST_F(NetEqDecodingTest, LongCngWithPositiveClockDriftNetworkFreezeExtraPull) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 870 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 871 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 872 | const double kNetworkFreezeTimeMs = 5000.0; |
| 873 | const bool kGetAudioDuringFreezeRecovery = true; |
| 874 | const int kDelayToleranceMs = 20; |
| 875 | const int kMaxTimeToSpeechMs = 100; |
| 876 | LongCngWithClockDrift(kDriftFactor, |
| 877 | kNetworkFreezeTimeMs, |
| 878 | kGetAudioDuringFreezeRecovery, |
| 879 | kDelayToleranceMs, |
| 880 | kMaxTimeToSpeechMs); |
| 881 | } |
| 882 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 883 | TEST_F(NetEqDecodingTest, LongCngWithoutClockDrift) { |
henrik.lundin@webrtc.org | 24779fe | 2014-03-14 12:40:05 +0000 | [diff] [blame] | 884 | const double kDriftFactor = 1.0; // No drift. |
| 885 | const double kNetworkFreezeTimeMs = 0.0; |
| 886 | const bool kGetAudioDuringFreezeRecovery = false; |
| 887 | const int kDelayToleranceMs = 10; |
| 888 | const int kMaxTimeToSpeechMs = 50; |
| 889 | LongCngWithClockDrift(kDriftFactor, |
| 890 | kNetworkFreezeTimeMs, |
| 891 | kGetAudioDuringFreezeRecovery, |
| 892 | kDelayToleranceMs, |
| 893 | kMaxTimeToSpeechMs); |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 894 | } |
| 895 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 896 | TEST_F(NetEqDecodingTest, UnknownPayloadType) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 897 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 898 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 899 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 900 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 901 | rtp_info.payloadType = 1; // Not registered as a decoder. |
| 902 | EXPECT_EQ(NetEq::kFail, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 905 | #if defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX) |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 906 | #define MAYBE_DecoderError DecoderError |
| 907 | #else |
| 908 | #define MAYBE_DecoderError DISABLED_DecoderError |
| 909 | #endif |
| 910 | |
Peter Boström | e2976c8 | 2016-01-04 22:44:05 +0100 | [diff] [blame] | 911 | TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 912 | const size_t kPayloadBytes = 100; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 913 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 914 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 915 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 916 | rtp_info.payloadType = 103; // iSAC, but the payload is invalid. |
| 917 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 918 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 919 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 920 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 921 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 922 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 923 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 924 | bool muted; |
| 925 | EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted)); |
| 926 | ASSERT_FALSE(muted); |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 927 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 928 | // Verify that the first 160 samples are set to 0. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 929 | static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 930 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 931 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
| 932 | std::ostringstream ss; |
| 933 | ss << "i = " << i; |
| 934 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 935 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
henrik.lundin@webrtc.org | b4e80e0 | 2014-05-15 07:14:00 +0000 | [diff] [blame] | 939 | TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 940 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 941 | // to GetAudio. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 942 | int16_t* out_frame_data = out_frame_.mutable_data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 943 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 944 | out_frame_data[i] = 1; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 945 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 946 | bool muted; |
| 947 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 948 | ASSERT_FALSE(muted); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 949 | // Verify that the first block of samples is set to 0. |
| 950 | static const int kExpectedOutputLength = |
| 951 | kInitSampleRateHz / 100; // 10 ms at initial sample rate. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 952 | const int16_t* const_out_frame_data = out_frame_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 953 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
| 954 | std::ostringstream ss; |
| 955 | ss << "i = " << i; |
| 956 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 957 | EXPECT_EQ(0, const_out_frame_data[i]); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 958 | } |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 959 | // Verify that the sample rate did not change from the initial configuration. |
| 960 | EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz()); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 961 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 962 | |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 963 | class NetEqBgnTest : public NetEqDecodingTest { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 964 | protected: |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 965 | virtual void TestCondition(double sum_squared_noise, |
| 966 | bool should_be_faded) = 0; |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 967 | |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 968 | void CheckBgn(int sampling_rate_hz) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 969 | size_t expected_samples_per_channel = 0; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 970 | uint8_t payload_type = 0xFF; // Invalid. |
| 971 | if (sampling_rate_hz == 8000) { |
| 972 | expected_samples_per_channel = kBlockSize8kHz; |
| 973 | payload_type = 93; // PCM 16, 8 kHz. |
| 974 | } else if (sampling_rate_hz == 16000) { |
| 975 | expected_samples_per_channel = kBlockSize16kHz; |
| 976 | payload_type = 94; // PCM 16, 16 kHZ. |
| 977 | } else if (sampling_rate_hz == 32000) { |
| 978 | expected_samples_per_channel = kBlockSize32kHz; |
| 979 | payload_type = 95; // PCM 16, 32 kHz. |
| 980 | } else { |
| 981 | ASSERT_TRUE(false); // Unsupported test case. |
| 982 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 983 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 984 | AudioFrame output; |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 985 | test::AudioLoop input; |
| 986 | // We are using the same 32 kHz input file for all tests, regardless of |
| 987 | // |sampling_rate_hz|. The output may sound weird, but the test is still |
| 988 | // valid. |
| 989 | ASSERT_TRUE(input.Init( |
| 990 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), |
| 991 | 10 * sampling_rate_hz, // Max 10 seconds loop length. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 992 | expected_samples_per_channel)); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 993 | |
| 994 | // Payload of 10 ms of PCM16 32 kHz. |
| 995 | uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 996 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 997 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 998 | rtp_info.payloadType = payload_type; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 999 | |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1000 | uint32_t receive_timestamp = 0; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1001 | bool muted; |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1002 | for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. |
kwiberg | 288886b | 2015-11-06 01:21:35 -0800 | [diff] [blame] | 1003 | auto block = input.GetNextBlock(); |
| 1004 | ASSERT_EQ(expected_samples_per_channel, block.size()); |
| 1005 | size_t enc_len_bytes = |
| 1006 | WebRtcPcm16b_Encode(block.data(), block.size(), payload); |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1007 | ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); |
| 1008 | |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 1009 | ASSERT_EQ(0, neteq_->InsertPacket( |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1010 | rtp_info, |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 1011 | rtc::ArrayView<const uint8_t>(payload, enc_len_bytes), |
| 1012 | receive_timestamp)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1013 | output.Reset(); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1014 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1015 | ASSERT_EQ(1u, output.num_channels_); |
| 1016 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1017 | ASSERT_EQ(AudioFrame::kNormalSpeech, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1018 | |
| 1019 | // Next packet. |
Mirko Bonadei | a811027 | 2017-10-18 14:22:50 +0200 | [diff] [blame] | 1020 | rtp_info.timestamp += rtc::checked_cast<uint32_t>( |
| 1021 | expected_samples_per_channel); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1022 | rtp_info.sequenceNumber++; |
Mirko Bonadei | a811027 | 2017-10-18 14:22:50 +0200 | [diff] [blame] | 1023 | receive_timestamp += rtc::checked_cast<uint32_t>( |
| 1024 | expected_samples_per_channel); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1027 | output.Reset(); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1028 | |
| 1029 | // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull |
| 1030 | // one frame without checking speech-type. This is the first frame pulled |
| 1031 | // without inserting any packet, and might not be labeled as PLC. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1032 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1033 | ASSERT_EQ(1u, output.num_channels_); |
| 1034 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1035 | |
| 1036 | // To be able to test the fading of background noise we need at lease to |
| 1037 | // pull 611 frames. |
| 1038 | const int kFadingThreshold = 611; |
| 1039 | |
| 1040 | // Test several CNG-to-PLC packet for the expected behavior. The number 20 |
| 1041 | // is arbitrary, but sufficiently large to test enough number of frames. |
| 1042 | const int kNumPlcToCngTestFrames = 20; |
| 1043 | bool plc_to_cng = false; |
| 1044 | for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1045 | output.Reset(); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1046 | // Set to non-zero. |
| 1047 | memset(output.mutable_data(), 1, AudioFrame::kMaxDataSizeBytes); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1048 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1049 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1050 | ASSERT_EQ(1u, output.num_channels_); |
| 1051 | ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1052 | if (output.speech_type_ == AudioFrame::kPLCCNG) { |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1053 | plc_to_cng = true; |
| 1054 | double sum_squared = 0; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1055 | const int16_t* output_data = output.data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1056 | for (size_t k = 0; |
| 1057 | k < output.num_channels_ * output.samples_per_channel_; ++k) |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1058 | sum_squared += output_data[k] * output_data[k]; |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1059 | TestCondition(sum_squared, n > kFadingThreshold); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1060 | } else { |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1061 | EXPECT_EQ(AudioFrame::kPLC, output.speech_type_); |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. |
| 1065 | } |
| 1066 | }; |
| 1067 | |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1068 | class NetEqBgnTestOn : public NetEqBgnTest { |
| 1069 | protected: |
| 1070 | NetEqBgnTestOn() : NetEqBgnTest() { |
| 1071 | config_.background_noise_mode = NetEq::kBgnOn; |
| 1072 | } |
| 1073 | |
| 1074 | void TestCondition(double sum_squared_noise, bool /*should_be_faded*/) { |
| 1075 | EXPECT_NE(0, sum_squared_noise); |
| 1076 | } |
| 1077 | }; |
| 1078 | |
| 1079 | class NetEqBgnTestOff : public NetEqBgnTest { |
| 1080 | protected: |
| 1081 | NetEqBgnTestOff() : NetEqBgnTest() { |
| 1082 | config_.background_noise_mode = NetEq::kBgnOff; |
| 1083 | } |
| 1084 | |
| 1085 | void TestCondition(double sum_squared_noise, bool /*should_be_faded*/) { |
| 1086 | EXPECT_EQ(0, sum_squared_noise); |
| 1087 | } |
| 1088 | }; |
| 1089 | |
| 1090 | class NetEqBgnTestFade : public NetEqBgnTest { |
| 1091 | protected: |
| 1092 | NetEqBgnTestFade() : NetEqBgnTest() { |
| 1093 | config_.background_noise_mode = NetEq::kBgnFade; |
| 1094 | } |
| 1095 | |
| 1096 | void TestCondition(double sum_squared_noise, bool should_be_faded) { |
| 1097 | if (should_be_faded) |
| 1098 | EXPECT_EQ(0, sum_squared_noise); |
| 1099 | } |
| 1100 | }; |
| 1101 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 1102 | TEST_F(NetEqBgnTestOn, RunTest) { |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1103 | CheckBgn(8000); |
| 1104 | CheckBgn(16000); |
| 1105 | CheckBgn(32000); |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 1106 | } |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 1107 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 1108 | TEST_F(NetEqBgnTestOff, RunTest) { |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1109 | CheckBgn(8000); |
| 1110 | CheckBgn(16000); |
| 1111 | CheckBgn(32000); |
| 1112 | } |
| 1113 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 1114 | TEST_F(NetEqBgnTestFade, RunTest) { |
henrik.lundin@webrtc.org | 9b8102c | 2014-08-21 08:27:44 +0000 | [diff] [blame] | 1115 | CheckBgn(8000); |
| 1116 | CheckBgn(16000); |
| 1117 | CheckBgn(32000); |
| 1118 | } |
henrik.lundin@webrtc.org | ea25784 | 2014-08-07 12:27:37 +0000 | [diff] [blame] | 1119 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1120 | void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, |
| 1121 | uint32_t start_timestamp, |
| 1122 | const std::set<uint16_t>& drop_seq_numbers, |
| 1123 | bool expect_seq_no_wrap, |
| 1124 | bool expect_timestamp_wrap) { |
| 1125 | uint16_t seq_no = start_seq_no; |
| 1126 | uint32_t timestamp = start_timestamp; |
| 1127 | const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. |
| 1128 | const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; |
| 1129 | const int kSamples = kBlockSize16kHz * kBlocksPerFrame; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1130 | const size_t kPayloadBytes = kSamples * sizeof(int16_t); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1131 | double next_input_time_ms = 0.0; |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1132 | uint32_t receive_timestamp = 0; |
| 1133 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1134 | // Insert speech for 2 seconds. |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1135 | const int kSpeechDurationMs = 2000; |
| 1136 | int packets_inserted = 0; |
| 1137 | uint16_t last_seq_no; |
| 1138 | uint32_t last_timestamp; |
| 1139 | bool timestamp_wrapped = false; |
| 1140 | bool seq_no_wrapped = false; |
| 1141 | for (double t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 1142 | // Each turn in this for loop is 10 ms. |
| 1143 | while (next_input_time_ms <= t_ms) { |
| 1144 | // Insert one 30 ms speech frame. |
| 1145 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1146 | RTPHeader rtp_info; |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1147 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 1148 | if (drop_seq_numbers.find(seq_no) == drop_seq_numbers.end()) { |
| 1149 | // This sequence number was not in the set to drop. Insert it. |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1150 | ASSERT_EQ(0, |
| 1151 | neteq_->InsertPacket(rtp_info, payload, receive_timestamp)); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1152 | ++packets_inserted; |
| 1153 | } |
| 1154 | NetEqNetworkStatistics network_stats; |
| 1155 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 1156 | |
| 1157 | // Due to internal NetEq logic, preferred buffer-size is about 4 times the |
| 1158 | // packet size for first few packets. Therefore we refrain from checking |
| 1159 | // the criteria. |
| 1160 | if (packets_inserted > 4) { |
| 1161 | // Expect preferred and actual buffer size to be no more than 2 frames. |
| 1162 | EXPECT_LE(network_stats.preferred_buffer_size_ms, kFrameSizeMs * 2); |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1163 | EXPECT_LE(network_stats.current_buffer_size_ms, kFrameSizeMs * 2 + |
| 1164 | algorithmic_delay_ms_); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1165 | } |
| 1166 | last_seq_no = seq_no; |
| 1167 | last_timestamp = timestamp; |
| 1168 | |
| 1169 | ++seq_no; |
| 1170 | timestamp += kSamples; |
| 1171 | receive_timestamp += kSamples; |
| 1172 | next_input_time_ms += static_cast<double>(kFrameSizeMs); |
| 1173 | |
| 1174 | seq_no_wrapped |= seq_no < last_seq_no; |
| 1175 | timestamp_wrapped |= timestamp < last_timestamp; |
| 1176 | } |
| 1177 | // Pull out data once. |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1178 | AudioFrame output; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1179 | bool muted; |
| 1180 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1181 | ASSERT_EQ(kBlockSize16kHz, output.samples_per_channel_); |
| 1182 | ASSERT_EQ(1u, output.num_channels_); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1183 | |
| 1184 | // Expect delay (in samples) to be less than 2 packets. |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1185 | rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1186 | ASSERT_TRUE(playout_timestamp); |
| 1187 | EXPECT_LE(timestamp - *playout_timestamp, |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1188 | static_cast<uint32_t>(kSamples * 2)); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1189 | } |
| 1190 | // Make sure we have actually tested wrap-around. |
| 1191 | ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); |
| 1192 | ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); |
| 1193 | } |
| 1194 | |
| 1195 | TEST_F(NetEqDecodingTest, SequenceNumberWrap) { |
| 1196 | // Start with a sequence number that will soon wrap. |
| 1197 | std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. |
| 1198 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1199 | } |
| 1200 | |
| 1201 | TEST_F(NetEqDecodingTest, SequenceNumberWrapAndDrop) { |
| 1202 | // Start with a sequence number that will soon wrap. |
| 1203 | std::set<uint16_t> drop_seq_numbers; |
| 1204 | drop_seq_numbers.insert(0xFFFF); |
| 1205 | drop_seq_numbers.insert(0x0); |
| 1206 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1207 | } |
| 1208 | |
| 1209 | TEST_F(NetEqDecodingTest, TimestampWrap) { |
| 1210 | // Start with a timestamp that will soon wrap. |
| 1211 | std::set<uint16_t> drop_seq_numbers; |
| 1212 | WrapTest(0, 0xFFFFFFFF - 3000, drop_seq_numbers, false, true); |
| 1213 | } |
| 1214 | |
| 1215 | TEST_F(NetEqDecodingTest, TimestampAndSequenceNumberWrap) { |
| 1216 | // Start with a timestamp and a sequence number that will wrap at the same |
| 1217 | // time. |
| 1218 | std::set<uint16_t> drop_seq_numbers; |
| 1219 | WrapTest(0xFFFF - 10, 0xFFFFFFFF - 5000, drop_seq_numbers, true, true); |
| 1220 | } |
| 1221 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1222 | void NetEqDecodingTest::DuplicateCng() { |
| 1223 | uint16_t seq_no = 0; |
| 1224 | uint32_t timestamp = 0; |
| 1225 | const int kFrameSizeMs = 10; |
| 1226 | const int kSampleRateKhz = 16; |
| 1227 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1228 | const size_t kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1229 | |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1230 | const int algorithmic_delay_samples = std::max( |
| 1231 | algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1232 | // Insert three speech packets. Three are needed to get the frame length |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1233 | // correct. |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1234 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1235 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1236 | bool muted; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1237 | for (int i = 0; i < 3; ++i) { |
| 1238 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1239 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1240 | ++seq_no; |
| 1241 | timestamp += kSamples; |
| 1242 | |
| 1243 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1244 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1245 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1246 | } |
| 1247 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1248 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1249 | |
| 1250 | // Insert same CNG packet twice. |
| 1251 | const int kCngPeriodMs = 100; |
| 1252 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1253 | size_t payload_len; |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1254 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
| 1255 | // This is the first time this CNG packet is inserted. |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1256 | ASSERT_EQ( |
| 1257 | 0, neteq_->InsertPacket( |
| 1258 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1259 | |
| 1260 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1261 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1262 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1263 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1264 | EXPECT_FALSE( |
| 1265 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1266 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
| 1267 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1268 | |
| 1269 | // Insert the same CNG packet again. Note that at this point it is old, since |
| 1270 | // we have already decoded the first copy of it. |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1271 | ASSERT_EQ( |
| 1272 | 0, neteq_->InsertPacket( |
| 1273 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1274 | |
| 1275 | // Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since |
| 1276 | // we have already pulled out CNG once. |
| 1277 | for (int cng_time_ms = 10; cng_time_ms < kCngPeriodMs; cng_time_ms += 10) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1278 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1279 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1280 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1281 | EXPECT_FALSE( |
| 1282 | neteq_->GetPlayoutTimestamp()); // Returns empty value during CNG. |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1283 | EXPECT_EQ(timestamp - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1284 | out_frame_.timestamp_ + out_frame_.samples_per_channel_); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | // Insert speech again. |
| 1288 | ++seq_no; |
| 1289 | timestamp += kCngPeriodSamples; |
| 1290 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1291 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1292 | |
| 1293 | // Pull audio once and verify that the output is speech again. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1294 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1295 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1296 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1297 | rtc::Optional<uint32_t> playout_timestamp = neteq_->GetPlayoutTimestamp(); |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1298 | ASSERT_TRUE(playout_timestamp); |
turaj@webrtc.org | 8d1cdaa | 2014-04-11 18:47:55 +0000 | [diff] [blame] | 1299 | EXPECT_EQ(timestamp + kSamples - algorithmic_delay_samples, |
henrik.lundin | 0d96ab7 | 2016-04-06 12:28:26 -0700 | [diff] [blame] | 1300 | *playout_timestamp); |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
henrik.lundin@webrtc.org | ca8cb95 | 2014-03-12 10:26:52 +0000 | [diff] [blame] | 1303 | TEST_F(NetEqDecodingTest, DiscardDuplicateCng) { DuplicateCng(); } |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1304 | |
| 1305 | TEST_F(NetEqDecodingTest, CngFirst) { |
| 1306 | uint16_t seq_no = 0; |
| 1307 | uint32_t timestamp = 0; |
| 1308 | const int kFrameSizeMs = 10; |
| 1309 | const int kSampleRateKhz = 16; |
| 1310 | const int kSamples = kFrameSizeMs * kSampleRateKhz; |
| 1311 | const int kPayloadBytes = kSamples * 2; |
| 1312 | const int kCngPeriodMs = 100; |
| 1313 | const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz; |
| 1314 | size_t payload_len; |
| 1315 | |
| 1316 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1317 | RTPHeader rtp_info; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1318 | |
| 1319 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1320 | ASSERT_EQ( |
| 1321 | NetEq::kOK, |
| 1322 | neteq_->InsertPacket( |
| 1323 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1324 | ++seq_no; |
| 1325 | timestamp += kCngPeriodSamples; |
| 1326 | |
| 1327 | // Pull audio once and make sure CNG is played. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1328 | bool muted; |
| 1329 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1330 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1331 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1332 | |
| 1333 | // Insert some speech packets. |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 1334 | const uint32_t first_speech_timestamp = timestamp; |
| 1335 | int timeout_counter = 0; |
| 1336 | do { |
| 1337 | ASSERT_LT(timeout_counter++, 20) << "Test timed out"; |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1338 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1339 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1340 | ++seq_no; |
| 1341 | timestamp += kSamples; |
| 1342 | |
| 1343 | // Pull audio once. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1344 | ASSERT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 1345 | ASSERT_EQ(kBlockSize16kHz, out_frame_.samples_per_channel_); |
henrik.lundin | 549d80b | 2016-08-25 00:44:24 -0700 | [diff] [blame] | 1346 | } while (!IsNewerTimestamp(out_frame_.timestamp_, first_speech_timestamp)); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1347 | // Verify speech output. |
henrik.lundin | 55480f5 | 2016-03-08 02:37:57 -0800 | [diff] [blame] | 1348 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
henrik.lundin@webrtc.org | c93437e | 2014-12-01 11:42:42 +0000 | [diff] [blame] | 1349 | } |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1350 | |
| 1351 | class NetEqDecodingTestWithMutedState : public NetEqDecodingTest { |
| 1352 | public: |
| 1353 | NetEqDecodingTestWithMutedState() : NetEqDecodingTest() { |
| 1354 | config_.enable_muted_state = true; |
| 1355 | } |
| 1356 | |
| 1357 | protected: |
| 1358 | static constexpr size_t kSamples = 10 * 16; |
| 1359 | static constexpr size_t kPayloadBytes = kSamples * 2; |
| 1360 | |
| 1361 | void InsertPacket(uint32_t rtp_timestamp) { |
| 1362 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1363 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1364 | PopulateRtpInfo(0, rtp_timestamp, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1365 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1368 | void InsertCngPacket(uint32_t rtp_timestamp) { |
| 1369 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1370 | RTPHeader rtp_info; |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1371 | size_t payload_len; |
| 1372 | PopulateCng(0, rtp_timestamp, &rtp_info, payload, &payload_len); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1373 | EXPECT_EQ( |
| 1374 | NetEq::kOK, |
| 1375 | neteq_->InsertPacket( |
| 1376 | rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0)); |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1379 | bool GetAudioReturnMuted() { |
| 1380 | bool muted; |
| 1381 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1382 | return muted; |
| 1383 | } |
| 1384 | |
| 1385 | void GetAudioUntilMuted() { |
| 1386 | while (!GetAudioReturnMuted()) { |
| 1387 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | void GetAudioUntilNormal() { |
| 1392 | bool muted = false; |
| 1393 | while (out_frame_.speech_type_ != AudioFrame::kNormalSpeech) { |
| 1394 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1395 | ASSERT_LT(counter_++, 1000) << "Test timed out"; |
| 1396 | } |
| 1397 | EXPECT_FALSE(muted); |
| 1398 | } |
| 1399 | |
| 1400 | int counter_ = 0; |
| 1401 | }; |
| 1402 | |
| 1403 | // Verifies that NetEq goes in and out of muted state as expected. |
| 1404 | TEST_F(NetEqDecodingTestWithMutedState, MutedState) { |
| 1405 | // Insert one speech packet. |
| 1406 | InsertPacket(0); |
| 1407 | // Pull out audio once and expect it not to be muted. |
| 1408 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1409 | // Pull data until faded out. |
| 1410 | GetAudioUntilMuted(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1411 | EXPECT_TRUE(out_frame_.muted()); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1412 | |
| 1413 | // Verify that output audio is not written during muted mode. Other parameters |
| 1414 | // should be correct, though. |
| 1415 | AudioFrame new_frame; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1416 | int16_t* frame_data = new_frame.mutable_data(); |
| 1417 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 1418 | frame_data[i] = 17; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1419 | } |
| 1420 | bool muted; |
| 1421 | EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted)); |
| 1422 | EXPECT_TRUE(muted); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1423 | EXPECT_TRUE(out_frame_.muted()); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1424 | for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) { |
| 1425 | EXPECT_EQ(17, frame_data[i]); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1426 | } |
| 1427 | EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_, |
| 1428 | new_frame.timestamp_); |
| 1429 | EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_); |
| 1430 | EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_); |
| 1431 | EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_); |
| 1432 | EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_); |
| 1433 | EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_); |
| 1434 | |
| 1435 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1436 | // packet. Verify that normal operation resumes. |
| 1437 | InsertPacket(kSamples * counter_); |
| 1438 | GetAudioUntilNormal(); |
henrik.lundin | a449107 | 2017-07-06 05:23:53 -0700 | [diff] [blame] | 1439 | EXPECT_FALSE(out_frame_.muted()); |
henrik.lundin | 612c25e | 2016-05-25 08:21:04 -0700 | [diff] [blame] | 1440 | |
| 1441 | NetEqNetworkStatistics stats; |
| 1442 | EXPECT_EQ(0, neteq_->NetworkStatistics(&stats)); |
| 1443 | // NetEqNetworkStatistics::expand_rate tells the fraction of samples that were |
| 1444 | // concealment samples, in Q14 (16384 = 100%) .The vast majority should be |
| 1445 | // concealment samples in this test. |
| 1446 | EXPECT_GT(stats.expand_rate, 14000); |
| 1447 | // And, it should be greater than the speech_expand_rate. |
| 1448 | EXPECT_GT(stats.expand_rate, stats.speech_expand_rate); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | // Verifies that NetEq goes out of muted state when given a delayed packet. |
| 1452 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateDelayedPacket) { |
| 1453 | // Insert one speech packet. |
| 1454 | InsertPacket(0); |
| 1455 | // Pull out audio once and expect it not to be muted. |
| 1456 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1457 | // Pull data until faded out. |
| 1458 | GetAudioUntilMuted(); |
| 1459 | // Insert new data. Timestamp is only corrected for the half of the time |
| 1460 | // elapsed since the last packet. That is, the new packet is delayed. Verify |
| 1461 | // that normal operation resumes. |
| 1462 | InsertPacket(kSamples * counter_ / 2); |
| 1463 | GetAudioUntilNormal(); |
| 1464 | } |
| 1465 | |
| 1466 | // Verifies that NetEq goes out of muted state when given a future packet. |
| 1467 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateFuturePacket) { |
| 1468 | // Insert one speech packet. |
| 1469 | InsertPacket(0); |
| 1470 | // Pull out audio once and expect it not to be muted. |
| 1471 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1472 | // Pull data until faded out. |
| 1473 | GetAudioUntilMuted(); |
| 1474 | // Insert new data. Timestamp is over-corrected for the time elapsed since the |
| 1475 | // last packet. That is, the new packet is too early. Verify that normal |
| 1476 | // operation resumes. |
| 1477 | InsertPacket(kSamples * counter_ * 2); |
| 1478 | GetAudioUntilNormal(); |
| 1479 | } |
| 1480 | |
| 1481 | // Verifies that NetEq goes out of muted state when given an old packet. |
| 1482 | TEST_F(NetEqDecodingTestWithMutedState, MutedStateOldPacket) { |
| 1483 | // Insert one speech packet. |
| 1484 | InsertPacket(0); |
| 1485 | // Pull out audio once and expect it not to be muted. |
| 1486 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1487 | // Pull data until faded out. |
| 1488 | GetAudioUntilMuted(); |
| 1489 | |
| 1490 | EXPECT_NE(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
| 1491 | // Insert packet which is older than the first packet. |
| 1492 | InsertPacket(kSamples * (counter_ - 1000)); |
| 1493 | EXPECT_FALSE(GetAudioReturnMuted()); |
| 1494 | EXPECT_EQ(AudioFrame::kNormalSpeech, out_frame_.speech_type_); |
| 1495 | } |
| 1496 | |
henrik.lundin | 42feb51 | 2016-09-20 06:51:40 -0700 | [diff] [blame] | 1497 | // Verifies that NetEq doesn't enter muted state when CNG mode is active and the |
| 1498 | // packet stream is suspended for a long time. |
| 1499 | TEST_F(NetEqDecodingTestWithMutedState, DoNotMuteExtendedCngWithoutPackets) { |
| 1500 | // Insert one CNG packet. |
| 1501 | InsertCngPacket(0); |
| 1502 | |
| 1503 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1504 | for (int i = 0; i < 1000; ++i) { |
| 1505 | bool muted; |
| 1506 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1507 | ASSERT_FALSE(muted); |
| 1508 | } |
| 1509 | EXPECT_EQ(AudioFrame::kCNG, out_frame_.speech_type_); |
| 1510 | } |
| 1511 | |
| 1512 | // Verifies that NetEq goes back to normal after a long CNG period with the |
| 1513 | // packet stream suspended. |
| 1514 | TEST_F(NetEqDecodingTestWithMutedState, RecoverAfterExtendedCngWithoutPackets) { |
| 1515 | // Insert one CNG packet. |
| 1516 | InsertCngPacket(0); |
| 1517 | |
| 1518 | // Pull 10 seconds of audio (10 ms audio generated per lap). |
| 1519 | for (int i = 0; i < 1000; ++i) { |
| 1520 | bool muted; |
| 1521 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); |
| 1522 | } |
| 1523 | |
| 1524 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1525 | // packet. Verify that normal operation resumes. |
| 1526 | InsertPacket(kSamples * counter_); |
| 1527 | GetAudioUntilNormal(); |
| 1528 | } |
| 1529 | |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1530 | class NetEqDecodingTestTwoInstances : public NetEqDecodingTest { |
| 1531 | public: |
| 1532 | NetEqDecodingTestTwoInstances() : NetEqDecodingTest() {} |
| 1533 | |
| 1534 | void SetUp() override { |
| 1535 | NetEqDecodingTest::SetUp(); |
| 1536 | config2_ = config_; |
| 1537 | } |
| 1538 | |
| 1539 | void CreateSecondInstance() { |
ossu | e352578 | 2016-05-25 07:37:43 -0700 | [diff] [blame] | 1540 | neteq2_.reset(NetEq::Create(config2_, CreateBuiltinAudioDecoderFactory())); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1541 | ASSERT_TRUE(neteq2_); |
| 1542 | LoadDecoders(neteq2_.get()); |
| 1543 | } |
| 1544 | |
| 1545 | protected: |
| 1546 | std::unique_ptr<NetEq> neteq2_; |
| 1547 | NetEq::Config config2_; |
| 1548 | }; |
| 1549 | |
| 1550 | namespace { |
| 1551 | ::testing::AssertionResult AudioFramesEqualExceptData(const AudioFrame& a, |
| 1552 | const AudioFrame& b) { |
| 1553 | if (a.timestamp_ != b.timestamp_) |
| 1554 | return ::testing::AssertionFailure() << "timestamp_ diff (" << a.timestamp_ |
| 1555 | << " != " << b.timestamp_ << ")"; |
| 1556 | if (a.sample_rate_hz_ != b.sample_rate_hz_) |
| 1557 | return ::testing::AssertionFailure() << "sample_rate_hz_ diff (" |
| 1558 | << a.sample_rate_hz_ |
| 1559 | << " != " << b.sample_rate_hz_ << ")"; |
| 1560 | if (a.samples_per_channel_ != b.samples_per_channel_) |
| 1561 | return ::testing::AssertionFailure() |
| 1562 | << "samples_per_channel_ diff (" << a.samples_per_channel_ |
| 1563 | << " != " << b.samples_per_channel_ << ")"; |
| 1564 | if (a.num_channels_ != b.num_channels_) |
| 1565 | return ::testing::AssertionFailure() << "num_channels_ diff (" |
| 1566 | << a.num_channels_ |
| 1567 | << " != " << b.num_channels_ << ")"; |
| 1568 | if (a.speech_type_ != b.speech_type_) |
| 1569 | return ::testing::AssertionFailure() << "speech_type_ diff (" |
| 1570 | << a.speech_type_ |
| 1571 | << " != " << b.speech_type_ << ")"; |
| 1572 | if (a.vad_activity_ != b.vad_activity_) |
| 1573 | return ::testing::AssertionFailure() << "vad_activity_ diff (" |
| 1574 | << a.vad_activity_ |
| 1575 | << " != " << b.vad_activity_ << ")"; |
| 1576 | return ::testing::AssertionSuccess(); |
| 1577 | } |
| 1578 | |
| 1579 | ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a, |
| 1580 | const AudioFrame& b) { |
| 1581 | ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b); |
| 1582 | if (!res) |
| 1583 | return res; |
| 1584 | if (memcmp( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 1585 | a.data(), b.data(), |
| 1586 | a.samples_per_channel_ * a.num_channels_ * sizeof(*a.data())) != 0) { |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1587 | return ::testing::AssertionFailure() << "data_ diff"; |
| 1588 | } |
| 1589 | return ::testing::AssertionSuccess(); |
| 1590 | } |
| 1591 | |
| 1592 | } // namespace |
| 1593 | |
| 1594 | TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) { |
| 1595 | ASSERT_FALSE(config_.enable_muted_state); |
| 1596 | config2_.enable_muted_state = true; |
| 1597 | CreateSecondInstance(); |
| 1598 | |
| 1599 | // Insert one speech packet into both NetEqs. |
| 1600 | const size_t kSamples = 10 * 16; |
| 1601 | const size_t kPayloadBytes = kSamples * 2; |
| 1602 | uint8_t payload[kPayloadBytes] = {0}; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1603 | RTPHeader rtp_info; |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1604 | PopulateRtpInfo(0, 0, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1605 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
| 1606 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1607 | |
| 1608 | AudioFrame out_frame1, out_frame2; |
| 1609 | bool muted; |
| 1610 | for (int i = 0; i < 1000; ++i) { |
| 1611 | std::ostringstream ss; |
| 1612 | ss << "i = " << i; |
| 1613 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 1614 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 1615 | EXPECT_FALSE(muted); |
| 1616 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 1617 | if (muted) { |
| 1618 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 1619 | } else { |
| 1620 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 1621 | } |
| 1622 | } |
| 1623 | EXPECT_TRUE(muted); |
| 1624 | |
| 1625 | // Insert new data. Timestamp is corrected for the time elapsed since the last |
| 1626 | // packet. |
| 1627 | PopulateRtpInfo(0, kSamples * 1000, &rtp_info); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 1628 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
| 1629 | EXPECT_EQ(0, neteq2_->InsertPacket(rtp_info, payload, 0)); |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 1630 | |
| 1631 | int counter = 0; |
| 1632 | while (out_frame1.speech_type_ != AudioFrame::kNormalSpeech) { |
| 1633 | ASSERT_LT(counter++, 1000) << "Test timed out"; |
| 1634 | std::ostringstream ss; |
| 1635 | ss << "counter = " << counter; |
| 1636 | SCOPED_TRACE(ss.str()); // Print out the loop iterator on failure. |
| 1637 | EXPECT_EQ(0, neteq_->GetAudio(&out_frame1, &muted)); |
| 1638 | EXPECT_FALSE(muted); |
| 1639 | EXPECT_EQ(0, neteq2_->GetAudio(&out_frame2, &muted)); |
| 1640 | if (muted) { |
| 1641 | EXPECT_TRUE(AudioFramesEqualExceptData(out_frame1, out_frame2)); |
| 1642 | } else { |
| 1643 | EXPECT_TRUE(AudioFramesEqual(out_frame1, out_frame2)); |
| 1644 | } |
| 1645 | } |
| 1646 | EXPECT_FALSE(muted); |
| 1647 | } |
| 1648 | |
henrik.lundin | 114c1b3 | 2017-04-26 07:47:32 -0700 | [diff] [blame] | 1649 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsEmpty) { |
| 1650 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1651 | |
| 1652 | // Pull out data once. |
| 1653 | AudioFrame output; |
| 1654 | bool muted; |
| 1655 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1656 | |
| 1657 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1658 | } |
| 1659 | |
| 1660 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsOneDecoded) { |
| 1661 | // Insert one packet with PCM16b WB data (this is what PopulateRtpInfo does by |
| 1662 | // default). Make the length 10 ms. |
| 1663 | constexpr size_t kPayloadSamples = 16 * 10; |
| 1664 | constexpr size_t kPayloadBytes = 2 * kPayloadSamples; |
| 1665 | uint8_t payload[kPayloadBytes] = {0}; |
| 1666 | |
| 1667 | RTPHeader rtp_info; |
| 1668 | constexpr uint32_t kRtpTimestamp = 0x1234; |
| 1669 | PopulateRtpInfo(0, kRtpTimestamp, &rtp_info); |
| 1670 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
| 1671 | |
| 1672 | // Pull out data once. |
| 1673 | AudioFrame output; |
| 1674 | bool muted; |
| 1675 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1676 | |
| 1677 | EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp}), |
| 1678 | neteq_->LastDecodedTimestamps()); |
| 1679 | |
| 1680 | // Nothing decoded on the second call. |
| 1681 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1682 | EXPECT_TRUE(neteq_->LastDecodedTimestamps().empty()); |
| 1683 | } |
| 1684 | |
| 1685 | TEST_F(NetEqDecodingTest, LastDecodedTimestampsTwoDecoded) { |
| 1686 | // Insert two packets with PCM16b WB data (this is what PopulateRtpInfo does |
| 1687 | // by default). Make the length 5 ms so that NetEq must decode them both in |
| 1688 | // the same GetAudio call. |
| 1689 | constexpr size_t kPayloadSamples = 16 * 5; |
| 1690 | constexpr size_t kPayloadBytes = 2 * kPayloadSamples; |
| 1691 | uint8_t payload[kPayloadBytes] = {0}; |
| 1692 | |
| 1693 | RTPHeader rtp_info; |
| 1694 | constexpr uint32_t kRtpTimestamp1 = 0x1234; |
| 1695 | PopulateRtpInfo(0, kRtpTimestamp1, &rtp_info); |
| 1696 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
| 1697 | constexpr uint32_t kRtpTimestamp2 = kRtpTimestamp1 + kPayloadSamples; |
| 1698 | PopulateRtpInfo(1, kRtpTimestamp2, &rtp_info); |
| 1699 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); |
| 1700 | |
| 1701 | // Pull out data once. |
| 1702 | AudioFrame output; |
| 1703 | bool muted; |
| 1704 | ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); |
| 1705 | |
| 1706 | EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp1, kRtpTimestamp2}), |
| 1707 | neteq_->LastDecodedTimestamps()); |
| 1708 | } |
| 1709 | |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 1710 | TEST_F(NetEqDecodingTest, TestConcealmentEvents) { |
| 1711 | const int kNumConcealmentEvents = 19; |
| 1712 | const size_t kSamples = 10 * 16; |
| 1713 | const size_t kPayloadBytes = kSamples * 2; |
| 1714 | int seq_no = 0; |
| 1715 | RTPHeader rtp_info; |
| 1716 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 1717 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 1718 | rtp_info.markerBit = 0; |
| 1719 | const uint8_t payload[kPayloadBytes] = {0}; |
| 1720 | bool muted; |
| 1721 | |
| 1722 | for (int i = 0; i < kNumConcealmentEvents; i++) { |
| 1723 | // Insert some packets of 10 ms size. |
| 1724 | for (int j = 0; j < 10; j++) { |
| 1725 | rtp_info.sequenceNumber = seq_no++; |
| 1726 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
| 1727 | neteq_->InsertPacket(rtp_info, payload, 0); |
| 1728 | neteq_->GetAudio(&out_frame_, &muted); |
| 1729 | } |
| 1730 | |
| 1731 | // Lose a number of packets. |
| 1732 | int num_lost = 1 + i; |
| 1733 | for (int j = 0; j < num_lost; j++) { |
| 1734 | seq_no++; |
| 1735 | neteq_->GetAudio(&out_frame_, &muted); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | // Check number of concealment events. |
| 1740 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 1741 | EXPECT_EQ(kNumConcealmentEvents, static_cast<int>(stats.concealment_events)); |
| 1742 | } |
| 1743 | |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1744 | // Test that the jitter buffer delay stat is computed correctly. |
| 1745 | void NetEqDecodingTestFaxMode::TestJitterBufferDelay(bool apply_packet_loss) { |
| 1746 | const int kNumPackets = 10; |
| 1747 | const int kDelayInNumPackets = 2; |
| 1748 | const int kPacketLenMs = 10; // All packets are of 10 ms size. |
| 1749 | const size_t kSamples = kPacketLenMs * 16; |
| 1750 | const size_t kPayloadBytes = kSamples * 2; |
| 1751 | RTPHeader rtp_info; |
| 1752 | rtp_info.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 1753 | rtp_info.payloadType = 94; // PCM16b WB codec. |
| 1754 | rtp_info.markerBit = 0; |
| 1755 | const uint8_t payload[kPayloadBytes] = {0}; |
| 1756 | bool muted; |
| 1757 | int packets_sent = 0; |
| 1758 | int packets_received = 0; |
| 1759 | int expected_delay = 0; |
| 1760 | while (packets_received < kNumPackets) { |
| 1761 | // Insert packet. |
| 1762 | if (packets_sent < kNumPackets) { |
| 1763 | rtp_info.sequenceNumber = packets_sent++; |
| 1764 | rtp_info.timestamp = rtp_info.sequenceNumber * kSamples; |
| 1765 | neteq_->InsertPacket(rtp_info, payload, 0); |
| 1766 | } |
| 1767 | |
| 1768 | // Get packet. |
| 1769 | if (packets_sent > kDelayInNumPackets) { |
| 1770 | neteq_->GetAudio(&out_frame_, &muted); |
| 1771 | packets_received++; |
| 1772 | |
| 1773 | // The delay reported by the jitter buffer never exceeds |
| 1774 | // the number of samples previously fetched with GetAudio |
| 1775 | // (hence the min()). |
| 1776 | int packets_delay = std::min(packets_received, kDelayInNumPackets + 1); |
| 1777 | |
| 1778 | // The increase of the expected delay is the product of |
| 1779 | // the current delay of the jitter buffer in ms * the |
| 1780 | // number of samples that are sent for play out. |
| 1781 | int current_delay_ms = packets_delay * kPacketLenMs; |
| 1782 | expected_delay += current_delay_ms * kSamples; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | if (apply_packet_loss) { |
| 1787 | // Extra call to GetAudio to cause concealment. |
| 1788 | neteq_->GetAudio(&out_frame_, &muted); |
| 1789 | } |
| 1790 | |
| 1791 | // Check jitter buffer delay. |
| 1792 | NetEqLifetimeStatistics stats = neteq_->GetLifetimeStatistics(); |
| 1793 | EXPECT_EQ(expected_delay, static_cast<int>(stats.jitter_buffer_delay_ms)); |
| 1794 | } |
| 1795 | |
| 1796 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithoutLoss) { |
| 1797 | TestJitterBufferDelay(false); |
| 1798 | } |
| 1799 | |
| 1800 | TEST_F(NetEqDecodingTestFaxMode, TestJitterBufferDelayWithLoss) { |
| 1801 | TestJitterBufferDelay(true); |
| 1802 | } |
| 1803 | |
henrik.lundin@webrtc.org | e7ce437 | 2014-01-09 14:01:55 +0000 | [diff] [blame] | 1804 | } // namespace webrtc |