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