OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004--2011 Google Inc. | 3 * Copyright 2004--2011 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 26 matching lines...) Expand all Loading... | |
37 #include "talk/app/webrtc/peerconnectionproxy.h" | 37 #include "talk/app/webrtc/peerconnectionproxy.h" |
38 #include "talk/app/webrtc/portallocatorfactory.h" | 38 #include "talk/app/webrtc/portallocatorfactory.h" |
39 #include "talk/app/webrtc/videosource.h" | 39 #include "talk/app/webrtc/videosource.h" |
40 #include "talk/app/webrtc/videosourceproxy.h" | 40 #include "talk/app/webrtc/videosourceproxy.h" |
41 #include "talk/app/webrtc/videotrack.h" | 41 #include "talk/app/webrtc/videotrack.h" |
42 #include "talk/media/webrtc/webrtcmediaengine.h" | 42 #include "talk/media/webrtc/webrtcmediaengine.h" |
43 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" | 43 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
44 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" | 44 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
45 #include "webrtc/base/bind.h" | 45 #include "webrtc/base/bind.h" |
46 #include "webrtc/modules/audio_device/include/audio_device.h" | 46 #include "webrtc/modules/audio_device/include/audio_device.h" |
47 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | |
48 #include "webrtc/p2p/client/basicportallocator.h" | |
47 | 49 |
48 namespace webrtc { | 50 namespace webrtc { |
49 | 51 |
50 namespace { | 52 namespace { |
51 | 53 |
52 // Passes down the calls to |store_|. See usage in CreatePeerConnection. | 54 // Passes down the calls to |store_|. See usage in CreatePeerConnection. |
53 class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface { | 55 class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface { |
54 public: | 56 public: |
55 DtlsIdentityStoreWrapper( | 57 DtlsIdentityStoreWrapper( |
56 const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store) | 58 const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 // libjingle source tree. So we can 't currently assert if this is NULL. | 151 // libjingle source tree. So we can 't currently assert if this is NULL. |
150 // ASSERT(default_adm != NULL); | 152 // ASSERT(default_adm != NULL); |
151 } | 153 } |
152 | 154 |
153 PeerConnectionFactory::~PeerConnectionFactory() { | 155 PeerConnectionFactory::~PeerConnectionFactory() { |
154 RTC_DCHECK(signaling_thread_->IsCurrent()); | 156 RTC_DCHECK(signaling_thread_->IsCurrent()); |
155 channel_manager_.reset(nullptr); | 157 channel_manager_.reset(nullptr); |
156 default_allocator_factory_ = nullptr; | 158 default_allocator_factory_ = nullptr; |
157 | 159 |
158 // Make sure |worker_thread_| and |signaling_thread_| outlive | 160 // Make sure |worker_thread_| and |signaling_thread_| outlive |
159 // |dtls_identity_store_|. | 161 // |dtls_identity_store_|, |default_socket_factory_| and |
162 // |default_network_manager_|. | |
160 dtls_identity_store_ = nullptr; | 163 dtls_identity_store_ = nullptr; |
164 default_socket_factory_ = nullptr; | |
165 default_network_manager_ = nullptr; | |
161 | 166 |
162 if (owns_ptrs_) { | 167 if (owns_ptrs_) { |
163 if (wraps_current_thread_) | 168 if (wraps_current_thread_) |
164 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); | 169 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
165 delete worker_thread_; | 170 delete worker_thread_; |
166 } | 171 } |
167 } | 172 } |
168 | 173 |
169 bool PeerConnectionFactory::Initialize() { | 174 bool PeerConnectionFactory::Initialize() { |
170 RTC_DCHECK(signaling_thread_->IsCurrent()); | 175 RTC_DCHECK(signaling_thread_->IsCurrent()); |
171 rtc::InitRandom(rtc::Time()); | 176 rtc::InitRandom(rtc::Time()); |
172 | 177 |
173 default_allocator_factory_ = PortAllocatorFactory::Create(worker_thread_); | 178 default_allocator_factory_ = PortAllocatorFactory::Create(worker_thread_); |
174 if (!default_allocator_factory_) | 179 if (!default_allocator_factory_) { |
175 return false; | 180 return false; |
181 } | |
182 | |
183 default_network_manager_.reset(new rtc::BasicNetworkManager()); | |
184 if (!default_network_manager_) { | |
185 return false; | |
186 } | |
187 | |
188 default_socket_factory_.reset( | |
189 new rtc::BasicPacketSocketFactory(worker_thread_)); | |
190 if (!default_socket_factory_) { | |
191 return false; | |
192 } | |
176 | 193 |
177 // TODO: Need to make sure only one VoE is created inside | 194 // TODO: Need to make sure only one VoE is created inside |
178 // WebRtcMediaEngine. | 195 // WebRtcMediaEngine. |
179 cricket::MediaEngineInterface* media_engine = | 196 cricket::MediaEngineInterface* media_engine = |
180 worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind( | 197 worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind( |
181 &PeerConnectionFactory::CreateMediaEngine_w, this)); | 198 &PeerConnectionFactory::CreateMediaEngine_w, this)); |
182 | 199 |
183 channel_manager_.reset( | 200 channel_manager_.reset( |
184 new cricket::ChannelManager(media_engine, worker_thread_)); | 201 new cricket::ChannelManager(media_engine, worker_thread_)); |
185 | 202 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 configuration, | 278 configuration, |
262 constraints, | 279 constraints, |
263 chosen_allocator_factory, | 280 chosen_allocator_factory, |
264 dtls_identity_store.Pass(), | 281 dtls_identity_store.Pass(), |
265 observer)) { | 282 observer)) { |
266 return NULL; | 283 return NULL; |
267 } | 284 } |
268 return PeerConnectionProxy::Create(signaling_thread(), pc); | 285 return PeerConnectionProxy::Create(signaling_thread(), pc); |
269 } | 286 } |
270 | 287 |
288 rtc::scoped_refptr<PeerConnectionInterface> | |
289 PeerConnectionFactory::CreatePeerConnection( | |
290 const PeerConnectionInterface::RTCConfiguration& configuration, | |
291 const MediaConstraintsInterface* constraints, | |
292 rtc::scoped_ptr<cricket::PortAllocator> allocator, | |
293 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | |
294 PeerConnectionObserver* observer) { | |
295 RTC_DCHECK(signaling_thread_->IsCurrent()); | |
296 | |
297 if (!dtls_identity_store.get()) { | |
298 // Because |pc|->Initialize takes ownership of the store we need a new | |
299 // wrapper object that can be deleted without deleting the underlying | |
300 // |dtls_identity_store_|, protecting it from being deleted multiple times. | |
301 dtls_identity_store.reset( | |
302 new DtlsIdentityStoreWrapper(dtls_identity_store_)); | |
303 } | |
304 | |
305 if (!allocator) { | |
306 allocator.reset(new cricket::BasicPortAllocator( | |
307 default_network_manager_.get(), default_socket_factory_.get())); | |
308 } | |
309 default_network_manager_->set_network_ignore_mask( | |
310 options_.network_ignore_mask); | |
311 | |
312 rtc::scoped_refptr<PeerConnection> pc( | |
313 new rtc::RefCountedObject<PeerConnection>(this)); | |
314 if (!pc->Initialize(configuration, constraints, allocator.Pass(), | |
pthatcher1
2015/11/20 05:43:50
Apparently we can use std::move instead of .Pass()
| |
315 dtls_identity_store.Pass(), observer)) { | |
316 return NULL; | |
317 } | |
318 return PeerConnectionProxy::Create(signaling_thread(), pc); | |
319 } | |
320 | |
271 rtc::scoped_refptr<MediaStreamInterface> | 321 rtc::scoped_refptr<MediaStreamInterface> |
272 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { | 322 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { |
273 RTC_DCHECK(signaling_thread_->IsCurrent()); | 323 RTC_DCHECK(signaling_thread_->IsCurrent()); |
274 return MediaStreamProxy::Create(signaling_thread_, | 324 return MediaStreamProxy::Create(signaling_thread_, |
275 MediaStream::Create(label)); | 325 MediaStream::Create(label)); |
276 } | 326 } |
277 | 327 |
278 rtc::scoped_refptr<VideoTrackInterface> | 328 rtc::scoped_refptr<VideoTrackInterface> |
279 PeerConnectionFactory::CreateVideoTrack( | 329 PeerConnectionFactory::CreateVideoTrack( |
280 const std::string& id, | 330 const std::string& id, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 363 } |
314 | 364 |
315 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { | 365 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { |
316 ASSERT(worker_thread_ == rtc::Thread::Current()); | 366 ASSERT(worker_thread_ == rtc::Thread::Current()); |
317 return cricket::WebRtcMediaEngineFactory::Create( | 367 return cricket::WebRtcMediaEngineFactory::Create( |
318 default_adm_.get(), video_encoder_factory_.get(), | 368 default_adm_.get(), video_encoder_factory_.get(), |
319 video_decoder_factory_.get()); | 369 video_decoder_factory_.get()); |
320 } | 370 } |
321 | 371 |
322 } // namespace webrtc | 372 } // namespace webrtc |
OLD | NEW |