solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/engine/apm_helpers.h" |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 12 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 13 | #include "api/scoped_refptr.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/audio_processing/include/audio_processing.h" |
| 15 | #include "test/gmock.h" |
| 16 | #include "test/gtest.h" |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | namespace { |
| 20 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 21 | struct TestHelper { |
| 22 | TestHelper() { |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 23 | // This replicates the conditions from voe_auto_test. |
| 24 | Config config; |
| 25 | config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 26 | apm_ = rtc::scoped_refptr<AudioProcessing>( |
| 27 | AudioProcessingBuilder().Create(config)); |
Fredrik Solenberg | 55900fd | 2017-11-23 20:22:55 +0100 | [diff] [blame] | 28 | apm_helpers::Init(apm()); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 29 | } |
| 30 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 31 | AudioProcessing* apm() { return apm_.get(); } |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 32 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 33 | const AudioProcessing* apm() const { return apm_.get(); } |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 34 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 35 | private: |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 36 | rtc::scoped_refptr<AudioProcessing> apm_; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 37 | }; |
| 38 | } // namespace |
| 39 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 40 | TEST(ApmHelpersTest, EcStatus_DefaultMode) { |
| 41 | TestHelper helper; |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 42 | webrtc::AudioProcessing::Config config = helper.apm()->GetConfig(); |
| 43 | EXPECT_FALSE(config.echo_canceller.enabled); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | TEST(ApmHelpersTest, EcStatus_EnableDisable) { |
| 47 | TestHelper helper; |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 48 | webrtc::AudioProcessing::Config config; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 49 | |
| 50 | apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm); |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 51 | config = helper.apm()->GetConfig(); |
| 52 | EXPECT_TRUE(config.echo_canceller.enabled); |
| 53 | EXPECT_TRUE(config.echo_canceller.mobile_mode); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 54 | |
| 55 | apm_helpers::SetEcStatus(helper.apm(), false, kEcAecm); |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 56 | config = helper.apm()->GetConfig(); |
| 57 | EXPECT_FALSE(config.echo_canceller.enabled); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 58 | |
| 59 | apm_helpers::SetEcStatus(helper.apm(), true, kEcConference); |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 60 | config = helper.apm()->GetConfig(); |
| 61 | EXPECT_TRUE(config.echo_canceller.enabled); |
| 62 | EXPECT_FALSE(config.echo_canceller.mobile_mode); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 63 | |
| 64 | apm_helpers::SetEcStatus(helper.apm(), false, kEcConference); |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 65 | config = helper.apm()->GetConfig(); |
| 66 | EXPECT_FALSE(config.echo_canceller.enabled); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 67 | |
| 68 | apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm); |
Sam Zackrisson | c1adcad | 2018-10-03 09:19:59 +0200 | [diff] [blame] | 69 | config = helper.apm()->GetConfig(); |
| 70 | EXPECT_TRUE(config.echo_canceller.enabled); |
| 71 | EXPECT_TRUE(config.echo_canceller.mobile_mode); |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 72 | } |
| 73 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 74 | TEST(ApmHelpersTest, NsStatus_DefaultMode) { |
| 75 | TestHelper helper; |
| 76 | NoiseSuppression* ns = helper.apm()->noise_suppression(); |
| 77 | EXPECT_EQ(NoiseSuppression::kModerate, ns->level()); |
| 78 | EXPECT_FALSE(ns->is_enabled()); |
| 79 | } |
| 80 | |
| 81 | TEST(ApmHelpersTest, NsStatus_EnableDisable) { |
| 82 | TestHelper helper; |
| 83 | NoiseSuppression* ns = helper.apm()->noise_suppression(); |
| 84 | apm_helpers::SetNsStatus(helper.apm(), true); |
| 85 | EXPECT_EQ(NoiseSuppression::kHigh, ns->level()); |
| 86 | EXPECT_TRUE(ns->is_enabled()); |
| 87 | apm_helpers::SetNsStatus(helper.apm(), false); |
| 88 | EXPECT_EQ(NoiseSuppression::kHigh, ns->level()); |
| 89 | EXPECT_FALSE(ns->is_enabled()); |
| 90 | } |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 91 | } // namespace webrtc |