Index: talk/app/webrtc/webrtcsession.cc |
diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc |
index b6a178cf392c2a671453de59da79410ac477b658..70a553b70c08f95efabb46103c51e361503fe7e3 100644 |
--- a/talk/app/webrtc/webrtcsession.cc |
+++ b/talk/app/webrtc/webrtcsession.cc |
@@ -517,14 +517,107 @@ WebRtcSession::~WebRtcSession() { |
for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
delete saved_candidates_[i]; |
} |
- delete identity(); |
} |
bool WebRtcSession::Initialize( |
const PeerConnectionFactoryInterface::Options& options, |
- const MediaConstraintsInterface* constraints, |
+ const MediaConstraintsInterface* constraints, |
DTLSIdentityServiceInterface* dtls_identity_service, |
const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
+ // Default |dtls_enabled_| value, may get overwritten in InitializeCommon. |
+ dtls_enabled_ = (dtls_identity_service != nullptr); |
+ |
+ if (!InitializeCommon(options, constraints, rtc_configuration)) { |
+ if (dtls_identity_service) { |
+ // Since we have the ownership of |dtls_identity_service| and will not |
+ // pass it to WebRtcSessionDescriptionFactory it is our job to delete it. |
+ delete dtls_identity_service; |
+ } |
+ return false; |
+ } |
+ |
+ if (dtls_enabled_) { |
+ // Note: the factory takes ownership of |dtls_identity_service|. |
+ webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
+ signaling_thread(), |
+ worker_thread(), |
+ channel_manager_, |
+ mediastream_signaling_, |
+ dtls_identity_service, |
+ this, |
+ id(), |
+ data_channel_type_)); |
+ } else { |
+ if (dtls_identity_service) { |
+ // Since we have the ownership of |dtls_identity_service| and will not |
+ // pass it to WebRtcSessionDescriptionFactory it is our job to delete it. |
+ delete dtls_identity_service; |
+ } |
+ |
+ webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
+ signaling_thread(), |
+ worker_thread(), |
+ channel_manager_, |
+ mediastream_signaling_, |
+ this, |
+ id(), |
+ data_channel_type_)); |
+ } |
+ InitializeFactoryAfterConstruction(options); |
+ return true; |
+} |
+ |
+bool WebRtcSession::Initialize( |
+ const PeerConnectionFactoryInterface::Options& options, |
+ const MediaConstraintsInterface* constraints, |
+ rtc::scoped_refptr<webrtc::DtlsCertificate> certificate, |
+ const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
+ DCHECK(certificate.get()); |
+ |
+ // Default |dtls_enabled_| value, may get overwritten in InitializeCommon. |
+ dtls_enabled_ = true; |
+ |
+ if (!InitializeCommon(options, constraints, rtc_configuration)) { |
+ return false; |
+ } |
+ |
+ if (dtls_enabled_) { |
+ webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
+ signaling_thread(), |
+ worker_thread(), |
+ channel_manager_, |
+ mediastream_signaling_, |
+ certificate, |
+ this, |
+ id(), |
+ data_channel_type_)); |
+ } else { |
+ webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
+ signaling_thread(), |
+ worker_thread(), |
+ channel_manager_, |
+ mediastream_signaling_, |
+ this, |
+ id(), |
+ data_channel_type_)); |
+ } |
+ InitializeFactoryAfterConstruction(options); |
+ return true; |
+} |
+ |
+void WebRtcSession::InitializeFactoryAfterConstruction( |
+ const PeerConnectionFactoryInterface::Options& options) { |
+ webrtc_session_desc_factory_->SignalCertificateReady.connect( |
+ this, &WebRtcSession::OnCertificateReady); |
+ if (options.disable_encryption) { |
+ webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
+ } |
+} |
+ |
+bool WebRtcSession::InitializeCommon( |
+ const PeerConnectionFactoryInterface::Options& options, |
+ const MediaConstraintsInterface* constraints, |
+ const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
bundle_policy_ = rtc_configuration.bundle_policy; |
rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
SetSslMaxProtocolVersion(options.ssl_max_version); |
@@ -537,13 +630,11 @@ bool WebRtcSession::Initialize( |
if (options.disable_encryption) { |
dtls_enabled_ = false; |
} else { |
- // Enable DTLS by default if |dtls_identity_service| is valid. |
- dtls_enabled_ = (dtls_identity_service != NULL); |
// |constraints| can override the default |dtls_enabled_| value. |
if (FindConstraint( |
constraints, |
MediaConstraintsInterface::kEnableDtlsSrtp, |
- &value, NULL)) { |
+ &value, nullptr)) { |
dtls_enabled_ = value; |
} |
} |
@@ -660,22 +751,6 @@ bool WebRtcSession::Initialize( |
channel_manager_->SetDefaultVideoEncoderConfig( |
cricket::VideoEncoderConfig(default_codec)); |
- webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
- signaling_thread(), |
- channel_manager_, |
- mediastream_signaling_, |
- dtls_identity_service, |
- this, |
- id(), |
- data_channel_type_, |
- dtls_enabled_)); |
- |
- webrtc_session_desc_factory_->SignalIdentityReady.connect( |
- this, &WebRtcSession::OnIdentityReady); |
- |
- if (options.disable_encryption) { |
- webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
- } |
port_allocator()->set_candidate_filter( |
ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); |
return true; |
@@ -1304,12 +1379,18 @@ void WebRtcSession::ResetIceRestartLatch() { |
ice_restart_latch_->Reset(); |
} |
-void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { |
- SetIdentity(identity); |
+void WebRtcSession::OnCertificateReady( |
+ rtc::scoped_refptr<DtlsCertificate> certificate) { |
+ certificate_ = certificate; |
+ SetCertificate(certificate_); |
+} |
+ |
+bool WebRtcSession::waiting_for_certificate() const { |
+ return webrtc_session_desc_factory_->waiting_for_certificate(); |
} |
-bool WebRtcSession::waiting_for_identity() const { |
- return webrtc_session_desc_factory_->waiting_for_identity(); |
+rtc::scoped_refptr<DtlsCertificate> WebRtcSession::get_certificate() const { |
+ return certificate_; |
} |
void WebRtcSession::SetIceConnectionState( |