blob: 3a14bec58dc5a664b6fda845fd03920fe9c864d5 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2013, Google Inc.
4 *
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.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/fakemediaengine.h"
36#include "talk/media/base/fakevideorenderer.h"
37#include "talk/media/devices/fakedevicemanager.h"
38
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;
46 constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false);
47 constraints.AddOptional(
48 MediaConstraintsInterface::kExperimentalEchoCancellation, true);
49 constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true);
50 constraints.AddOptional(
51 MediaConstraintsInterface::kExperimentalAutoGainControl, true);
52 constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false);
53 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true);
54
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000056 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
57 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058
59 bool value;
60 EXPECT_TRUE(source->options().echo_cancellation.Get(&value));
61 EXPECT_FALSE(value);
62 EXPECT_TRUE(source->options().experimental_aec.Get(&value));
63 EXPECT_TRUE(value);
64 EXPECT_TRUE(source->options().auto_gain_control.Get(&value));
65 EXPECT_TRUE(value);
66 EXPECT_TRUE(source->options().experimental_agc.Get(&value));
67 EXPECT_TRUE(value);
68 EXPECT_TRUE(source->options().noise_suppression.Get(&value));
69 EXPECT_FALSE(value);
70 EXPECT_TRUE(source->options().highpass_filter.Get(&value));
71 EXPECT_TRUE(value);
72}
73
74TEST(LocalAudioSourceTest, OptionNotSet) {
75 webrtc::FakeConstraints constraints;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000076 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000077 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
78 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 bool value;
80 EXPECT_FALSE(source->options().highpass_filter.Get(&value));
81}
82
83TEST(LocalAudioSourceTest, MandatoryOverridesOptional) {
84 webrtc::FakeConstraints constraints;
85 constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false);
86 constraints.AddOptional(MediaConstraintsInterface::kEchoCancellation, true);
87
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000088 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +000089 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
90 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
92 bool value;
93 EXPECT_TRUE(source->options().echo_cancellation.Get(&value));
94 EXPECT_FALSE(value);
95}
96
97TEST(LocalAudioSourceTest, InvalidOptional) {
98 webrtc::FakeConstraints constraints;
99 constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false);
100 constraints.AddOptional("invalidKey", false);
101
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000102 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000103 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
104 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
106 EXPECT_EQ(MediaSourceInterface::kLive, source->state());
107 bool value;
108 EXPECT_TRUE(source->options().highpass_filter.Get(&value));
109 EXPECT_FALSE(value);
110}
111
112TEST(LocalAudioSourceTest, InvalidMandatory) {
113 webrtc::FakeConstraints constraints;
114 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
115 constraints.AddMandatory("invalidKey", false);
116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117 rtc::scoped_refptr<LocalAudioSource> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000118 LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(),
119 &constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
121 EXPECT_EQ(MediaSourceInterface::kEnded, source->state());
122 bool value;
123 EXPECT_FALSE(source->options().highpass_filter.Get(&value));
124}