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