henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/media/base/fakemediaengine.h" |
| 35 | #include "talk/media/base/fakevideorenderer.h" |
| 36 | #include "talk/media/devices/fakedevicemanager.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 37 | #include "webrtc/base/gunit.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
| 39 | using webrtc::LocalAudioSource; |
| 40 | using webrtc::MediaConstraintsInterface; |
| 41 | using webrtc::MediaSourceInterface; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 42 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
| 44 | TEST(LocalAudioSourceTest, SetValidOptions) { |
| 45 | webrtc::FakeConstraints constraints; |
| 46 | constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false); |
| 47 | constraints.AddOptional( |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame^] | 48 | MediaConstraintsInterface::kExtendedFilterEchoCancellation, true); |
Bjorn Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 49 | constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | 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 Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 55 | constraints.AddOptional(MediaConstraintsInterface::kAecDump, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 58 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 59 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | |
| 61 | bool value; |
| 62 | EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); |
| 63 | EXPECT_FALSE(value); |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame^] | 64 | EXPECT_TRUE(source->options().extended_filter_aec.Get(&value)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | EXPECT_TRUE(value); |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 66 | EXPECT_TRUE(source->options().delay_agnostic_aec.Get(&value)); |
Bjorn Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 67 | EXPECT_TRUE(value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | EXPECT_TRUE(source->options().auto_gain_control.Get(&value)); |
| 69 | EXPECT_TRUE(value); |
| 70 | EXPECT_TRUE(source->options().experimental_agc.Get(&value)); |
| 71 | EXPECT_TRUE(value); |
| 72 | EXPECT_TRUE(source->options().noise_suppression.Get(&value)); |
| 73 | EXPECT_FALSE(value); |
| 74 | EXPECT_TRUE(source->options().highpass_filter.Get(&value)); |
| 75 | EXPECT_TRUE(value); |
Bjorn Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 76 | EXPECT_TRUE(source->options().aec_dump.Get(&value)); |
| 77 | EXPECT_TRUE(value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame^] | 80 | // TODO(henrik.lundin) Remove SetExtendedFilterEchoCancellationOff test. |
| 81 | // https://code.google.com/p/webrtc/issues/detail?id=4696 |
| 82 | TEST(LocalAudioSourceTest, SetExtendedFilterEchoCancellationOff) { |
| 83 | webrtc::FakeConstraints constraints; |
| 84 | constraints.AddOptional( |
| 85 | MediaConstraintsInterface::kExtendedFilterEchoCancellation, false); |
| 86 | |
| 87 | rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create( |
| 88 | PeerConnectionFactoryInterface::Options(), &constraints); |
| 89 | |
| 90 | bool value; |
| 91 | EXPECT_TRUE(source->options().extended_filter_aec.Get(&value)); |
| 92 | EXPECT_FALSE(value); |
| 93 | } |
| 94 | |
| 95 | // TODO(henrik.lundin) Remove SetExperimentalEchoCancellationOn test. |
| 96 | // https://code.google.com/p/webrtc/issues/detail?id=4696 |
| 97 | TEST(LocalAudioSourceTest, SetExperimentalEchoCancellationOn) { |
| 98 | webrtc::FakeConstraints constraints; |
| 99 | constraints.AddOptional( |
| 100 | MediaConstraintsInterface::kExperimentalEchoCancellation, true); |
| 101 | |
| 102 | rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create( |
| 103 | PeerConnectionFactoryInterface::Options(), &constraints); |
| 104 | |
| 105 | bool value; |
| 106 | EXPECT_TRUE(source->options().extended_filter_aec.Get(&value)); |
| 107 | EXPECT_TRUE(value); |
| 108 | } |
| 109 | |
| 110 | // TODO(henrik.lundin) Remove SetExperimentalEchoCancellationOff test. |
| 111 | // https://code.google.com/p/webrtc/issues/detail?id=4696 |
| 112 | TEST(LocalAudioSourceTest, SetExperimentalEchoCancellationOff) { |
| 113 | webrtc::FakeConstraints constraints; |
| 114 | constraints.AddOptional( |
| 115 | MediaConstraintsInterface::kExperimentalEchoCancellation, false); |
| 116 | |
| 117 | rtc::scoped_refptr<LocalAudioSource> source = LocalAudioSource::Create( |
| 118 | PeerConnectionFactoryInterface::Options(), &constraints); |
| 119 | |
| 120 | bool value; |
| 121 | EXPECT_TRUE(source->options().extended_filter_aec.Get(&value)); |
| 122 | EXPECT_FALSE(value); |
| 123 | } |
| 124 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | TEST(LocalAudioSourceTest, OptionNotSet) { |
| 126 | webrtc::FakeConstraints constraints; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 127 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 128 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 129 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | bool value; |
| 131 | EXPECT_FALSE(source->options().highpass_filter.Get(&value)); |
| 132 | } |
| 133 | |
| 134 | TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { |
| 135 | webrtc::FakeConstraints constraints; |
| 136 | constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false); |
| 137 | constraints.AddOptional(MediaConstraintsInterface::kEchoCancellation, true); |
| 138 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 139 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 140 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 141 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | |
| 143 | bool value; |
| 144 | EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); |
| 145 | EXPECT_FALSE(value); |
| 146 | } |
| 147 | |
| 148 | TEST(LocalAudioSourceTest, InvalidOptional) { |
| 149 | webrtc::FakeConstraints constraints; |
| 150 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false); |
| 151 | constraints.AddOptional("invalidKey", false); |
| 152 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 153 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 154 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 155 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | |
| 157 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
| 158 | bool value; |
| 159 | EXPECT_TRUE(source->options().highpass_filter.Get(&value)); |
| 160 | EXPECT_FALSE(value); |
| 161 | } |
| 162 | |
| 163 | TEST(LocalAudioSourceTest, InvalidMandatory) { |
| 164 | webrtc::FakeConstraints constraints; |
| 165 | constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 166 | constraints.AddMandatory("invalidKey", false); |
| 167 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 168 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 169 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 170 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 171 | |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame] | 172 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | bool value; |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame] | 174 | EXPECT_TRUE(source->options().highpass_filter.Get(&value)); |
| 175 | EXPECT_FALSE(value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | } |