Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "talk/app/webrtc/videotrack.h" | 42 #include "talk/app/webrtc/videotrack.h" |
| 43 #include "talk/media/devices/dummydevicemanager.h" | 43 #include "talk/media/devices/dummydevicemanager.h" |
| 44 #include "talk/media/webrtc/webrtcmediaengine.h" | 44 #include "talk/media/webrtc/webrtcmediaengine.h" |
| 45 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" | 45 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
| 46 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" | 46 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
| 47 #include "webrtc/base/bind.h" | 47 #include "webrtc/base/bind.h" |
| 48 #include "webrtc/modules/audio_device/include/audio_device.h" | 48 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 49 | 49 |
| 50 namespace webrtc { | 50 namespace webrtc { |
| 51 | 51 |
| 52 namespace { | |
| 53 | |
| 54 class BlockingIdentityRequestObserver : public DTLSIdentityRequestObserver { | |
| 55 public: | |
| 56 BlockingIdentityRequestObserver( | |
| 57 rtc::scoped_refptr<DtlsCertificate>* out_certificate) | |
| 58 : has_been_called_(false), | |
| 59 out_certificate_(out_certificate) { | |
| 60 DCHECK(out_certificate_); | |
| 61 } | |
| 62 | |
| 63 void OnFailure(int error) override { | |
| 64 ReturnIdentity(nullptr); | |
| 65 } | |
| 66 void OnSuccess(const std::string& der_cert, | |
| 67 const std::string& der_private_key) override { | |
| 68 std::string pem_cert = rtc::SSLIdentity::DerToPem( | |
| 69 rtc::kPemTypeCertificate, | |
| 70 reinterpret_cast<const unsigned char*>(der_cert.data()), | |
| 71 der_cert.length()); | |
| 72 std::string pem_key = rtc::SSLIdentity::DerToPem( | |
| 73 rtc::kPemTypeRsaPrivateKey, | |
| 74 reinterpret_cast<const unsigned char*>(der_private_key.data()), | |
| 75 der_private_key.length()); | |
| 76 rtc::scoped_ptr<rtc::SSLIdentity> identity( | |
| 77 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert)); | |
| 78 OnSuccessWithIdentityObj(identity.Pass()); | |
| 79 } | |
| 80 void OnSuccessWithIdentityObj( | |
| 81 rtc::scoped_ptr<rtc::SSLIdentity> identity) override { | |
| 82 ReturnIdentity(identity.Pass()); | |
| 83 } | |
| 84 | |
| 85 void WaitForIdentity() { | |
| 86 // Process messages while waiting for |has_been_called_| to become true. | |
| 87 // If the service generating the identity is Posting to the current thread | |
| 88 // then processing messages is necessary for identity generation to finish | |
| 89 // (waiting without processing would block forever). | |
| 90 while (!has_been_called_) { | |
| 91 rtc::Thread::Current()->ProcessMessages(1); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 void ReturnIdentity(rtc::scoped_ptr<rtc::SSLIdentity> identity) { | |
| 97 if (identity.get()) | |
| 98 *out_certificate_ = DtlsCertificate::Create(identity.Pass()); | |
| 99 else | |
| 100 *out_certificate_ = nullptr; | |
| 101 has_been_called_ = true; | |
| 102 } | |
| 103 | |
| 104 volatile bool has_been_called_; | |
| 105 rtc::scoped_refptr<DtlsCertificate>* out_certificate_; | |
| 106 }; | |
| 107 | |
| 108 } // anonymous namespace | |
| 109 | |
| 52 rtc::scoped_refptr<PeerConnectionFactoryInterface> | 110 rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 53 CreatePeerConnectionFactory() { | 111 CreatePeerConnectionFactory() { |
| 54 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( | 112 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 55 new rtc::RefCountedObject<PeerConnectionFactory>()); | 113 new rtc::RefCountedObject<PeerConnectionFactory>()); |
| 56 | 114 |
| 57 | 115 |
| 58 // Call Initialize synchronously but make sure its executed on | 116 // Call Initialize synchronously but make sure its executed on |
| 59 // |signaling_thread|. | 117 // |signaling_thread|. |
| 60 MethodCall0<PeerConnectionFactory, bool> call( | 118 MethodCall0<PeerConnectionFactory, bool> call( |
| 61 pc_factory.get(), | 119 pc_factory.get(), |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { | 256 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { |
| 199 DCHECK(signaling_thread_->IsCurrent()); | 257 DCHECK(signaling_thread_->IsCurrent()); |
| 200 return channel_manager_->StartAecDump(file); | 258 return channel_manager_->StartAecDump(file); |
| 201 } | 259 } |
| 202 | 260 |
| 203 rtc::scoped_refptr<PeerConnectionInterface> | 261 rtc::scoped_refptr<PeerConnectionInterface> |
| 204 PeerConnectionFactory::CreatePeerConnection( | 262 PeerConnectionFactory::CreatePeerConnection( |
| 205 const PeerConnectionInterface::RTCConfiguration& configuration, | 263 const PeerConnectionInterface::RTCConfiguration& configuration, |
| 206 const MediaConstraintsInterface* constraints, | 264 const MediaConstraintsInterface* constraints, |
| 207 PortAllocatorFactoryInterface* allocator_factory, | 265 PortAllocatorFactoryInterface* allocator_factory, |
| 208 DTLSIdentityServiceInterface* dtls_identity_service, | 266 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate, |
| 209 PeerConnectionObserver* observer) { | 267 PeerConnectionObserver* observer) { |
| 210 DCHECK(signaling_thread_->IsCurrent()); | 268 DCHECK(signaling_thread_->IsCurrent()); |
| 211 DCHECK(allocator_factory || default_allocator_factory_); | 269 DCHECK(allocator_factory || default_allocator_factory_); |
| 212 | 270 |
| 213 if (!dtls_identity_service) { | |
| 214 dtls_identity_service = new DtlsIdentityService(dtls_identity_store_.get()); | |
| 215 } | |
| 216 | |
| 217 PortAllocatorFactoryInterface* chosen_allocator_factory = | 271 PortAllocatorFactoryInterface* chosen_allocator_factory = |
| 218 allocator_factory ? allocator_factory : default_allocator_factory_.get(); | 272 allocator_factory ? allocator_factory : default_allocator_factory_.get(); |
| 219 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); | 273 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); |
| 220 | 274 |
| 221 rtc::scoped_refptr<PeerConnection> pc( | 275 rtc::scoped_refptr<PeerConnection> pc( |
| 222 new rtc::RefCountedObject<PeerConnection>(this)); | 276 new rtc::RefCountedObject<PeerConnection>(this)); |
| 223 if (!pc->Initialize( | 277 if (!pc->Initialize( |
| 224 configuration, | 278 configuration, |
| 225 constraints, | 279 constraints, |
| 226 chosen_allocator_factory, | 280 chosen_allocator_factory, |
| 227 dtls_identity_service, | 281 certificate, |
| 228 observer)) { | 282 observer)) { |
| 229 return NULL; | 283 return NULL; |
| 230 } | 284 } |
| 231 return PeerConnectionProxy::Create(signaling_thread(), pc); | 285 return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 232 } | 286 } |
| 233 | 287 |
| 288 rtc::scoped_refptr<PeerConnectionInterface> | |
| 289 PeerConnectionFactory::CreatePeerConnection( | |
| 290 const PeerConnectionInterface::RTCConfiguration& configuration, | |
| 291 const MediaConstraintsInterface* constraints, | |
| 292 PortAllocatorFactoryInterface* allocator_factory, | |
| 293 DTLSIdentityServiceInterface* dtls_identity_service, | |
| 294 PeerConnectionObserver* observer) { | |
|
hbos
2015/08/04 12:50:21
This version of CreatePeerConnection uses the old
| |
| 295 DCHECK(signaling_thread_->IsCurrent()); | |
| 296 | |
| 297 if (!dtls_identity_service) { | |
| 298 dtls_identity_service = new DtlsIdentityService(dtls_identity_store_.get()); | |
| 299 } | |
| 300 // TODO(hbos): This certificate generation is a blocking operation and does | |
| 301 // not inform if the generation failed (but then a null certificate will be | |
| 302 // passed and some failure will likely occur later). This function signature | |
| 303 // only exists temporarily as to not break Chromium. It shall be removed ASAP. | |
| 304 rtc::scoped_refptr<DtlsCertificate> certificate; | |
| 305 rtc::scoped_refptr<BlockingIdentityRequestObserver> cert_blocking_observer( | |
| 306 new rtc::RefCountedObject<BlockingIdentityRequestObserver>(&certificate)); | |
| 307 dtls_identity_service->RequestIdentity( | |
| 308 DtlsIdentityStore::kIdentityName, DtlsIdentityStore::kIdentityName, | |
| 309 cert_blocking_observer.get()); | |
| 310 cert_blocking_observer->WaitForIdentity(); | |
| 311 // Having taken ownership of |dtls_identity_service| it is up to us to delete. | |
| 312 delete dtls_identity_service; | |
| 313 dtls_identity_service = nullptr; | |
| 314 | |
| 315 return CreatePeerConnection(configuration, constraints, allocator_factory, | |
| 316 certificate, observer); | |
| 317 } | |
| 318 | |
| 234 rtc::scoped_refptr<MediaStreamInterface> | 319 rtc::scoped_refptr<MediaStreamInterface> |
| 235 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { | 320 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { |
| 236 DCHECK(signaling_thread_->IsCurrent()); | 321 DCHECK(signaling_thread_->IsCurrent()); |
| 237 return MediaStreamProxy::Create(signaling_thread_, | 322 return MediaStreamProxy::Create(signaling_thread_, |
| 238 MediaStream::Create(label)); | 323 MediaStream::Create(label)); |
| 239 } | 324 } |
| 240 | 325 |
| 241 rtc::scoped_refptr<VideoTrackInterface> | 326 rtc::scoped_refptr<VideoTrackInterface> |
| 242 PeerConnectionFactory::CreateVideoTrack( | 327 PeerConnectionFactory::CreateVideoTrack( |
| 243 const std::string& id, | 328 const std::string& id, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 274 } | 359 } |
| 275 | 360 |
| 276 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { | 361 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { |
| 277 ASSERT(worker_thread_ == rtc::Thread::Current()); | 362 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 278 return cricket::WebRtcMediaEngineFactory::Create( | 363 return cricket::WebRtcMediaEngineFactory::Create( |
| 279 default_adm_.get(), video_encoder_factory_.get(), | 364 default_adm_.get(), video_encoder_factory_.get(), |
| 280 video_decoder_factory_.get()); | 365 video_decoder_factory_.get()); |
| 281 } | 366 } |
| 282 | 367 |
| 283 } // namespace webrtc | 368 } // namespace webrtc |
| OLD | NEW |