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