OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2008 Google Inc. | 3 * Copyright 2008 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 14 matching lines...) Expand all Loading... |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/app/webrtc/mediacontroller.h" | 28 #include "talk/app/webrtc/mediacontroller.h" |
29 #include "talk/media/base/fakecapturemanager.h" | 29 #include "talk/media/base/fakecapturemanager.h" |
30 #include "talk/media/base/fakemediaengine.h" | 30 #include "talk/media/base/fakemediaengine.h" |
31 #include "talk/media/base/fakemediaprocessor.h" | 31 #include "talk/media/base/fakemediaprocessor.h" |
32 #include "talk/media/base/testutils.h" | 32 #include "talk/media/base/testutils.h" |
33 #include "talk/media/devices/fakedevicemanager.h" | 33 #include "talk/media/devices/fakedevicemanager.h" |
34 #include "talk/media/webrtc/fakewebrtccall.h" | 34 #include "talk/media/webrtc/fakewebrtccall.h" |
| 35 #include "webrtc/p2p/base/fakesession.h" |
35 #include "talk/session/media/channelmanager.h" | 36 #include "talk/session/media/channelmanager.h" |
36 #include "webrtc/base/gunit.h" | 37 #include "webrtc/base/gunit.h" |
37 #include "webrtc/base/logging.h" | 38 #include "webrtc/base/logging.h" |
38 #include "webrtc/base/thread.h" | 39 #include "webrtc/base/thread.h" |
39 #include "webrtc/p2p/base/faketransportcontroller.h" | |
40 | 40 |
41 namespace cricket { | 41 namespace cricket { |
42 | 42 |
43 static const AudioCodec kAudioCodecs[] = { | 43 static const AudioCodec kAudioCodecs[] = { |
44 AudioCodec(97, "voice", 1, 2, 3, 0), | 44 AudioCodec(97, "voice", 1, 2, 3, 0), |
45 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), | 45 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), |
46 }; | 46 }; |
47 | 47 |
48 static const VideoCodec kVideoCodecs[] = { | 48 static const VideoCodec kVideoCodecs[] = { |
49 VideoCodec(99, "H264", 100, 200, 300, 0), | 49 VideoCodec(99, "H264", 100, 200, 300, 0), |
50 VideoCodec(100, "VP8", 100, 200, 300, 0), | 50 VideoCodec(100, "VP8", 100, 200, 300, 0), |
51 VideoCodec(96, "rtx", 100, 200, 300, 0), | 51 VideoCodec(96, "rtx", 100, 200, 300, 0), |
52 }; | 52 }; |
53 | 53 |
54 class FakeMediaController : public webrtc::MediaControllerInterface { | 54 class FakeMediaController : public webrtc::MediaControllerInterface { |
55 public: | 55 public: |
56 explicit FakeMediaController(webrtc::Call* call) : call_(call) { | 56 explicit FakeMediaController(webrtc::Call* call) : call_(call) { |
57 RTC_DCHECK(nullptr != call); | 57 RTC_DCHECK(nullptr != call); |
58 } | 58 } |
59 ~FakeMediaController() override {} | 59 ~FakeMediaController() override {} |
60 webrtc::Call* call_w() override { return call_; } | 60 webrtc::Call* call_w() override { return call_; } |
61 | |
62 private: | 61 private: |
63 webrtc::Call* call_; | 62 webrtc::Call* call_; |
64 }; | 63 }; |
65 | 64 |
66 class ChannelManagerTest : public testing::Test { | 65 class ChannelManagerTest : public testing::Test { |
67 protected: | 66 protected: |
68 ChannelManagerTest() | 67 ChannelManagerTest() : fake_call_(webrtc::Call::Config()), |
69 : fake_call_(webrtc::Call::Config()), | 68 fake_mc_(&fake_call_), fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {} |
70 fake_mc_(&fake_call_), | |
71 fme_(NULL), | |
72 fdm_(NULL), | |
73 fcm_(NULL), | |
74 cm_(NULL) {} | |
75 | 69 |
76 virtual void SetUp() { | 70 virtual void SetUp() { |
77 fme_ = new cricket::FakeMediaEngine(); | 71 fme_ = new cricket::FakeMediaEngine(); |
78 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); | 72 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
79 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); | 73 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
80 fdme_ = new cricket::FakeDataEngine(); | 74 fdme_ = new cricket::FakeDataEngine(); |
81 fdm_ = new cricket::FakeDeviceManager(); | 75 fdm_ = new cricket::FakeDeviceManager(); |
82 fcm_ = new cricket::FakeCaptureManager(); | 76 fcm_ = new cricket::FakeCaptureManager(); |
83 cm_ = new cricket::ChannelManager( | 77 cm_ = new cricket::ChannelManager( |
84 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); | 78 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); |
85 transport_controller_ = | 79 session_ = new cricket::FakeSession(true); |
86 new cricket::FakeTransportController(ICEROLE_CONTROLLING); | |
87 | 80 |
88 std::vector<std::string> in_device_list, out_device_list, vid_device_list; | 81 std::vector<std::string> in_device_list, out_device_list, vid_device_list; |
89 in_device_list.push_back("audio-in1"); | 82 in_device_list.push_back("audio-in1"); |
90 in_device_list.push_back("audio-in2"); | 83 in_device_list.push_back("audio-in2"); |
91 out_device_list.push_back("audio-out1"); | 84 out_device_list.push_back("audio-out1"); |
92 out_device_list.push_back("audio-out2"); | 85 out_device_list.push_back("audio-out2"); |
93 vid_device_list.push_back("video-in1"); | 86 vid_device_list.push_back("video-in1"); |
94 vid_device_list.push_back("video-in2"); | 87 vid_device_list.push_back("video-in2"); |
95 fdm_->SetAudioInputDevices(in_device_list); | 88 fdm_->SetAudioInputDevices(in_device_list); |
96 fdm_->SetAudioOutputDevices(out_device_list); | 89 fdm_->SetAudioOutputDevices(out_device_list); |
97 fdm_->SetVideoCaptureDevices(vid_device_list); | 90 fdm_->SetVideoCaptureDevices(vid_device_list); |
98 } | 91 } |
99 | 92 |
100 virtual void TearDown() { | 93 virtual void TearDown() { |
101 delete transport_controller_; | 94 delete session_; |
102 delete cm_; | 95 delete cm_; |
103 cm_ = NULL; | 96 cm_ = NULL; |
104 fdm_ = NULL; | 97 fdm_ = NULL; |
105 fcm_ = NULL; | 98 fcm_ = NULL; |
106 fdme_ = NULL; | 99 fdme_ = NULL; |
107 fme_ = NULL; | 100 fme_ = NULL; |
108 } | 101 } |
109 | 102 |
110 rtc::Thread worker_; | 103 rtc::Thread worker_; |
111 cricket::FakeCall fake_call_; | 104 cricket::FakeCall fake_call_; |
112 cricket::FakeMediaController fake_mc_; | 105 cricket::FakeMediaController fake_mc_; |
113 cricket::FakeMediaEngine* fme_; | 106 cricket::FakeMediaEngine* fme_; |
114 cricket::FakeDataEngine* fdme_; | 107 cricket::FakeDataEngine* fdme_; |
115 cricket::FakeDeviceManager* fdm_; | 108 cricket::FakeDeviceManager* fdm_; |
116 cricket::FakeCaptureManager* fcm_; | 109 cricket::FakeCaptureManager* fcm_; |
117 cricket::ChannelManager* cm_; | 110 cricket::ChannelManager* cm_; |
118 cricket::FakeTransportController* transport_controller_; | 111 cricket::FakeSession* session_; |
119 }; | 112 }; |
120 | 113 |
121 // Test that we startup/shutdown properly. | 114 // Test that we startup/shutdown properly. |
122 TEST_F(ChannelManagerTest, StartupShutdown) { | 115 TEST_F(ChannelManagerTest, StartupShutdown) { |
123 EXPECT_FALSE(cm_->initialized()); | 116 EXPECT_FALSE(cm_->initialized()); |
124 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); | 117 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
125 EXPECT_TRUE(cm_->Init()); | 118 EXPECT_TRUE(cm_->Init()); |
126 EXPECT_TRUE(cm_->initialized()); | 119 EXPECT_TRUE(cm_->initialized()); |
127 cm_->Terminate(); | 120 cm_->Terminate(); |
128 EXPECT_FALSE(cm_->initialized()); | 121 EXPECT_FALSE(cm_->initialized()); |
(...skipping 10 matching lines...) Expand all Loading... |
139 EXPECT_TRUE(cm_->initialized()); | 132 EXPECT_TRUE(cm_->initialized()); |
140 // Setting the worker thread while initialized should fail. | 133 // Setting the worker thread while initialized should fail. |
141 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); | 134 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); |
142 cm_->Terminate(); | 135 cm_->Terminate(); |
143 EXPECT_FALSE(cm_->initialized()); | 136 EXPECT_FALSE(cm_->initialized()); |
144 } | 137 } |
145 | 138 |
146 // Test that we can create and destroy a voice and video channel. | 139 // Test that we can create and destroy a voice and video channel. |
147 TEST_F(ChannelManagerTest, CreateDestroyChannels) { | 140 TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
148 EXPECT_TRUE(cm_->Init()); | 141 EXPECT_TRUE(cm_->Init()); |
149 cricket::VoiceChannel* voice_channel = | 142 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
150 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, | 143 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); |
151 cricket::CN_AUDIO, false, AudioOptions()); | |
152 EXPECT_TRUE(voice_channel != nullptr); | 144 EXPECT_TRUE(voice_channel != nullptr); |
153 cricket::VideoChannel* video_channel = | 145 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
154 cm_->CreateVideoChannel(&fake_mc_, transport_controller_, | 146 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); |
155 cricket::CN_VIDEO, false, VideoOptions()); | |
156 EXPECT_TRUE(video_channel != nullptr); | 147 EXPECT_TRUE(video_channel != nullptr); |
157 cricket::DataChannel* data_channel = cm_->CreateDataChannel( | 148 cricket::DataChannel* data_channel = |
158 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); | 149 cm_->CreateDataChannel(session_, cricket::CN_DATA, |
| 150 false, cricket::DCT_RTP); |
159 EXPECT_TRUE(data_channel != nullptr); | 151 EXPECT_TRUE(data_channel != nullptr); |
160 cm_->DestroyVideoChannel(video_channel); | 152 cm_->DestroyVideoChannel(video_channel); |
161 cm_->DestroyVoiceChannel(voice_channel); | 153 cm_->DestroyVoiceChannel(voice_channel); |
162 cm_->DestroyDataChannel(data_channel); | 154 cm_->DestroyDataChannel(data_channel); |
163 cm_->Terminate(); | 155 cm_->Terminate(); |
164 } | 156 } |
165 | 157 |
166 // Test that we can create and destroy a voice and video channel with a worker. | 158 // Test that we can create and destroy a voice and video channel with a worker. |
167 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { | 159 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
168 worker_.Start(); | 160 worker_.Start(); |
169 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); | 161 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
170 EXPECT_TRUE(cm_->Init()); | 162 EXPECT_TRUE(cm_->Init()); |
171 delete transport_controller_; | 163 delete session_; |
172 transport_controller_ = | 164 session_ = new cricket::FakeSession(&worker_, true); |
173 new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING); | 165 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
174 cricket::VoiceChannel* voice_channel = | 166 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); |
175 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, | |
176 cricket::CN_AUDIO, false, AudioOptions()); | |
177 EXPECT_TRUE(voice_channel != nullptr); | 167 EXPECT_TRUE(voice_channel != nullptr); |
178 cricket::VideoChannel* video_channel = | 168 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
179 cm_->CreateVideoChannel(&fake_mc_, transport_controller_, | 169 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); |
180 cricket::CN_VIDEO, false, VideoOptions()); | |
181 EXPECT_TRUE(video_channel != nullptr); | 170 EXPECT_TRUE(video_channel != nullptr); |
182 cricket::DataChannel* data_channel = cm_->CreateDataChannel( | 171 cricket::DataChannel* data_channel = |
183 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); | 172 cm_->CreateDataChannel(session_, cricket::CN_DATA, |
| 173 false, cricket::DCT_RTP); |
184 EXPECT_TRUE(data_channel != nullptr); | 174 EXPECT_TRUE(data_channel != nullptr); |
185 cm_->DestroyVideoChannel(video_channel); | 175 cm_->DestroyVideoChannel(video_channel); |
186 cm_->DestroyVoiceChannel(voice_channel); | 176 cm_->DestroyVoiceChannel(voice_channel); |
187 cm_->DestroyDataChannel(data_channel); | 177 cm_->DestroyDataChannel(data_channel); |
188 cm_->Terminate(); | 178 cm_->Terminate(); |
189 } | 179 } |
190 | 180 |
191 // Test that we fail to create a voice/video channel if the session is unable | 181 // Test that we fail to create a voice/video channel if the session is unable |
192 // to create a cricket::TransportChannel | 182 // to create a cricket::TransportChannel |
193 TEST_F(ChannelManagerTest, NoTransportChannelTest) { | 183 TEST_F(ChannelManagerTest, NoTransportChannelTest) { |
194 EXPECT_TRUE(cm_->Init()); | 184 EXPECT_TRUE(cm_->Init()); |
195 transport_controller_->set_fail_channel_creation(true); | 185 session_->set_fail_channel_creation(true); |
196 // The test is useless unless the session does not fail creating | 186 // The test is useless unless the session does not fail creating |
197 // cricket::TransportChannel. | 187 // cricket::TransportChannel. |
198 ASSERT_TRUE(transport_controller_->CreateTransportChannel_w( | 188 ASSERT_TRUE(session_->CreateChannel( |
199 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); | 189 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); |
200 | 190 |
201 cricket::VoiceChannel* voice_channel = | 191 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
202 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_, | 192 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); |
203 cricket::CN_AUDIO, false, AudioOptions()); | |
204 EXPECT_TRUE(voice_channel == nullptr); | 193 EXPECT_TRUE(voice_channel == nullptr); |
205 cricket::VideoChannel* video_channel = | 194 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
206 cm_->CreateVideoChannel(&fake_mc_, transport_controller_, | 195 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); |
207 cricket::CN_VIDEO, false, VideoOptions()); | |
208 EXPECT_TRUE(video_channel == nullptr); | 196 EXPECT_TRUE(video_channel == nullptr); |
209 cricket::DataChannel* data_channel = cm_->CreateDataChannel( | 197 cricket::DataChannel* data_channel = |
210 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); | 198 cm_->CreateDataChannel(session_, cricket::CN_DATA, |
| 199 false, cricket::DCT_RTP); |
211 EXPECT_TRUE(data_channel == nullptr); | 200 EXPECT_TRUE(data_channel == nullptr); |
212 cm_->Terminate(); | 201 cm_->Terminate(); |
213 } | 202 } |
214 | 203 |
215 // Test that SetDefaultVideoCodec passes through the right values. | 204 // Test that SetDefaultVideoCodec passes through the right values. |
216 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { | 205 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { |
217 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); | 206 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); |
218 cricket::VideoEncoderConfig config(codec, 1, 2); | 207 cricket::VideoEncoderConfig config(codec, 1, 2); |
219 EXPECT_TRUE(cm_->Init()); | 208 EXPECT_TRUE(cm_->Init()); |
220 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); | 209 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); | 592 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
604 | 593 |
605 // Can set again after terminate. | 594 // Can set again after terminate. |
606 cm_->Terminate(); | 595 cm_->Terminate(); |
607 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); | 596 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
608 cm_->GetSupportedVideoCodecs(&codecs); | 597 cm_->GetSupportedVideoCodecs(&codecs); |
609 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); | 598 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
610 } | 599 } |
611 | 600 |
612 } // namespace cricket | 601 } // namespace cricket |
OLD | NEW |