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

Side by Side Diff: webrtc/media/engine/apm_helpers_unittest.cc

Issue 2681033010: Remove usage of VoEAudioProcessing from WVoE/MC. (Closed)
Patch Set: better comment Created 3 years, 10 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
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/media/engine/apm_helpers.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/media/engine/webrtcvoe.h"
15 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
16 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/test/gmock.h"
19 #include "webrtc/test/gtest.h"
20 #include "webrtc/voice_engine/transmit_mixer.h"
21
22 namespace webrtc {
23 namespace {
24
25 constexpr AgcConfig kDefaultAgcConfig = { 3, 9, true };
26
27 struct TestHelper {
28 TestHelper() {
29 // TODO(solenberg): This replicates the conditions from voe_auto_test.
hlundin-webrtc 2017/02/20 09:01:08 This is a statement, not a TODO. :)
the sun 2017/02/20 19:37:58 Done.
30 Config config;
31 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
32 RTC_CHECK_EQ(0, voe_wrapper_.base()->Init(
hlundin-webrtc 2017/02/20 09:01:08 You should typically avoid (D)CHECKs in test code,
the sun 2017/02/20 19:37:58 Unfortunately ASSERT_EQ cannot be used. IIUC this
33 &mock_audio_device_,
34 AudioProcessing::Create(config),
35 MockAudioDecoderFactory::CreateEmptyFactory()));
36 }
37
38 AudioProcessing* apm() {
39 return voe_wrapper_.base()->audio_processing();
40 }
41
42 const AudioProcessing* apm() const {
43 return voe_wrapper_.base()->audio_processing();
44 }
45
46 test::MockAudioDeviceModule* adm() {
47 return &mock_audio_device_;
48 }
49
50 voe::TransmitMixer* transmit_mixer() {
51 return voe_wrapper_.base()->transmit_mixer();
52 }
53
54 bool GetEcMetricsStatus() const {
55 EchoCancellation* ec = apm()->echo_cancellation();
56 bool metrics_enabled = ec->are_metrics_enabled();
57 EXPECT_EQ(metrics_enabled, ec->is_delay_logging_enabled());
58 return metrics_enabled;
59 }
60
61 bool CanGetEcMetrics() const {
62 EchoCancellation* ec = apm()->echo_cancellation();
63 EchoCancellation::Metrics metrics;
64 int metrics_result = ec->GetMetrics(&metrics);
65 int median = 0;
66 int std = 0;
67 float fraction = 0;
68 int delay_metrics_result = ec->GetDelayMetrics(&median, &std, &fraction);
69 return metrics_result == AudioProcessing::kNoError &&
70 delay_metrics_result == AudioProcessing::kNoError;
71 }
72
73 private:
74 testing::NiceMock<test::MockAudioDeviceModule> mock_audio_device_;
75 cricket::VoEWrapper voe_wrapper_;
76 };
77 } // namespace
78
79 TEST(ApmHelpersTest, AgcConfig_DefaultConfiguration) {
80 TestHelper helper;
81 AgcConfig agc_config =
82 apm_helpers::GetAgcConfig(helper.apm());
83
84 EXPECT_EQ(kDefaultAgcConfig.targetLeveldBOv, agc_config.targetLeveldBOv);
85 EXPECT_EQ(kDefaultAgcConfig.digitalCompressionGaindB,
86 agc_config.digitalCompressionGaindB);
87 EXPECT_EQ(kDefaultAgcConfig.limiterEnable, agc_config.limiterEnable);
88 }
89
90 TEST(ApmHelpersTest, AgcConfig_GetAndSet) {
91 const AgcConfig agc_config = { 11, 17, false };
hlundin-webrtc 2017/02/20 09:01:08 Double space before "17".
the sun 2017/02/20 19:37:58 Done.
92
93 TestHelper helper;
94 apm_helpers::SetAgcConfig(helper.apm(), agc_config);
95 AgcConfig actual_config =
96 apm_helpers::GetAgcConfig(helper.apm());
97
98 EXPECT_EQ(agc_config.digitalCompressionGaindB,
99 actual_config.digitalCompressionGaindB);
100 EXPECT_EQ(agc_config.limiterEnable,
101 actual_config.limiterEnable);
102 EXPECT_EQ(agc_config.targetLeveldBOv,
103 actual_config.targetLeveldBOv);
104 }
105
106 TEST(ApmHelpersTest, AgcStatus_DefaultMode) {
107 TestHelper helper;
108 GainControl* gc = helper.apm()->gain_control();
109 #if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
110 EXPECT_FALSE(gc->is_enabled());
111 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
112 #else
113 EXPECT_TRUE(gc->is_enabled());
114 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
115 #endif
116 }
117
118 TEST(ApmHelpersTest, AgcStatus_EnableDisable) {
119 TestHelper helper;
120 GainControl* gc = helper.apm()->gain_control();
121 #if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
122 apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), false,
123 kAgcFixedDigital);
124 EXPECT_FALSE(gc->is_enabled());
125 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
126
127 apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), true,
128 kAgcFixedDigital);
129 EXPECT_TRUE(gc->is_enabled());
130 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
131 #else
132 EXPECT_CALL(*helper.adm(), SetAGC(false)).WillOnce(testing::Return(0));
133 apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), false,
134 kAgcAdaptiveAnalog);
135 EXPECT_FALSE(gc->is_enabled());
136 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
137
138 EXPECT_CALL(*helper.adm(), SetAGC(true)).WillOnce(testing::Return(0));
139 apm_helpers::SetAgcStatus(helper.apm(), helper.adm(), true,
140 kAgcAdaptiveAnalog);
141 EXPECT_TRUE(gc->is_enabled());
142 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
143 #endif
144 }
145
146 TEST(ApmHelpersTest, EcStatus_DefaultMode) {
147 TestHelper helper;
148 EchoCancellation* ec = helper.apm()->echo_cancellation();
149 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
150 EXPECT_FALSE(ec->is_enabled());
151 EXPECT_FALSE(ecm->is_enabled());
152 }
153
154 TEST(ApmHelpersTest, EcStatus_EnableDisable) {
155 TestHelper helper;
156 EchoCancellation* ec = helper.apm()->echo_cancellation();
157 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
158
159 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
160 EXPECT_FALSE(ec->is_enabled());
161 EXPECT_TRUE(ecm->is_enabled());
162
163 apm_helpers::SetEcStatus(helper.apm(), false, kEcAecm);
164 EXPECT_FALSE(ec->is_enabled());
165 EXPECT_FALSE(ecm->is_enabled());
166
167 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
168 EXPECT_TRUE(ec->is_enabled());
169 EXPECT_FALSE(ecm->is_enabled());
170 EXPECT_EQ(EchoCancellation::kHighSuppression, ec->suppression_level());
171
172 apm_helpers::SetEcStatus(helper.apm(), false, kEcConference);
173 EXPECT_FALSE(ec->is_enabled());
174 EXPECT_FALSE(ecm->is_enabled());
175 EXPECT_EQ(EchoCancellation::kHighSuppression, ec->suppression_level());
176
177 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
178 EXPECT_FALSE(ec->is_enabled());
179 EXPECT_TRUE(ecm->is_enabled());
180 }
181
182 TEST(ApmHelpersTest, EcMetrics_DefaultMode) {
183 TestHelper helper;
184 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
185 EXPECT_TRUE(helper.GetEcMetricsStatus());
186 }
187
188 TEST(ApmHelpersTest, EcMetrics_CanEnableDisable) {
189 TestHelper helper;
190 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
191
192 apm_helpers::SetEcMetricsStatus(helper.apm(), true);
193 EXPECT_TRUE(helper.GetEcMetricsStatus());
194 apm_helpers::SetEcMetricsStatus(helper.apm(), false);
195 EXPECT_FALSE(helper.GetEcMetricsStatus());
196 }
197
198 TEST(ApmHelpersTest, EcMetrics_NoStatsUnlessEcMetricsAndEcEnabled) {
199 TestHelper helper;
200 EXPECT_FALSE(helper.CanGetEcMetrics());
201
202 apm_helpers::SetEcMetricsStatus(helper.apm(), true);
203 EXPECT_FALSE(helper.CanGetEcMetrics());
204
205 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
206 EXPECT_TRUE(helper.CanGetEcMetrics());
207
208 apm_helpers::SetEcMetricsStatus(helper.apm(), false);
209 EXPECT_FALSE(helper.CanGetEcMetrics());
210 }
211
212 TEST(ApmHelpersTest, AecmMode_DefaultMode) {
213 TestHelper helper;
214 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
215 EXPECT_EQ(EchoControlMobile::kSpeakerphone, ecm->routing_mode());
216 EXPECT_TRUE(ecm->is_comfort_noise_enabled());
217 }
218
219 TEST(ApmHelpersTest, AecmMode_EnableDisableCng) {
220 TestHelper helper;
221 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
222 apm_helpers::SetAecmMode(helper.apm(), false);
223 EXPECT_FALSE(ecm->is_comfort_noise_enabled());
224 apm_helpers::SetAecmMode(helper.apm(), true);
225 EXPECT_TRUE(ecm->is_comfort_noise_enabled());
226 }
227
228 TEST(ApmHelpersTest, NsStatus_DefaultMode) {
229 TestHelper helper;
230 NoiseSuppression* ns = helper.apm()->noise_suppression();
231 EXPECT_EQ(NoiseSuppression::kModerate, ns->level());
232 EXPECT_FALSE(ns->is_enabled());
233 }
234
235 TEST(ApmHelpersTest, NsStatus_EnableDisable) {
236 TestHelper helper;
237 NoiseSuppression* ns = helper.apm()->noise_suppression();
238 apm_helpers::SetNsStatus(helper.apm(), true);
239 EXPECT_EQ(NoiseSuppression::kHigh, ns->level());
240 EXPECT_TRUE(ns->is_enabled());
241 apm_helpers::SetNsStatus(helper.apm(), false);
242 EXPECT_EQ(NoiseSuppression::kHigh, ns->level());
243 EXPECT_FALSE(ns->is_enabled());
244 }
245
246 TEST(ApmHelpersTest, TypingDetectionStatus_DefaultMode) {
247 TestHelper helper;
248 VoiceDetection* vd = helper.apm()->voice_detection();
249 EXPECT_FALSE(vd->is_enabled());
250 }
251
252 TEST(ApmHelpersTest, TypingDetectionStatus_EnableDisable) {
253 TestHelper helper;
254 VoiceDetection* vd = helper.apm()->voice_detection();
255 apm_helpers::SetTypingDetectionStatus(helper.apm(), true);
256 EXPECT_TRUE(vd->is_enabled());
257 apm_helpers::SetTypingDetectionStatus(helper.apm(), false);
258 EXPECT_FALSE(vd->is_enabled());
259 }
260
261 // TODO(solenberg): Move this test to a better place - added here for the sake
262 // of duplicating all relevant tests from audio_processing_test.cc.
263 TEST(ApmHelpersTest, HighPassFilter_DefaultMode) {
264 TestHelper helper;
265 EXPECT_TRUE(helper.apm()->high_pass_filter()->is_enabled());
266 }
267
268 // TODO(solenberg): Move this test to a better place - added here for the sake
269 // of duplicating all relevant tests from audio_processing_test.cc.
270 TEST(ApmHelpersTest, StereoSwapping_DefaultMode) {
271 TestHelper helper;
272 EXPECT_FALSE(helper.transmit_mixer()->IsStereoChannelSwappingEnabled());
273 }
274
275 // TODO(solenberg): Move this test to a better place - added here for the sake
276 // of duplicating all relevant tests from audio_processing_test.cc.
277 TEST(ApmHelpersTest, StereoSwapping_EnableDisable) {
278 TestHelper helper;
279 helper.transmit_mixer()->EnableStereoChannelSwapping(true);
280 EXPECT_TRUE(helper.transmit_mixer()->IsStereoChannelSwappingEnabled());
281 helper.transmit_mixer()->EnableStereoChannelSwapping(false);
282 EXPECT_FALSE(helper.transmit_mixer()->IsStereoChannelSwappingEnabled());
283 }
284 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698