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

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

Issue 1350523003: TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Mac test. 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
« no previous file with comments | « talk/session/media/channelmanager.cc ('k') | webrtc/base/fakenetwork.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
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"
36 #include "talk/session/media/channelmanager.h" 35 #include "talk/session/media/channelmanager.h"
37 #include "webrtc/base/gunit.h" 36 #include "webrtc/base/gunit.h"
38 #include "webrtc/base/logging.h" 37 #include "webrtc/base/logging.h"
39 #include "webrtc/base/thread.h" 38 #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
61 private: 62 private:
62 webrtc::Call* call_; 63 webrtc::Call* call_;
63 }; 64 };
64 65
65 class ChannelManagerTest : public testing::Test { 66 class ChannelManagerTest : public testing::Test {
66 protected: 67 protected:
67 ChannelManagerTest() : fake_call_(webrtc::Call::Config()), 68 ChannelManagerTest()
68 fake_mc_(&fake_call_), fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {} 69 : fake_call_(webrtc::Call::Config()),
70 fake_mc_(&fake_call_),
71 fme_(NULL),
72 fdm_(NULL),
73 fcm_(NULL),
74 cm_(NULL) {}
69 75
70 virtual void SetUp() { 76 virtual void SetUp() {
71 fme_ = new cricket::FakeMediaEngine(); 77 fme_ = new cricket::FakeMediaEngine();
72 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); 78 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
73 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); 79 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
74 fdme_ = new cricket::FakeDataEngine(); 80 fdme_ = new cricket::FakeDataEngine();
75 fdm_ = new cricket::FakeDeviceManager(); 81 fdm_ = new cricket::FakeDeviceManager();
76 fcm_ = new cricket::FakeCaptureManager(); 82 fcm_ = new cricket::FakeCaptureManager();
77 cm_ = new cricket::ChannelManager( 83 cm_ = new cricket::ChannelManager(
78 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); 84 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
79 session_ = new cricket::FakeSession(true); 85 transport_controller_ =
86 new cricket::FakeTransportController(ICEROLE_CONTROLLING);
80 87
81 std::vector<std::string> in_device_list, out_device_list, vid_device_list; 88 std::vector<std::string> in_device_list, out_device_list, vid_device_list;
82 in_device_list.push_back("audio-in1"); 89 in_device_list.push_back("audio-in1");
83 in_device_list.push_back("audio-in2"); 90 in_device_list.push_back("audio-in2");
84 out_device_list.push_back("audio-out1"); 91 out_device_list.push_back("audio-out1");
85 out_device_list.push_back("audio-out2"); 92 out_device_list.push_back("audio-out2");
86 vid_device_list.push_back("video-in1"); 93 vid_device_list.push_back("video-in1");
87 vid_device_list.push_back("video-in2"); 94 vid_device_list.push_back("video-in2");
88 fdm_->SetAudioInputDevices(in_device_list); 95 fdm_->SetAudioInputDevices(in_device_list);
89 fdm_->SetAudioOutputDevices(out_device_list); 96 fdm_->SetAudioOutputDevices(out_device_list);
90 fdm_->SetVideoCaptureDevices(vid_device_list); 97 fdm_->SetVideoCaptureDevices(vid_device_list);
91 } 98 }
92 99
93 virtual void TearDown() { 100 virtual void TearDown() {
94 delete session_; 101 delete transport_controller_;
95 delete cm_; 102 delete cm_;
96 cm_ = NULL; 103 cm_ = NULL;
97 fdm_ = NULL; 104 fdm_ = NULL;
98 fcm_ = NULL; 105 fcm_ = NULL;
99 fdme_ = NULL; 106 fdme_ = NULL;
100 fme_ = NULL; 107 fme_ = NULL;
101 } 108 }
102 109
103 rtc::Thread worker_; 110 rtc::Thread worker_;
104 cricket::FakeCall fake_call_; 111 cricket::FakeCall fake_call_;
105 cricket::FakeMediaController fake_mc_; 112 cricket::FakeMediaController fake_mc_;
106 cricket::FakeMediaEngine* fme_; 113 cricket::FakeMediaEngine* fme_;
107 cricket::FakeDataEngine* fdme_; 114 cricket::FakeDataEngine* fdme_;
108 cricket::FakeDeviceManager* fdm_; 115 cricket::FakeDeviceManager* fdm_;
109 cricket::FakeCaptureManager* fcm_; 116 cricket::FakeCaptureManager* fcm_;
110 cricket::ChannelManager* cm_; 117 cricket::ChannelManager* cm_;
111 cricket::FakeSession* session_; 118 cricket::FakeTransportController* transport_controller_;
112 }; 119 };
113 120
114 // Test that we startup/shutdown properly. 121 // Test that we startup/shutdown properly.
115 TEST_F(ChannelManagerTest, StartupShutdown) { 122 TEST_F(ChannelManagerTest, StartupShutdown) {
116 EXPECT_FALSE(cm_->initialized()); 123 EXPECT_FALSE(cm_->initialized());
117 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); 124 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
118 EXPECT_TRUE(cm_->Init()); 125 EXPECT_TRUE(cm_->Init());
119 EXPECT_TRUE(cm_->initialized()); 126 EXPECT_TRUE(cm_->initialized());
120 cm_->Terminate(); 127 cm_->Terminate();
121 EXPECT_FALSE(cm_->initialized()); 128 EXPECT_FALSE(cm_->initialized());
(...skipping 10 matching lines...) Expand all
132 EXPECT_TRUE(cm_->initialized()); 139 EXPECT_TRUE(cm_->initialized());
133 // Setting the worker thread while initialized should fail. 140 // Setting the worker thread while initialized should fail.
134 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); 141 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
135 cm_->Terminate(); 142 cm_->Terminate();
136 EXPECT_FALSE(cm_->initialized()); 143 EXPECT_FALSE(cm_->initialized());
137 } 144 }
138 145
139 // Test that we can create and destroy a voice and video channel. 146 // Test that we can create and destroy a voice and video channel.
140 TEST_F(ChannelManagerTest, CreateDestroyChannels) { 147 TEST_F(ChannelManagerTest, CreateDestroyChannels) {
141 EXPECT_TRUE(cm_->Init()); 148 EXPECT_TRUE(cm_->Init());
142 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 149 cricket::VoiceChannel* voice_channel =
143 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); 150 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
151 cricket::CN_AUDIO, false, AudioOptions());
144 EXPECT_TRUE(voice_channel != nullptr); 152 EXPECT_TRUE(voice_channel != nullptr);
145 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 153 cricket::VideoChannel* video_channel =
146 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); 154 cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
155 cricket::CN_VIDEO, false, VideoOptions());
147 EXPECT_TRUE(video_channel != nullptr); 156 EXPECT_TRUE(video_channel != nullptr);
148 cricket::DataChannel* data_channel = 157 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
149 cm_->CreateDataChannel(session_, cricket::CN_DATA, 158 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
150 false, cricket::DCT_RTP);
151 EXPECT_TRUE(data_channel != nullptr); 159 EXPECT_TRUE(data_channel != nullptr);
152 cm_->DestroyVideoChannel(video_channel); 160 cm_->DestroyVideoChannel(video_channel);
153 cm_->DestroyVoiceChannel(voice_channel); 161 cm_->DestroyVoiceChannel(voice_channel);
154 cm_->DestroyDataChannel(data_channel); 162 cm_->DestroyDataChannel(data_channel);
155 cm_->Terminate(); 163 cm_->Terminate();
156 } 164 }
157 165
158 // Test that we can create and destroy a voice and video channel with a worker. 166 // Test that we can create and destroy a voice and video channel with a worker.
159 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { 167 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
160 worker_.Start(); 168 worker_.Start();
161 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); 169 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
162 EXPECT_TRUE(cm_->Init()); 170 EXPECT_TRUE(cm_->Init());
163 delete session_; 171 delete transport_controller_;
164 session_ = new cricket::FakeSession(&worker_, true); 172 transport_controller_ =
165 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 173 new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING);
166 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); 174 cricket::VoiceChannel* voice_channel =
175 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
176 cricket::CN_AUDIO, false, AudioOptions());
167 EXPECT_TRUE(voice_channel != nullptr); 177 EXPECT_TRUE(voice_channel != nullptr);
168 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 178 cricket::VideoChannel* video_channel =
169 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); 179 cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
180 cricket::CN_VIDEO, false, VideoOptions());
170 EXPECT_TRUE(video_channel != nullptr); 181 EXPECT_TRUE(video_channel != nullptr);
171 cricket::DataChannel* data_channel = 182 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
172 cm_->CreateDataChannel(session_, cricket::CN_DATA, 183 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
173 false, cricket::DCT_RTP);
174 EXPECT_TRUE(data_channel != nullptr); 184 EXPECT_TRUE(data_channel != nullptr);
175 cm_->DestroyVideoChannel(video_channel); 185 cm_->DestroyVideoChannel(video_channel);
176 cm_->DestroyVoiceChannel(voice_channel); 186 cm_->DestroyVoiceChannel(voice_channel);
177 cm_->DestroyDataChannel(data_channel); 187 cm_->DestroyDataChannel(data_channel);
178 cm_->Terminate(); 188 cm_->Terminate();
179 } 189 }
180 190
181 // Test that we fail to create a voice/video channel if the session is unable 191 // Test that we fail to create a voice/video channel if the session is unable
182 // to create a cricket::TransportChannel 192 // to create a cricket::TransportChannel
183 TEST_F(ChannelManagerTest, NoTransportChannelTest) { 193 TEST_F(ChannelManagerTest, NoTransportChannelTest) {
184 EXPECT_TRUE(cm_->Init()); 194 EXPECT_TRUE(cm_->Init());
185 session_->set_fail_channel_creation(true); 195 transport_controller_->set_fail_channel_creation(true);
186 // The test is useless unless the session does not fail creating 196 // The test is useless unless the session does not fail creating
187 // cricket::TransportChannel. 197 // cricket::TransportChannel.
188 ASSERT_TRUE(session_->CreateChannel( 198 ASSERT_TRUE(transport_controller_->CreateTransportChannel_w(
189 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); 199 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr);
190 200
191 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 201 cricket::VoiceChannel* voice_channel =
192 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions()); 202 cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
203 cricket::CN_AUDIO, false, AudioOptions());
193 EXPECT_TRUE(voice_channel == nullptr); 204 EXPECT_TRUE(voice_channel == nullptr);
194 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 205 cricket::VideoChannel* video_channel =
195 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions()); 206 cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
207 cricket::CN_VIDEO, false, VideoOptions());
196 EXPECT_TRUE(video_channel == nullptr); 208 EXPECT_TRUE(video_channel == nullptr);
197 cricket::DataChannel* data_channel = 209 cricket::DataChannel* data_channel = cm_->CreateDataChannel(
198 cm_->CreateDataChannel(session_, cricket::CN_DATA, 210 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
199 false, cricket::DCT_RTP);
200 EXPECT_TRUE(data_channel == nullptr); 211 EXPECT_TRUE(data_channel == nullptr);
201 cm_->Terminate(); 212 cm_->Terminate();
202 } 213 }
203 214
204 // Test that SetDefaultVideoCodec passes through the right values. 215 // Test that SetDefaultVideoCodec passes through the right values.
205 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { 216 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
206 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); 217 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
207 cricket::VideoEncoderConfig config(codec, 1, 2); 218 cricket::VideoEncoderConfig config(codec, 1, 2);
208 EXPECT_TRUE(cm_->Init()); 219 EXPECT_TRUE(cm_->Init());
209 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); 220 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); 603 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
593 604
594 // Can set again after terminate. 605 // Can set again after terminate.
595 cm_->Terminate(); 606 cm_->Terminate();
596 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); 607 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
597 cm_->GetSupportedVideoCodecs(&codecs); 608 cm_->GetSupportedVideoCodecs(&codecs);
598 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); 609 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
599 } 610 }
600 611
601 } // namespace cricket 612 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/session/media/channelmanager.cc ('k') | webrtc/base/fakenetwork.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698