henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This file includes unit tests for NetEQ. |
| 13 | */ |
| 14 | |
| 15 | #include "webrtc/modules/audio_coding/neteq4/interface/neteq.h" |
| 16 | |
pbos@webrtc.org | 3ecc162 | 2014-03-07 15:23:34 +0000 | [diff] [blame^] | 17 | #include <math.h> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <string.h> // memset |
| 20 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 21 | #include <set> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 25 | #include "gflags/gflags.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 26 | #include "gtest/gtest.h" |
| 27 | #include "webrtc/modules/audio_coding/neteq4/test/NETEQTEST_RTPpacket.h" |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 28 | #include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 29 | #include "webrtc/test/testsupport/fileutils.h" |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 30 | #include "webrtc/test/testsupport/gtest_disable.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 31 | #include "webrtc/typedefs.h" |
| 32 | |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 33 | DEFINE_bool(gen_ref, false, "Generate reference files."); |
| 34 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 35 | namespace webrtc { |
| 36 | |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 37 | static bool IsAllZero(const int16_t* buf, int buf_length) { |
| 38 | bool all_zero = true; |
| 39 | for (int n = 0; n < buf_length && all_zero; ++n) |
| 40 | all_zero = buf[n] == 0; |
| 41 | return all_zero; |
| 42 | } |
| 43 | |
| 44 | static bool IsAllNonZero(const int16_t* buf, int buf_length) { |
| 45 | bool all_non_zero = true; |
| 46 | for (int n = 0; n < buf_length && all_non_zero; ++n) |
| 47 | all_non_zero = buf[n] != 0; |
| 48 | return all_non_zero; |
| 49 | } |
| 50 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 51 | class RefFiles { |
| 52 | public: |
| 53 | RefFiles(const std::string& input_file, const std::string& output_file); |
| 54 | ~RefFiles(); |
| 55 | template<class T> void ProcessReference(const T& test_results); |
| 56 | template<typename T, size_t n> void ProcessReference( |
| 57 | const T (&test_results)[n], |
| 58 | size_t length); |
| 59 | template<typename T, size_t n> void WriteToFile( |
| 60 | const T (&test_results)[n], |
| 61 | size_t length); |
| 62 | template<typename T, size_t n> void ReadFromFileAndCompare( |
| 63 | const T (&test_results)[n], |
| 64 | size_t length); |
| 65 | void WriteToFile(const NetEqNetworkStatistics& stats); |
| 66 | void ReadFromFileAndCompare(const NetEqNetworkStatistics& stats); |
| 67 | void WriteToFile(const RtcpStatistics& stats); |
| 68 | void ReadFromFileAndCompare(const RtcpStatistics& stats); |
| 69 | |
| 70 | FILE* input_fp_; |
| 71 | FILE* output_fp_; |
| 72 | }; |
| 73 | |
| 74 | RefFiles::RefFiles(const std::string &input_file, |
| 75 | const std::string &output_file) |
| 76 | : input_fp_(NULL), |
| 77 | output_fp_(NULL) { |
| 78 | if (!input_file.empty()) { |
| 79 | input_fp_ = fopen(input_file.c_str(), "rb"); |
| 80 | EXPECT_TRUE(input_fp_ != NULL); |
| 81 | } |
| 82 | if (!output_file.empty()) { |
| 83 | output_fp_ = fopen(output_file.c_str(), "wb"); |
| 84 | EXPECT_TRUE(output_fp_ != NULL); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | RefFiles::~RefFiles() { |
| 89 | if (input_fp_) { |
| 90 | EXPECT_EQ(EOF, fgetc(input_fp_)); // Make sure that we reached the end. |
| 91 | fclose(input_fp_); |
| 92 | } |
| 93 | if (output_fp_) fclose(output_fp_); |
| 94 | } |
| 95 | |
| 96 | template<class T> |
| 97 | void RefFiles::ProcessReference(const T& test_results) { |
| 98 | WriteToFile(test_results); |
| 99 | ReadFromFileAndCompare(test_results); |
| 100 | } |
| 101 | |
| 102 | template<typename T, size_t n> |
| 103 | void RefFiles::ProcessReference(const T (&test_results)[n], size_t length) { |
| 104 | WriteToFile(test_results, length); |
| 105 | ReadFromFileAndCompare(test_results, length); |
| 106 | } |
| 107 | |
| 108 | template<typename T, size_t n> |
| 109 | void RefFiles::WriteToFile(const T (&test_results)[n], size_t length) { |
| 110 | if (output_fp_) { |
| 111 | ASSERT_EQ(length, fwrite(&test_results, sizeof(T), length, output_fp_)); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | template<typename T, size_t n> |
| 116 | void RefFiles::ReadFromFileAndCompare(const T (&test_results)[n], |
| 117 | size_t length) { |
| 118 | if (input_fp_) { |
| 119 | // Read from ref file. |
| 120 | T* ref = new T[length]; |
| 121 | ASSERT_EQ(length, fread(ref, sizeof(T), length, input_fp_)); |
| 122 | // Compare |
| 123 | ASSERT_EQ(0, memcmp(&test_results, ref, sizeof(T) * length)); |
| 124 | delete [] ref; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void RefFiles::WriteToFile(const NetEqNetworkStatistics& stats) { |
| 129 | if (output_fp_) { |
| 130 | ASSERT_EQ(1u, fwrite(&stats, sizeof(NetEqNetworkStatistics), 1, |
| 131 | output_fp_)); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void RefFiles::ReadFromFileAndCompare( |
| 136 | const NetEqNetworkStatistics& stats) { |
| 137 | if (input_fp_) { |
| 138 | // Read from ref file. |
| 139 | size_t stat_size = sizeof(NetEqNetworkStatistics); |
| 140 | NetEqNetworkStatistics ref_stats; |
| 141 | ASSERT_EQ(1u, fread(&ref_stats, stat_size, 1, input_fp_)); |
| 142 | // Compare |
| 143 | EXPECT_EQ(0, memcmp(&stats, &ref_stats, stat_size)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void RefFiles::WriteToFile(const RtcpStatistics& stats) { |
| 148 | if (output_fp_) { |
| 149 | ASSERT_EQ(1u, fwrite(&(stats.fraction_lost), sizeof(stats.fraction_lost), 1, |
| 150 | output_fp_)); |
| 151 | ASSERT_EQ(1u, fwrite(&(stats.cumulative_lost), |
| 152 | sizeof(stats.cumulative_lost), 1, output_fp_)); |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 +0000 | [diff] [blame] | 153 | ASSERT_EQ(1u, fwrite(&(stats.extended_max_sequence_number), |
| 154 | sizeof(stats.extended_max_sequence_number), 1, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 155 | output_fp_)); |
| 156 | ASSERT_EQ(1u, fwrite(&(stats.jitter), sizeof(stats.jitter), 1, |
| 157 | output_fp_)); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void RefFiles::ReadFromFileAndCompare( |
| 162 | const RtcpStatistics& stats) { |
| 163 | if (input_fp_) { |
| 164 | // Read from ref file. |
| 165 | RtcpStatistics ref_stats; |
| 166 | ASSERT_EQ(1u, fread(&(ref_stats.fraction_lost), |
| 167 | sizeof(ref_stats.fraction_lost), 1, input_fp_)); |
| 168 | ASSERT_EQ(1u, fread(&(ref_stats.cumulative_lost), |
| 169 | sizeof(ref_stats.cumulative_lost), 1, input_fp_)); |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 +0000 | [diff] [blame] | 170 | ASSERT_EQ(1u, fread(&(ref_stats.extended_max_sequence_number), |
| 171 | sizeof(ref_stats.extended_max_sequence_number), 1, |
| 172 | input_fp_)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 173 | ASSERT_EQ(1u, fread(&(ref_stats.jitter), sizeof(ref_stats.jitter), 1, |
| 174 | input_fp_)); |
| 175 | // Compare |
| 176 | EXPECT_EQ(ref_stats.fraction_lost, stats.fraction_lost); |
| 177 | EXPECT_EQ(ref_stats.cumulative_lost, stats.cumulative_lost); |
sprang@webrtc.org | fe5d36b | 2013-10-28 09:21:07 +0000 | [diff] [blame] | 178 | EXPECT_EQ(ref_stats.extended_max_sequence_number, |
| 179 | stats.extended_max_sequence_number); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 180 | EXPECT_EQ(ref_stats.jitter, stats.jitter); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | class NetEqDecodingTest : public ::testing::Test { |
| 185 | protected: |
| 186 | // NetEQ must be polled for data once every 10 ms. Thus, neither of the |
| 187 | // constants below can be changed. |
| 188 | static const int kTimeStepMs = 10; |
| 189 | static const int kBlockSize8kHz = kTimeStepMs * 8; |
| 190 | static const int kBlockSize16kHz = kTimeStepMs * 16; |
| 191 | static const int kBlockSize32kHz = kTimeStepMs * 32; |
| 192 | static const int kMaxBlockSize = kBlockSize32kHz; |
| 193 | static const int kInitSampleRateHz = 8000; |
| 194 | |
| 195 | NetEqDecodingTest(); |
| 196 | virtual void SetUp(); |
| 197 | virtual void TearDown(); |
| 198 | void SelectDecoders(NetEqDecoder* used_codec); |
| 199 | void LoadDecoders(); |
| 200 | void OpenInputFile(const std::string &rtp_file); |
| 201 | void Process(NETEQTEST_RTPpacket* rtp_ptr, int* out_len); |
| 202 | void DecodeAndCompare(const std::string &rtp_file, |
| 203 | const std::string &ref_file); |
| 204 | void DecodeAndCheckStats(const std::string &rtp_file, |
| 205 | const std::string &stat_ref_file, |
| 206 | const std::string &rtcp_ref_file); |
| 207 | static void PopulateRtpInfo(int frame_index, |
| 208 | int timestamp, |
| 209 | WebRtcRTPHeader* rtp_info); |
| 210 | static void PopulateCng(int frame_index, |
| 211 | int timestamp, |
| 212 | WebRtcRTPHeader* rtp_info, |
| 213 | uint8_t* payload, |
| 214 | int* payload_len); |
| 215 | |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 216 | void CheckBgnOff(int sampling_rate, NetEqBackgroundNoiseMode bgn_mode); |
| 217 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 218 | void WrapTest(uint16_t start_seq_no, uint32_t start_timestamp, |
| 219 | const std::set<uint16_t>& drop_seq_numbers, |
| 220 | bool expect_seq_no_wrap, bool expect_timestamp_wrap); |
| 221 | |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 222 | void LongCngWithClockDrift(double drift_factor); |
| 223 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 224 | NetEq* neteq_; |
| 225 | FILE* rtp_fp_; |
| 226 | unsigned int sim_clock_; |
| 227 | int16_t out_data_[kMaxBlockSize]; |
| 228 | int output_sample_rate_; |
| 229 | }; |
| 230 | |
| 231 | // Allocating the static const so that it can be passed by reference. |
| 232 | const int NetEqDecodingTest::kTimeStepMs; |
| 233 | const int NetEqDecodingTest::kBlockSize8kHz; |
| 234 | const int NetEqDecodingTest::kBlockSize16kHz; |
| 235 | const int NetEqDecodingTest::kBlockSize32kHz; |
| 236 | const int NetEqDecodingTest::kMaxBlockSize; |
| 237 | const int NetEqDecodingTest::kInitSampleRateHz; |
| 238 | |
| 239 | NetEqDecodingTest::NetEqDecodingTest() |
| 240 | : neteq_(NULL), |
| 241 | rtp_fp_(NULL), |
| 242 | sim_clock_(0), |
| 243 | output_sample_rate_(kInitSampleRateHz) { |
| 244 | memset(out_data_, 0, sizeof(out_data_)); |
| 245 | } |
| 246 | |
| 247 | void NetEqDecodingTest::SetUp() { |
| 248 | neteq_ = NetEq::Create(kInitSampleRateHz); |
| 249 | ASSERT_TRUE(neteq_); |
| 250 | LoadDecoders(); |
| 251 | } |
| 252 | |
| 253 | void NetEqDecodingTest::TearDown() { |
| 254 | delete neteq_; |
| 255 | if (rtp_fp_) |
| 256 | fclose(rtp_fp_); |
| 257 | } |
| 258 | |
| 259 | void NetEqDecodingTest::LoadDecoders() { |
| 260 | // Load PCMu. |
| 261 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCMu, 0)); |
| 262 | // Load PCMa. |
| 263 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCMa, 8)); |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 264 | #ifndef WEBRTC_ANDROID |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 265 | // Load iLBC. |
| 266 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderILBC, 102)); |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 267 | #endif // WEBRTC_ANDROID |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 268 | // Load iSAC. |
| 269 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderISAC, 103)); |
turaj@webrtc.org | 5272eb8 | 2013-11-23 00:11:32 +0000 | [diff] [blame] | 270 | #ifndef WEBRTC_ANDROID |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 271 | // Load iSAC SWB. |
| 272 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderISACswb, 104)); |
henrik.lundin@webrtc.org | ac59dba | 2013-01-31 09:55:24 +0000 | [diff] [blame] | 273 | // Load iSAC FB. |
| 274 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderISACfb, 105)); |
turaj@webrtc.org | 5272eb8 | 2013-11-23 00:11:32 +0000 | [diff] [blame] | 275 | #endif // WEBRTC_ANDROID |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 276 | // Load PCM16B nb. |
| 277 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCM16B, 93)); |
| 278 | // Load PCM16B wb. |
| 279 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCM16Bwb, 94)); |
| 280 | // Load PCM16B swb32. |
| 281 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCM16Bswb32kHz, 95)); |
| 282 | // Load CNG 8 kHz. |
| 283 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGnb, 13)); |
| 284 | // Load CNG 16 kHz. |
| 285 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGwb, 98)); |
| 286 | } |
| 287 | |
| 288 | void NetEqDecodingTest::OpenInputFile(const std::string &rtp_file) { |
| 289 | rtp_fp_ = fopen(rtp_file.c_str(), "rb"); |
| 290 | ASSERT_TRUE(rtp_fp_ != NULL); |
| 291 | ASSERT_EQ(0, NETEQTEST_RTPpacket::skipFileHeader(rtp_fp_)); |
| 292 | } |
| 293 | |
| 294 | void NetEqDecodingTest::Process(NETEQTEST_RTPpacket* rtp, int* out_len) { |
| 295 | // Check if time to receive. |
| 296 | while ((sim_clock_ >= rtp->time()) && |
| 297 | (rtp->dataLen() >= 0)) { |
| 298 | if (rtp->dataLen() > 0) { |
| 299 | WebRtcRTPHeader rtpInfo; |
| 300 | rtp->parseHeader(&rtpInfo); |
| 301 | ASSERT_EQ(0, neteq_->InsertPacket( |
| 302 | rtpInfo, |
| 303 | rtp->payload(), |
| 304 | rtp->payloadLen(), |
| 305 | rtp->time() * (output_sample_rate_ / 1000))); |
| 306 | } |
| 307 | // Get next packet. |
| 308 | ASSERT_NE(-1, rtp->readFromFile(rtp_fp_)); |
| 309 | } |
| 310 | |
henrik.lundin@webrtc.org | e1d468c | 2013-01-30 07:37:20 +0000 | [diff] [blame] | 311 | // Get audio from NetEq. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 312 | NetEqOutputType type; |
| 313 | int num_channels; |
| 314 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, out_len, |
| 315 | &num_channels, &type)); |
| 316 | ASSERT_TRUE((*out_len == kBlockSize8kHz) || |
| 317 | (*out_len == kBlockSize16kHz) || |
| 318 | (*out_len == kBlockSize32kHz)); |
| 319 | output_sample_rate_ = *out_len / 10 * 1000; |
| 320 | |
| 321 | // Increase time. |
| 322 | sim_clock_ += kTimeStepMs; |
| 323 | } |
| 324 | |
| 325 | void NetEqDecodingTest::DecodeAndCompare(const std::string &rtp_file, |
| 326 | const std::string &ref_file) { |
| 327 | OpenInputFile(rtp_file); |
| 328 | |
| 329 | std::string ref_out_file = ""; |
| 330 | if (ref_file.empty()) { |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 331 | ref_out_file = webrtc::test::OutputPath() + "neteq_universal_ref.pcm"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 332 | } |
| 333 | RefFiles ref_files(ref_file, ref_out_file); |
| 334 | |
| 335 | NETEQTEST_RTPpacket rtp; |
| 336 | ASSERT_GT(rtp.readFromFile(rtp_fp_), 0); |
| 337 | int i = 0; |
| 338 | while (rtp.dataLen() >= 0) { |
| 339 | std::ostringstream ss; |
| 340 | ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; |
| 341 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
turaj@webrtc.org | 58cd316 | 2013-10-31 15:15:55 +0000 | [diff] [blame] | 342 | int out_len = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 343 | ASSERT_NO_FATAL_FAILURE(Process(&rtp, &out_len)); |
| 344 | ASSERT_NO_FATAL_FAILURE(ref_files.ProcessReference(out_data_, out_len)); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void NetEqDecodingTest::DecodeAndCheckStats(const std::string &rtp_file, |
| 349 | const std::string &stat_ref_file, |
| 350 | const std::string &rtcp_ref_file) { |
| 351 | OpenInputFile(rtp_file); |
| 352 | std::string stat_out_file = ""; |
| 353 | if (stat_ref_file.empty()) { |
| 354 | stat_out_file = webrtc::test::OutputPath() + |
| 355 | "neteq_network_stats.dat"; |
| 356 | } |
| 357 | RefFiles network_stat_files(stat_ref_file, stat_out_file); |
| 358 | |
| 359 | std::string rtcp_out_file = ""; |
| 360 | if (rtcp_ref_file.empty()) { |
| 361 | rtcp_out_file = webrtc::test::OutputPath() + |
| 362 | "neteq_rtcp_stats.dat"; |
| 363 | } |
| 364 | RefFiles rtcp_stat_files(rtcp_ref_file, rtcp_out_file); |
| 365 | |
| 366 | NETEQTEST_RTPpacket rtp; |
| 367 | ASSERT_GT(rtp.readFromFile(rtp_fp_), 0); |
| 368 | while (rtp.dataLen() >= 0) { |
| 369 | int out_len; |
| 370 | Process(&rtp, &out_len); |
| 371 | |
| 372 | // Query the network statistics API once per second |
| 373 | if (sim_clock_ % 1000 == 0) { |
| 374 | // Process NetworkStatistics. |
| 375 | NetEqNetworkStatistics network_stats; |
| 376 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 377 | network_stat_files.ProcessReference(network_stats); |
| 378 | |
| 379 | // Process RTCPstat. |
| 380 | RtcpStatistics rtcp_stats; |
| 381 | neteq_->GetRtcpStatistics(&rtcp_stats); |
| 382 | rtcp_stat_files.ProcessReference(rtcp_stats); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void NetEqDecodingTest::PopulateRtpInfo(int frame_index, |
| 388 | int timestamp, |
| 389 | WebRtcRTPHeader* rtp_info) { |
| 390 | rtp_info->header.sequenceNumber = frame_index; |
| 391 | rtp_info->header.timestamp = timestamp; |
| 392 | rtp_info->header.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 393 | rtp_info->header.payloadType = 94; // PCM16b WB codec. |
| 394 | rtp_info->header.markerBit = 0; |
| 395 | } |
| 396 | |
| 397 | void NetEqDecodingTest::PopulateCng(int frame_index, |
| 398 | int timestamp, |
| 399 | WebRtcRTPHeader* rtp_info, |
| 400 | uint8_t* payload, |
| 401 | int* payload_len) { |
| 402 | rtp_info->header.sequenceNumber = frame_index; |
| 403 | rtp_info->header.timestamp = timestamp; |
| 404 | rtp_info->header.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 405 | rtp_info->header.payloadType = 98; // WB CNG. |
| 406 | rtp_info->header.markerBit = 0; |
| 407 | payload[0] = 64; // Noise level -64 dBov, quite arbitrarily chosen. |
| 408 | *payload_len = 1; // Only noise level, no spectral parameters. |
| 409 | } |
| 410 | |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 411 | void NetEqDecodingTest::CheckBgnOff(int sampling_rate_hz, |
| 412 | NetEqBackgroundNoiseMode bgn_mode) { |
| 413 | int expected_samples_per_channel = 0; |
| 414 | uint8_t payload_type = 0xFF; // Invalid. |
| 415 | if (sampling_rate_hz == 8000) { |
| 416 | expected_samples_per_channel = kBlockSize8kHz; |
| 417 | payload_type = 93; // PCM 16, 8 kHz. |
| 418 | } else if (sampling_rate_hz == 16000) { |
| 419 | expected_samples_per_channel = kBlockSize16kHz; |
| 420 | payload_type = 94; // PCM 16, 16 kHZ. |
| 421 | } else if (sampling_rate_hz == 32000) { |
| 422 | expected_samples_per_channel = kBlockSize32kHz; |
| 423 | payload_type = 95; // PCM 16, 32 kHz. |
| 424 | } else { |
| 425 | ASSERT_TRUE(false); // Unsupported test case. |
| 426 | } |
| 427 | |
| 428 | NetEqOutputType type; |
| 429 | int16_t output[kBlockSize32kHz]; // Maximum size is chosen. |
| 430 | int16_t input[kBlockSize32kHz]; // Maximum size is chosen. |
| 431 | |
| 432 | // Payload of 10 ms of PCM16 32 kHz. |
| 433 | uint8_t payload[kBlockSize32kHz * sizeof(int16_t)]; |
| 434 | |
| 435 | // Random payload. |
| 436 | for (int n = 0; n < expected_samples_per_channel; ++n) { |
| 437 | input[n] = (rand() & ((1 << 10) - 1)) - ((1 << 5) - 1); |
| 438 | } |
| 439 | int enc_len_bytes = WebRtcPcm16b_EncodeW16( |
| 440 | input, expected_samples_per_channel, reinterpret_cast<int16_t*>(payload)); |
| 441 | ASSERT_EQ(enc_len_bytes, expected_samples_per_channel * 2); |
| 442 | |
| 443 | WebRtcRTPHeader rtp_info; |
| 444 | PopulateRtpInfo(0, 0, &rtp_info); |
| 445 | rtp_info.header.payloadType = payload_type; |
| 446 | |
| 447 | int number_channels = 0; |
| 448 | int samples_per_channel = 0; |
| 449 | |
| 450 | uint32_t receive_timestamp = 0; |
| 451 | for (int n = 0; n < 10; ++n) { // Insert few packets and get audio. |
| 452 | number_channels = 0; |
| 453 | samples_per_channel = 0; |
| 454 | ASSERT_EQ(0, neteq_->InsertPacket( |
| 455 | rtp_info, payload, enc_len_bytes, receive_timestamp)); |
| 456 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel, |
| 457 | &number_channels, &type)); |
| 458 | ASSERT_EQ(1, number_channels); |
| 459 | ASSERT_EQ(expected_samples_per_channel, samples_per_channel); |
| 460 | ASSERT_EQ(kOutputNormal, type); |
| 461 | |
| 462 | // Next packet. |
| 463 | rtp_info.header.timestamp += expected_samples_per_channel; |
| 464 | rtp_info.header.sequenceNumber++; |
| 465 | receive_timestamp += expected_samples_per_channel; |
| 466 | } |
| 467 | |
| 468 | number_channels = 0; |
| 469 | samples_per_channel = 0; |
| 470 | |
| 471 | // Get audio without inserting packets, expecting PLC and PLC-to-CNG. Pull one |
| 472 | // frame without checking speech-type. This is the first frame pulled without |
| 473 | // inserting any packet, and might not be labeled as PCL. |
| 474 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel, |
| 475 | &number_channels, &type)); |
| 476 | ASSERT_EQ(1, number_channels); |
| 477 | ASSERT_EQ(expected_samples_per_channel, samples_per_channel); |
| 478 | |
| 479 | // To be able to test the fading of background noise we need at lease to pull |
| 480 | // 610 frames. |
| 481 | const int kFadingThreshold = 610; |
| 482 | |
| 483 | // Test several CNG-to-PLC packet for the expected behavior. The number 20 is |
| 484 | // arbitrary, but sufficiently large to test enough number of frames. |
| 485 | const int kNumPlcToCngTestFrames = 20; |
| 486 | bool plc_to_cng = false; |
| 487 | for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { |
| 488 | number_channels = 0; |
| 489 | samples_per_channel = 0; |
| 490 | memset(output, 1, sizeof(output)); // Set to non-zero. |
| 491 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, &samples_per_channel, |
| 492 | &number_channels, &type)); |
| 493 | ASSERT_EQ(1, number_channels); |
| 494 | ASSERT_EQ(expected_samples_per_channel, samples_per_channel); |
| 495 | if (type == kOutputPLCtoCNG) { |
| 496 | plc_to_cng = true; |
| 497 | double sum_squared = 0; |
| 498 | for (int k = 0; k < number_channels * samples_per_channel; ++k) |
| 499 | sum_squared += output[k] * output[k]; |
| 500 | if (bgn_mode == kBgnOn) { |
| 501 | EXPECT_NE(0, sum_squared); |
| 502 | } else if (bgn_mode == kBgnOff || n > kFadingThreshold) { |
| 503 | EXPECT_EQ(0, sum_squared); |
| 504 | } |
| 505 | } else { |
| 506 | EXPECT_EQ(kOutputPLC, type); |
| 507 | } |
| 508 | } |
| 509 | EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. |
| 510 | } |
| 511 | |
kjellander@webrtc.org | 6eba277 | 2013-06-04 05:46:37 +0000 | [diff] [blame] | 512 | #if defined(_WIN32) && defined(WEBRTC_ARCH_64_BITS) |
| 513 | // Disabled for Windows 64-bit until webrtc:1458 is fixed. |
| 514 | #define MAYBE_TestBitExactness DISABLED_TestBitExactness |
| 515 | #else |
| 516 | #define MAYBE_TestBitExactness TestBitExactness |
| 517 | #endif |
| 518 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 519 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(MAYBE_TestBitExactness)) { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 520 | const std::string input_rtp_file = webrtc::test::ProjectRootPath() + |
henrik.lundin@webrtc.org | 73deaad | 2013-01-31 13:32:51 +0000 | [diff] [blame] | 521 | "resources/audio_coding/neteq_universal_new.rtp"; |
henrik.lundin@webrtc.org | 6e3968f | 2013-01-31 15:07:30 +0000 | [diff] [blame] | 522 | #if defined(_MSC_VER) && (_MSC_VER >= 1700) |
| 523 | // For Visual Studio 2012 and later, we will have to use the generic reference |
| 524 | // file, rather than the windows-specific one. |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 525 | const std::string input_ref_file = webrtc::test::ProjectRootPath() + |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 526 | "resources/audio_coding/neteq4_universal_ref.pcm"; |
henrik.lundin@webrtc.org | 6e3968f | 2013-01-31 15:07:30 +0000 | [diff] [blame] | 527 | #else |
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 | #endif |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 531 | |
| 532 | if (FLAGS_gen_ref) { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 533 | DecodeAndCompare(input_rtp_file, ""); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 534 | } else { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 535 | DecodeAndCompare(input_rtp_file, input_ref_file); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 536 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 537 | } |
| 538 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 539 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(TestNetworkStatistics)) { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 540 | const std::string input_rtp_file = webrtc::test::ProjectRootPath() + |
henrik.lundin@webrtc.org | 73deaad | 2013-01-31 13:32:51 +0000 | [diff] [blame] | 541 | "resources/audio_coding/neteq_universal_new.rtp"; |
henrik.lundin@webrtc.org | 6e3968f | 2013-01-31 15:07:30 +0000 | [diff] [blame] | 542 | #if defined(_MSC_VER) && (_MSC_VER >= 1700) |
| 543 | // For Visual Studio 2012 and later, we will have to use the generic reference |
| 544 | // file, rather than the windows-specific one. |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 545 | const std::string network_stat_ref_file = webrtc::test::ProjectRootPath() + |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 546 | "resources/audio_coding/neteq4_network_stats.dat"; |
henrik.lundin@webrtc.org | 6e3968f | 2013-01-31 15:07:30 +0000 | [diff] [blame] | 547 | #else |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 548 | const std::string network_stat_ref_file = |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 549 | webrtc::test::ResourcePath("audio_coding/neteq4_network_stats", "dat"); |
henrik.lundin@webrtc.org | 6e3968f | 2013-01-31 15:07:30 +0000 | [diff] [blame] | 550 | #endif |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 551 | const std::string rtcp_stat_ref_file = |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 552 | webrtc::test::ResourcePath("audio_coding/neteq4_rtcp_stats", "dat"); |
| 553 | if (FLAGS_gen_ref) { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 554 | DecodeAndCheckStats(input_rtp_file, "", ""); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 555 | } else { |
andrew@webrtc.org | f6a638e | 2014-02-04 01:31:28 +0000 | [diff] [blame] | 556 | DecodeAndCheckStats(input_rtp_file, network_stat_ref_file, |
| 557 | rtcp_stat_ref_file); |
turaj@webrtc.org | a6101d7 | 2013-10-01 22:01:09 +0000 | [diff] [blame] | 558 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | // TODO(hlundin): Re-enable test once the statistics interface is up and again. |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 562 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(TestFrameWaitingTimeStatistics)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 563 | // Use fax mode to avoid time-scaling. This is to simplify the testing of |
| 564 | // packet waiting times in the packet buffer. |
| 565 | neteq_->SetPlayoutMode(kPlayoutFax); |
| 566 | ASSERT_EQ(kPlayoutFax, neteq_->PlayoutMode()); |
| 567 | // Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio. |
| 568 | size_t num_frames = 30; |
| 569 | const int kSamples = 10 * 16; |
| 570 | const int kPayloadBytes = kSamples * 2; |
| 571 | for (size_t i = 0; i < num_frames; ++i) { |
| 572 | uint16_t payload[kSamples] = {0}; |
| 573 | WebRtcRTPHeader rtp_info; |
| 574 | rtp_info.header.sequenceNumber = i; |
| 575 | rtp_info.header.timestamp = i * kSamples; |
| 576 | rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC. |
| 577 | rtp_info.header.payloadType = 94; // PCM16b WB codec. |
| 578 | rtp_info.header.markerBit = 0; |
| 579 | ASSERT_EQ(0, neteq_->InsertPacket( |
| 580 | rtp_info, |
| 581 | reinterpret_cast<uint8_t*>(payload), |
| 582 | kPayloadBytes, 0)); |
| 583 | } |
| 584 | // Pull out all data. |
| 585 | for (size_t i = 0; i < num_frames; ++i) { |
| 586 | int out_len; |
| 587 | int num_channels; |
| 588 | NetEqOutputType type; |
| 589 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 590 | &num_channels, &type)); |
| 591 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 592 | } |
| 593 | |
| 594 | std::vector<int> waiting_times; |
| 595 | neteq_->WaitingTimes(&waiting_times); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 596 | EXPECT_EQ(num_frames, waiting_times.size()); |
| 597 | // Since all frames are dumped into NetEQ at once, but pulled out with 10 ms |
| 598 | // spacing (per definition), we expect the delay to increase with 10 ms for |
| 599 | // each packet. |
| 600 | for (size_t i = 0; i < waiting_times.size(); ++i) { |
| 601 | EXPECT_EQ(static_cast<int>(i + 1) * 10, waiting_times[i]); |
| 602 | } |
| 603 | |
| 604 | // Check statistics again and make sure it's been reset. |
| 605 | neteq_->WaitingTimes(&waiting_times); |
turaj@webrtc.org | 58cd316 | 2013-10-31 15:15:55 +0000 | [diff] [blame] | 606 | int len = waiting_times.size(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 607 | EXPECT_EQ(0, len); |
| 608 | |
| 609 | // Process > 100 frames, and make sure that that we get statistics |
| 610 | // only for 100 frames. Note the new SSRC, causing NetEQ to reset. |
| 611 | num_frames = 110; |
| 612 | for (size_t i = 0; i < num_frames; ++i) { |
| 613 | uint16_t payload[kSamples] = {0}; |
| 614 | WebRtcRTPHeader rtp_info; |
| 615 | rtp_info.header.sequenceNumber = i; |
| 616 | rtp_info.header.timestamp = i * kSamples; |
| 617 | rtp_info.header.ssrc = 0x1235; // Just an arbitrary SSRC. |
| 618 | rtp_info.header.payloadType = 94; // PCM16b WB codec. |
| 619 | rtp_info.header.markerBit = 0; |
| 620 | ASSERT_EQ(0, neteq_->InsertPacket( |
| 621 | rtp_info, |
| 622 | reinterpret_cast<uint8_t*>(payload), |
| 623 | kPayloadBytes, 0)); |
| 624 | int out_len; |
| 625 | int num_channels; |
| 626 | NetEqOutputType type; |
| 627 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 628 | &num_channels, &type)); |
| 629 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 630 | } |
| 631 | |
| 632 | neteq_->WaitingTimes(&waiting_times); |
| 633 | EXPECT_EQ(100u, waiting_times.size()); |
| 634 | } |
| 635 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 636 | TEST_F(NetEqDecodingTest, |
| 637 | DISABLED_ON_ANDROID(TestAverageInterArrivalTimeNegative)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 638 | const int kNumFrames = 3000; // Needed for convergence. |
| 639 | int frame_index = 0; |
| 640 | const int kSamples = 10 * 16; |
| 641 | const int kPayloadBytes = kSamples * 2; |
| 642 | while (frame_index < kNumFrames) { |
| 643 | // Insert one packet each time, except every 10th time where we insert two |
| 644 | // packets at once. This will create a negative clock-drift of approx. 10%. |
| 645 | int num_packets = (frame_index % 10 == 0 ? 2 : 1); |
| 646 | for (int n = 0; n < num_packets; ++n) { |
| 647 | uint8_t payload[kPayloadBytes] = {0}; |
| 648 | WebRtcRTPHeader rtp_info; |
| 649 | PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
| 650 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 651 | ++frame_index; |
| 652 | } |
| 653 | |
| 654 | // Pull out data once. |
| 655 | int out_len; |
| 656 | int num_channels; |
| 657 | NetEqOutputType type; |
| 658 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 659 | &num_channels, &type)); |
| 660 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 661 | } |
| 662 | |
| 663 | NetEqNetworkStatistics network_stats; |
| 664 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 665 | EXPECT_EQ(-103196, network_stats.clockdrift_ppm); |
| 666 | } |
| 667 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 668 | TEST_F(NetEqDecodingTest, |
| 669 | DISABLED_ON_ANDROID(TestAverageInterArrivalTimePositive)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 670 | const int kNumFrames = 5000; // Needed for convergence. |
| 671 | int frame_index = 0; |
| 672 | const int kSamples = 10 * 16; |
| 673 | const int kPayloadBytes = kSamples * 2; |
| 674 | for (int i = 0; i < kNumFrames; ++i) { |
| 675 | // Insert one packet each time, except every 10th time where we don't insert |
| 676 | // any packet. This will create a positive clock-drift of approx. 11%. |
| 677 | int num_packets = (i % 10 == 9 ? 0 : 1); |
| 678 | for (int n = 0; n < num_packets; ++n) { |
| 679 | uint8_t payload[kPayloadBytes] = {0}; |
| 680 | WebRtcRTPHeader rtp_info; |
| 681 | PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info); |
| 682 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 683 | ++frame_index; |
| 684 | } |
| 685 | |
| 686 | // Pull out data once. |
| 687 | int out_len; |
| 688 | int num_channels; |
| 689 | NetEqOutputType type; |
| 690 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 691 | &num_channels, &type)); |
| 692 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 693 | } |
| 694 | |
| 695 | NetEqNetworkStatistics network_stats; |
| 696 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 697 | EXPECT_EQ(110946, network_stats.clockdrift_ppm); |
| 698 | } |
| 699 | |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 700 | void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 701 | uint16_t seq_no = 0; |
| 702 | uint32_t timestamp = 0; |
| 703 | const int kFrameSizeMs = 30; |
| 704 | const int kSamples = kFrameSizeMs * 16; |
| 705 | const int kPayloadBytes = kSamples * 2; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 706 | double next_input_time_ms = 0.0; |
| 707 | double t_ms; |
| 708 | NetEqOutputType type; |
| 709 | |
| 710 | // Insert speech for 5 seconds. |
| 711 | const int kSpeechDurationMs = 5000; |
| 712 | for (t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 713 | // Each turn in this for loop is 10 ms. |
| 714 | while (next_input_time_ms <= t_ms) { |
| 715 | // Insert one 30 ms speech frame. |
| 716 | uint8_t payload[kPayloadBytes] = {0}; |
| 717 | WebRtcRTPHeader rtp_info; |
| 718 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 719 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 720 | ++seq_no; |
| 721 | timestamp += kSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 722 | next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 723 | } |
| 724 | // Pull out data once. |
| 725 | int out_len; |
| 726 | int num_channels; |
| 727 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 728 | &num_channels, &type)); |
| 729 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 730 | } |
| 731 | |
| 732 | EXPECT_EQ(kOutputNormal, type); |
| 733 | int32_t delay_before = timestamp - neteq_->PlayoutTimestamp(); |
| 734 | |
| 735 | // Insert CNG for 1 minute (= 60000 ms). |
| 736 | const int kCngPeriodMs = 100; |
| 737 | const int kCngPeriodSamples = kCngPeriodMs * 16; // Period in 16 kHz samples. |
| 738 | const int kCngDurationMs = 60000; |
| 739 | for (; t_ms < kSpeechDurationMs + kCngDurationMs; t_ms += 10) { |
| 740 | // Each turn in this for loop is 10 ms. |
| 741 | while (next_input_time_ms <= t_ms) { |
| 742 | // Insert one CNG frame each 100 ms. |
| 743 | uint8_t payload[kPayloadBytes]; |
| 744 | int payload_len; |
| 745 | WebRtcRTPHeader rtp_info; |
| 746 | PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len); |
| 747 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, payload_len, 0)); |
| 748 | ++seq_no; |
| 749 | timestamp += kCngPeriodSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 750 | next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 751 | } |
| 752 | // Pull out data once. |
| 753 | int out_len; |
| 754 | int num_channels; |
| 755 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 756 | &num_channels, &type)); |
| 757 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 758 | } |
| 759 | |
| 760 | EXPECT_EQ(kOutputCNG, type); |
| 761 | |
| 762 | // Insert speech again until output type is speech. |
| 763 | while (type != kOutputNormal) { |
| 764 | // Each turn in this for loop is 10 ms. |
| 765 | while (next_input_time_ms <= t_ms) { |
| 766 | // Insert one 30 ms speech frame. |
| 767 | uint8_t payload[kPayloadBytes] = {0}; |
| 768 | WebRtcRTPHeader rtp_info; |
| 769 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 770 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 771 | ++seq_no; |
| 772 | timestamp += kSamples; |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 773 | next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 774 | } |
| 775 | // Pull out data once. |
| 776 | int out_len; |
| 777 | int num_channels; |
| 778 | ASSERT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, &out_len, |
| 779 | &num_channels, &type)); |
| 780 | ASSERT_EQ(kBlockSize16kHz, out_len); |
| 781 | // Increase clock. |
| 782 | t_ms += 10; |
| 783 | } |
| 784 | |
| 785 | int32_t delay_after = timestamp - neteq_->PlayoutTimestamp(); |
| 786 | // Compare delay before and after, and make sure it differs less than 20 ms. |
| 787 | EXPECT_LE(delay_after, delay_before + 20 * 16); |
| 788 | EXPECT_GE(delay_after, delay_before - 20 * 16); |
| 789 | } |
| 790 | |
henrik.lundin@webrtc.org | ed865b5 | 2014-03-06 10:28:07 +0000 | [diff] [blame] | 791 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(LongCngWithNegativeClockDrift)) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 792 | // Apply a clock drift of -25 ms / s (sender faster than receiver). |
| 793 | const double kDriftFactor = 1000.0 / (1000.0 + 25.0); |
| 794 | LongCngWithClockDrift(kDriftFactor); |
| 795 | } |
| 796 | |
| 797 | // TODO(hlundin): Re-enable this test and fix the issues to make it pass. |
henrik.lundin@webrtc.org | ed865b5 | 2014-03-06 10:28:07 +0000 | [diff] [blame] | 798 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(LongCngWithPositiveClockDrift)) { |
henrik.lundin@webrtc.org | fcfc6a9 | 2014-02-13 11:42:28 +0000 | [diff] [blame] | 799 | // Apply a clock drift of +25 ms / s (sender slower than receiver). |
| 800 | const double kDriftFactor = 1000.0 / (1000.0 - 25.0); |
| 801 | LongCngWithClockDrift(kDriftFactor); |
| 802 | } |
| 803 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 804 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(UnknownPayloadType)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 805 | const int kPayloadBytes = 100; |
| 806 | uint8_t payload[kPayloadBytes] = {0}; |
| 807 | WebRtcRTPHeader rtp_info; |
| 808 | PopulateRtpInfo(0, 0, &rtp_info); |
| 809 | rtp_info.header.payloadType = 1; // Not registered as a decoder. |
| 810 | EXPECT_EQ(NetEq::kFail, |
| 811 | neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 812 | EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); |
| 813 | } |
| 814 | |
minyue@webrtc.org | 7bb5436 | 2013-08-06 05:40:57 +0000 | [diff] [blame] | 815 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(OversizePacket)) { |
| 816 | // Payload size is greater than packet buffer size |
| 817 | const int kPayloadBytes = NetEq::kMaxBytesInBuffer + 1; |
| 818 | uint8_t payload[kPayloadBytes] = {0}; |
| 819 | WebRtcRTPHeader rtp_info; |
| 820 | PopulateRtpInfo(0, 0, &rtp_info); |
| 821 | rtp_info.header.payloadType = 103; // iSAC, no packet splitting. |
| 822 | EXPECT_EQ(NetEq::kFail, |
| 823 | neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 824 | EXPECT_EQ(NetEq::kOversizePacket, neteq_->LastError()); |
| 825 | } |
| 826 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 827 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(DecoderError)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 828 | const int kPayloadBytes = 100; |
| 829 | uint8_t payload[kPayloadBytes] = {0}; |
| 830 | WebRtcRTPHeader rtp_info; |
| 831 | PopulateRtpInfo(0, 0, &rtp_info); |
| 832 | rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid. |
| 833 | EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); |
| 834 | NetEqOutputType type; |
| 835 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 836 | // to GetAudio. |
| 837 | for (int i = 0; i < kMaxBlockSize; ++i) { |
| 838 | out_data_[i] = 1; |
| 839 | } |
| 840 | int num_channels; |
| 841 | int samples_per_channel; |
| 842 | EXPECT_EQ(NetEq::kFail, |
| 843 | neteq_->GetAudio(kMaxBlockSize, out_data_, |
| 844 | &samples_per_channel, &num_channels, &type)); |
| 845 | // Verify that there is a decoder error to check. |
| 846 | EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); |
| 847 | // Code 6730 is an iSAC error code. |
| 848 | EXPECT_EQ(6730, neteq_->LastDecoderError()); |
| 849 | // Verify that the first 160 samples are set to 0, and that the remaining |
| 850 | // samples are left unmodified. |
| 851 | static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. |
| 852 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
| 853 | std::ostringstream ss; |
| 854 | ss << "i = " << i; |
| 855 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
| 856 | EXPECT_EQ(0, out_data_[i]); |
| 857 | } |
| 858 | for (int i = kExpectedOutputLength; i < kMaxBlockSize; ++i) { |
| 859 | std::ostringstream ss; |
| 860 | ss << "i = " << i; |
| 861 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
| 862 | EXPECT_EQ(1, out_data_[i]); |
| 863 | } |
| 864 | } |
| 865 | |
henrike@webrtc.org | a950300b | 2013-07-08 18:53:54 +0000 | [diff] [blame] | 866 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(GetAudioBeforeInsertPacket)) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 867 | NetEqOutputType type; |
| 868 | // Set all of |out_data_| to 1, and verify that it was set to 0 by the call |
| 869 | // to GetAudio. |
| 870 | for (int i = 0; i < kMaxBlockSize; ++i) { |
| 871 | out_data_[i] = 1; |
| 872 | } |
| 873 | int num_channels; |
| 874 | int samples_per_channel; |
| 875 | EXPECT_EQ(0, neteq_->GetAudio(kMaxBlockSize, out_data_, |
| 876 | &samples_per_channel, |
| 877 | &num_channels, &type)); |
| 878 | // Verify that the first block of samples is set to 0. |
| 879 | static const int kExpectedOutputLength = |
| 880 | kInitSampleRateHz / 100; // 10 ms at initial sample rate. |
| 881 | for (int i = 0; i < kExpectedOutputLength; ++i) { |
| 882 | std::ostringstream ss; |
| 883 | ss << "i = " << i; |
| 884 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
| 885 | EXPECT_EQ(0, out_data_[i]); |
| 886 | } |
| 887 | } |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 888 | |
turaj@webrtc.org | 3fdeddb | 2013-09-25 22:19:22 +0000 | [diff] [blame] | 889 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(BackgroundNoise)) { |
turaj@webrtc.org | ff43c85 | 2013-09-25 00:07:27 +0000 | [diff] [blame] | 890 | neteq_->SetBackgroundNoiseMode(kBgnOn); |
| 891 | CheckBgnOff(8000, kBgnOn); |
| 892 | CheckBgnOff(16000, kBgnOn); |
| 893 | CheckBgnOff(32000, kBgnOn); |
| 894 | EXPECT_EQ(kBgnOn, neteq_->BackgroundNoiseMode()); |
| 895 | |
| 896 | neteq_->SetBackgroundNoiseMode(kBgnOff); |
| 897 | CheckBgnOff(8000, kBgnOff); |
| 898 | CheckBgnOff(16000, kBgnOff); |
| 899 | CheckBgnOff(32000, kBgnOff); |
| 900 | EXPECT_EQ(kBgnOff, neteq_->BackgroundNoiseMode()); |
| 901 | |
| 902 | neteq_->SetBackgroundNoiseMode(kBgnFade); |
| 903 | CheckBgnOff(8000, kBgnFade); |
| 904 | CheckBgnOff(16000, kBgnFade); |
| 905 | CheckBgnOff(32000, kBgnFade); |
| 906 | EXPECT_EQ(kBgnFade, neteq_->BackgroundNoiseMode()); |
| 907 | } |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 908 | |
| 909 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(SyncPacketInsert)) { |
| 910 | WebRtcRTPHeader rtp_info; |
| 911 | uint32_t receive_timestamp = 0; |
| 912 | // For the readability use the following payloads instead of the defaults of |
| 913 | // this test. |
| 914 | uint8_t kPcm16WbPayloadType = 1; |
| 915 | uint8_t kCngNbPayloadType = 2; |
| 916 | uint8_t kCngWbPayloadType = 3; |
| 917 | uint8_t kCngSwb32PayloadType = 4; |
| 918 | uint8_t kCngSwb48PayloadType = 5; |
| 919 | uint8_t kAvtPayloadType = 6; |
| 920 | uint8_t kRedPayloadType = 7; |
| 921 | uint8_t kIsacPayloadType = 9; // Payload type 8 is already registered. |
| 922 | |
| 923 | // Register decoders. |
| 924 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderPCM16Bwb, |
| 925 | kPcm16WbPayloadType)); |
| 926 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGnb, kCngNbPayloadType)); |
| 927 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGwb, kCngWbPayloadType)); |
| 928 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGswb32kHz, |
| 929 | kCngSwb32PayloadType)); |
| 930 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderCNGswb48kHz, |
| 931 | kCngSwb48PayloadType)); |
| 932 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderAVT, kAvtPayloadType)); |
| 933 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderRED, kRedPayloadType)); |
| 934 | ASSERT_EQ(0, neteq_->RegisterPayloadType(kDecoderISAC, kIsacPayloadType)); |
| 935 | |
| 936 | PopulateRtpInfo(0, 0, &rtp_info); |
| 937 | rtp_info.header.payloadType = kPcm16WbPayloadType; |
| 938 | |
| 939 | // The first packet injected cannot be sync-packet. |
| 940 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 941 | |
| 942 | // Payload length of 10 ms PCM16 16 kHz. |
| 943 | const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
| 944 | uint8_t payload[kPayloadBytes] = {0}; |
| 945 | ASSERT_EQ(0, neteq_->InsertPacket( |
| 946 | rtp_info, payload, kPayloadBytes, receive_timestamp)); |
| 947 | |
| 948 | // Next packet. Last packet contained 10 ms audio. |
| 949 | rtp_info.header.sequenceNumber++; |
| 950 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 951 | receive_timestamp += kBlockSize16kHz; |
| 952 | |
| 953 | // Unacceptable payload types CNG, AVT (DTMF), RED. |
| 954 | rtp_info.header.payloadType = kCngNbPayloadType; |
| 955 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 956 | |
| 957 | rtp_info.header.payloadType = kCngWbPayloadType; |
| 958 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 959 | |
| 960 | rtp_info.header.payloadType = kCngSwb32PayloadType; |
| 961 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 962 | |
| 963 | rtp_info.header.payloadType = kCngSwb48PayloadType; |
| 964 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 965 | |
| 966 | rtp_info.header.payloadType = kAvtPayloadType; |
| 967 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 968 | |
| 969 | rtp_info.header.payloadType = kRedPayloadType; |
| 970 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 971 | |
| 972 | // Change of codec cannot be initiated with a sync packet. |
| 973 | rtp_info.header.payloadType = kIsacPayloadType; |
| 974 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 975 | |
| 976 | // Change of SSRC is not allowed with a sync packet. |
| 977 | rtp_info.header.payloadType = kPcm16WbPayloadType; |
| 978 | ++rtp_info.header.ssrc; |
| 979 | EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 980 | |
| 981 | --rtp_info.header.ssrc; |
| 982 | EXPECT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 983 | } |
| 984 | |
| 985 | // First insert several noise like packets, then sync-packets. Decoding all |
| 986 | // packets should not produce error, statistics should not show any packet loss |
| 987 | // and sync-packets should decode to zero. |
| 988 | TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(SyncPacketDecode)) { |
| 989 | WebRtcRTPHeader rtp_info; |
| 990 | PopulateRtpInfo(0, 0, &rtp_info); |
| 991 | const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
| 992 | uint8_t payload[kPayloadBytes]; |
| 993 | int16_t decoded[kBlockSize16kHz]; |
| 994 | for (int n = 0; n < kPayloadBytes; ++n) { |
| 995 | payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
| 996 | } |
| 997 | // Insert some packets which decode to noise. We are not interested in |
| 998 | // actual decoded values. |
| 999 | NetEqOutputType output_type; |
| 1000 | int num_channels; |
| 1001 | int samples_per_channel; |
| 1002 | uint32_t receive_timestamp = 0; |
| 1003 | int delay_samples = 0; |
| 1004 | for (int n = 0; n < 100; ++n) { |
| 1005 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
| 1006 | receive_timestamp)); |
| 1007 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1008 | &samples_per_channel, &num_channels, |
| 1009 | &output_type)); |
| 1010 | ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
| 1011 | ASSERT_EQ(1, num_channels); |
| 1012 | |
| 1013 | // Even if there is RTP packet in NetEq's buffer, the first frame pulled |
| 1014 | // from NetEq starts with few zero samples. Here we measure this delay. |
| 1015 | if (n == 0) { |
henrik.lundin@webrtc.org | e7ce437 | 2014-01-09 14:01:55 +0000 | [diff] [blame] | 1016 | while (decoded[delay_samples] == 0) delay_samples++; |
turaj@webrtc.org | 7b75ac6 | 2013-09-26 00:27:56 +0000 | [diff] [blame] | 1017 | } |
| 1018 | rtp_info.header.sequenceNumber++; |
| 1019 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 1020 | receive_timestamp += kBlockSize16kHz; |
| 1021 | } |
| 1022 | const int kNumSyncPackets = 10; |
| 1023 | // Insert sync-packets, the decoded sequence should be all-zero. |
| 1024 | for (int n = 0; n < kNumSyncPackets; ++n) { |
| 1025 | ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 1026 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1027 | &samples_per_channel, &num_channels, |
| 1028 | &output_type)); |
| 1029 | ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
| 1030 | ASSERT_EQ(1, num_channels); |
| 1031 | EXPECT_TRUE(IsAllZero(&decoded[delay_samples], |
| 1032 | samples_per_channel * num_channels - delay_samples)); |
| 1033 | delay_samples = 0; // Delay only matters in the first frame. |
| 1034 | rtp_info.header.sequenceNumber++; |
| 1035 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 1036 | receive_timestamp += kBlockSize16kHz; |
| 1037 | } |
| 1038 | // We insert a regular packet, if sync packet are not correctly buffered then |
| 1039 | // network statistics would show some packet loss. |
| 1040 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
| 1041 | receive_timestamp)); |
| 1042 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1043 | &samples_per_channel, &num_channels, |
| 1044 | &output_type)); |
| 1045 | // Make sure the last inserted packet is decoded and there are non-zero |
| 1046 | // samples. |
| 1047 | EXPECT_FALSE(IsAllZero(decoded, samples_per_channel * num_channels)); |
| 1048 | NetEqNetworkStatistics network_stats; |
| 1049 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 1050 | // Expecting a "clean" network. |
| 1051 | EXPECT_EQ(0, network_stats.packet_loss_rate); |
| 1052 | EXPECT_EQ(0, network_stats.expand_rate); |
| 1053 | EXPECT_EQ(0, network_stats.accelerate_rate); |
| 1054 | EXPECT_EQ(0, network_stats.preemptive_rate); |
| 1055 | } |
| 1056 | |
| 1057 | // Test if the size of the packet buffer reported correctly when containing |
| 1058 | // sync packets. Also, test if network packets override sync packets. That is to |
| 1059 | // prefer decoding a network packet to a sync packet, if both have same sequence |
| 1060 | // number and timestamp. |
| 1061 | TEST_F(NetEqDecodingTest, |
| 1062 | DISABLED_ON_ANDROID(SyncPacketBufferSizeAndOverridenByNetworkPackets)) { |
| 1063 | WebRtcRTPHeader rtp_info; |
| 1064 | PopulateRtpInfo(0, 0, &rtp_info); |
| 1065 | const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t); |
| 1066 | uint8_t payload[kPayloadBytes]; |
| 1067 | int16_t decoded[kBlockSize16kHz]; |
| 1068 | for (int n = 0; n < kPayloadBytes; ++n) { |
| 1069 | payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence. |
| 1070 | } |
| 1071 | // Insert some packets which decode to noise. We are not interested in |
| 1072 | // actual decoded values. |
| 1073 | NetEqOutputType output_type; |
| 1074 | int num_channels; |
| 1075 | int samples_per_channel; |
| 1076 | uint32_t receive_timestamp = 0; |
| 1077 | for (int n = 0; n < 1; ++n) { |
| 1078 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
| 1079 | receive_timestamp)); |
| 1080 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1081 | &samples_per_channel, &num_channels, |
| 1082 | &output_type)); |
| 1083 | ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
| 1084 | ASSERT_EQ(1, num_channels); |
| 1085 | rtp_info.header.sequenceNumber++; |
| 1086 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 1087 | receive_timestamp += kBlockSize16kHz; |
| 1088 | } |
| 1089 | const int kNumSyncPackets = 10; |
| 1090 | |
| 1091 | WebRtcRTPHeader first_sync_packet_rtp_info; |
| 1092 | memcpy(&first_sync_packet_rtp_info, &rtp_info, sizeof(rtp_info)); |
| 1093 | |
| 1094 | // Insert sync-packets, but no decoding. |
| 1095 | for (int n = 0; n < kNumSyncPackets; ++n) { |
| 1096 | ASSERT_EQ(0, neteq_->InsertSyncPacket(rtp_info, receive_timestamp)); |
| 1097 | rtp_info.header.sequenceNumber++; |
| 1098 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 1099 | receive_timestamp += kBlockSize16kHz; |
| 1100 | } |
| 1101 | NetEqNetworkStatistics network_stats; |
| 1102 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 1103 | EXPECT_EQ(kNumSyncPackets * 10, network_stats.current_buffer_size_ms); |
| 1104 | |
| 1105 | // Rewind |rtp_info| to that of the first sync packet. |
| 1106 | memcpy(&rtp_info, &first_sync_packet_rtp_info, sizeof(rtp_info)); |
| 1107 | |
| 1108 | // Insert. |
| 1109 | for (int n = 0; n < kNumSyncPackets; ++n) { |
| 1110 | ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
| 1111 | receive_timestamp)); |
| 1112 | rtp_info.header.sequenceNumber++; |
| 1113 | rtp_info.header.timestamp += kBlockSize16kHz; |
| 1114 | receive_timestamp += kBlockSize16kHz; |
| 1115 | } |
| 1116 | |
| 1117 | // Decode. |
| 1118 | for (int n = 0; n < kNumSyncPackets; ++n) { |
| 1119 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1120 | &samples_per_channel, &num_channels, |
| 1121 | &output_type)); |
| 1122 | ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
| 1123 | ASSERT_EQ(1, num_channels); |
| 1124 | EXPECT_TRUE(IsAllNonZero(decoded, samples_per_channel * num_channels)); |
| 1125 | } |
| 1126 | } |
| 1127 | |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1128 | void NetEqDecodingTest::WrapTest(uint16_t start_seq_no, |
| 1129 | uint32_t start_timestamp, |
| 1130 | const std::set<uint16_t>& drop_seq_numbers, |
| 1131 | bool expect_seq_no_wrap, |
| 1132 | bool expect_timestamp_wrap) { |
| 1133 | uint16_t seq_no = start_seq_no; |
| 1134 | uint32_t timestamp = start_timestamp; |
| 1135 | const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame. |
| 1136 | const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs; |
| 1137 | const int kSamples = kBlockSize16kHz * kBlocksPerFrame; |
| 1138 | const int kPayloadBytes = kSamples * sizeof(int16_t); |
| 1139 | double next_input_time_ms = 0.0; |
| 1140 | int16_t decoded[kBlockSize16kHz]; |
| 1141 | int num_channels; |
| 1142 | int samples_per_channel; |
| 1143 | NetEqOutputType output_type; |
| 1144 | uint32_t receive_timestamp = 0; |
| 1145 | |
| 1146 | // Insert speech for 1 second. |
| 1147 | const int kSpeechDurationMs = 2000; |
| 1148 | int packets_inserted = 0; |
| 1149 | uint16_t last_seq_no; |
| 1150 | uint32_t last_timestamp; |
| 1151 | bool timestamp_wrapped = false; |
| 1152 | bool seq_no_wrapped = false; |
| 1153 | for (double t_ms = 0; t_ms < kSpeechDurationMs; t_ms += 10) { |
| 1154 | // Each turn in this for loop is 10 ms. |
| 1155 | while (next_input_time_ms <= t_ms) { |
| 1156 | // Insert one 30 ms speech frame. |
| 1157 | uint8_t payload[kPayloadBytes] = {0}; |
| 1158 | WebRtcRTPHeader rtp_info; |
| 1159 | PopulateRtpInfo(seq_no, timestamp, &rtp_info); |
| 1160 | if (drop_seq_numbers.find(seq_no) == drop_seq_numbers.end()) { |
| 1161 | // This sequence number was not in the set to drop. Insert it. |
| 1162 | ASSERT_EQ(0, |
| 1163 | neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, |
| 1164 | receive_timestamp)); |
| 1165 | ++packets_inserted; |
| 1166 | } |
| 1167 | NetEqNetworkStatistics network_stats; |
| 1168 | ASSERT_EQ(0, neteq_->NetworkStatistics(&network_stats)); |
| 1169 | |
| 1170 | // Due to internal NetEq logic, preferred buffer-size is about 4 times the |
| 1171 | // packet size for first few packets. Therefore we refrain from checking |
| 1172 | // the criteria. |
| 1173 | if (packets_inserted > 4) { |
| 1174 | // Expect preferred and actual buffer size to be no more than 2 frames. |
| 1175 | EXPECT_LE(network_stats.preferred_buffer_size_ms, kFrameSizeMs * 2); |
| 1176 | EXPECT_LE(network_stats.current_buffer_size_ms, kFrameSizeMs * 2); |
| 1177 | } |
| 1178 | last_seq_no = seq_no; |
| 1179 | last_timestamp = timestamp; |
| 1180 | |
| 1181 | ++seq_no; |
| 1182 | timestamp += kSamples; |
| 1183 | receive_timestamp += kSamples; |
| 1184 | next_input_time_ms += static_cast<double>(kFrameSizeMs); |
| 1185 | |
| 1186 | seq_no_wrapped |= seq_no < last_seq_no; |
| 1187 | timestamp_wrapped |= timestamp < last_timestamp; |
| 1188 | } |
| 1189 | // Pull out data once. |
| 1190 | ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded, |
| 1191 | &samples_per_channel, &num_channels, |
| 1192 | &output_type)); |
| 1193 | ASSERT_EQ(kBlockSize16kHz, samples_per_channel); |
| 1194 | ASSERT_EQ(1, num_channels); |
| 1195 | |
| 1196 | // Expect delay (in samples) to be less than 2 packets. |
| 1197 | EXPECT_LE(timestamp - neteq_->PlayoutTimestamp(), |
| 1198 | static_cast<uint32_t>(kSamples * 2)); |
turaj@webrtc.org | 78b41a0 | 2013-11-22 20:27:07 +0000 | [diff] [blame] | 1199 | } |
| 1200 | // Make sure we have actually tested wrap-around. |
| 1201 | ASSERT_EQ(expect_seq_no_wrap, seq_no_wrapped); |
| 1202 | ASSERT_EQ(expect_timestamp_wrap, timestamp_wrapped); |
| 1203 | } |
| 1204 | |
| 1205 | TEST_F(NetEqDecodingTest, SequenceNumberWrap) { |
| 1206 | // Start with a sequence number that will soon wrap. |
| 1207 | std::set<uint16_t> drop_seq_numbers; // Don't drop any packets. |
| 1208 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1209 | } |
| 1210 | |
| 1211 | TEST_F(NetEqDecodingTest, SequenceNumberWrapAndDrop) { |
| 1212 | // Start with a sequence number that will soon wrap. |
| 1213 | std::set<uint16_t> drop_seq_numbers; |
| 1214 | drop_seq_numbers.insert(0xFFFF); |
| 1215 | drop_seq_numbers.insert(0x0); |
| 1216 | WrapTest(0xFFFF - 10, 0, drop_seq_numbers, true, false); |
| 1217 | } |
| 1218 | |
| 1219 | TEST_F(NetEqDecodingTest, TimestampWrap) { |
| 1220 | // Start with a timestamp that will soon wrap. |
| 1221 | std::set<uint16_t> drop_seq_numbers; |
| 1222 | WrapTest(0, 0xFFFFFFFF - 3000, drop_seq_numbers, false, true); |
| 1223 | } |
| 1224 | |
| 1225 | TEST_F(NetEqDecodingTest, TimestampAndSequenceNumberWrap) { |
| 1226 | // Start with a timestamp and a sequence number that will wrap at the same |
| 1227 | // time. |
| 1228 | std::set<uint16_t> drop_seq_numbers; |
| 1229 | WrapTest(0xFFFF - 10, 0xFFFFFFFF - 5000, drop_seq_numbers, true, true); |
| 1230 | } |
| 1231 | |
henrik.lundin@webrtc.org | e7ce437 | 2014-01-09 14:01:55 +0000 | [diff] [blame] | 1232 | } // namespace webrtc |