Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: talk/session/media/channelmanager_unittest.cc

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More renaming, formatting and other polish Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_ =
67 new cricket::FakeTransportController(ICEROLE_CONTROLLING);
67 68
68 std::vector<std::string> in_device_list, out_device_list, vid_device_list; 69 std::vector<std::string> in_device_list, out_device_list, vid_device_list;
69 in_device_list.push_back("audio-in1"); 70 in_device_list.push_back("audio-in1");
70 in_device_list.push_back("audio-in2"); 71 in_device_list.push_back("audio-in2");
71 out_device_list.push_back("audio-out1"); 72 out_device_list.push_back("audio-out1");
72 out_device_list.push_back("audio-out2"); 73 out_device_list.push_back("audio-out2");
73 vid_device_list.push_back("video-in1"); 74 vid_device_list.push_back("video-in1");
74 vid_device_list.push_back("video-in2"); 75 vid_device_list.push_back("video-in2");
75 fdm_->SetAudioInputDevices(in_device_list); 76 fdm_->SetAudioInputDevices(in_device_list);
76 fdm_->SetAudioOutputDevices(out_device_list); 77 fdm_->SetAudioOutputDevices(out_device_list);
77 fdm_->SetVideoCaptureDevices(vid_device_list); 78 fdm_->SetVideoCaptureDevices(vid_device_list);
78 } 79 }
79 80
80 virtual void TearDown() { 81 virtual void TearDown() {
81 delete session_; 82 delete transport_controller_;
82 delete cm_; 83 delete cm_;
83 cm_ = NULL; 84 cm_ = NULL;
84 fdm_ = NULL; 85 fdm_ = NULL;
85 fcm_ = NULL; 86 fcm_ = NULL;
86 fdme_ = NULL; 87 fdme_ = NULL;
87 fme_ = NULL; 88 fme_ = NULL;
88 } 89 }
89 90
90 rtc::Thread worker_; 91 rtc::Thread worker_;
91 cricket::FakeMediaEngine* fme_; 92 cricket::FakeMediaEngine* fme_;
92 cricket::FakeDataEngine* fdme_; 93 cricket::FakeDataEngine* fdme_;
93 cricket::FakeDeviceManager* fdm_; 94 cricket::FakeDeviceManager* fdm_;
94 cricket::FakeCaptureManager* fcm_; 95 cricket::FakeCaptureManager* fcm_;
95 cricket::ChannelManager* cm_; 96 cricket::ChannelManager* cm_;
96 cricket::FakeSession* session_; 97 cricket::FakeTransportController* transport_controller_;
97 }; 98 };
98 99
99 // Test that we startup/shutdown properly. 100 // Test that we startup/shutdown properly.
100 TEST_F(ChannelManagerTest, StartupShutdown) { 101 TEST_F(ChannelManagerTest, StartupShutdown) {
101 EXPECT_FALSE(cm_->initialized()); 102 EXPECT_FALSE(cm_->initialized());
102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); 103 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
103 EXPECT_TRUE(cm_->Init()); 104 EXPECT_TRUE(cm_->Init());
104 EXPECT_TRUE(cm_->initialized()); 105 EXPECT_TRUE(cm_->initialized());
105 cm_->Terminate(); 106 cm_->Terminate();
106 EXPECT_FALSE(cm_->initialized()); 107 EXPECT_FALSE(cm_->initialized());
(...skipping 11 matching lines...) Expand all
118 // Setting the worker thread while initialized should fail. 119 // Setting the worker thread while initialized should fail.
119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); 120 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
120 cm_->Terminate(); 121 cm_->Terminate();
121 EXPECT_FALSE(cm_->initialized()); 122 EXPECT_FALSE(cm_->initialized());
122 } 123 }
123 124
124 // Test that we can create and destroy a voice and video channel. 125 // Test that we can create and destroy a voice and video channel.
125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { 126 TEST_F(ChannelManagerTest, CreateDestroyChannels) {
126 EXPECT_TRUE(cm_->Init()); 127 EXPECT_TRUE(cm_->Init());
127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 128 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
128 session_, cricket::CN_AUDIO, false, AudioOptions()); 129 transport_controller_, cricket::CN_AUDIO, false, AudioOptions());
129 EXPECT_TRUE(voice_channel != nullptr); 130 EXPECT_TRUE(voice_channel != nullptr);
130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 131 cricket::VideoChannel* video_channel =
131 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 132 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false,
133 VideoOptions(), voice_channel);
132 EXPECT_TRUE(video_channel != nullptr); 134 EXPECT_TRUE(video_channel != nullptr);
133 cricket::DataChannel* data_channel = 135 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
134 cm_->CreateDataChannel(session_, cricket::CN_DATA, 136 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
135 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_ =
151 new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING);
150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 152 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
151 session_, cricket::CN_AUDIO, false, AudioOptions()); 153 transport_controller_, cricket::CN_AUDIO, false, AudioOptions());
152 EXPECT_TRUE(voice_channel != nullptr); 154 EXPECT_TRUE(voice_channel != nullptr);
153 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 155 cricket::VideoChannel* video_channel =
154 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 156 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false,
157 VideoOptions(), voice_channel);
155 EXPECT_TRUE(video_channel != nullptr); 158 EXPECT_TRUE(video_channel != nullptr);
156 cricket::DataChannel* data_channel = 159 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
157 cm_->CreateDataChannel(session_, cricket::CN_DATA, 160 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
158 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 =
180 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 182 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false,
183 VideoOptions(), voice_channel);
181 EXPECT_TRUE(video_channel == nullptr); 184 EXPECT_TRUE(video_channel == nullptr);
182 cricket::DataChannel* data_channel = 185 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
183 cm_->CreateDataChannel(session_, cricket::CN_DATA, 186 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
184 false, cricket::DCT_RTP);
185 EXPECT_TRUE(data_channel == nullptr); 187 EXPECT_TRUE(data_channel == nullptr);
186 cm_->Terminate(); 188 cm_->Terminate();
187 } 189 }
188 190
189 // Test that SetDefaultVideoCodec passes through the right values. 191 // Test that SetDefaultVideoCodec passes through the right values.
190 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { 192 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
191 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); 193 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
192 cricket::VideoEncoderConfig config(codec, 1, 2); 194 cricket::VideoEncoderConfig config(codec, 1, 2);
193 EXPECT_TRUE(cm_->Init()); 195 EXPECT_TRUE(cm_->Init());
194 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); 196 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); 579 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
578 580
579 // Can set again after terminate. 581 // Can set again after terminate.
580 cm_->Terminate(); 582 cm_->Terminate();
581 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); 583 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
582 cm_->GetSupportedVideoCodecs(&codecs); 584 cm_->GetSupportedVideoCodecs(&codecs);
583 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); 585 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
584 } 586 }
585 587
586 } // namespace cricket 588 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698