blob: f496ee93103593db9258ee93981b28a55113deb7 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
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.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakecapturemanager.h"
29#include "talk/media/base/fakemediaengine.h"
30#include "talk/media/base/fakemediaprocessor.h"
31#include "talk/media/base/nullvideorenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include "talk/media/base/testutils.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000033#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000034#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/session/media/channelmanager.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "webrtc/base/gunit.h"
37#include "webrtc/base/logging.h"
38#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039
40namespace cricket {
41
42static const AudioCodec kAudioCodecs[] = {
43 AudioCodec(97, "voice", 1, 2, 3, 0),
44 AudioCodec(110, "CELT", 32000, 48000, 2, 0),
45 AudioCodec(111, "OPUS", 48000, 32000, 2, 0),
46};
47
48static const VideoCodec kVideoCodecs[] = {
49 VideoCodec(99, "H264", 100, 200, 300, 0),
50 VideoCodec(100, "VP8", 100, 200, 300, 0),
51 VideoCodec(96, "rtx", 100, 200, 300, 0),
52};
53
54class ChannelManagerTest : public testing::Test {
55 protected:
56 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {
57 }
58
59 virtual void SetUp() {
60 fme_ = new cricket::FakeMediaEngine();
61 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
62 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
63 fdme_ = new cricket::FakeDataEngine();
64 fdm_ = new cricket::FakeDeviceManager();
65 fcm_ = new cricket::FakeCaptureManager();
66 cm_ = new cricket::ChannelManager(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000067 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 session_ = new cricket::FakeSession(true);
69
70 std::vector<std::string> in_device_list, out_device_list, vid_device_list;
71 in_device_list.push_back("audio-in1");
72 in_device_list.push_back("audio-in2");
73 out_device_list.push_back("audio-out1");
74 out_device_list.push_back("audio-out2");
75 vid_device_list.push_back("video-in1");
76 vid_device_list.push_back("video-in2");
77 fdm_->SetAudioInputDevices(in_device_list);
78 fdm_->SetAudioOutputDevices(out_device_list);
79 fdm_->SetVideoCaptureDevices(vid_device_list);
80 }
81
82 virtual void TearDown() {
83 delete session_;
84 delete cm_;
85 cm_ = NULL;
86 fdm_ = NULL;
87 fcm_ = NULL;
88 fdme_ = NULL;
89 fme_ = NULL;
90 }
91
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000092 rtc::Thread worker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093 cricket::FakeMediaEngine* fme_;
94 cricket::FakeDataEngine* fdme_;
95 cricket::FakeDeviceManager* fdm_;
96 cricket::FakeCaptureManager* fcm_;
97 cricket::ChannelManager* cm_;
98 cricket::FakeSession* session_;
99};
100
101// Test that we startup/shutdown properly.
102TEST_F(ChannelManagerTest, StartupShutdown) {
103 EXPECT_FALSE(cm_->initialized());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000104 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 EXPECT_TRUE(cm_->Init());
106 EXPECT_TRUE(cm_->initialized());
107 cm_->Terminate();
108 EXPECT_FALSE(cm_->initialized());
109}
110
111// Test that we startup/shutdown properly with a worker thread.
112TEST_F(ChannelManagerTest, StartupShutdownOnThread) {
113 worker_.Start();
114 EXPECT_FALSE(cm_->initialized());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000115 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
117 EXPECT_EQ(&worker_, cm_->worker_thread());
118 EXPECT_TRUE(cm_->Init());
119 EXPECT_TRUE(cm_->initialized());
120 // Setting the worker thread while initialized should fail.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000121 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 cm_->Terminate();
123 EXPECT_FALSE(cm_->initialized());
124}
125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// Test that we can create and destroy a voice and video channel.
127TEST_F(ChannelManagerTest, CreateDestroyChannels) {
128 EXPECT_TRUE(cm_->Init());
129 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
130 session_, cricket::CN_AUDIO, false);
131 EXPECT_TRUE(voice_channel != NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000132 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
133 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 EXPECT_TRUE(video_channel != NULL);
135 cricket::DataChannel* data_channel =
136 cm_->CreateDataChannel(session_, cricket::CN_DATA,
137 false, cricket::DCT_RTP);
138 EXPECT_TRUE(data_channel != NULL);
139 cm_->DestroyVideoChannel(video_channel);
140 cm_->DestroyVoiceChannel(voice_channel);
141 cm_->DestroyDataChannel(data_channel);
142 cm_->Terminate();
143}
144
145// Test that we can create and destroy a voice and video channel with a worker.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000146TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 worker_.Start();
148 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
149 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000150 delete session_;
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000151 session_ = new cricket::FakeSession(&worker_, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
153 session_, cricket::CN_AUDIO, false);
154 EXPECT_TRUE(voice_channel != NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000155 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
156 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 EXPECT_TRUE(video_channel != NULL);
158 cricket::DataChannel* data_channel =
159 cm_->CreateDataChannel(session_, cricket::CN_DATA,
160 false, cricket::DCT_RTP);
161 EXPECT_TRUE(data_channel != NULL);
162 cm_->DestroyVideoChannel(video_channel);
163 cm_->DestroyVoiceChannel(voice_channel);
164 cm_->DestroyDataChannel(data_channel);
165 cm_->Terminate();
166}
167
168// Test that we fail to create a voice/video channel if the session is unable
169// to create a cricket::TransportChannel
170TEST_F(ChannelManagerTest, NoTransportChannelTest) {
171 EXPECT_TRUE(cm_->Init());
172 session_->set_fail_channel_creation(true);
173 // The test is useless unless the session does not fail creating
174 // cricket::TransportChannel.
175 ASSERT_TRUE(session_->CreateChannel(
176 "audio", "rtp", cricket::ICE_CANDIDATE_COMPONENT_RTP) == NULL);
177
178 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
179 session_, cricket::CN_AUDIO, false);
180 EXPECT_TRUE(voice_channel == NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000181 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
182 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 EXPECT_TRUE(video_channel == NULL);
184 cricket::DataChannel* data_channel =
185 cm_->CreateDataChannel(session_, cricket::CN_DATA,
186 false, cricket::DCT_RTP);
187 EXPECT_TRUE(data_channel == NULL);
188 cm_->Terminate();
189}
190
191// Test that SetDefaultVideoCodec passes through the right values.
192TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
193 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
194 cricket::VideoEncoderConfig config(codec, 1, 2);
195 EXPECT_TRUE(cm_->Init());
196 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
197 EXPECT_EQ(config, fme_->default_video_encoder_config());
198}
199
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000200struct GetCapturerFrameSize : public sigslot::has_slots<> {
201 void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* frame) {
202 width = frame->GetWidth();
203 height = frame->GetHeight();
204 }
205 GetCapturerFrameSize(VideoCapturer* capturer) : width(0), height(0) {
206 capturer->SignalVideoFrame.connect(this,
207 &GetCapturerFrameSize::OnVideoFrame);
208 static_cast<FakeVideoCapturer*>(capturer)->CaptureFrame();
209 }
210 size_t width;
211 size_t height;
212};
213
214TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) {
215 VideoCodec codec(100, "VP8", 640, 360, 30, 0);
216 VideoFormat format(640, 360, 33, FOURCC_ANY);
217 VideoEncoderConfig config(codec, 1, 2);
218 EXPECT_TRUE(cm_->Init());
219 // A capturer created before the default encoder config is set will have no
magjed@webrtc.org35c1ace2014-11-13 16:21:49 +0000220 // set aspect ratio, so it'll be 4:3 (based on the fake video capture impl).
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000221 VideoCapturer* capturer = cm_->CreateVideoCapturer();
222 ASSERT_TRUE(capturer != NULL);
223 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
224 GetCapturerFrameSize size(capturer);
225 EXPECT_EQ(640u, size.width);
magjed@webrtc.org35c1ace2014-11-13 16:21:49 +0000226 EXPECT_EQ(480u, size.height);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000227 delete capturer;
228 // Try again, but with the encoder config set to 16:9.
229 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
230 capturer = cm_->CreateVideoCapturer();
231 ASSERT_TRUE(capturer != NULL);
232 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
233 GetCapturerFrameSize cropped_size(capturer);
234 EXPECT_EQ(640u, cropped_size.width);
235 EXPECT_EQ(360u, cropped_size.height);
236 delete capturer;
237}
238
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239// Test that SetDefaultVideoCodec passes through the right values.
240TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
241 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
242 cricket::VideoEncoderConfig config(codec, 1, 2);
243 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
244 EXPECT_TRUE(cm_->Init());
245 EXPECT_EQ(config, fme_->default_video_encoder_config());
246}
247
248TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) {
249 // Test that values that we set before Init are applied.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000250 AudioOptions options;
251 options.auto_gain_control.Set(true);
252 options.echo_cancellation.Set(false);
253 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
254 std::string audio_in, audio_out;
255 AudioOptions set_options;
256 // Check options before Init.
257 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
258 EXPECT_EQ("audio-in1", audio_in);
259 EXPECT_EQ("audio-out1", audio_out);
260 EXPECT_EQ(options, set_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000262 // Check options after Init.
263 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
264 EXPECT_EQ("audio-in1", audio_in);
265 EXPECT_EQ("audio-out1", audio_out);
266 EXPECT_EQ(options, set_options);
267 // At this point, the media engine should also be initialized.
268 EXPECT_EQ(options, fme_->audio_options());
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000269 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 fme_->audio_delay_offset());
271}
272
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) {
274 std::string audio_in, audio_out;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000275 AudioOptions options;
276 options.echo_cancellation.Set(true);
277 EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL));
279 EXPECT_EQ("audio-in2", audio_in);
280 EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL));
281 EXPECT_EQ("audio-out2", audio_out);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000282 AudioOptions out_options;
283 EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options));
284 bool echo_cancellation = false;
285 EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation));
286 EXPECT_TRUE(echo_cancellation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287}
288
289TEST_F(ChannelManagerTest, SetAudioOptions) {
290 // Test initial state.
291 EXPECT_TRUE(cm_->Init());
292 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
293 fme_->audio_in_device());
294 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
295 fme_->audio_out_device());
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000296 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 fme_->audio_delay_offset());
298 // Test setting specific values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000299 AudioOptions options;
300 options.auto_gain_control.Set(true);
301 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 EXPECT_EQ("audio-in1", fme_->audio_in_device());
303 EXPECT_EQ("audio-out1", fme_->audio_out_device());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000304 bool auto_gain_control = false;
305 EXPECT_TRUE(
306 fme_->audio_options().auto_gain_control.Get(&auto_gain_control));
307 EXPECT_TRUE(auto_gain_control);
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000308 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 fme_->audio_delay_offset());
310 // Test setting bad values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000311 EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312}
313
buildbot@webrtc.org88d9fa62014-06-16 14:11:32 +0000314TEST_F(ChannelManagerTest, SetEngineAudioOptions) {
315 EXPECT_TRUE(cm_->Init());
316 // Test setting specific values.
317 AudioOptions options;
318 options.experimental_ns.Set(true);
319 EXPECT_TRUE(cm_->SetEngineAudioOptions(options));
320 bool experimental_ns = false;
321 EXPECT_TRUE(fme_->audio_options().experimental_ns.Get(&experimental_ns));
322 EXPECT_TRUE(experimental_ns);
323}
324
325TEST_F(ChannelManagerTest, SetEngineAudioOptionsBeforeInitFails) {
326 // Test that values that we set before Init are not applied.
327 AudioOptions options;
328 options.experimental_ns.Set(true);
329 EXPECT_FALSE(cm_->SetEngineAudioOptions(options));
330 EXPECT_FALSE(fme_->audio_options().experimental_ns.IsSet());
331}
332
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) {
334 // Test that values that we set before Init are applied.
335 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
336 EXPECT_TRUE(cm_->Init());
337 EXPECT_EQ("video-in2", cm_->video_device_name());
338}
339
340TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) {
341 std::string video_in;
342 // Test that GetCaptureDevice works before Init.
343 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
344 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
345 EXPECT_EQ("video-in1", video_in);
346 // Test that options set before Init can be gotten after Init.
347 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
348 EXPECT_TRUE(cm_->Init());
349 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
350 EXPECT_EQ("video-in2", video_in);
351}
352
353TEST_F(ChannelManagerTest, SetCaptureDevice) {
354 // Test setting defaults.
355 EXPECT_TRUE(cm_->Init());
356 EXPECT_TRUE(cm_->SetCaptureDevice("")); // will use DeviceManager default
357 EXPECT_EQ("video-in1", cm_->video_device_name());
358 // Test setting specific values.
359 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
360 EXPECT_EQ("video-in2", cm_->video_device_name());
361 // TODO(juberti): Add test for invalid value here.
362}
363
364// Test unplugging and plugging back the preferred devices. When the preferred
365// device is unplugged, we fall back to the default device. When the preferred
366// device is plugged back, we use it.
367TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) {
368 // Set preferences "audio-in1" and "audio-out1" before init.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000369 AudioOptions options;
370 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 // Unplug device "audio-in1" and "audio-out1".
372 std::vector<std::string> in_device_list, out_device_list;
373 in_device_list.push_back("audio-in2");
374 out_device_list.push_back("audio-out2");
375 fdm_->SetAudioInputDevices(in_device_list);
376 fdm_->SetAudioOutputDevices(out_device_list);
377 // Init should fall back to default devices.
378 EXPECT_TRUE(cm_->Init());
379 // The media engine should use the default.
380 EXPECT_EQ("", fme_->audio_in_device());
381 EXPECT_EQ("", fme_->audio_out_device());
382 // The channel manager keeps the preferences "audio-in1" and "audio-out1".
383 std::string audio_in, audio_out;
384 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
385 EXPECT_EQ("audio-in1", audio_in);
386 EXPECT_EQ("audio-out1", audio_out);
387 cm_->Terminate();
388
389 // Plug devices "audio-in2" and "audio-out2" back.
390 in_device_list.push_back("audio-in1");
391 out_device_list.push_back("audio-out1");
392 fdm_->SetAudioInputDevices(in_device_list);
393 fdm_->SetAudioOutputDevices(out_device_list);
394 // Init again. The preferences, "audio-in2" and "audio-out2", are used.
395 EXPECT_TRUE(cm_->Init());
396 EXPECT_EQ("audio-in1", fme_->audio_in_device());
397 EXPECT_EQ("audio-out1", fme_->audio_out_device());
398 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
399 EXPECT_EQ("audio-in1", audio_in);
400 EXPECT_EQ("audio-out1", audio_out);
401}
402
403// We have one camera. Unplug it, fall back to no camera.
404TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) {
405 // Set preferences "video-in1" before init.
406 std::vector<std::string> vid_device_list;
407 vid_device_list.push_back("video-in1");
408 fdm_->SetVideoCaptureDevices(vid_device_list);
409 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
410
411 // Unplug "video-in1".
412 vid_device_list.clear();
413 fdm_->SetVideoCaptureDevices(vid_device_list);
414
415 // Init should fall back to avatar.
416 EXPECT_TRUE(cm_->Init());
417 // The media engine should use no camera.
418 EXPECT_EQ("", cm_->video_device_name());
419 // The channel manager keeps the user preference "video-in".
420 std::string video_in;
421 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
422 EXPECT_EQ("video-in1", video_in);
423 cm_->Terminate();
424
425 // Plug device "video-in1" back.
426 vid_device_list.push_back("video-in1");
427 fdm_->SetVideoCaptureDevices(vid_device_list);
428 // Init again. The user preferred device, "video-in1", is used.
429 EXPECT_TRUE(cm_->Init());
430 EXPECT_EQ("video-in1", cm_->video_device_name());
431 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
432 EXPECT_EQ("video-in1", video_in);
433}
434
435// We have multiple cameras. Unplug the preferred, fall back to another camera.
436TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) {
437 // Set video device to "video-in1" before init.
438 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
439 // Unplug device "video-in1".
440 std::vector<std::string> vid_device_list;
441 vid_device_list.push_back("video-in2");
442 fdm_->SetVideoCaptureDevices(vid_device_list);
443 // Init should fall back to default device "video-in2".
444 EXPECT_TRUE(cm_->Init());
445 // The media engine should use the default device "video-in2".
446 EXPECT_EQ("video-in2", cm_->video_device_name());
447 // The channel manager keeps the user preference "video-in".
448 std::string video_in;
449 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
450 EXPECT_EQ("video-in1", video_in);
451 cm_->Terminate();
452
453 // Plug device "video-in1" back.
454 vid_device_list.push_back("video-in1");
455 fdm_->SetVideoCaptureDevices(vid_device_list);
456 // Init again. The user preferred device, "video-in1", is used.
457 EXPECT_TRUE(cm_->Init());
458 EXPECT_EQ("video-in1", cm_->video_device_name());
459 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
460 EXPECT_EQ("video-in1", video_in);
461}
462
463TEST_F(ChannelManagerTest, GetCaptureDevice) {
464 std::string video_in;
465 // Test setting/getting defaults.
466 EXPECT_TRUE(cm_->Init());
467 EXPECT_TRUE(cm_->SetCaptureDevice(""));
468 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
469 EXPECT_EQ("video-in1", video_in);
470 // Test setting/getting specific values.
471 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
472 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
473 EXPECT_EQ("video-in2", video_in);
474}
475
476TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) {
477 int level;
478 // Before init, SetOutputVolume() remembers the volume but does not change the
479 // volume of the engine. GetOutputVolume() should fail.
480 EXPECT_EQ(-1, fme_->output_volume());
481 EXPECT_FALSE(cm_->GetOutputVolume(&level));
482 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
483 EXPECT_TRUE(cm_->SetOutputVolume(99));
484 EXPECT_EQ(-1, fme_->output_volume());
485
486 // Init() will apply the remembered volume.
487 EXPECT_TRUE(cm_->Init());
488 EXPECT_TRUE(cm_->GetOutputVolume(&level));
489 EXPECT_EQ(99, level);
490 EXPECT_EQ(level, fme_->output_volume());
491
492 EXPECT_TRUE(cm_->SetOutputVolume(60));
493 EXPECT_TRUE(cm_->GetOutputVolume(&level));
494 EXPECT_EQ(60, level);
495 EXPECT_EQ(level, fme_->output_volume());
496}
497
498TEST_F(ChannelManagerTest, GetSetOutputVolume) {
499 int level;
500 EXPECT_TRUE(cm_->Init());
501 EXPECT_TRUE(cm_->GetOutputVolume(&level));
502 EXPECT_EQ(level, fme_->output_volume());
503
504 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
505 EXPECT_TRUE(cm_->SetOutputVolume(60));
506 EXPECT_EQ(60, fme_->output_volume());
507 EXPECT_TRUE(cm_->GetOutputVolume(&level));
508 EXPECT_EQ(60, level);
509}
510
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511// Test that logging options set before Init are applied properly,
512// and retained even after Init.
513TEST_F(ChannelManagerTest, SetLoggingBeforeInit) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000514 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
515 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
516 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000518 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
520 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000521 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000523 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
525}
526
527// Test that logging options set after Init are applied properly.
528TEST_F(ChannelManagerTest, SetLogging) {
529 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000530 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
531 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
532 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000534 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
536}
537
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538// Test that the Video/Voice Processors register and unregister
539TEST_F(ChannelManagerTest, RegisterProcessors) {
540 cricket::FakeMediaProcessor fmp;
541 EXPECT_TRUE(cm_->Init());
542 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
543 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
544
545 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
546 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
547
548 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
549 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
550
551 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
552 &fmp,
553 cricket::MPD_RX));
554 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
555 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_RX));
556
557
558 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
559 &fmp,
560 cricket::MPD_RX));
561 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
562 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
563
564 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
565 &fmp,
566 cricket::MPD_TX));
567 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_TX));
568 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
569
570 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
571 &fmp,
572 cricket::MPD_TX));
573 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
574 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
575}
576
577TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
578 std::vector<VideoCodec> codecs;
579 const VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
580
581 // By default RTX is disabled.
582 cm_->GetSupportedVideoCodecs(&codecs);
583 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
584
585 // Enable and check.
586 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
587 cm_->GetSupportedVideoCodecs(&codecs);
588 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
589
590 // Disable and check.
591 EXPECT_TRUE(cm_->SetVideoRtxEnabled(false));
592 cm_->GetSupportedVideoCodecs(&codecs);
593 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
594
595 // Cannot toggle rtx after initialization.
596 EXPECT_TRUE(cm_->Init());
597 EXPECT_FALSE(cm_->SetVideoRtxEnabled(true));
598 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
599
600 // Can set again after terminate.
601 cm_->Terminate();
602 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
603 cm_->GetSupportedVideoCodecs(&codecs);
604 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
605}
606
607} // namespace cricket