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