jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2008 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/fakemediacontroller.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 12 | #include "webrtc/base/gunit.h" |
| 13 | #include "webrtc/base/logging.h" |
| 14 | #include "webrtc/base/thread.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame^] | 15 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 16 | #include "webrtc/media/base/fakemediaengine.h" |
| 17 | #include "webrtc/media/base/fakevideocapturer.h" |
| 18 | #include "webrtc/media/base/testutils.h" |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 19 | #include "webrtc/media/engine/fakewebrtccall.h" |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 20 | #include "webrtc/p2p/base/faketransportcontroller.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 21 | #include "webrtc/pc/channelmanager.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
| 23 | namespace cricket { |
| 24 | |
| 25 | static const AudioCodec kAudioCodecs[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 26 | AudioCodec(97, "voice", 1, 2, 3), AudioCodec(111, "OPUS", 48000, 32000, 2), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static const VideoCodec kVideoCodecs[] = { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 30 | VideoCodec(99, "H264", 100, 200, 300), |
| 31 | VideoCodec(100, "VP8", 100, 200, 300), VideoCodec(96, "rtx", 100, 200, 300), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | class ChannelManagerTest : public testing::Test { |
| 35 | protected: |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 36 | ChannelManagerTest() |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 37 | : fme_(new cricket::FakeMediaEngine()), |
| 38 | fdme_(new cricket::FakeDataEngine()), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame^] | 39 | cm_(new cricket::ChannelManager(fme_, fdme_, rtc::Thread::Current())), |
| 40 | fake_call_(webrtc::Call::Config(&event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 41 | fake_mc_(cm_, &fake_call_), |
| 42 | transport_controller_( |
| 43 | new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
| 45 | virtual void SetUp() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
| 47 | fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | virtual void TearDown() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 51 | delete transport_controller_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | delete cm_; |
| 53 | cm_ = NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | fdme_ = NULL; |
| 55 | fme_ = NULL; |
| 56 | } |
| 57 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame^] | 58 | webrtc::RtcEventLogNullImpl event_log_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 59 | rtc::Thread network_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 60 | rtc::Thread worker_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | cricket::FakeMediaEngine* fme_; |
| 62 | cricket::FakeDataEngine* fdme_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | cricket::ChannelManager* cm_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 64 | cricket::FakeCall fake_call_; |
| 65 | cricket::FakeMediaController fake_mc_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 66 | cricket::FakeTransportController* transport_controller_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // Test that we startup/shutdown properly. |
| 70 | TEST_F(ChannelManagerTest, StartupShutdown) { |
| 71 | EXPECT_FALSE(cm_->initialized()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 72 | EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | EXPECT_TRUE(cm_->Init()); |
| 74 | EXPECT_TRUE(cm_->initialized()); |
| 75 | cm_->Terminate(); |
| 76 | EXPECT_FALSE(cm_->initialized()); |
| 77 | } |
| 78 | |
| 79 | // Test that we startup/shutdown properly with a worker thread. |
| 80 | TEST_F(ChannelManagerTest, StartupShutdownOnThread) { |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 81 | network_.Start(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | worker_.Start(); |
| 83 | EXPECT_FALSE(cm_->initialized()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 84 | EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 85 | EXPECT_TRUE(cm_->set_network_thread(&network_)); |
| 86 | EXPECT_EQ(&network_, cm_->network_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
| 88 | EXPECT_EQ(&worker_, cm_->worker_thread()); |
| 89 | EXPECT_TRUE(cm_->Init()); |
| 90 | EXPECT_TRUE(cm_->initialized()); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 91 | // Setting the network or worker thread while initialized should fail. |
| 92 | EXPECT_FALSE(cm_->set_network_thread(rtc::Thread::Current())); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 93 | EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | cm_->Terminate(); |
| 95 | EXPECT_FALSE(cm_->initialized()); |
| 96 | } |
| 97 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | // Test that we can create and destroy a voice and video channel. |
| 99 | TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
| 100 | EXPECT_TRUE(cm_->Init()); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 101 | cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 102 | &fake_mc_, transport_controller_, cricket::CN_AUDIO, nullptr, false, |
| 103 | AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 104 | EXPECT_TRUE(voice_channel != nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 105 | cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
| 106 | &fake_mc_, transport_controller_, cricket::CN_VIDEO, nullptr, false, |
| 107 | VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 108 | EXPECT_TRUE(video_channel != nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 109 | cricket::DataChannel* data_channel = |
| 110 | cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, nullptr, |
| 111 | false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 112 | EXPECT_TRUE(data_channel != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | cm_->DestroyVideoChannel(video_channel); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 114 | cm_->DestroyVoiceChannel(voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | cm_->DestroyDataChannel(data_channel); |
| 116 | cm_->Terminate(); |
| 117 | } |
| 118 | |
| 119 | // Test that we can create and destroy a voice and video channel with a worker. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 120 | TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 121 | network_.Start(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | worker_.Start(); |
| 123 | EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 124 | EXPECT_TRUE(cm_->set_network_thread(&network_)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | EXPECT_TRUE(cm_->Init()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 126 | delete transport_controller_; |
| 127 | transport_controller_ = |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 128 | new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 129 | cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 130 | &fake_mc_, transport_controller_, cricket::CN_AUDIO, nullptr, false, |
| 131 | AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 132 | EXPECT_TRUE(voice_channel != nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 133 | cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
| 134 | &fake_mc_, transport_controller_, cricket::CN_VIDEO, nullptr, false, |
| 135 | VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 136 | EXPECT_TRUE(video_channel != nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 137 | cricket::DataChannel* data_channel = |
| 138 | cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, nullptr, |
| 139 | false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 140 | EXPECT_TRUE(data_channel != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | cm_->DestroyVideoChannel(video_channel); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 142 | cm_->DestroyVoiceChannel(voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | cm_->DestroyDataChannel(data_channel); |
| 144 | cm_->Terminate(); |
| 145 | } |
| 146 | |
| 147 | // Test that we fail to create a voice/video channel if the session is unable |
| 148 | // to create a cricket::TransportChannel |
| 149 | TEST_F(ChannelManagerTest, NoTransportChannelTest) { |
| 150 | EXPECT_TRUE(cm_->Init()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 151 | transport_controller_->set_fail_channel_creation(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | // The test is useless unless the session does not fail creating |
| 153 | // cricket::TransportChannel. |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 154 | ASSERT_TRUE(transport_controller_->CreateTransportChannel_n( |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 155 | "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 157 | cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 158 | &fake_mc_, transport_controller_, cricket::CN_AUDIO, nullptr, false, |
| 159 | AudioOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 160 | EXPECT_TRUE(voice_channel == nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 161 | cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
| 162 | &fake_mc_, transport_controller_, cricket::CN_VIDEO, nullptr, false, |
| 163 | VideoOptions()); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 164 | EXPECT_TRUE(video_channel == nullptr); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 165 | cricket::DataChannel* data_channel = |
| 166 | cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, nullptr, |
| 167 | false, cricket::DCT_RTP); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 168 | EXPECT_TRUE(data_channel == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | cm_->Terminate(); |
| 170 | } |
| 171 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | TEST_F(ChannelManagerTest, SetVideoRtxEnabled) { |
| 173 | std::vector<VideoCodec> codecs; |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 174 | const VideoCodec rtx_codec(96, "rtx", 0, 0, 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | |
| 176 | // By default RTX is disabled. |
| 177 | cm_->GetSupportedVideoCodecs(&codecs); |
| 178 | EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 179 | |
| 180 | // Enable and check. |
| 181 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
| 182 | cm_->GetSupportedVideoCodecs(&codecs); |
| 183 | EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 184 | |
| 185 | // Disable and check. |
| 186 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(false)); |
| 187 | cm_->GetSupportedVideoCodecs(&codecs); |
| 188 | EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 189 | |
| 190 | // Cannot toggle rtx after initialization. |
| 191 | EXPECT_TRUE(cm_->Init()); |
| 192 | EXPECT_FALSE(cm_->SetVideoRtxEnabled(true)); |
| 193 | EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
| 194 | |
| 195 | // Can set again after terminate. |
| 196 | cm_->Terminate(); |
| 197 | EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
| 198 | cm_->GetSupportedVideoCodecs(&codecs); |
| 199 | EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 200 | } |
| 201 | |
| 202 | } // namespace cricket |