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