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