blob: 5ff1a7a66425a37d55a03de0f33bff521f4eb181 [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"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "webrtc/base/gunit.h"
kjellandera96e2d72016-02-04 23:52:28 -080035#include "webrtc/media/base/fakemediaengine.h"
36#include "webrtc/media/base/fakevideorenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037
38using webrtc::LocalAudioSource;
39using webrtc::MediaConstraintsInterface;
40using webrtc::MediaSourceInterface;
wu@webrtc.org97077a32013-10-25 21:18:33 +000041using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
43TEST(LocalAudioSourceTest, SetValidOptions) {
44 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +020045 constraints.AddMandatory(
46 MediaConstraintsInterface::kGoogEchoCancellation, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047 constraints.AddOptional(
Henrik Lundin441f6342015-06-09 16:03:13 +020048 MediaConstraintsInterface::kExtendedFilterEchoCancellation, true);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020049 constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true);
51 constraints.AddOptional(
52 MediaConstraintsInterface::kExperimentalAutoGainControl, true);
53 constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false);
54 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true);
Bjorn Volcker1ba344a2015-04-29 07:28:10 +020055 constraints.AddOptional(MediaConstraintsInterface::kAecDump, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000058 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
59 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
Karl Wibergbe579832015-11-10 22:34:18 +010061 EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation);
62 EXPECT_EQ(rtc::Optional<bool>(true), source->options().extended_filter_aec);
63 EXPECT_EQ(rtc::Optional<bool>(true), source->options().delay_agnostic_aec);
64 EXPECT_EQ(rtc::Optional<bool>(true), source->options().auto_gain_control);
65 EXPECT_EQ(rtc::Optional<bool>(true), source->options().experimental_agc);
66 EXPECT_EQ(rtc::Optional<bool>(false), source->options().noise_suppression);
67 EXPECT_EQ(rtc::Optional<bool>(true), source->options().highpass_filter);
68 EXPECT_EQ(rtc::Optional<bool>(true), source->options().aec_dump);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069}
70
71TEST(LocalAudioSourceTest, OptionNotSet) {
72 webrtc::FakeConstraints constraints;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000073 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000074 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
75 &constraints);
Karl Wibergbe579832015-11-10 22:34:18 +010076 EXPECT_EQ(rtc::Optional<bool>(), source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077}
78
79TEST(LocalAudioSourceTest, MandatoryOverridesOptional) {
80 webrtc::FakeConstraints constraints;
Tommi70c7fe12015-06-15 09:14:03 +020081 constraints.AddMandatory(
82 MediaConstraintsInterface::kGoogEchoCancellation, false);
83 constraints.AddOptional(
84 MediaConstraintsInterface::kGoogEchoCancellation, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000086 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000087 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
88 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
Karl Wibergbe579832015-11-10 22:34:18 +010090 EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091}
92
93TEST(LocalAudioSourceTest, InvalidOptional) {
94 webrtc::FakeConstraints constraints;
95 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false);
96 constraints.AddOptional("invalidKey", false);
97
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000098 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000099 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
100 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
102 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
Karl Wibergbe579832015-11-10 22:34:18 +0100103 EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104}
105
106TEST(LocalAudioSourceTest, InvalidMandatory) {
107 webrtc::FakeConstraints constraints;
108 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
109 constraints.AddMandatory("invalidKey", false);
110
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000111 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000112 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
113 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
xians@webrtc.org38d88812014-08-13 13:51:58 +0000115 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
Karl Wibergbe579832015-11-10 22:34:18 +0100116 EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117}