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 12 matching lines...) Expand all Loading... |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/media/base/fakecapturemanager.h" | 28 #include "talk/media/base/fakecapturemanager.h" |
29 #include "talk/media/base/fakemediaengine.h" | 29 #include "talk/media/base/fakemediaengine.h" |
30 #include "talk/media/base/fakemediaprocessor.h" | 30 #include "talk/media/base/fakemediaprocessor.h" |
31 #include "talk/media/base/testutils.h" | 31 #include "talk/media/base/testutils.h" |
32 #include "talk/media/devices/fakedevicemanager.h" | 32 #include "talk/media/devices/fakedevicemanager.h" |
33 #include "webrtc/p2p/base/fakesession.h" | |
34 #include "talk/session/media/channelmanager.h" | 33 #include "talk/session/media/channelmanager.h" |
35 #include "webrtc/base/gunit.h" | 34 #include "webrtc/base/gunit.h" |
36 #include "webrtc/base/logging.h" | 35 #include "webrtc/base/logging.h" |
37 #include "webrtc/base/thread.h" | 36 #include "webrtc/base/thread.h" |
| 37 #include "webrtc/p2p/base/faketransportcontroller.h" |
38 | 38 |
39 namespace cricket { | 39 namespace cricket { |
40 | 40 |
41 static const AudioCodec kAudioCodecs[] = { | 41 static const AudioCodec kAudioCodecs[] = { |
42 AudioCodec(97, "voice", 1, 2, 3, 0), | 42 AudioCodec(97, "voice", 1, 2, 3, 0), |
43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), | 43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), |
44 }; | 44 }; |
45 | 45 |
46 static const VideoCodec kVideoCodecs[] = { | 46 static const VideoCodec kVideoCodecs[] = { |
47 VideoCodec(99, "H264", 100, 200, 300, 0), | 47 VideoCodec(99, "H264", 100, 200, 300, 0), |
48 VideoCodec(100, "VP8", 100, 200, 300, 0), | 48 VideoCodec(100, "VP8", 100, 200, 300, 0), |
49 VideoCodec(96, "rtx", 100, 200, 300, 0), | 49 VideoCodec(96, "rtx", 100, 200, 300, 0), |
50 }; | 50 }; |
51 | 51 |
52 class ChannelManagerTest : public testing::Test { | 52 class ChannelManagerTest : public testing::Test { |
53 protected: | 53 protected: |
54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) { | 54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) { |
55 } | 55 } |
56 | 56 |
57 virtual void SetUp() { | 57 virtual void SetUp() { |
58 fme_ = new cricket::FakeMediaEngine(); | 58 fme_ = new cricket::FakeMediaEngine(); |
59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); | 59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); | 60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
61 fdme_ = new cricket::FakeDataEngine(); | 61 fdme_ = new cricket::FakeDataEngine(); |
62 fdm_ = new cricket::FakeDeviceManager(); | 62 fdm_ = new cricket::FakeDeviceManager(); |
63 fcm_ = new cricket::FakeCaptureManager(); | 63 fcm_ = new cricket::FakeCaptureManager(); |
64 cm_ = new cricket::ChannelManager( | 64 cm_ = new cricket::ChannelManager( |
65 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); | 65 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); |
66 session_ = new cricket::FakeSession(true); | 66 transport_controller_ = new cricket::FakeTransportController(true); |
67 | 67 |
68 std::vector<std::string> in_device_list, out_device_list, vid_device_list; | 68 std::vector<std::string> in_device_list, out_device_list, vid_device_list; |
69 in_device_list.push_back("audio-in1"); | 69 in_device_list.push_back("audio-in1"); |
70 in_device_list.push_back("audio-in2"); | 70 in_device_list.push_back("audio-in2"); |
71 out_device_list.push_back("audio-out1"); | 71 out_device_list.push_back("audio-out1"); |
72 out_device_list.push_back("audio-out2"); | 72 out_device_list.push_back("audio-out2"); |
73 vid_device_list.push_back("video-in1"); | 73 vid_device_list.push_back("video-in1"); |
74 vid_device_list.push_back("video-in2"); | 74 vid_device_list.push_back("video-in2"); |
75 fdm_->SetAudioInputDevices(in_device_list); | 75 fdm_->SetAudioInputDevices(in_device_list); |
76 fdm_->SetAudioOutputDevices(out_device_list); | 76 fdm_->SetAudioOutputDevices(out_device_list); |
77 fdm_->SetVideoCaptureDevices(vid_device_list); | 77 fdm_->SetVideoCaptureDevices(vid_device_list); |
78 } | 78 } |
79 | 79 |
80 virtual void TearDown() { | 80 virtual void TearDown() { |
81 delete session_; | 81 delete transport_controller_; |
82 delete cm_; | 82 delete cm_; |
83 cm_ = NULL; | 83 cm_ = NULL; |
84 fdm_ = NULL; | 84 fdm_ = NULL; |
85 fcm_ = NULL; | 85 fcm_ = NULL; |
86 fdme_ = NULL; | 86 fdme_ = NULL; |
87 fme_ = NULL; | 87 fme_ = NULL; |
88 } | 88 } |
89 | 89 |
90 rtc::Thread worker_; | 90 rtc::Thread worker_; |
91 cricket::FakeMediaEngine* fme_; | 91 cricket::FakeMediaEngine* fme_; |
92 cricket::FakeDataEngine* fdme_; | 92 cricket::FakeDataEngine* fdme_; |
93 cricket::FakeDeviceManager* fdm_; | 93 cricket::FakeDeviceManager* fdm_; |
94 cricket::FakeCaptureManager* fcm_; | 94 cricket::FakeCaptureManager* fcm_; |
95 cricket::ChannelManager* cm_; | 95 cricket::ChannelManager* cm_; |
96 cricket::FakeSession* session_; | 96 cricket::FakeTransportController* transport_controller_; |
97 }; | 97 }; |
98 | 98 |
99 // Test that we startup/shutdown properly. | 99 // Test that we startup/shutdown properly. |
100 TEST_F(ChannelManagerTest, StartupShutdown) { | 100 TEST_F(ChannelManagerTest, StartupShutdown) { |
101 EXPECT_FALSE(cm_->initialized()); | 101 EXPECT_FALSE(cm_->initialized()); |
102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); | 102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
103 EXPECT_TRUE(cm_->Init()); | 103 EXPECT_TRUE(cm_->Init()); |
104 EXPECT_TRUE(cm_->initialized()); | 104 EXPECT_TRUE(cm_->initialized()); |
105 cm_->Terminate(); | 105 cm_->Terminate(); |
106 EXPECT_FALSE(cm_->initialized()); | 106 EXPECT_FALSE(cm_->initialized()); |
(...skipping 11 matching lines...) Expand all Loading... |
118 // Setting the worker thread while initialized should fail. | 118 // Setting the worker thread while initialized should fail. |
119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); | 119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); |
120 cm_->Terminate(); | 120 cm_->Terminate(); |
121 EXPECT_FALSE(cm_->initialized()); | 121 EXPECT_FALSE(cm_->initialized()); |
122 } | 122 } |
123 | 123 |
124 // Test that we can create and destroy a voice and video channel. | 124 // Test that we can create and destroy a voice and video channel. |
125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { | 125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
126 EXPECT_TRUE(cm_->Init()); | 126 EXPECT_TRUE(cm_->Init()); |
127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
128 session_, cricket::CN_AUDIO, false, AudioOptions()); | 128 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
129 EXPECT_TRUE(voice_channel != nullptr); | 129 EXPECT_TRUE(voice_channel != nullptr); |
130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
131 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 131 transport_controller_, cricket::CN_VIDEO, false, VideoOptions(), |
| 132 voice_channel); |
132 EXPECT_TRUE(video_channel != nullptr); | 133 EXPECT_TRUE(video_channel != nullptr); |
133 cricket::DataChannel* data_channel = | 134 cricket::DataChannel* data_channel = |
134 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 135 cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, |
135 false, cricket::DCT_RTP); | 136 false, cricket::DCT_RTP); |
136 EXPECT_TRUE(data_channel != nullptr); | 137 EXPECT_TRUE(data_channel != nullptr); |
137 cm_->DestroyVideoChannel(video_channel); | 138 cm_->DestroyVideoChannel(video_channel); |
138 cm_->DestroyVoiceChannel(voice_channel, nullptr); | 139 cm_->DestroyVoiceChannel(voice_channel, nullptr); |
139 cm_->DestroyDataChannel(data_channel); | 140 cm_->DestroyDataChannel(data_channel); |
140 cm_->Terminate(); | 141 cm_->Terminate(); |
141 } | 142 } |
142 | 143 |
143 // Test that we can create and destroy a voice and video channel with a worker. | 144 // Test that we can create and destroy a voice and video channel with a worker. |
144 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { | 145 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
145 worker_.Start(); | 146 worker_.Start(); |
146 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); | 147 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
147 EXPECT_TRUE(cm_->Init()); | 148 EXPECT_TRUE(cm_->Init()); |
148 delete session_; | 149 delete transport_controller_; |
149 session_ = new cricket::FakeSession(&worker_, true); | 150 transport_controller_ = new cricket::FakeTransportController(&worker_, true); |
150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 151 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
151 session_, cricket::CN_AUDIO, false, AudioOptions()); | 152 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
152 EXPECT_TRUE(voice_channel != nullptr); | 153 EXPECT_TRUE(voice_channel != nullptr); |
153 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 154 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
154 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 155 transport_controller_, cricket::CN_VIDEO, false, VideoOptions(), |
| 156 voice_channel); |
155 EXPECT_TRUE(video_channel != nullptr); | 157 EXPECT_TRUE(video_channel != nullptr); |
156 cricket::DataChannel* data_channel = | 158 cricket::DataChannel* data_channel = |
157 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 159 cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, |
158 false, cricket::DCT_RTP); | 160 false, cricket::DCT_RTP); |
159 EXPECT_TRUE(data_channel != nullptr); | 161 EXPECT_TRUE(data_channel != nullptr); |
160 cm_->DestroyVideoChannel(video_channel); | 162 cm_->DestroyVideoChannel(video_channel); |
161 cm_->DestroyVoiceChannel(voice_channel, nullptr); | 163 cm_->DestroyVoiceChannel(voice_channel, nullptr); |
162 cm_->DestroyDataChannel(data_channel); | 164 cm_->DestroyDataChannel(data_channel); |
163 cm_->Terminate(); | 165 cm_->Terminate(); |
164 } | 166 } |
165 | 167 |
166 // Test that we fail to create a voice/video channel if the session is unable | 168 // Test that we fail to create a voice/video channel if the session is unable |
167 // to create a cricket::TransportChannel | 169 // to create a cricket::TransportChannel |
168 TEST_F(ChannelManagerTest, NoTransportChannelTest) { | 170 TEST_F(ChannelManagerTest, NoTransportChannelTest) { |
169 EXPECT_TRUE(cm_->Init()); | 171 EXPECT_TRUE(cm_->Init()); |
170 session_->set_fail_channel_creation(true); | 172 transport_controller_->set_fail_channel_creation(true); |
171 // The test is useless unless the session does not fail creating | 173 // The test is useless unless the session does not fail creating |
172 // cricket::TransportChannel. | 174 // cricket::TransportChannel. |
173 ASSERT_TRUE(session_->CreateChannel( | 175 ASSERT_TRUE(transport_controller_->CreateTransportChannel_w( |
174 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); | 176 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); |
175 | 177 |
176 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 178 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
177 session_, cricket::CN_AUDIO, false, AudioOptions()); | 179 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
178 EXPECT_TRUE(voice_channel == nullptr); | 180 EXPECT_TRUE(voice_channel == nullptr); |
179 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 181 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( |
180 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 182 transport_controller_, cricket::CN_VIDEO, false, VideoOptions(), |
| 183 voice_channel); |
181 EXPECT_TRUE(video_channel == nullptr); | 184 EXPECT_TRUE(video_channel == nullptr); |
182 cricket::DataChannel* data_channel = | 185 cricket::DataChannel* data_channel = |
183 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 186 cm_->CreateDataChannel(transport_controller_, cricket::CN_DATA, |
184 false, cricket::DCT_RTP); | 187 false, cricket::DCT_RTP); |
185 EXPECT_TRUE(data_channel == nullptr); | 188 EXPECT_TRUE(data_channel == nullptr); |
186 cm_->Terminate(); | 189 cm_->Terminate(); |
187 } | 190 } |
188 | 191 |
189 // Test that SetDefaultVideoCodec passes through the right values. | 192 // Test that SetDefaultVideoCodec passes through the right values. |
190 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { | 193 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { |
191 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); | 194 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); |
192 cricket::VideoEncoderConfig config(codec, 1, 2); | 195 cricket::VideoEncoderConfig config(codec, 1, 2); |
193 EXPECT_TRUE(cm_->Init()); | 196 EXPECT_TRUE(cm_->Init()); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); | 580 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
578 | 581 |
579 // Can set again after terminate. | 582 // Can set again after terminate. |
580 cm_->Terminate(); | 583 cm_->Terminate(); |
581 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); | 584 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
582 cm_->GetSupportedVideoCodecs(&codecs); | 585 cm_->GetSupportedVideoCodecs(&codecs); |
583 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); | 586 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
584 } | 587 } |
585 | 588 |
586 } // namespace cricket | 589 } // namespace cricket |
OLD | NEW |