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 13 matching lines...) Expand all Loading... | |
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/webrtcsession.h" | 28 #include "talk/app/webrtc/webrtcsession.h" |
29 | 29 |
30 #include <limits.h> | 30 #include <limits.h> |
31 | 31 |
32 #include <algorithm> | 32 #include <algorithm> |
33 #include <vector> | 33 #include <vector> |
34 #include <set> | |
34 | 35 |
35 #include "talk/app/webrtc/jsepicecandidate.h" | 36 #include "talk/app/webrtc/jsepicecandidate.h" |
36 #include "talk/app/webrtc/jsepsessiondescription.h" | 37 #include "talk/app/webrtc/jsepsessiondescription.h" |
37 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 38 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
38 #include "talk/app/webrtc/mediastreamsignaling.h" | 39 #include "talk/app/webrtc/mediastreamsignaling.h" |
39 #include "talk/app/webrtc/peerconnectioninterface.h" | 40 #include "talk/app/webrtc/peerconnectioninterface.h" |
40 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" | 41 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
41 #include "talk/media/base/constants.h" | 42 #include "talk/media/base/constants.h" |
42 #include "talk/media/base/videocapturer.h" | 43 #include "talk/media/base/videocapturer.h" |
43 #include "talk/session/media/channel.h" | 44 #include "talk/session/media/channel.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
74 const char kSdpWithoutSdesCrypto[] = | 75 const char kSdpWithoutSdesCrypto[] = |
75 "Called with SDP without SDES crypto."; | 76 "Called with SDP without SDES crypto."; |
76 const char kSdpWithoutIceUfragPwd[] = | 77 const char kSdpWithoutIceUfragPwd[] = |
77 "Called with SDP without ice-ufrag and ice-pwd."; | 78 "Called with SDP without ice-ufrag and ice-pwd."; |
78 const char kSessionError[] = "Session error code: "; | 79 const char kSessionError[] = "Session error code: "; |
79 const char kSessionErrorDesc[] = "Session error description: "; | 80 const char kSessionErrorDesc[] = "Session error description: "; |
80 const char kDtlsSetupFailureRtp[] = | 81 const char kDtlsSetupFailureRtp[] = |
81 "Couldn't set up DTLS-SRTP on RTP channel."; | 82 "Couldn't set up DTLS-SRTP on RTP channel."; |
82 const char kDtlsSetupFailureRtcp[] = | 83 const char kDtlsSetupFailureRtcp[] = |
83 "Couldn't set up DTLS-SRTP on RTCP channel."; | 84 "Couldn't set up DTLS-SRTP on RTCP channel."; |
85 const char kEnableBundleFailed[] = "Failed to enable BUNDLE."; | |
84 const int kMaxUnsignalledRecvStreams = 20; | 86 const int kMaxUnsignalledRecvStreams = 20; |
85 | 87 |
86 // Compares |answer| against |offer|. Comparision is done | 88 // Compares |answer| against |offer|. Comparision is done |
87 // for number of m-lines in answer against offer. If matches true will be | 89 // for number of m-lines in answer against offer. If matches true will be |
88 // returned otherwise false. | 90 // returned otherwise false. |
89 static bool VerifyMediaDescriptions( | 91 static bool VerifyMediaDescriptions( |
90 const SessionDescription* answer, const SessionDescription* offer) { | 92 const SessionDescription* answer, const SessionDescription* offer) { |
91 if (offer->contents().size() != answer->contents().size()) | 93 if (offer->contents().size() != answer->contents().size()) |
92 return false; | 94 return false; |
93 | 95 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 WebRtcSession::WebRtcSession( | 476 WebRtcSession::WebRtcSession( |
475 cricket::ChannelManager* channel_manager, | 477 cricket::ChannelManager* channel_manager, |
476 rtc::Thread* signaling_thread, | 478 rtc::Thread* signaling_thread, |
477 rtc::Thread* worker_thread, | 479 rtc::Thread* worker_thread, |
478 cricket::PortAllocator* port_allocator, | 480 cricket::PortAllocator* port_allocator, |
479 MediaStreamSignaling* mediastream_signaling) | 481 MediaStreamSignaling* mediastream_signaling) |
480 : cricket::BaseSession(signaling_thread, | 482 : cricket::BaseSession(signaling_thread, |
481 worker_thread, | 483 worker_thread, |
482 port_allocator, | 484 port_allocator, |
483 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX), | 485 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX), |
484 cricket::NS_JINGLE_RTP, | |
485 false), | 486 false), |
486 // RFC 3264: The numeric value of the session id and version in the | 487 // RFC 3264: The numeric value of the session id and version in the |
487 // o line MUST be representable with a "64 bit signed integer". | 488 // o line MUST be representable with a "64 bit signed integer". |
488 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. | 489 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
489 channel_manager_(channel_manager), | 490 channel_manager_(channel_manager), |
490 mediastream_signaling_(mediastream_signaling), | 491 mediastream_signaling_(mediastream_signaling), |
491 ice_observer_(NULL), | 492 ice_observer_(NULL), |
492 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), | 493 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
493 ice_connection_receiving_(true), | 494 ice_connection_receiving_(true), |
494 older_version_remote_peer_(false), | 495 older_version_remote_peer_(false), |
495 dtls_enabled_(false), | 496 dtls_enabled_(false), |
496 data_channel_type_(cricket::DCT_NONE), | 497 data_channel_type_(cricket::DCT_NONE), |
497 ice_restart_latch_(new IceRestartAnswerLatch), | 498 ice_restart_latch_(new IceRestartAnswerLatch), |
498 metrics_observer_(NULL) { | 499 metrics_observer_(NULL) { |
500 transport_controller()->SignalConnectionState.connect( | |
501 this, &WebRtcSession::OnTransportControllerConnectionState); | |
502 transport_controller()->SignalReceiving.connect( | |
503 this, &WebRtcSession::OnTransportControllerReceiving); | |
504 transport_controller()->SignalGatheringState.connect( | |
505 this, &WebRtcSession::OnTransportControllerGatheringState); | |
506 transport_controller()->SignalCandidatesGathered.connect( | |
507 this, &WebRtcSession::OnTransportControllerCandidatesGathered); | |
499 } | 508 } |
500 | 509 |
501 WebRtcSession::~WebRtcSession() { | 510 WebRtcSession::~WebRtcSession() { |
502 ASSERT(signaling_thread()->IsCurrent()); | 511 ASSERT(signaling_thread()->IsCurrent()); |
503 // Destroy video_channel_ first since it may have a pointer to the | 512 // Destroy video_channel_ first since it may have a pointer to the |
504 // voice_channel_. | 513 // voice_channel_. |
505 if (video_channel_) { | 514 if (video_channel_) { |
506 SignalVideoChannelDestroyed(); | 515 SignalVideoChannelDestroyed(); |
507 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 516 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
508 } | 517 } |
509 if (voice_channel_) { | 518 if (voice_channel_) { |
510 SignalVoiceChannelDestroyed(); | 519 SignalVoiceChannelDestroyed(); |
511 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr); | 520 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr); |
512 } | 521 } |
513 if (data_channel_) { | 522 if (data_channel_) { |
514 SignalDataChannelDestroyed(); | 523 SignalDataChannelDestroyed(); |
515 channel_manager_->DestroyDataChannel(data_channel_.release()); | 524 channel_manager_->DestroyDataChannel(data_channel_.release()); |
516 } | 525 } |
517 for (size_t i = 0; i < saved_candidates_.size(); ++i) { | 526 for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
518 delete saved_candidates_[i]; | 527 delete saved_candidates_[i]; |
519 } | 528 } |
520 delete identity(); | |
521 } | 529 } |
522 | 530 |
523 bool WebRtcSession::Initialize( | 531 bool WebRtcSession::Initialize( |
524 const PeerConnectionFactoryInterface::Options& options, | 532 const PeerConnectionFactoryInterface::Options& options, |
525 const MediaConstraintsInterface* constraints, | 533 const MediaConstraintsInterface* constraints, |
526 DTLSIdentityServiceInterface* dtls_identity_service, | 534 DTLSIdentityServiceInterface* dtls_identity_service, |
527 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 535 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
528 bundle_policy_ = rtc_configuration.bundle_policy; | 536 bundle_policy_ = rtc_configuration.bundle_policy; |
529 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 537 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
530 SetSslMaxProtocolVersion(options.ssl_max_version); | 538 transport_controller()->SetSslMaxProtocolVersion(options.ssl_max_version); |
531 | 539 |
532 // TODO(perkj): Take |constraints| into consideration. Return false if not all | 540 // TODO(perkj): Take |constraints| into consideration. Return false if not all |
533 // mandatory constraints can be fulfilled. Note that |constraints| | 541 // mandatory constraints can be fulfilled. Note that |constraints| |
534 // can be null. | 542 // can be null. |
535 bool value; | 543 bool value; |
536 | 544 |
537 if (options.disable_encryption) { | 545 if (options.disable_encryption) { |
538 dtls_enabled_ = false; | 546 dtls_enabled_ = false; |
539 } else { | 547 } else { |
540 // Enable DTLS by default if |dtls_identity_service| is valid. | 548 // Enable DTLS by default if |dtls_identity_service| is valid. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 if (options.disable_encryption) { | 684 if (options.disable_encryption) { |
677 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); | 685 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
678 } | 686 } |
679 port_allocator()->set_candidate_filter( | 687 port_allocator()->set_candidate_filter( |
680 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); | 688 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); |
681 return true; | 689 return true; |
682 } | 690 } |
683 | 691 |
684 void WebRtcSession::Terminate() { | 692 void WebRtcSession::Terminate() { |
685 SetState(STATE_RECEIVEDTERMINATE); | 693 SetState(STATE_RECEIVEDTERMINATE); |
686 RemoveUnusedChannelsAndTransports(NULL); | 694 RemoveUnusedChannels(NULL); |
687 ASSERT(!voice_channel_); | 695 ASSERT(!voice_channel_); |
688 ASSERT(!video_channel_); | 696 ASSERT(!video_channel_); |
689 ASSERT(!data_channel_); | 697 ASSERT(!data_channel_); |
690 } | 698 } |
691 | 699 |
692 bool WebRtcSession::StartCandidatesAllocation() { | 700 bool WebRtcSession::StartGatheringCandidates() { |
693 // SpeculativelyConnectTransportChannels, will call ConnectChannels method | |
694 // from TransportProxy to start gathering ice candidates. | |
695 SpeculativelyConnectAllTransportChannels(); | |
696 if (!saved_candidates_.empty()) { | 701 if (!saved_candidates_.empty()) { |
697 // If there are saved candidates which arrived before local description is | 702 // If there are saved candidates which arrived before local description is |
698 // set, copy those to remote description. | 703 // set, copy those to remote description. |
699 CopySavedCandidates(remote_desc_.get()); | 704 CopySavedCandidates(remote_desc_.get()); |
700 } | 705 } |
701 // Push remote candidates present in remote description to transport channels. | 706 // Push remote candidates present in remote description to transport channels. |
702 UseCandidatesInSessionDescription(remote_desc_.get()); | 707 UseCandidatesInSessionDescription(remote_desc_.get()); |
703 return true; | 708 return true; |
704 } | 709 } |
705 | 710 |
706 void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) { | 711 void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) { |
707 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy); | 712 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy); |
708 } | 713 } |
709 | 714 |
710 cricket::SecurePolicy WebRtcSession::SdesPolicy() const { | 715 cricket::SecurePolicy WebRtcSession::SdesPolicy() const { |
711 return webrtc_session_desc_factory_->SdesPolicy(); | 716 return webrtc_session_desc_factory_->SdesPolicy(); |
712 } | 717 } |
713 | 718 |
714 bool WebRtcSession::GetSslRole(rtc::SSLRole* role) { | 719 bool WebRtcSession::GetSslRole(rtc::SSLRole* role) { |
715 if (local_description() == NULL || remote_description() == NULL) { | 720 if (local_description() == NULL || remote_description() == NULL) { |
716 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " | 721 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " |
717 << "SSL Role of the session."; | 722 << "SSL Role of the session."; |
718 return false; | 723 return false; |
719 } | 724 } |
720 | 725 |
721 // TODO(mallinath) - Return role of each transport, as role may differ from | 726 return transport_controller()->GetSslRole(role); |
722 // one another. | |
723 // In current implementaion we just return the role of first transport in the | |
724 // transport map. | |
725 for (cricket::TransportMap::const_iterator iter = transport_proxies().begin(); | |
726 iter != transport_proxies().end(); ++iter) { | |
727 if (iter->second->impl()) { | |
728 return iter->second->impl()->GetSslRole(role); | |
729 } | |
730 } | |
731 return false; | |
732 } | 727 } |
733 | 728 |
734 void WebRtcSession::CreateOffer( | 729 void WebRtcSession::CreateOffer( |
735 CreateSessionDescriptionObserver* observer, | 730 CreateSessionDescriptionObserver* observer, |
736 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { | 731 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
737 webrtc_session_desc_factory_->CreateOffer(observer, options); | 732 webrtc_session_desc_factory_->CreateOffer(observer, options); |
738 } | 733 } |
739 | 734 |
740 void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer, | 735 void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer, |
741 const MediaConstraintsInterface* constraints) { | 736 const MediaConstraintsInterface* constraints) { |
742 webrtc_session_desc_factory_->CreateAnswer(observer, constraints); | 737 webrtc_session_desc_factory_->CreateAnswer(observer, constraints); |
743 } | 738 } |
744 | 739 |
745 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, | 740 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
746 std::string* err_desc) { | 741 std::string* err_desc) { |
742 ASSERT(signaling_thread()->IsCurrent()); | |
743 | |
747 // Takes the ownership of |desc| regardless of the result. | 744 // Takes the ownership of |desc| regardless of the result. |
748 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 745 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
749 | 746 |
750 // Validate SDP. | 747 // Validate SDP. |
751 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { | 748 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { |
752 return false; | 749 return false; |
753 } | 750 } |
754 | 751 |
755 // Update the initiator flag if this session is the initiator. | 752 // Update the initiator flag if this session is the initiator. |
756 Action action = GetAction(desc->type()); | 753 Action action = GetAction(desc->type()); |
(...skipping 12 matching lines...) Expand all Loading... | |
769 set_local_description(desc->description()->Copy()); | 766 set_local_description(desc->description()->Copy()); |
770 local_desc_.reset(desc_temp.release()); | 767 local_desc_.reset(desc_temp.release()); |
771 | 768 |
772 // Transport and Media channels will be created only when offer is set. | 769 // Transport and Media channels will be created only when offer is set. |
773 if (action == kOffer && !CreateChannels(local_desc_->description())) { | 770 if (action == kOffer && !CreateChannels(local_desc_->description())) { |
774 // TODO(mallinath) - Handle CreateChannel failure, as new local description | 771 // TODO(mallinath) - Handle CreateChannel failure, as new local description |
775 // is applied. Restore back to old description. | 772 // is applied. Restore back to old description. |
776 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); | 773 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); |
777 } | 774 } |
778 | 775 |
779 // Remove channel and transport proxies, if MediaContentDescription is | 776 // Enable BUNDLE before when kMaxBundle policy is in effect |
780 // rejected. | 777 if (bundle_policy_ == PeerConnectionInterface::kBundlePolicyMaxBundle) { |
781 RemoveUnusedChannelsAndTransports(local_desc_->description()); | 778 const cricket::ContentGroup* local_bundle = |
779 BaseSession::local_description()->GetGroupByName( | |
780 cricket::GROUP_TYPE_BUNDLE); | |
781 if (!local_bundle) { | |
782 LOG(LS_WARNING) << "max-bundle specified without BUNDLE specified"; | |
783 return false; | |
784 } | |
785 if (!EnableBundle(*local_bundle)) { | |
786 LOG(LS_WARNING) << "max-bundle failed to enable bundling."; | |
787 return false; | |
788 } | |
789 } | |
790 | |
791 // Remove unused channels if MediaContentDescription is rejected. | |
792 RemoveUnusedChannels(local_desc_->description()); | |
782 | 793 |
783 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { | 794 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { |
784 return false; | 795 return false; |
785 } | 796 } |
786 | 797 |
787 // Kick starting the ice candidates allocation. | 798 // Kick starting the ice candidates allocation. |
788 StartCandidatesAllocation(); | 799 StartGatheringCandidates(); |
pthatcher1
2015/08/18 22:32:47
Here's where that code can be inlined. Just delet
Taylor Brandstetter
2015/08/25 01:04:05
Done.
| |
789 | 800 |
790 // Update state and SSRC of local MediaStreams and DataChannels based on the | 801 // Update state and SSRC of local MediaStreams and DataChannels based on the |
791 // local session description. | 802 // local session description. |
792 mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get()); | 803 mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get()); |
793 | 804 |
794 rtc::SSLRole role; | 805 rtc::SSLRole role; |
795 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { | 806 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { |
796 mediastream_signaling_->OnDtlsRoleReadyForSctp(role); | 807 mediastream_signaling_->OnDtlsRoleReadyForSctp(role); |
797 } | 808 } |
798 if (error() != cricket::BaseSession::ERROR_NONE) { | 809 if (error() != cricket::BaseSession::ERROR_NONE) { |
799 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); | 810 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
800 } | 811 } |
801 return true; | 812 return true; |
802 } | 813 } |
803 | 814 |
804 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, | 815 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, |
805 std::string* err_desc) { | 816 std::string* err_desc) { |
817 ASSERT(signaling_thread()->IsCurrent()); | |
818 | |
806 // Takes the ownership of |desc| regardless of the result. | 819 // Takes the ownership of |desc| regardless of the result. |
807 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 820 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
808 | 821 |
809 // Validate SDP. | 822 // Validate SDP. |
810 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { | 823 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { |
811 return false; | 824 return false; |
812 } | 825 } |
813 | 826 |
814 // Transport and Media channels will be created only when offer is set. | 827 // Transport and Media channels will be created only when offer is set. |
815 Action action = GetAction(desc->type()); | 828 Action action = GetAction(desc->type()); |
816 if (action == kOffer && !CreateChannels(desc->description())) { | 829 if (action == kOffer && !CreateChannels(desc->description())) { |
817 // TODO(mallinath) - Handle CreateChannel failure, as new local description | 830 // TODO(mallinath) - Handle CreateChannel failure, as new local description |
818 // is applied. Restore back to old description. | 831 // is applied. Restore back to old description. |
819 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); | 832 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); |
820 } | 833 } |
821 | 834 |
822 // Remove channel and transport proxies, if MediaContentDescription is | 835 // Remove unused channels if MediaContentDescription is rejected. |
823 // rejected. | 836 RemoveUnusedChannels(desc->description()); |
824 RemoveUnusedChannelsAndTransports(desc->description()); | |
825 | 837 |
826 // NOTE: Candidates allocation will be initiated only when SetLocalDescription | 838 // NOTE: Candidates allocation will be initiated only when SetLocalDescription |
827 // is called. | 839 // is called. |
828 set_remote_description(desc->description()->Copy()); | 840 set_remote_description(desc->description()->Copy()); |
829 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { | 841 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { |
830 return false; | 842 return false; |
831 } | 843 } |
832 | 844 |
833 // Update remote MediaStreams. | 845 // Update remote MediaStreams. |
834 mediastream_signaling_->OnRemoteDescriptionChanged(desc); | 846 mediastream_signaling_->OnRemoteDescriptionChanged(desc); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 if (desc->type() != SessionDescriptionInterface::kOffer && | 885 if (desc->type() != SessionDescriptionInterface::kOffer && |
874 ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) { | 886 ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) { |
875 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); | 887 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
876 } | 888 } |
877 return true; | 889 return true; |
878 } | 890 } |
879 | 891 |
880 bool WebRtcSession::UpdateSessionState( | 892 bool WebRtcSession::UpdateSessionState( |
881 Action action, cricket::ContentSource source, | 893 Action action, cricket::ContentSource source, |
882 std::string* err_desc) { | 894 std::string* err_desc) { |
895 ASSERT(signaling_thread()->IsCurrent()); | |
896 | |
883 // If there's already a pending error then no state transition should happen. | 897 // If there's already a pending error then no state transition should happen. |
884 // But all call-sites should be verifying this before calling us! | 898 // But all call-sites should be verifying this before calling us! |
885 ASSERT(error() == cricket::BaseSession::ERROR_NONE); | 899 ASSERT(error() == cricket::BaseSession::ERROR_NONE); |
886 std::string td_err; | 900 std::string td_err; |
887 if (action == kOffer) { | 901 if (action == kOffer) { |
888 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) { | 902 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) { |
889 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc); | 903 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc); |
890 } | 904 } |
891 SetState(source == cricket::CS_LOCAL ? | 905 SetState(source == cricket::CS_LOCAL ? |
892 STATE_SENTINITIATE : STATE_RECEIVEDINITIATE); | 906 STATE_SENTINITIATE : STATE_RECEIVEDINITIATE); |
(...skipping 13 matching lines...) Expand all Loading... | |
906 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { | 920 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { |
907 SetError(BaseSession::ERROR_CONTENT, *err_desc); | 921 SetError(BaseSession::ERROR_CONTENT, *err_desc); |
908 } | 922 } |
909 if (error() != cricket::BaseSession::ERROR_NONE) { | 923 if (error() != cricket::BaseSession::ERROR_NONE) { |
910 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); | 924 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); |
911 } | 925 } |
912 } else if (action == kAnswer) { | 926 } else if (action == kAnswer) { |
913 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) { | 927 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) { |
914 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc); | 928 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc); |
915 } | 929 } |
916 MaybeEnableMuxingSupport(); | 930 const cricket::ContentGroup* local_bundle = |
931 BaseSession::local_description()->GetGroupByName( | |
932 cricket::GROUP_TYPE_BUNDLE); | |
933 const cricket::ContentGroup* remote_bundle = | |
934 BaseSession::remote_description()->GetGroupByName( | |
935 cricket::GROUP_TYPE_BUNDLE); | |
936 if (local_bundle && remote_bundle) { | |
937 // The answerer decides the transport to bundle on | |
938 const cricket::ContentGroup* answer_bundle = | |
939 (source == cricket::CS_LOCAL ? local_bundle : remote_bundle); | |
940 if (!EnableBundle(*answer_bundle)) { | |
941 LOG(LS_WARNING) << "Failed to enable BUNDLE."; | |
942 return BadAnswerSdp(source, kEnableBundleFailed, err_desc); | |
943 } | |
944 } | |
917 EnableChannels(); | 945 EnableChannels(); |
918 SetState(source == cricket::CS_LOCAL ? | 946 SetState(source == cricket::CS_LOCAL ? |
919 STATE_SENTACCEPT : STATE_RECEIVEDACCEPT); | 947 STATE_SENTACCEPT : STATE_RECEIVEDACCEPT); |
920 if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) { | 948 if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) { |
921 SetError(BaseSession::ERROR_CONTENT, *err_desc); | 949 SetError(BaseSession::ERROR_CONTENT, *err_desc); |
922 } | 950 } |
923 if (error() != cricket::BaseSession::ERROR_NONE) { | 951 if (error() != cricket::BaseSession::ERROR_NONE) { |
924 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc); | 952 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc); |
925 } | 953 } |
926 } | 954 } |
(...skipping 28 matching lines...) Expand all Loading... | |
955 return WebRtcSession::kPrAnswer; | 983 return WebRtcSession::kPrAnswer; |
956 } else if (type == SessionDescriptionInterface::kAnswer) { | 984 } else if (type == SessionDescriptionInterface::kAnswer) { |
957 return WebRtcSession::kAnswer; | 985 return WebRtcSession::kAnswer; |
958 } | 986 } |
959 ASSERT(false && "unknown action type"); | 987 ASSERT(false && "unknown action type"); |
960 return WebRtcSession::kOffer; | 988 return WebRtcSession::kOffer; |
961 } | 989 } |
962 | 990 |
963 bool WebRtcSession::GetTransportStats(cricket::SessionStats* stats) { | 991 bool WebRtcSession::GetTransportStats(cricket::SessionStats* stats) { |
964 ASSERT(signaling_thread()->IsCurrent()); | 992 ASSERT(signaling_thread()->IsCurrent()); |
993 return (GetChannelTransportStats(voice_channel(), stats) && | |
994 GetChannelTransportStats(video_channel(), stats) && | |
995 GetChannelTransportStats(data_channel(), stats)); | |
996 } | |
965 | 997 |
966 const auto get_transport_stats = [stats](const std::string& content_name, | 998 bool WebRtcSession::GetChannelTransportStats(cricket::BaseChannel* ch, |
967 cricket::Transport* transport) { | 999 cricket::SessionStats* stats) { |
968 const std::string& transport_id = transport->content_name(); | 1000 ASSERT(signaling_thread()->IsCurrent()); |
969 stats->proxy_to_transport[content_name] = transport_id; | 1001 if (!ch) { |
970 if (stats->transport_stats.find(transport_id) | 1002 // Not using this channel. |
971 != stats->transport_stats.end()) { | 1003 return true; |
972 // Transport stats already done for this transport. | 1004 } |
973 return true; | |
974 } | |
975 | 1005 |
976 cricket::TransportStats tstats; | 1006 const std::string& content_name = ch->content_name(); |
977 if (!transport->GetStats(&tstats)) { | 1007 const std::string& transport_name = ch->transport_name(); |
978 return false; | 1008 stats->proxy_to_transport[content_name] = transport_name; |
979 } | 1009 if (stats->transport_stats.find(transport_name) != |
1010 stats->transport_stats.end()) { | |
1011 // Transport stats already done for this transport. | |
1012 return true; | |
1013 } | |
980 | 1014 |
981 stats->transport_stats[transport_id] = tstats; | 1015 cricket::TransportStats tstats; |
982 return true; | 1016 if (!transport_controller()->GetStats(transport_name, &tstats)) { |
983 }; | 1017 return false; |
1018 } | |
984 | 1019 |
985 for (const auto& kv : transport_proxies()) { | 1020 stats->transport_stats[transport_name] = tstats; |
986 cricket::Transport* transport = kv.second->impl(); | |
987 if (transport && !get_transport_stats(kv.first, transport)) { | |
988 return false; | |
989 } | |
990 } | |
991 return true; | 1021 return true; |
992 } | 1022 } |
993 | 1023 |
1024 bool WebRtcSession::GetIdentity(const std::string& content_name, | |
1025 rtc::SSLIdentity** identity) { | |
1026 ASSERT(signaling_thread()->IsCurrent()); | |
1027 | |
1028 cricket::BaseChannel* ch = GetChannel(content_name); | |
1029 if (!ch) { | |
1030 return false; | |
1031 } | |
1032 | |
1033 return transport_controller()->GetIdentity(ch->transport_name(), identity); | |
1034 } | |
1035 | |
1036 bool WebRtcSession::GetRemoteCertificate(const std::string& content_name, | |
1037 rtc::SSLCertificate** cert) { | |
1038 ASSERT(signaling_thread()->IsCurrent()); | |
1039 | |
1040 cricket::BaseChannel* ch = GetChannel(content_name); | |
1041 if (!ch) { | |
1042 return false; | |
1043 } | |
1044 | |
1045 return transport_controller()->GetRemoteCertificate(ch->transport_name(), | |
1046 cert); | |
1047 } | |
1048 | |
1049 cricket::BaseChannel* WebRtcSession::GetChannel( | |
1050 const std::string& content_name) { | |
1051 if (voice_channel() && voice_channel()->content_name() == content_name) { | |
1052 return voice_channel(); | |
1053 } | |
1054 if (video_channel() && video_channel()->content_name() == content_name) { | |
1055 return video_channel(); | |
1056 } | |
1057 if (data_channel() && data_channel()->content_name() == content_name) { | |
1058 return data_channel(); | |
1059 } | |
1060 return nullptr; | |
1061 } | |
1062 | |
1063 bool WebRtcSession::EnableBundle(const cricket::ContentGroup& bundle) { | |
1064 const std::string* first_content_name = bundle.FirstContentName(); | |
1065 if (!first_content_name) { | |
1066 LOG(LS_WARNING) << "Tried to BUNDLE with no contents."; | |
1067 return false; | |
1068 } | |
1069 const std::string& transport_name = *first_content_name; | |
1070 cricket::BaseChannel* first_channel = GetChannel(transport_name); | |
1071 | |
1072 auto maybe_set_transport = | |
1073 [this, bundle, transport_name, first_channel](cricket::BaseChannel* ch) { | |
1074 if (!ch || !bundle.HasContentName(ch->content_name())) { | |
1075 return true; | |
1076 } | |
1077 | |
1078 if (ch->transport_name() == transport_name) { | |
1079 LOG(LS_INFO) << "BUNDLE already enabled for " << ch->content_name() | |
1080 << " on " << transport_name << "."; | |
1081 return true; | |
1082 } | |
1083 | |
1084 if (!ch->SetTransport(transport_name)) { | |
1085 LOG(LS_WARNING) << "Failed to enable BUNDLE for " | |
1086 << ch->content_name(); | |
1087 return false; | |
1088 } | |
1089 LOG(LS_INFO) << "Enabled BUNDLE for " << ch->content_name() << " on " | |
1090 << transport_name << "."; | |
1091 return true; | |
1092 }; | |
1093 | |
1094 if (!maybe_set_transport(voice_channel()) || | |
1095 !maybe_set_transport(video_channel()) || | |
1096 !maybe_set_transport(data_channel())) { | |
1097 return false; | |
1098 } | |
1099 | |
1100 return true; | |
1101 } | |
1102 | |
994 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { | 1103 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
995 if (state() == STATE_INIT) { | 1104 if (state() == STATE_INIT) { |
996 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " | 1105 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
997 << "without any offer (local or remote) " | 1106 << "without any offer (local or remote) " |
998 << "session description."; | 1107 << "session description."; |
999 return false; | 1108 return false; |
1000 } | 1109 } |
1001 | 1110 |
1002 if (!candidate) { | 1111 if (!candidate) { |
1003 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL"; | 1112 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL"; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1298 | 1407 |
1299 bool WebRtcSession::IceRestartPending() const { | 1408 bool WebRtcSession::IceRestartPending() const { |
1300 return ice_restart_latch_->Get(); | 1409 return ice_restart_latch_->Get(); |
1301 } | 1410 } |
1302 | 1411 |
1303 void WebRtcSession::ResetIceRestartLatch() { | 1412 void WebRtcSession::ResetIceRestartLatch() { |
1304 ice_restart_latch_->Reset(); | 1413 ice_restart_latch_->Reset(); |
1305 } | 1414 } |
1306 | 1415 |
1307 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { | 1416 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { |
1308 SetIdentity(identity); | 1417 transport_controller()->SetIdentity(identity); |
1309 } | 1418 } |
1310 | 1419 |
1311 bool WebRtcSession::waiting_for_identity() const { | 1420 bool WebRtcSession::waiting_for_identity() const { |
1312 return webrtc_session_desc_factory_->waiting_for_identity(); | 1421 return webrtc_session_desc_factory_->waiting_for_identity(); |
1313 } | 1422 } |
1314 | 1423 |
1315 void WebRtcSession::SetIceConnectionState( | 1424 void WebRtcSession::SetIceConnectionState( |
1316 PeerConnectionInterface::IceConnectionState state) { | 1425 PeerConnectionInterface::IceConnectionState state) { |
1317 if (ice_connection_state_ == state) { | 1426 if (ice_connection_state_ == state) { |
1318 return; | 1427 return; |
1319 } | 1428 } |
1320 | 1429 |
1321 // ASSERT that the requested transition is allowed. Note that | 1430 // ASSERT that the requested transition is allowed. Note that |
1322 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled | 1431 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled |
1323 // within PeerConnection). This switch statement should compile away when | 1432 // within PeerConnection). This switch statement should compile away when |
1324 // ASSERTs are disabled. | 1433 // ASSERTs are disabled. |
1434 LOG(LS_INFO) << "Changing IceConnectionState " << ice_connection_state_ | |
1435 << " => " << state; | |
1325 switch (ice_connection_state_) { | 1436 switch (ice_connection_state_) { |
1326 case PeerConnectionInterface::kIceConnectionNew: | 1437 case PeerConnectionInterface::kIceConnectionNew: |
1327 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking); | 1438 ASSERT(state == PeerConnectionInterface::kIceConnectionChecking); |
1328 break; | 1439 break; |
1329 case PeerConnectionInterface::kIceConnectionChecking: | 1440 case PeerConnectionInterface::kIceConnectionChecking: |
1330 ASSERT(state == PeerConnectionInterface::kIceConnectionFailed || | 1441 ASSERT(state == PeerConnectionInterface::kIceConnectionFailed || |
1331 state == PeerConnectionInterface::kIceConnectionConnected); | 1442 state == PeerConnectionInterface::kIceConnectionConnected); |
1332 break; | 1443 break; |
1333 case PeerConnectionInterface::kIceConnectionConnected: | 1444 case PeerConnectionInterface::kIceConnectionConnected: |
1334 ASSERT(state == PeerConnectionInterface::kIceConnectionDisconnected || | 1445 ASSERT(state == PeerConnectionInterface::kIceConnectionDisconnected || |
(...skipping 20 matching lines...) Expand all Loading... | |
1355 ASSERT(false); | 1466 ASSERT(false); |
1356 break; | 1467 break; |
1357 } | 1468 } |
1358 | 1469 |
1359 ice_connection_state_ = state; | 1470 ice_connection_state_ = state; |
1360 if (ice_observer_) { | 1471 if (ice_observer_) { |
1361 ice_observer_->OnIceConnectionChange(ice_connection_state_); | 1472 ice_observer_->OnIceConnectionChange(ice_connection_state_); |
1362 } | 1473 } |
1363 } | 1474 } |
1364 | 1475 |
1365 void WebRtcSession::OnTransportRequestSignaling( | 1476 void WebRtcSession::OnTransportControllerConnectionState( |
1366 cricket::Transport* transport) { | 1477 cricket::ConnectionState state) { |
1367 ASSERT(signaling_thread()->IsCurrent()); | 1478 switch (state) { |
1368 transport->OnSignalingReady(); | 1479 case cricket::kConnectionConnecting: |
1369 if (ice_observer_) { | 1480 // If the current state is Connected or Completed, then there were |
1370 ice_observer_->OnIceGatheringChange( | 1481 // writable channels but now there are not, so the next state must |
1371 PeerConnectionInterface::kIceGatheringGathering); | 1482 // be Disconnected. |
1483 if (ice_connection_state_ == | |
1484 PeerConnectionInterface::kIceConnectionConnected || | |
1485 ice_connection_state_ == | |
1486 PeerConnectionInterface::kIceConnectionCompleted) { | |
1487 SetIceConnectionState( | |
1488 PeerConnectionInterface::kIceConnectionDisconnected); | |
1489 } | |
1490 break; | |
1491 case cricket::kConnectionFailed: | |
1492 SetIceConnectionState(PeerConnectionInterface::kIceConnectionFailed); | |
1493 break; | |
1494 case cricket::kConnectionConnected: | |
1495 LOG(LS_INFO) << "Changing to ICE connected state because " | |
1496 << "all transports are writable."; | |
1497 SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); | |
1498 break; | |
1499 case cricket::kConnectionCompleted: | |
1500 LOG(LS_INFO) << "Changing to ICE completed state because " | |
1501 << "all transports are complete."; | |
1502 if (ice_connection_state_ != | |
1503 PeerConnectionInterface::kIceConnectionConnected) { | |
1504 // If jumping directly from "checking" to "connected", | |
1505 // signal "connected" first. | |
1506 SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); | |
1507 } | |
1508 SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted); | |
1509 if (metrics_observer_) { | |
1510 // Once ICE connection is completed, report stats for all transports | |
1511 // in use. | |
1512 std::set<std::string> transport_names; | |
1513 if (voice_channel()) { | |
1514 transport_names.insert(voice_channel()->transport_name()); | |
1515 } | |
1516 if (video_channel()) { | |
1517 transport_names.insert(video_channel()->transport_name()); | |
1518 } | |
1519 if (data_channel()) { | |
1520 transport_names.insert(data_channel()->transport_name()); | |
1521 } | |
1522 for (auto name : transport_names) { | |
1523 cricket::TransportStats stats; | |
1524 if (transport_controller()->GetStats(name, &stats)) { | |
1525 ReportBestConnectionState(stats); | |
1526 ReportNegotiatedCiphers(stats); | |
1527 } | |
1528 } | |
1529 } | |
1530 break; | |
1531 default: | |
1532 ASSERT(false); | |
1372 } | 1533 } |
1373 } | 1534 } |
1374 | 1535 |
1375 void WebRtcSession::OnTransportConnecting(cricket::Transport* transport) { | 1536 void WebRtcSession::OnTransportControllerReceiving(bool receiving) { |
1376 ASSERT(signaling_thread()->IsCurrent()); | |
1377 // start monitoring for the write state of the transport. | |
1378 OnTransportWritable(transport); | |
1379 } | |
1380 | |
1381 void WebRtcSession::OnTransportWritable(cricket::Transport* transport) { | |
1382 ASSERT(signaling_thread()->IsCurrent()); | |
1383 if (transport->all_channels_writable()) { | |
1384 SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected); | |
1385 } else if (transport->HasChannels()) { | |
1386 // If the current state is Connected or Completed, then there were writable | |
1387 // channels but now there are not, so the next state must be Disconnected. | |
1388 if (ice_connection_state_ == | |
1389 PeerConnectionInterface::kIceConnectionConnected || | |
1390 ice_connection_state_ == | |
1391 PeerConnectionInterface::kIceConnectionCompleted) { | |
1392 SetIceConnectionState( | |
1393 PeerConnectionInterface::kIceConnectionDisconnected); | |
1394 } | |
1395 } | |
1396 } | |
1397 | |
1398 void WebRtcSession::OnTransportCompleted(cricket::Transport* transport) { | |
1399 ASSERT(signaling_thread()->IsCurrent()); | |
1400 PeerConnectionInterface::IceConnectionState old_state = ice_connection_state_; | |
1401 SetIceConnectionState(PeerConnectionInterface::kIceConnectionCompleted); | |
1402 // Only report once when Ice connection is completed. | |
1403 if (old_state != PeerConnectionInterface::kIceConnectionCompleted) { | |
1404 cricket::TransportStats stats; | |
1405 if (metrics_observer_ && transport->GetStats(&stats)) { | |
1406 ReportBestConnectionState(stats); | |
1407 ReportNegotiatedCiphers(stats); | |
1408 } | |
1409 } | |
1410 } | |
1411 | |
1412 void WebRtcSession::OnTransportFailed(cricket::Transport* transport) { | |
1413 ASSERT(signaling_thread()->IsCurrent()); | |
1414 SetIceConnectionState(PeerConnectionInterface::kIceConnectionFailed); | |
1415 } | |
1416 | |
1417 void WebRtcSession::OnTransportReceiving(cricket::Transport* transport) { | |
1418 ASSERT(signaling_thread()->IsCurrent()); | |
1419 // The ice connection is considered receiving if at least one transport is | |
1420 // receiving on any channels. | |
1421 bool receiving = false; | |
1422 for (const auto& kv : transport_proxies()) { | |
1423 cricket::Transport* transport = kv.second->impl(); | |
1424 if (transport && transport->any_channel_receiving()) { | |
1425 receiving = true; | |
1426 break; | |
1427 } | |
1428 } | |
1429 SetIceConnectionReceiving(receiving); | 1537 SetIceConnectionReceiving(receiving); |
1430 } | 1538 } |
1431 | 1539 |
1432 void WebRtcSession::SetIceConnectionReceiving(bool receiving) { | 1540 void WebRtcSession::SetIceConnectionReceiving(bool receiving) { |
1433 if (ice_connection_receiving_ == receiving) { | 1541 if (ice_connection_receiving_ == receiving) { |
1434 return; | 1542 return; |
1435 } | 1543 } |
1436 ice_connection_receiving_ = receiving; | 1544 ice_connection_receiving_ = receiving; |
1437 if (ice_observer_) { | 1545 if (ice_observer_) { |
1438 ice_observer_->OnIceConnectionReceivingChange(receiving); | 1546 ice_observer_->OnIceConnectionReceivingChange(receiving); |
1439 } | 1547 } |
1440 } | 1548 } |
1441 | 1549 |
1442 void WebRtcSession::OnTransportProxyCandidatesReady( | 1550 void WebRtcSession::OnTransportControllerCandidatesGathered( |
1443 cricket::TransportProxy* proxy, const cricket::Candidates& candidates) { | 1551 const std::string& transport_name, |
1552 const cricket::Candidates& candidates) { | |
1444 ASSERT(signaling_thread()->IsCurrent()); | 1553 ASSERT(signaling_thread()->IsCurrent()); |
1445 ProcessNewLocalCandidate(proxy->content_name(), candidates); | 1554 int sdp_mline_index; |
1446 } | 1555 if (!GetLocalCandidateMediaIndex(transport_name, &sdp_mline_index)) { |
1556 LOG(LS_ERROR) << "OnTransportControllerCandidatesGathered: content name " | |
1557 << transport_name << " not found"; | |
1558 return; | |
1559 } | |
1447 | 1560 |
1448 void WebRtcSession::OnCandidatesAllocationDone() { | 1561 for (cricket::Candidates::const_iterator citer = candidates.begin(); |
1449 ASSERT(signaling_thread()->IsCurrent()); | 1562 citer != candidates.end(); ++citer) { |
1450 if (ice_observer_) { | 1563 // Use transport_name as the candidate media id. |
1451 ice_observer_->OnIceGatheringChange( | 1564 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); |
1452 PeerConnectionInterface::kIceGatheringComplete); | 1565 if (ice_observer_) { |
1453 ice_observer_->OnIceComplete(); | 1566 ice_observer_->OnIceCandidate(&candidate); |
1567 } | |
1568 if (local_desc_) { | |
1569 local_desc_->AddCandidate(&candidate); | |
1570 } | |
1454 } | 1571 } |
1455 } | 1572 } |
1456 | 1573 |
1457 // Enabling voice and video channel. | 1574 // Enabling voice and video channel. |
1458 void WebRtcSession::EnableChannels() { | 1575 void WebRtcSession::EnableChannels() { |
1459 if (voice_channel_ && !voice_channel_->enabled()) | 1576 if (voice_channel_ && !voice_channel_->enabled()) |
1460 voice_channel_->Enable(true); | 1577 voice_channel_->Enable(true); |
1461 | 1578 |
1462 if (video_channel_ && !video_channel_->enabled()) | 1579 if (video_channel_ && !video_channel_->enabled()) |
1463 video_channel_->Enable(true); | 1580 video_channel_->Enable(true); |
1464 | 1581 |
1465 if (data_channel_ && !data_channel_->enabled()) | 1582 if (data_channel_ && !data_channel_->enabled()) |
1466 data_channel_->Enable(true); | 1583 data_channel_->Enable(true); |
1467 } | 1584 } |
1468 | 1585 |
1469 void WebRtcSession::ProcessNewLocalCandidate( | |
1470 const std::string& content_name, | |
1471 const cricket::Candidates& candidates) { | |
1472 int sdp_mline_index; | |
1473 if (!GetLocalCandidateMediaIndex(content_name, &sdp_mline_index)) { | |
1474 LOG(LS_ERROR) << "ProcessNewLocalCandidate: content name " | |
1475 << content_name << " not found"; | |
1476 return; | |
1477 } | |
1478 | |
1479 for (cricket::Candidates::const_iterator citer = candidates.begin(); | |
1480 citer != candidates.end(); ++citer) { | |
1481 // Use content_name as the candidate media id. | |
1482 JsepIceCandidate candidate(content_name, sdp_mline_index, *citer); | |
1483 if (ice_observer_) { | |
1484 ice_observer_->OnIceCandidate(&candidate); | |
1485 } | |
1486 if (local_desc_) { | |
1487 local_desc_->AddCandidate(&candidate); | |
1488 } | |
1489 } | |
1490 } | |
1491 | |
1492 // Returns the media index for a local ice candidate given the content name. | 1586 // Returns the media index for a local ice candidate given the content name. |
1493 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, | 1587 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, |
1494 int* sdp_mline_index) { | 1588 int* sdp_mline_index) { |
1495 if (!base_local_description() || !sdp_mline_index) | 1589 if (!base_local_description() || !sdp_mline_index) |
1496 return false; | 1590 return false; |
1497 | 1591 |
1498 bool content_found = false; | 1592 bool content_found = false; |
1499 const ContentInfos& contents = base_local_description()->contents(); | 1593 const ContentInfos& contents = base_local_description()->contents(); |
1500 for (size_t index = 0; index < contents.size(); ++index) { | 1594 for (size_t index = 0; index < contents.size(); ++index) { |
1501 if (contents[index].name == content_name) { | 1595 if (contents[index].name == content_name) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1542 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); | 1636 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
1543 size_t remote_content_size = base_remote_description()->contents().size(); | 1637 size_t remote_content_size = base_remote_description()->contents().size(); |
1544 if (mediacontent_index >= remote_content_size) { | 1638 if (mediacontent_index >= remote_content_size) { |
1545 LOG(LS_ERROR) | 1639 LOG(LS_ERROR) |
1546 << "UseRemoteCandidateInSession: Invalid candidate media index."; | 1640 << "UseRemoteCandidateInSession: Invalid candidate media index."; |
1547 return false; | 1641 return false; |
1548 } | 1642 } |
1549 | 1643 |
1550 cricket::ContentInfo content = | 1644 cricket::ContentInfo content = |
1551 base_remote_description()->contents()[mediacontent_index]; | 1645 base_remote_description()->contents()[mediacontent_index]; |
1646 | |
1552 std::vector<cricket::Candidate> candidates; | 1647 std::vector<cricket::Candidate> candidates; |
1553 candidates.push_back(candidate->candidate()); | 1648 candidates.push_back(candidate->candidate()); |
1554 // Invoking BaseSession method to handle remote candidates. | 1649 // Invoking BaseSession method to handle remote candidates. |
1555 std::string error; | 1650 std::string error; |
1556 if (OnRemoteCandidates(content.name, candidates, &error)) { | 1651 if (transport_controller()->AddRemoteCandidates(content.name, candidates, |
1652 &error)) { | |
1557 // Candidates successfully submitted for checking. | 1653 // Candidates successfully submitted for checking. |
1558 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || | 1654 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
1559 ice_connection_state_ == | 1655 ice_connection_state_ == |
1560 PeerConnectionInterface::kIceConnectionDisconnected) { | 1656 PeerConnectionInterface::kIceConnectionDisconnected) { |
1561 // If state is New, then the session has just gotten its first remote ICE | 1657 // If state is New, then the session has just gotten its first remote ICE |
1562 // candidates, so go to Checking. | 1658 // candidates, so go to Checking. |
1563 // If state is Disconnected, the session is re-using old candidates or | 1659 // If state is Disconnected, the session is re-using old candidates or |
1564 // receiving additional ones, so go to Checking. | 1660 // receiving additional ones, so go to Checking. |
1565 // If state is Connected, stay Connected. | 1661 // If state is Connected, stay Connected. |
1566 // TODO(bemasc): If state is Connected, and the new candidates are for a | 1662 // TODO(bemasc): If state is Connected, and the new candidates are for a |
1567 // newly added transport, then the state actually _should_ move to | 1663 // newly added transport, then the state actually _should_ move to |
1568 // checking. Add a way to distinguish that case. | 1664 // checking. Add a way to distinguish that case. |
1569 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); | 1665 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
1570 } | 1666 } |
1571 // TODO(bemasc): If state is Completed, go back to Connected. | 1667 // TODO(bemasc): If state is Completed, go back to Connected. |
1572 } else { | 1668 } else { |
1573 if (!error.empty()) { | 1669 if (!error.empty()) { |
1574 LOG(LS_WARNING) << error; | 1670 LOG(LS_WARNING) << error; |
1575 } | 1671 } |
1576 } | 1672 } |
1577 return true; | 1673 return true; |
1578 } | 1674 } |
1579 | 1675 |
1580 void WebRtcSession::RemoveUnusedChannelsAndTransports( | 1676 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { |
1581 const SessionDescription* desc) { | |
1582 // Destroy video_channel_ first since it may have a pointer to the | 1677 // Destroy video_channel_ first since it may have a pointer to the |
1583 // voice_channel_. | 1678 // voice_channel_. |
1584 const cricket::ContentInfo* video_info = | 1679 const cricket::ContentInfo* video_info = |
1585 cricket::GetFirstVideoContent(desc); | 1680 cricket::GetFirstVideoContent(desc); |
1586 if ((!video_info || video_info->rejected) && video_channel_) { | 1681 if ((!video_info || video_info->rejected) && video_channel_) { |
1587 mediastream_signaling_->OnVideoChannelClose(); | 1682 mediastream_signaling_->OnVideoChannelClose(); |
1588 SignalVideoChannelDestroyed(); | 1683 SignalVideoChannelDestroyed(); |
1589 const std::string content_name = video_channel_->content_name(); | 1684 const std::string content_name = video_channel_->content_name(); |
1590 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 1685 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
1591 DestroyTransportProxy(content_name); | |
1592 } | 1686 } |
1593 | 1687 |
1594 const cricket::ContentInfo* voice_info = | 1688 const cricket::ContentInfo* voice_info = |
1595 cricket::GetFirstAudioContent(desc); | 1689 cricket::GetFirstAudioContent(desc); |
1596 if ((!voice_info || voice_info->rejected) && voice_channel_) { | 1690 if ((!voice_info || voice_info->rejected) && voice_channel_) { |
1597 mediastream_signaling_->OnAudioChannelClose(); | 1691 mediastream_signaling_->OnAudioChannelClose(); |
1598 SignalVoiceChannelDestroyed(); | 1692 SignalVoiceChannelDestroyed(); |
1599 const std::string content_name = voice_channel_->content_name(); | 1693 const std::string content_name = voice_channel_->content_name(); |
1600 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), | 1694 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), |
1601 video_channel_.get()); | 1695 video_channel_.get()); |
1602 DestroyTransportProxy(content_name); | |
1603 } | 1696 } |
1604 | 1697 |
1605 const cricket::ContentInfo* data_info = | 1698 const cricket::ContentInfo* data_info = |
1606 cricket::GetFirstDataContent(desc); | 1699 cricket::GetFirstDataContent(desc); |
1607 if ((!data_info || data_info->rejected) && data_channel_) { | 1700 if ((!data_info || data_info->rejected) && data_channel_) { |
1608 mediastream_signaling_->OnDataChannelClose(); | 1701 mediastream_signaling_->OnDataChannelClose(); |
1609 SignalDataChannelDestroyed(); | 1702 SignalDataChannelDestroyed(); |
1610 const std::string content_name = data_channel_->content_name(); | 1703 const std::string content_name = data_channel_->content_name(); |
1611 channel_manager_->DestroyDataChannel(data_channel_.release()); | 1704 channel_manager_->DestroyDataChannel(data_channel_.release()); |
1612 DestroyTransportProxy(content_name); | |
1613 } | 1705 } |
1614 } | 1706 } |
1615 | 1707 |
1616 // TODO(mallinath) - Add a correct error code if the channels are not creatued | 1708 // TODO(mallinath) - Add a correct error code if the channels are not creatued |
1617 // due to BUNDLE is enabled but rtcp-mux is disabled. | 1709 // due to BUNDLE is enabled but rtcp-mux is disabled. |
1618 bool WebRtcSession::CreateChannels(const SessionDescription* desc) { | 1710 bool WebRtcSession::CreateChannels(const SessionDescription* desc) { |
1619 // Creating the media channels and transport proxies. | 1711 // Creating the media channels and transport proxies. |
1620 const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc); | 1712 const cricket::ContentInfo* voice = cricket::GetFirstAudioContent(desc); |
1621 if (voice && !voice->rejected && !voice_channel_) { | 1713 if (voice && !voice->rejected && !voice_channel_) { |
1622 if (!CreateVoiceChannel(voice)) { | 1714 if (!CreateVoiceChannel(voice)) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1655 } | 1747 } |
1656 | 1748 |
1657 // Enable bundle before when kMaxBundle policy is in effect. | 1749 // Enable bundle before when kMaxBundle policy is in effect. |
1658 if (bundle_policy_ == PeerConnectionInterface::kBundlePolicyMaxBundle) { | 1750 if (bundle_policy_ == PeerConnectionInterface::kBundlePolicyMaxBundle) { |
1659 const cricket::ContentGroup* bundle_group = desc->GetGroupByName( | 1751 const cricket::ContentGroup* bundle_group = desc->GetGroupByName( |
1660 cricket::GROUP_TYPE_BUNDLE); | 1752 cricket::GROUP_TYPE_BUNDLE); |
1661 if (!bundle_group) { | 1753 if (!bundle_group) { |
1662 LOG(LS_WARNING) << "max-bundle specified without BUNDLE specified"; | 1754 LOG(LS_WARNING) << "max-bundle specified without BUNDLE specified"; |
1663 return false; | 1755 return false; |
1664 } | 1756 } |
1665 if (!BaseSession::BundleContentGroup(bundle_group)) { | 1757 if (!EnableBundle(*bundle_group)) { |
1666 LOG(LS_WARNING) << "max-bundle failed to enable bundling."; | 1758 LOG(LS_WARNING) << "max-bundle failed to enable bundling."; |
1667 return false; | 1759 return false; |
1668 } | 1760 } |
1669 } | 1761 } |
1670 | 1762 |
1671 return true; | 1763 return true; |
1672 } | 1764 } |
1673 | 1765 |
1674 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { | 1766 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { |
1675 voice_channel_.reset(channel_manager_->CreateVoiceChannel( | 1767 voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
1676 this, content->name, true, audio_options_)); | 1768 transport_controller(), content->name, true, audio_options_)); |
1677 if (!voice_channel_) { | 1769 if (!voice_channel_) { |
1678 return false; | 1770 return false; |
1679 } | 1771 } |
1680 | 1772 |
1681 voice_channel_->SignalDtlsSetupFailure.connect( | 1773 voice_channel_->SignalDtlsSetupFailure.connect( |
1682 this, &WebRtcSession::OnDtlsSetupFailure); | 1774 this, &WebRtcSession::OnDtlsSetupFailure); |
1683 return true; | 1775 return true; |
1684 } | 1776 } |
1685 | 1777 |
1686 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { | 1778 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { |
1687 video_channel_.reset(channel_manager_->CreateVideoChannel( | 1779 video_channel_.reset(channel_manager_->CreateVideoChannel( |
1688 this, content->name, true, video_options_, voice_channel_.get())); | 1780 transport_controller(), content->name, true, video_options_, |
1781 voice_channel_.get())); | |
1689 if (!video_channel_) { | 1782 if (!video_channel_) { |
1690 return false; | 1783 return false; |
1691 } | 1784 } |
1692 | 1785 |
1693 video_channel_->SignalDtlsSetupFailure.connect( | 1786 video_channel_->SignalDtlsSetupFailure.connect( |
1694 this, &WebRtcSession::OnDtlsSetupFailure); | 1787 this, &WebRtcSession::OnDtlsSetupFailure); |
1695 return true; | 1788 return true; |
1696 } | 1789 } |
1697 | 1790 |
1698 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { | 1791 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { |
1699 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); | 1792 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
1700 data_channel_.reset(channel_manager_->CreateDataChannel( | 1793 data_channel_.reset(channel_manager_->CreateDataChannel( |
1701 this, content->name, !sctp, data_channel_type_)); | 1794 transport_controller(), content->name, !sctp, data_channel_type_)); |
1702 if (!data_channel_) { | 1795 if (!data_channel_) { |
1703 return false; | 1796 return false; |
1704 } | 1797 } |
1705 | 1798 |
1706 if (sctp) { | 1799 if (sctp) { |
1707 mediastream_signaling_->OnDataTransportCreatedForSctp(); | 1800 mediastream_signaling_->OnDataTransportCreatedForSctp(); |
1708 data_channel_->SignalDataReceived.connect( | 1801 data_channel_->SignalDataReceived.connect( |
1709 this, &WebRtcSession::OnDataChannelMessageReceived); | 1802 this, &WebRtcSession::OnDataChannelMessageReceived); |
1710 data_channel_->SignalStreamClosedRemotely.connect( | 1803 data_channel_->SignalStreamClosedRemotely.connect( |
1711 mediastream_signaling_, | 1804 mediastream_signaling_, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1872 // We need to check the local/remote description for the Transport instead of | 1965 // We need to check the local/remote description for the Transport instead of |
1873 // the session, because a new Transport added during renegotiation may have | 1966 // the session, because a new Transport added during renegotiation may have |
1874 // them unset while the session has them set from the previous negotiation. | 1967 // them unset while the session has them set from the previous negotiation. |
1875 // Not doing so may trigger the auto generation of transport description and | 1968 // Not doing so may trigger the auto generation of transport description and |
1876 // mess up DTLS identity information, ICE credential, etc. | 1969 // mess up DTLS identity information, ICE credential, etc. |
1877 bool WebRtcSession::ReadyToUseRemoteCandidate( | 1970 bool WebRtcSession::ReadyToUseRemoteCandidate( |
1878 const IceCandidateInterface* candidate, | 1971 const IceCandidateInterface* candidate, |
1879 const SessionDescriptionInterface* remote_desc, | 1972 const SessionDescriptionInterface* remote_desc, |
1880 bool* valid) { | 1973 bool* valid) { |
1881 *valid = true;; | 1974 *valid = true;; |
1882 cricket::TransportProxy* transport_proxy = NULL; | |
1883 | 1975 |
1884 const SessionDescriptionInterface* current_remote_desc = | 1976 const SessionDescriptionInterface* current_remote_desc = |
1885 remote_desc ? remote_desc : remote_description(); | 1977 remote_desc ? remote_desc : remote_description(); |
1886 | 1978 |
1887 if (!current_remote_desc) | 1979 if (!current_remote_desc) |
1888 return false; | 1980 return false; |
1889 | 1981 |
1890 size_t mediacontent_index = | 1982 size_t mediacontent_index = |
1891 static_cast<size_t>(candidate->sdp_mline_index()); | 1983 static_cast<size_t>(candidate->sdp_mline_index()); |
1892 size_t remote_content_size = | 1984 size_t remote_content_size = |
1893 current_remote_desc->description()->contents().size(); | 1985 current_remote_desc->description()->contents().size(); |
1894 if (mediacontent_index >= remote_content_size) { | 1986 if (mediacontent_index >= remote_content_size) { |
1895 LOG(LS_ERROR) | 1987 LOG(LS_ERROR) |
1896 << "ReadyToUseRemoteCandidate: Invalid candidate media index."; | 1988 << "ReadyToUseRemoteCandidate: Invalid candidate media index."; |
1897 | 1989 |
1898 *valid = false; | 1990 *valid = false; |
1899 return false; | 1991 return false; |
1900 } | 1992 } |
1901 | 1993 |
1902 cricket::ContentInfo content = | 1994 cricket::ContentInfo content = |
1903 current_remote_desc->description()->contents()[mediacontent_index]; | 1995 current_remote_desc->description()->contents()[mediacontent_index]; |
1904 transport_proxy = GetTransportProxy(content.name); | 1996 cricket::BaseChannel* channel = GetChannel(content.name); |
1997 if (!channel) { | |
1998 return false; | |
1999 } | |
1905 | 2000 |
1906 return transport_proxy && transport_proxy->local_description_set() && | 2001 return transport_controller()->ReadyForRemoteCandidates( |
1907 transport_proxy->remote_description_set(); | 2002 channel->transport_name()); |
2003 } | |
2004 | |
2005 void WebRtcSession::OnTransportControllerGatheringState( | |
2006 cricket::GatheringState state) { | |
2007 ASSERT(signaling_thread()->IsCurrent()); | |
2008 if (state == cricket::kGatheringGathering) { | |
2009 if (ice_observer_) { | |
2010 ice_observer_->OnIceGatheringChange( | |
2011 PeerConnectionInterface::kIceGatheringGathering); | |
2012 } | |
2013 } else if (state == cricket::kGatheringComplete) { | |
2014 ice_observer_->OnIceGatheringChange( | |
pthatcher1
2015/08/18 22:32:47
I think we need to check if(ice_observer_), in cas
Taylor Brandstetter
2015/08/25 01:04:05
Done.
| |
2015 PeerConnectionInterface::kIceGatheringComplete); | |
2016 ice_observer_->OnIceComplete(); | |
2017 } | |
1908 } | 2018 } |
1909 | 2019 |
1910 // Walk through the ConnectionInfos to gather best connection usage | 2020 // Walk through the ConnectionInfos to gather best connection usage |
1911 // for IPv4 and IPv6. | 2021 // for IPv4 and IPv6. |
1912 void WebRtcSession::ReportBestConnectionState( | 2022 void WebRtcSession::ReportBestConnectionState( |
1913 const cricket::TransportStats& stats) { | 2023 const cricket::TransportStats& stats) { |
1914 DCHECK(metrics_observer_ != NULL); | 2024 DCHECK(metrics_observer_ != NULL); |
1915 for (cricket::TransportChannelStatsList::const_iterator it = | 2025 for (cricket::TransportChannelStatsList::const_iterator it = |
1916 stats.channel_stats.begin(); | 2026 stats.channel_stats.begin(); |
1917 it != stats.channel_stats.end(); ++it) { | 2027 it != stats.channel_stats.end(); ++it) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1965 | 2075 |
1966 if (!srtp_cipher.empty()) { | 2076 if (!srtp_cipher.empty()) { |
1967 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); | 2077 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); |
1968 } | 2078 } |
1969 if (!ssl_cipher.empty()) { | 2079 if (!ssl_cipher.empty()) { |
1970 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); | 2080 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); |
1971 } | 2081 } |
1972 } | 2082 } |
1973 | 2083 |
1974 } // namespace webrtc | 2084 } // namespace webrtc |
OLD | NEW |