blob: 4c6f4ab0370deff35983e07cb5545155e45fdbe8 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// libjingle
2// Copyright 2008 Google Inc.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// 3. The name of the author may not be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026#include "talk/media/base/fakecapturemanager.h"
27#include "talk/media/base/fakemediaengine.h"
28#include "talk/media/base/fakemediaprocessor.h"
29#include "talk/media/base/nullvideorenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/media/base/testutils.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000031#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000032#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/session/media/channelmanager.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "webrtc/base/gunit.h"
35#include "webrtc/base/logging.h"
36#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037
38namespace cricket {
39
40static const AudioCodec kAudioCodecs[] = {
41 AudioCodec(97, "voice", 1, 2, 3, 0),
42 AudioCodec(110, "CELT", 32000, 48000, 2, 0),
43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0),
44};
45
46static const VideoCodec kVideoCodecs[] = {
47 VideoCodec(99, "H264", 100, 200, 300, 0),
48 VideoCodec(100, "VP8", 100, 200, 300, 0),
49 VideoCodec(96, "rtx", 100, 200, 300, 0),
50};
51
52class ChannelManagerTest : public testing::Test {
53 protected:
54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {
55 }
56
57 virtual void SetUp() {
58 fme_ = new cricket::FakeMediaEngine();
59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
61 fdme_ = new cricket::FakeDataEngine();
62 fdm_ = new cricket::FakeDeviceManager();
63 fcm_ = new cricket::FakeCaptureManager();
64 cm_ = new cricket::ChannelManager(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000065 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 session_ = new cricket::FakeSession(true);
67
68 std::vector<std::string> in_device_list, out_device_list, vid_device_list;
69 in_device_list.push_back("audio-in1");
70 in_device_list.push_back("audio-in2");
71 out_device_list.push_back("audio-out1");
72 out_device_list.push_back("audio-out2");
73 vid_device_list.push_back("video-in1");
74 vid_device_list.push_back("video-in2");
75 fdm_->SetAudioInputDevices(in_device_list);
76 fdm_->SetAudioOutputDevices(out_device_list);
77 fdm_->SetVideoCaptureDevices(vid_device_list);
78 }
79
80 virtual void TearDown() {
81 delete session_;
82 delete cm_;
83 cm_ = NULL;
84 fdm_ = NULL;
85 fcm_ = NULL;
86 fdme_ = NULL;
87 fme_ = NULL;
88 }
89
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000090 rtc::Thread worker_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 cricket::FakeMediaEngine* fme_;
92 cricket::FakeDataEngine* fdme_;
93 cricket::FakeDeviceManager* fdm_;
94 cricket::FakeCaptureManager* fcm_;
95 cricket::ChannelManager* cm_;
96 cricket::FakeSession* session_;
97};
98
99// Test that we startup/shutdown properly.
100TEST_F(ChannelManagerTest, StartupShutdown) {
101 EXPECT_FALSE(cm_->initialized());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 EXPECT_TRUE(cm_->Init());
104 EXPECT_TRUE(cm_->initialized());
105 cm_->Terminate();
106 EXPECT_FALSE(cm_->initialized());
107}
108
109// Test that we startup/shutdown properly with a worker thread.
110TEST_F(ChannelManagerTest, StartupShutdownOnThread) {
111 worker_.Start();
112 EXPECT_FALSE(cm_->initialized());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000113 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
115 EXPECT_EQ(&worker_, cm_->worker_thread());
116 EXPECT_TRUE(cm_->Init());
117 EXPECT_TRUE(cm_->initialized());
118 // Setting the worker thread while initialized should fail.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 cm_->Terminate();
121 EXPECT_FALSE(cm_->initialized());
122}
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Test that we can create and destroy a voice and video channel.
125TEST_F(ChannelManagerTest, CreateDestroyChannels) {
126 EXPECT_TRUE(cm_->Init());
127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
128 session_, cricket::CN_AUDIO, false);
129 EXPECT_TRUE(voice_channel != NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
131 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 EXPECT_TRUE(video_channel != NULL);
133 cricket::DataChannel* data_channel =
134 cm_->CreateDataChannel(session_, cricket::CN_DATA,
135 false, cricket::DCT_RTP);
136 EXPECT_TRUE(data_channel != NULL);
137 cm_->DestroyVideoChannel(video_channel);
138 cm_->DestroyVoiceChannel(voice_channel);
139 cm_->DestroyDataChannel(data_channel);
140 cm_->Terminate();
141}
142
143// Test that we can create and destroy a voice and video channel with a worker.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000144TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 worker_.Start();
146 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
147 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000148 delete session_;
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000149 session_ = new cricket::FakeSession(&worker_, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
151 session_, cricket::CN_AUDIO, false);
152 EXPECT_TRUE(voice_channel != NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000153 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
154 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 EXPECT_TRUE(video_channel != NULL);
156 cricket::DataChannel* data_channel =
157 cm_->CreateDataChannel(session_, cricket::CN_DATA,
158 false, cricket::DCT_RTP);
159 EXPECT_TRUE(data_channel != NULL);
160 cm_->DestroyVideoChannel(video_channel);
161 cm_->DestroyVoiceChannel(voice_channel);
162 cm_->DestroyDataChannel(data_channel);
163 cm_->Terminate();
164}
165
166// Test that we fail to create a voice/video channel if the session is unable
167// to create a cricket::TransportChannel
168TEST_F(ChannelManagerTest, NoTransportChannelTest) {
169 EXPECT_TRUE(cm_->Init());
170 session_->set_fail_channel_creation(true);
171 // The test is useless unless the session does not fail creating
172 // cricket::TransportChannel.
173 ASSERT_TRUE(session_->CreateChannel(
174 "audio", "rtp", cricket::ICE_CANDIDATE_COMPONENT_RTP) == NULL);
175
176 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
177 session_, cricket::CN_AUDIO, false);
178 EXPECT_TRUE(voice_channel == NULL);
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000179 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
180 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 EXPECT_TRUE(video_channel == NULL);
182 cricket::DataChannel* data_channel =
183 cm_->CreateDataChannel(session_, cricket::CN_DATA,
184 false, cricket::DCT_RTP);
185 EXPECT_TRUE(data_channel == NULL);
186 cm_->Terminate();
187}
188
189// Test that SetDefaultVideoCodec passes through the right values.
190TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
191 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
192 cricket::VideoEncoderConfig config(codec, 1, 2);
193 EXPECT_TRUE(cm_->Init());
194 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
195 EXPECT_EQ(config, fme_->default_video_encoder_config());
196}
197
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000198struct GetCapturerFrameSize : public sigslot::has_slots<> {
199 void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* frame) {
200 width = frame->GetWidth();
201 height = frame->GetHeight();
202 }
203 GetCapturerFrameSize(VideoCapturer* capturer) : width(0), height(0) {
204 capturer->SignalVideoFrame.connect(this,
205 &GetCapturerFrameSize::OnVideoFrame);
206 static_cast<FakeVideoCapturer*>(capturer)->CaptureFrame();
207 }
208 size_t width;
209 size_t height;
210};
211
212TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) {
213 VideoCodec codec(100, "VP8", 640, 360, 30, 0);
214 VideoFormat format(640, 360, 33, FOURCC_ANY);
215 VideoEncoderConfig config(codec, 1, 2);
216 EXPECT_TRUE(cm_->Init());
217 // A capturer created before the default encoder config is set will have no
magjed@webrtc.org35c1ace2014-11-13 16:21:49 +0000218 // set aspect ratio, so it'll be 4:3 (based on the fake video capture impl).
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000219 VideoCapturer* capturer = cm_->CreateVideoCapturer();
220 ASSERT_TRUE(capturer != NULL);
221 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
222 GetCapturerFrameSize size(capturer);
223 EXPECT_EQ(640u, size.width);
magjed@webrtc.org35c1ace2014-11-13 16:21:49 +0000224 EXPECT_EQ(480u, size.height);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000225 delete capturer;
226 // Try again, but with the encoder config set to 16:9.
227 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
228 capturer = cm_->CreateVideoCapturer();
229 ASSERT_TRUE(capturer != NULL);
230 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
231 GetCapturerFrameSize cropped_size(capturer);
232 EXPECT_EQ(640u, cropped_size.width);
233 EXPECT_EQ(360u, cropped_size.height);
234 delete capturer;
235}
236
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237// Test that SetDefaultVideoCodec passes through the right values.
238TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
239 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
240 cricket::VideoEncoderConfig config(codec, 1, 2);
241 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
242 EXPECT_TRUE(cm_->Init());
243 EXPECT_EQ(config, fme_->default_video_encoder_config());
244}
245
246TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) {
247 // Test that values that we set before Init are applied.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000248 AudioOptions options;
249 options.auto_gain_control.Set(true);
250 options.echo_cancellation.Set(false);
251 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
252 std::string audio_in, audio_out;
253 AudioOptions set_options;
254 // Check options before Init.
255 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
256 EXPECT_EQ("audio-in1", audio_in);
257 EXPECT_EQ("audio-out1", audio_out);
258 EXPECT_EQ(options, set_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000260 // Check options after Init.
261 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
262 EXPECT_EQ("audio-in1", audio_in);
263 EXPECT_EQ("audio-out1", audio_out);
264 EXPECT_EQ(options, set_options);
265 // At this point, the media engine should also be initialized.
266 EXPECT_EQ(options, fme_->audio_options());
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000267 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 fme_->audio_delay_offset());
269}
270
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) {
272 std::string audio_in, audio_out;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000273 AudioOptions options;
274 options.echo_cancellation.Set(true);
275 EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL));
277 EXPECT_EQ("audio-in2", audio_in);
278 EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL));
279 EXPECT_EQ("audio-out2", audio_out);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000280 AudioOptions out_options;
281 EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options));
282 bool echo_cancellation = false;
283 EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation));
284 EXPECT_TRUE(echo_cancellation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285}
286
287TEST_F(ChannelManagerTest, SetAudioOptions) {
288 // Test initial state.
289 EXPECT_TRUE(cm_->Init());
290 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
291 fme_->audio_in_device());
292 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
293 fme_->audio_out_device());
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000294 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 fme_->audio_delay_offset());
296 // Test setting specific values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000297 AudioOptions options;
298 options.auto_gain_control.Set(true);
299 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 EXPECT_EQ("audio-in1", fme_->audio_in_device());
301 EXPECT_EQ("audio-out1", fme_->audio_out_device());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000302 bool auto_gain_control = false;
303 EXPECT_TRUE(
304 fme_->audio_options().auto_gain_control.Get(&auto_gain_control));
305 EXPECT_TRUE(auto_gain_control);
henrike@webrtc.org0481f152014-08-19 14:56:59 +0000306 EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 fme_->audio_delay_offset());
308 // Test setting bad values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000309 EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310}
311
buildbot@webrtc.org88d9fa62014-06-16 14:11:32 +0000312TEST_F(ChannelManagerTest, SetEngineAudioOptions) {
313 EXPECT_TRUE(cm_->Init());
314 // Test setting specific values.
315 AudioOptions options;
316 options.experimental_ns.Set(true);
317 EXPECT_TRUE(cm_->SetEngineAudioOptions(options));
318 bool experimental_ns = false;
319 EXPECT_TRUE(fme_->audio_options().experimental_ns.Get(&experimental_ns));
320 EXPECT_TRUE(experimental_ns);
321}
322
323TEST_F(ChannelManagerTest, SetEngineAudioOptionsBeforeInitFails) {
324 // Test that values that we set before Init are not applied.
325 AudioOptions options;
326 options.experimental_ns.Set(true);
327 EXPECT_FALSE(cm_->SetEngineAudioOptions(options));
328 EXPECT_FALSE(fme_->audio_options().experimental_ns.IsSet());
329}
330
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) {
332 // Test that values that we set before Init are applied.
333 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
334 EXPECT_TRUE(cm_->Init());
335 EXPECT_EQ("video-in2", cm_->video_device_name());
336}
337
338TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) {
339 std::string video_in;
340 // Test that GetCaptureDevice works before Init.
341 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
342 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
343 EXPECT_EQ("video-in1", video_in);
344 // Test that options set before Init can be gotten after Init.
345 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
346 EXPECT_TRUE(cm_->Init());
347 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
348 EXPECT_EQ("video-in2", video_in);
349}
350
351TEST_F(ChannelManagerTest, SetCaptureDevice) {
352 // Test setting defaults.
353 EXPECT_TRUE(cm_->Init());
354 EXPECT_TRUE(cm_->SetCaptureDevice("")); // will use DeviceManager default
355 EXPECT_EQ("video-in1", cm_->video_device_name());
356 // Test setting specific values.
357 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
358 EXPECT_EQ("video-in2", cm_->video_device_name());
359 // TODO(juberti): Add test for invalid value here.
360}
361
362// Test unplugging and plugging back the preferred devices. When the preferred
363// device is unplugged, we fall back to the default device. When the preferred
364// device is plugged back, we use it.
365TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) {
366 // Set preferences "audio-in1" and "audio-out1" before init.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000367 AudioOptions options;
368 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 // Unplug device "audio-in1" and "audio-out1".
370 std::vector<std::string> in_device_list, out_device_list;
371 in_device_list.push_back("audio-in2");
372 out_device_list.push_back("audio-out2");
373 fdm_->SetAudioInputDevices(in_device_list);
374 fdm_->SetAudioOutputDevices(out_device_list);
375 // Init should fall back to default devices.
376 EXPECT_TRUE(cm_->Init());
377 // The media engine should use the default.
378 EXPECT_EQ("", fme_->audio_in_device());
379 EXPECT_EQ("", fme_->audio_out_device());
380 // The channel manager keeps the preferences "audio-in1" and "audio-out1".
381 std::string audio_in, audio_out;
382 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
383 EXPECT_EQ("audio-in1", audio_in);
384 EXPECT_EQ("audio-out1", audio_out);
385 cm_->Terminate();
386
387 // Plug devices "audio-in2" and "audio-out2" back.
388 in_device_list.push_back("audio-in1");
389 out_device_list.push_back("audio-out1");
390 fdm_->SetAudioInputDevices(in_device_list);
391 fdm_->SetAudioOutputDevices(out_device_list);
392 // Init again. The preferences, "audio-in2" and "audio-out2", are used.
393 EXPECT_TRUE(cm_->Init());
394 EXPECT_EQ("audio-in1", fme_->audio_in_device());
395 EXPECT_EQ("audio-out1", fme_->audio_out_device());
396 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
397 EXPECT_EQ("audio-in1", audio_in);
398 EXPECT_EQ("audio-out1", audio_out);
399}
400
401// We have one camera. Unplug it, fall back to no camera.
402TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) {
403 // Set preferences "video-in1" before init.
404 std::vector<std::string> vid_device_list;
405 vid_device_list.push_back("video-in1");
406 fdm_->SetVideoCaptureDevices(vid_device_list);
407 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
408
409 // Unplug "video-in1".
410 vid_device_list.clear();
411 fdm_->SetVideoCaptureDevices(vid_device_list);
412
413 // Init should fall back to avatar.
414 EXPECT_TRUE(cm_->Init());
415 // The media engine should use no camera.
416 EXPECT_EQ("", cm_->video_device_name());
417 // The channel manager keeps the user preference "video-in".
418 std::string video_in;
419 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
420 EXPECT_EQ("video-in1", video_in);
421 cm_->Terminate();
422
423 // Plug device "video-in1" back.
424 vid_device_list.push_back("video-in1");
425 fdm_->SetVideoCaptureDevices(vid_device_list);
426 // Init again. The user preferred device, "video-in1", is used.
427 EXPECT_TRUE(cm_->Init());
428 EXPECT_EQ("video-in1", cm_->video_device_name());
429 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
430 EXPECT_EQ("video-in1", video_in);
431}
432
433// We have multiple cameras. Unplug the preferred, fall back to another camera.
434TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) {
435 // Set video device to "video-in1" before init.
436 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
437 // Unplug device "video-in1".
438 std::vector<std::string> vid_device_list;
439 vid_device_list.push_back("video-in2");
440 fdm_->SetVideoCaptureDevices(vid_device_list);
441 // Init should fall back to default device "video-in2".
442 EXPECT_TRUE(cm_->Init());
443 // The media engine should use the default device "video-in2".
444 EXPECT_EQ("video-in2", cm_->video_device_name());
445 // The channel manager keeps the user preference "video-in".
446 std::string video_in;
447 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
448 EXPECT_EQ("video-in1", video_in);
449 cm_->Terminate();
450
451 // Plug device "video-in1" back.
452 vid_device_list.push_back("video-in1");
453 fdm_->SetVideoCaptureDevices(vid_device_list);
454 // Init again. The user preferred device, "video-in1", is used.
455 EXPECT_TRUE(cm_->Init());
456 EXPECT_EQ("video-in1", cm_->video_device_name());
457 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
458 EXPECT_EQ("video-in1", video_in);
459}
460
461TEST_F(ChannelManagerTest, GetCaptureDevice) {
462 std::string video_in;
463 // Test setting/getting defaults.
464 EXPECT_TRUE(cm_->Init());
465 EXPECT_TRUE(cm_->SetCaptureDevice(""));
466 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
467 EXPECT_EQ("video-in1", video_in);
468 // Test setting/getting specific values.
469 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
470 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
471 EXPECT_EQ("video-in2", video_in);
472}
473
474TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) {
475 int level;
476 // Before init, SetOutputVolume() remembers the volume but does not change the
477 // volume of the engine. GetOutputVolume() should fail.
478 EXPECT_EQ(-1, fme_->output_volume());
479 EXPECT_FALSE(cm_->GetOutputVolume(&level));
480 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
481 EXPECT_TRUE(cm_->SetOutputVolume(99));
482 EXPECT_EQ(-1, fme_->output_volume());
483
484 // Init() will apply the remembered volume.
485 EXPECT_TRUE(cm_->Init());
486 EXPECT_TRUE(cm_->GetOutputVolume(&level));
487 EXPECT_EQ(99, level);
488 EXPECT_EQ(level, fme_->output_volume());
489
490 EXPECT_TRUE(cm_->SetOutputVolume(60));
491 EXPECT_TRUE(cm_->GetOutputVolume(&level));
492 EXPECT_EQ(60, level);
493 EXPECT_EQ(level, fme_->output_volume());
494}
495
496TEST_F(ChannelManagerTest, GetSetOutputVolume) {
497 int level;
498 EXPECT_TRUE(cm_->Init());
499 EXPECT_TRUE(cm_->GetOutputVolume(&level));
500 EXPECT_EQ(level, fme_->output_volume());
501
502 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
503 EXPECT_TRUE(cm_->SetOutputVolume(60));
504 EXPECT_EQ(60, fme_->output_volume());
505 EXPECT_TRUE(cm_->GetOutputVolume(&level));
506 EXPECT_EQ(60, level);
507}
508
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509// Test that logging options set before Init are applied properly,
510// and retained even after Init.
511TEST_F(ChannelManagerTest, SetLoggingBeforeInit) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000512 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
513 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
514 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000516 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
518 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000519 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000521 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
523}
524
525// Test that logging options set after Init are applied properly.
526TEST_F(ChannelManagerTest, SetLogging) {
527 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000528 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
529 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
530 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000532 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
534}
535
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536// Test that the Video/Voice Processors register and unregister
537TEST_F(ChannelManagerTest, RegisterProcessors) {
538 cricket::FakeMediaProcessor fmp;
539 EXPECT_TRUE(cm_->Init());
540 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
541 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
542
543 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
544 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
545
546 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
547 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
548
549 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
550 &fmp,
551 cricket::MPD_RX));
552 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
553 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_RX));
554
555
556 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
557 &fmp,
558 cricket::MPD_RX));
559 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
560 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
561
562 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
563 &fmp,
564 cricket::MPD_TX));
565 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_TX));
566 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
567
568 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
569 &fmp,
570 cricket::MPD_TX));
571 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
572 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
573}
574
575TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
576 std::vector<VideoCodec> codecs;
577 const VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
578
579 // By default RTX is disabled.
580 cm_->GetSupportedVideoCodecs(&codecs);
581 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
582
583 // Enable and check.
584 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
585 cm_->GetSupportedVideoCodecs(&codecs);
586 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
587
588 // Disable and check.
589 EXPECT_TRUE(cm_->SetVideoRtxEnabled(false));
590 cm_->GetSupportedVideoCodecs(&codecs);
591 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
592
593 // Cannot toggle rtx after initialization.
594 EXPECT_TRUE(cm_->Init());
595 EXPECT_FALSE(cm_->SetVideoRtxEnabled(true));
596 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
597
598 // Can set again after terminate.
599 cm_->Terminate();
600 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
601 cm_->GetSupportedVideoCodecs(&codecs);
602 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
603}
604
605} // namespace cricket