blob: 6c0a4a516871822755738784119591f4601aa2cc [file] [log] [blame]
solenberg76377c52017-02-21 00:54:31 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/engine/apm_helpers.h"
solenberg76377c52017-02-21 00:54:31 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/audio_processing/include/audio_processing.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010014#include "rtc_base/scoped_ref_ptr.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/gmock.h"
16#include "test/gtest.h"
solenberg76377c52017-02-21 00:54:31 -080017
18namespace webrtc {
19namespace {
20
Yves Gerey665174f2018-06-19 15:03:05 +020021constexpr AgcConfig kDefaultAgcConfig = {3, 9, true};
solenberg76377c52017-02-21 00:54:31 -080022
23struct TestHelper {
24 TestHelper() {
solenberg76377c52017-02-21 00:54:31 -080025 // This replicates the conditions from voe_auto_test.
26 Config config;
27 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
Ivo Creusen62337e52018-01-09 14:17:33 +010028 apm_ = rtc::scoped_refptr<AudioProcessing>(
29 AudioProcessingBuilder().Create(config));
Fredrik Solenberg55900fd2017-11-23 20:22:55 +010030 apm_helpers::Init(apm());
solenberg76377c52017-02-21 00:54:31 -080031 }
32
peaha9cc40b2017-06-29 08:32:09 -070033 AudioProcessing* apm() { return apm_.get(); }
solenberg76377c52017-02-21 00:54:31 -080034
peaha9cc40b2017-06-29 08:32:09 -070035 const AudioProcessing* apm() const { return apm_.get(); }
solenberg76377c52017-02-21 00:54:31 -080036
solenberg76377c52017-02-21 00:54:31 -080037 private:
peaha9cc40b2017-06-29 08:32:09 -070038 rtc::scoped_refptr<AudioProcessing> apm_;
solenberg76377c52017-02-21 00:54:31 -080039};
40} // namespace
41
42TEST(ApmHelpersTest, AgcConfig_DefaultConfiguration) {
43 TestHelper helper;
Yves Gerey665174f2018-06-19 15:03:05 +020044 AgcConfig agc_config = apm_helpers::GetAgcConfig(helper.apm());
solenberg76377c52017-02-21 00:54:31 -080045
46 EXPECT_EQ(kDefaultAgcConfig.targetLeveldBOv, agc_config.targetLeveldBOv);
47 EXPECT_EQ(kDefaultAgcConfig.digitalCompressionGaindB,
48 agc_config.digitalCompressionGaindB);
49 EXPECT_EQ(kDefaultAgcConfig.limiterEnable, agc_config.limiterEnable);
50}
51
52TEST(ApmHelpersTest, AgcConfig_GetAndSet) {
Yves Gerey665174f2018-06-19 15:03:05 +020053 const AgcConfig agc_config = {11, 17, false};
solenberg76377c52017-02-21 00:54:31 -080054
55 TestHelper helper;
56 apm_helpers::SetAgcConfig(helper.apm(), agc_config);
Yves Gerey665174f2018-06-19 15:03:05 +020057 AgcConfig actual_config = apm_helpers::GetAgcConfig(helper.apm());
solenberg76377c52017-02-21 00:54:31 -080058
59 EXPECT_EQ(agc_config.digitalCompressionGaindB,
60 actual_config.digitalCompressionGaindB);
Yves Gerey665174f2018-06-19 15:03:05 +020061 EXPECT_EQ(agc_config.limiterEnable, actual_config.limiterEnable);
62 EXPECT_EQ(agc_config.targetLeveldBOv, actual_config.targetLeveldBOv);
solenberg76377c52017-02-21 00:54:31 -080063}
64
65TEST(ApmHelpersTest, AgcStatus_DefaultMode) {
66 TestHelper helper;
67 GainControl* gc = helper.apm()->gain_control();
Fredrik Solenberg55900fd2017-11-23 20:22:55 +010068 EXPECT_FALSE(gc->is_enabled());
oprypin45197522017-06-22 01:47:20 -070069#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
Fredrik Solenberg55900fd2017-11-23 20:22:55 +010070 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
oprypin45197522017-06-22 01:47:20 -070071#elif defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
solenberg76377c52017-02-21 00:54:31 -080072 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
73#else
solenberg76377c52017-02-21 00:54:31 -080074 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
75#endif
76}
77
78TEST(ApmHelpersTest, AgcStatus_EnableDisable) {
79 TestHelper helper;
80 GainControl* gc = helper.apm()->gain_control();
81#if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)
henrikae26456a2017-12-13 14:08:48 +010082 apm_helpers::SetAgcStatus(helper.apm(), false);
solenberg76377c52017-02-21 00:54:31 -080083 EXPECT_FALSE(gc->is_enabled());
84 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
85
henrikae26456a2017-12-13 14:08:48 +010086 apm_helpers::SetAgcStatus(helper.apm(), true);
solenberg76377c52017-02-21 00:54:31 -080087 EXPECT_TRUE(gc->is_enabled());
88 EXPECT_EQ(GainControl::kFixedDigital, gc->mode());
89#else
henrikae26456a2017-12-13 14:08:48 +010090 apm_helpers::SetAgcStatus(helper.apm(), false);
solenberg76377c52017-02-21 00:54:31 -080091 EXPECT_FALSE(gc->is_enabled());
92 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
henrikae26456a2017-12-13 14:08:48 +010093 apm_helpers::SetAgcStatus(helper.apm(), true);
solenberg76377c52017-02-21 00:54:31 -080094 EXPECT_TRUE(gc->is_enabled());
95 EXPECT_EQ(GainControl::kAdaptiveAnalog, gc->mode());
96#endif
97}
98
99TEST(ApmHelpersTest, EcStatus_DefaultMode) {
100 TestHelper helper;
101 EchoCancellation* ec = helper.apm()->echo_cancellation();
102 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
103 EXPECT_FALSE(ec->is_enabled());
104 EXPECT_FALSE(ecm->is_enabled());
105}
106
107TEST(ApmHelpersTest, EcStatus_EnableDisable) {
108 TestHelper helper;
109 EchoCancellation* ec = helper.apm()->echo_cancellation();
110 EchoControlMobile* ecm = helper.apm()->echo_control_mobile();
111
112 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
113 EXPECT_FALSE(ec->is_enabled());
114 EXPECT_TRUE(ecm->is_enabled());
115
116 apm_helpers::SetEcStatus(helper.apm(), false, kEcAecm);
117 EXPECT_FALSE(ec->is_enabled());
118 EXPECT_FALSE(ecm->is_enabled());
119
120 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
121 EXPECT_TRUE(ec->is_enabled());
122 EXPECT_FALSE(ecm->is_enabled());
123 EXPECT_EQ(EchoCancellation::kHighSuppression, ec->suppression_level());
124
125 apm_helpers::SetEcStatus(helper.apm(), false, kEcConference);
126 EXPECT_FALSE(ec->is_enabled());
127 EXPECT_FALSE(ecm->is_enabled());
128 EXPECT_EQ(EchoCancellation::kHighSuppression, ec->suppression_level());
129
130 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
131 EXPECT_FALSE(ec->is_enabled());
132 EXPECT_TRUE(ecm->is_enabled());
133}
134
solenberg76377c52017-02-21 00:54:31 -0800135TEST(ApmHelpersTest, NsStatus_DefaultMode) {
136 TestHelper helper;
137 NoiseSuppression* ns = helper.apm()->noise_suppression();
138 EXPECT_EQ(NoiseSuppression::kModerate, ns->level());
139 EXPECT_FALSE(ns->is_enabled());
140}
141
142TEST(ApmHelpersTest, NsStatus_EnableDisable) {
143 TestHelper helper;
144 NoiseSuppression* ns = helper.apm()->noise_suppression();
145 apm_helpers::SetNsStatus(helper.apm(), true);
146 EXPECT_EQ(NoiseSuppression::kHigh, ns->level());
147 EXPECT_TRUE(ns->is_enabled());
148 apm_helpers::SetNsStatus(helper.apm(), false);
149 EXPECT_EQ(NoiseSuppression::kHigh, ns->level());
150 EXPECT_FALSE(ns->is_enabled());
151}
152
153TEST(ApmHelpersTest, TypingDetectionStatus_DefaultMode) {
154 TestHelper helper;
155 VoiceDetection* vd = helper.apm()->voice_detection();
156 EXPECT_FALSE(vd->is_enabled());
157}
158
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100159TEST(ApmHelpersTest, TypingDetectionStatus_EnableDisable) {
solenberg76377c52017-02-21 00:54:31 -0800160 TestHelper helper;
161 VoiceDetection* vd = helper.apm()->voice_detection();
162 apm_helpers::SetTypingDetectionStatus(helper.apm(), true);
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100163 EXPECT_EQ(VoiceDetection::kVeryLowLikelihood, vd->likelihood());
solenberg76377c52017-02-21 00:54:31 -0800164 EXPECT_TRUE(vd->is_enabled());
165 apm_helpers::SetTypingDetectionStatus(helper.apm(), false);
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100166 EXPECT_EQ(VoiceDetection::kVeryLowLikelihood, vd->likelihood());
solenberg76377c52017-02-21 00:54:31 -0800167 EXPECT_FALSE(vd->is_enabled());
168}
169
170// TODO(solenberg): Move this test to a better place - added here for the sake
171// of duplicating all relevant tests from audio_processing_test.cc.
172TEST(ApmHelpersTest, HighPassFilter_DefaultMode) {
173 TestHelper helper;
Fredrik Solenberg55900fd2017-11-23 20:22:55 +0100174 EXPECT_FALSE(helper.apm()->high_pass_filter()->is_enabled());
solenberg76377c52017-02-21 00:54:31 -0800175}
solenberg76377c52017-02-21 00:54:31 -0800176} // namespace webrtc