blob: e418795b13660c637b9434d3e323d1f980ca93f7 [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 Bonadeid9708072019-01-25 20:26:48 +010013#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_processing/include/audio_processing.h"
15#include "test/gmock.h"
16#include "test/gtest.h"
solenberg76377c52017-02-21 00:54:31 -080017
18namespace webrtc {
19namespace {
20
solenberg76377c52017-02-21 00:54:31 -080021struct TestHelper {
22 TestHelper() {
solenberg76377c52017-02-21 00:54:31 -080023 // This replicates the conditions from voe_auto_test.
24 Config config;
25 config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
Ivo Creusen62337e52018-01-09 14:17:33 +010026 apm_ = rtc::scoped_refptr<AudioProcessing>(
27 AudioProcessingBuilder().Create(config));
Fredrik Solenberg55900fd2017-11-23 20:22:55 +010028 apm_helpers::Init(apm());
solenberg76377c52017-02-21 00:54:31 -080029 }
30
peaha9cc40b2017-06-29 08:32:09 -070031 AudioProcessing* apm() { return apm_.get(); }
solenberg76377c52017-02-21 00:54:31 -080032
peaha9cc40b2017-06-29 08:32:09 -070033 const AudioProcessing* apm() const { return apm_.get(); }
solenberg76377c52017-02-21 00:54:31 -080034
solenberg76377c52017-02-21 00:54:31 -080035 private:
peaha9cc40b2017-06-29 08:32:09 -070036 rtc::scoped_refptr<AudioProcessing> apm_;
solenberg76377c52017-02-21 00:54:31 -080037};
38} // namespace
39
solenberg76377c52017-02-21 00:54:31 -080040TEST(ApmHelpersTest, EcStatus_DefaultMode) {
41 TestHelper helper;
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020042 webrtc::AudioProcessing::Config config = helper.apm()->GetConfig();
43 EXPECT_FALSE(config.echo_canceller.enabled);
solenberg76377c52017-02-21 00:54:31 -080044}
45
46TEST(ApmHelpersTest, EcStatus_EnableDisable) {
47 TestHelper helper;
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020048 webrtc::AudioProcessing::Config config;
solenberg76377c52017-02-21 00:54:31 -080049
50 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020051 config = helper.apm()->GetConfig();
52 EXPECT_TRUE(config.echo_canceller.enabled);
53 EXPECT_TRUE(config.echo_canceller.mobile_mode);
solenberg76377c52017-02-21 00:54:31 -080054
55 apm_helpers::SetEcStatus(helper.apm(), false, kEcAecm);
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020056 config = helper.apm()->GetConfig();
57 EXPECT_FALSE(config.echo_canceller.enabled);
solenberg76377c52017-02-21 00:54:31 -080058
59 apm_helpers::SetEcStatus(helper.apm(), true, kEcConference);
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020060 config = helper.apm()->GetConfig();
61 EXPECT_TRUE(config.echo_canceller.enabled);
62 EXPECT_FALSE(config.echo_canceller.mobile_mode);
solenberg76377c52017-02-21 00:54:31 -080063
64 apm_helpers::SetEcStatus(helper.apm(), false, kEcConference);
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020065 config = helper.apm()->GetConfig();
66 EXPECT_FALSE(config.echo_canceller.enabled);
solenberg76377c52017-02-21 00:54:31 -080067
68 apm_helpers::SetEcStatus(helper.apm(), true, kEcAecm);
Sam Zackrissonc1adcad2018-10-03 09:19:59 +020069 config = helper.apm()->GetConfig();
70 EXPECT_TRUE(config.echo_canceller.enabled);
71 EXPECT_TRUE(config.echo_canceller.mobile_mode);
solenberg76377c52017-02-21 00:54:31 -080072}
73
solenberg76377c52017-02-21 00:54:31 -080074TEST(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
81TEST(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}
solenberg76377c52017-02-21 00:54:31 -080091} // namespace webrtc