OLD | NEW |
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 |
11 #include "webrtc/test/testsupport/fileutils.h" | 11 #include "webrtc/test/testsupport/fileutils.h" |
12 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" | 12 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" |
13 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" | 13 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" |
14 | 14 |
15 class RxCallback : public webrtc::VoERxVadCallback { | |
16 public: | |
17 RxCallback() : | |
18 vad_decision(-1) { | |
19 } | |
20 | |
21 virtual void OnRxVad(int, int vadDecision) { | |
22 char msg[128]; | |
23 sprintf(msg, "RX VAD detected decision %d \n", vadDecision); | |
24 TEST_LOG("%s", msg); | |
25 vad_decision = vadDecision; | |
26 } | |
27 | |
28 int vad_decision; | |
29 }; | |
30 | |
31 class AudioProcessingTest : public AfterStreamingFixture { | 15 class AudioProcessingTest : public AfterStreamingFixture { |
32 protected: | 16 protected: |
33 // Note: Be careful with this one, it is used in the | 17 // Note: Be careful with this one, it is used in the |
34 // Android / iPhone part too. | 18 // Android / iPhone part too. |
35 void TryEnablingAgcWithMode(webrtc::AgcModes agc_mode_to_set) { | 19 void TryEnablingAgcWithMode(webrtc::AgcModes agc_mode_to_set) { |
36 EXPECT_EQ(0, voe_apm_->SetAgcStatus(true, agc_mode_to_set)); | 20 EXPECT_EQ(0, voe_apm_->SetAgcStatus(true, agc_mode_to_set)); |
37 | 21 |
38 bool agc_enabled = false; | 22 bool agc_enabled = false; |
39 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; | 23 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; |
40 | 24 |
41 EXPECT_EQ(0, voe_apm_->GetAgcStatus(agc_enabled, agc_mode)); | 25 EXPECT_EQ(0, voe_apm_->GetAgcStatus(agc_enabled, agc_mode)); |
42 EXPECT_TRUE(agc_enabled); | 26 EXPECT_TRUE(agc_enabled); |
43 EXPECT_EQ(agc_mode_to_set, agc_mode); | 27 EXPECT_EQ(agc_mode_to_set, agc_mode); |
44 } | 28 } |
45 | 29 |
46 void TryEnablingRxAgcWithMode(webrtc::AgcModes agc_mode_to_set) { | |
47 EXPECT_EQ(0, voe_apm_->SetRxAgcStatus(channel_, true, agc_mode_to_set)); | |
48 | |
49 bool rx_agc_enabled = false; | |
50 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; | |
51 | |
52 EXPECT_EQ(0, voe_apm_->GetRxAgcStatus(channel_, rx_agc_enabled, agc_mode)); | |
53 EXPECT_TRUE(rx_agc_enabled); | |
54 EXPECT_EQ(agc_mode_to_set, agc_mode); | |
55 } | |
56 | |
57 // EC modes can map to other EC modes, so we have a separate parameter | 30 // EC modes can map to other EC modes, so we have a separate parameter |
58 // for what we expect the EC mode to be set to. | 31 // for what we expect the EC mode to be set to. |
59 void TryEnablingEcWithMode(webrtc::EcModes ec_mode_to_set, | 32 void TryEnablingEcWithMode(webrtc::EcModes ec_mode_to_set, |
60 webrtc::EcModes expected_mode) { | 33 webrtc::EcModes expected_mode) { |
61 EXPECT_EQ(0, voe_apm_->SetEcStatus(true, ec_mode_to_set)); | 34 EXPECT_EQ(0, voe_apm_->SetEcStatus(true, ec_mode_to_set)); |
62 | 35 |
63 bool ec_enabled = true; | 36 bool ec_enabled = true; |
64 webrtc::EcModes ec_mode = webrtc::kEcDefault; | 37 webrtc::EcModes ec_mode = webrtc::kEcDefault; |
65 | 38 |
66 EXPECT_EQ(0, voe_apm_->GetEcStatus(ec_enabled, ec_mode)); | 39 EXPECT_EQ(0, voe_apm_->GetEcStatus(ec_enabled, ec_mode)); |
(...skipping 20 matching lines...) Expand all Loading... |
87 EXPECT_EQ(0, voe_apm_->SetNsStatus(true, ns_mode_to_set)); | 60 EXPECT_EQ(0, voe_apm_->SetNsStatus(true, ns_mode_to_set)); |
88 | 61 |
89 bool ns_status = true; | 62 bool ns_status = true; |
90 webrtc::NsModes ns_mode = webrtc::kNsDefault; | 63 webrtc::NsModes ns_mode = webrtc::kNsDefault; |
91 EXPECT_EQ(0, voe_apm_->GetNsStatus(ns_status, ns_mode)); | 64 EXPECT_EQ(0, voe_apm_->GetNsStatus(ns_status, ns_mode)); |
92 | 65 |
93 EXPECT_TRUE(ns_status); | 66 EXPECT_TRUE(ns_status); |
94 EXPECT_EQ(expected_ns_mode, ns_mode); | 67 EXPECT_EQ(expected_ns_mode, ns_mode); |
95 } | 68 } |
96 | 69 |
97 void TryEnablingRxNsWithMode(webrtc::NsModes ns_mode_to_set, | |
98 webrtc::NsModes expected_ns_mode) { | |
99 EXPECT_EQ(0, voe_apm_->SetRxNsStatus(channel_, true, ns_mode_to_set)); | |
100 | |
101 bool ns_status = true; | |
102 webrtc::NsModes ns_mode = webrtc::kNsDefault; | |
103 EXPECT_EQ(0, voe_apm_->GetRxNsStatus(channel_, ns_status, ns_mode)); | |
104 | |
105 EXPECT_TRUE(ns_status); | |
106 EXPECT_EQ(expected_ns_mode, ns_mode); | |
107 } | |
108 | |
109 void TryDetectingSilence() { | 70 void TryDetectingSilence() { |
110 // Here, speech is running. Shut down speech. | 71 // Here, speech is running. Shut down speech. |
111 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true)); | 72 EXPECT_EQ(0, voe_codec_->SetVADStatus(channel_, true)); |
112 EXPECT_EQ(0, voe_volume_control_->SetInputMute(channel_, true)); | 73 EXPECT_EQ(0, voe_volume_control_->SetInputMute(channel_, true)); |
113 EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_)); | 74 EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_)); |
114 | 75 |
115 // We should detect the silence after a short time. | 76 // We should detect the silence after a short time. |
116 Sleep(50); | 77 Sleep(50); |
117 for (int i = 0; i < 25; i++) { | 78 for (int i = 0; i < 25; i++) { |
118 EXPECT_EQ(0, voe_apm_->VoiceActivityIndicator(channel_)); | 79 EXPECT_EQ(0, voe_apm_->VoiceActivityIndicator(channel_)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 153 } |
193 | 154 |
194 bool ec_enabled = true; | 155 bool ec_enabled = true; |
195 webrtc::EcModes ec_mode = webrtc::kEcDefault; | 156 webrtc::EcModes ec_mode = webrtc::kEcDefault; |
196 EXPECT_EQ(0, voe_apm_->GetEcStatus(ec_enabled, ec_mode)); | 157 EXPECT_EQ(0, voe_apm_->GetEcStatus(ec_enabled, ec_mode)); |
197 | 158 |
198 EXPECT_FALSE(ec_enabled); | 159 EXPECT_FALSE(ec_enabled); |
199 EXPECT_EQ(webrtc::kEcAec, ec_mode); | 160 EXPECT_EQ(webrtc::kEcAec, ec_mode); |
200 } | 161 } |
201 | 162 |
202 // TODO(phoglund): Reenable below test when it's no longer flaky. | |
203 TEST_F(AudioProcessingTest, DISABLED_TestVoiceActivityDetectionWithObserver) { | |
204 RxCallback rx_callback; | |
205 EXPECT_EQ(0, voe_apm_->RegisterRxVadObserver(channel_, rx_callback)); | |
206 | |
207 // The extra sleeps are to allow decisions some time to propagate to the | |
208 // observer. | |
209 TryDetectingSilence(); | |
210 Sleep(100); | |
211 | |
212 EXPECT_EQ(0, rx_callback.vad_decision); | |
213 | |
214 TryDetectingSpeechAfterSilence(); | |
215 Sleep(100); | |
216 | |
217 EXPECT_EQ(1, rx_callback.vad_decision); | |
218 | |
219 EXPECT_EQ(0, voe_apm_->DeRegisterRxVadObserver(channel_)); | |
220 } | |
221 | |
222 #endif // !WEBRTC_IOS && !WEBRTC_ANDROID | 163 #endif // !WEBRTC_IOS && !WEBRTC_ANDROID |
223 | 164 |
224 TEST_F(AudioProcessingTest, EnablingEcAecmShouldEnableEcAecm) { | 165 TEST_F(AudioProcessingTest, EnablingEcAecmShouldEnableEcAecm) { |
225 // This one apparently applies to Android and iPhone as well. | 166 // This one apparently applies to Android and iPhone as well. |
226 TryEnablingEcWithMode(webrtc::kEcAecm, webrtc::kEcAecm); | 167 TryEnablingEcWithMode(webrtc::kEcAecm, webrtc::kEcAecm); |
227 } | 168 } |
228 | 169 |
229 TEST_F(AudioProcessingTest, EcAecmModeIsEnabledAndSpeakerphoneByDefault) { | 170 TEST_F(AudioProcessingTest, EcAecmModeIsEnabledAndSpeakerphoneByDefault) { |
230 bool cng_enabled = false; | 171 bool cng_enabled = false; |
231 webrtc::AecmModes aecm_mode = webrtc::kAecmEarpiece; | 172 webrtc::AecmModes aecm_mode = webrtc::kAecmEarpiece; |
232 | 173 |
233 voe_apm_->GetAecmMode(aecm_mode, cng_enabled); | 174 voe_apm_->GetAecmMode(aecm_mode, cng_enabled); |
234 | 175 |
235 EXPECT_TRUE(cng_enabled); | 176 EXPECT_TRUE(cng_enabled); |
236 EXPECT_EQ(webrtc::kAecmSpeakerphone, aecm_mode); | 177 EXPECT_EQ(webrtc::kAecmSpeakerphone, aecm_mode); |
237 } | 178 } |
238 | 179 |
239 TEST_F(AudioProcessingTest, CanSetAecmMode) { | 180 TEST_F(AudioProcessingTest, CanSetAecmMode) { |
240 EXPECT_EQ(0, voe_apm_->SetEcStatus(true, webrtc::kEcAecm)); | 181 EXPECT_EQ(0, voe_apm_->SetEcStatus(true, webrtc::kEcAecm)); |
241 | 182 |
242 // Try some AECM mode - CNG enabled combinations. | 183 // Try some AECM mode - CNG enabled combinations. |
243 TryEnablingAecmWithMode(webrtc::kAecmEarpiece, true); | 184 TryEnablingAecmWithMode(webrtc::kAecmEarpiece, true); |
244 TryEnablingAecmWithMode(webrtc::kAecmEarpiece, false); | 185 TryEnablingAecmWithMode(webrtc::kAecmEarpiece, false); |
245 TryEnablingAecmWithMode(webrtc::kAecmLoudEarpiece, true); | 186 TryEnablingAecmWithMode(webrtc::kAecmLoudEarpiece, true); |
246 TryEnablingAecmWithMode(webrtc::kAecmLoudSpeakerphone, false); | 187 TryEnablingAecmWithMode(webrtc::kAecmLoudSpeakerphone, false); |
247 TryEnablingAecmWithMode(webrtc::kAecmQuietEarpieceOrHeadset, true); | 188 TryEnablingAecmWithMode(webrtc::kAecmQuietEarpieceOrHeadset, true); |
248 TryEnablingAecmWithMode(webrtc::kAecmSpeakerphone, false); | 189 TryEnablingAecmWithMode(webrtc::kAecmSpeakerphone, false); |
249 } | 190 } |
250 | 191 |
251 TEST_F(AudioProcessingTest, RxAgcShouldBeOffByDefault) { | |
252 bool rx_agc_enabled = true; | |
253 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; | |
254 | |
255 EXPECT_EQ(0, voe_apm_->GetRxAgcStatus(channel_, rx_agc_enabled, agc_mode)); | |
256 EXPECT_FALSE(rx_agc_enabled); | |
257 EXPECT_EQ(webrtc::kAgcAdaptiveDigital, agc_mode); | |
258 } | |
259 | |
260 TEST_F(AudioProcessingTest, CanTurnOnDigitalRxAcg) { | |
261 TryEnablingRxAgcWithMode(webrtc::kAgcAdaptiveDigital); | |
262 TryEnablingRxAgcWithMode(webrtc::kAgcFixedDigital); | |
263 } | |
264 | |
265 TEST_F(AudioProcessingTest, CannotTurnOnAdaptiveAnalogRxAgc) { | |
266 EXPECT_EQ(-1, voe_apm_->SetRxAgcStatus( | |
267 channel_, true, webrtc::kAgcAdaptiveAnalog)); | |
268 } | |
269 | |
270 TEST_F(AudioProcessingTest, NsIsOffWithModerateSuppressionByDefault) { | 192 TEST_F(AudioProcessingTest, NsIsOffWithModerateSuppressionByDefault) { |
271 bool ns_status = true; | 193 bool ns_status = true; |
272 webrtc::NsModes ns_mode = webrtc::kNsDefault; | 194 webrtc::NsModes ns_mode = webrtc::kNsDefault; |
273 EXPECT_EQ(0, voe_apm_->GetNsStatus(ns_status, ns_mode)); | 195 EXPECT_EQ(0, voe_apm_->GetNsStatus(ns_status, ns_mode)); |
274 | 196 |
275 EXPECT_FALSE(ns_status); | 197 EXPECT_FALSE(ns_status); |
276 EXPECT_EQ(webrtc::kNsModerateSuppression, ns_mode); | 198 EXPECT_EQ(webrtc::kNsModerateSuppression, ns_mode); |
277 } | 199 } |
278 | 200 |
279 TEST_F(AudioProcessingTest, CanSetNsMode) { | 201 TEST_F(AudioProcessingTest, CanSetNsMode) { |
280 // Concrete suppression values map to themselves. | 202 // Concrete suppression values map to themselves. |
281 TryEnablingNsWithMode(webrtc::kNsHighSuppression, | 203 TryEnablingNsWithMode(webrtc::kNsHighSuppression, |
282 webrtc::kNsHighSuppression); | 204 webrtc::kNsHighSuppression); |
283 TryEnablingNsWithMode(webrtc::kNsLowSuppression, | 205 TryEnablingNsWithMode(webrtc::kNsLowSuppression, |
284 webrtc::kNsLowSuppression); | 206 webrtc::kNsLowSuppression); |
285 TryEnablingNsWithMode(webrtc::kNsModerateSuppression, | 207 TryEnablingNsWithMode(webrtc::kNsModerateSuppression, |
286 webrtc::kNsModerateSuppression); | 208 webrtc::kNsModerateSuppression); |
287 TryEnablingNsWithMode(webrtc::kNsVeryHighSuppression, | 209 TryEnablingNsWithMode(webrtc::kNsVeryHighSuppression, |
288 webrtc::kNsVeryHighSuppression); | 210 webrtc::kNsVeryHighSuppression); |
289 | 211 |
290 // Conference and Default map to concrete values. | 212 // Conference and Default map to concrete values. |
291 TryEnablingNsWithMode(webrtc::kNsConference, | 213 TryEnablingNsWithMode(webrtc::kNsConference, |
292 webrtc::kNsHighSuppression); | 214 webrtc::kNsHighSuppression); |
293 TryEnablingNsWithMode(webrtc::kNsDefault, | 215 TryEnablingNsWithMode(webrtc::kNsDefault, |
294 webrtc::kNsModerateSuppression); | 216 webrtc::kNsModerateSuppression); |
295 } | 217 } |
296 | 218 |
297 TEST_F(AudioProcessingTest, RxNsIsOffWithModerateSuppressionByDefault) { | |
298 bool ns_status = true; | |
299 webrtc::NsModes ns_mode = webrtc::kNsDefault; | |
300 EXPECT_EQ(0, voe_apm_->GetRxNsStatus(channel_, ns_status, ns_mode)); | |
301 | |
302 EXPECT_FALSE(ns_status); | |
303 EXPECT_EQ(webrtc::kNsModerateSuppression, ns_mode); | |
304 } | |
305 | |
306 TEST_F(AudioProcessingTest, CanSetRxNsMode) { | |
307 EXPECT_EQ(0, voe_apm_->SetRxNsStatus(channel_, true)); | |
308 | |
309 // See comments on the regular NS test above. | |
310 TryEnablingRxNsWithMode(webrtc::kNsHighSuppression, | |
311 webrtc::kNsHighSuppression); | |
312 TryEnablingRxNsWithMode(webrtc::kNsLowSuppression, | |
313 webrtc::kNsLowSuppression); | |
314 TryEnablingRxNsWithMode(webrtc::kNsModerateSuppression, | |
315 webrtc::kNsModerateSuppression); | |
316 TryEnablingRxNsWithMode(webrtc::kNsVeryHighSuppression, | |
317 webrtc::kNsVeryHighSuppression); | |
318 TryEnablingRxNsWithMode(webrtc::kNsConference, | |
319 webrtc::kNsHighSuppression); | |
320 TryEnablingRxNsWithMode(webrtc::kNsDefault, | |
321 webrtc::kNsModerateSuppression); | |
322 } | |
323 | |
324 TEST_F(AudioProcessingTest, VadIsDisabledByDefault) { | 219 TEST_F(AudioProcessingTest, VadIsDisabledByDefault) { |
325 bool vad_enabled; | 220 bool vad_enabled; |
326 bool disabled_dtx; | 221 bool disabled_dtx; |
327 webrtc::VadModes vad_mode; | 222 webrtc::VadModes vad_mode; |
328 | 223 |
329 EXPECT_EQ(0, voe_codec_->GetVADStatus( | 224 EXPECT_EQ(0, voe_codec_->GetVADStatus( |
330 channel_, vad_enabled, vad_mode, disabled_dtx)); | 225 channel_, vad_enabled, vad_mode, disabled_dtx)); |
331 | 226 |
332 EXPECT_FALSE(vad_enabled); | 227 EXPECT_FALSE(vad_enabled); |
333 } | 228 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 EXPECT_FALSE(ec_enabled); | 301 EXPECT_FALSE(ec_enabled); |
407 EXPECT_EQ(webrtc::kEcAecm, ec_mode); | 302 EXPECT_EQ(webrtc::kEcAecm, ec_mode); |
408 } | 303 } |
409 | 304 |
410 TEST_F(AudioProcessingTest, TestVoiceActivityDetection) { | 305 TEST_F(AudioProcessingTest, TestVoiceActivityDetection) { |
411 TryDetectingSilence(); | 306 TryDetectingSilence(); |
412 TryDetectingSpeechAfterSilence(); | 307 TryDetectingSpeechAfterSilence(); |
413 } | 308 } |
414 | 309 |
415 #endif // WEBRTC_IOS || WEBRTC_ANDROID | 310 #endif // WEBRTC_IOS || WEBRTC_ANDROID |
OLD | NEW |