jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2008 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 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 28 | #include "talk/app/webrtc/mediacontroller.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | #include "talk/media/base/fakecapturemanager.h" |
| 30 | #include "talk/media/base/fakemediaengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | #include "talk/media/base/testutils.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 32 | #include "talk/media/devices/fakedevicemanager.h" |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 33 | #include "talk/media/webrtc/fakewebrtccall.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/session/media/channelmanager.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "webrtc/base/gunit.h" |
| 36 | #include "webrtc/base/logging.h" |
| 37 | #include "webrtc/base/thread.h" |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 38 | #include "webrtc/p2p/base/faketransportcontroller.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | |
| 40 | namespace cricket { |
| 41 | |
| 42 | static const AudioCodec kAudioCodecs[] = { |
| 43 | AudioCodec(97, "voice", 1, 2, 3, 0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | AudioCodec(111, "OPUS", 48000, 32000, 2, 0), |
| 45 | }; |
| 46 | |
| 47 | static const VideoCodec kVideoCodecs[] = { |
| 48 | VideoCodec(99, "H264", 100, 200, 300, 0), |
| 49 | VideoCodec(100, "VP8", 100, 200, 300, 0), |
| 50 | VideoCodec(96, "rtx", 100, 200, 300, 0), |
| 51 | }; |
| 52 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 53 | class FakeMediaController : public webrtc::MediaControllerInterface { |
| 54 | public: |
| 55 | explicit FakeMediaController(webrtc::Call* call) : call_(call) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 56 | RTC_DCHECK(nullptr != call); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 57 | } |
| 58 | ~FakeMediaController() override {} |
| 59 | webrtc::Call* call_w() override { return call_; } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 60 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 61 | private: |
| 62 | webrtc::Call* call_; |
| 63 | }; |
| 64 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | class ChannelManagerTest : public testing::Test { |
| 66 | protected: |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 67 | ChannelManagerTest() |
| 68 | : fake_call_(webrtc::Call::Config()), |
| 69 | fake_mc_(&fake_call_), |
| 70 | fme_(NULL), |
| 71 | fdm_(NULL), |
| 72 | fcm_(NULL), |
| 73 | cm_(NULL) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
| 75 | virtual void SetUp() { |
| 76 | fme_ = new cricket::FakeMediaEngine(); |
| 77 | fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
| 78 | fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
| 79 | fdme_ = new cricket::FakeDataEngine(); |
| 80 | fdm_ = new cricket::FakeDeviceManager(); |
| 81 | fcm_ = new cricket::FakeCaptureManager(); |
| 82 | cm_ = new cricket::ChannelManager( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 83 | fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 84 | transport_controller_ = |
| 85 | new cricket::FakeTransportController(ICEROLE_CONTROLLING); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
| 87 | std::vector<std::string> in_device_list, out_device_list, vid_device_list; |
| 88 | in_device_list.push_back("audio-in1"); |
| 89 | in_device_list.push_back("audio-in2"); |
| 90 | out_device_list.push_back("audio-out1"); |
| 91 | out_device_list.push_back("audio-out2"); |
| 92 | vid_device_list.push_back("video-in1"); |
| 93 | vid_device_list.push_back("video-in2"); |
| 94 | fdm_->SetAudioInputDevices(in_device_list); |
| 95 | fdm_->SetAudioOutputDevices(out_device_list); |
| 96 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 97 | } |
| 98 | |
| 99 | virtual void TearDown() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 100 | delete transport_controller_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | delete cm_; |
| 102 | cm_ = NULL; |
| 103 | fdm_ = NULL; |
| 104 | fcm_ = NULL; |
| 105 | fdme_ = NULL; |
| 106 | fme_ = NULL; |
| 107 | } |
| 108 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 109 | rtc::Thread worker_; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 110 | cricket::FakeCall fake_call_; |
| 111 | cricket::FakeMediaController fake_mc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | cricket::FakeMediaEngine* fme_; |
| 113 | cricket::FakeDataEngine* fdme_; |
| 114 | cricket::FakeDeviceManager* fdm_; |
| 115 | cricket::FakeCaptureManager* fcm_; |
| 116 | cricket::ChannelManager* cm_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 117 | cricket::FakeTransportController* transport_controller_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | // Test that we startup/shutdown properly. |
| 121 | TEST_F(ChannelManagerTest, StartupShutdown) { |
| 122 | EXPECT_FALSE(cm_->initialized()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 123 | EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | EXPECT_TRUE(cm_->Init()); |
| 125 | EXPECT_TRUE(cm_->initialized()); |
| 126 | cm_->Terminate(); |
| 127 | EXPECT_FALSE(cm_->initialized()); |
| 128 | } |
| 129 | |
| 130 | // Test that we startup/shutdown properly with a worker thread. |
| 131 | TEST_F(ChannelManagerTest, StartupShutdownOnThread) { |
| 132 | worker_.Start(); |
| 133 | EXPECT_FALSE(cm_->initialized()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 134 | EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
| 136 | EXPECT_EQ(&worker_, cm_->worker_thread()); |
| 137 | EXPECT_TRUE(cm_->Init()); |
| 138 | EXPECT_TRUE(cm_->initialized()); |
| 139 | // Setting the worker thread while initialized should fail. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 140 | EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | cm_->Terminate(); |
| 142 | EXPECT_FALSE(cm_->initialized()); |
| 143 | } |
| 144 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | // Test that we can create and destroy a voice and video channel. |
| 146 | TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
| 147 | EXPECT_TRUE(cm_->Init()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 148 | cricket::VoiceChannel* voice_channel = |
| 149 | cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, |
| 150 | cricket::CN_AUDIO, false, AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 151 | EXPECT_TRUE(voice_channel != nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 152 | cricket::VideoChannel* video_channel = |
| 153 | cm_->CreateVideoChannel(&fake_mc_, transport_controller_, |
| 154 | cricket::CN_VIDEO, false, VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 155 | EXPECT_TRUE(video_channel != nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 156 | cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 157 | transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 158 | EXPECT_TRUE(data_channel != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 159 | cm_->DestroyVideoChannel(video_channel); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 160 | cm_->DestroyVoiceChannel(voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | cm_->DestroyDataChannel(data_channel); |
| 162 | cm_->Terminate(); |
| 163 | } |
| 164 | |
| 165 | // Test that we can create and destroy a voice and video channel with a worker. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 166 | TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | worker_.Start(); |
| 168 | EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
| 169 | EXPECT_TRUE(cm_->Init()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 170 | delete transport_controller_; |
| 171 | transport_controller_ = |
| 172 | new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING); |
| 173 | cricket::VoiceChannel* voice_channel = |
| 174 | cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, |
| 175 | cricket::CN_AUDIO, false, AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 176 | EXPECT_TRUE(voice_channel != nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 177 | cricket::VideoChannel* video_channel = |
| 178 | cm_->CreateVideoChannel(&fake_mc_, transport_controller_, |
| 179 | cricket::CN_VIDEO, false, VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 180 | EXPECT_TRUE(video_channel != nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 181 | cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 182 | transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 183 | EXPECT_TRUE(data_channel != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | cm_->DestroyVideoChannel(video_channel); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 185 | cm_->DestroyVoiceChannel(voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | cm_->DestroyDataChannel(data_channel); |
| 187 | cm_->Terminate(); |
| 188 | } |
| 189 | |
| 190 | // Test that we fail to create a voice/video channel if the session is unable |
| 191 | // to create a cricket::TransportChannel |
| 192 | TEST_F(ChannelManagerTest, NoTransportChannelTest) { |
| 193 | EXPECT_TRUE(cm_->Init()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 194 | transport_controller_->set_fail_channel_creation(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | // The test is useless unless the session does not fail creating |
| 196 | // cricket::TransportChannel. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 197 | ASSERT_TRUE(transport_controller_->CreateTransportChannel_w( |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 198 | "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 200 | cricket::VoiceChannel* voice_channel = |
| 201 | cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, |
| 202 | cricket::CN_AUDIO, false, AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 203 | EXPECT_TRUE(voice_channel == nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 204 | cricket::VideoChannel* video_channel = |
| 205 | cm_->CreateVideoChannel(&fake_mc_, transport_controller_, |
| 206 | cricket::CN_VIDEO, false, VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 207 | EXPECT_TRUE(video_channel == nullptr); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame^] | 208 | cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 209 | transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 210 | EXPECT_TRUE(data_channel == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 211 | cm_->Terminate(); |
| 212 | } |
| 213 | |
| 214 | // Test that SetDefaultVideoCodec passes through the right values. |
| 215 | TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { |
| 216 | cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); |
| 217 | cricket::VideoEncoderConfig config(codec, 1, 2); |
| 218 | EXPECT_TRUE(cm_->Init()); |
| 219 | EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); |
| 220 | EXPECT_EQ(config, fme_->default_video_encoder_config()); |
| 221 | } |
| 222 | |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 223 | struct GetCapturerFrameSize : public sigslot::has_slots<> { |
| 224 | void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* frame) { |
| 225 | width = frame->GetWidth(); |
| 226 | height = frame->GetHeight(); |
| 227 | } |
| 228 | GetCapturerFrameSize(VideoCapturer* capturer) : width(0), height(0) { |
| 229 | capturer->SignalVideoFrame.connect(this, |
| 230 | &GetCapturerFrameSize::OnVideoFrame); |
| 231 | static_cast<FakeVideoCapturer*>(capturer)->CaptureFrame(); |
| 232 | } |
| 233 | size_t width; |
| 234 | size_t height; |
| 235 | }; |
| 236 | |
| 237 | TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) { |
| 238 | VideoCodec codec(100, "VP8", 640, 360, 30, 0); |
| 239 | VideoFormat format(640, 360, 33, FOURCC_ANY); |
| 240 | VideoEncoderConfig config(codec, 1, 2); |
| 241 | EXPECT_TRUE(cm_->Init()); |
| 242 | // A capturer created before the default encoder config is set will have no |
magjed@webrtc.org | 35c1ace | 2014-11-13 16:21:49 +0000 | [diff] [blame] | 243 | // set aspect ratio, so it'll be 4:3 (based on the fake video capture impl). |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 244 | VideoCapturer* capturer = cm_->CreateVideoCapturer(); |
| 245 | ASSERT_TRUE(capturer != NULL); |
| 246 | EXPECT_EQ(CS_RUNNING, capturer->Start(format)); |
| 247 | GetCapturerFrameSize size(capturer); |
| 248 | EXPECT_EQ(640u, size.width); |
magjed@webrtc.org | 35c1ace | 2014-11-13 16:21:49 +0000 | [diff] [blame] | 249 | EXPECT_EQ(480u, size.height); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 250 | delete capturer; |
| 251 | // Try again, but with the encoder config set to 16:9. |
| 252 | EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); |
| 253 | capturer = cm_->CreateVideoCapturer(); |
| 254 | ASSERT_TRUE(capturer != NULL); |
| 255 | EXPECT_EQ(CS_RUNNING, capturer->Start(format)); |
| 256 | GetCapturerFrameSize cropped_size(capturer); |
| 257 | EXPECT_EQ(640u, cropped_size.width); |
| 258 | EXPECT_EQ(360u, cropped_size.height); |
| 259 | delete capturer; |
| 260 | } |
| 261 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 262 | // Test that SetDefaultVideoCodec passes through the right values. |
| 263 | TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) { |
| 264 | cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); |
| 265 | cricket::VideoEncoderConfig config(codec, 1, 2); |
| 266 | EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); |
| 267 | EXPECT_TRUE(cm_->Init()); |
| 268 | EXPECT_EQ(config, fme_->default_video_encoder_config()); |
| 269 | } |
| 270 | |
| 271 | TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) { |
| 272 | // Test that values that we set before Init are applied. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 273 | AudioOptions options; |
| 274 | options.auto_gain_control.Set(true); |
| 275 | options.echo_cancellation.Set(false); |
| 276 | EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options)); |
| 277 | std::string audio_in, audio_out; |
| 278 | AudioOptions set_options; |
| 279 | // Check options before Init. |
| 280 | EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options)); |
| 281 | EXPECT_EQ("audio-in1", audio_in); |
| 282 | EXPECT_EQ("audio-out1", audio_out); |
| 283 | EXPECT_EQ(options, set_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 284 | EXPECT_TRUE(cm_->Init()); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 285 | // Check options after Init. |
| 286 | EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options)); |
| 287 | EXPECT_EQ("audio-in1", audio_in); |
| 288 | EXPECT_EQ("audio-out1", audio_out); |
| 289 | EXPECT_EQ(options, set_options); |
| 290 | // At this point, the media engine should also be initialized. |
| 291 | EXPECT_EQ(options, fme_->audio_options()); |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 292 | EXPECT_EQ(cricket::kDefaultAudioDelayOffset, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | fme_->audio_delay_offset()); |
| 294 | } |
| 295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 296 | TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) { |
| 297 | std::string audio_in, audio_out; |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 298 | AudioOptions options; |
| 299 | options.echo_cancellation.Set(true); |
| 300 | EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL)); |
| 302 | EXPECT_EQ("audio-in2", audio_in); |
| 303 | EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL)); |
| 304 | EXPECT_EQ("audio-out2", audio_out); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 305 | AudioOptions out_options; |
| 306 | EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options)); |
| 307 | bool echo_cancellation = false; |
| 308 | EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation)); |
| 309 | EXPECT_TRUE(echo_cancellation); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | TEST_F(ChannelManagerTest, SetAudioOptions) { |
| 313 | // Test initial state. |
| 314 | EXPECT_TRUE(cm_->Init()); |
| 315 | EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName), |
| 316 | fme_->audio_in_device()); |
| 317 | EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName), |
| 318 | fme_->audio_out_device()); |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 319 | EXPECT_EQ(cricket::kDefaultAudioDelayOffset, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | fme_->audio_delay_offset()); |
| 321 | // Test setting specific values. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 322 | AudioOptions options; |
| 323 | options.auto_gain_control.Set(true); |
| 324 | EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | EXPECT_EQ("audio-in1", fme_->audio_in_device()); |
| 326 | EXPECT_EQ("audio-out1", fme_->audio_out_device()); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 327 | bool auto_gain_control = false; |
| 328 | EXPECT_TRUE( |
| 329 | fme_->audio_options().auto_gain_control.Get(&auto_gain_control)); |
| 330 | EXPECT_TRUE(auto_gain_control); |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 331 | EXPECT_EQ(cricket::kDefaultAudioDelayOffset, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 332 | fme_->audio_delay_offset()); |
| 333 | // Test setting bad values. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 334 | EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) { |
| 338 | // Test that values that we set before Init are applied. |
| 339 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in2")); |
| 340 | EXPECT_TRUE(cm_->Init()); |
| 341 | EXPECT_EQ("video-in2", cm_->video_device_name()); |
| 342 | } |
| 343 | |
| 344 | TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) { |
| 345 | std::string video_in; |
| 346 | // Test that GetCaptureDevice works before Init. |
| 347 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in1")); |
| 348 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 349 | EXPECT_EQ("video-in1", video_in); |
| 350 | // Test that options set before Init can be gotten after Init. |
| 351 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in2")); |
| 352 | EXPECT_TRUE(cm_->Init()); |
| 353 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 354 | EXPECT_EQ("video-in2", video_in); |
| 355 | } |
| 356 | |
| 357 | TEST_F(ChannelManagerTest, SetCaptureDevice) { |
| 358 | // Test setting defaults. |
| 359 | EXPECT_TRUE(cm_->Init()); |
| 360 | EXPECT_TRUE(cm_->SetCaptureDevice("")); // will use DeviceManager default |
| 361 | EXPECT_EQ("video-in1", cm_->video_device_name()); |
| 362 | // Test setting specific values. |
| 363 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in2")); |
| 364 | EXPECT_EQ("video-in2", cm_->video_device_name()); |
| 365 | // TODO(juberti): Add test for invalid value here. |
| 366 | } |
| 367 | |
| 368 | // Test unplugging and plugging back the preferred devices. When the preferred |
| 369 | // device is unplugged, we fall back to the default device. When the preferred |
| 370 | // device is plugged back, we use it. |
| 371 | TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) { |
| 372 | // Set preferences "audio-in1" and "audio-out1" before init. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 373 | AudioOptions options; |
| 374 | EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | // Unplug device "audio-in1" and "audio-out1". |
| 376 | std::vector<std::string> in_device_list, out_device_list; |
| 377 | in_device_list.push_back("audio-in2"); |
| 378 | out_device_list.push_back("audio-out2"); |
| 379 | fdm_->SetAudioInputDevices(in_device_list); |
| 380 | fdm_->SetAudioOutputDevices(out_device_list); |
| 381 | // Init should fall back to default devices. |
| 382 | EXPECT_TRUE(cm_->Init()); |
| 383 | // The media engine should use the default. |
| 384 | EXPECT_EQ("", fme_->audio_in_device()); |
| 385 | EXPECT_EQ("", fme_->audio_out_device()); |
| 386 | // The channel manager keeps the preferences "audio-in1" and "audio-out1". |
| 387 | std::string audio_in, audio_out; |
| 388 | EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL)); |
| 389 | EXPECT_EQ("audio-in1", audio_in); |
| 390 | EXPECT_EQ("audio-out1", audio_out); |
| 391 | cm_->Terminate(); |
| 392 | |
| 393 | // Plug devices "audio-in2" and "audio-out2" back. |
| 394 | in_device_list.push_back("audio-in1"); |
| 395 | out_device_list.push_back("audio-out1"); |
| 396 | fdm_->SetAudioInputDevices(in_device_list); |
| 397 | fdm_->SetAudioOutputDevices(out_device_list); |
| 398 | // Init again. The preferences, "audio-in2" and "audio-out2", are used. |
| 399 | EXPECT_TRUE(cm_->Init()); |
| 400 | EXPECT_EQ("audio-in1", fme_->audio_in_device()); |
| 401 | EXPECT_EQ("audio-out1", fme_->audio_out_device()); |
| 402 | EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL)); |
| 403 | EXPECT_EQ("audio-in1", audio_in); |
| 404 | EXPECT_EQ("audio-out1", audio_out); |
| 405 | } |
| 406 | |
| 407 | // We have one camera. Unplug it, fall back to no camera. |
| 408 | TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) { |
| 409 | // Set preferences "video-in1" before init. |
| 410 | std::vector<std::string> vid_device_list; |
| 411 | vid_device_list.push_back("video-in1"); |
| 412 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 413 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in1")); |
| 414 | |
| 415 | // Unplug "video-in1". |
| 416 | vid_device_list.clear(); |
| 417 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 418 | |
| 419 | // Init should fall back to avatar. |
| 420 | EXPECT_TRUE(cm_->Init()); |
| 421 | // The media engine should use no camera. |
| 422 | EXPECT_EQ("", cm_->video_device_name()); |
| 423 | // The channel manager keeps the user preference "video-in". |
| 424 | std::string video_in; |
| 425 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 426 | EXPECT_EQ("video-in1", video_in); |
| 427 | cm_->Terminate(); |
| 428 | |
| 429 | // Plug device "video-in1" back. |
| 430 | vid_device_list.push_back("video-in1"); |
| 431 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 432 | // Init again. The user preferred device, "video-in1", is used. |
| 433 | EXPECT_TRUE(cm_->Init()); |
| 434 | EXPECT_EQ("video-in1", cm_->video_device_name()); |
| 435 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 436 | EXPECT_EQ("video-in1", video_in); |
| 437 | } |
| 438 | |
| 439 | // We have multiple cameras. Unplug the preferred, fall back to another camera. |
| 440 | TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) { |
| 441 | // Set video device to "video-in1" before init. |
| 442 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in1")); |
| 443 | // Unplug device "video-in1". |
| 444 | std::vector<std::string> vid_device_list; |
| 445 | vid_device_list.push_back("video-in2"); |
| 446 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 447 | // Init should fall back to default device "video-in2". |
| 448 | EXPECT_TRUE(cm_->Init()); |
| 449 | // The media engine should use the default device "video-in2". |
| 450 | EXPECT_EQ("video-in2", cm_->video_device_name()); |
| 451 | // The channel manager keeps the user preference "video-in". |
| 452 | std::string video_in; |
| 453 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 454 | EXPECT_EQ("video-in1", video_in); |
| 455 | cm_->Terminate(); |
| 456 | |
| 457 | // Plug device "video-in1" back. |
| 458 | vid_device_list.push_back("video-in1"); |
| 459 | fdm_->SetVideoCaptureDevices(vid_device_list); |
| 460 | // Init again. The user preferred device, "video-in1", is used. |
| 461 | EXPECT_TRUE(cm_->Init()); |
| 462 | EXPECT_EQ("video-in1", cm_->video_device_name()); |
| 463 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 464 | EXPECT_EQ("video-in1", video_in); |
| 465 | } |
| 466 | |
| 467 | TEST_F(ChannelManagerTest, GetCaptureDevice) { |
| 468 | std::string video_in; |
| 469 | // Test setting/getting defaults. |
| 470 | EXPECT_TRUE(cm_->Init()); |
| 471 | EXPECT_TRUE(cm_->SetCaptureDevice("")); |
| 472 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 473 | EXPECT_EQ("video-in1", video_in); |
| 474 | // Test setting/getting specific values. |
| 475 | EXPECT_TRUE(cm_->SetCaptureDevice("video-in2")); |
| 476 | EXPECT_TRUE(cm_->GetCaptureDevice(&video_in)); |
| 477 | EXPECT_EQ("video-in2", video_in); |
| 478 | } |
| 479 | |
| 480 | TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) { |
| 481 | int level; |
| 482 | // Before init, SetOutputVolume() remembers the volume but does not change the |
| 483 | // volume of the engine. GetOutputVolume() should fail. |
| 484 | EXPECT_EQ(-1, fme_->output_volume()); |
| 485 | EXPECT_FALSE(cm_->GetOutputVolume(&level)); |
| 486 | EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume. |
| 487 | EXPECT_TRUE(cm_->SetOutputVolume(99)); |
| 488 | EXPECT_EQ(-1, fme_->output_volume()); |
| 489 | |
| 490 | // Init() will apply the remembered volume. |
| 491 | EXPECT_TRUE(cm_->Init()); |
| 492 | EXPECT_TRUE(cm_->GetOutputVolume(&level)); |
| 493 | EXPECT_EQ(99, level); |
| 494 | EXPECT_EQ(level, fme_->output_volume()); |
| 495 | |
| 496 | EXPECT_TRUE(cm_->SetOutputVolume(60)); |
| 497 | EXPECT_TRUE(cm_->GetOutputVolume(&level)); |
| 498 | EXPECT_EQ(60, level); |
| 499 | EXPECT_EQ(level, fme_->output_volume()); |
| 500 | } |
| 501 | |
| 502 | TEST_F(ChannelManagerTest, GetSetOutputVolume) { |
| 503 | int level; |
| 504 | EXPECT_TRUE(cm_->Init()); |
| 505 | EXPECT_TRUE(cm_->GetOutputVolume(&level)); |
| 506 | EXPECT_EQ(level, fme_->output_volume()); |
| 507 | |
| 508 | EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume. |
| 509 | EXPECT_TRUE(cm_->SetOutputVolume(60)); |
| 510 | EXPECT_EQ(60, fme_->output_volume()); |
| 511 | EXPECT_TRUE(cm_->GetOutputVolume(&level)); |
| 512 | EXPECT_EQ(60, level); |
| 513 | } |
| 514 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | // Test that logging options set before Init are applied properly, |
| 516 | // and retained even after Init. |
| 517 | TEST_F(ChannelManagerTest, SetLoggingBeforeInit) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 518 | cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice"); |
| 519 | cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video"); |
| 520 | EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 522 | EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 523 | EXPECT_STREQ("test-video", fme_->video_logfilter().c_str()); |
| 524 | EXPECT_TRUE(cm_->Init()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 525 | EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 526 | EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 527 | EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 528 | EXPECT_STREQ("test-video", fme_->video_logfilter().c_str()); |
| 529 | } |
| 530 | |
| 531 | // Test that logging options set after Init are applied properly. |
| 532 | TEST_F(ChannelManagerTest, SetLogging) { |
| 533 | EXPECT_TRUE(cm_->Init()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 534 | cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice"); |
| 535 | cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video"); |
| 536 | EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 537 | EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 538 | EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | EXPECT_STREQ("test-video", fme_->video_logfilter().c_str()); |
| 540 | } |
| 541 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 542 | TEST_F(ChannelManagerTest, SetVideoRtxEnabled) { |
| 543 | std::vector<VideoCodec> codecs; |
| 544 | const VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0); |
| 545 | |
| 546 | // By default RTX is disabled. |
| 547 | cm_->GetSupportedVideoCodecs(&codecs); |
| 548 | EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 549 | |
| 550 | // Enable and check. |
| 551 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
| 552 | cm_->GetSupportedVideoCodecs(&codecs); |
| 553 | EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 554 | |
| 555 | // Disable and check. |
| 556 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(false)); |
| 557 | cm_->GetSupportedVideoCodecs(&codecs); |
| 558 | EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 559 | |
| 560 | // Cannot toggle rtx after initialization. |
| 561 | EXPECT_TRUE(cm_->Init()); |
| 562 | EXPECT_FALSE(cm_->SetVideoRtxEnabled(true)); |
| 563 | EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
| 564 | |
| 565 | // Can set again after terminate. |
| 566 | cm_->Terminate(); |
| 567 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
| 568 | cm_->GetSupportedVideoCodecs(&codecs); |
| 569 | EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 570 | } |
| 571 | |
| 572 | } // namespace cricket |