blob: d7e470ca120f9cadda7feb81a21fe49570905312 [file] [log] [blame]
peah8d2ade62016-03-22 11:05:12 -07001/*
Sam Zackrisson8c147b62018-09-28 12:40:47 +02002 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
peah8d2ade62016-03-22 11:05:12 -07003 *
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 */
Sam Zackrisson8c147b62018-09-28 12:40:47 +020010
11#include <array>
peah8d2ade62016-03-22 11:05:12 -070012#include <vector>
13
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_processing/echo_control_mobile_impl.h"
Sam Zackrisson8c147b62018-09-28 12:40:47 +020015#include "modules/audio_processing/include/audio_processing.h"
16#include "rtc_base/criticalsection.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "test/gtest.h"
peah8d2ade62016-03-22 11:05:12 -070018
19namespace webrtc {
Sam Zackrisson8c147b62018-09-28 12:40:47 +020020TEST(EchoControlMobileTest, InterfaceConfiguration) {
peah8d2ade62016-03-22 11:05:12 -070021 rtc::CriticalSection crit_render;
22 rtc::CriticalSection crit_capture;
Sam Zackrisson8c147b62018-09-28 12:40:47 +020023 EchoControlMobileImpl aecm(&crit_render, &crit_capture);
24 aecm.Initialize(AudioProcessing::kSampleRate16kHz, 2, 2);
peah8d2ade62016-03-22 11:05:12 -070025
Sam Zackrisson8c147b62018-09-28 12:40:47 +020026 // Turn AECM on
27 EXPECT_EQ(0, aecm.Enable(true));
28 EXPECT_TRUE(aecm.is_enabled());
peah8d2ade62016-03-22 11:05:12 -070029
Sam Zackrisson8c147b62018-09-28 12:40:47 +020030 // Toggle routing modes
31 std::array<EchoControlMobileImpl::RoutingMode, 5> routing_modes = {
32 EchoControlMobileImpl::kQuietEarpieceOrHeadset,
33 EchoControlMobileImpl::kEarpiece,
34 EchoControlMobileImpl::kLoudEarpiece,
35 EchoControlMobileImpl::kSpeakerphone,
36 EchoControlMobileImpl::kLoudSpeakerphone,
37 };
38 for (auto mode : routing_modes) {
39 EXPECT_EQ(0, aecm.set_routing_mode(mode));
40 EXPECT_EQ(mode, aecm.routing_mode());
peah8d2ade62016-03-22 11:05:12 -070041 }
42
Sam Zackrisson8c147b62018-09-28 12:40:47 +020043 // Turn comfort noise off/on
44 EXPECT_EQ(0, aecm.enable_comfort_noise(false));
45 EXPECT_FALSE(aecm.is_comfort_noise_enabled());
46 EXPECT_EQ(0, aecm.enable_comfort_noise(true));
47 EXPECT_TRUE(aecm.is_comfort_noise_enabled());
peah8d2ade62016-03-22 11:05:12 -070048
Sam Zackrisson8c147b62018-09-28 12:40:47 +020049 // Set and get echo path
50 const size_t echo_path_size = aecm.echo_path_size_bytes();
51 std::vector<uint8_t> echo_path_in(echo_path_size);
52 std::vector<uint8_t> echo_path_out(echo_path_size);
53 EXPECT_EQ(AudioProcessing::kNullPointerError,
54 aecm.SetEchoPath(nullptr, echo_path_size));
55 EXPECT_EQ(AudioProcessing::kNullPointerError,
56 aecm.GetEchoPath(nullptr, echo_path_size));
57 EXPECT_EQ(AudioProcessing::kBadParameterError,
58 aecm.GetEchoPath(echo_path_out.data(), 1));
59 EXPECT_EQ(0, aecm.GetEchoPath(echo_path_out.data(), echo_path_size));
60 for (size_t i = 0; i < echo_path_size; i++) {
61 echo_path_in[i] = echo_path_out[i] + 1;
62 }
63 EXPECT_EQ(AudioProcessing::kBadParameterError,
64 aecm.SetEchoPath(echo_path_in.data(), 1));
65 EXPECT_EQ(0, aecm.SetEchoPath(echo_path_in.data(), echo_path_size));
66 EXPECT_EQ(0, aecm.GetEchoPath(echo_path_out.data(), echo_path_size));
67 for (size_t i = 0; i < echo_path_size; i++) {
68 EXPECT_EQ(echo_path_in[i], echo_path_out[i]);
69 }
peah8d2ade62016-03-22 11:05:12 -070070
Sam Zackrisson8c147b62018-09-28 12:40:47 +020071 // Turn AECM off
72 EXPECT_EQ(0, aecm.Enable(false));
73 EXPECT_FALSE(aecm.is_enabled());
peah8d2ade62016-03-22 11:05:12 -070074}
75
76} // namespace webrtc