OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 SignalVoiceChannelDestroyed(); | 510 SignalVoiceChannelDestroyed(); |
511 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr); | 511 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr); |
512 } | 512 } |
513 if (data_channel_) { | 513 if (data_channel_) { |
514 SignalDataChannelDestroyed(); | 514 SignalDataChannelDestroyed(); |
515 channel_manager_->DestroyDataChannel(data_channel_.release()); | 515 channel_manager_->DestroyDataChannel(data_channel_.release()); |
516 } | 516 } |
517 for (size_t i = 0; i < saved_candidates_.size(); ++i) { | 517 for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
518 delete saved_candidates_[i]; | 518 delete saved_candidates_[i]; |
519 } | 519 } |
520 delete identity(); | |
521 } | 520 } |
522 | 521 |
523 bool WebRtcSession::Initialize( | 522 bool WebRtcSession::Initialize( |
524 const PeerConnectionFactoryInterface::Options& options, | 523 const PeerConnectionFactoryInterface::Options& options, |
525 const MediaConstraintsInterface* constraints, | 524 const MediaConstraintsInterface* constraints, |
526 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 525 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
527 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 526 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| 527 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon. |
| 528 dtls_enabled_ = (dtls_identity_store != nullptr); |
| 529 |
| 530 if (!InitializeInternal(options, constraints, rtc_configuration)) { |
| 531 return false; |
| 532 } |
| 533 |
| 534 if (dtls_enabled_) { |
| 535 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 536 signaling_thread(), |
| 537 worker_thread(), |
| 538 channel_manager_, |
| 539 mediastream_signaling_, |
| 540 dtls_identity_store.Pass(), |
| 541 this, |
| 542 id(), |
| 543 data_channel_type_)); |
| 544 } else { |
| 545 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 546 signaling_thread(), |
| 547 worker_thread(), |
| 548 channel_manager_, |
| 549 mediastream_signaling_, |
| 550 this, |
| 551 id(), |
| 552 data_channel_type_)); |
| 553 } |
| 554 InitializeFactoryAfterConstruction(options); |
| 555 return true; |
| 556 } |
| 557 |
| 558 bool WebRtcSession::Initialize( |
| 559 const PeerConnectionFactoryInterface::Options& options, |
| 560 const MediaConstraintsInterface* constraints, |
| 561 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate, |
| 562 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| 563 DCHECK(certificate.get()); |
| 564 |
| 565 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon. |
| 566 dtls_enabled_ = true; |
| 567 |
| 568 if (!InitializeInternal(options, constraints, rtc_configuration)) { |
| 569 return false; |
| 570 } |
| 571 |
| 572 if (dtls_enabled_) { |
| 573 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 574 signaling_thread(), |
| 575 worker_thread(), |
| 576 channel_manager_, |
| 577 mediastream_signaling_, |
| 578 certificate, |
| 579 this, |
| 580 id(), |
| 581 data_channel_type_)); |
| 582 } else { |
| 583 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 584 signaling_thread(), |
| 585 worker_thread(), |
| 586 channel_manager_, |
| 587 mediastream_signaling_, |
| 588 this, |
| 589 id(), |
| 590 data_channel_type_)); |
| 591 } |
| 592 InitializeFactoryAfterConstruction(options); |
| 593 return true; |
| 594 } |
| 595 |
| 596 bool WebRtcSession::InitializeInternal( |
| 597 const PeerConnectionFactoryInterface::Options& options, |
| 598 const MediaConstraintsInterface* constraints, |
| 599 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
528 bundle_policy_ = rtc_configuration.bundle_policy; | 600 bundle_policy_ = rtc_configuration.bundle_policy; |
529 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 601 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
530 SetSslMaxProtocolVersion(options.ssl_max_version); | 602 SetSslMaxProtocolVersion(options.ssl_max_version); |
531 | 603 |
532 // TODO(perkj): Take |constraints| into consideration. Return false if not all | 604 // TODO(perkj): Take |constraints| into consideration. Return false if not all |
533 // mandatory constraints can be fulfilled. Note that |constraints| | 605 // mandatory constraints can be fulfilled. Note that |constraints| |
534 // can be null. | 606 // can be null. |
535 bool value; | 607 bool value; |
536 | 608 |
537 if (options.disable_encryption) { | 609 if (options.disable_encryption) { |
538 dtls_enabled_ = false; | 610 dtls_enabled_ = false; |
539 } else { | 611 } else { |
540 // Enable DTLS by default if we have a |dtls_identity_store|. | |
541 dtls_enabled_ = (dtls_identity_store != nullptr); | |
542 // |constraints| can override the default |dtls_enabled_| value. | 612 // |constraints| can override the default |dtls_enabled_| value. |
543 if (FindConstraint( | 613 if (FindConstraint( |
544 constraints, | 614 constraints, |
545 MediaConstraintsInterface::kEnableDtlsSrtp, | 615 MediaConstraintsInterface::kEnableDtlsSrtp, |
546 &value, NULL)) { | 616 &value, nullptr)) { |
547 dtls_enabled_ = value; | 617 dtls_enabled_ = value; |
548 } | 618 } |
549 } | 619 } |
550 | 620 |
551 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. | 621 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |
552 // It takes precendence over the disable_sctp_data_channels | 622 // It takes precendence over the disable_sctp_data_channels |
553 // PeerConnectionFactoryInterface::Options. | 623 // PeerConnectionFactoryInterface::Options. |
554 if (FindConstraint( | 624 if (FindConstraint( |
555 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, | 625 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, |
556 &value, NULL) && value) { | 626 &value, NULL) && value) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 const cricket::VideoCodec default_codec( | 723 const cricket::VideoCodec default_codec( |
654 JsepSessionDescription::kDefaultVideoCodecId, | 724 JsepSessionDescription::kDefaultVideoCodecId, |
655 JsepSessionDescription::kDefaultVideoCodecName, | 725 JsepSessionDescription::kDefaultVideoCodecName, |
656 JsepSessionDescription::kMaxVideoCodecWidth, | 726 JsepSessionDescription::kMaxVideoCodecWidth, |
657 JsepSessionDescription::kMaxVideoCodecHeight, | 727 JsepSessionDescription::kMaxVideoCodecHeight, |
658 JsepSessionDescription::kDefaultVideoCodecFramerate, | 728 JsepSessionDescription::kDefaultVideoCodecFramerate, |
659 JsepSessionDescription::kDefaultVideoCodecPreference); | 729 JsepSessionDescription::kDefaultVideoCodecPreference); |
660 channel_manager_->SetDefaultVideoEncoderConfig( | 730 channel_manager_->SetDefaultVideoEncoderConfig( |
661 cricket::VideoEncoderConfig(default_codec)); | 731 cricket::VideoEncoderConfig(default_codec)); |
662 | 732 |
663 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | |
664 signaling_thread(), | |
665 channel_manager_, | |
666 mediastream_signaling_, | |
667 dtls_identity_store.Pass(), | |
668 this, | |
669 id(), | |
670 data_channel_type_, | |
671 dtls_enabled_)); | |
672 | |
673 webrtc_session_desc_factory_->SignalIdentityReady.connect( | |
674 this, &WebRtcSession::OnIdentityReady); | |
675 | |
676 if (options.disable_encryption) { | |
677 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); | |
678 } | |
679 port_allocator()->set_candidate_filter( | 733 port_allocator()->set_candidate_filter( |
680 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); | 734 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); |
681 return true; | 735 return true; |
682 } | 736 } |
683 | 737 |
| 738 void WebRtcSession::InitializeFactoryAfterConstruction( |
| 739 const PeerConnectionFactoryInterface::Options& options) { |
| 740 webrtc_session_desc_factory_->SignalCertificateReady.connect( |
| 741 this, &WebRtcSession::OnCertificateReady); |
| 742 if (options.disable_encryption) { |
| 743 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
| 744 } |
| 745 } |
| 746 |
684 void WebRtcSession::Terminate() { | 747 void WebRtcSession::Terminate() { |
685 SetState(STATE_RECEIVEDTERMINATE); | 748 SetState(STATE_RECEIVEDTERMINATE); |
686 RemoveUnusedChannelsAndTransports(NULL); | 749 RemoveUnusedChannelsAndTransports(NULL); |
687 ASSERT(!voice_channel_); | 750 ASSERT(!voice_channel_); |
688 ASSERT(!video_channel_); | 751 ASSERT(!video_channel_); |
689 ASSERT(!data_channel_); | 752 ASSERT(!data_channel_); |
690 } | 753 } |
691 | 754 |
692 bool WebRtcSession::StartCandidatesAllocation() { | 755 bool WebRtcSession::StartCandidatesAllocation() { |
693 // SpeculativelyConnectTransportChannels, will call ConnectChannels method | 756 // SpeculativelyConnectTransportChannels, will call ConnectChannels method |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 } | 1360 } |
1298 | 1361 |
1299 bool WebRtcSession::IceRestartPending() const { | 1362 bool WebRtcSession::IceRestartPending() const { |
1300 return ice_restart_latch_->Get(); | 1363 return ice_restart_latch_->Get(); |
1301 } | 1364 } |
1302 | 1365 |
1303 void WebRtcSession::ResetIceRestartLatch() { | 1366 void WebRtcSession::ResetIceRestartLatch() { |
1304 ice_restart_latch_->Reset(); | 1367 ice_restart_latch_->Reset(); |
1305 } | 1368 } |
1306 | 1369 |
1307 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { | 1370 void WebRtcSession::OnCertificateReady( |
1308 SetIdentity(identity); | 1371 const rtc::scoped_refptr<DtlsCertificate>& certificate) { |
| 1372 certificate_ = certificate; |
| 1373 SetCertificate(certificate_); |
1309 } | 1374 } |
1310 | 1375 |
1311 bool WebRtcSession::waiting_for_identity() const { | 1376 bool WebRtcSession::IsWaitingForCertificate() const { |
1312 return webrtc_session_desc_factory_->waiting_for_identity(); | 1377 return webrtc_session_desc_factory_->waiting_for_certificate(); |
1313 } | 1378 } |
1314 | 1379 |
1315 void WebRtcSession::SetIceConnectionState( | 1380 void WebRtcSession::SetIceConnectionState( |
1316 PeerConnectionInterface::IceConnectionState state) { | 1381 PeerConnectionInterface::IceConnectionState state) { |
1317 if (ice_connection_state_ == state) { | 1382 if (ice_connection_state_ == state) { |
1318 return; | 1383 return; |
1319 } | 1384 } |
1320 | 1385 |
1321 // ASSERT that the requested transition is allowed. Note that | 1386 // ASSERT that the requested transition is allowed. Note that |
1322 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled | 1387 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 | 2030 |
1966 if (!srtp_cipher.empty()) { | 2031 if (!srtp_cipher.empty()) { |
1967 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); | 2032 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); |
1968 } | 2033 } |
1969 if (!ssl_cipher.empty()) { | 2034 if (!ssl_cipher.empty()) { |
1970 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); | 2035 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); |
1971 } | 2036 } |
1972 } | 2037 } |
1973 | 2038 |
1974 } // namespace webrtc | 2039 } // namespace webrtc |
OLD | NEW |