Chromium Code Reviews| Index: webrtc/modules/audio_processing/aec3/echo_canceller3_unittest.cc |
| diff --git a/webrtc/modules/audio_processing/aec3/echo_canceller3_unittest.cc b/webrtc/modules/audio_processing/aec3/echo_canceller3_unittest.cc |
| index 8ccaa51e52cd11c17f3d70c3fba65ad393d71800..daa85f4b993743316ec947d7972c91c4155472c7 100644 |
| --- a/webrtc/modules/audio_processing/aec3/echo_canceller3_unittest.cc |
| +++ b/webrtc/modules/audio_processing/aec3/echo_canceller3_unittest.cc |
| @@ -17,7 +17,7 @@ |
| #include <utility> |
| #include <vector> |
| -#include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
| +#include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
| #include "webrtc/modules/audio_processing/aec3/block_processor.h" |
| #include "webrtc/modules/audio_processing/aec3/frame_blocker.h" |
| #include "webrtc/modules/audio_processing/aec3/mock/mock_block_processor.h" |
| @@ -48,6 +48,17 @@ void PopulateInputFrame(size_t frame_length, |
| } |
| } |
| +// Populates the frame with linearly increasing sample values. |
| +void PopulateInputFrame(size_t frame_length, |
| + size_t frame_index, |
| + float* frame, |
| + int offset) { |
| + for (size_t i = 0; i < frame_length; ++i) { |
| + float value = static_cast<int>(frame_index * frame_length + i) + offset; |
| + frame[i] = std::max(value, 0.f); |
| + } |
| +} |
| + |
| // Verifies the that samples in the output frame are identical to the samples |
| // that were produced for the input frame, with an offset in order to compensate |
| // for buffering delays. |
| @@ -75,6 +86,25 @@ bool VerifyOutputFrameBitexactness(size_t frame_length, |
| return true; |
| } |
| +// Verifies the that samples in the output frame are identical to the samples |
| +// that were produced for the input frame, with an offset in order to compensate |
| +// for buffering delays. |
| +bool VerifyOutputFrameBitexactness(size_t frame_length, |
| + size_t frame_index, |
| + const float* const* frame, |
| + int offset) { |
| + float reference_frame[480]; |
| + |
| + PopulateInputFrame(frame_length, frame_index, reference_frame, offset); |
| + for (size_t i = 0; i < frame_length; ++i) { |
| + if (reference_frame[i] != frame[0][i]) { |
| + return false; |
| + } |
| + } |
| + |
| + return true; |
| +} |
| + |
| // Class for testing that the capture data is properly received by the block |
| // processor and that the processor data is properly passed to the |
| // EchoCanceller3 output. |
| @@ -156,11 +186,11 @@ class EchoCanceller3Tester { |
| for (size_t frame_index = 0; frame_index < kNumFramesToProcess; |
| ++frame_index) { |
| aec3.AnalyzeCapture(&capture_buffer_); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| &capture_buffer_.split_bands_f(0)[0], 0); |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 100); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| aec3.ProcessCapture(&capture_buffer_, false); |
| @@ -181,17 +211,17 @@ class EchoCanceller3Tester { |
| for (size_t frame_index = 0; frame_index < kNumFramesToProcess; |
| ++frame_index) { |
| aec3.AnalyzeCapture(&capture_buffer_); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| &capture_buffer_.split_bands_f(0)[0], 100); |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| aec3.ProcessCapture(&capture_buffer_, false); |
| EXPECT_TRUE(VerifyOutputFrameBitexactness( |
| - frame_length_, num_bands_, frame_index, |
| - &capture_buffer_.split_bands_f(0)[0], -64)); |
| + frame_length_, frame_index, &capture_buffer_.split_bands_f(0)[0], |
| + -64)); |
| } |
| } |
| @@ -259,12 +289,12 @@ class EchoCanceller3Tester { |
| } |
| aec3.AnalyzeCapture(&capture_buffer_); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| &capture_buffer_.split_bands_f(0)[0], 0); |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| aec3.ProcessCapture(&capture_buffer_, echo_path_change); |
| @@ -350,12 +380,12 @@ class EchoCanceller3Tester { |
| } |
| aec3.AnalyzeCapture(&capture_buffer_); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| &capture_buffer_.split_bands_f(0)[0], 0); |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| aec3.ProcessCapture(&capture_buffer_, false); |
| @@ -414,7 +444,6 @@ class EchoCanceller3Tester { |
| EchoCanceller3 aec3(sample_rate_hz_, false, |
| std::move(block_processor_mock)); |
| - |
| for (size_t frame_index = 0; frame_index < kNumFramesToProcess; |
| ++frame_index) { |
| for (int k = 0; k < fullband_frame_length_; ++k) { |
| @@ -436,12 +465,12 @@ class EchoCanceller3Tester { |
| } |
| aec3.AnalyzeCapture(&capture_buffer_); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| &capture_buffer_.split_bands_f(0)[0], 0); |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| aec3.ProcessCapture(&capture_buffer_, false); |
| @@ -462,8 +491,8 @@ class EchoCanceller3Tester { |
| if (sample_rate_hz_ > 16000) { |
| render_buffer_.SplitIntoFrequencyBands(); |
| } |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| } |
| @@ -480,8 +509,8 @@ class EchoCanceller3Tester { |
| aec3.ProcessCapture(&capture_buffer_, false); |
| EXPECT_TRUE(VerifyOutputFrameBitexactness( |
| - frame_length_, num_bands_, frame_index, |
| - &capture_buffer_.split_bands_f(0)[0], -64)); |
| + frame_length_, frame_index, &capture_buffer_.split_bands_f(0)[0], |
| + -64)); |
| } |
| } |
| @@ -497,8 +526,8 @@ class EchoCanceller3Tester { |
| if (sample_rate_hz_ > 16000) { |
| render_buffer_.SplitIntoFrequencyBands(); |
| } |
| - PopulateInputFrame(frame_length_, num_bands_, frame_index, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, frame_index, |
| + &render_buffer_.channels_f()[0][0], 0); |
| if (k == 0) { |
| EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_)); |
| @@ -518,8 +547,7 @@ class EchoCanceller3Tester { |
| // way that the number of bands for the rates are different. |
| const int aec3_sample_rate_hz = sample_rate_hz_ == 48000 ? 32000 : 48000; |
| EchoCanceller3 aec3(aec3_sample_rate_hz, false); |
| - PopulateInputFrame(frame_length_, num_bands_, 0, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + PopulateInputFrame(frame_length_, 0, &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_DEATH(aec3.AnalyzeRender(&render_buffer_), ""); |
| } |
| @@ -546,9 +574,8 @@ class EchoCanceller3Tester { |
| const int aec3_sample_rate_hz = sample_rate_hz_ == 8000 ? 16000 : 8000; |
| EchoCanceller3 aec3(aec3_sample_rate_hz, false); |
| - OptionalBandSplit(); |
| - PopulateInputFrame(frame_length_, num_bands_, 0, |
| - &render_buffer_.split_bands_f(0)[0], 0); |
| + OptionalCaptureBandSplit(); |
| + PopulateInputFrame(frame_length_, 0, &render_buffer_.channels_f()[0][0], 0); |
| EXPECT_DEATH(aec3.AnalyzeRender(&render_buffer_), ""); |
| } |
| @@ -562,7 +589,7 @@ class EchoCanceller3Tester { |
| const int aec3_sample_rate_hz = sample_rate_hz_ == 8000 ? 16000 : 8000; |
| EchoCanceller3 aec3(aec3_sample_rate_hz, false); |
| - OptionalBandSplit(); |
| + OptionalCaptureBandSplit(); |
| PopulateInputFrame(frame_length_, num_bands_, 0, |
| &capture_buffer_.split_bands_f(0)[0], 100); |
| @@ -572,7 +599,14 @@ class EchoCanceller3Tester { |
| #endif |
| private: |
| - void OptionalBandSplit() { |
| + void OptionalCaptureBandSplit() { |
| + if (sample_rate_hz_ > 16000) { |
| + capture_buffer_.SplitIntoFrequencyBands(); |
| + render_buffer_.SplitIntoFrequencyBands(); |
| + } |
| + } |
| + |
| + void OptionalRenderBandSplit() { |
|
hlundin-webrtc
2017/02/22 20:54:16
OptionalRenderBandSplit looks exactly the same as
peah-webrtc
2017/02/22 23:51:37
Good find! That is not indended. Since OptionalRen
|
| if (sample_rate_hz_ > 16000) { |
| capture_buffer_.SplitIntoFrequencyBands(); |
| render_buffer_.SplitIntoFrequencyBands(); |
| @@ -673,12 +707,6 @@ TEST(EchoCanceller3Messaging, EchoLeakage) { |
| } |
| #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| -TEST(EchoCanceller3InputCheck, WrongRenderNumBandsCheckVerification) { |
| - for (auto rate : {8000, 16000, 32000, 48000}) { |
| - SCOPED_TRACE(ProduceDebugText(rate)); |
| - EchoCanceller3Tester(rate).RunAnalyzeRenderNumBandsCheckVerification(); |
| - } |
| -} |
| TEST(EchoCanceller3InputCheck, WrongCaptureNumBandsCheckVerification) { |
| for (auto rate : {8000, 16000, 32000, 48000}) { |
| @@ -687,7 +715,10 @@ TEST(EchoCanceller3InputCheck, WrongCaptureNumBandsCheckVerification) { |
| } |
| } |
| -TEST(EchoCanceller3InputCheck, WrongRenderFrameLengthCheckVerification) { |
| +// TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
|
hlundin-webrtc
2017/02/22 20:54:16
Wrong comment? This is not a death test.
peah-webrtc
2017/02/22 23:51:37
It is actually a death test, but the actual test i
|
| +// tests on test bots has been fixed. |
| +TEST(EchoCanceller3InputCheck, |
| + DISABLED_WrongRenderFrameLengthCheckVerification) { |
| for (auto rate : {8000, 16000}) { |
| SCOPED_TRACE(ProduceDebugText(rate)); |
| EchoCanceller3Tester(rate).RunAnalyzeRenderFrameLengthCheckVerification(); |