henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 34 | #include "webrtc/base/gunit.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include "talk/media/base/fakemediaengine.h" |
| 36 | #include "talk/media/base/fakevideorenderer.h" |
| 37 | #include "talk/media/devices/fakedevicemanager.h" |
| 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( |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 55 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 56 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 57 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 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 | |
| 74 | TEST(LocalAudioSourceTest, OptionNotSet) { |
| 75 | webrtc::FakeConstraints constraints; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 76 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 77 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 78 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | bool value; |
| 80 | EXPECT_FALSE(source->options().highpass_filter.Get(&value)); |
| 81 | } |
| 82 | |
| 83 | TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { |
| 84 | webrtc::FakeConstraints constraints; |
| 85 | constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false); |
| 86 | constraints.AddOptional(MediaConstraintsInterface::kEchoCancellation, true); |
| 87 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 88 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 89 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 90 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | |
| 92 | bool value; |
| 93 | EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); |
| 94 | EXPECT_FALSE(value); |
| 95 | } |
| 96 | |
| 97 | TEST(LocalAudioSourceTest, InvalidOptional) { |
| 98 | webrtc::FakeConstraints constraints; |
| 99 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false); |
| 100 | constraints.AddOptional("invalidKey", false); |
| 101 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 102 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 103 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 104 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | |
| 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 | |
| 112 | TEST(LocalAudioSourceTest, InvalidMandatory) { |
| 113 | webrtc::FakeConstraints constraints; |
| 114 | constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 115 | constraints.AddMandatory("invalidKey", false); |
| 116 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 117 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 118 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 119 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame^] | 121 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | bool value; |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame^] | 123 | EXPECT_TRUE(source->options().highpass_filter.Get(&value)); |
| 124 | EXPECT_FALSE(value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | } |