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 = 100; | 29 const size_t kNumFramesToProcess = 500; |
30 const size_t kProcessingBatchSize = 20; | |
30 const int kSampleRate = AudioProcessing::kSampleRate48kHz; | 31 const int kSampleRate = AudioProcessing::kSampleRate48kHz; |
31 const int kNumberOfChannels = 1; | 32 const int kNumberOfChannels = 1; |
32 | 33 |
33 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) { | 34 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) { |
34 std::string s = std::to_string(timer.GetDurationAverage()); | 35 std::string s = std::to_string(timer.GetDurationAverage()); |
35 s += ", "; | 36 s += ", "; |
36 s += std::to_string(timer.GetDurationStandardDeviation()); | 37 s += std::to_string(timer.GetDurationStandardDeviation()); |
37 return s; | 38 return s; |
38 } | 39 } |
39 | 40 |
40 void RunStandaloneSubmodule() { | 41 void RunStandaloneSubmodule() { |
41 test::SimulatorBuffers buffers( | 42 test::SimulatorBuffers buffers( |
42 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, | 43 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
43 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); | 44 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
44 test::PerformanceTimer timer(kNumFramesToProcess); | 45 test::PerformanceTimer timer(kNumFramesToProcess); |
45 | 46 |
46 ResidualEchoDetector echo_detector; | 47 ResidualEchoDetector echo_detector; |
47 echo_detector.Initialize(); | 48 echo_detector.Initialize(); |
48 | 49 |
49 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | 50 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { |
51 // The first batch of frames are for warming up, and are not part of the | |
52 // benchmark. After that the processing time is measured in chunks of | |
53 // kProcessingBatchSize frames. | |
54 if (frame_no >= kProcessingBatchSize && | |
peah-webrtc
2016/12/14 09:54:32
I think this is good, but if needed you could sepa
ivoc
2016/12/14 13:28:42
Done.
| |
55 frame_no % kProcessingBatchSize == 0) { | |
56 timer.StartTimer(); | |
57 } | |
58 | |
50 buffers.UpdateInputBuffers(); | 59 buffers.UpdateInputBuffers(); |
51 | |
52 timer.StartTimer(); | |
53 echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>( | 60 echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>( |
54 buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz], | 61 buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
55 buffers.render_input_buffer->num_frames_per_band())); | 62 buffers.render_input_buffer->num_frames_per_band())); |
56 echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>( | 63 echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>( |
57 buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz], | 64 buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
58 buffers.capture_input_buffer->num_frames_per_band())); | 65 buffers.capture_input_buffer->num_frames_per_band())); |
59 timer.StopTimer(); | 66 |
67 if (frame_no >= kProcessingBatchSize && | |
68 frame_no % kProcessingBatchSize == kProcessingBatchSize - 1) { | |
69 timer.StopTimer(); | |
70 } | |
60 } | 71 } |
61 webrtc::test::PrintResultMeanAndError( | 72 webrtc::test::PrintResultMeanAndError( |
62 "echo_detector_call_durations", "", "StandaloneEchoDetector", | 73 "echo_detector_call_durations", "", "StandaloneEchoDetector", |
63 FormPerformanceMeasureString(timer), "us", false); | 74 FormPerformanceMeasureString(timer), "us", false); |
64 } | 75 } |
65 | 76 |
66 void RunTogetherWithApm(std::string test_description, | 77 void RunTogetherWithApm(std::string test_description, |
67 bool use_mobile_aec, | 78 bool use_mobile_aec, |
68 bool include_default_apm_processing) { | 79 bool include_default_apm_processing) { |
69 test::SimulatorBuffers buffers( | 80 test::SimulatorBuffers buffers( |
70 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, | 81 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
71 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); | 82 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
72 test::PerformanceTimer render_timer(kNumFramesToProcess); | 83 test::PerformanceTimer timer(kNumFramesToProcess); |
73 test::PerformanceTimer capture_timer(kNumFramesToProcess); | |
74 test::PerformanceTimer total_timer(kNumFramesToProcess); | |
75 | 84 |
76 webrtc::Config config; | 85 webrtc::Config config; |
77 AudioProcessing::Config apm_config; | 86 AudioProcessing::Config apm_config; |
78 if (include_default_apm_processing) { | 87 if (include_default_apm_processing) { |
79 config.Set<DelayAgnostic>(new DelayAgnostic(true)); | 88 config.Set<DelayAgnostic>(new DelayAgnostic(true)); |
80 config.Set<ExtendedFilter>(new ExtendedFilter(true)); | 89 config.Set<ExtendedFilter>(new ExtendedFilter(true)); |
81 } | 90 } |
82 apm_config.level_controller.enabled = include_default_apm_processing; | 91 apm_config.level_controller.enabled = include_default_apm_processing; |
83 apm_config.residual_echo_detector.enabled = true; | 92 apm_config.residual_echo_detector.enabled = true; |
84 | 93 |
(...skipping 20 matching lines...) Expand all Loading... | |
105 ASSERT_EQ(AudioProcessing::kNoError, | 114 ASSERT_EQ(AudioProcessing::kNoError, |
106 apm->noise_suppression()->Enable(include_default_apm_processing)); | 115 apm->noise_suppression()->Enable(include_default_apm_processing)); |
107 ASSERT_EQ(AudioProcessing::kNoError, | 116 ASSERT_EQ(AudioProcessing::kNoError, |
108 apm->voice_detection()->Enable(include_default_apm_processing)); | 117 apm->voice_detection()->Enable(include_default_apm_processing)); |
109 ASSERT_EQ(AudioProcessing::kNoError, | 118 ASSERT_EQ(AudioProcessing::kNoError, |
110 apm->level_estimator()->Enable(include_default_apm_processing)); | 119 apm->level_estimator()->Enable(include_default_apm_processing)); |
111 | 120 |
112 StreamConfig stream_config(kSampleRate, kNumberOfChannels, false); | 121 StreamConfig stream_config(kSampleRate, kNumberOfChannels, false); |
113 | 122 |
114 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | 123 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 | |
125 // benchmark. After that the processing time is measured in chunks of | |
126 // kProcessingBatchSize frames. | |
127 if (frame_no >= kProcessingBatchSize && | |
128 frame_no % kProcessingBatchSize == 0) { | |
129 timer.StartTimer(); | |
130 } | |
131 | |
115 buffers.UpdateInputBuffers(); | 132 buffers.UpdateInputBuffers(); |
116 | 133 |
117 total_timer.StartTimer(); | |
118 render_timer.StartTimer(); | |
119 ASSERT_EQ( | 134 ASSERT_EQ( |
120 AudioProcessing::kNoError, | 135 AudioProcessing::kNoError, |
121 apm->ProcessReverseStream(&buffers.render_input[0], stream_config, | 136 apm->ProcessReverseStream(&buffers.render_input[0], stream_config, |
122 stream_config, &buffers.render_output[0])); | 137 stream_config, &buffers.render_output[0])); |
123 | 138 |
124 render_timer.StopTimer(); | |
125 | |
126 capture_timer.StartTimer(); | |
127 ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0)); | 139 ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0)); |
128 if (include_default_apm_processing) { | 140 if (include_default_apm_processing) { |
129 apm->gain_control()->set_stream_analog_level(0); | 141 apm->gain_control()->set_stream_analog_level(0); |
130 if (!use_mobile_aec) { | 142 if (!use_mobile_aec) { |
131 apm->echo_cancellation()->set_stream_drift_samples(0); | 143 apm->echo_cancellation()->set_stream_drift_samples(0); |
132 } | 144 } |
133 } | 145 } |
134 ASSERT_EQ(AudioProcessing::kNoError, | 146 ASSERT_EQ(AudioProcessing::kNoError, |
135 apm->ProcessStream(&buffers.capture_input[0], stream_config, | 147 apm->ProcessStream(&buffers.capture_input[0], stream_config, |
136 stream_config, &buffers.capture_output[0])); | 148 stream_config, &buffers.capture_output[0])); |
137 | 149 |
138 capture_timer.StopTimer(); | 150 if (frame_no >= kProcessingBatchSize && |
139 total_timer.StopTimer(); | 151 frame_no % kProcessingBatchSize == kProcessingBatchSize - 1) { |
152 timer.StopTimer(); | |
153 } | |
140 } | 154 } |
141 | 155 |
142 webrtc::test::PrintResultMeanAndError( | 156 webrtc::test::PrintResultMeanAndError( |
143 "echo_detector_call_durations", "_render", test_description, | |
144 FormPerformanceMeasureString(render_timer), "us", false); | |
145 webrtc::test::PrintResultMeanAndError( | |
146 "echo_detector_call_durations", "_capture", test_description, | |
147 FormPerformanceMeasureString(capture_timer), "us", false); | |
148 webrtc::test::PrintResultMeanAndError( | |
149 "echo_detector_call_durations", "_total", test_description, | 157 "echo_detector_call_durations", "_total", test_description, |
150 FormPerformanceMeasureString(total_timer), "us", false); | 158 FormPerformanceMeasureString(timer), "us", false); |
151 } | 159 } |
152 | 160 |
153 } // namespace | 161 } // namespace |
154 | 162 |
155 TEST(EchoDetectorPerformanceTest, StandaloneProcessing) { | 163 TEST(EchoDetectorPerformanceTest, StandaloneProcessing) { |
156 RunStandaloneSubmodule(); | 164 RunStandaloneSubmodule(); |
157 } | 165 } |
158 | 166 |
159 TEST(EchoDetectorPerformanceTest, ProcessingViaApm) { | 167 TEST(EchoDetectorPerformanceTest, ProcessingViaApm) { |
160 RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false); | 168 RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false); |
161 } | 169 } |
162 | 170 |
163 TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) { | 171 TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) { |
164 RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true); | 172 RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true); |
165 RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true); | 173 RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true); |
166 } | 174 } |
167 | 175 |
168 } // namespace webrtc | 176 } // namespace webrtc |
OLD | NEW |