blob: 7e5d8dea678557696ec4e476e69e4e4c095c95b0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2013 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/localaudiosource.h"
29
30#include <string>
31#include <vector>
32
33#include "talk/app/webrtc/test/fakeconstraints.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/media/base/fakemediaengine.h"
35#include "talk/media/base/fakevideorenderer.h"
36#include "talk/media/devices/fakedevicemanager.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
39using webrtc::LocalAudioSource;
40using webrtc::MediaConstraintsInterface;
41using webrtc::MediaSourceInterface;
wu@webrtc.org97077a32013-10-25 21:18:33 +000042using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043
44TEST(LocalAudioSourceTest, SetValidOptions) {
45 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +020046 constraints.AddMandatory(
47 MediaConstraintsInterface::kGoogEchoCancellation, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 constraints.AddOptional(
Henrik Lundin441f6342015-06-09 16:03:13 +020049 MediaConstraintsInterface::kExtendedFilterEchoCancellation, true);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020050 constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true);
52 constraints.AddOptional(
53 MediaConstraintsInterface::kExperimentalAutoGainControl, true);
54 constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false);
55 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020056 constraints.AddOptional(MediaConstraintsInterface::kAecDump, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000059 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
60 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
62 bool value;
63 EXPECT_TRUE(source->options().echo_cancellation.Get(&value));
64 EXPECT_FALSE(value);
Henrik Lundin441f6342015-06-09 16:03:13 +020065 EXPECT_TRUE(source->options().extended_filter_aec.Get(&value));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 EXPECT_TRUE(value);
Bjorn Volckerbf395c12015-03-25 22:45:56 +010067 EXPECT_TRUE(source->options().delay_agnostic_aec.Get(&value));
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020068 EXPECT_TRUE(value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 EXPECT_TRUE(source->options().auto_gain_control.Get(&value));
70 EXPECT_TRUE(value);
71 EXPECT_TRUE(source->options().experimental_agc.Get(&value));
72 EXPECT_TRUE(value);
73 EXPECT_TRUE(source->options().noise_suppression.Get(&value));
74 EXPECT_FALSE(value);
75 EXPECT_TRUE(source->options().highpass_filter.Get(&value));
76 EXPECT_TRUE(value);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020077 EXPECT_TRUE(source->options().aec_dump.Get(&value));
78 EXPECT_TRUE(value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079}
80
Henrik Lundin441f6342015-06-09 16:03:13 +020081// TODO(henrik.lundin) Remove SetExtendedFilterEchoCancellationOff test.
82// https://code.google.com/p/webrtc/issues/detail?id=4696
83TEST(LocalAudioSourceTest, SetExtendedFilterEchoCancellationOff) {
84 webrtc::FakeConstraints constraints;
85 constraints.AddOptional(
86 MediaConstraintsInterface::kExtendedFilterEchoCancellation, false);
87
88 rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create(
89 PeerConnectionFactoryInterface::Options(), &constraints);
90
91 bool value;
92 EXPECT_TRUE(source->options().extended_filter_aec.Get(&value));
93 EXPECT_FALSE(value);
94}
95
96// TODO(henrik.lundin) Remove SetExperimentalEchoCancellationOn test.
97// https://code.google.com/p/webrtc/issues/detail?id=4696
98TEST(LocalAudioSourceTest, SetExperimentalEchoCancellationOn) {
99 webrtc::FakeConstraints constraints;
100 constraints.AddOptional(
101 MediaConstraintsInterface::kExperimentalEchoCancellation, true);
102
103 rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create(
104 PeerConnectionFactoryInterface::Options(), &constraints);
105
106 bool value;
107 EXPECT_TRUE(source->options().extended_filter_aec.Get(&value));
108 EXPECT_TRUE(value);
109}
110
111// TODO(henrik.lundin) Remove SetExperimentalEchoCancellationOff test.
112// https://code.google.com/p/webrtc/issues/detail?id=4696
113TEST(LocalAudioSourceTest, SetExperimentalEchoCancellationOff) {
114 webrtc::FakeConstraints constraints;
115 constraints.AddOptional(
116 MediaConstraintsInterface::kExperimentalEchoCancellation, false);
117
118 rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create(
119 PeerConnectionFactoryInterface::Options(), &constraints);
120
121 bool value;
122 EXPECT_TRUE(source->options().extended_filter_aec.Get(&value));
123 EXPECT_FALSE(value);
124}
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126TEST(LocalAudioSourceTest, OptionNotSet) {
127 webrtc::FakeConstraints constraints;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000128 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000129 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
130 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 bool value;
132 EXPECT_FALSE(source->options().highpass_filter.Get(&value));
133}
134
135TEST(LocalAudioSourceTest, MandatoryOverridesOptional) {
136 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +0200137 constraints.AddMandatory(
138 MediaConstraintsInterface::kGoogEchoCancellation, false);
139 constraints.AddOptional(
140 MediaConstraintsInterface::kGoogEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000142 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000143 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
144 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145
146 bool value;
147 EXPECT_TRUE(source->options().echo_cancellation.Get(&value));
148 EXPECT_FALSE(value);
149}
150
151TEST(LocalAudioSourceTest, InvalidOptional) {
152 webrtc::FakeConstraints constraints;
153 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false);
154 constraints.AddOptional("invalidKey", false);
155
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000156 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000157 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
158 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159
160 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
161 bool value;
162 EXPECT_TRUE(source->options().highpass_filter.Get(&value));
163 EXPECT_FALSE(value);
164}
165
166TEST(LocalAudioSourceTest, InvalidMandatory) {
167 webrtc::FakeConstraints constraints;
168 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
169 constraints.AddMandatory("invalidKey", false);
170
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000171 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000172 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
173 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174
xians@webrtc.org38d88812014-08-13 13:51:58 +0000175 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 bool value;
xians@webrtc.org38d88812014-08-13 13:51:58 +0000177 EXPECT_TRUE(source->options().highpass_filter.Get(&value));
178 EXPECT_FALSE(value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179}