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

Side by Side Diff: webrtc/api/peerconnectionfactory.cc

Issue 1968393002: Propogate network-worker thread split to api (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase including nits Created 4 years, 7 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 | « webrtc/api/peerconnectionfactory.h ('k') | webrtc/api/peerconnectionfactory_unittest.cc » ('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 * 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
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 network_thread_(rtc::Thread::CreateWithSocketServer().release()),
108 worker_thread_(new rtc::Thread) { 106 worker_thread_(rtc::Thread::Create().release()),
107 signaling_thread_(rtc::Thread::Current()) {
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),
125 network_thread_(network_thread),
126 worker_thread_(worker_thread),
124 signaling_thread_(signaling_thread), 127 signaling_thread_(signaling_thread),
125 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::Time32()); 160 rtc::InitRandom(rtc::Time32());
157 161
158 default_network_manager_.reset(new rtc::BasicNetworkManager()); 162 default_network_manager_.reset(new rtc::BasicNetworkManager());
159 if (!default_network_manager_) { 163 if (!default_network_manager_) {
160 return false; 164 return false;
161 } 165 }
162 166
163 default_socket_factory_.reset( 167 default_socket_factory_.reset(
164 new rtc::BasicPacketSocketFactory(worker_thread_)); 168 new rtc::BasicPacketSocketFactory(network_thread_));
165 if (!default_socket_factory_) { 169 if (!default_socket_factory_) {
166 return false; 170 return false;
167 } 171 }
168 172
169 // TODO: Need to make sure only one VoE is created inside 173 // TODO: Need to make sure only one VoE is created inside
170 // WebRtcMediaEngine. 174 // WebRtcMediaEngine.
171 cricket::MediaEngineInterface* media_engine = 175 cricket::MediaEngineInterface* media_engine =
172 worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind( 176 worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind(
173 &PeerConnectionFactory::CreateMediaEngine_w, this)); 177 &PeerConnectionFactory::CreateMediaEngine_w, this));
174 178
175 rtc::Thread* const network_thread = worker_thread_;
176 channel_manager_.reset(new cricket::ChannelManager( 179 channel_manager_.reset(new cricket::ChannelManager(
177 media_engine, worker_thread_, network_thread)); 180 media_engine, worker_thread_, network_thread_));
178 181
179 channel_manager_->SetVideoRtxEnabled(true); 182 channel_manager_->SetVideoRtxEnabled(true);
180 if (!channel_manager_->Init()) { 183 if (!channel_manager_->Init()) {
181 return false; 184 return false;
182 } 185 }
183 186
184 dtls_identity_store_ = new RefCountedDtlsIdentityStore( 187 dtls_identity_store_ =
185 signaling_thread_, worker_thread_); 188 new RefCountedDtlsIdentityStore(signaling_thread_, network_thread_);
186 189
187 return true; 190 return true;
188 } 191 }
189 192
190 rtc::scoped_refptr<AudioSourceInterface> 193 rtc::scoped_refptr<AudioSourceInterface>
191 PeerConnectionFactory::CreateAudioSource( 194 PeerConnectionFactory::CreateAudioSource(
192 const MediaConstraintsInterface* constraints) { 195 const MediaConstraintsInterface* constraints) {
193 RTC_DCHECK(signaling_thread_->IsCurrent()); 196 RTC_DCHECK(signaling_thread_->IsCurrent());
194 rtc::scoped_refptr<LocalAudioSource> source( 197 rtc::scoped_refptr<LocalAudioSource> source(
195 LocalAudioSource::Create(options_, constraints)); 198 LocalAudioSource::Create(options_, constraints));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // This method can be called on a different thread when the factory is 336 // This method can be called on a different thread when the factory is
334 // created in CreatePeerConnectionFactory(). 337 // created in CreatePeerConnectionFactory().
335 return signaling_thread_; 338 return signaling_thread_;
336 } 339 }
337 340
338 rtc::Thread* PeerConnectionFactory::worker_thread() { 341 rtc::Thread* PeerConnectionFactory::worker_thread() {
339 RTC_DCHECK(signaling_thread_->IsCurrent()); 342 RTC_DCHECK(signaling_thread_->IsCurrent());
340 return worker_thread_; 343 return worker_thread_;
341 } 344 }
342 345
346 rtc::Thread* PeerConnectionFactory::network_thread() {
347 return network_thread_;
348 }
349
343 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { 350 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() {
344 ASSERT(worker_thread_ == rtc::Thread::Current()); 351 ASSERT(worker_thread_ == rtc::Thread::Current());
345 return cricket::WebRtcMediaEngineFactory::Create( 352 return cricket::WebRtcMediaEngineFactory::Create(
346 default_adm_.get(), video_encoder_factory_.get(), 353 default_adm_.get(), video_encoder_factory_.get(),
347 video_decoder_factory_.get()); 354 video_decoder_factory_.get());
348 } 355 }
349 356
350 } // namespace webrtc 357 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/peerconnectionfactory.h ('k') | webrtc/api/peerconnectionfactory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698