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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/localaudiosource.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "api/test/fakeconstraints.h" |
| 17 | #include "media/base/fakemediaengine.h" |
| 18 | #include "media/base/fakevideorenderer.h" |
| 19 | #include "rtc_base/gunit.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; |
| 24 | |
| 25 | TEST(LocalAudioSourceTest, SetValidOptions) { |
| 26 | webrtc::FakeConstraints constraints; |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 27 | constraints.AddMandatory( |
| 28 | MediaConstraintsInterface::kGoogEchoCancellation, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | constraints.AddOptional( |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 30 | MediaConstraintsInterface::kExtendedFilterEchoCancellation, true); |
Bjorn Volcker | 1ba344a | 2015-04-29 07:28:10 +0200 | [diff] [blame] | 31 | constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true); |
| 33 | constraints.AddOptional( |
| 34 | MediaConstraintsInterface::kExperimentalAutoGainControl, true); |
| 35 | constraints.AddMandatory(MediaConstraintsInterface::kNoiseSuppression, false); |
| 36 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, true); |
| 37 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 38 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 39 | LocalAudioSource::Create(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 41 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation); |
| 42 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().extended_filter_aec); |
| 43 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().delay_agnostic_aec); |
| 44 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().auto_gain_control); |
| 45 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().experimental_agc); |
| 46 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().noise_suppression); |
| 47 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | TEST(LocalAudioSourceTest, OptionNotSet) { |
| 51 | webrtc::FakeConstraints constraints; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 53 | LocalAudioSource::Create(&constraints); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 54 | EXPECT_EQ(rtc::Optional<bool>(), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { |
| 58 | webrtc::FakeConstraints constraints; |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 59 | constraints.AddMandatory( |
| 60 | MediaConstraintsInterface::kGoogEchoCancellation, false); |
| 61 | constraints.AddOptional( |
| 62 | MediaConstraintsInterface::kGoogEchoCancellation, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 64 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 65 | LocalAudioSource::Create(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 67 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().echo_cancellation); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | TEST(LocalAudioSourceTest, InvalidOptional) { |
| 71 | webrtc::FakeConstraints constraints; |
| 72 | constraints.AddOptional(MediaConstraintsInterface::kHighpassFilter, false); |
| 73 | constraints.AddOptional("invalidKey", false); |
| 74 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 75 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 76 | LocalAudioSource::Create(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | |
| 78 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 79 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TEST(LocalAudioSourceTest, InvalidMandatory) { |
| 83 | webrtc::FakeConstraints constraints; |
| 84 | constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false); |
| 85 | constraints.AddMandatory("invalidKey", false); |
| 86 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 87 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 88 | LocalAudioSource::Create(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | |
xians@webrtc.org | 38d8881 | 2014-08-13 13:51:58 +0000 | [diff] [blame] | 90 | EXPECT_EQ(MediaSourceInterface::kLive, source->state()); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 91 | EXPECT_EQ(rtc::Optional<bool>(false), source->options().highpass_filter); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | } |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 93 | |
| 94 | TEST(LocalAudioSourceTest, InitWithAudioOptions) { |
| 95 | cricket::AudioOptions audio_options; |
| 96 | audio_options.highpass_filter = rtc::Optional<bool>(true); |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 97 | rtc::scoped_refptr<LocalAudioSource> source = |
| 98 | LocalAudioSource::Create(&audio_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 99 | EXPECT_EQ(rtc::Optional<bool>(true), source->options().highpass_filter); |
| 100 | } |
| 101 | |
| 102 | TEST(LocalAudioSourceTest, InitWithNoOptions) { |
| 103 | rtc::scoped_refptr<LocalAudioSource> source = |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 104 | LocalAudioSource::Create((cricket::AudioOptions*)nullptr); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 105 | EXPECT_EQ(rtc::Optional<bool>(), source->options().highpass_filter); |
| 106 | } |