| 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 10 matching lines...) Expand all Loading... |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/app/webrtc/peerconnectionfactory.h" | 28 #include "talk/app/webrtc/peerconnectionfactory.h" |
| 29 | 29 |
| 30 #include "talk/app/webrtc/audiotrack.h" | 30 #include "talk/app/webrtc/audiotrack.h" |
| 31 #include "talk/app/webrtc/dtlsidentityservice.h" | |
| 32 #include "talk/app/webrtc/dtlsidentitystore.h" | |
| 33 #include "talk/app/webrtc/localaudiosource.h" | 31 #include "talk/app/webrtc/localaudiosource.h" |
| 34 #include "talk/app/webrtc/mediastreamproxy.h" | 32 #include "talk/app/webrtc/mediastreamproxy.h" |
| 35 #include "talk/app/webrtc/mediastreamtrackproxy.h" | 33 #include "talk/app/webrtc/mediastreamtrackproxy.h" |
| 36 #include "talk/app/webrtc/peerconnection.h" | 34 #include "talk/app/webrtc/peerconnection.h" |
| 37 #include "talk/app/webrtc/peerconnectionfactoryproxy.h" | 35 #include "talk/app/webrtc/peerconnectionfactoryproxy.h" |
| 38 #include "talk/app/webrtc/peerconnectionproxy.h" | 36 #include "talk/app/webrtc/peerconnectionproxy.h" |
| 39 #include "talk/app/webrtc/portallocatorfactory.h" | 37 #include "talk/app/webrtc/portallocatorfactory.h" |
| 40 #include "talk/app/webrtc/videosource.h" | 38 #include "talk/app/webrtc/videosource.h" |
| 41 #include "talk/app/webrtc/videosourceproxy.h" | 39 #include "talk/app/webrtc/videosourceproxy.h" |
| 42 #include "talk/app/webrtc/videotrack.h" | 40 #include "talk/app/webrtc/videotrack.h" |
| 43 #include "talk/media/devices/dummydevicemanager.h" | 41 #include "talk/media/devices/dummydevicemanager.h" |
| 44 #include "talk/media/webrtc/webrtcmediaengine.h" | 42 #include "talk/media/webrtc/webrtcmediaengine.h" |
| 45 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" | 43 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
| 46 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" | 44 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
| 47 #include "webrtc/base/bind.h" | 45 #include "webrtc/base/bind.h" |
| 48 #include "webrtc/modules/audio_device/include/audio_device.h" | 46 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 49 | 47 |
| 50 namespace webrtc { | 48 namespace webrtc { |
| 51 | 49 |
| 50 namespace { |
| 51 |
| 52 // Passes down the calls to |store_|. See usage in CreatePeerConnection. |
| 53 class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface { |
| 54 public: |
| 55 DtlsIdentityStoreWrapper( |
| 56 const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store) |
| 57 : store_(store) { |
| 58 DCHECK(store_); |
| 59 } |
| 60 |
| 61 void RequestIdentity( |
| 62 rtc::KeyType key_type, |
| 63 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& |
| 64 observer) override { |
| 65 store_->RequestIdentity(key_type, observer); |
| 66 } |
| 67 |
| 68 private: |
| 69 rtc::scoped_refptr<RefCountedDtlsIdentityStore> store_; |
| 70 }; |
| 71 |
| 72 } // anonymous namespace |
| 73 |
| 52 rtc::scoped_refptr<PeerConnectionFactoryInterface> | 74 rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 53 CreatePeerConnectionFactory() { | 75 CreatePeerConnectionFactory() { |
| 54 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( | 76 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 55 new rtc::RefCountedObject<PeerConnectionFactory>()); | 77 new rtc::RefCountedObject<PeerConnectionFactory>()); |
| 56 | 78 |
| 57 | 79 |
| 58 // Call Initialize synchronously but make sure its executed on | 80 // Call Initialize synchronously but make sure its executed on |
| 59 // |signaling_thread|. | 81 // |signaling_thread|. |
| 60 MethodCall0<PeerConnectionFactory, bool> call( | 82 MethodCall0<PeerConnectionFactory, bool> call( |
| 61 pc_factory.get(), | 83 pc_factory.get(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 video_decoder_factory_(video_decoder_factory) { | 145 video_decoder_factory_(video_decoder_factory) { |
| 124 ASSERT(worker_thread != NULL); | 146 ASSERT(worker_thread != NULL); |
| 125 ASSERT(signaling_thread != NULL); | 147 ASSERT(signaling_thread != NULL); |
| 126 // TODO: Currently there is no way creating an external adm in | 148 // TODO: Currently there is no way creating an external adm in |
| 127 // libjingle source tree. So we can 't currently assert if this is NULL. | 149 // libjingle source tree. So we can 't currently assert if this is NULL. |
| 128 // ASSERT(default_adm != NULL); | 150 // ASSERT(default_adm != NULL); |
| 129 } | 151 } |
| 130 | 152 |
| 131 PeerConnectionFactory::~PeerConnectionFactory() { | 153 PeerConnectionFactory::~PeerConnectionFactory() { |
| 132 DCHECK(signaling_thread_->IsCurrent()); | 154 DCHECK(signaling_thread_->IsCurrent()); |
| 133 channel_manager_.reset(NULL); | 155 channel_manager_.reset(nullptr); |
| 134 default_allocator_factory_ = NULL; | 156 default_allocator_factory_ = nullptr; |
| 135 | 157 |
| 136 // Make sure |worker_thread_| and |signaling_thread_| outlive | 158 // Make sure |worker_thread_| and |signaling_thread_| outlive |
| 137 // |dtls_identity_store_|. | 159 // |dtls_identity_store_|. |
| 138 dtls_identity_store_.reset(NULL); | 160 dtls_identity_store_ = nullptr; |
| 139 | 161 |
| 140 if (owns_ptrs_) { | 162 if (owns_ptrs_) { |
| 141 if (wraps_current_thread_) | 163 if (wraps_current_thread_) |
| 142 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); | 164 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
| 143 delete worker_thread_; | 165 delete worker_thread_; |
| 144 } | 166 } |
| 145 } | 167 } |
| 146 | 168 |
| 147 bool PeerConnectionFactory::Initialize() { | 169 bool PeerConnectionFactory::Initialize() { |
| 148 DCHECK(signaling_thread_->IsCurrent()); | 170 DCHECK(signaling_thread_->IsCurrent()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 162 &PeerConnectionFactory::CreateMediaEngine_w, this)); | 184 &PeerConnectionFactory::CreateMediaEngine_w, this)); |
| 163 | 185 |
| 164 channel_manager_.reset(new cricket::ChannelManager( | 186 channel_manager_.reset(new cricket::ChannelManager( |
| 165 media_engine, device_manager, worker_thread_)); | 187 media_engine, device_manager, worker_thread_)); |
| 166 | 188 |
| 167 channel_manager_->SetVideoRtxEnabled(true); | 189 channel_manager_->SetVideoRtxEnabled(true); |
| 168 if (!channel_manager_->Init()) { | 190 if (!channel_manager_->Init()) { |
| 169 return false; | 191 return false; |
| 170 } | 192 } |
| 171 | 193 |
| 172 dtls_identity_store_.reset( | 194 dtls_identity_store_ = new RefCountedDtlsIdentityStore( |
| 173 new DtlsIdentityStore(signaling_thread_, worker_thread_)); | 195 signaling_thread_, worker_thread_); |
| 174 dtls_identity_store_->Initialize(); | |
| 175 | 196 |
| 176 return true; | 197 return true; |
| 177 } | 198 } |
| 178 | 199 |
| 179 rtc::scoped_refptr<AudioSourceInterface> | 200 rtc::scoped_refptr<AudioSourceInterface> |
| 180 PeerConnectionFactory::CreateAudioSource( | 201 PeerConnectionFactory::CreateAudioSource( |
| 181 const MediaConstraintsInterface* constraints) { | 202 const MediaConstraintsInterface* constraints) { |
| 182 DCHECK(signaling_thread_->IsCurrent()); | 203 DCHECK(signaling_thread_->IsCurrent()); |
| 183 rtc::scoped_refptr<LocalAudioSource> source( | 204 rtc::scoped_refptr<LocalAudioSource> source( |
| 184 LocalAudioSource::Create(options_, constraints)); | 205 LocalAudioSource::Create(options_, constraints)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { | 219 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { |
| 199 DCHECK(signaling_thread_->IsCurrent()); | 220 DCHECK(signaling_thread_->IsCurrent()); |
| 200 return channel_manager_->StartAecDump(file); | 221 return channel_manager_->StartAecDump(file); |
| 201 } | 222 } |
| 202 | 223 |
| 203 rtc::scoped_refptr<PeerConnectionInterface> | 224 rtc::scoped_refptr<PeerConnectionInterface> |
| 204 PeerConnectionFactory::CreatePeerConnection( | 225 PeerConnectionFactory::CreatePeerConnection( |
| 205 const PeerConnectionInterface::RTCConfiguration& configuration, | 226 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 206 const MediaConstraintsInterface* constraints, | 227 const MediaConstraintsInterface* constraints, |
| 207 PortAllocatorFactoryInterface* allocator_factory, | 228 PortAllocatorFactoryInterface* allocator_factory, |
| 208 DTLSIdentityServiceInterface* dtls_identity_service, | 229 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 209 PeerConnectionObserver* observer) { | 230 PeerConnectionObserver* observer) { |
| 210 DCHECK(signaling_thread_->IsCurrent()); | 231 DCHECK(signaling_thread_->IsCurrent()); |
| 211 DCHECK(allocator_factory || default_allocator_factory_); | 232 DCHECK(allocator_factory || default_allocator_factory_); |
| 212 | 233 |
| 213 if (!dtls_identity_service) { | 234 if (!dtls_identity_store.get()) { |
| 214 dtls_identity_service = new DtlsIdentityService(dtls_identity_store_.get()); | 235 // Because |pc|->Initialize takes ownership of the store we need a new |
| 236 // wrapper object that can be deleted without deleting the underlying |
| 237 // |dtls_identity_store_|, protecting it from being deleted multiple times. |
| 238 dtls_identity_store.reset( |
| 239 new DtlsIdentityStoreWrapper(dtls_identity_store_)); |
| 215 } | 240 } |
| 216 | 241 |
| 217 PortAllocatorFactoryInterface* chosen_allocator_factory = | 242 PortAllocatorFactoryInterface* chosen_allocator_factory = |
| 218 allocator_factory ? allocator_factory : default_allocator_factory_.get(); | 243 allocator_factory ? allocator_factory : default_allocator_factory_.get(); |
| 219 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); | 244 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); |
| 220 | 245 |
| 221 rtc::scoped_refptr<PeerConnection> pc( | 246 rtc::scoped_refptr<PeerConnection> pc( |
| 222 new rtc::RefCountedObject<PeerConnection>(this)); | 247 new rtc::RefCountedObject<PeerConnection>(this)); |
| 223 if (!pc->Initialize( | 248 if (!pc->Initialize( |
| 224 configuration, | 249 configuration, |
| 225 constraints, | 250 constraints, |
| 226 chosen_allocator_factory, | 251 chosen_allocator_factory, |
| 227 dtls_identity_service, | 252 dtls_identity_store.Pass(), |
| 228 observer)) { | 253 observer)) { |
| 229 return NULL; | 254 return NULL; |
| 230 } | 255 } |
| 231 return PeerConnectionProxy::Create(signaling_thread(), pc); | 256 return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 232 } | 257 } |
| 233 | 258 |
| 234 rtc::scoped_refptr<MediaStreamInterface> | 259 rtc::scoped_refptr<MediaStreamInterface> |
| 235 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { | 260 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { |
| 236 DCHECK(signaling_thread_->IsCurrent()); | 261 DCHECK(signaling_thread_->IsCurrent()); |
| 237 return MediaStreamProxy::Create(signaling_thread_, | 262 return MediaStreamProxy::Create(signaling_thread_, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 299 } |
| 275 | 300 |
| 276 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { | 301 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { |
| 277 ASSERT(worker_thread_ == rtc::Thread::Current()); | 302 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 278 return cricket::WebRtcMediaEngineFactory::Create( | 303 return cricket::WebRtcMediaEngineFactory::Create( |
| 279 default_adm_.get(), video_encoder_factory_.get(), | 304 default_adm_.get(), video_encoder_factory_.get(), |
| 280 video_decoder_factory_.get()); | 305 video_decoder_factory_.get()); |
| 281 } | 306 } |
| 282 | 307 |
| 283 } // namespace webrtc | 308 } // namespace webrtc |
| OLD | NEW |