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 DTLSIdentityServiceInterface* dtls_identity_service, | 525 DTLSIdentityServiceInterface* dtls_identity_service, |
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_service != nullptr); |
| 529 |
| 530 if (!InitializeCommon(options, constraints, rtc_configuration)) { |
| 531 // Since we have the ownership of |dtls_identity_service| and will not |
| 532 // pass it to WebRtcSessionDescriptionFactory it is our job to delete it. |
| 533 delete dtls_identity_service; |
| 534 return false; |
| 535 } |
| 536 |
| 537 if (dtls_enabled_) { |
| 538 // Note: the factory takes ownership of |dtls_identity_service|. |
| 539 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 540 signaling_thread(), |
| 541 worker_thread(), |
| 542 channel_manager_, |
| 543 mediastream_signaling_, |
| 544 dtls_identity_service, |
| 545 this, |
| 546 id(), |
| 547 data_channel_type_)); |
| 548 } else { |
| 549 if (dtls_identity_service) { |
| 550 // Since we have the ownership of |dtls_identity_service| and will not |
| 551 // pass it to WebRtcSessionDescriptionFactory it is our job to delete it. |
| 552 delete dtls_identity_service; |
| 553 } |
| 554 |
| 555 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 556 signaling_thread(), |
| 557 worker_thread(), |
| 558 channel_manager_, |
| 559 mediastream_signaling_, |
| 560 this, |
| 561 id(), |
| 562 data_channel_type_)); |
| 563 } |
| 564 InitializeFactoryAfterConstruction(options); |
| 565 return true; |
| 566 } |
| 567 |
| 568 bool WebRtcSession::Initialize( |
| 569 const PeerConnectionFactoryInterface::Options& options, |
| 570 const MediaConstraintsInterface* constraints, |
| 571 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate, |
| 572 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| 573 DCHECK(certificate.get()); |
| 574 |
| 575 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon. |
| 576 dtls_enabled_ = true; |
| 577 |
| 578 if (!InitializeCommon(options, constraints, rtc_configuration)) { |
| 579 return false; |
| 580 } |
| 581 |
| 582 if (dtls_enabled_) { |
| 583 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 584 signaling_thread(), |
| 585 worker_thread(), |
| 586 channel_manager_, |
| 587 mediastream_signaling_, |
| 588 certificate, |
| 589 this, |
| 590 id(), |
| 591 data_channel_type_)); |
| 592 } else { |
| 593 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
| 594 signaling_thread(), |
| 595 worker_thread(), |
| 596 channel_manager_, |
| 597 mediastream_signaling_, |
| 598 this, |
| 599 id(), |
| 600 data_channel_type_)); |
| 601 } |
| 602 InitializeFactoryAfterConstruction(options); |
| 603 return true; |
| 604 } |
| 605 |
| 606 void WebRtcSession::InitializeFactoryAfterConstruction( |
| 607 const PeerConnectionFactoryInterface::Options& options) { |
| 608 webrtc_session_desc_factory_->SignalCertificateReady.connect( |
| 609 this, &WebRtcSession::OnCertificateReady); |
| 610 if (options.disable_encryption) { |
| 611 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
| 612 } |
| 613 } |
| 614 |
| 615 bool WebRtcSession::InitializeCommon( |
| 616 const PeerConnectionFactoryInterface::Options& options, |
| 617 const MediaConstraintsInterface* constraints, |
| 618 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
528 bundle_policy_ = rtc_configuration.bundle_policy; | 619 bundle_policy_ = rtc_configuration.bundle_policy; |
529 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 620 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
530 SetSslMaxProtocolVersion(options.ssl_max_version); | 621 SetSslMaxProtocolVersion(options.ssl_max_version); |
531 | 622 |
532 // TODO(perkj): Take |constraints| into consideration. Return false if not all | 623 // TODO(perkj): Take |constraints| into consideration. Return false if not all |
533 // mandatory constraints can be fulfilled. Note that |constraints| | 624 // mandatory constraints can be fulfilled. Note that |constraints| |
534 // can be null. | 625 // can be null. |
535 bool value; | 626 bool value; |
536 | 627 |
537 if (options.disable_encryption) { | 628 if (options.disable_encryption) { |
538 dtls_enabled_ = false; | 629 dtls_enabled_ = false; |
539 } else { | 630 } else { |
540 // Enable DTLS by default if |dtls_identity_service| is valid. | |
541 dtls_enabled_ = (dtls_identity_service != NULL); | |
542 // |constraints| can override the default |dtls_enabled_| value. | 631 // |constraints| can override the default |dtls_enabled_| value. |
543 if (FindConstraint( | 632 if (FindConstraint( |
544 constraints, | 633 constraints, |
545 MediaConstraintsInterface::kEnableDtlsSrtp, | 634 MediaConstraintsInterface::kEnableDtlsSrtp, |
546 &value, NULL)) { | 635 &value, nullptr)) { |
547 dtls_enabled_ = value; | 636 dtls_enabled_ = value; |
548 } | 637 } |
549 } | 638 } |
550 | 639 |
551 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. | 640 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. |
552 // It takes precendence over the disable_sctp_data_channels | 641 // It takes precendence over the disable_sctp_data_channels |
553 // PeerConnectionFactoryInterface::Options. | 642 // PeerConnectionFactoryInterface::Options. |
554 if (FindConstraint( | 643 if (FindConstraint( |
555 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, | 644 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, |
556 &value, NULL) && value) { | 645 &value, NULL) && value) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 const cricket::VideoCodec default_codec( | 742 const cricket::VideoCodec default_codec( |
654 JsepSessionDescription::kDefaultVideoCodecId, | 743 JsepSessionDescription::kDefaultVideoCodecId, |
655 JsepSessionDescription::kDefaultVideoCodecName, | 744 JsepSessionDescription::kDefaultVideoCodecName, |
656 JsepSessionDescription::kMaxVideoCodecWidth, | 745 JsepSessionDescription::kMaxVideoCodecWidth, |
657 JsepSessionDescription::kMaxVideoCodecHeight, | 746 JsepSessionDescription::kMaxVideoCodecHeight, |
658 JsepSessionDescription::kDefaultVideoCodecFramerate, | 747 JsepSessionDescription::kDefaultVideoCodecFramerate, |
659 JsepSessionDescription::kDefaultVideoCodecPreference); | 748 JsepSessionDescription::kDefaultVideoCodecPreference); |
660 channel_manager_->SetDefaultVideoEncoderConfig( | 749 channel_manager_->SetDefaultVideoEncoderConfig( |
661 cricket::VideoEncoderConfig(default_codec)); | 750 cricket::VideoEncoderConfig(default_codec)); |
662 | 751 |
663 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | |
664 signaling_thread(), | |
665 channel_manager_, | |
666 mediastream_signaling_, | |
667 dtls_identity_service, | |
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( | 752 port_allocator()->set_candidate_filter( |
680 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); | 753 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); |
| 754 |
681 return true; | 755 return true; |
682 } | 756 } |
683 | 757 |
684 void WebRtcSession::Terminate() { | 758 void WebRtcSession::Terminate() { |
685 SetState(STATE_RECEIVEDTERMINATE); | 759 SetState(STATE_RECEIVEDTERMINATE); |
686 RemoveUnusedChannelsAndTransports(NULL); | 760 RemoveUnusedChannelsAndTransports(NULL); |
687 ASSERT(!voice_channel_); | 761 ASSERT(!voice_channel_); |
688 ASSERT(!video_channel_); | 762 ASSERT(!video_channel_); |
689 ASSERT(!data_channel_); | 763 ASSERT(!data_channel_); |
690 } | 764 } |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 } | 1371 } |
1298 | 1372 |
1299 bool WebRtcSession::IceRestartPending() const { | 1373 bool WebRtcSession::IceRestartPending() const { |
1300 return ice_restart_latch_->Get(); | 1374 return ice_restart_latch_->Get(); |
1301 } | 1375 } |
1302 | 1376 |
1303 void WebRtcSession::ResetIceRestartLatch() { | 1377 void WebRtcSession::ResetIceRestartLatch() { |
1304 ice_restart_latch_->Reset(); | 1378 ice_restart_latch_->Reset(); |
1305 } | 1379 } |
1306 | 1380 |
1307 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { | 1381 void WebRtcSession::OnCertificateReady( |
1308 SetIdentity(identity); | 1382 rtc::scoped_refptr<DtlsCertificate> certificate) { |
| 1383 certificate_ = certificate; |
| 1384 SetCertificate(certificate_); |
1309 } | 1385 } |
1310 | 1386 |
1311 bool WebRtcSession::waiting_for_identity() const { | 1387 bool WebRtcSession::waiting_for_certificate() const { |
1312 return webrtc_session_desc_factory_->waiting_for_identity(); | 1388 return webrtc_session_desc_factory_->waiting_for_certificate(); |
| 1389 } |
| 1390 |
| 1391 rtc::scoped_refptr<DtlsCertificate> WebRtcSession::get_certificate() const { |
| 1392 return certificate_; |
1313 } | 1393 } |
1314 | 1394 |
1315 void WebRtcSession::SetIceConnectionState( | 1395 void WebRtcSession::SetIceConnectionState( |
1316 PeerConnectionInterface::IceConnectionState state) { | 1396 PeerConnectionInterface::IceConnectionState state) { |
1317 if (ice_connection_state_ == state) { | 1397 if (ice_connection_state_ == state) { |
1318 return; | 1398 return; |
1319 } | 1399 } |
1320 | 1400 |
1321 // ASSERT that the requested transition is allowed. Note that | 1401 // ASSERT that the requested transition is allowed. Note that |
1322 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled | 1402 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 | 2045 |
1966 if (!srtp_cipher.empty()) { | 2046 if (!srtp_cipher.empty()) { |
1967 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); | 2047 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); |
1968 } | 2048 } |
1969 if (!ssl_cipher.empty()) { | 2049 if (!ssl_cipher.empty()) { |
1970 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); | 2050 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); |
1971 } | 2051 } |
1972 } | 2052 } |
1973 | 2053 |
1974 } // namespace webrtc | 2054 } // namespace webrtc |
OLD | NEW |