| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread()); | 67 RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread()); |
| 68 // The signaling thread is the current thread so we can | 68 // The signaling thread is the current thread so we can |
| 69 // safely call Initialize directly. | 69 // safely call Initialize directly. |
| 70 if (!pc_factory->Initialize()) { | 70 if (!pc_factory->Initialize()) { |
| 71 return nullptr; | 71 return nullptr; |
| 72 } | 72 } |
| 73 return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), | 73 return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), |
| 74 pc_factory); | 74 pc_factory); |
| 75 } | 75 } |
| 76 | 76 |
| 77 rtc::scoped_refptr<PeerConnectionFactoryInterface> | 77 rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 78 CreatePeerConnectionFactory( | 78 rtc::Thread* network_thread, |
| 79 rtc::Thread* worker_thread, | 79 rtc::Thread* worker_thread, |
| 80 rtc::Thread* signaling_thread, | 80 rtc::Thread* signaling_thread, |
| 81 AudioDeviceModule* default_adm, | 81 AudioDeviceModule* default_adm, |
| 82 cricket::WebRtcVideoEncoderFactory* encoder_factory, | 82 cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 83 cricket::WebRtcVideoDecoderFactory* decoder_factory) { | 83 cricket::WebRtcVideoDecoderFactory* decoder_factory) { |
| 84 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( | 84 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 85 new rtc::RefCountedObject<PeerConnectionFactory>(worker_thread, | 85 new rtc::RefCountedObject<PeerConnectionFactory>( |
| 86 signaling_thread, | 86 network_thread, worker_thread, signaling_thread, default_adm, |
| 87 default_adm, | 87 encoder_factory, decoder_factory)); |
| 88 encoder_factory, | |
| 89 decoder_factory)); | |
| 90 | 88 |
| 91 // Call Initialize synchronously but make sure its executed on | 89 // Call Initialize synchronously but make sure its executed on |
| 92 // |signaling_thread|. | 90 // |signaling_thread|. |
| 93 MethodCall0<PeerConnectionFactory, bool> call( | 91 MethodCall0<PeerConnectionFactory, bool> call( |
| 94 pc_factory.get(), | 92 pc_factory.get(), |
| 95 &PeerConnectionFactory::Initialize); | 93 &PeerConnectionFactory::Initialize); |
| 96 bool result = call.Marshal(signaling_thread); | 94 bool result = call.Marshal(signaling_thread); |
| 97 | 95 |
| 98 if (!result) { | 96 if (!result) { |
| 99 return nullptr; | 97 return nullptr; |
| 100 } | 98 } |
| 101 return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); | 99 return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); |
| 102 } | 100 } |
| 103 | 101 |
| 104 PeerConnectionFactory::PeerConnectionFactory() | 102 PeerConnectionFactory::PeerConnectionFactory() |
| 105 : owns_ptrs_(true), | 103 : owns_ptrs_(true), |
| 106 wraps_current_thread_(false), | 104 wraps_current_thread_(false), |
| 107 signaling_thread_(rtc::ThreadManager::Instance()->CurrentThread()), | 105 signaling_thread_(rtc::Thread::Current()), |
| 108 worker_thread_(new rtc::Thread) { | 106 network_thread_(rtc::Thread::CreateWithSocketServer().release()), |
| 107 worker_thread_(rtc::Thread::Create().release()) { |
| 109 if (!signaling_thread_) { | 108 if (!signaling_thread_) { |
| 110 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); | 109 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); |
| 111 wraps_current_thread_ = true; | 110 wraps_current_thread_ = true; |
| 112 } | 111 } |
| 112 network_thread_->Start(); |
| 113 worker_thread_->Start(); | 113 worker_thread_->Start(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 PeerConnectionFactory::PeerConnectionFactory( | 116 PeerConnectionFactory::PeerConnectionFactory( |
| 117 rtc::Thread* network_thread, |
| 117 rtc::Thread* worker_thread, | 118 rtc::Thread* worker_thread, |
| 118 rtc::Thread* signaling_thread, | 119 rtc::Thread* signaling_thread, |
| 119 AudioDeviceModule* default_adm, | 120 AudioDeviceModule* default_adm, |
| 120 cricket::WebRtcVideoEncoderFactory* video_encoder_factory, | 121 cricket::WebRtcVideoEncoderFactory* video_encoder_factory, |
| 121 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) | 122 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) |
| 122 : owns_ptrs_(false), | 123 : owns_ptrs_(false), |
| 123 wraps_current_thread_(false), | 124 wraps_current_thread_(false), |
| 124 signaling_thread_(signaling_thread), | 125 signaling_thread_(signaling_thread), |
| 126 network_thread_(network_thread), |
| 125 worker_thread_(worker_thread), | 127 worker_thread_(worker_thread), |
| 126 default_adm_(default_adm), | 128 default_adm_(default_adm), |
| 127 video_encoder_factory_(video_encoder_factory), | 129 video_encoder_factory_(video_encoder_factory), |
| 128 video_decoder_factory_(video_decoder_factory) { | 130 video_decoder_factory_(video_decoder_factory) { |
| 129 ASSERT(worker_thread != NULL); | 131 RTC_DCHECK(network_thread); |
| 130 ASSERT(signaling_thread != NULL); | 132 RTC_DCHECK(worker_thread); |
| 133 RTC_DCHECK(signaling_thread); |
| 131 // TODO: Currently there is no way creating an external adm in | 134 // TODO: Currently there is no way creating an external adm in |
| 132 // libjingle source tree. So we can 't currently assert if this is NULL. | 135 // libjingle source tree. So we can 't currently assert if this is NULL. |
| 133 // ASSERT(default_adm != NULL); | 136 // ASSERT(default_adm != NULL); |
| 134 } | 137 } |
| 135 | 138 |
| 136 PeerConnectionFactory::~PeerConnectionFactory() { | 139 PeerConnectionFactory::~PeerConnectionFactory() { |
| 137 RTC_DCHECK(signaling_thread_->IsCurrent()); | 140 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 138 channel_manager_.reset(nullptr); | 141 channel_manager_.reset(nullptr); |
| 139 | 142 |
| 140 // Make sure |worker_thread_| and |signaling_thread_| outlive | 143 // Make sure |worker_thread_| and |signaling_thread_| outlive |
| 141 // |dtls_identity_store_|, |default_socket_factory_| and | 144 // |dtls_identity_store_|, |default_socket_factory_| and |
| 142 // |default_network_manager_|. | 145 // |default_network_manager_|. |
| 143 dtls_identity_store_ = nullptr; | 146 dtls_identity_store_ = nullptr; |
| 144 default_socket_factory_ = nullptr; | 147 default_socket_factory_ = nullptr; |
| 145 default_network_manager_ = nullptr; | 148 default_network_manager_ = nullptr; |
| 146 | 149 |
| 147 if (owns_ptrs_) { | 150 if (owns_ptrs_) { |
| 148 if (wraps_current_thread_) | 151 if (wraps_current_thread_) |
| 149 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); | 152 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
| 150 delete worker_thread_; | 153 delete worker_thread_; |
| 154 delete network_thread_; |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 | 157 |
| 154 bool PeerConnectionFactory::Initialize() { | 158 bool PeerConnectionFactory::Initialize() { |
| 155 RTC_DCHECK(signaling_thread_->IsCurrent()); | 159 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 156 rtc::InitRandom(rtc::Time()); | 160 rtc::InitRandom(rtc::Time()); |
| 157 | 161 |
| 158 default_network_manager_.reset(new rtc::BasicNetworkManager()); | 162 network_thread_->Invoke<void>([this] { |
| 159 if (!default_network_manager_) { | 163 default_network_manager_.reset(new rtc::BasicNetworkManager()); |
| 160 return false; | 164 default_socket_factory_.reset( |
| 161 } | 165 new rtc::BasicPacketSocketFactory(network_thread_)); |
| 162 | 166 }); |
| 163 default_socket_factory_.reset( | |
| 164 new rtc::BasicPacketSocketFactory(worker_thread_)); | |
| 165 if (!default_socket_factory_) { | |
| 166 return false; | |
| 167 } | |
| 168 | 167 |
| 169 // TODO: Need to make sure only one VoE is created inside | 168 // TODO: Need to make sure only one VoE is created inside |
| 170 // WebRtcMediaEngine. | 169 // WebRtcMediaEngine. |
| 171 cricket::MediaEngineInterface* media_engine = | 170 cricket::MediaEngineInterface* media_engine = |
| 172 worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind( | 171 worker_thread_->Invoke<cricket::MediaEngineInterface*>([this] { |
| 173 &PeerConnectionFactory::CreateMediaEngine_w, this)); | 172 return cricket::WebRtcMediaEngineFactory::Create( |
| 173 default_adm_.get(), video_encoder_factory_.get(), |
| 174 video_decoder_factory_.get()); |
| 175 }); |
| 174 | 176 |
| 175 channel_manager_.reset( | 177 channel_manager_.reset(new cricket::ChannelManager( |
| 176 new cricket::ChannelManager(media_engine, worker_thread_)); | 178 media_engine, worker_thread_, network_thread_)); |
| 177 | 179 |
| 178 channel_manager_->SetVideoRtxEnabled(true); | 180 channel_manager_->SetVideoRtxEnabled(true); |
| 179 if (!channel_manager_->Init()) { | 181 if (!channel_manager_->Init()) { |
| 180 return false; | 182 return false; |
| 181 } | 183 } |
| 182 | 184 |
| 183 dtls_identity_store_ = new RefCountedDtlsIdentityStore( | 185 dtls_identity_store_ = |
| 184 signaling_thread_, worker_thread_); | 186 new RefCountedDtlsIdentityStore(signaling_thread_, network_thread_); |
| 185 | 187 |
| 186 return true; | 188 return true; |
| 187 } | 189 } |
| 188 | 190 |
| 189 rtc::scoped_refptr<AudioSourceInterface> | 191 rtc::scoped_refptr<AudioSourceInterface> |
| 190 PeerConnectionFactory::CreateAudioSource( | 192 PeerConnectionFactory::CreateAudioSource( |
| 191 const MediaConstraintsInterface* constraints) { | 193 const MediaConstraintsInterface* constraints) { |
| 192 RTC_DCHECK(signaling_thread_->IsCurrent()); | 194 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 193 rtc::scoped_refptr<LocalAudioSource> source( | 195 rtc::scoped_refptr<LocalAudioSource> source( |
| 194 LocalAudioSource::Create(options_, constraints)); | 196 LocalAudioSource::Create(options_, constraints)); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 // This method can be called on a different thread when the factory is | 331 // This method can be called on a different thread when the factory is |
| 330 // created in CreatePeerConnectionFactory(). | 332 // created in CreatePeerConnectionFactory(). |
| 331 return signaling_thread_; | 333 return signaling_thread_; |
| 332 } | 334 } |
| 333 | 335 |
| 334 rtc::Thread* PeerConnectionFactory::worker_thread() { | 336 rtc::Thread* PeerConnectionFactory::worker_thread() { |
| 335 RTC_DCHECK(signaling_thread_->IsCurrent()); | 337 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 336 return worker_thread_; | 338 return worker_thread_; |
| 337 } | 339 } |
| 338 | 340 |
| 341 rtc::Thread* PeerConnectionFactory::network_thread() { |
| 342 return network_thread_; |
| 343 } |
| 344 |
| 339 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { | 345 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { |
| 340 ASSERT(worker_thread_ == rtc::Thread::Current()); | 346 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 341 return cricket::WebRtcMediaEngineFactory::Create( | 347 return cricket::WebRtcMediaEngineFactory::Create( |
| 342 default_adm_.get(), video_encoder_factory_.get(), | 348 default_adm_.get(), video_encoder_factory_.get(), |
| 343 video_decoder_factory_.get()); | 349 video_decoder_factory_.get()); |
| 344 } | 350 } |
| 345 | 351 |
| 346 } // namespace webrtc | 352 } // namespace webrtc |
| OLD | NEW |