| 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_ = worker_thread_->Invoke<bool>( |
| 158 &ChannelManager::InitMediaEngine_w, this)); | 157 Bind(&ChannelManager::InitMediaEngine_w, this)); |
| 159 ASSERT(initialized_); | 158 ASSERT(initialized_); |
| 160 if (!initialized_) { | 159 if (!initialized_) { |
| 161 return false; | 160 return false; |
| 162 } | 161 } |
| 163 | 162 |
| 164 // If audio_output_volume_ has been set via SetOutputVolume(), set the | 163 // If audio_output_volume_ has been set via SetOutputVolume(), set the |
| 165 // audio output volume of the engine. | 164 // audio output volume of the engine. |
| 166 if (kNotSetOutputVolume != audio_output_volume_ && | 165 if (kNotSetOutputVolume != audio_output_volume_ && |
| 167 !SetOutputVolume(audio_output_volume_)) { | 166 !SetOutputVolume(audio_output_volume_)) { |
| 168 LOG(LS_WARNING) << "Failed to SetOutputVolume to " | 167 LOG(LS_WARNING) << "Failed to SetOutputVolume to " |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 const AudioOptions& options) { | 220 const AudioOptions& options) { |
| 222 ASSERT(initialized_); | 221 ASSERT(initialized_); |
| 223 ASSERT(worker_thread_ == rtc::Thread::Current()); | 222 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 224 ASSERT(nullptr != media_controller); | 223 ASSERT(nullptr != media_controller); |
| 225 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( | 224 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( |
| 226 media_controller->call_w(), media_controller->config(), options); | 225 media_controller->call_w(), media_controller->config(), options); |
| 227 if (!media_channel) | 226 if (!media_channel) |
| 228 return nullptr; | 227 return nullptr; |
| 229 | 228 |
| 230 VoiceChannel* voice_channel = | 229 VoiceChannel* voice_channel = |
| 231 new VoiceChannel(worker_thread_, media_engine_.get(), media_channel, | 230 new VoiceChannel(worker_thread_, network_thread_, media_engine_.get(), |
| 232 transport_controller, content_name, rtcp); | 231 media_channel, transport_controller, content_name, rtcp); |
| 233 if (!voice_channel->Init()) { | 232 if (!voice_channel->Init_w()) { |
| 234 delete voice_channel; | 233 delete voice_channel; |
| 235 return nullptr; | 234 return nullptr; |
| 236 } | 235 } |
| 237 voice_channels_.push_back(voice_channel); | 236 voice_channels_.push_back(voice_channel); |
| 238 return voice_channel; | 237 return voice_channel; |
| 239 } | 238 } |
| 240 | 239 |
| 241 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { | 240 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
| 242 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); | 241 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
| 243 if (voice_channel) { | 242 if (voice_channel) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 const VideoOptions& options) { | 278 const VideoOptions& options) { |
| 280 ASSERT(initialized_); | 279 ASSERT(initialized_); |
| 281 ASSERT(worker_thread_ == rtc::Thread::Current()); | 280 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 282 ASSERT(nullptr != media_controller); | 281 ASSERT(nullptr != media_controller); |
| 283 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( | 282 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( |
| 284 media_controller->call_w(), media_controller->config(), options); | 283 media_controller->call_w(), media_controller->config(), options); |
| 285 if (media_channel == NULL) { | 284 if (media_channel == NULL) { |
| 286 return NULL; | 285 return NULL; |
| 287 } | 286 } |
| 288 | 287 |
| 289 VideoChannel* video_channel = new VideoChannel( | 288 VideoChannel* video_channel = |
| 290 worker_thread_, media_channel, transport_controller, content_name, rtcp); | 289 new VideoChannel(worker_thread_, network_thread_, media_channel, |
| 291 if (!video_channel->Init()) { | 290 transport_controller, content_name, rtcp); |
| 291 if (!video_channel->Init_w()) { |
| 292 delete video_channel; | 292 delete video_channel; |
| 293 return NULL; | 293 return NULL; |
| 294 } | 294 } |
| 295 video_channels_.push_back(video_channel); | 295 video_channels_.push_back(video_channel); |
| 296 return video_channel; | 296 return video_channel; |
| 297 } | 297 } |
| 298 | 298 |
| 299 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { | 299 void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
| 300 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); | 300 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); |
| 301 if (video_channel) { | 301 if (video_channel) { |
| (...skipping 35 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. | 337 // This is ok to alloc from a thread other than the worker thread. |
| 338 ASSERT(initialized_); | 338 ASSERT(initialized_); |
| 339 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( | 339 DataMediaChannel* media_channel = data_media_engine_->CreateChannel( |
| 340 data_channel_type); | 340 data_channel_type); |
| 341 if (!media_channel) { | 341 if (!media_channel) { |
| 342 LOG(LS_WARNING) << "Failed to create data channel of type " | 342 LOG(LS_WARNING) << "Failed to create data channel of type " |
| 343 << data_channel_type; | 343 << data_channel_type; |
| 344 return NULL; | 344 return NULL; |
| 345 } | 345 } |
| 346 | 346 |
| 347 DataChannel* data_channel = new DataChannel( | 347 DataChannel* data_channel = |
| 348 worker_thread_, media_channel, transport_controller, content_name, rtcp); | 348 new DataChannel(worker_thread_, network_thread_, media_channel, |
| 349 if (!data_channel->Init()) { | 349 transport_controller, content_name, rtcp); |
| 350 if (!data_channel->Init_w()) { |
| 350 LOG(LS_WARNING) << "Failed to init data channel."; | 351 LOG(LS_WARNING) << "Failed to init data channel."; |
| 351 delete data_channel; | 352 delete data_channel; |
| 352 return NULL; | 353 return NULL; |
| 353 } | 354 } |
| 354 data_channels_.push_back(data_channel); | 355 data_channels_.push_back(data_channel); |
| 355 return data_channel; | 356 return data_channel; |
| 356 } | 357 } |
| 357 | 358 |
| 358 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { | 359 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { |
| 359 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); | 360 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return worker_thread_->Invoke<bool>( | 418 return worker_thread_->Invoke<bool>( |
| 418 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); | 419 Bind(&MediaEngineInterface::StartRtcEventLog, media_engine_.get(), file)); |
| 419 } | 420 } |
| 420 | 421 |
| 421 void ChannelManager::StopRtcEventLog() { | 422 void ChannelManager::StopRtcEventLog() { |
| 422 worker_thread_->Invoke<void>( | 423 worker_thread_->Invoke<void>( |
| 423 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); | 424 Bind(&MediaEngineInterface::StopRtcEventLog, media_engine_.get())); |
| 424 } | 425 } |
| 425 | 426 |
| 426 } // namespace cricket | 427 } // namespace cricket |
| OLD | NEW |