blob: bf566c627e28abcce6c88d009ccc310ab2c3a58b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "pc/localaudiosource.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
13#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/test/fakeconstraints.h"
17#include "media/base/fakemediaengine.h"
18#include "media/base/fakevideorenderer.h"
19#include "rtc_base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020
21using webrtc::LocalAudioSource;
22using webrtc::MediaConstraintsInterface;
23using webrtc::MediaSourceInterface;
24
25TEST(LocalAudioSourceTest, SetValidOptions) {
26 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +020027 constraints.AddMandatory(
28 MediaConstraintsInterface::kGoogEchoCancellation, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029 constraints.AddOptional(
Henrik Lundin441f6342015-06-09 16:03:13 +020030 MediaConstraintsInterface::kExtendedFilterEchoCancellation, true);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020031 constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true);
33 constraints.AddOptional(
34 MediaConstraintsInterface::kExperimentalAutoGainControl, true);
35 constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false);
36 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true);
37
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000038 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -080039 LocalAudioSource::Create(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010041 EXPECT_EQ(false, source->options().echo_cancellation);
42 EXPECT_EQ(true, source->options().extended_filter_aec);
43 EXPECT_EQ(true, source->options().delay_agnostic_aec);
44 EXPECT_EQ(true, source->options().auto_gain_control);
45 EXPECT_EQ(true, source->options().experimental_agc);
46 EXPECT_EQ(false, source->options().noise_suppression);
47 EXPECT_EQ(true, source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048}
49
50TEST(LocalAudioSourceTest, OptionNotSet) {
51 webrtc::FakeConstraints constraints;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -080053 LocalAudioSource::Create(&constraints);
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010054 EXPECT_EQ(rtc::nullopt, source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055}
56
57TEST(LocalAudioSourceTest, MandatoryOverridesOptional) {
58 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +020059 constraints.AddMandatory(
60 MediaConstraintsInterface::kGoogEchoCancellation, false);
61 constraints.AddOptional(
62 MediaConstraintsInterface::kGoogEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -080065 LocalAudioSource::Create(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010067 EXPECT_EQ(false, source->options().echo_cancellation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068}
69
70TEST(LocalAudioSourceTest, InvalidOptional) {
71 webrtc::FakeConstraints constraints;
72 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false);
73 constraints.AddOptional("invalidKey", false);
74
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -080076 LocalAudioSource::Create(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
78 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010079 EXPECT_EQ(false, source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080}
81
82TEST(LocalAudioSourceTest, InvalidMandatory) {
83 webrtc::FakeConstraints constraints;
84 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
85 constraints.AddMandatory("invalidKey", false);
86
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -080088 LocalAudioSource::Create(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
xians@webrtc.org38d88812014-08-13 13:51:58 +000090 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010091 EXPECT_EQ(false, source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092}
htaa2a49d92016-03-04 02:51:39 -080093
94TEST(LocalAudioSourceTest, InitWithAudioOptions) {
95 cricket::AudioOptions audio_options;
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010096 audio_options.highpass_filter = true;
deadbeef757146b2017-02-10 21:26:48 -080097 rtc::scoped_refptr<LocalAudioSource> source =
98 LocalAudioSource::Create(&audio_options);
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +010099 EXPECT_EQ(true, source->options().highpass_filter);
htaa2a49d92016-03-04 02:51:39 -0800100}
101
102TEST(LocalAudioSourceTest, InitWithNoOptions) {
103 rtc::scoped_refptr<LocalAudioSource> source =
deadbeef757146b2017-02-10 21:26:48 -0800104 LocalAudioSource::Create((cricket::AudioOptions*)nullptr);
Oskar Sundbom36f8f3e2017-11-16 10:54:27 +0100105 EXPECT_EQ(rtc::nullopt, source->options().highpass_filter);
htaa2a49d92016-03-04 02:51:39 -0800106}