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