blob: f3018295d2ec291b147955c02721d829aa99037f [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
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/gunit.h"
27#include "webrtc/base/logging.h"
28#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029#include "talk/media/base/fakecapturemanager.h"
30#include "talk/media/base/fakemediaengine.h"
31#include "talk/media/base/fakemediaprocessor.h"
32#include "talk/media/base/nullvideorenderer.h"
33#include "talk/media/devices/fakedevicemanager.h"
34#include "talk/media/base/testutils.h"
35#include "talk/p2p/base/fakesession.h"
36#include "talk/session/media/channelmanager.h"
37
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);
130 cricket::VideoChannel* video_channel =
131 cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
132 false, voice_channel);
133 EXPECT_TRUE(video_channel != NULL);
134 cricket::DataChannel* data_channel =
135 cm_->CreateDataChannel(session_, cricket::CN_DATA,
136 false, cricket::DCT_RTP);
137 EXPECT_TRUE(data_channel != NULL);
138 cm_->DestroyVideoChannel(video_channel);
139 cm_->DestroyVoiceChannel(voice_channel);
140 cm_->DestroyDataChannel(data_channel);
141 cm_->Terminate();
142}
143
144// Test that we can create and destroy a voice and video channel with a worker.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000145TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 worker_.Start();
147 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
148 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000149 delete session_;
wu@webrtc.org1d1ffc92013-10-16 18:12:02 +0000150 session_ = new cricket::FakeSession(&worker_, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
152 session_, cricket::CN_AUDIO, false);
153 EXPECT_TRUE(voice_channel != NULL);
154 cricket::VideoChannel* video_channel =
155 cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
156 false, voice_channel);
157 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);
181 cricket::VideoChannel* video_channel =
182 cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
183 false, voice_channel);
184 EXPECT_TRUE(video_channel == NULL);
185 cricket::DataChannel* data_channel =
186 cm_->CreateDataChannel(session_, cricket::CN_DATA,
187 false, cricket::DCT_RTP);
188 EXPECT_TRUE(data_channel == NULL);
189 cm_->Terminate();
190}
191
192// Test that SetDefaultVideoCodec passes through the right values.
193TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
194 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
195 cricket::VideoEncoderConfig config(codec, 1, 2);
196 EXPECT_TRUE(cm_->Init());
197 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
198 EXPECT_EQ(config, fme_->default_video_encoder_config());
199}
200
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000201struct GetCapturerFrameSize : public sigslot::has_slots<> {
202 void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* frame) {
203 width = frame->GetWidth();
204 height = frame->GetHeight();
205 }
206 GetCapturerFrameSize(VideoCapturer* capturer) : width(0), height(0) {
207 capturer->SignalVideoFrame.connect(this,
208 &GetCapturerFrameSize::OnVideoFrame);
209 static_cast<FakeVideoCapturer*>(capturer)->CaptureFrame();
210 }
211 size_t width;
212 size_t height;
213};
214
215TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) {
216 VideoCodec codec(100, "VP8", 640, 360, 30, 0);
217 VideoFormat format(640, 360, 33, FOURCC_ANY);
218 VideoEncoderConfig config(codec, 1, 2);
219 EXPECT_TRUE(cm_->Init());
220 // A capturer created before the default encoder config is set will have no
221 // set aspect ratio, so it'll be 4:3 (based on the fake video capture impl).
222 VideoCapturer* capturer = cm_->CreateVideoCapturer();
223 ASSERT_TRUE(capturer != NULL);
224 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
225 GetCapturerFrameSize size(capturer);
226 EXPECT_EQ(640u, size.width);
227 EXPECT_EQ(480u, size.height);
228 delete capturer;
229 // Try again, but with the encoder config set to 16:9.
230 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
231 capturer = cm_->CreateVideoCapturer();
232 ASSERT_TRUE(capturer != NULL);
233 EXPECT_EQ(CS_RUNNING, capturer->Start(format));
234 GetCapturerFrameSize cropped_size(capturer);
235 EXPECT_EQ(640u, cropped_size.width);
236 EXPECT_EQ(360u, cropped_size.height);
237 delete capturer;
238}
239
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240// Test that SetDefaultVideoCodec passes through the right values.
241TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
242 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
243 cricket::VideoEncoderConfig config(codec, 1, 2);
244 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
245 EXPECT_TRUE(cm_->Init());
246 EXPECT_EQ(config, fme_->default_video_encoder_config());
247}
248
249TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) {
250 // Test that values that we set before Init are applied.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000251 AudioOptions options;
252 options.auto_gain_control.Set(true);
253 options.echo_cancellation.Set(false);
254 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
255 std::string audio_in, audio_out;
256 AudioOptions set_options;
257 // Check options before Init.
258 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
259 EXPECT_EQ("audio-in1", audio_in);
260 EXPECT_EQ("audio-out1", audio_out);
261 EXPECT_EQ(options, set_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 EXPECT_TRUE(cm_->Init());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000263 // Check options after Init.
264 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
265 EXPECT_EQ("audio-in1", audio_in);
266 EXPECT_EQ("audio-out1", audio_out);
267 EXPECT_EQ(options, set_options);
268 // At this point, the media engine should also be initialized.
269 EXPECT_EQ(options, fme_->audio_options());
buildbot@webrtc.orgbb2d6582014-06-20 14:58:56 +0000270 EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 fme_->audio_delay_offset());
272}
273
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) {
275 std::string audio_in, audio_out;
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000276 AudioOptions options;
277 options.echo_cancellation.Set(true);
278 EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL));
280 EXPECT_EQ("audio-in2", audio_in);
281 EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL));
282 EXPECT_EQ("audio-out2", audio_out);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000283 AudioOptions out_options;
284 EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options));
285 bool echo_cancellation = false;
286 EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation));
287 EXPECT_TRUE(echo_cancellation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288}
289
290TEST_F(ChannelManagerTest, SetAudioOptions) {
291 // Test initial state.
292 EXPECT_TRUE(cm_->Init());
293 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
294 fme_->audio_in_device());
295 EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
296 fme_->audio_out_device());
buildbot@webrtc.orgbb2d6582014-06-20 14:58:56 +0000297 EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 fme_->audio_delay_offset());
299 // Test setting specific values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000300 AudioOptions options;
301 options.auto_gain_control.Set(true);
302 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 EXPECT_EQ("audio-in1", fme_->audio_in_device());
304 EXPECT_EQ("audio-out1", fme_->audio_out_device());
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000305 bool auto_gain_control = false;
306 EXPECT_TRUE(
307 fme_->audio_options().auto_gain_control.Get(&auto_gain_control));
308 EXPECT_TRUE(auto_gain_control);
buildbot@webrtc.orgbb2d6582014-06-20 14:58:56 +0000309 EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 fme_->audio_delay_offset());
311 // Test setting bad values.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000312 EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313}
314
buildbot@webrtc.org88d9fa62014-06-16 14:11:32 +0000315TEST_F(ChannelManagerTest, SetEngineAudioOptions) {
316 EXPECT_TRUE(cm_->Init());
317 // Test setting specific values.
318 AudioOptions options;
319 options.experimental_ns.Set(true);
320 EXPECT_TRUE(cm_->SetEngineAudioOptions(options));
321 bool experimental_ns = false;
322 EXPECT_TRUE(fme_->audio_options().experimental_ns.Get(&experimental_ns));
323 EXPECT_TRUE(experimental_ns);
324}
325
326TEST_F(ChannelManagerTest, SetEngineAudioOptionsBeforeInitFails) {
327 // Test that values that we set before Init are not applied.
328 AudioOptions options;
329 options.experimental_ns.Set(true);
330 EXPECT_FALSE(cm_->SetEngineAudioOptions(options));
331 EXPECT_FALSE(fme_->audio_options().experimental_ns.IsSet());
332}
333
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) {
335 // Test that values that we set before Init are applied.
336 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
337 EXPECT_TRUE(cm_->Init());
338 EXPECT_EQ("video-in2", cm_->video_device_name());
339}
340
341TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) {
342 std::string video_in;
343 // Test that GetCaptureDevice works before Init.
344 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
345 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
346 EXPECT_EQ("video-in1", video_in);
347 // Test that options set before Init can be gotten after Init.
348 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
349 EXPECT_TRUE(cm_->Init());
350 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
351 EXPECT_EQ("video-in2", video_in);
352}
353
354TEST_F(ChannelManagerTest, SetCaptureDevice) {
355 // Test setting defaults.
356 EXPECT_TRUE(cm_->Init());
357 EXPECT_TRUE(cm_->SetCaptureDevice("")); // will use DeviceManager default
358 EXPECT_EQ("video-in1", cm_->video_device_name());
359 // Test setting specific values.
360 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
361 EXPECT_EQ("video-in2", cm_->video_device_name());
362 // TODO(juberti): Add test for invalid value here.
363}
364
365// Test unplugging and plugging back the preferred devices. When the preferred
366// device is unplugged, we fall back to the default device. When the preferred
367// device is plugged back, we use it.
368TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) {
369 // Set preferences "audio-in1" and "audio-out1" before init.
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000370 AudioOptions options;
371 EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 // Unplug device "audio-in1" and "audio-out1".
373 std::vector<std::string> in_device_list, out_device_list;
374 in_device_list.push_back("audio-in2");
375 out_device_list.push_back("audio-out2");
376 fdm_->SetAudioInputDevices(in_device_list);
377 fdm_->SetAudioOutputDevices(out_device_list);
378 // Init should fall back to default devices.
379 EXPECT_TRUE(cm_->Init());
380 // The media engine should use the default.
381 EXPECT_EQ("", fme_->audio_in_device());
382 EXPECT_EQ("", fme_->audio_out_device());
383 // The channel manager keeps the preferences "audio-in1" and "audio-out1".
384 std::string audio_in, audio_out;
385 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
386 EXPECT_EQ("audio-in1", audio_in);
387 EXPECT_EQ("audio-out1", audio_out);
388 cm_->Terminate();
389
390 // Plug devices "audio-in2" and "audio-out2" back.
391 in_device_list.push_back("audio-in1");
392 out_device_list.push_back("audio-out1");
393 fdm_->SetAudioInputDevices(in_device_list);
394 fdm_->SetAudioOutputDevices(out_device_list);
395 // Init again. The preferences, "audio-in2" and "audio-out2", are used.
396 EXPECT_TRUE(cm_->Init());
397 EXPECT_EQ("audio-in1", fme_->audio_in_device());
398 EXPECT_EQ("audio-out1", fme_->audio_out_device());
399 EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
400 EXPECT_EQ("audio-in1", audio_in);
401 EXPECT_EQ("audio-out1", audio_out);
402}
403
404// We have one camera. Unplug it, fall back to no camera.
405TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) {
406 // Set preferences "video-in1" before init.
407 std::vector<std::string> vid_device_list;
408 vid_device_list.push_back("video-in1");
409 fdm_->SetVideoCaptureDevices(vid_device_list);
410 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
411
412 // Unplug "video-in1".
413 vid_device_list.clear();
414 fdm_->SetVideoCaptureDevices(vid_device_list);
415
416 // Init should fall back to avatar.
417 EXPECT_TRUE(cm_->Init());
418 // The media engine should use no camera.
419 EXPECT_EQ("", cm_->video_device_name());
420 // The channel manager keeps the user preference "video-in".
421 std::string video_in;
422 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
423 EXPECT_EQ("video-in1", video_in);
424 cm_->Terminate();
425
426 // Plug device "video-in1" back.
427 vid_device_list.push_back("video-in1");
428 fdm_->SetVideoCaptureDevices(vid_device_list);
429 // Init again. The user preferred device, "video-in1", is used.
430 EXPECT_TRUE(cm_->Init());
431 EXPECT_EQ("video-in1", cm_->video_device_name());
432 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
433 EXPECT_EQ("video-in1", video_in);
434}
435
436// We have multiple cameras. Unplug the preferred, fall back to another camera.
437TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) {
438 // Set video device to "video-in1" before init.
439 EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
440 // Unplug device "video-in1".
441 std::vector<std::string> vid_device_list;
442 vid_device_list.push_back("video-in2");
443 fdm_->SetVideoCaptureDevices(vid_device_list);
444 // Init should fall back to default device "video-in2".
445 EXPECT_TRUE(cm_->Init());
446 // The media engine should use the default device "video-in2".
447 EXPECT_EQ("video-in2", cm_->video_device_name());
448 // The channel manager keeps the user preference "video-in".
449 std::string video_in;
450 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
451 EXPECT_EQ("video-in1", video_in);
452 cm_->Terminate();
453
454 // Plug device "video-in1" back.
455 vid_device_list.push_back("video-in1");
456 fdm_->SetVideoCaptureDevices(vid_device_list);
457 // Init again. The user preferred device, "video-in1", is used.
458 EXPECT_TRUE(cm_->Init());
459 EXPECT_EQ("video-in1", cm_->video_device_name());
460 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
461 EXPECT_EQ("video-in1", video_in);
462}
463
464TEST_F(ChannelManagerTest, GetCaptureDevice) {
465 std::string video_in;
466 // Test setting/getting defaults.
467 EXPECT_TRUE(cm_->Init());
468 EXPECT_TRUE(cm_->SetCaptureDevice(""));
469 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
470 EXPECT_EQ("video-in1", video_in);
471 // Test setting/getting specific values.
472 EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
473 EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
474 EXPECT_EQ("video-in2", video_in);
475}
476
477TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) {
478 int level;
479 // Before init, SetOutputVolume() remembers the volume but does not change the
480 // volume of the engine. GetOutputVolume() should fail.
481 EXPECT_EQ(-1, fme_->output_volume());
482 EXPECT_FALSE(cm_->GetOutputVolume(&level));
483 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
484 EXPECT_TRUE(cm_->SetOutputVolume(99));
485 EXPECT_EQ(-1, fme_->output_volume());
486
487 // Init() will apply the remembered volume.
488 EXPECT_TRUE(cm_->Init());
489 EXPECT_TRUE(cm_->GetOutputVolume(&level));
490 EXPECT_EQ(99, level);
491 EXPECT_EQ(level, fme_->output_volume());
492
493 EXPECT_TRUE(cm_->SetOutputVolume(60));
494 EXPECT_TRUE(cm_->GetOutputVolume(&level));
495 EXPECT_EQ(60, level);
496 EXPECT_EQ(level, fme_->output_volume());
497}
498
499TEST_F(ChannelManagerTest, GetSetOutputVolume) {
500 int level;
501 EXPECT_TRUE(cm_->Init());
502 EXPECT_TRUE(cm_->GetOutputVolume(&level));
503 EXPECT_EQ(level, fme_->output_volume());
504
505 EXPECT_FALSE(cm_->SetOutputVolume(-1)); // Invalid volume.
506 EXPECT_TRUE(cm_->SetOutputVolume(60));
507 EXPECT_EQ(60, fme_->output_volume());
508 EXPECT_TRUE(cm_->GetOutputVolume(&level));
509 EXPECT_EQ(60, level);
510}
511
512// Test that a value set before Init is applied properly.
513TEST_F(ChannelManagerTest, SetLocalRendererBeforeInit) {
514 cricket::NullVideoRenderer renderer;
515 EXPECT_TRUE(cm_->SetLocalRenderer(&renderer));
516 EXPECT_TRUE(cm_->Init());
517 EXPECT_EQ(&renderer, fme_->local_renderer());
518}
519
520// Test that a value set after init is passed through properly.
521TEST_F(ChannelManagerTest, SetLocalRenderer) {
522 cricket::NullVideoRenderer renderer;
523 EXPECT_TRUE(cm_->Init());
524 EXPECT_TRUE(cm_->SetLocalRenderer(&renderer));
525 EXPECT_EQ(&renderer, fme_->local_renderer());
526}
527
528// Test that logging options set before Init are applied properly,
529// and retained even after Init.
530TEST_F(ChannelManagerTest, SetLoggingBeforeInit) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000531 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
532 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
533 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000535 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
537 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000540 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
542}
543
544// Test that logging options set after Init are applied properly.
545TEST_F(ChannelManagerTest, SetLogging) {
546 EXPECT_TRUE(cm_->Init());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000547 cm_->SetVoiceLogging(rtc::LS_INFO, "test-voice");
548 cm_->SetVideoLogging(rtc::LS_VERBOSE, "test-video");
549 EXPECT_EQ(rtc::LS_INFO, fme_->voice_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 EXPECT_EQ(rtc::LS_VERBOSE, fme_->video_loglevel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
553}
554
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555// Test that the Video/Voice Processors register and unregister
556TEST_F(ChannelManagerTest, RegisterProcessors) {
557 cricket::FakeMediaProcessor fmp;
558 EXPECT_TRUE(cm_->Init());
559 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
560 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
561
562 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
563 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
564
565 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
566 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
567
568 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
569 &fmp,
570 cricket::MPD_RX));
571 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
572 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_RX));
573
574
575 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
576 &fmp,
577 cricket::MPD_RX));
578 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
579 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
580
581 EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
582 &fmp,
583 cricket::MPD_TX));
584 EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_TX));
585 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
586
587 EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
588 &fmp,
589 cricket::MPD_TX));
590 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
591 EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
592}
593
594TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
595 std::vector<VideoCodec> codecs;
596 const VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
597
598 // By default RTX is disabled.
599 cm_->GetSupportedVideoCodecs(&codecs);
600 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
601
602 // Enable and check.
603 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
604 cm_->GetSupportedVideoCodecs(&codecs);
605 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
606
607 // Disable and check.
608 EXPECT_TRUE(cm_->SetVideoRtxEnabled(false));
609 cm_->GetSupportedVideoCodecs(&codecs);
610 EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
611
612 // Cannot toggle rtx after initialization.
613 EXPECT_TRUE(cm_->Init());
614 EXPECT_FALSE(cm_->SetVideoRtxEnabled(true));
615 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
616
617 // Can set again after terminate.
618 cm_->Terminate();
619 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
620 cm_->GetSupportedVideoCodecs(&codecs);
621 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
622}
623
624} // namespace cricket