henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | // Test to verify correct stereo and multi-channel operation. |
| 12 | |
henrik.lundin@webrtc.org | be50ab6 | 2014-03-04 15:10:03 +0000 | [diff] [blame] | 13 | #include <algorithm> |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 14 | #include <memory> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <list> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 19 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" |
| 21 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 22 | #include "modules/audio_coding/neteq/tools/input_audio_file.h" |
| 23 | #include "modules/audio_coding/neteq/tools/rtp_generator.h" |
| 24 | #include "modules/include/module_common_types.h" |
| 25 | #include "test/gtest.h" |
| 26 | #include "test/testsupport/fileutils.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | struct TestParameters { |
| 31 | int frame_size; |
| 32 | int sample_rate; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 33 | size_t num_channels; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | // This is a parameterized test. The test parameters are supplied through a |
| 37 | // TestParameters struct, which is obtained through the GetParam() method. |
| 38 | // |
| 39 | // The objective of the test is to create a mono input signal and a |
| 40 | // multi-channel input signal, where each channel is identical to the mono |
| 41 | // input channel. The two input signals are processed through their respective |
| 42 | // NetEq instances. After that, the output signals are compared. The expected |
| 43 | // result is that each channel in the multi-channel output is identical to the |
| 44 | // mono output. |
| 45 | class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> { |
| 46 | protected: |
| 47 | static const int kTimeStepMs = 10; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 48 | static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz. |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 49 | static const uint8_t kPayloadTypeMono = 95; |
| 50 | static const uint8_t kPayloadTypeMulti = 96; |
| 51 | |
| 52 | NetEqStereoTest() |
| 53 | : num_channels_(GetParam().num_channels), |
| 54 | sample_rate_hz_(GetParam().sample_rate), |
| 55 | samples_per_ms_(sample_rate_hz_ / 1000), |
| 56 | frame_size_ms_(GetParam().frame_size), |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 57 | frame_size_samples_( |
| 58 | static_cast<size_t>(frame_size_ms_ * samples_per_ms_)), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 59 | output_size_samples_(10 * samples_per_ms_), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 60 | rtp_generator_mono_(samples_per_ms_), |
| 61 | rtp_generator_(samples_per_ms_), |
| 62 | payload_size_bytes_(0), |
| 63 | multi_payload_size_bytes_(0), |
| 64 | last_send_time_(0), |
| 65 | last_arrival_time_(0) { |
henrik.lundin@webrtc.org | 35ead38 | 2014-04-14 18:49:17 +0000 | [diff] [blame] | 66 | NetEq::Config config; |
| 67 | config.sample_rate_hz = sample_rate_hz_; |
ossu | e352578 | 2016-05-25 07:37:43 -0700 | [diff] [blame] | 68 | rtc::scoped_refptr<AudioDecoderFactory> factory = |
| 69 | CreateBuiltinAudioDecoderFactory(); |
| 70 | neteq_mono_ = NetEq::Create(config, factory); |
| 71 | neteq_ = NetEq::Create(config, factory); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 72 | input_ = new int16_t[frame_size_samples_]; |
| 73 | encoded_ = new uint8_t[2 * frame_size_samples_]; |
| 74 | input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_]; |
| 75 | encoded_multi_channel_ = new uint8_t[frame_size_samples_ * 2 * |
| 76 | num_channels_]; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | ~NetEqStereoTest() { |
| 80 | delete neteq_mono_; |
| 81 | delete neteq_; |
| 82 | delete [] input_; |
| 83 | delete [] encoded_; |
| 84 | delete [] input_multi_channel_; |
| 85 | delete [] encoded_multi_channel_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | virtual void SetUp() { |
| 89 | const std::string file_name = |
| 90 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 91 | input_file_.reset(new test::InputAudioFile(file_name)); |
| 92 | NetEqDecoder mono_decoder; |
| 93 | NetEqDecoder multi_decoder; |
| 94 | switch (sample_rate_hz_) { |
| 95 | case 8000: |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 96 | mono_decoder = NetEqDecoder::kDecoderPCM16B; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 97 | if (num_channels_ == 2) { |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 98 | multi_decoder = NetEqDecoder::kDecoderPCM16B_2ch; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 99 | } else if (num_channels_ == 5) { |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 100 | multi_decoder = NetEqDecoder::kDecoderPCM16B_5ch; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 101 | } else { |
| 102 | FAIL() << "Only 2 and 5 channels supported for 8000 Hz."; |
| 103 | } |
| 104 | break; |
| 105 | case 16000: |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 106 | mono_decoder = NetEqDecoder::kDecoderPCM16Bwb; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 107 | if (num_channels_ == 2) { |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 108 | multi_decoder = NetEqDecoder::kDecoderPCM16Bwb_2ch; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 109 | } else { |
| 110 | FAIL() << "More than 2 channels is not supported for 16000 Hz."; |
| 111 | } |
| 112 | break; |
| 113 | case 32000: |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 114 | mono_decoder = NetEqDecoder::kDecoderPCM16Bswb32kHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 115 | if (num_channels_ == 2) { |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 116 | multi_decoder = NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 117 | } else { |
| 118 | FAIL() << "More than 2 channels is not supported for 32000 Hz."; |
| 119 | } |
| 120 | break; |
| 121 | case 48000: |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 122 | mono_decoder = NetEqDecoder::kDecoderPCM16Bswb48kHz; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 123 | if (num_channels_ == 2) { |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 124 | multi_decoder = NetEqDecoder::kDecoderPCM16Bswb48kHz_2ch; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 125 | } else { |
| 126 | FAIL() << "More than 2 channels is not supported for 48000 Hz."; |
| 127 | } |
| 128 | break; |
| 129 | default: |
| 130 | FAIL() << "We shouldn't get here."; |
| 131 | } |
henrik.lundin | 4cf61dd | 2015-12-09 06:20:58 -0800 | [diff] [blame] | 132 | ASSERT_EQ(NetEq::kOK, neteq_mono_->RegisterPayloadType(mono_decoder, "mono", |
| 133 | kPayloadTypeMono)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 134 | ASSERT_EQ(NetEq::kOK, |
henrik.lundin | 4cf61dd | 2015-12-09 06:20:58 -0800 | [diff] [blame] | 135 | neteq_->RegisterPayloadType(multi_decoder, "multi-channel", |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 136 | kPayloadTypeMulti)); |
| 137 | } |
| 138 | |
| 139 | virtual void TearDown() {} |
| 140 | |
| 141 | int GetNewPackets() { |
| 142 | if (!input_file_->Read(frame_size_samples_, input_)) { |
| 143 | return -1; |
| 144 | } |
| 145 | payload_size_bytes_ = WebRtcPcm16b_Encode(input_, frame_size_samples_, |
| 146 | encoded_); |
| 147 | if (frame_size_samples_ * 2 != payload_size_bytes_) { |
| 148 | return -1; |
| 149 | } |
| 150 | int next_send_time = rtp_generator_mono_.GetRtpHeader(kPayloadTypeMono, |
| 151 | frame_size_samples_, |
| 152 | &rtp_header_mono_); |
| 153 | test::InputAudioFile::DuplicateInterleaved(input_, frame_size_samples_, |
| 154 | num_channels_, |
| 155 | input_multi_channel_); |
| 156 | multi_payload_size_bytes_ = WebRtcPcm16b_Encode( |
| 157 | input_multi_channel_, frame_size_samples_ * num_channels_, |
| 158 | encoded_multi_channel_); |
| 159 | if (frame_size_samples_ * 2 * num_channels_ != multi_payload_size_bytes_) { |
| 160 | return -1; |
| 161 | } |
| 162 | rtp_generator_.GetRtpHeader(kPayloadTypeMulti, frame_size_samples_, |
| 163 | &rtp_header_); |
| 164 | return next_send_time; |
| 165 | } |
| 166 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 167 | virtual void VerifyOutput(size_t num_samples) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 168 | const int16_t* output_data = output_.data(); |
| 169 | const int16_t* output_multi_channel_data = output_multi_channel_.data(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 170 | for (size_t i = 0; i < num_samples; ++i) { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 171 | for (size_t j = 0; j < num_channels_; ++j) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 172 | ASSERT_EQ(output_data[i], |
| 173 | output_multi_channel_data[i * num_channels_ + j]) |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 174 | << "Diff in sample " << i << ", channel " << j << "."; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | virtual int GetArrivalTime(int send_time) { |
| 180 | int arrival_time = last_arrival_time_ + (send_time - last_send_time_); |
| 181 | last_send_time_ = send_time; |
| 182 | last_arrival_time_ = arrival_time; |
| 183 | return arrival_time; |
| 184 | } |
| 185 | |
| 186 | virtual bool Lost() { return false; } |
| 187 | |
| 188 | void RunTest(int num_loops) { |
| 189 | // Get next input packets (mono and multi-channel). |
| 190 | int next_send_time; |
| 191 | int next_arrival_time; |
| 192 | do { |
| 193 | next_send_time = GetNewPackets(); |
| 194 | ASSERT_NE(-1, next_send_time); |
| 195 | next_arrival_time = GetArrivalTime(next_send_time); |
| 196 | } while (Lost()); // If lost, immediately read the next packet. |
| 197 | |
| 198 | int time_now = 0; |
| 199 | for (int k = 0; k < num_loops; ++k) { |
| 200 | while (time_now >= next_arrival_time) { |
| 201 | // Insert packet in mono instance. |
| 202 | ASSERT_EQ(NetEq::kOK, |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 203 | neteq_mono_->InsertPacket(rtp_header_mono_, |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 204 | rtc::ArrayView<const uint8_t>( |
| 205 | encoded_, payload_size_bytes_), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 206 | next_arrival_time)); |
| 207 | // Insert packet in multi-channel instance. |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 208 | ASSERT_EQ(NetEq::kOK, |
| 209 | neteq_->InsertPacket( |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 210 | rtp_header_, |
Henrik Lundin | 70c09bd | 2017-04-24 15:56:56 +0200 | [diff] [blame] | 211 | rtc::ArrayView<const uint8_t>(encoded_multi_channel_, |
| 212 | multi_payload_size_bytes_), |
| 213 | next_arrival_time)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 214 | // Get next input packets (mono and multi-channel). |
| 215 | do { |
| 216 | next_send_time = GetNewPackets(); |
| 217 | ASSERT_NE(-1, next_send_time); |
| 218 | next_arrival_time = GetArrivalTime(next_send_time); |
| 219 | } while (Lost()); // If lost, immediately read the next packet. |
| 220 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 221 | // Get audio from mono instance. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 222 | bool muted; |
| 223 | EXPECT_EQ(NetEq::kOK, neteq_mono_->GetAudio(&output_, &muted)); |
| 224 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 225 | EXPECT_EQ(1u, output_.num_channels_); |
| 226 | EXPECT_EQ(output_size_samples_, output_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 227 | // Get audio from multi-channel instance. |
henrik.lundin | 7a92681 | 2016-05-12 13:51:28 -0700 | [diff] [blame] | 228 | ASSERT_EQ(NetEq::kOK, neteq_->GetAudio(&output_multi_channel_, &muted)); |
| 229 | ASSERT_FALSE(muted); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 230 | EXPECT_EQ(num_channels_, output_multi_channel_.num_channels_); |
| 231 | EXPECT_EQ(output_size_samples_, |
| 232 | output_multi_channel_.samples_per_channel_); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 233 | std::ostringstream ss; |
| 234 | ss << "Lap number " << k << "."; |
| 235 | SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. |
| 236 | // Compare mono and multi-channel. |
| 237 | ASSERT_NO_FATAL_FAILURE(VerifyOutput(output_size_samples_)); |
| 238 | |
| 239 | time_now += kTimeStepMs; |
| 240 | } |
| 241 | } |
| 242 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 243 | const size_t num_channels_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 244 | const int sample_rate_hz_; |
| 245 | const int samples_per_ms_; |
| 246 | const int frame_size_ms_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 247 | const size_t frame_size_samples_; |
| 248 | const size_t output_size_samples_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 249 | NetEq* neteq_mono_; |
| 250 | NetEq* neteq_; |
| 251 | test::RtpGenerator rtp_generator_mono_; |
| 252 | test::RtpGenerator rtp_generator_; |
| 253 | int16_t* input_; |
| 254 | int16_t* input_multi_channel_; |
| 255 | uint8_t* encoded_; |
| 256 | uint8_t* encoded_multi_channel_; |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 257 | AudioFrame output_; |
| 258 | AudioFrame output_multi_channel_; |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 259 | RTPHeader rtp_header_mono_; |
| 260 | RTPHeader rtp_header_; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 261 | size_t payload_size_bytes_; |
| 262 | size_t multi_payload_size_bytes_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 263 | int last_send_time_; |
| 264 | int last_arrival_time_; |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 265 | std::unique_ptr<test::InputAudioFile> input_file_; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | class NetEqStereoTestNoJitter : public NetEqStereoTest { |
| 269 | protected: |
| 270 | NetEqStereoTestNoJitter() |
| 271 | : NetEqStereoTest() { |
| 272 | // Start the sender 100 ms before the receiver to pre-fill the buffer. |
| 273 | // This is to avoid doing preemptive expand early in the test. |
| 274 | // TODO(hlundin): Mock the decision making instead to control the modes. |
| 275 | last_arrival_time_ = -100; |
| 276 | } |
| 277 | }; |
| 278 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 279 | TEST_P(NetEqStereoTestNoJitter, RunTest) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 280 | RunTest(8); |
| 281 | } |
| 282 | |
| 283 | class NetEqStereoTestPositiveDrift : public NetEqStereoTest { |
| 284 | protected: |
| 285 | NetEqStereoTestPositiveDrift() |
| 286 | : NetEqStereoTest(), |
| 287 | drift_factor(0.9) { |
| 288 | // Start the sender 100 ms before the receiver to pre-fill the buffer. |
| 289 | // This is to avoid doing preemptive expand early in the test. |
| 290 | // TODO(hlundin): Mock the decision making instead to control the modes. |
| 291 | last_arrival_time_ = -100; |
| 292 | } |
| 293 | virtual int GetArrivalTime(int send_time) { |
| 294 | int arrival_time = last_arrival_time_ + |
| 295 | drift_factor * (send_time - last_send_time_); |
| 296 | last_send_time_ = send_time; |
| 297 | last_arrival_time_ = arrival_time; |
| 298 | return arrival_time; |
| 299 | } |
| 300 | |
| 301 | double drift_factor; |
| 302 | }; |
| 303 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 304 | TEST_P(NetEqStereoTestPositiveDrift, RunTest) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 305 | RunTest(100); |
| 306 | } |
| 307 | |
| 308 | class NetEqStereoTestNegativeDrift : public NetEqStereoTestPositiveDrift { |
| 309 | protected: |
| 310 | NetEqStereoTestNegativeDrift() |
| 311 | : NetEqStereoTestPositiveDrift() { |
| 312 | drift_factor = 1.1; |
| 313 | last_arrival_time_ = 0; |
| 314 | } |
| 315 | }; |
| 316 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 317 | TEST_P(NetEqStereoTestNegativeDrift, RunTest) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 318 | RunTest(100); |
| 319 | } |
| 320 | |
| 321 | class NetEqStereoTestDelays : public NetEqStereoTest { |
| 322 | protected: |
| 323 | static const int kDelayInterval = 10; |
| 324 | static const int kDelay = 1000; |
| 325 | NetEqStereoTestDelays() |
| 326 | : NetEqStereoTest(), |
| 327 | frame_index_(0) { |
| 328 | } |
| 329 | |
| 330 | virtual int GetArrivalTime(int send_time) { |
| 331 | // Deliver immediately, unless we have a back-log. |
| 332 | int arrival_time = std::min(last_arrival_time_, send_time); |
| 333 | if (++frame_index_ % kDelayInterval == 0) { |
| 334 | // Delay this packet. |
| 335 | arrival_time += kDelay; |
| 336 | } |
| 337 | last_send_time_ = send_time; |
| 338 | last_arrival_time_ = arrival_time; |
| 339 | return arrival_time; |
| 340 | } |
| 341 | |
| 342 | int frame_index_; |
| 343 | }; |
| 344 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 345 | TEST_P(NetEqStereoTestDelays, RunTest) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 346 | RunTest(1000); |
| 347 | } |
| 348 | |
| 349 | class NetEqStereoTestLosses : public NetEqStereoTest { |
| 350 | protected: |
| 351 | static const int kLossInterval = 10; |
| 352 | NetEqStereoTestLosses() |
| 353 | : NetEqStereoTest(), |
| 354 | frame_index_(0) { |
| 355 | } |
| 356 | |
| 357 | virtual bool Lost() { |
| 358 | return (++frame_index_) % kLossInterval == 0; |
| 359 | } |
| 360 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 361 | // TODO(hlundin): NetEq is not giving bitexact results for these cases. |
| 362 | virtual void VerifyOutput(size_t num_samples) { |
| 363 | for (size_t i = 0; i < num_samples; ++i) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 364 | const int16_t* output_data = output_.data(); |
| 365 | const int16_t* output_multi_channel_data = output_multi_channel_.data(); |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 366 | auto first_channel_sample = |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 367 | output_multi_channel_data[i * num_channels_]; |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 368 | for (size_t j = 0; j < num_channels_; ++j) { |
| 369 | const int kErrorMargin = 200; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 370 | EXPECT_NEAR(output_data[i], |
| 371 | output_multi_channel_data[i * num_channels_ + j], |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 372 | kErrorMargin) |
| 373 | << "Diff in sample " << i << ", channel " << j << "."; |
| 374 | EXPECT_EQ(first_channel_sample, |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 375 | output_multi_channel_data[i * num_channels_ + j]); |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 380 | int frame_index_; |
| 381 | }; |
| 382 | |
ivoc | 72c08ed | 2016-01-20 07:26:24 -0800 | [diff] [blame] | 383 | TEST_P(NetEqStereoTestLosses, RunTest) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 384 | RunTest(100); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | // Creates a list of parameter sets. |
| 389 | std::list<TestParameters> GetTestParameters() { |
| 390 | std::list<TestParameters> l; |
| 391 | const int sample_rates[] = {8000, 16000, 32000}; |
| 392 | const int num_rates = sizeof(sample_rates) / sizeof(sample_rates[0]); |
| 393 | // Loop through sample rates. |
| 394 | for (int rate_index = 0; rate_index < num_rates; ++rate_index) { |
| 395 | int sample_rate = sample_rates[rate_index]; |
| 396 | // Loop through all frame sizes between 10 and 60 ms. |
| 397 | for (int frame_size = 10; frame_size <= 60; frame_size += 10) { |
| 398 | TestParameters p; |
| 399 | p.frame_size = frame_size; |
| 400 | p.sample_rate = sample_rate; |
| 401 | p.num_channels = 2; |
| 402 | l.push_back(p); |
| 403 | if (sample_rate == 8000) { |
| 404 | // Add a five-channel test for 8000 Hz. |
| 405 | p.num_channels = 5; |
| 406 | l.push_back(p); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | return l; |
| 411 | } |
| 412 | |
| 413 | // Pretty-printing the test parameters in case of an error. |
| 414 | void PrintTo(const TestParameters& p, ::std::ostream* os) { |
| 415 | *os << "{frame_size = " << p.frame_size << |
| 416 | ", num_channels = " << p.num_channels << |
| 417 | ", sample_rate = " << p.sample_rate << "}"; |
| 418 | } |
| 419 | |
| 420 | // Instantiate the tests. Each test is instantiated using the function above, |
| 421 | // so that all different parameter combinations are tested. |
| 422 | INSTANTIATE_TEST_CASE_P(MultiChannel, |
| 423 | NetEqStereoTestNoJitter, |
| 424 | ::testing::ValuesIn(GetTestParameters())); |
| 425 | |
| 426 | INSTANTIATE_TEST_CASE_P(MultiChannel, |
| 427 | NetEqStereoTestPositiveDrift, |
| 428 | ::testing::ValuesIn(GetTestParameters())); |
| 429 | |
| 430 | INSTANTIATE_TEST_CASE_P(MultiChannel, |
| 431 | NetEqStereoTestNegativeDrift, |
| 432 | ::testing::ValuesIn(GetTestParameters())); |
| 433 | |
| 434 | INSTANTIATE_TEST_CASE_P(MultiChannel, |
| 435 | NetEqStereoTestDelays, |
| 436 | ::testing::ValuesIn(GetTestParameters())); |
| 437 | |
| 438 | INSTANTIATE_TEST_CASE_P(MultiChannel, |
| 439 | NetEqStereoTestLosses, |
| 440 | ::testing::ValuesIn(GetTestParameters())); |
| 441 | |
| 442 | } // namespace webrtc |