OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 |
(...skipping 26 matching lines...) Expand all Loading... |
37 static DataEngineInterface* ConstructDataEngine() { | 37 static DataEngineInterface* ConstructDataEngine() { |
38 #ifdef HAVE_SCTP | 38 #ifdef HAVE_SCTP |
39 return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); | 39 return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); |
40 #else | 40 #else |
41 return new RtpDataEngine(); | 41 return new RtpDataEngine(); |
42 #endif | 42 #endif |
43 } | 43 } |
44 | 44 |
45 ChannelManager::ChannelManager(MediaEngineInterface* me, | 45 ChannelManager::ChannelManager(MediaEngineInterface* me, |
46 DataEngineInterface* dme, | 46 DataEngineInterface* dme, |
47 rtc::Thread* worker_thread) { | 47 rtc::Thread* thread) { |
48 Construct(me, dme, worker_thread); | 48 Construct(me, dme, thread, thread); |
49 } | 49 } |
50 | 50 |
51 ChannelManager::ChannelManager(MediaEngineInterface* me, | 51 ChannelManager::ChannelManager(MediaEngineInterface* me, |
52 rtc::Thread* worker_thread) { | 52 rtc::Thread* worker_thread, |
53 Construct(me, | 53 rtc::Thread* network_thread) { |
54 ConstructDataEngine(), | 54 Construct(me, ConstructDataEngine(), worker_thread, network_thread); |
55 worker_thread); | |
56 } | 55 } |
57 | 56 |
58 void ChannelManager::Construct(MediaEngineInterface* me, | 57 void ChannelManager::Construct(MediaEngineInterface* me, |
59 DataEngineInterface* dme, | 58 DataEngineInterface* dme, |
60 rtc::Thread* worker_thread) { | 59 rtc::Thread* worker_thread, |
| 60 rtc::Thread* network_thread) { |
61 media_engine_.reset(me); | 61 media_engine_.reset(me); |
62 data_media_engine_.reset(dme); | 62 data_media_engine_.reset(dme); |
63 initialized_ = false; | 63 initialized_ = false; |
64 main_thread_ = rtc::Thread::Current(); | 64 main_thread_ = rtc::Thread::Current(); |
65 worker_thread_ = worker_thread; | 65 worker_thread_ = worker_thread; |
| 66 network_thread_ = network_thread; |
66 audio_output_volume_ = kNotSetOutputVolume; | 67 audio_output_volume_ = kNotSetOutputVolume; |
67 capturing_ = false; | 68 capturing_ = false; |
68 enable_rtx_ = false; | 69 enable_rtx_ = false; |
69 } | 70 } |
70 | 71 |
71 ChannelManager::~ChannelManager() { | 72 ChannelManager::~ChannelManager() { |
72 if (initialized_) { | 73 if (initialized_) { |
73 Terminate(); | 74 Terminate(); |
74 // If srtp is initialized (done by the Channel) then we must call | 75 // If srtp is initialized (done by the Channel) then we must call |
75 // srtp_shutdown to free all crypto kernel lists. But we need to make sure | 76 // srtp_shutdown to free all crypto kernel lists. But we need to make sure |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void ChannelManager::GetSupportedDataCodecs( | 138 void ChannelManager::GetSupportedDataCodecs( |
138 std::vector<DataCodec>* codecs) const { | 139 std::vector<DataCodec>* codecs) const { |
139 *codecs = data_media_engine_->data_codecs(); | 140 *codecs = data_media_engine_->data_codecs(); |
140 } | 141 } |
141 | 142 |
142 bool ChannelManager::Init() { | 143 bool ChannelManager::Init() { |
143 ASSERT(!initialized_); | 144 ASSERT(!initialized_); |
144 if (initialized_) { | 145 if (initialized_) { |
145 return false; | 146 return false; |
146 } | 147 } |
147 ASSERT(worker_thread_ != NULL); | 148 RTC_DCHECK(network_thread_); |
148 if (!worker_thread_) { | 149 RTC_DCHECK(worker_thread_); |
149 return false; | 150 if (!network_thread_->IsCurrent()) { |
150 } | 151 // Do not allow invoking calls to other threads on the network thread. |
151 if (worker_thread_ != rtc::Thread::Current()) { | 152 network_thread_->Invoke<bool>( |
152 // Do not allow invoking calls to other threads on the worker thread. | 153 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); |
153 worker_thread_->Invoke<bool>(rtc::Bind( | |
154 &rtc::Thread::SetAllowBlockingCalls, worker_thread_, false)); | |
155 } | 154 } |
156 | 155 |
157 initialized_ = worker_thread_->Invoke<bool>(Bind( | 156 initialized_ = |
158 &ChannelManager::InitMediaEngine_w, this)); | 157 worker_thread_->Invoke<bool>([this] { return media_engine_->Init(); }); |
159 ASSERT(initialized_); | 158 RTC_DCHECK(initialized_); |
160 if (!initialized_) { | |
161 return false; | |
162 } | |
163 | 159 |
164 // If audio_output_volume_ has been set via SetOutputVolume(), set the | 160 // If audio_output_volume_ has been set via SetOutputVolume(), set the |
165 // audio output volume of the engine. | 161 // audio output volume of the engine. |
166 if (kNotSetOutputVolume != audio_output_volume_ && | 162 if (kNotSetOutputVolume != audio_output_volume_ && |
167 !SetOutputVolume(audio_output_volume_)) { | 163 !SetOutputVolume(audio_output_volume_)) { |
168 LOG(LS_WARNING) << "Failed to SetOutputVolume to " | 164 LOG(LS_WARNING) << "Failed to SetOutputVolume to " |
169 << audio_output_volume_; | 165 << audio_output_volume_; |
170 } | 166 } |
171 | 167 |
172 return initialized_; | 168 return initialized_; |
173 } | 169 } |
174 | 170 |
175 bool ChannelManager::InitMediaEngine_w() { | |
176 ASSERT(worker_thread_ == rtc::Thread::Current()); | |
177 return media_engine_->Init(); | |
178 } | |
179 | |
180 void ChannelManager::Terminate() { | 171 void ChannelManager::Terminate() { |
181 ASSERT(initialized_); | 172 ASSERT(initialized_); |
182 if (!initialized_) { | 173 if (!initialized_) { |
183 return; | 174 return; |
184 } | 175 } |
185 worker_thread_->Invoke<void>(Bind(&ChannelManager::Terminate_w, this)); | 176 worker_thread_->Invoke<void>(Bind(&ChannelManager::Terminate_w, this)); |
186 initialized_ = false; | 177 initialized_ = false; |
187 } | 178 } |
188 | 179 |
189 void ChannelManager::DestructorDeletes_w() { | 180 void ChannelManager::DestructorDeletes_w() { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 const AudioOptions& options) { | 212 const AudioOptions& options) { |
222 ASSERT(initialized_); | 213 ASSERT(initialized_); |
223 ASSERT(worker_thread_ == rtc::Thread::Current()); | 214 ASSERT(worker_thread_ == rtc::Thread::Current()); |
224 ASSERT(nullptr != media_controller); | 215 ASSERT(nullptr != media_controller); |
225 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( | 216 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( |
226 media_controller->call_w(), media_controller->config(), options); | 217 media_controller->call_w(), media_controller->config(), options); |
227 if (!media_channel) | 218 if (!media_channel) |
228 return nullptr; | 219 return nullptr; |
229 | 220 |
230 VoiceChannel* voice_channel = | 221 VoiceChannel* voice_channel = |
231 new VoiceChannel(worker_thread_, media_engine_.get(), media_channel, | 222 new VoiceChannel(worker_thread_, network_thread_, media_engine_.get(), |
232 transport_controller, content_name, rtcp); | 223 media_channel, transport_controller, content_name, rtcp); |
233 if (!voice_channel->Init()) { | 224 if (!voice_channel->Init()) { |
234 delete voice_channel; | 225 delete voice_channel; |
235 return nullptr; | 226 return nullptr; |
236 } | 227 } |
237 voice_channels_.push_back(voice_channel); | 228 voice_channels_.push_back(voice_channel); |
238 return voice_channel; | 229 return voice_channel; |
239 } | 230 } |
240 | 231 |
241 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { | 232 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
242 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); | 233 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 const VideoOptions& options) { | 270 const VideoOptions& options) { |
280 ASSERT(initialized_); | 271 ASSERT(initialized_); |
281 ASSERT(worker_thread_ == rtc::Thread::Current()); | 272 ASSERT(worker_thread_ == rtc::Thread::Current()); |
282 ASSERT(nullptr != media_controller); | 273 ASSERT(nullptr != media_controller); |
283 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( | 274 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( |
284 media_controller->call_w(), media_controller->config(), options); | 275 media_controller->call_w(), media_controller->config(), options); |
285 if (media_channel == NULL) { | 276 if (media_channel == NULL) { |
286 return NULL; | 277 return NULL; |
287 } | 278 } |
288 | 279 |
289 VideoChannel* video_channel = new VideoChannel( | 280 VideoChannel* video_channel = |
290 worker_thread_, media_channel, transport_controller, content_name, rtcp); | 281 new VideoChannel(worker_thread_, network_thread_, media_channel, |
| 282 transport_controller, content_name, rtcp); |
291 if (!video_channel->Init()) { | 283 if (!video_channel->Init()) { |
292 delete video_channel; | 284 delete video_channel; |
293 return NULL; | 285 return NULL; |
294 } | 286 } |
295 video_channels_.push_back(video_channel); | 287 video_channels_.push_back(video_channel); |
296 return video_channel; | 288 return video_channel; |
297 } | 289 } |
298 | 290 |
299 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { | 291 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
300 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); | 292 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // This is ok to alloc from a thread other than the worker thread. | 329 // This is ok to alloc from a thread other than the worker thread. |
338 ASSERT(initialized_); | 330 ASSERT(initialized_); |
339 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( | 331 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( |
340 data_channel_type); | 332 data_channel_type); |
341 if (!media_channel) { | 333 if (!media_channel) { |
342 LOG(LS_WARNING) << "Failed to create data channel of type " | 334 LOG(LS_WARNING) << "Failed to create data channel of type " |
343 << data_channel_type; | 335 << data_channel_type; |
344 return NULL; | 336 return NULL; |
345 } | 337 } |
346 | 338 |
347 DataChannel* data_channel = new DataChannel( | 339 DataChannel* data_channel = |
348 worker_thread_, media_channel, transport_controller, content_name, rtcp); | 340 new DataChannel(worker_thread_, network_thread_, media_channel, |
| 341 transport_controller, content_name, rtcp); |
349 if (!data_channel->Init()) { | 342 if (!data_channel->Init()) { |
350 LOG(LS_WARNING) << "Failed to init data channel."; | 343 LOG(LS_WARNING) << "Failed to init data channel."; |
351 delete data_channel; | 344 delete data_channel; |
352 return NULL; | 345 return NULL; |
353 } | 346 } |
354 data_channels_.push_back(data_channel); | 347 data_channels_.push_back(data_channel); |
355 return data_channel; | 348 return data_channel; |
356 } | 349 } |
357 | 350 |
358 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { | 351 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 return worker_thread_->Invoke<bool>( | 410 return worker_thread_->Invoke<bool>( |
418 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); | 411 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); |
419 } | 412 } |
420 | 413 |
421 void ChannelManager::StopRtcEventLog() { | 414 void ChannelManager::StopRtcEventLog() { |
422 worker_thread_->Invoke<void>( | 415 worker_thread_->Invoke<void>( |
423 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); | 416 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); |
424 } | 417 } |
425 | 418 |
426 } // namespace cricket | 419 } // namespace cricket |
OLD | NEW |