OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webrtc/base/checks.h" | |
13 extern "C" { | 12 extern "C" { |
14 #include "webrtc/modules/audio_processing/aec/aec_core.h" | 13 #include "webrtc/modules/audio_processing/aec/aec_core.h" |
15 } | 14 } |
16 #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" | 15 #include "webrtc/modules/audio_processing/aec/echo_cancellation_internal.h" |
17 #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" | 16 #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h" |
18 #include "webrtc/test/testsupport/gtest_disable.h" | 17 #include "webrtc/test/testsupport/gtest_disable.h" |
19 #include "webrtc/typedefs.h" | 18 #include "webrtc/typedefs.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 static const int kStableConvergenceMs = 100; | 92 static const int kStableConvergenceMs = 100; |
94 | 93 |
95 // Maximum convergence time in ms. This means that we should leave the startup | 94 // Maximum convergence time in ms. This means that we should leave the startup |
96 // phase after |kMaxConvergenceMs| independent of device buffer stability | 95 // phase after |kMaxConvergenceMs| independent of device buffer stability |
97 // conditions. | 96 // conditions. |
98 static const int kMaxConvergenceMs = 500; | 97 static const int kMaxConvergenceMs = 500; |
99 | 98 |
100 void SystemDelayTest::Init(int sample_rate_hz) { | 99 void SystemDelayTest::Init(int sample_rate_hz) { |
101 // Initialize AEC | 100 // Initialize AEC |
102 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000)); | 101 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000)); |
102 EXPECT_EQ(0, WebRtcAec_system_delay(self_->aec)); | |
103 | 103 |
104 // One frame equals 10 ms of data. | 104 // One frame equals 10 ms of data. |
105 samples_per_frame_ = sample_rate_hz / 100; | 105 samples_per_frame_ = sample_rate_hz / 100; |
106 } | 106 } |
107 | 107 |
108 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) { | 108 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) { |
109 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); | 109 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); |
110 EXPECT_EQ(0, | 110 EXPECT_EQ(0, |
111 WebRtcAec_Process(handle_, | 111 WebRtcAec_Process(handle_, |
112 &near_ptr_, | 112 &near_ptr_, |
(...skipping 15 matching lines...) Expand all Loading... | |
128 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec)); | 128 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec)); |
129 } | 129 } |
130 return buffer_size; | 130 return buffer_size; |
131 } | 131 } |
132 | 132 |
133 void SystemDelayTest::RunStableStartup() { | 133 void SystemDelayTest::RunStableStartup() { |
134 // To make sure we have a full buffer when we verify stability we first fill | 134 // To make sure we have a full buffer when we verify stability we first fill |
135 // up the far-end buffer with the same amount as we will report in through | 135 // up the far-end buffer with the same amount as we will report in through |
136 // Process(). | 136 // Process(). |
137 int buffer_size = BufferFillUp(); | 137 int buffer_size = BufferFillUp(); |
138 // A stable device should be accepted and put in a regular process mode within | 138 |
139 // |kStableConvergenceMs|. | 139 if (WebRtcAec_reported_delay_enabled(self_->aec) == 0) { |
140 int process_time_ms = 0; | 140 // In extended_filter mode we set the buffer size after the first processed |
141 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { | 141 // 10 ms chunk. Hence, we don't need to wait for the reported system delay |
142 // values to become stable. | |
142 RenderAndCapture(kDeviceBufMs); | 143 RenderAndCapture(kDeviceBufMs); |
143 buffer_size += samples_per_frame_; | 144 buffer_size += samples_per_frame_; |
144 if (self_->startup_phase == 0) { | 145 EXPECT_EQ(0, self_->startup_phase); |
145 // We have left the startup phase. | 146 } else { |
146 break; | 147 // A stable device should be accepted and put in a regular process mode |
148 // within |kStableConvergenceMs|. | |
149 int process_time_ms = 0; | |
150 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { | |
151 RenderAndCapture(kDeviceBufMs); | |
152 buffer_size += samples_per_frame_; | |
153 if (self_->startup_phase == 0) { | |
154 // We have left the startup phase. | |
155 break; | |
156 } | |
147 } | 157 } |
158 // Verify convergence time. | |
159 EXPECT_GT(kStableConvergenceMs, process_time_ms); | |
148 } | 160 } |
149 // Verify convergence time. | |
150 EXPECT_GT(kStableConvergenceMs, process_time_ms); | |
151 // Verify that the buffer has been flushed. | 161 // Verify that the buffer has been flushed. |
152 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec)); | 162 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec)); |
153 } | 163 } |
154 | 164 |
155 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms) { | 165 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms) { |
156 // The extra 10 ms corresponds to the unprocessed frame. | 166 // The extra 10 ms corresponds to the unprocessed frame. |
157 return (size_in_ms + 10) * samples_per_frame_ / 10; | 167 return (size_in_ms + 10) * samples_per_frame_ / 10; |
158 } | 168 } |
159 | 169 |
160 // The tests should meet basic requirements and not be adjusted to what is | 170 // The tests should meet basic requirements and not be adjusted to what is |
(...skipping 13 matching lines...) Expand all Loading... | |
174 // |kMaxConvergenceMs| ms. | 184 // |kMaxConvergenceMs| ms. |
175 // 6) If the local buffer runs out of data we should stuff the buffer with older | 185 // 6) If the local buffer runs out of data we should stuff the buffer with older |
176 // frames. | 186 // frames. |
177 // 7) The system delay should within |kMaxConvergenceMs| ms heal from | 187 // 7) The system delay should within |kMaxConvergenceMs| ms heal from |
178 // disturbances like drift, data glitches, toggling events and outliers. | 188 // disturbances like drift, data glitches, toggling events and outliers. |
179 // 8) The system delay should never become negative. | 189 // 8) The system delay should never become negative. |
180 | 190 |
181 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) { | 191 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) { |
182 // When we add data to the AEC buffer the internal system delay should be | 192 // When we add data to the AEC buffer the internal system delay should be |
183 // incremented with the same amount as the size of data. | 193 // incremented with the same amount as the size of data. |
184 for (size_t i = 0; i < kNumSampleRates; i++) { | 194 // This process should be independent of DA-AEC and extended_filter mode. |
185 Init(kSampleRateHz[i]); | 195 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { |
186 | 196 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); |
187 // Loop through a couple of calls to make sure the system delay increments | 197 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); |
hlundin-webrtc
2015/06/17 14:09:18
The parameters should be swapped, right?
EXPECT_EQ
bjornv1
2015/06/17 14:25:18
Done.
| |
188 // correctly. | 198 for (int da_aec = 0; da_aec <= 1; ++da_aec) { |
189 for (int j = 1; j <= 5; j++) { | 199 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); |
190 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); | 200 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); |
hlundin-webrtc
2015/06/17 14:09:18
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
191 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec)); | 201 for (size_t i = 0; i < kNumSampleRates; i++) { |
202 Init(kSampleRateHz[i]); | |
203 // Loop through a couple of calls to make sure the system delay | |
204 // increments correctly. | |
205 for (int j = 1; j <= 5; j++) { | |
206 EXPECT_EQ(0, | |
207 WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); | |
208 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec)); | |
209 } | |
210 } | |
192 } | 211 } |
193 } | 212 } |
194 } | 213 } |
195 | 214 |
196 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full | 215 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full |
197 // when adding new data. | 216 // when adding new data. |
198 | 217 |
199 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) { | 218 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) { |
200 // We run the system in a stable startup. After that we verify that the system | 219 // We run the system in a stable startup. After that we verify that the system |
201 // delay meets the requirements. | 220 // delay meets the requirements. |
202 for (size_t i = 0; i < kNumSampleRates; i++) { | 221 // This process should be independent of DA-AEC and extended_filter mode. |
203 Init(kSampleRateHz[i]); | 222 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { |
204 RunStableStartup(); | 223 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); |
224 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); | |
hlundin-webrtc
2015/06/17 14:09:18
Swap parameters.
bjornv1
2015/06/17 14:25:17
Done.
| |
225 for (int da_aec = 0; da_aec <= 1; ++da_aec) { | |
226 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); | |
227 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
228 for (size_t i = 0; i < kNumSampleRates; i++) { | |
229 Init(kSampleRateHz[i]); | |
230 RunStableStartup(); | |
205 | 231 |
206 // Verify system delay with respect to requirements, i.e., the | 232 // Verify system delay with respect to requirements, i.e., the |
207 // |system_delay| is in the interval [75%, 100%] of what's reported on the | 233 // |system_delay| is in the interval [75%, 100%] of what's reported on |
208 // average. | 234 // the average. |
209 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10; | 235 // In extended_filter mode we target 50% and measure after one processed |
210 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec)); | 236 // 10 ms chunk. |
211 EXPECT_LE(average_reported_delay * 3 / 4, | 237 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10; |
212 WebRtcAec_system_delay(self_->aec)); | 238 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec)); |
239 int lower_bound = WebRtcAec_extended_filter_enabled(self_->aec) | |
240 ? average_reported_delay / 2 - samples_per_frame_ | |
241 : average_reported_delay * 3 / 4; | |
242 EXPECT_LE(lower_bound, WebRtcAec_system_delay(self_->aec)); | |
243 } | |
244 } | |
213 } | 245 } |
214 } | 246 } |
215 | 247 |
216 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) { | 248 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) { |
249 // This test does not apply in extended_filter mode, since we only use the | |
250 // the first 10 ms chunk to determine a reasonable buffer size. Neither does | |
hlundin-webrtc
2015/06/17 14:09:18
does does
bjornv1
2015/06/17 14:25:18
Done.
| |
251 // does it apply if DA-AEC is on because that overrides the startup procedure. | |
252 WebRtcAec_enable_extended_filter(self_->aec, false); | |
253 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
254 WebRtcAec_enable_reported_delay(self_->aec, true); | |
255 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), 1); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
256 | |
217 // In an unstable system we would start processing after |kMaxConvergenceMs|. | 257 // In an unstable system we would start processing after |kMaxConvergenceMs|. |
218 // On the last frame the AEC buffer is adjusted to 60% of the last reported | 258 // On the last frame the AEC buffer is adjusted to 60% of the last reported |
219 // device buffer size. | 259 // device buffer size. |
220 // We construct an unstable system by altering the device buffer size between | 260 // We construct an unstable system by altering the device buffer size between |
221 // two values |kDeviceBufMs| +- 25 ms. | 261 // two values |kDeviceBufMs| +- 25 ms. |
222 for (size_t i = 0; i < kNumSampleRates; i++) { | 262 for (size_t i = 0; i < kNumSampleRates; i++) { |
223 Init(kSampleRateHz[i]); | 263 Init(kSampleRateHz[i]); |
224 | 264 |
225 // To make sure we have a full buffer when we verify stability we first fill | 265 // To make sure we have a full buffer when we verify stability we first fill |
226 // up the far-end buffer with the same amount as we will report in on the | 266 // up the far-end buffer with the same amount as we will report in on the |
(...skipping 20 matching lines...) Expand all Loading... | |
247 | 287 |
248 // Verify system delay with respect to requirements, i.e., the | 288 // Verify system delay with respect to requirements, i.e., the |
249 // |system_delay| is in the interval [60%, 100%] of what's last reported. | 289 // |system_delay| is in the interval [60%, 100%] of what's last reported. |
250 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10, | 290 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10, |
251 WebRtcAec_system_delay(self_->aec)); | 291 WebRtcAec_system_delay(self_->aec)); |
252 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5, | 292 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5, |
253 WebRtcAec_system_delay(self_->aec)); | 293 WebRtcAec_system_delay(self_->aec)); |
254 } | 294 } |
255 } | 295 } |
256 | 296 |
257 TEST_F(SystemDelayTest, | 297 TEST_F(SystemDelayTest, CorrectDelayAfterStableBufferBuildUp) { |
258 DISABLED_ON_ANDROID(CorrectDelayAfterStableBufferBuildUp)) { | 298 // This test does not apply in extended_filter mode, since we only use the |
299 // the first 10 ms chunk to determine a reasonable buffer size. Neither does | |
hlundin-webrtc
2015/06/17 14:09:19
does does
bjornv1
2015/06/17 14:25:18
Done.
| |
300 // does it apply if DA-AEC is on because that overrides the startup procedure. | |
301 WebRtcAec_enable_extended_filter(self_->aec, false); | |
302 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
303 WebRtcAec_enable_reported_delay(self_->aec, true); | |
304 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), 1); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
305 | |
259 // In this test we start by establishing the device buffer size during stable | 306 // In this test we start by establishing the device buffer size during stable |
260 // conditions, but with an empty internal far-end buffer. Once that is done we | 307 // conditions, but with an empty internal far-end buffer. Once that is done we |
261 // verify that the system delay is increased correctly until we have reach an | 308 // verify that the system delay is increased correctly until we have reach an |
262 // internal buffer size of 75% of what's been reported. | 309 // internal buffer size of 75% of what's been reported. |
263 | 310 |
264 // This test assumes the reported delays are used. | |
265 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); | |
266 for (size_t i = 0; i < kNumSampleRates; i++) { | 311 for (size_t i = 0; i < kNumSampleRates; i++) { |
267 Init(kSampleRateHz[i]); | 312 Init(kSampleRateHz[i]); |
268 | 313 |
269 // We assume that running |kStableConvergenceMs| calls will put the | 314 // We assume that running |kStableConvergenceMs| calls will put the |
270 // algorithm in a state where the device buffer size has been determined. We | 315 // algorithm in a state where the device buffer size has been determined. We |
271 // can make that assumption since we have a separate stability test. | 316 // can make that assumption since we have a separate stability test. |
272 int process_time_ms = 0; | 317 int process_time_ms = 0; |
273 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { | 318 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { |
274 EXPECT_EQ(0, | 319 EXPECT_EQ(0, |
275 WebRtcAec_Process(handle_, | 320 WebRtcAec_Process(handle_, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); | 354 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); |
310 } | 355 } |
311 } | 356 } |
312 } | 357 } |
313 | 358 |
314 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) { | 359 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) { |
315 // Here we test a buffer under run scenario. If we keep on calling | 360 // Here we test a buffer under run scenario. If we keep on calling |
316 // WebRtcAec_Process() we will finally run out of data, but should | 361 // WebRtcAec_Process() we will finally run out of data, but should |
317 // automatically stuff the buffer. We verify this behavior by checking if the | 362 // automatically stuff the buffer. We verify this behavior by checking if the |
318 // system delay goes negative. | 363 // system delay goes negative. |
319 for (size_t i = 0; i < kNumSampleRates; i++) { | 364 // This process should be independent of DA-AEC and extended_filter mode. |
320 Init(kSampleRateHz[i]); | 365 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { |
321 RunStableStartup(); | 366 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); |
367 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
368 for (int da_aec = 0; da_aec <= 1; ++da_aec) { | |
369 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); | |
370 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); | |
hlundin-webrtc
2015/06/17 14:09:18
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
371 for (size_t i = 0; i < kNumSampleRates; i++) { | |
372 Init(kSampleRateHz[i]); | |
373 RunStableStartup(); | |
322 | 374 |
323 // The AEC has now left the Startup phase. We now have at most | 375 // The AEC has now left the Startup phase. We now have at most |
324 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until | 376 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until |
325 // we run out of data and verify that the system delay is non-negative. | 377 // we run out of data and verify that the system delay is non-negative. |
326 for (int j = 0; j <= kStableConvergenceMs; j += 10) { | 378 for (int j = 0; j <= kStableConvergenceMs; j += 10) { |
327 EXPECT_EQ(0, | 379 EXPECT_EQ(0, WebRtcAec_Process(handle_, &near_ptr_, 1, &out_ptr_, |
328 WebRtcAec_Process(handle_, | 380 samples_per_frame_, kDeviceBufMs, 0)); |
329 &near_ptr_, | 381 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); |
330 1, | 382 } |
331 &out_ptr_, | 383 } |
332 samples_per_frame_, | |
333 kDeviceBufMs, | |
334 0)); | |
335 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
336 } | 384 } |
337 } | 385 } |
338 } | 386 } |
339 | 387 |
340 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(CorrectDelayDuringDrift)) { | 388 TEST_F(SystemDelayTest, CorrectDelayDuringDrift) { |
341 // This drift test should verify that the system delay is never exceeding the | 389 // This drift test should verify that the system delay is never exceeding the |
342 // device buffer. The drift is simulated by decreasing the reported device | 390 // device buffer. The drift is simulated by decreasing the reported device |
343 // buffer size by 1 ms every 100 ms. If the device buffer size goes below 30 | 391 // buffer size by 1 ms every 100 ms. If the device buffer size goes below 30 |
344 // ms we jump (add) 10 ms to give a repeated pattern. | 392 // ms we jump (add) 10 ms to give a repeated pattern. |
345 | 393 |
346 // This test assumes the reported delays are used. | 394 // This process should be independent of DA-AEC and extended_filter mode. |
347 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); | 395 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { |
348 for (size_t i = 0; i < kNumSampleRates; i++) { | 396 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); |
349 Init(kSampleRateHz[i]); | 397 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
350 RunStableStartup(); | 398 for (int da_aec = 0; da_aec <= 1; ++da_aec) { |
399 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); | |
400 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
401 for (size_t i = 0; i < kNumSampleRates; i++) { | |
402 Init(kSampleRateHz[i]); | |
403 RunStableStartup(); | |
351 | 404 |
352 // We have now left the startup phase and proceed with normal processing. | 405 // We have left the startup phase and proceed with normal processing. |
353 int jump = 0; | 406 int jump = 0; |
354 for (int j = 0; j < 1000; j++) { | 407 for (int j = 0; j < 1000; j++) { |
355 // Drift = -1 ms per 100 ms of data. | 408 // Drift = -1 ms per 100 ms of data. |
356 int device_buf_ms = kDeviceBufMs - (j / 10) + jump; | 409 int device_buf_ms = kDeviceBufMs - (j / 10) + jump; |
357 int device_buf = MapBufferSizeToSamples(device_buf_ms); | 410 int device_buf = MapBufferSizeToSamples(device_buf_ms); |
358 | 411 |
359 if (device_buf_ms < 30) { | 412 if (device_buf_ms < 30) { |
360 // Add 10 ms data, taking affect next frame. | 413 // Add 10 ms data, taking affect next frame. |
361 jump += 10; | 414 jump += 10; |
415 } | |
416 RenderAndCapture(device_buf_ms); | |
417 | |
418 // Verify that the system delay does not exceed the device buffer. | |
419 EXPECT_GE(device_buf, WebRtcAec_system_delay(self_->aec)); | |
420 | |
421 // Verify that the system delay is non-negative. | |
422 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
423 } | |
362 } | 424 } |
363 RenderAndCapture(device_buf_ms); | |
364 | |
365 // Verify that the system delay does not exceed the device buffer. | |
366 EXPECT_GE(device_buf, WebRtcAec_system_delay(self_->aec)); | |
367 | |
368 // Verify that the system delay is non-negative. | |
369 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
370 } | 425 } |
371 } | 426 } |
372 } | 427 } |
373 | 428 |
374 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(ShouldRecoverAfterGlitch)) { | 429 TEST_F(SystemDelayTest, ShouldRecoverAfterGlitch) { |
375 // This glitch test should verify that the system delay recovers if there is | 430 // This glitch test should verify that the system delay recovers if there is |
376 // a glitch in data. The data glitch is constructed as 200 ms of buffering | 431 // a glitch in data. The data glitch is constructed as 200 ms of buffering |
377 // after which the stable procedure continues. The glitch is never reported by | 432 // after which the stable procedure continues. The glitch is never reported by |
378 // the device. | 433 // the device. |
379 // The system is said to be in a non-causal state if the difference between | 434 // The system is said to be in a non-causal state if the difference between |
380 // the device buffer and system delay is less than a block (64 samples). | 435 // the device buffer and system delay is less than a block (64 samples). |
381 | 436 |
382 // This test assumes the reported delays are used. | 437 // This process should be independent of DA-AEC and extended_filter mode. |
383 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); | 438 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { |
384 for (size_t i = 0; i < kNumSampleRates; i++) { | 439 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); |
385 Init(kSampleRateHz[i]); | 440 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
386 RunStableStartup(); | 441 for (int da_aec = 0; da_aec <= 1; ++da_aec) { |
387 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | 442 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); |
388 // Glitch state. | 443 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
389 for (int j = 0; j < 20; j++) { | 444 for (size_t i = 0; i < kNumSampleRates; i++) { |
390 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); | 445 Init(kSampleRateHz[i]); |
391 // No need to verify system delay, since that is done in a separate test. | 446 RunStableStartup(); |
447 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | |
448 // Glitch state. | |
449 for (int j = 0; j < 20; j++) { | |
450 EXPECT_EQ(0, | |
451 WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); | |
452 // No need to verify system delay, since that is done in a separate | |
453 // test. | |
454 } | |
455 // Verify that we are in a non-causal state, i.e., | |
456 // |system_delay| > |device_buf|. | |
457 EXPECT_LT(device_buf, WebRtcAec_system_delay(self_->aec)); | |
458 | |
459 // Recover state. Should recover at least 4 ms of data per 10 ms, hence | |
460 // a glitch of 200 ms will take at most 200 * 10 / 4 = 500 ms to recover | |
461 // from. | |
462 bool non_causal = true; // We are currently in a non-causal state. | |
463 for (int j = 0; j < 50; j++) { | |
464 int system_delay_before = WebRtcAec_system_delay(self_->aec); | |
465 RenderAndCapture(kDeviceBufMs); | |
466 int system_delay_after = WebRtcAec_system_delay(self_->aec); | |
467 int buffer_difference_recovered = PART_LEN * (1 + extended_filter); | |
468 // We have recovered if |device_buf| - |system_delay_after| >= | |
469 // |buffer_difference_recovered| (1-2 blocks). During recovery | |
470 // |system_delay_after| < |system_delay_before|, otherwise they are | |
471 // equal. | |
472 if (non_causal) { | |
473 EXPECT_LT(system_delay_after, system_delay_before); | |
474 if (device_buf - system_delay_after >= | |
475 buffer_difference_recovered) { | |
476 non_causal = false; | |
477 } | |
478 } else { | |
479 EXPECT_EQ(system_delay_before, system_delay_after); | |
480 } | |
481 // Verify that the system delay is non-negative. | |
482 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
483 } | |
484 // Check that we have recovered. | |
485 EXPECT_FALSE(non_causal); | |
486 } | |
392 } | 487 } |
393 // Verify that we are in a non-causal state, i.e., | |
394 // |system_delay| > |device_buf|. | |
395 EXPECT_LT(device_buf, WebRtcAec_system_delay(self_->aec)); | |
396 | |
397 // Recover state. Should recover at least 4 ms of data per 10 ms, hence a | |
398 // glitch of 200 ms will take at most 200 * 10 / 4 = 500 ms to recover from. | |
399 bool non_causal = true; // We are currently in a non-causal state. | |
400 for (int j = 0; j < 50; j++) { | |
401 int system_delay_before = WebRtcAec_system_delay(self_->aec); | |
402 RenderAndCapture(kDeviceBufMs); | |
403 int system_delay_after = WebRtcAec_system_delay(self_->aec); | |
404 | |
405 // We have recovered if |device_buf| - |system_delay_after| >= 64 (one | |
406 // block). During recovery |system_delay_after| < |system_delay_before|, | |
407 // otherwise they are equal. | |
408 if (non_causal) { | |
409 EXPECT_LT(system_delay_after, system_delay_before); | |
410 if (device_buf - system_delay_after >= 64) { | |
411 non_causal = false; | |
412 } | |
413 } else { | |
414 EXPECT_EQ(system_delay_before, system_delay_after); | |
415 } | |
416 // Verify that the system delay is non-negative. | |
417 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
418 } | |
419 // Check that we have recovered. | |
420 EXPECT_FALSE(non_causal); | |
421 } | 488 } |
422 } | 489 } |
423 | 490 |
424 TEST_F(SystemDelayTest, UnaffectedWhenSpuriousDeviceBufferValues) { | 491 TEST_F(SystemDelayTest, UnaffectedWhenSpuriousDeviceBufferValues) { |
425 // This spurious device buffer data test aims at verifying that the system | 492 // This test does not apply in extended_filter mode, since we only use the |
426 // delay is unaffected by large outliers. | 493 // the first 10 ms chunk to determine a reasonable buffer size. |
427 // The system is said to be in a non-causal state if the difference between | 494 WebRtcAec_enable_extended_filter(self_->aec, false); |
428 // the device buffer and system delay is less than a block (64 samples). | 495 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0); |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
429 for (size_t i = 0; i < kNumSampleRates; i++) { | |
430 Init(kSampleRateHz[i]); | |
431 RunStableStartup(); | |
432 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | |
433 | 496 |
434 // Normal state. We are currently not in a non-causal state. | 497 // Should be DA-AEC independent. |
435 bool non_causal = false; | 498 for (int da_aec = 0; da_aec <= 1; ++da_aec) { |
499 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); | |
500 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
501 // This spurious device buffer data test aims at verifying that the system | |
502 // delay is unaffected by large outliers. | |
503 // The system is said to be in a non-causal state if the difference between | |
504 // the device buffer and system delay is less than a block (64 samples). | |
505 for (size_t i = 0; i < kNumSampleRates; i++) { | |
506 Init(kSampleRateHz[i]); | |
507 RunStableStartup(); | |
508 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | |
436 | 509 |
437 // Run 1 s and replace device buffer size with 500 ms every 100 ms. | 510 // Normal state. We are currently not in a non-causal state. |
438 for (int j = 0; j < 100; j++) { | 511 bool non_causal = false; |
439 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec); | 512 |
440 int device_buf_ms = kDeviceBufMs; | 513 // Run 1 s and replace device buffer size with 500 ms every 100 ms. |
441 if (j % 10 == 0) { | 514 for (int j = 0; j < 100; j++) { |
442 device_buf_ms = 500; | 515 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec); |
516 int device_buf_ms = j % 10 == 0 ? 500 : kDeviceBufMs; | |
517 RenderAndCapture(device_buf_ms); | |
518 | |
519 // Check for non-causality. | |
520 if (device_buf - WebRtcAec_system_delay(self_->aec) < PART_LEN) { | |
521 non_causal = true; | |
522 } | |
523 EXPECT_FALSE(non_causal); | |
524 EXPECT_EQ(system_delay_before_calls, | |
525 WebRtcAec_system_delay(self_->aec)); | |
526 | |
527 // Verify that the system delay is non-negative. | |
528 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
443 } | 529 } |
444 RenderAndCapture(device_buf_ms); | |
445 | |
446 // Check for non-causality. | |
447 if (device_buf - WebRtcAec_system_delay(self_->aec) < 64) { | |
448 non_causal = true; | |
449 } | |
450 EXPECT_FALSE(non_causal); | |
451 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); | |
452 | |
453 // Verify that the system delay is non-negative. | |
454 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
455 } | 530 } |
456 } | 531 } |
457 } | 532 } |
458 | 533 |
459 TEST_F(SystemDelayTest, CorrectImpactWhenTogglingDeviceBufferValues) { | 534 TEST_F(SystemDelayTest, CorrectImpactWhenTogglingDeviceBufferValues) { |
460 // This test aims at verifying that the system delay is "unaffected" by | 535 // This test aims at verifying that the system delay is "unaffected" by |
461 // toggling values reported by the device. | 536 // toggling values reported by the device. |
462 // The test is constructed such that every other device buffer value is zero | 537 // The test is constructed such that every other device buffer value is zero |
463 // and then 2 * |kDeviceBufMs|, hence the size is constant on the average. The | 538 // and then 2 * |kDeviceBufMs|, hence the size is constant on the average. The |
464 // zero values will force us into a non-causal state and thereby lowering the | 539 // zero values will force us into a non-causal state and thereby lowering the |
465 // system delay until we basically runs out of data. Once that happens the | 540 // system delay until we basically run out of data. Once that happens the |
466 // buffer will be stuffed. | 541 // buffer will be stuffed. |
467 // TODO(bjornv): This test will have a better impact if we verified that the | 542 // TODO(bjornv): This test will have a better impact if we verified that the |
468 // delay estimate goes up when the system delay goes done to meet the average | 543 // delay estimate goes up when the system delay goes down to meet the average |
469 // device buffer size. | 544 // device buffer size. |
470 for (size_t i = 0; i < kNumSampleRates; i++) { | |
471 Init(kSampleRateHz[i]); | |
472 RunStableStartup(); | |
473 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | |
474 | 545 |
475 // Normal state. We are currently not in a non-causal state. | 546 // This test does not apply if DA-AEC is enabled and extended_filter mode |
476 bool non_causal = false; | 547 // disabled. |
548 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) { | |
549 WebRtcAec_enable_extended_filter(self_->aec, extended_filter); | |
550 EXPECT_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:18
Done.
| |
551 for (int da_aec = 0; da_aec <= 1; ++da_aec) { | |
552 WebRtcAec_enable_reported_delay(self_->aec, !da_aec); | |
553 EXPECT_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec); | |
hlundin-webrtc
2015/06/17 14:09:19
Swap parameters.
bjornv1
2015/06/17 14:25:17
Done.
| |
554 if (extended_filter == 0 && da_aec == 1) { | |
555 break; | |
hlundin-webrtc
2015/06/17 14:09:19
I think "continue" is more correct than "break". I
bjornv1
2015/06/17 14:25:17
Done.
| |
556 } | |
557 for (size_t i = 0; i < kNumSampleRates; i++) { | |
558 Init(kSampleRateHz[i]); | |
559 RunStableStartup(); | |
560 const int device_buf = MapBufferSizeToSamples(kDeviceBufMs); | |
477 | 561 |
478 // Loop through 100 frames (both render and capture), which equals 1 s of | 562 // Normal state. We are currently not in a non-causal state. |
479 // data. Every odd frame we set the device buffer size to 2 * |kDeviceBufMs| | 563 bool non_causal = false; |
480 // and even frames we set the device buffer size to zero. | |
481 for (int j = 0; j < 100; j++) { | |
482 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec); | |
483 int device_buf_ms = 2 * (j % 2) * kDeviceBufMs; | |
484 RenderAndCapture(device_buf_ms); | |
485 | 564 |
486 // Check for non-causality, compared with the average device buffer size. | 565 // Loop through 100 frames (both render and capture), which equals 1 s |
487 non_causal |= (device_buf - WebRtcAec_system_delay(self_->aec) < 64); | 566 // of data. Every odd frame we set the device buffer size to |
488 EXPECT_GE(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); | 567 // 2 * |kDeviceBufMs| and even frames we set the device buffer size to |
568 // zero. | |
569 for (int j = 0; j < 100; j++) { | |
570 int system_delay_before_calls = WebRtcAec_system_delay(self_->aec); | |
571 int device_buf_ms = 2 * (j % 2) * kDeviceBufMs; | |
572 RenderAndCapture(device_buf_ms); | |
489 | 573 |
490 // Verify that the system delay is non-negative. | 574 // Check for non-causality, compared with the average device buffer |
491 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | 575 // size. |
576 non_causal |= (device_buf - WebRtcAec_system_delay(self_->aec) < 64); | |
577 EXPECT_GE(system_delay_before_calls, | |
578 WebRtcAec_system_delay(self_->aec)); | |
579 | |
580 // Verify that the system delay is non-negative. | |
581 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec)); | |
582 } | |
583 // Verify we are not in a non-causal state. | |
584 EXPECT_FALSE(non_causal); | |
585 } | |
492 } | 586 } |
493 // Verify we are not in a non-causal state. | |
494 EXPECT_FALSE(non_causal); | |
495 } | 587 } |
496 } | 588 } |
497 | 589 |
498 } // namespace | 590 } // namespace |
OLD | NEW |