OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2008 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
12 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
13 #include "webrtc/base/thread.h" | 15 #include "webrtc/base/thread.h" |
14 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 16 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
15 #include "webrtc/media/base/fakemediaengine.h" | 17 #include "webrtc/media/base/fakemediaengine.h" |
16 #include "webrtc/media/base/fakevideocapturer.h" | 18 #include "webrtc/media/base/fakevideocapturer.h" |
17 #include "webrtc/media/base/testutils.h" | 19 #include "webrtc/media/base/testutils.h" |
18 #include "webrtc/media/engine/fakewebrtccall.h" | 20 #include "webrtc/media/engine/fakewebrtccall.h" |
19 #include "webrtc/p2p/base/faketransportcontroller.h" | 21 #include "webrtc/p2p/base/faketransportcontroller.h" |
20 #include "webrtc/pc/channelmanager.h" | 22 #include "webrtc/pc/channelmanager.h" |
21 #include "webrtc/pc/fakemediacontroller.h" | 23 #include "webrtc/pc/fakemediacontroller.h" |
22 | 24 |
23 namespace cricket { | 25 namespace { |
24 const bool kDefaultRtcpMuxRequired = true; | |
25 const bool kDefaultSrtpRequired = true; | 26 const bool kDefaultSrtpRequired = true; |
26 } | 27 } |
27 | 28 |
28 namespace cricket { | 29 namespace cricket { |
29 | 30 |
30 static const AudioCodec kAudioCodecs[] = { | 31 static const AudioCodec kAudioCodecs[] = { |
31 AudioCodec(97, "voice", 1, 2, 3), AudioCodec(111, "OPUS", 48000, 32000, 2), | 32 AudioCodec(97, "voice", 1, 2, 3), AudioCodec(111, "OPUS", 48000, 32000, 2), |
32 }; | 33 }; |
33 | 34 |
34 static const VideoCodec kVideoCodecs[] = { | 35 static const VideoCodec kVideoCodecs[] = { |
35 VideoCodec(99, "H264"), VideoCodec(100, "VP8"), VideoCodec(96, "rtx"), | 36 VideoCodec(99, "H264"), VideoCodec(100, "VP8"), VideoCodec(96, "rtx"), |
36 }; | 37 }; |
37 | 38 |
38 class ChannelManagerTest : public testing::Test { | 39 class ChannelManagerTest : public testing::Test { |
39 protected: | 40 protected: |
40 ChannelManagerTest() | 41 ChannelManagerTest() |
41 : fme_(new cricket::FakeMediaEngine()), | 42 : fme_(new cricket::FakeMediaEngine()), |
42 fdme_(new cricket::FakeDataEngine()), | 43 fdme_(new cricket::FakeDataEngine()), |
43 cm_(new cricket::ChannelManager(fme_, fdme_, rtc::Thread::Current())), | 44 cm_(new cricket::ChannelManager( |
| 45 std::unique_ptr<MediaEngineInterface>(fme_), |
| 46 std::unique_ptr<DataEngineInterface>(fdme_), |
| 47 rtc::Thread::Current())), |
44 fake_call_(webrtc::Call::Config(&event_log_)), | 48 fake_call_(webrtc::Call::Config(&event_log_)), |
45 fake_mc_(cm_, &fake_call_), | 49 fake_mc_(cm_.get(), &fake_call_), |
46 transport_controller_( | 50 transport_controller_( |
47 new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {} | 51 new cricket::FakeTransportController(ICEROLE_CONTROLLING)) { |
48 | |
49 virtual void SetUp() { | |
50 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); | 52 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
51 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); | 53 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
52 } | 54 } |
53 | 55 |
54 virtual void TearDown() { | |
55 delete transport_controller_; | |
56 delete cm_; | |
57 cm_ = NULL; | |
58 fdme_ = NULL; | |
59 fme_ = NULL; | |
60 } | |
61 | |
62 webrtc::RtcEventLogNullImpl event_log_; | 56 webrtc::RtcEventLogNullImpl event_log_; |
63 rtc::Thread network_; | 57 rtc::Thread network_; |
64 rtc::Thread worker_; | 58 rtc::Thread worker_; |
| 59 // |fme_| and |fdme_| are actually owned by |cm_|. |
65 cricket::FakeMediaEngine* fme_; | 60 cricket::FakeMediaEngine* fme_; |
66 cricket::FakeDataEngine* fdme_; | 61 cricket::FakeDataEngine* fdme_; |
67 cricket::ChannelManager* cm_; | 62 std::unique_ptr<cricket::ChannelManager> cm_; |
68 cricket::FakeCall fake_call_; | 63 cricket::FakeCall fake_call_; |
69 cricket::FakeMediaController fake_mc_; | 64 cricket::FakeMediaController fake_mc_; |
70 cricket::FakeTransportController* transport_controller_; | 65 std::unique_ptr<cricket::FakeTransportController> transport_controller_; |
71 }; | 66 }; |
72 | 67 |
73 // Test that we startup/shutdown properly. | 68 // Test that we startup/shutdown properly. |
74 TEST_F(ChannelManagerTest, StartupShutdown) { | 69 TEST_F(ChannelManagerTest, StartupShutdown) { |
75 EXPECT_FALSE(cm_->initialized()); | 70 EXPECT_FALSE(cm_->initialized()); |
76 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); | 71 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
77 EXPECT_TRUE(cm_->Init()); | 72 EXPECT_TRUE(cm_->Init()); |
78 EXPECT_TRUE(cm_->initialized()); | 73 EXPECT_TRUE(cm_->initialized()); |
79 cm_->Terminate(); | 74 cm_->Terminate(); |
80 EXPECT_FALSE(cm_->initialized()); | 75 EXPECT_FALSE(cm_->initialized()); |
(...skipping 19 matching lines...) Expand all Loading... |
100 } | 95 } |
101 | 96 |
102 // Test that we can create and destroy a voice and video channel. | 97 // Test that we can create and destroy a voice and video channel. |
103 TEST_F(ChannelManagerTest, CreateDestroyChannels) { | 98 TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
104 EXPECT_TRUE(cm_->Init()); | 99 EXPECT_TRUE(cm_->Init()); |
105 cricket::DtlsTransportInternal* rtp_transport = | 100 cricket::DtlsTransportInternal* rtp_transport = |
106 transport_controller_->CreateDtlsTransport( | 101 transport_controller_->CreateDtlsTransport( |
107 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 102 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
108 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 103 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
109 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 104 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
110 rtc::Thread::Current(), cricket::CN_AUDIO, nullptr, | 105 rtc::Thread::Current(), cricket::CN_AUDIO, kDefaultSrtpRequired, |
111 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, AudioOptions()); | 106 AudioOptions()); |
112 EXPECT_TRUE(voice_channel != nullptr); | 107 EXPECT_TRUE(voice_channel != nullptr); |
113 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 108 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
114 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 109 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
115 rtc::Thread::Current(), cricket::CN_VIDEO, nullptr, | 110 rtc::Thread::Current(), cricket::CN_VIDEO, kDefaultSrtpRequired, |
116 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, VideoOptions()); | 111 VideoOptions()); |
117 EXPECT_TRUE(video_channel != nullptr); | 112 EXPECT_TRUE(video_channel != nullptr); |
118 cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel( | 113 cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel( |
119 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 114 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
120 rtc::Thread::Current(), cricket::CN_DATA, nullptr, | 115 rtc::Thread::Current(), cricket::CN_DATA, kDefaultSrtpRequired); |
121 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); | |
122 EXPECT_TRUE(rtp_data_channel != nullptr); | 116 EXPECT_TRUE(rtp_data_channel != nullptr); |
123 cm_->DestroyVideoChannel(video_channel); | 117 cm_->DestroyVideoChannel(video_channel); |
124 cm_->DestroyVoiceChannel(voice_channel); | 118 cm_->DestroyVoiceChannel(voice_channel); |
125 cm_->DestroyRtpDataChannel(rtp_data_channel); | 119 cm_->DestroyRtpDataChannel(rtp_data_channel); |
126 cm_->Terminate(); | 120 cm_->Terminate(); |
127 } | 121 } |
128 | 122 |
129 // Test that we can create and destroy a voice and video channel with a worker. | 123 // Test that we can create and destroy a voice and video channel with a worker. |
130 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { | 124 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
131 network_.Start(); | 125 network_.Start(); |
132 worker_.Start(); | 126 worker_.Start(); |
133 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); | 127 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
134 EXPECT_TRUE(cm_->set_network_thread(&network_)); | 128 EXPECT_TRUE(cm_->set_network_thread(&network_)); |
135 EXPECT_TRUE(cm_->Init()); | 129 EXPECT_TRUE(cm_->Init()); |
136 delete transport_controller_; | 130 transport_controller_.reset( |
137 transport_controller_ = | 131 new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING)); |
138 new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING); | |
139 cricket::DtlsTransportInternal* rtp_transport = | 132 cricket::DtlsTransportInternal* rtp_transport = |
140 transport_controller_->CreateDtlsTransport( | 133 transport_controller_->CreateDtlsTransport( |
141 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 134 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
142 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 135 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
143 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 136 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
144 rtc::Thread::Current(), cricket::CN_AUDIO, nullptr, | 137 rtc::Thread::Current(), cricket::CN_AUDIO, kDefaultSrtpRequired, |
145 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, AudioOptions()); | 138 AudioOptions()); |
146 EXPECT_TRUE(voice_channel != nullptr); | 139 EXPECT_TRUE(voice_channel != nullptr); |
147 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 140 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
148 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 141 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
149 rtc::Thread::Current(), cricket::CN_VIDEO, nullptr, | 142 rtc::Thread::Current(), cricket::CN_VIDEO, kDefaultSrtpRequired, |
150 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, VideoOptions()); | 143 VideoOptions()); |
151 EXPECT_TRUE(video_channel != nullptr); | 144 EXPECT_TRUE(video_channel != nullptr); |
152 cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel( | 145 cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel( |
153 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, | 146 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, |
154 rtc::Thread::Current(), cricket::CN_DATA, nullptr, | 147 rtc::Thread::Current(), cricket::CN_DATA, kDefaultSrtpRequired); |
155 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); | |
156 EXPECT_TRUE(rtp_data_channel != nullptr); | 148 EXPECT_TRUE(rtp_data_channel != nullptr); |
157 cm_->DestroyVideoChannel(video_channel); | 149 cm_->DestroyVideoChannel(video_channel); |
158 cm_->DestroyVoiceChannel(voice_channel); | 150 cm_->DestroyVoiceChannel(voice_channel); |
159 cm_->DestroyRtpDataChannel(rtp_data_channel); | 151 cm_->DestroyRtpDataChannel(rtp_data_channel); |
160 cm_->Terminate(); | 152 cm_->Terminate(); |
161 } | 153 } |
162 | 154 |
163 TEST_F(ChannelManagerTest, SetVideoRtxEnabled) { | 155 TEST_F(ChannelManagerTest, SetVideoRtxEnabled) { |
164 std::vector<VideoCodec> codecs; | 156 std::vector<VideoCodec> codecs; |
165 const VideoCodec rtx_codec(96, "rtx"); | 157 const VideoCodec rtx_codec(96, "rtx"); |
(...skipping 18 matching lines...) Expand all Loading... |
184 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); | 176 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
185 | 177 |
186 // Can set again after terminate. | 178 // Can set again after terminate. |
187 cm_->Terminate(); | 179 cm_->Terminate(); |
188 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); | 180 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
189 cm_->GetSupportedVideoCodecs(&codecs); | 181 cm_->GetSupportedVideoCodecs(&codecs); |
190 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); | 182 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
191 } | 183 } |
192 | 184 |
193 } // namespace cricket | 185 } // namespace cricket |
OLD | NEW |