| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 <numeric> | 11 #include <numeric> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "webrtc/base/array_view.h" | 14 #include "webrtc/base/array_view.h" |
| 15 #include "webrtc/base/random.h" | 15 #include "webrtc/base/random.h" |
| 16 #include "webrtc/modules/audio_processing/audio_buffer.h" | 16 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 18 #include "webrtc/modules/audio_processing/residual_echo_detector.h" | 18 #include "webrtc/modules/audio_processing/residual_echo_detector.h" |
| 19 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" | 19 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" |
| 20 #include "webrtc/modules/audio_processing/test/performance_timer.h" | 20 #include "webrtc/modules/audio_processing/test/performance_timer.h" |
| 21 #include "webrtc/modules/audio_processing/test/simulator_buffers.h" | 21 #include "webrtc/modules/audio_processing/test/simulator_buffers.h" |
| 22 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 #include "webrtc/test/gtest.h" | 23 #include "webrtc/test/gtest.h" |
| 24 #include "webrtc/test/testsupport/perf_test.h" | 24 #include "webrtc/test/testsupport/perf_test.h" |
| 25 | 25 |
| 26 namespace webrtc { | 26 namespace webrtc { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const size_t kNumFramesToProcess = 500; | 29 constexpr size_t kNumFramesToProcess = 20000; |
| 30 const size_t kProcessingBatchSize = 20; | 30 constexpr size_t kNumFramesToProcessStandalone = 50 * kNumFramesToProcess; |
| 31 const size_t kWarmupBatchSize = 2 * kProcessingBatchSize; | 31 constexpr size_t kProcessingBatchSize = 200; |
| 32 const int kSampleRate = AudioProcessing::kSampleRate48kHz; | 32 constexpr size_t kProcessingBatchSizeStandalone = 50 * kProcessingBatchSize; |
| 33 const int kNumberOfChannels = 1; | 33 constexpr size_t kNumberOfWarmupMeasurements = |
| 34 (kNumFramesToProcess / kProcessingBatchSize) / 2; |
| 35 constexpr size_t kNumberOfWarmupMeasurementsStandalone = |
| 36 (kNumFramesToProcessStandalone / kProcessingBatchSizeStandalone) / 2; |
| 37 constexpr int kSampleRate = AudioProcessing::kSampleRate48kHz; |
| 38 constexpr int kNumberOfChannels = 1; |
| 34 | 39 |
| 35 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) { | 40 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer, |
| 36 std::string s = std::to_string(timer.GetDurationAverage()); | 41 int number_of_warmup_samples) { |
| 42 std::string s = |
| 43 std::to_string(timer.GetDurationAverage(number_of_warmup_samples)); |
| 37 s += ", "; | 44 s += ", "; |
| 38 s += std::to_string(timer.GetDurationStandardDeviation()); | 45 s += std::to_string( |
| 46 timer.GetDurationStandardDeviation(number_of_warmup_samples)); |
| 39 return s; | 47 return s; |
| 40 } | 48 } |
| 41 | 49 |
| 42 void RunStandaloneSubmodule() { | 50 void RunStandaloneSubmodule() { |
| 43 test::SimulatorBuffers buffers( | 51 test::SimulatorBuffers buffers( |
| 44 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, | 52 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
| 45 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); | 53 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
| 46 test::PerformanceTimer timer(kNumFramesToProcess); | 54 test::PerformanceTimer timer(kNumFramesToProcessStandalone / |
| 55 kProcessingBatchSizeStandalone); |
| 47 | 56 |
| 48 ResidualEchoDetector echo_detector; | 57 ResidualEchoDetector echo_detector; |
| 49 echo_detector.Initialize(); | 58 echo_detector.Initialize(); |
| 59 float sum = 0.f; |
| 50 | 60 |
| 51 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | 61 for (size_t frame_no = 0; frame_no < kNumFramesToProcessStandalone; |
| 62 ++frame_no) { |
| 52 // The first batch of frames are for warming up, and are not part of the | 63 // The first batch of frames are for warming up, and are not part of the |
| 53 // benchmark. After that the processing time is measured in chunks of | 64 // benchmark. After that the processing time is measured in chunks of |
| 54 // kProcessingBatchSize frames. | 65 // kProcessingBatchSize frames. |
| 55 if (frame_no >= kWarmupBatchSize && frame_no % kProcessingBatchSize == 0) { | 66 if (frame_no % kProcessingBatchSizeStandalone == 0) { |
| 56 timer.StartTimer(); | 67 timer.StartTimer(); |
| 57 } | 68 } |
| 58 | 69 |
| 59 buffers.UpdateInputBuffers(); | 70 buffers.UpdateInputBuffers(); |
| 60 echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>( | 71 echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>( |
| 61 buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz], | 72 buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
| 62 buffers.render_input_buffer->num_frames_per_band())); | 73 buffers.render_input_buffer->num_frames_per_band())); |
| 63 echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>( | 74 echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>( |
| 64 buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz], | 75 buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
| 65 buffers.capture_input_buffer->num_frames_per_band())); | 76 buffers.capture_input_buffer->num_frames_per_band())); |
| 77 sum += echo_detector.echo_likelihood(); |
| 66 | 78 |
| 67 if (frame_no >= kWarmupBatchSize && | 79 if (frame_no % kProcessingBatchSizeStandalone == |
| 68 frame_no % kProcessingBatchSize == kProcessingBatchSize - 1) { | 80 kProcessingBatchSizeStandalone - 1) { |
| 69 timer.StopTimer(); | 81 timer.StopTimer(); |
| 70 } | 82 } |
| 71 } | 83 } |
| 84 EXPECT_EQ(0.0f, sum); |
| 72 webrtc::test::PrintResultMeanAndError( | 85 webrtc::test::PrintResultMeanAndError( |
| 73 "echo_detector_call_durations", "", "StandaloneEchoDetector", | 86 "echo_detector_call_durations", "", "StandaloneEchoDetector", |
| 74 FormPerformanceMeasureString(timer), "us", false); | 87 FormPerformanceMeasureString(timer, |
| 88 kNumberOfWarmupMeasurementsStandalone), |
| 89 "us", false); |
| 75 } | 90 } |
| 76 | 91 |
| 77 void RunTogetherWithApm(std::string test_description, | 92 void RunTogetherWithApm(std::string test_description, |
| 78 bool use_mobile_aec, | 93 bool use_mobile_aec, |
| 79 bool include_default_apm_processing) { | 94 bool include_default_apm_processing) { |
| 80 test::SimulatorBuffers buffers( | 95 test::SimulatorBuffers buffers( |
| 81 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, | 96 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
| 82 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); | 97 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
| 83 test::PerformanceTimer timer(kNumFramesToProcess); | 98 test::PerformanceTimer timer(kNumFramesToProcess / kProcessingBatchSize); |
| 84 | 99 |
| 85 webrtc::Config config; | 100 webrtc::Config config; |
| 86 AudioProcessing::Config apm_config; | 101 AudioProcessing::Config apm_config; |
| 87 if (include_default_apm_processing) { | 102 if (include_default_apm_processing) { |
| 88 config.Set<DelayAgnostic>(new DelayAgnostic(true)); | 103 config.Set<DelayAgnostic>(new DelayAgnostic(true)); |
| 89 config.Set<ExtendedFilter>(new ExtendedFilter(true)); | 104 config.Set<ExtendedFilter>(new ExtendedFilter(true)); |
| 90 } | 105 } |
| 91 apm_config.level_controller.enabled = include_default_apm_processing; | 106 apm_config.level_controller.enabled = include_default_apm_processing; |
| 92 apm_config.residual_echo_detector.enabled = true; | 107 apm_config.residual_echo_detector.enabled = true; |
| 93 | 108 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 117 apm->voice_detection()->Enable(include_default_apm_processing)); | 132 apm->voice_detection()->Enable(include_default_apm_processing)); |
| 118 ASSERT_EQ(AudioProcessing::kNoError, | 133 ASSERT_EQ(AudioProcessing::kNoError, |
| 119 apm->level_estimator()->Enable(include_default_apm_processing)); | 134 apm->level_estimator()->Enable(include_default_apm_processing)); |
| 120 | 135 |
| 121 StreamConfig stream_config(kSampleRate, kNumberOfChannels, false); | 136 StreamConfig stream_config(kSampleRate, kNumberOfChannels, false); |
| 122 | 137 |
| 123 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | 138 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { |
| 124 // The first batch of frames are for warming up, and are not part of the | 139 // The first batch of frames are for warming up, and are not part of the |
| 125 // benchmark. After that the processing time is measured in chunks of | 140 // benchmark. After that the processing time is measured in chunks of |
| 126 // kProcessingBatchSize frames. | 141 // kProcessingBatchSize frames. |
| 127 if (frame_no >= kWarmupBatchSize && frame_no % kProcessingBatchSize == 0) { | 142 if (frame_no % kProcessingBatchSize == 0) { |
| 128 timer.StartTimer(); | 143 timer.StartTimer(); |
| 129 } | 144 } |
| 130 | 145 |
| 131 buffers.UpdateInputBuffers(); | 146 buffers.UpdateInputBuffers(); |
| 132 | 147 |
| 133 ASSERT_EQ( | 148 ASSERT_EQ( |
| 134 AudioProcessing::kNoError, | 149 AudioProcessing::kNoError, |
| 135 apm->ProcessReverseStream(&buffers.render_input[0], stream_config, | 150 apm->ProcessReverseStream(&buffers.render_input[0], stream_config, |
| 136 stream_config, &buffers.render_output[0])); | 151 stream_config, &buffers.render_output[0])); |
| 137 | 152 |
| 138 ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0)); | 153 ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0)); |
| 139 if (include_default_apm_processing) { | 154 if (include_default_apm_processing) { |
| 140 apm->gain_control()->set_stream_analog_level(0); | 155 apm->gain_control()->set_stream_analog_level(0); |
| 141 if (!use_mobile_aec) { | 156 if (!use_mobile_aec) { |
| 142 apm->echo_cancellation()->set_stream_drift_samples(0); | 157 apm->echo_cancellation()->set_stream_drift_samples(0); |
| 143 } | 158 } |
| 144 } | 159 } |
| 145 ASSERT_EQ(AudioProcessing::kNoError, | 160 ASSERT_EQ(AudioProcessing::kNoError, |
| 146 apm->ProcessStream(&buffers.capture_input[0], stream_config, | 161 apm->ProcessStream(&buffers.capture_input[0], stream_config, |
| 147 stream_config, &buffers.capture_output[0])); | 162 stream_config, &buffers.capture_output[0])); |
| 148 | 163 |
| 149 if (frame_no >= kWarmupBatchSize && | 164 if (frame_no % kProcessingBatchSize == kProcessingBatchSize - 1) { |
| 150 frame_no % kProcessingBatchSize == kProcessingBatchSize - 1) { | |
| 151 timer.StopTimer(); | 165 timer.StopTimer(); |
| 152 } | 166 } |
| 153 } | 167 } |
| 154 | 168 |
| 155 webrtc::test::PrintResultMeanAndError( | 169 webrtc::test::PrintResultMeanAndError( |
| 156 "echo_detector_call_durations", "_total", test_description, | 170 "echo_detector_call_durations", "_total", test_description, |
| 157 FormPerformanceMeasureString(timer), "us", false); | 171 FormPerformanceMeasureString(timer, kNumberOfWarmupMeasurements), "us", |
| 172 false); |
| 158 } | 173 } |
| 159 | 174 |
| 160 } // namespace | 175 } // namespace |
| 161 | 176 |
| 162 TEST(EchoDetectorPerformanceTest, StandaloneProcessing) { | 177 TEST(EchoDetectorPerformanceTest, StandaloneProcessing) { |
| 163 RunStandaloneSubmodule(); | 178 RunStandaloneSubmodule(); |
| 164 } | 179 } |
| 165 | 180 |
| 166 TEST(EchoDetectorPerformanceTest, ProcessingViaApm) { | 181 TEST(EchoDetectorPerformanceTest, ProcessingViaApm) { |
| 167 RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false); | 182 RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false); |
| 168 } | 183 } |
| 169 | 184 |
| 170 TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) { | 185 TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) { |
| 171 RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true); | 186 RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true); |
| 172 RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true); | 187 RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true); |
| 173 } | 188 } |
| 174 | 189 |
| 175 } // namespace webrtc | 190 } // namespace webrtc |
| OLD | NEW |