Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/talk/session/media/channelmanager_unittest.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 23.7 KB
Line 
1// 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
26#include "talk/base/gunit.h"
27#include "talk/base/logging.h"
28#include "talk/base/thread.h"
29#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(
65        fme_, fdme_, fdm_, fcm_, talk_base::Thread::Current());
66    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
90  talk_base::Thread worker_;
91  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());
102  EXPECT_EQ(talk_base::Thread::Current(), cm_->worker_thread());
103  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());
113  EXPECT_EQ(talk_base::Thread::Current(), cm_->worker_thread());
114  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.
119  EXPECT_FALSE(cm_->set_worker_thread(talk_base::Thread::Current()));
120  cm_->Terminate();
121  EXPECT_FALSE(cm_->initialized());
122}
123
124// Test that we fail to startup if we're given an unstarted thread.
125TEST_F(ChannelManagerTest, StartupShutdownOnUnstartedThread) {
126  EXPECT_TRUE(cm_->set_worker_thread(&worker_));
127  EXPECT_FALSE(cm_->Init());
128  EXPECT_FALSE(cm_->initialized());
129}
130
131// Test that we can create and destroy a voice and video channel.
132TEST_F(ChannelManagerTest, CreateDestroyChannels) {
133  EXPECT_TRUE(cm_->Init());
134  cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
135      session_, cricket::CN_AUDIO, false);
136  EXPECT_TRUE(voice_channel != NULL);
137  cricket::VideoChannel* video_channel =
138      cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
139                              false, voice_channel);
140  EXPECT_TRUE(video_channel != NULL);
141  cricket::DataChannel* data_channel =
142      cm_->CreateDataChannel(session_, cricket::CN_DATA,
143                             false, cricket::DCT_RTP);
144  EXPECT_TRUE(data_channel != NULL);
145  cm_->DestroyVideoChannel(video_channel);
146  cm_->DestroyVoiceChannel(voice_channel);
147  cm_->DestroyDataChannel(data_channel);
148  cm_->Terminate();
149}
150
151// Test that we can create and destroy a voice and video channel with a worker.
152TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
153  worker_.Start();
154  EXPECT_TRUE(cm_->set_worker_thread(&worker_));
155  EXPECT_TRUE(cm_->Init());
156  delete session_;
157  session_ = new cricket::FakeSession(&worker_, true);
158  cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
159      session_, cricket::CN_AUDIO, false);
160  EXPECT_TRUE(voice_channel != NULL);
161  cricket::VideoChannel* video_channel =
162      cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
163                              false, voice_channel);
164  EXPECT_TRUE(video_channel != NULL);
165  cricket::DataChannel* data_channel =
166      cm_->CreateDataChannel(session_, cricket::CN_DATA,
167                             false, cricket::DCT_RTP);
168  EXPECT_TRUE(data_channel != NULL);
169  cm_->DestroyVideoChannel(video_channel);
170  cm_->DestroyVoiceChannel(voice_channel);
171  cm_->DestroyDataChannel(data_channel);
172  cm_->Terminate();
173}
174
175// Test that we fail to create a voice/video channel if the session is unable
176// to create a cricket::TransportChannel
177TEST_F(ChannelManagerTest, NoTransportChannelTest) {
178  EXPECT_TRUE(cm_->Init());
179  session_->set_fail_channel_creation(true);
180  // The test is useless unless the session does not fail creating
181  // cricket::TransportChannel.
182  ASSERT_TRUE(session_->CreateChannel(
183      "audio", "rtp", cricket::ICE_CANDIDATE_COMPONENT_RTP) == NULL);
184
185  cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
186      session_, cricket::CN_AUDIO, false);
187  EXPECT_TRUE(voice_channel == NULL);
188  cricket::VideoChannel* video_channel =
189      cm_->CreateVideoChannel(session_, cricket::CN_VIDEO,
190                              false, voice_channel);
191  EXPECT_TRUE(video_channel == NULL);
192  cricket::DataChannel* data_channel =
193      cm_->CreateDataChannel(session_, cricket::CN_DATA,
194                             false, cricket::DCT_RTP);
195  EXPECT_TRUE(data_channel == NULL);
196  cm_->Terminate();
197}
198
199// Test that SetDefaultVideoCodec passes through the right values.
200TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
201  cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
202  cricket::VideoEncoderConfig config(codec, 1, 2);
203  EXPECT_TRUE(cm_->Init());
204  EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
205  EXPECT_EQ(config, fme_->default_video_encoder_config());
206}
207
208struct GetCapturerFrameSize : public sigslot::has_slots<> {
209  void OnVideoFrame(VideoCapturer* capturer, const VideoFrame* frame) {
210    width = frame->GetWidth();
211    height = frame->GetHeight();
212  }
213  GetCapturerFrameSize(VideoCapturer* capturer) : width(0), height(0) {
214    capturer->SignalVideoFrame.connect(this,
215                                       &GetCapturerFrameSize::OnVideoFrame);
216    static_cast<FakeVideoCapturer*>(capturer)->CaptureFrame();
217  }
218  size_t width;
219  size_t height;
220};
221
222TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) {
223  VideoCodec codec(100, "VP8", 640, 360, 30, 0);
224  VideoFormat format(640, 360, 33, FOURCC_ANY);
225  VideoEncoderConfig config(codec, 1, 2);
226  EXPECT_TRUE(cm_->Init());
227  // A capturer created before the default encoder config is set will have no
228  // set aspect ratio, so it'll be 4:3 (based on the fake video capture impl).
229  VideoCapturer* capturer = cm_->CreateVideoCapturer();
230  ASSERT_TRUE(capturer != NULL);
231  EXPECT_EQ(CS_RUNNING, capturer->Start(format));
232  GetCapturerFrameSize size(capturer);
233  EXPECT_EQ(640u, size.width);
234  EXPECT_EQ(480u, size.height);
235  delete capturer;
236  // Try again, but with the encoder config set to 16:9.
237  EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
238  capturer = cm_->CreateVideoCapturer();
239  ASSERT_TRUE(capturer != NULL);
240  EXPECT_EQ(CS_RUNNING, capturer->Start(format));
241  GetCapturerFrameSize cropped_size(capturer);
242  EXPECT_EQ(640u, cropped_size.width);
243  EXPECT_EQ(360u, cropped_size.height);
244  delete capturer;
245}
246
247// Test that SetDefaultVideoCodec passes through the right values.
248TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
249  cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
250  cricket::VideoEncoderConfig config(codec, 1, 2);
251  EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
252  EXPECT_TRUE(cm_->Init());
253  EXPECT_EQ(config, fme_->default_video_encoder_config());
254}
255
256TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) {
257  // Test that values that we set before Init are applied.
258  AudioOptions options;
259  options.auto_gain_control.Set(true);
260  options.echo_cancellation.Set(false);
261  EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
262  std::string audio_in, audio_out;
263  AudioOptions set_options;
264  // Check options before Init.
265  EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
266  EXPECT_EQ("audio-in1", audio_in);
267  EXPECT_EQ("audio-out1", audio_out);
268  EXPECT_EQ(options, set_options);
269  EXPECT_TRUE(cm_->Init());
270  // Check options after Init.
271  EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
272  EXPECT_EQ("audio-in1", audio_in);
273  EXPECT_EQ("audio-out1", audio_out);
274  EXPECT_EQ(options, set_options);
275  // At this point, the media engine should also be initialized.
276  EXPECT_EQ(options, fme_->audio_options());
277  EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
278            fme_->audio_delay_offset());
279}
280
281TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) {
282  std::string audio_in, audio_out;
283  AudioOptions options;
284  options.echo_cancellation.Set(true);
285  EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options));
286  EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL));
287  EXPECT_EQ("audio-in2", audio_in);
288  EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL));
289  EXPECT_EQ("audio-out2", audio_out);
290  AudioOptions out_options;
291  EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options));
292  bool echo_cancellation = false;
293  EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation));
294  EXPECT_TRUE(echo_cancellation);
295}
296
297TEST_F(ChannelManagerTest, SetAudioOptions) {
298  // Test initial state.
299  EXPECT_TRUE(cm_->Init());
300  EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
301            fme_->audio_in_device());
302  EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
303            fme_->audio_out_device());
304  EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
305            fme_->audio_delay_offset());
306  // Test setting specific values.
307  AudioOptions options;
308  options.auto_gain_control.Set(true);
309  EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
310  EXPECT_EQ("audio-in1", fme_->audio_in_device());
311  EXPECT_EQ("audio-out1", fme_->audio_out_device());
312  bool auto_gain_control = false;
313  EXPECT_TRUE(
314      fme_->audio_options().auto_gain_control.Get(&auto_gain_control));
315  EXPECT_TRUE(auto_gain_control);
316  EXPECT_EQ(cricket::MediaEngineInterface::kDefaultAudioDelayOffset,
317            fme_->audio_delay_offset());
318  // Test setting bad values.
319  EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options));
320}
321
322TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) {
323  // Test that values that we set before Init are applied.
324  EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
325  EXPECT_TRUE(cm_->Init());
326  EXPECT_EQ("video-in2", cm_->video_device_name());
327}
328
329TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) {
330  std::string video_in;
331  // Test that GetCaptureDevice works before Init.
332  EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
333  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
334  EXPECT_EQ("video-in1", video_in);
335  // Test that options set before Init can be gotten after Init.
336  EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
337  EXPECT_TRUE(cm_->Init());
338  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
339  EXPECT_EQ("video-in2", video_in);
340}
341
342TEST_F(ChannelManagerTest, SetCaptureDevice) {
343  // Test setting defaults.
344  EXPECT_TRUE(cm_->Init());
345  EXPECT_TRUE(cm_->SetCaptureDevice(""));  // will use DeviceManager default
346  EXPECT_EQ("video-in1", cm_->video_device_name());
347  // Test setting specific values.
348  EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
349  EXPECT_EQ("video-in2", cm_->video_device_name());
350  // TODO(juberti): Add test for invalid value here.
351}
352
353// Test unplugging and plugging back the preferred devices. When the preferred
354// device is unplugged, we fall back to the default device. When the preferred
355// device is plugged back, we use it.
356TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) {
357  // Set preferences "audio-in1" and "audio-out1" before init.
358  AudioOptions options;
359  EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
360  // Unplug device "audio-in1" and "audio-out1".
361  std::vector<std::string> in_device_list, out_device_list;
362  in_device_list.push_back("audio-in2");
363  out_device_list.push_back("audio-out2");
364  fdm_->SetAudioInputDevices(in_device_list);
365  fdm_->SetAudioOutputDevices(out_device_list);
366  // Init should fall back to default devices.
367  EXPECT_TRUE(cm_->Init());
368  // The media engine should use the default.
369  EXPECT_EQ("", fme_->audio_in_device());
370  EXPECT_EQ("", fme_->audio_out_device());
371  // The channel manager keeps the preferences "audio-in1" and "audio-out1".
372  std::string audio_in, audio_out;
373  EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
374  EXPECT_EQ("audio-in1", audio_in);
375  EXPECT_EQ("audio-out1", audio_out);
376  cm_->Terminate();
377
378  // Plug devices "audio-in2" and "audio-out2" back.
379  in_device_list.push_back("audio-in1");
380  out_device_list.push_back("audio-out1");
381  fdm_->SetAudioInputDevices(in_device_list);
382  fdm_->SetAudioOutputDevices(out_device_list);
383  // Init again. The preferences, "audio-in2" and "audio-out2", are used.
384  EXPECT_TRUE(cm_->Init());
385  EXPECT_EQ("audio-in1", fme_->audio_in_device());
386  EXPECT_EQ("audio-out1", fme_->audio_out_device());
387  EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
388  EXPECT_EQ("audio-in1", audio_in);
389  EXPECT_EQ("audio-out1", audio_out);
390}
391
392// We have one camera. Unplug it, fall back to no camera.
393TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) {
394  // Set preferences "video-in1" before init.
395  std::vector<std::string> vid_device_list;
396  vid_device_list.push_back("video-in1");
397  fdm_->SetVideoCaptureDevices(vid_device_list);
398  EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
399
400  // Unplug "video-in1".
401  vid_device_list.clear();
402  fdm_->SetVideoCaptureDevices(vid_device_list);
403
404  // Init should fall back to avatar.
405  EXPECT_TRUE(cm_->Init());
406  // The media engine should use no camera.
407  EXPECT_EQ("", cm_->video_device_name());
408  // The channel manager keeps the user preference "video-in".
409  std::string video_in;
410  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
411  EXPECT_EQ("video-in1", video_in);
412  cm_->Terminate();
413
414  // Plug device "video-in1" back.
415  vid_device_list.push_back("video-in1");
416  fdm_->SetVideoCaptureDevices(vid_device_list);
417  // Init again. The user preferred device, "video-in1", is used.
418  EXPECT_TRUE(cm_->Init());
419  EXPECT_EQ("video-in1", cm_->video_device_name());
420  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
421  EXPECT_EQ("video-in1", video_in);
422}
423
424// We have multiple cameras. Unplug the preferred, fall back to another camera.
425TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) {
426  // Set video device to "video-in1" before init.
427  EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
428  // Unplug device "video-in1".
429  std::vector<std::string> vid_device_list;
430  vid_device_list.push_back("video-in2");
431  fdm_->SetVideoCaptureDevices(vid_device_list);
432  // Init should fall back to default device "video-in2".
433  EXPECT_TRUE(cm_->Init());
434  // The media engine should use the default device "video-in2".
435  EXPECT_EQ("video-in2", cm_->video_device_name());
436  // The channel manager keeps the user preference "video-in".
437  std::string video_in;
438  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
439  EXPECT_EQ("video-in1", video_in);
440  cm_->Terminate();
441
442  // Plug device "video-in1" back.
443  vid_device_list.push_back("video-in1");
444  fdm_->SetVideoCaptureDevices(vid_device_list);
445  // Init again. The user preferred device, "video-in1", is used.
446  EXPECT_TRUE(cm_->Init());
447  EXPECT_EQ("video-in1", cm_->video_device_name());
448  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
449  EXPECT_EQ("video-in1", video_in);
450}
451
452TEST_F(ChannelManagerTest, GetCaptureDevice) {
453  std::string video_in;
454  // Test setting/getting defaults.
455  EXPECT_TRUE(cm_->Init());
456  EXPECT_TRUE(cm_->SetCaptureDevice(""));
457  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
458  EXPECT_EQ("video-in1", video_in);
459  // Test setting/getting specific values.
460  EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
461  EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
462  EXPECT_EQ("video-in2", video_in);
463}
464
465TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) {
466  int level;
467  // Before init, SetOutputVolume() remembers the volume but does not change the
468  // volume of the engine. GetOutputVolume() should fail.
469  EXPECT_EQ(-1, fme_->output_volume());
470  EXPECT_FALSE(cm_->GetOutputVolume(&level));
471  EXPECT_FALSE(cm_->SetOutputVolume(-1));  // Invalid volume.
472  EXPECT_TRUE(cm_->SetOutputVolume(99));
473  EXPECT_EQ(-1, fme_->output_volume());
474
475  // Init() will apply the remembered volume.
476  EXPECT_TRUE(cm_->Init());
477  EXPECT_TRUE(cm_->GetOutputVolume(&level));
478  EXPECT_EQ(99, level);
479  EXPECT_EQ(level, fme_->output_volume());
480
481  EXPECT_TRUE(cm_->SetOutputVolume(60));
482  EXPECT_TRUE(cm_->GetOutputVolume(&level));
483  EXPECT_EQ(60, level);
484  EXPECT_EQ(level, fme_->output_volume());
485}
486
487TEST_F(ChannelManagerTest, GetSetOutputVolume) {
488  int level;
489  EXPECT_TRUE(cm_->Init());
490  EXPECT_TRUE(cm_->GetOutputVolume(&level));
491  EXPECT_EQ(level, fme_->output_volume());
492
493  EXPECT_FALSE(cm_->SetOutputVolume(-1));  // Invalid volume.
494  EXPECT_TRUE(cm_->SetOutputVolume(60));
495  EXPECT_EQ(60, fme_->output_volume());
496  EXPECT_TRUE(cm_->GetOutputVolume(&level));
497  EXPECT_EQ(60, level);
498}
499
500// Test that a value set before Init is applied properly.
501TEST_F(ChannelManagerTest, SetLocalRendererBeforeInit) {
502  cricket::NullVideoRenderer renderer;
503  EXPECT_TRUE(cm_->SetLocalRenderer(&renderer));
504  EXPECT_TRUE(cm_->Init());
505  EXPECT_EQ(&renderer, fme_->local_renderer());
506}
507
508// Test that a value set after init is passed through properly.
509TEST_F(ChannelManagerTest, SetLocalRenderer) {
510  cricket::NullVideoRenderer renderer;
511  EXPECT_TRUE(cm_->Init());
512  EXPECT_TRUE(cm_->SetLocalRenderer(&renderer));
513  EXPECT_EQ(&renderer, fme_->local_renderer());
514}
515
516// Test that logging options set before Init are applied properly,
517// and retained even after Init.
518TEST_F(ChannelManagerTest, SetLoggingBeforeInit) {
519  cm_->SetVoiceLogging(talk_base::LS_INFO, "test-voice");
520  cm_->SetVideoLogging(talk_base::LS_VERBOSE, "test-video");
521  EXPECT_EQ(talk_base::LS_INFO, fme_->voice_loglevel());
522  EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
523  EXPECT_EQ(talk_base::LS_VERBOSE, fme_->video_loglevel());
524  EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
525  EXPECT_TRUE(cm_->Init());
526  EXPECT_EQ(talk_base::LS_INFO, fme_->voice_loglevel());
527  EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
528  EXPECT_EQ(talk_base::LS_VERBOSE, fme_->video_loglevel());
529  EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
530}
531
532// Test that logging options set after Init are applied properly.
533TEST_F(ChannelManagerTest, SetLogging) {
534  EXPECT_TRUE(cm_->Init());
535  cm_->SetVoiceLogging(talk_base::LS_INFO, "test-voice");
536  cm_->SetVideoLogging(talk_base::LS_VERBOSE, "test-video");
537  EXPECT_EQ(talk_base::LS_INFO, fme_->voice_loglevel());
538  EXPECT_STREQ("test-voice", fme_->voice_logfilter().c_str());
539  EXPECT_EQ(talk_base::LS_VERBOSE, fme_->video_loglevel());
540  EXPECT_STREQ("test-video", fme_->video_logfilter().c_str());
541}
542
543// Test that the Video/Voice Processors register and unregister
544TEST_F(ChannelManagerTest, RegisterProcessors) {
545  cricket::FakeMediaProcessor fmp;
546  EXPECT_TRUE(cm_->Init());
547  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
548  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
549
550  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
551  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
552
553  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
554  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
555
556  EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
557                                          &fmp,
558                                          cricket::MPD_RX));
559  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
560  EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_RX));
561
562
563  EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
564                                            &fmp,
565                                            cricket::MPD_RX));
566  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
567  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
568
569  EXPECT_TRUE(cm_->RegisterVoiceProcessor(1,
570                                          &fmp,
571                                          cricket::MPD_TX));
572  EXPECT_TRUE(fme_->voice_processor_registered(cricket::MPD_TX));
573  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
574
575  EXPECT_TRUE(cm_->UnregisterVoiceProcessor(1,
576                                            &fmp,
577                                            cricket::MPD_TX));
578  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_TX));
579  EXPECT_FALSE(fme_->voice_processor_registered(cricket::MPD_RX));
580}
581
582TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
583  std::vector<VideoCodec> codecs;
584  const VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0);
585
586  // By default RTX is disabled.
587  cm_->GetSupportedVideoCodecs(&codecs);
588  EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
589
590  // Enable and check.
591  EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
592  cm_->GetSupportedVideoCodecs(&codecs);
593  EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
594
595  // Disable and check.
596  EXPECT_TRUE(cm_->SetVideoRtxEnabled(false));
597  cm_->GetSupportedVideoCodecs(&codecs);
598  EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
599
600  // Cannot toggle rtx after initialization.
601  EXPECT_TRUE(cm_->Init());
602  EXPECT_FALSE(cm_->SetVideoRtxEnabled(true));
603  EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
604
605  // Can set again after terminate.
606  cm_->Terminate();
607  EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
608  cm_->GetSupportedVideoCodecs(&codecs);
609  EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
610}
611
612}  // namespace cricket
Note: See TracBrowser for help on using the repository browser.