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