henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/localaudiosource.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/test/fakeconstraints.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 17 | #include "webrtc/base/gunit.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 18 | #include "webrtc/media/base/fakemediaengine.h" |
| 19 | #include "webrtc/media/base/fakevideorenderer.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | |
| 21 | using webrtc::LocalAudioSource; |
| 22 | using webrtc::MediaConstraintsInterface; |
| 23 | using webrtc::MediaSourceInterface; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 24 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
| 26 | TEST(LocalAudioSourceTest, SetValidOptions) { |
| 27 | webrtc::FakeConstraints constraints; |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 28 | constraints.AddMandatory( |
| 29 | MediaConstraintsInterface::kGoogEchoCancellation, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | constraints.AddOptional( |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 31 | MediaConstraintsInterface::kExtendedFilterEchoCancellation, true); |
Bjorn Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 32 | constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true); |
| 34 | constraints.AddOptional( |
| 35 | MediaConstraintsInterface::kExperimentalAutoGainControl, true); |
| 36 | constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false); |
| 37 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true); |
| 38 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 39 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 40 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 41 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 43 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation); |
| 44 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().extended_filter_aec); |
| 45 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().delay_agnostic_aec); |
| 46 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().auto_gain_control); |
| 47 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().experimental_agc); |
| 48 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().noise_suppression); |
| 49 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | TEST(LocalAudioSourceTest, OptionNotSet) { |
| 53 | webrtc::FakeConstraints constraints; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 54 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 55 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 56 | &constraints); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 57 | EXPECT_EQ(rtc::Optional<bool>(), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { |
| 61 | webrtc::FakeConstraints constraints; |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 62 | constraints.AddMandatory( |
| 63 | MediaConstraintsInterface::kGoogEchoCancellation, false); |
| 64 | constraints.AddOptional( |
| 65 | MediaConstraintsInterface::kGoogEchoCancellation, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 67 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 68 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 69 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 71 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | TEST(LocalAudioSourceTest, InvalidOptional) { |
| 75 | webrtc::FakeConstraints constraints; |
| 76 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false); |
| 77 | constraints.AddOptional("invalidKey", false); |
| 78 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 79 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 80 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 81 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
| 83 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 84 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | TEST(LocalAudioSourceTest, InvalidMandatory) { |
| 88 | webrtc::FakeConstraints constraints; |
| 89 | constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 90 | constraints.AddMandatory("invalidKey", false); |
| 91 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 92 | rtc::scoped_refptr<LocalAudioSource> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 93 | LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), |
| 94 | &constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame] | 96 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 97 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | } |