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