Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: webrtc/modules/audio_processing/aec/system_delay_unittest.cc

Issue 1187943005: Reland "Revert "audio_processing/aec: make delay estimator aware of starving farend buffer"" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static const int kStableConvergenceMs = 100; 93 static const int kStableConvergenceMs = 100;
94 94
95 // Maximum convergence time in ms. This means that we should leave the startup 95 // Maximum convergence time in ms. This means that we should leave the startup
96 // phase after |kMaxConvergenceMs| independent of device buffer stability 96 // phase after |kMaxConvergenceMs| independent of device buffer stability
97 // conditions. 97 // conditions.
98 static const int kMaxConvergenceMs = 500; 98 static const int kMaxConvergenceMs = 500;
99 99
100 void SystemDelayTest::Init(int sample_rate_hz) { 100 void SystemDelayTest::Init(int sample_rate_hz) {
101 // Initialize AEC 101 // Initialize AEC
102 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000)); 102 EXPECT_EQ(0, WebRtcAec_Init(handle_, sample_rate_hz, 48000));
103 CHECK_EQ(WebRtcAec_system_delay(self_->aec), 0);
103 104
104 // One frame equals 10 ms of data. 105 // One frame equals 10 ms of data.
105 samples_per_frame_ = sample_rate_hz / 100; 106 samples_per_frame_ = sample_rate_hz / 100;
106 } 107 }
107 108
108 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) { 109 void SystemDelayTest::RenderAndCapture(int device_buffer_ms) {
109 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 110 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_));
110 EXPECT_EQ(0, 111 EXPECT_EQ(0,
111 WebRtcAec_Process(handle_, 112 WebRtcAec_Process(handle_,
112 &near_ptr_, 113 &near_ptr_,
(...skipping 15 matching lines...) Expand all
128 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec)); 129 EXPECT_EQ(buffer_size, WebRtcAec_system_delay(self_->aec));
129 } 130 }
130 return buffer_size; 131 return buffer_size;
131 } 132 }
132 133
133 void SystemDelayTest::RunStableStartup() { 134 void SystemDelayTest::RunStableStartup() {
134 // To make sure we have a full buffer when we verify stability we first fill 135 // 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 136 // up the far-end buffer with the same amount as we will report in through
136 // Process(). 137 // Process().
137 int buffer_size = BufferFillUp(); 138 int buffer_size = BufferFillUp();
138 // A stable device should be accepted and put in a regular process mode within 139
139 // |kStableConvergenceMs|. 140 if (WebRtcAec_reported_delay_enabled(self_->aec) == 0) {
140 int process_time_ms = 0; 141 // In extended_filter mode we set the buffer size after the first processed
141 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { 142 // 10 ms chunk. Hence, we don't need to wait for the reported system delay
143 // values to become stable.
142 RenderAndCapture(kDeviceBufMs); 144 RenderAndCapture(kDeviceBufMs);
143 buffer_size += samples_per_frame_; 145 buffer_size += samples_per_frame_;
144 if (self_->startup_phase == 0) { 146 CHECK(!self_->startup_phase);
145 // We have left the startup phase. 147 } else {
146 break; 148 // A stable device should be accepted and put in a regular process mode
149 // within |kStableConvergenceMs|.
150 int process_time_ms = 0;
151 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) {
152 RenderAndCapture(kDeviceBufMs);
153 buffer_size += samples_per_frame_;
154 if (self_->startup_phase == 0) {
155 // We have left the startup phase.
156 break;
157 }
147 } 158 }
159 // Verify convergence time.
160 EXPECT_GT(kStableConvergenceMs, process_time_ms);
148 } 161 }
149 // Verify convergence time.
150 EXPECT_GT(kStableConvergenceMs, process_time_ms);
151 // Verify that the buffer has been flushed. 162 // Verify that the buffer has been flushed.
152 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec)); 163 EXPECT_GE(buffer_size, WebRtcAec_system_delay(self_->aec));
153 } 164 }
154 165
155 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms) { 166 int SystemDelayTest::MapBufferSizeToSamples(int size_in_ms) {
156 // The extra 10 ms corresponds to the unprocessed frame. 167 // The extra 10 ms corresponds to the unprocessed frame.
157 return (size_in_ms + 10) * samples_per_frame_ / 10; 168 return (size_in_ms + 10) * samples_per_frame_ / 10;
158 } 169 }
159 170
160 // The tests should meet basic requirements and not be adjusted to what is 171 // The tests should meet basic requirements and not be adjusted to what is
(...skipping 13 matching lines...) Expand all
174 // |kMaxConvergenceMs| ms. 185 // |kMaxConvergenceMs| ms.
175 // 6) If the local buffer runs out of data we should stuff the buffer with older 186 // 6) If the local buffer runs out of data we should stuff the buffer with older
176 // frames. 187 // frames.
177 // 7) The system delay should within |kMaxConvergenceMs| ms heal from 188 // 7) The system delay should within |kMaxConvergenceMs| ms heal from
178 // disturbances like drift, data glitches, toggling events and outliers. 189 // disturbances like drift, data glitches, toggling events and outliers.
179 // 8) The system delay should never become negative. 190 // 8) The system delay should never become negative.
180 191
181 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) { 192 TEST_F(SystemDelayTest, CorrectIncreaseWhenBufferFarend) {
182 // When we add data to the AEC buffer the internal system delay should be 193 // 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. 194 // incremented with the same amount as the size of data.
184 for (size_t i = 0; i < kNumSampleRates; i++) { 195 // This process should be independent of DA-AEC and extended_filter mode.
185 Init(kSampleRateHz[i]); 196 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
186 197 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
187 // Loop through a couple of calls to make sure the system delay increments 198 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
188 // correctly. 199 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
189 for (int j = 1; j <= 5; j++) { 200 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
190 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 201 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
191 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec)); 202 for (size_t i = 0; i < kNumSampleRates; i++) {
203 Init(kSampleRateHz[i]);
204 // Loop through a couple of calls to make sure the system delay
205 // increments correctly.
206 for (int j = 1; j <= 5; j++) {
207 EXPECT_EQ(0,
208 WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_));
209 EXPECT_EQ(j * samples_per_frame_, WebRtcAec_system_delay(self_->aec));
210 }
211 }
192 } 212 }
193 } 213 }
194 } 214 }
195 215
196 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full 216 // TODO(bjornv): Add a test to verify behavior if the far-end buffer is full
197 // when adding new data. 217 // when adding new data.
198 218
199 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) { 219 TEST_F(SystemDelayTest, CorrectDelayAfterStableStartup) {
200 // We run the system in a stable startup. After that we verify that the system 220 // We run the system in a stable startup. After that we verify that the system
201 // delay meets the requirements. 221 // delay meets the requirements.
202 for (size_t i = 0; i < kNumSampleRates; i++) { 222 // This process should be independent of DA-AEC and extended_filter mode.
203 Init(kSampleRateHz[i]); 223 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
204 RunStableStartup(); 224 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
225 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
226 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
227 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
228 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
229 for (size_t i = 0; i < kNumSampleRates; i++) {
230 Init(kSampleRateHz[i]);
231 RunStableStartup();
205 232
206 // Verify system delay with respect to requirements, i.e., the 233 // 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 234 // |system_delay| is in the interval [75%, 100%] of what's reported on
208 // average. 235 // the average.
209 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10; 236 // In extended_filter mode we target 50% and measure after one processed
210 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec)); 237 // 10 ms chunk.
211 EXPECT_LE(average_reported_delay * 3 / 4, 238 int average_reported_delay = kDeviceBufMs * samples_per_frame_ / 10;
212 WebRtcAec_system_delay(self_->aec)); 239 EXPECT_GE(average_reported_delay, WebRtcAec_system_delay(self_->aec));
240 int lower_bound = WebRtcAec_extended_filter_enabled(self_->aec)
241 ? average_reported_delay / 2 - samples_per_frame_
242 : average_reported_delay * 3 / 4;
243 EXPECT_LE(lower_bound, WebRtcAec_system_delay(self_->aec));
244 }
245 }
213 } 246 }
214 } 247 }
215 248
216 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) { 249 TEST_F(SystemDelayTest, CorrectDelayAfterUnstableStartup) {
250 // This test does not apply in extended_filter mode, since we only use the
251 // the first 10 ms chunk to determine a reasonable buffer size. Neither does
252 // does it apply if DA-AEC is on because that overrides the startup procedure.
253 WebRtcAec_enable_extended_filter(self_->aec, false);
254 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0);
255 WebRtcAec_enable_reported_delay(self_->aec, true);
256 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), 1);
257
217 // In an unstable system we would start processing after |kMaxConvergenceMs|. 258 // 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 259 // On the last frame the AEC buffer is adjusted to 60% of the last reported
219 // device buffer size. 260 // device buffer size.
220 // We construct an unstable system by altering the device buffer size between 261 // We construct an unstable system by altering the device buffer size between
221 // two values |kDeviceBufMs| +- 25 ms. 262 // two values |kDeviceBufMs| +- 25 ms.
222 for (size_t i = 0; i < kNumSampleRates; i++) { 263 for (size_t i = 0; i < kNumSampleRates; i++) {
223 Init(kSampleRateHz[i]); 264 Init(kSampleRateHz[i]);
224 265
225 // To make sure we have a full buffer when we verify stability we first fill 266 // 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 267 // up the far-end buffer with the same amount as we will report in on the
(...skipping 20 matching lines...) Expand all
247 288
248 // Verify system delay with respect to requirements, i.e., the 289 // Verify system delay with respect to requirements, i.e., the
249 // |system_delay| is in the interval [60%, 100%] of what's last reported. 290 // |system_delay| is in the interval [60%, 100%] of what's last reported.
250 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10, 291 EXPECT_GE(reported_delay_ms * samples_per_frame_ / 10,
251 WebRtcAec_system_delay(self_->aec)); 292 WebRtcAec_system_delay(self_->aec));
252 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5, 293 EXPECT_LE(reported_delay_ms * samples_per_frame_ / 10 * 3 / 5,
253 WebRtcAec_system_delay(self_->aec)); 294 WebRtcAec_system_delay(self_->aec));
254 } 295 }
255 } 296 }
256 297
257 TEST_F(SystemDelayTest, 298 TEST_F(SystemDelayTest, CorrectDelayAfterStableBufferBuildUp) {
258 DISABLED_ON_ANDROID(CorrectDelayAfterStableBufferBuildUp)) { 299 // This test does not apply in extended_filter mode, since we only use the
300 // the first 10 ms chunk to determine a reasonable buffer size. Neither does
301 // does it apply if DA-AEC is on because that overrides the startup procedure.
302 WebRtcAec_enable_extended_filter(self_->aec, false);
303 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0);
304 WebRtcAec_enable_reported_delay(self_->aec, true);
305 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), 1);
306
259 // In this test we start by establishing the device buffer size during stable 307 // 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 308 // 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 309 // verify that the system delay is increased correctly until we have reach an
262 // internal buffer size of 75% of what's been reported. 310 // internal buffer size of 75% of what's been reported.
263 311
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++) { 312 for (size_t i = 0; i < kNumSampleRates; i++) {
267 Init(kSampleRateHz[i]); 313 Init(kSampleRateHz[i]);
268 314
269 // We assume that running |kStableConvergenceMs| calls will put the 315 // We assume that running |kStableConvergenceMs| calls will put the
270 // algorithm in a state where the device buffer size has been determined. We 316 // 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. 317 // can make that assumption since we have a separate stability test.
272 int process_time_ms = 0; 318 int process_time_ms = 0;
273 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) { 319 for (; process_time_ms < kStableConvergenceMs; process_time_ms += 10) {
274 EXPECT_EQ(0, 320 EXPECT_EQ(0,
275 WebRtcAec_Process(handle_, 321 WebRtcAec_Process(handle_,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec)); 355 EXPECT_EQ(system_delay_before_calls, WebRtcAec_system_delay(self_->aec));
310 } 356 }
311 } 357 }
312 } 358 }
313 359
314 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) { 360 TEST_F(SystemDelayTest, CorrectDelayWhenBufferUnderrun) {
315 // Here we test a buffer under run scenario. If we keep on calling 361 // 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 362 // WebRtcAec_Process() we will finally run out of data, but should
317 // automatically stuff the buffer. We verify this behavior by checking if the 363 // automatically stuff the buffer. We verify this behavior by checking if the
318 // system delay goes negative. 364 // system delay goes negative.
319 for (size_t i = 0; i < kNumSampleRates; i++) { 365 // This process should be independent of DA-AEC and extended_filter mode.
320 Init(kSampleRateHz[i]); 366 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
321 RunStableStartup(); 367 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
368 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
369 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
370 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
371 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
372 for (size_t i = 0; i < kNumSampleRates; i++) {
373 Init(kSampleRateHz[i]);
374 RunStableStartup();
322 375
323 // The AEC has now left the Startup phase. We now have at most 376 // The AEC has now left the Startup phase. We now have at most
324 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until 377 // |kStableConvergenceMs| in the buffer. Keep on calling Process() until
325 // we run out of data and verify that the system delay is non-negative. 378 // we run out of data and verify that the system delay is non-negative.
326 for (int j = 0; j <= kStableConvergenceMs; j += 10) { 379 for (int j = 0; j <= kStableConvergenceMs; j += 10) {
327 EXPECT_EQ(0, 380 EXPECT_EQ(0, WebRtcAec_Process(handle_, &near_ptr_, 1, &out_ptr_,
328 WebRtcAec_Process(handle_, 381 samples_per_frame_, kDeviceBufMs, 0));
329 &near_ptr_, 382 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
330 1, 383 }
331 &out_ptr_, 384 }
332 samples_per_frame_,
333 kDeviceBufMs,
334 0));
335 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
336 } 385 }
337 } 386 }
338 } 387 }
339 388
340 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(CorrectDelayDuringDrift)) { 389 TEST_F(SystemDelayTest, CorrectDelayDuringDrift) {
341 // This drift test should verify that the system delay is never exceeding the 390 // 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 391 // 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 392 // 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. 393 // ms we jump (add) 10 ms to give a repeated pattern.
345 394
346 // This test assumes the reported delays are used. 395 // This process should be independent of DA-AEC and extended_filter mode.
347 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); 396 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
348 for (size_t i = 0; i < kNumSampleRates; i++) { 397 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
349 Init(kSampleRateHz[i]); 398 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
350 RunStableStartup(); 399 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
400 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
401 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
402 for (size_t i = 0; i < kNumSampleRates; i++) {
403 Init(kSampleRateHz[i]);
404 RunStableStartup();
351 405
352 // We have now left the startup phase and proceed with normal processing. 406 // We have left the startup phase and proceed with normal processing.
353 int jump = 0; 407 int jump = 0;
354 for (int j = 0; j < 1000; j++) { 408 for (int j = 0; j < 1000; j++) {
355 // Drift = -1 ms per 100 ms of data. 409 // Drift = -1 ms per 100 ms of data.
356 int device_buf_ms = kDeviceBufMs - (j / 10) + jump; 410 int device_buf_ms = kDeviceBufMs - (j / 10) + jump;
357 int device_buf = MapBufferSizeToSamples(device_buf_ms); 411 int device_buf = MapBufferSizeToSamples(device_buf_ms);
358 412
359 if (device_buf_ms < 30) { 413 if (device_buf_ms < 30) {
360 // Add 10 ms data, taking affect next frame. 414 // Add 10 ms data, taking affect next frame.
361 jump += 10; 415 jump += 10;
416 }
417 RenderAndCapture(device_buf_ms);
418
419 // Verify that the system delay does not exceed the device buffer.
420 EXPECT_GE(device_buf, WebRtcAec_system_delay(self_->aec));
421
422 // Verify that the system delay is non-negative.
423 EXPECT_LE(0, WebRtcAec_system_delay(self_->aec));
424 }
362 } 425 }
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 } 426 }
371 } 427 }
372 } 428 }
373 429
374 TEST_F(SystemDelayTest, DISABLED_ON_ANDROID(ShouldRecoverAfterGlitch)) { 430 TEST_F(SystemDelayTest, ShouldRecoverAfterGlitch) {
375 // This glitch test should verify that the system delay recovers if there is 431 // 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 432 // 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 433 // after which the stable procedure continues. The glitch is never reported by
378 // the device. 434 // the device.
379 // The system is said to be in a non-causal state if the difference between 435 // 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). 436 // the device buffer and system delay is less than a block (64 samples).
381 437
382 // This test assumes the reported delays are used. 438 // This process should be independent of DA-AEC and extended_filter mode.
383 WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(handle_), 1); 439 for (int extended_filter = 0; extended_filter <= 1; ++extended_filter) {
384 for (size_t i = 0; i < kNumSampleRates; i++) { 440 WebRtcAec_enable_extended_filter(self_->aec, extended_filter);
385 Init(kSampleRateHz[i]); 441 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
386 RunStableStartup(); 442 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
387 int device_buf = MapBufferSizeToSamples(kDeviceBufMs); 443 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
388 // Glitch state. 444 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
389 for (int j = 0; j < 20; j++) { 445 for (size_t i = 0; i < kNumSampleRates; i++) {
390 EXPECT_EQ(0, WebRtcAec_BufferFarend(handle_, far_, samples_per_frame_)); 446 Init(kSampleRateHz[i]);
391 // No need to verify system delay, since that is done in a separate test. 447 RunStableStartup();
448 int device_buf = MapBufferSizeToSamples(kDeviceBufMs);
449 // Glitch state.
450 for (int j = 0; j < 20; j++) {
451 CHECK(!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 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), 0);
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 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
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 CHECK_EQ(WebRtcAec_extended_filter_enabled(self_->aec), extended_filter);
551 for (int da_aec = 0; da_aec <= 1; ++da_aec) {
552 WebRtcAec_enable_reported_delay(self_->aec, !da_aec);
553 CHECK_EQ(WebRtcAec_reported_delay_enabled(self_->aec), !da_aec);
554 if (extended_filter == 0 && da_aec == 1) {
555 break;
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698