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