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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 324 } |
325 } | 325 } |
326 return false; | 326 return false; |
327 } | 327 } |
328 | 328 |
329 static bool BadSdp(const std::string& source, | 329 static bool BadSdp(const std::string& source, |
330 const std::string& type, | 330 const std::string& type, |
331 const std::string& reason, | 331 const std::string& reason, |
332 std::string* err_desc) { | 332 std::string* err_desc) { |
333 std::ostringstream desc; | 333 std::ostringstream desc; |
334 desc << "Failed to set " << source << " " << type << " sdp: " << reason; | 334 desc << "Failed to set " << source; |
| 335 if (!type.empty()) { |
| 336 desc << " " << type; |
| 337 } |
| 338 desc << " sdp: " << reason; |
335 | 339 |
336 if (err_desc) { | 340 if (err_desc) { |
337 *err_desc = desc.str(); | 341 *err_desc = desc.str(); |
338 } | 342 } |
339 LOG(LS_ERROR) << desc.str(); | 343 LOG(LS_ERROR) << desc.str(); |
340 return false; | 344 return false; |
341 } | 345 } |
342 | 346 |
343 static bool BadSdp(cricket::ContentSource source, | 347 static bool BadSdp(cricket::ContentSource source, |
344 const std::string& type, | 348 const std::string& type, |
(...skipping 30 matching lines...) Expand all Loading... |
375 return BadSdp(source, SessionDescriptionInterface::kPrAnswer, | 379 return BadSdp(source, SessionDescriptionInterface::kPrAnswer, |
376 reason, err_desc); | 380 reason, err_desc); |
377 } | 381 } |
378 | 382 |
379 static bool BadAnswerSdp(cricket::ContentSource source, | 383 static bool BadAnswerSdp(cricket::ContentSource source, |
380 const std::string& reason, | 384 const std::string& reason, |
381 std::string* err_desc) { | 385 std::string* err_desc) { |
382 return BadSdp(source, SessionDescriptionInterface::kAnswer, reason, err_desc); | 386 return BadSdp(source, SessionDescriptionInterface::kAnswer, reason, err_desc); |
383 } | 387 } |
384 | 388 |
385 #define GET_STRING_OF_STATE(state) \ | 389 #define GET_STRING_OF_STATE(state) \ |
386 case cricket::BaseSession::state: \ | 390 case webrtc::WebRtcSession::state: \ |
387 result = #state; \ | 391 result = #state; \ |
388 break; | 392 break; |
389 | 393 |
390 static std::string GetStateString(cricket::BaseSession::State state) { | 394 static std::string GetStateString(webrtc::WebRtcSession::State state) { |
391 std::string result; | 395 std::string result; |
392 switch (state) { | 396 switch (state) { |
393 GET_STRING_OF_STATE(STATE_INIT) | 397 GET_STRING_OF_STATE(STATE_INIT) |
394 GET_STRING_OF_STATE(STATE_SENTINITIATE) | 398 GET_STRING_OF_STATE(STATE_SENTOFFER) |
395 GET_STRING_OF_STATE(STATE_RECEIVEDINITIATE) | 399 GET_STRING_OF_STATE(STATE_RECEIVEDOFFER) |
396 GET_STRING_OF_STATE(STATE_SENTPRACCEPT) | 400 GET_STRING_OF_STATE(STATE_SENTPRANSWER) |
397 GET_STRING_OF_STATE(STATE_SENTACCEPT) | 401 GET_STRING_OF_STATE(STATE_RECEIVEDPRANSWER) |
398 GET_STRING_OF_STATE(STATE_RECEIVEDPRACCEPT) | |
399 GET_STRING_OF_STATE(STATE_RECEIVEDACCEPT) | |
400 GET_STRING_OF_STATE(STATE_SENTMODIFY) | |
401 GET_STRING_OF_STATE(STATE_RECEIVEDMODIFY) | |
402 GET_STRING_OF_STATE(STATE_SENTREJECT) | |
403 GET_STRING_OF_STATE(STATE_RECEIVEDREJECT) | |
404 GET_STRING_OF_STATE(STATE_SENTREDIRECT) | |
405 GET_STRING_OF_STATE(STATE_SENTTERMINATE) | |
406 GET_STRING_OF_STATE(STATE_RECEIVEDTERMINATE) | |
407 GET_STRING_OF_STATE(STATE_INPROGRESS) | 402 GET_STRING_OF_STATE(STATE_INPROGRESS) |
408 GET_STRING_OF_STATE(STATE_DEINIT) | 403 GET_STRING_OF_STATE(STATE_CLOSED) |
409 default: | 404 default: |
410 ASSERT(false); | 405 ASSERT(false); |
411 break; | 406 break; |
412 } | 407 } |
413 return result; | 408 return result; |
414 } | 409 } |
415 | 410 |
416 #define GET_STRING_OF_ERROR_CODE(err) \ | 411 #define GET_STRING_OF_ERROR_CODE(err) \ |
417 case cricket::BaseSession::err: \ | 412 case webrtc::WebRtcSession::err: \ |
418 result = #err; \ | 413 result = #err; \ |
419 break; | 414 break; |
420 | 415 |
421 static std::string GetErrorCodeString(cricket::BaseSession::Error err) { | 416 static std::string GetErrorCodeString(webrtc::WebRtcSession::Error err) { |
422 std::string result; | 417 std::string result; |
423 switch (err) { | 418 switch (err) { |
424 GET_STRING_OF_ERROR_CODE(ERROR_NONE) | 419 GET_STRING_OF_ERROR_CODE(ERROR_NONE) |
425 GET_STRING_OF_ERROR_CODE(ERROR_TIME) | |
426 GET_STRING_OF_ERROR_CODE(ERROR_RESPONSE) | |
427 GET_STRING_OF_ERROR_CODE(ERROR_NETWORK) | |
428 GET_STRING_OF_ERROR_CODE(ERROR_CONTENT) | 420 GET_STRING_OF_ERROR_CODE(ERROR_CONTENT) |
429 GET_STRING_OF_ERROR_CODE(ERROR_TRANSPORT) | 421 GET_STRING_OF_ERROR_CODE(ERROR_TRANSPORT) |
430 default: | 422 default: |
431 ASSERT(false); | 423 RTC_DCHECK(false); |
432 break; | 424 break; |
433 } | 425 } |
434 return result; | 426 return result; |
435 } | 427 } |
436 | 428 |
437 static std::string MakeErrorString(const std::string& error, | 429 static std::string MakeErrorString(const std::string& error, |
438 const std::string& desc) { | 430 const std::string& desc) { |
439 std::ostringstream ret; | 431 std::ostringstream ret; |
440 ret << error << " " << desc; | 432 ret << error << " " << desc; |
441 return ret.str(); | 433 return ret.str(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 526 } |
535 | 527 |
536 private: | 528 private: |
537 bool ice_restart_; | 529 bool ice_restart_; |
538 }; | 530 }; |
539 | 531 |
540 WebRtcSession::WebRtcSession(cricket::ChannelManager* channel_manager, | 532 WebRtcSession::WebRtcSession(cricket::ChannelManager* channel_manager, |
541 rtc::Thread* signaling_thread, | 533 rtc::Thread* signaling_thread, |
542 rtc::Thread* worker_thread, | 534 rtc::Thread* worker_thread, |
543 cricket::PortAllocator* port_allocator) | 535 cricket::PortAllocator* port_allocator) |
544 : cricket::BaseSession(signaling_thread, | 536 : signaling_thread_(signaling_thread), |
545 worker_thread, | 537 worker_thread_(worker_thread), |
546 port_allocator, | 538 port_allocator_(port_allocator), |
547 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX), | |
548 false), | |
549 // RFC 3264: The numeric value of the session id and version in the | 539 // RFC 3264: The numeric value of the session id and version in the |
550 // o line MUST be representable with a "64 bit signed integer". | 540 // o line MUST be representable with a "64 bit signed integer". |
551 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. | 541 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
| 542 sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)), |
| 543 transport_controller_(new cricket::TransportController(signaling_thread, |
| 544 worker_thread, |
| 545 port_allocator)), |
552 channel_manager_(channel_manager), | 546 channel_manager_(channel_manager), |
553 ice_observer_(NULL), | 547 ice_observer_(NULL), |
554 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), | 548 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
555 ice_connection_receiving_(true), | 549 ice_connection_receiving_(true), |
556 older_version_remote_peer_(false), | 550 older_version_remote_peer_(false), |
557 dtls_enabled_(false), | 551 dtls_enabled_(false), |
558 data_channel_type_(cricket::DCT_NONE), | 552 data_channel_type_(cricket::DCT_NONE), |
559 ice_restart_latch_(new IceRestartAnswerLatch), | 553 ice_restart_latch_(new IceRestartAnswerLatch), |
560 metrics_observer_(NULL) { | 554 metrics_observer_(NULL) { |
561 transport_controller()->SignalConnectionState.connect( | 555 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 556 transport_controller_->SignalConnectionState.connect( |
562 this, &WebRtcSession::OnTransportControllerConnectionState); | 557 this, &WebRtcSession::OnTransportControllerConnectionState); |
563 transport_controller()->SignalReceiving.connect( | 558 transport_controller_->SignalReceiving.connect( |
564 this, &WebRtcSession::OnTransportControllerReceiving); | 559 this, &WebRtcSession::OnTransportControllerReceiving); |
565 transport_controller()->SignalGatheringState.connect( | 560 transport_controller_->SignalGatheringState.connect( |
566 this, &WebRtcSession::OnTransportControllerGatheringState); | 561 this, &WebRtcSession::OnTransportControllerGatheringState); |
567 transport_controller()->SignalCandidatesGathered.connect( | 562 transport_controller_->SignalCandidatesGathered.connect( |
568 this, &WebRtcSession::OnTransportControllerCandidatesGathered); | 563 this, &WebRtcSession::OnTransportControllerCandidatesGathered); |
569 } | 564 } |
570 | 565 |
571 WebRtcSession::~WebRtcSession() { | 566 WebRtcSession::~WebRtcSession() { |
572 ASSERT(signaling_thread()->IsCurrent()); | 567 ASSERT(signaling_thread()->IsCurrent()); |
573 // Destroy video_channel_ first since it may have a pointer to the | 568 // Destroy video_channel_ first since it may have a pointer to the |
574 // voice_channel_. | 569 // voice_channel_. |
575 if (video_channel_) { | 570 if (video_channel_) { |
576 SignalVideoChannelDestroyed(); | 571 SignalVideoChannelDestroyed(); |
577 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 572 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
578 } | 573 } |
579 if (voice_channel_) { | 574 if (voice_channel_) { |
580 SignalVoiceChannelDestroyed(); | 575 SignalVoiceChannelDestroyed(); |
581 channel_manager_->DestroyVoiceChannel(voice_channel_.release()); | 576 channel_manager_->DestroyVoiceChannel(voice_channel_.release()); |
582 } | 577 } |
583 if (data_channel_) { | 578 if (data_channel_) { |
584 SignalDataChannelDestroyed(); | 579 SignalDataChannelDestroyed(); |
585 channel_manager_->DestroyDataChannel(data_channel_.release()); | 580 channel_manager_->DestroyDataChannel(data_channel_.release()); |
586 } | 581 } |
587 for (size_t i = 0; i < saved_candidates_.size(); ++i) { | 582 |
588 delete saved_candidates_[i]; | 583 LOG(LS_INFO) << "Session: " << id() << " is destroyed."; |
589 } | |
590 } | 584 } |
591 | 585 |
592 bool WebRtcSession::Initialize( | 586 bool WebRtcSession::Initialize( |
593 const PeerConnectionFactoryInterface::Options& options, | 587 const PeerConnectionFactoryInterface::Options& options, |
594 const MediaConstraintsInterface* constraints, | 588 const MediaConstraintsInterface* constraints, |
595 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 589 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
596 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { | 590 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
597 bundle_policy_ = rtc_configuration.bundle_policy; | 591 bundle_policy_ = rtc_configuration.bundle_policy; |
598 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; | 592 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; |
599 transport_controller()->SetSslMaxProtocolVersion(options.ssl_max_version); | 593 transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version); |
600 | 594 |
601 // Obtain a certificate from RTCConfiguration if any were provided (optional). | 595 // Obtain a certificate from RTCConfiguration if any were provided (optional). |
602 rtc::scoped_refptr<rtc::RTCCertificate> certificate; | 596 rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
603 if (!rtc_configuration.certificates.empty()) { | 597 if (!rtc_configuration.certificates.empty()) { |
604 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of | 598 // TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of |
605 // just picking the first one. The decision should be made based on the DTLS | 599 // just picking the first one. The decision should be made based on the DTLS |
606 // handshake. The DTLS negotiations need to know about all certificates. | 600 // handshake. The DTLS negotiations need to know about all certificates. |
607 certificate = rtc_configuration.certificates[0]; | 601 certificate = rtc_configuration.certificates[0]; |
608 } | 602 } |
609 | 603 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 port_allocator()->flags() | | 762 port_allocator()->flags() | |
769 cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE); | 763 cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE); |
770 } | 764 } |
771 | 765 |
772 media_controller_.reset(MediaControllerInterface::Create( | 766 media_controller_.reset(MediaControllerInterface::Create( |
773 worker_thread(), channel_manager_->media_engine()->GetVoE())); | 767 worker_thread(), channel_manager_->media_engine()->GetVoE())); |
774 | 768 |
775 return true; | 769 return true; |
776 } | 770 } |
777 | 771 |
778 cricket::IceConfig WebRtcSession::ParseIceConfig( | 772 void WebRtcSession::Close() { |
779 const PeerConnectionInterface::RTCConfiguration& config) const { | 773 SetState(STATE_CLOSED); |
780 cricket::IceConfig ice_config; | 774 RemoveUnusedChannels(nullptr); |
781 ice_config.receiving_timeout_ms = config.ice_connection_receiving_timeout; | |
782 ice_config.gather_continually = (config.continual_gathering_policy == | |
783 PeerConnectionInterface::GATHER_CONTINUALLY); | |
784 return ice_config; | |
785 } | |
786 | |
787 void WebRtcSession::Terminate() { | |
788 SetState(STATE_RECEIVEDTERMINATE); | |
789 RemoveUnusedChannels(NULL); | |
790 ASSERT(!voice_channel_); | 775 ASSERT(!voice_channel_); |
791 ASSERT(!video_channel_); | 776 ASSERT(!video_channel_); |
792 ASSERT(!data_channel_); | 777 ASSERT(!data_channel_); |
793 } | 778 } |
794 | 779 |
795 void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) { | 780 void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) { |
796 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy); | 781 webrtc_session_desc_factory_->SetSdesPolicy(secure_policy); |
797 } | 782 } |
798 | 783 |
799 cricket::SecurePolicy WebRtcSession::SdesPolicy() const { | 784 cricket::SecurePolicy WebRtcSession::SdesPolicy() const { |
800 return webrtc_session_desc_factory_->SdesPolicy(); | 785 return webrtc_session_desc_factory_->SdesPolicy(); |
801 } | 786 } |
802 | 787 |
803 bool WebRtcSession::GetSslRole(rtc::SSLRole* role) { | 788 bool WebRtcSession::GetSslRole(rtc::SSLRole* role) { |
804 if (local_description() == NULL || remote_description() == NULL) { | 789 if (!local_desc_ || !remote_desc_) { |
805 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " | 790 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " |
806 << "SSL Role of the session."; | 791 << "SSL Role of the session."; |
807 return false; | 792 return false; |
808 } | 793 } |
809 | 794 |
810 return transport_controller()->GetSslRole(role); | 795 return transport_controller_->GetSslRole(role); |
811 } | 796 } |
812 | 797 |
813 void WebRtcSession::CreateOffer( | 798 void WebRtcSession::CreateOffer( |
814 CreateSessionDescriptionObserver* observer, | 799 CreateSessionDescriptionObserver* observer, |
815 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | 800 const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
816 const cricket::MediaSessionOptions& session_options) { | 801 const cricket::MediaSessionOptions& session_options) { |
817 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); | 802 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); |
818 } | 803 } |
819 | 804 |
820 void WebRtcSession::CreateAnswer( | 805 void WebRtcSession::CreateAnswer( |
821 CreateSessionDescriptionObserver* observer, | 806 CreateSessionDescriptionObserver* observer, |
822 const MediaConstraintsInterface* constraints, | 807 const MediaConstraintsInterface* constraints, |
823 const cricket::MediaSessionOptions& session_options) { | 808 const cricket::MediaSessionOptions& session_options) { |
824 webrtc_session_desc_factory_->CreateAnswer(observer, constraints, | 809 webrtc_session_desc_factory_->CreateAnswer(observer, constraints, |
825 session_options); | 810 session_options); |
826 } | 811 } |
827 | 812 |
828 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, | 813 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
829 std::string* err_desc) { | 814 std::string* err_desc) { |
830 ASSERT(signaling_thread()->IsCurrent()); | 815 ASSERT(signaling_thread()->IsCurrent()); |
831 | 816 |
832 // Takes the ownership of |desc| regardless of the result. | 817 // Takes the ownership of |desc| regardless of the result. |
833 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 818 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
834 | 819 |
835 // Validate SDP. | 820 // Validate SDP. |
836 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { | 821 if (!ValidateSessionDescription(desc, cricket::CS_LOCAL, err_desc)) { |
837 return false; | 822 return false; |
838 } | 823 } |
839 | 824 |
840 // Update the initiator flag if this session is the initiator. | 825 // Update the initial_offerer flag if this session is the initial_offerer. |
841 Action action = GetAction(desc->type()); | 826 Action action = GetAction(desc->type()); |
842 if (state() == STATE_INIT && action == kOffer) { | 827 if (state() == STATE_INIT && action == kOffer) { |
843 set_initiator(true); | 828 initial_offerer_ = true; |
| 829 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); |
844 } | 830 } |
845 | 831 |
846 cricket::SecurePolicy sdes_policy = | 832 cricket::SecurePolicy sdes_policy = |
847 webrtc_session_desc_factory_->SdesPolicy(); | 833 webrtc_session_desc_factory_->SdesPolicy(); |
848 cricket::CryptoType crypto_required = dtls_enabled_ ? | 834 cricket::CryptoType crypto_required = dtls_enabled_ ? |
849 cricket::CT_DTLS : (sdes_policy == cricket::SEC_REQUIRED ? | 835 cricket::CT_DTLS : (sdes_policy == cricket::SEC_REQUIRED ? |
850 cricket::CT_SDES : cricket::CT_NONE); | 836 cricket::CT_SDES : cricket::CT_NONE); |
851 // Update the MediaContentDescription crypto settings as per the policy set. | 837 // Update the MediaContentDescription crypto settings as per the policy set. |
852 UpdateSessionDescriptionSecurePolicy(crypto_required, desc->description()); | 838 UpdateSessionDescriptionSecurePolicy(crypto_required, desc->description()); |
853 | 839 |
854 set_local_description(desc->description()->Copy()); | |
855 local_desc_.reset(desc_temp.release()); | 840 local_desc_.reset(desc_temp.release()); |
856 | 841 |
857 // Transport and Media channels will be created only when offer is set. | 842 // Transport and Media channels will be created only when offer is set. |
858 if (action == kOffer && !CreateChannels(local_desc_->description())) { | 843 if (action == kOffer && !CreateChannels(local_desc_->description())) { |
859 // TODO(mallinath) - Handle CreateChannel failure, as new local description | 844 // TODO(mallinath) - Handle CreateChannel failure, as new local description |
860 // is applied. Restore back to old description. | 845 // is applied. Restore back to old description. |
861 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); | 846 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); |
862 } | 847 } |
863 | 848 |
864 // Remove unused channels if MediaContentDescription is rejected. | 849 // Remove unused channels if MediaContentDescription is rejected. |
865 RemoveUnusedChannels(local_desc_->description()); | 850 RemoveUnusedChannels(local_desc_->description()); |
866 | 851 |
867 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { | 852 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { |
868 return false; | 853 return false; |
869 } | 854 } |
870 | 855 |
871 if (remote_description()) { | 856 if (remote_desc_) { |
872 // Now that we have a local description, we can push down remote candidates | 857 // Now that we have a local description, we can push down remote candidates. |
873 // that we stored, and those from the remote description. | |
874 if (!saved_candidates_.empty()) { | |
875 // If there are saved candidates which arrived before the local | |
876 // description was set, copy those to the remote description. | |
877 CopySavedCandidates(remote_desc_.get()); | |
878 } | |
879 // Push remote candidates in remote description to transport channels. | |
880 UseCandidatesInSessionDescription(remote_desc_.get()); | 858 UseCandidatesInSessionDescription(remote_desc_.get()); |
881 } | 859 } |
882 | 860 |
883 if (error() != cricket::BaseSession::ERROR_NONE) { | 861 if (error() != ERROR_NONE) { |
884 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); | 862 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
885 } | 863 } |
886 return true; | 864 return true; |
887 } | 865 } |
888 | 866 |
889 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, | 867 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, |
890 std::string* err_desc) { | 868 std::string* err_desc) { |
891 ASSERT(signaling_thread()->IsCurrent()); | 869 ASSERT(signaling_thread()->IsCurrent()); |
892 | 870 |
893 // Takes the ownership of |desc| regardless of the result. | 871 // Takes the ownership of |desc| regardless of the result. |
894 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 872 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
895 | 873 |
896 // Validate SDP. | 874 // Validate SDP. |
897 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { | 875 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { |
898 return false; | 876 return false; |
899 } | 877 } |
900 | 878 |
| 879 rtc::scoped_ptr<SessionDescriptionInterface> old_remote_desc( |
| 880 remote_desc_.release()); |
| 881 remote_desc_.reset(desc_temp.release()); |
| 882 |
901 // Transport and Media channels will be created only when offer is set. | 883 // Transport and Media channels will be created only when offer is set. |
902 Action action = GetAction(desc->type()); | 884 Action action = GetAction(desc->type()); |
903 if (action == kOffer && !CreateChannels(desc->description())) { | 885 if (action == kOffer && !CreateChannels(desc->description())) { |
904 // TODO(mallinath) - Handle CreateChannel failure, as new local description | 886 // TODO(mallinath) - Handle CreateChannel failure, as new local description |
905 // is applied. Restore back to old description. | 887 // is applied. Restore back to old description. |
906 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); | 888 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); |
907 } | 889 } |
908 | 890 |
909 // Remove unused channels if MediaContentDescription is rejected. | 891 // Remove unused channels if MediaContentDescription is rejected. |
910 RemoveUnusedChannels(desc->description()); | 892 RemoveUnusedChannels(desc->description()); |
911 | 893 |
912 // NOTE: Candidates allocation will be initiated only when SetLocalDescription | 894 // NOTE: Candidates allocation will be initiated only when SetLocalDescription |
913 // is called. | 895 // is called. |
914 set_remote_description(desc->description()->Copy()); | |
915 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { | 896 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { |
916 return false; | 897 return false; |
917 } | 898 } |
918 | 899 |
919 if (local_description() && !UseCandidatesInSessionDescription(desc)) { | 900 if (local_desc_ && !UseCandidatesInSessionDescription(desc)) { |
920 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); | 901 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); |
921 } | 902 } |
922 | 903 |
923 // Copy all saved candidates. | |
924 CopySavedCandidates(desc); | |
925 | |
926 // Check if this new SessionDescription contains new ice ufrag and password | 904 // Check if this new SessionDescription contains new ice ufrag and password |
927 // that indicates the remote peer requests ice restart. | 905 // that indicates the remote peer requests ice restart. |
928 bool ice_restart = | 906 bool ice_restart = |
929 ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(), desc); | 907 ice_restart_latch_->CheckForRemoteIceRestart(old_remote_desc.get(), desc); |
930 // We retain all received candidates only if ICE is not restarted. | 908 // We retain all received candidates only if ICE is not restarted. |
931 // When ICE is restarted, all previous candidates belong to an old generation | 909 // When ICE is restarted, all previous candidates belong to an old generation |
932 // and should not be kept. | 910 // and should not be kept. |
| 911 // TODO(deadbeef): This goes against the W3C spec which says the remote |
| 912 // description should only contain candidates from the last set remote |
| 913 // description plus any candidates added since then. We should remove this |
| 914 // once we're sure it won't break anything. |
933 if (!ice_restart) { | 915 if (!ice_restart) { |
934 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( | 916 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
935 remote_desc_.get(), desc); | 917 old_remote_desc.get(), desc); |
936 } | 918 } |
937 | 919 |
938 remote_desc_.reset(desc_temp.release()); | 920 if (error() != ERROR_NONE) { |
939 | |
940 if (error() != cricket::BaseSession::ERROR_NONE) { | |
941 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); | 921 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
942 } | 922 } |
943 | 923 |
944 // Set the the ICE connection state to connecting since the connection may | 924 // Set the the ICE connection state to connecting since the connection may |
945 // become writable with peer reflexive candidates before any remote candidate | 925 // become writable with peer reflexive candidates before any remote candidate |
946 // is signaled. | 926 // is signaled. |
947 // TODO(pthatcher): This is a short-term solution for crbug/446908. A real fix | 927 // TODO(pthatcher): This is a short-term solution for crbug/446908. A real fix |
948 // is to have a new signal the indicates a change in checking state from the | 928 // is to have a new signal the indicates a change in checking state from the |
949 // transport and expose a new checking() member from transport that can be | 929 // transport and expose a new checking() member from transport that can be |
950 // read to determine the current checking state. The existing SignalConnecting | 930 // read to determine the current checking state. The existing SignalConnecting |
951 // actually means "gathering candidates", so cannot be be used here. | 931 // actually means "gathering candidates", so cannot be be used here. |
952 if (desc->type() != SessionDescriptionInterface::kOffer && | 932 if (desc->type() != SessionDescriptionInterface::kOffer && |
953 ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) { | 933 ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew) { |
954 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); | 934 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
955 } | 935 } |
956 return true; | 936 return true; |
957 } | 937 } |
958 | 938 |
| 939 void WebRtcSession::LogState(State old_state, State new_state) { |
| 940 LOG(LS_INFO) << "Session:" << id() |
| 941 << " Old state:" << GetStateString(old_state) |
| 942 << " New state:" << GetStateString(new_state); |
| 943 } |
| 944 |
| 945 void WebRtcSession::SetState(State state) { |
| 946 ASSERT(signaling_thread_->IsCurrent()); |
| 947 if (state != state_) { |
| 948 LogState(state_, state); |
| 949 state_ = state; |
| 950 SignalState(this, state_); |
| 951 } |
| 952 } |
| 953 |
| 954 void WebRtcSession::SetError(Error error, const std::string& error_desc) { |
| 955 ASSERT(signaling_thread_->IsCurrent()); |
| 956 if (error != error_) { |
| 957 error_ = error; |
| 958 error_desc_ = error_desc; |
| 959 } |
| 960 } |
| 961 |
959 bool WebRtcSession::UpdateSessionState( | 962 bool WebRtcSession::UpdateSessionState( |
960 Action action, cricket::ContentSource source, | 963 Action action, cricket::ContentSource source, |
961 std::string* err_desc) { | 964 std::string* err_desc) { |
962 ASSERT(signaling_thread()->IsCurrent()); | 965 ASSERT(signaling_thread()->IsCurrent()); |
963 | 966 |
964 // If there's already a pending error then no state transition should happen. | 967 // If there's already a pending error then no state transition should happen. |
965 // But all call-sites should be verifying this before calling us! | 968 // But all call-sites should be verifying this before calling us! |
966 ASSERT(error() == cricket::BaseSession::ERROR_NONE); | 969 ASSERT(error() == ERROR_NONE); |
967 std::string td_err; | 970 std::string td_err; |
968 if (action == kOffer) { | 971 if (action == kOffer) { |
969 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) { | 972 if (!PushdownTransportDescription(source, cricket::CA_OFFER, &td_err)) { |
970 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc); | 973 return BadOfferSdp(source, MakeTdErrorString(td_err), err_desc); |
971 } | 974 } |
972 SetState(source == cricket::CS_LOCAL ? | 975 SetState(source == cricket::CS_LOCAL ? STATE_SENTOFFER |
973 STATE_SENTINITIATE : STATE_RECEIVEDINITIATE); | 976 : STATE_RECEIVEDOFFER); |
974 if (!PushdownMediaDescription(cricket::CA_OFFER, source, err_desc)) { | 977 if (!PushdownMediaDescription(cricket::CA_OFFER, source, err_desc)) { |
975 SetError(BaseSession::ERROR_CONTENT, *err_desc); | 978 SetError(ERROR_CONTENT, *err_desc); |
976 } | 979 } |
977 if (error() != cricket::BaseSession::ERROR_NONE) { | 980 if (error() != ERROR_NONE) { |
978 return BadOfferSdp(source, GetSessionErrorMsg(), err_desc); | 981 return BadOfferSdp(source, GetSessionErrorMsg(), err_desc); |
979 } | 982 } |
980 } else if (action == kPrAnswer) { | 983 } else if (action == kPrAnswer) { |
981 if (!PushdownTransportDescription(source, cricket::CA_PRANSWER, &td_err)) { | 984 if (!PushdownTransportDescription(source, cricket::CA_PRANSWER, &td_err)) { |
982 return BadPranswerSdp(source, MakeTdErrorString(td_err), err_desc); | 985 return BadPranswerSdp(source, MakeTdErrorString(td_err), err_desc); |
983 } | 986 } |
984 EnableChannels(); | 987 EnableChannels(); |
985 SetState(source == cricket::CS_LOCAL ? | 988 SetState(source == cricket::CS_LOCAL ? STATE_SENTPRANSWER |
986 STATE_SENTPRACCEPT : STATE_RECEIVEDPRACCEPT); | 989 : STATE_RECEIVEDPRANSWER); |
987 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { | 990 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { |
988 SetError(BaseSession::ERROR_CONTENT, *err_desc); | 991 SetError(ERROR_CONTENT, *err_desc); |
989 } | 992 } |
990 if (error() != cricket::BaseSession::ERROR_NONE) { | 993 if (error() != ERROR_NONE) { |
991 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); | 994 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); |
992 } | 995 } |
993 } else if (action == kAnswer) { | 996 } else if (action == kAnswer) { |
994 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) { | 997 if (!PushdownTransportDescription(source, cricket::CA_ANSWER, &td_err)) { |
995 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc); | 998 return BadAnswerSdp(source, MakeTdErrorString(td_err), err_desc); |
996 } | 999 } |
997 const cricket::ContentGroup* local_bundle = | 1000 const cricket::ContentGroup* local_bundle = |
998 BaseSession::local_description()->GetGroupByName( | 1001 local_desc_->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
999 cricket::GROUP_TYPE_BUNDLE); | |
1000 const cricket::ContentGroup* remote_bundle = | 1002 const cricket::ContentGroup* remote_bundle = |
1001 BaseSession::remote_description()->GetGroupByName( | 1003 remote_desc_->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
1002 cricket::GROUP_TYPE_BUNDLE); | |
1003 if (local_bundle && remote_bundle) { | 1004 if (local_bundle && remote_bundle) { |
1004 // The answerer decides the transport to bundle on | 1005 // The answerer decides the transport to bundle on |
1005 const cricket::ContentGroup* answer_bundle = | 1006 const cricket::ContentGroup* answer_bundle = |
1006 (source == cricket::CS_LOCAL ? local_bundle : remote_bundle); | 1007 (source == cricket::CS_LOCAL ? local_bundle : remote_bundle); |
1007 if (!EnableBundle(*answer_bundle)) { | 1008 if (!EnableBundle(*answer_bundle)) { |
1008 LOG(LS_WARNING) << "Failed to enable BUNDLE."; | 1009 LOG(LS_WARNING) << "Failed to enable BUNDLE."; |
1009 return BadAnswerSdp(source, kEnableBundleFailed, err_desc); | 1010 return BadAnswerSdp(source, kEnableBundleFailed, err_desc); |
1010 } | 1011 } |
1011 } | 1012 } |
1012 EnableChannels(); | 1013 EnableChannels(); |
1013 SetState(source == cricket::CS_LOCAL ? | 1014 SetState(STATE_INPROGRESS); |
1014 STATE_SENTACCEPT : STATE_RECEIVEDACCEPT); | |
1015 if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) { | 1015 if (!PushdownMediaDescription(cricket::CA_ANSWER, source, err_desc)) { |
1016 SetError(BaseSession::ERROR_CONTENT, *err_desc); | 1016 SetError(ERROR_CONTENT, *err_desc); |
1017 } | 1017 } |
1018 if (error() != cricket::BaseSession::ERROR_NONE) { | 1018 if (error() != ERROR_NONE) { |
1019 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc); | 1019 return BadAnswerSdp(source, GetSessionErrorMsg(), err_desc); |
1020 } | 1020 } |
1021 } | 1021 } |
1022 return true; | 1022 return true; |
1023 } | 1023 } |
1024 | 1024 |
| 1025 WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) { |
| 1026 if (type == SessionDescriptionInterface::kOffer) { |
| 1027 return WebRtcSession::kOffer; |
| 1028 } else if (type == SessionDescriptionInterface::kPrAnswer) { |
| 1029 return WebRtcSession::kPrAnswer; |
| 1030 } else if (type == SessionDescriptionInterface::kAnswer) { |
| 1031 return WebRtcSession::kAnswer; |
| 1032 } |
| 1033 ASSERT(false && "unknown action type"); |
| 1034 return WebRtcSession::kOffer; |
| 1035 } |
| 1036 |
1025 bool WebRtcSession::PushdownMediaDescription( | 1037 bool WebRtcSession::PushdownMediaDescription( |
1026 cricket::ContentAction action, | 1038 cricket::ContentAction action, |
1027 cricket::ContentSource source, | 1039 cricket::ContentSource source, |
1028 std::string* err) { | 1040 std::string* err) { |
1029 auto set_content = [this, action, source, err](cricket::BaseChannel* ch) { | 1041 auto set_content = [this, action, source, err](cricket::BaseChannel* ch) { |
1030 if (!ch) { | 1042 if (!ch) { |
1031 return true; | 1043 return true; |
1032 } else if (source == cricket::CS_LOCAL) { | 1044 } else if (source == cricket::CS_LOCAL) { |
1033 return ch->PushdownLocalDescription( | 1045 return ch->PushdownLocalDescription(local_desc_->description(), action, |
1034 base_local_description(), action, err); | 1046 err); |
1035 } else { | 1047 } else { |
1036 return ch->PushdownRemoteDescription( | 1048 return ch->PushdownRemoteDescription(remote_desc_->description(), action, |
1037 base_remote_description(), action, err); | 1049 err); |
1038 } | 1050 } |
1039 }; | 1051 }; |
1040 | 1052 |
1041 return (set_content(voice_channel()) && | 1053 return (set_content(voice_channel()) && |
1042 set_content(video_channel()) && | 1054 set_content(video_channel()) && |
1043 set_content(data_channel())); | 1055 set_content(data_channel())); |
1044 } | 1056 } |
1045 | 1057 |
1046 WebRtcSession::Action WebRtcSession::GetAction(const std::string& type) { | 1058 bool WebRtcSession::PushdownTransportDescription(cricket::ContentSource source, |
1047 if (type == SessionDescriptionInterface::kOffer) { | 1059 cricket::ContentAction action, |
1048 return WebRtcSession::kOffer; | 1060 std::string* error_desc) { |
1049 } else if (type == SessionDescriptionInterface::kPrAnswer) { | 1061 RTC_DCHECK(signaling_thread()->IsCurrent()); |
1050 return WebRtcSession::kPrAnswer; | 1062 |
1051 } else if (type == SessionDescriptionInterface::kAnswer) { | 1063 if (source == cricket::CS_LOCAL) { |
1052 return WebRtcSession::kAnswer; | 1064 return PushdownLocalTransportDescription(local_desc_->description(), action, |
| 1065 error_desc); |
1053 } | 1066 } |
1054 ASSERT(false && "unknown action type"); | 1067 return PushdownRemoteTransportDescription(remote_desc_->description(), action, |
1055 return WebRtcSession::kOffer; | 1068 error_desc); |
1056 } | 1069 } |
1057 | 1070 |
1058 bool WebRtcSession::GetTransportStats(cricket::SessionStats* stats) { | 1071 bool WebRtcSession::PushdownLocalTransportDescription( |
| 1072 const SessionDescription* sdesc, |
| 1073 cricket::ContentAction action, |
| 1074 std::string* err) { |
| 1075 RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 1076 |
| 1077 if (!sdesc) { |
| 1078 return false; |
| 1079 } |
| 1080 |
| 1081 for (const TransportInfo& tinfo : sdesc->transport_infos()) { |
| 1082 if (!transport_controller_->SetLocalTransportDescription( |
| 1083 tinfo.content_name, tinfo.description, action, err)) { |
| 1084 return false; |
| 1085 } |
| 1086 } |
| 1087 |
| 1088 return true; |
| 1089 } |
| 1090 |
| 1091 bool WebRtcSession::PushdownRemoteTransportDescription( |
| 1092 const SessionDescription* sdesc, |
| 1093 cricket::ContentAction action, |
| 1094 std::string* err) { |
| 1095 RTC_DCHECK(signaling_thread()->IsCurrent()); |
| 1096 |
| 1097 if (!sdesc) { |
| 1098 return false; |
| 1099 } |
| 1100 |
| 1101 for (const TransportInfo& tinfo : sdesc->transport_infos()) { |
| 1102 if (!transport_controller_->SetRemoteTransportDescription( |
| 1103 tinfo.content_name, tinfo.description, action, err)) { |
| 1104 return false; |
| 1105 } |
| 1106 } |
| 1107 |
| 1108 return true; |
| 1109 } |
| 1110 |
| 1111 bool WebRtcSession::GetTransportDescription( |
| 1112 const SessionDescription* description, |
| 1113 const std::string& content_name, |
| 1114 cricket::TransportDescription* tdesc) { |
| 1115 if (!description || !tdesc) { |
| 1116 return false; |
| 1117 } |
| 1118 const TransportInfo* transport_info = |
| 1119 description->GetTransportInfoByName(content_name); |
| 1120 if (!transport_info) { |
| 1121 return false; |
| 1122 } |
| 1123 *tdesc = transport_info->description; |
| 1124 return true; |
| 1125 } |
| 1126 |
| 1127 bool WebRtcSession::GetTransportStats(SessionStats* stats) { |
1059 ASSERT(signaling_thread()->IsCurrent()); | 1128 ASSERT(signaling_thread()->IsCurrent()); |
1060 return (GetChannelTransportStats(voice_channel(), stats) && | 1129 return (GetChannelTransportStats(voice_channel(), stats) && |
1061 GetChannelTransportStats(video_channel(), stats) && | 1130 GetChannelTransportStats(video_channel(), stats) && |
1062 GetChannelTransportStats(data_channel(), stats)); | 1131 GetChannelTransportStats(data_channel(), stats)); |
1063 } | 1132 } |
1064 | 1133 |
1065 bool WebRtcSession::GetChannelTransportStats(cricket::BaseChannel* ch, | 1134 bool WebRtcSession::GetChannelTransportStats(cricket::BaseChannel* ch, |
1066 cricket::SessionStats* stats) { | 1135 SessionStats* stats) { |
1067 ASSERT(signaling_thread()->IsCurrent()); | 1136 ASSERT(signaling_thread()->IsCurrent()); |
1068 if (!ch) { | 1137 if (!ch) { |
1069 // Not using this channel. | 1138 // Not using this channel. |
1070 return true; | 1139 return true; |
1071 } | 1140 } |
1072 | 1141 |
1073 const std::string& content_name = ch->content_name(); | 1142 const std::string& content_name = ch->content_name(); |
1074 const std::string& transport_name = ch->transport_name(); | 1143 const std::string& transport_name = ch->transport_name(); |
1075 stats->proxy_to_transport[content_name] = transport_name; | 1144 stats->proxy_to_transport[content_name] = transport_name; |
1076 if (stats->transport_stats.find(transport_name) != | 1145 if (stats->transport_stats.find(transport_name) != |
1077 stats->transport_stats.end()) { | 1146 stats->transport_stats.end()) { |
1078 // Transport stats already done for this transport. | 1147 // Transport stats already done for this transport. |
1079 return true; | 1148 return true; |
1080 } | 1149 } |
1081 | 1150 |
1082 cricket::TransportStats tstats; | 1151 cricket::TransportStats tstats; |
1083 if (!transport_controller()->GetStats(transport_name, &tstats)) { | 1152 if (!transport_controller_->GetStats(transport_name, &tstats)) { |
1084 return false; | 1153 return false; |
1085 } | 1154 } |
1086 | 1155 |
1087 stats->transport_stats[transport_name] = tstats; | 1156 stats->transport_stats[transport_name] = tstats; |
1088 return true; | 1157 return true; |
1089 } | 1158 } |
1090 | 1159 |
1091 bool WebRtcSession::GetLocalCertificate( | 1160 bool WebRtcSession::GetLocalCertificate( |
1092 const std::string& transport_name, | 1161 const std::string& transport_name, |
1093 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | 1162 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
1094 ASSERT(signaling_thread()->IsCurrent()); | 1163 ASSERT(signaling_thread()->IsCurrent()); |
1095 return transport_controller()->GetLocalCertificate(transport_name, | 1164 return transport_controller_->GetLocalCertificate(transport_name, |
1096 certificate); | 1165 certificate); |
1097 } | 1166 } |
1098 | 1167 |
1099 bool WebRtcSession::GetRemoteSSLCertificate(const std::string& transport_name, | 1168 bool WebRtcSession::GetRemoteSSLCertificate(const std::string& transport_name, |
1100 rtc::SSLCertificate** cert) { | 1169 rtc::SSLCertificate** cert) { |
1101 ASSERT(signaling_thread()->IsCurrent()); | 1170 ASSERT(signaling_thread()->IsCurrent()); |
1102 return transport_controller()->GetRemoteSSLCertificate(transport_name, cert); | 1171 return transport_controller_->GetRemoteSSLCertificate(transport_name, cert); |
1103 } | 1172 } |
1104 | 1173 |
1105 cricket::BaseChannel* WebRtcSession::GetChannel( | 1174 cricket::BaseChannel* WebRtcSession::GetChannel( |
1106 const std::string& content_name) { | 1175 const std::string& content_name) { |
1107 if (voice_channel() && voice_channel()->content_name() == content_name) { | 1176 if (voice_channel() && voice_channel()->content_name() == content_name) { |
1108 return voice_channel(); | 1177 return voice_channel(); |
1109 } | 1178 } |
1110 if (video_channel() && video_channel()->content_name() == content_name) { | 1179 if (video_channel() && video_channel()->content_name() == content_name) { |
1111 return video_channel(); | 1180 return video_channel(); |
1112 } | 1181 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 if (!maybe_set_transport(voice_channel()) || | 1218 if (!maybe_set_transport(voice_channel()) || |
1150 !maybe_set_transport(video_channel()) || | 1219 !maybe_set_transport(video_channel()) || |
1151 !maybe_set_transport(data_channel())) { | 1220 !maybe_set_transport(data_channel())) { |
1152 return false; | 1221 return false; |
1153 } | 1222 } |
1154 | 1223 |
1155 return true; | 1224 return true; |
1156 } | 1225 } |
1157 | 1226 |
1158 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { | 1227 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
1159 if (state() == STATE_INIT) { | 1228 if (!remote_desc_) { |
1160 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " | 1229 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
1161 << "without any offer (local or remote) " | 1230 << "without any remote session description."; |
1162 << "session description."; | |
1163 return false; | 1231 return false; |
1164 } | 1232 } |
1165 | 1233 |
1166 if (!candidate) { | 1234 if (!candidate) { |
1167 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL"; | 1235 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; |
1168 return false; | 1236 return false; |
1169 } | 1237 } |
1170 | 1238 |
1171 bool valid = false; | 1239 bool valid = false; |
1172 if (!ReadyToUseRemoteCandidate(candidate, NULL, &valid)) { | 1240 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); |
1173 if (valid) { | 1241 if (!valid) { |
1174 LOG(LS_INFO) << "ProcessIceMessage: Candidate saved"; | 1242 return false; |
1175 saved_candidates_.push_back( | |
1176 new JsepIceCandidate(candidate->sdp_mid(), | |
1177 candidate->sdp_mline_index(), | |
1178 candidate->candidate())); | |
1179 } | |
1180 return valid; | |
1181 } | 1243 } |
1182 | 1244 |
1183 // Add this candidate to the remote session description. | 1245 // Add this candidate to the remote session description. |
1184 if (!remote_desc_->AddCandidate(candidate)) { | 1246 if (!remote_desc_->AddCandidate(candidate)) { |
1185 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used"; | 1247 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; |
1186 return false; | 1248 return false; |
1187 } | 1249 } |
1188 | 1250 |
1189 return UseCandidate(candidate); | 1251 if (ready) { |
| 1252 return UseCandidate(candidate); |
| 1253 } else { |
| 1254 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; |
| 1255 return true; |
| 1256 } |
1190 } | 1257 } |
1191 | 1258 |
1192 bool WebRtcSession::SetIceTransports( | 1259 bool WebRtcSession::SetIceTransports( |
1193 PeerConnectionInterface::IceTransportsType type) { | 1260 PeerConnectionInterface::IceTransportsType type) { |
1194 return port_allocator()->set_candidate_filter( | 1261 return port_allocator()->set_candidate_filter( |
1195 ConvertIceTransportTypeToCandidateFilter(type)); | 1262 ConvertIceTransportTypeToCandidateFilter(type)); |
1196 } | 1263 } |
1197 | 1264 |
| 1265 cricket::IceConfig WebRtcSession::ParseIceConfig( |
| 1266 const PeerConnectionInterface::RTCConfiguration& config) const { |
| 1267 cricket::IceConfig ice_config; |
| 1268 ice_config.receiving_timeout_ms = config.ice_connection_receiving_timeout; |
| 1269 ice_config.gather_continually = (config.continual_gathering_policy == |
| 1270 PeerConnectionInterface::GATHER_CONTINUALLY); |
| 1271 return ice_config; |
| 1272 } |
| 1273 |
| 1274 void WebRtcSession::SetIceConfig(const cricket::IceConfig& config) { |
| 1275 transport_controller_->SetIceConfig(config); |
| 1276 } |
| 1277 |
| 1278 void WebRtcSession::MaybeStartGathering() { |
| 1279 transport_controller_->MaybeStartGathering(); |
| 1280 } |
| 1281 |
1198 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc, | 1282 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc, |
1199 std::string* track_id) { | 1283 std::string* track_id) { |
1200 if (!base_local_description()) | 1284 if (!local_desc_) { |
1201 return false; | 1285 return false; |
1202 return webrtc::GetTrackIdBySsrc(base_local_description(), ssrc, track_id); | 1286 } |
| 1287 return webrtc::GetTrackIdBySsrc(local_desc_->description(), ssrc, track_id); |
1203 } | 1288 } |
1204 | 1289 |
1205 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc, | 1290 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc, |
1206 std::string* track_id) { | 1291 std::string* track_id) { |
1207 if (!base_remote_description()) | 1292 if (!remote_desc_) { |
1208 return false; | 1293 return false; |
1209 return webrtc::GetTrackIdBySsrc(base_remote_description(), ssrc, track_id); | 1294 } |
| 1295 return webrtc::GetTrackIdBySsrc(remote_desc_->description(), ssrc, track_id); |
1210 } | 1296 } |
1211 | 1297 |
1212 std::string WebRtcSession::BadStateErrMsg(State state) { | 1298 std::string WebRtcSession::BadStateErrMsg(State state) { |
1213 std::ostringstream desc; | 1299 std::ostringstream desc; |
1214 desc << "Called in wrong state: " << GetStateString(state); | 1300 desc << "Called in wrong state: " << GetStateString(state); |
1215 return desc.str(); | 1301 return desc.str(); |
1216 } | 1302 } |
1217 | 1303 |
1218 void WebRtcSession::SetAudioPlayout(uint32_t ssrc, bool enable) { | 1304 void WebRtcSession::SetAudioPlayout(uint32_t ssrc, bool enable) { |
1219 ASSERT(signaling_thread()->IsCurrent()); | 1305 ASSERT(signaling_thread()->IsCurrent()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 | 1396 |
1311 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { | 1397 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { |
1312 ASSERT(signaling_thread()->IsCurrent()); | 1398 ASSERT(signaling_thread()->IsCurrent()); |
1313 if (!voice_channel_) { | 1399 if (!voice_channel_) { |
1314 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; | 1400 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; |
1315 return false; | 1401 return false; |
1316 } | 1402 } |
1317 uint32_t send_ssrc = 0; | 1403 uint32_t send_ssrc = 0; |
1318 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc | 1404 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc |
1319 // exists. | 1405 // exists. |
1320 if (!GetAudioSsrcByTrackId(base_local_description(), track_id, | 1406 if (!local_desc_ || |
| 1407 !GetAudioSsrcByTrackId(local_desc_->description(), track_id, |
1321 &send_ssrc)) { | 1408 &send_ssrc)) { |
1322 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; | 1409 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; |
1323 return false; | 1410 return false; |
1324 } | 1411 } |
1325 return voice_channel_->CanInsertDtmf(); | 1412 return voice_channel_->CanInsertDtmf(); |
1326 } | 1413 } |
1327 | 1414 |
1328 bool WebRtcSession::InsertDtmf(const std::string& track_id, | 1415 bool WebRtcSession::InsertDtmf(const std::string& track_id, |
1329 int code, int duration) { | 1416 int code, int duration) { |
1330 ASSERT(signaling_thread()->IsCurrent()); | 1417 ASSERT(signaling_thread()->IsCurrent()); |
1331 if (!voice_channel_) { | 1418 if (!voice_channel_) { |
1332 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; | 1419 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; |
1333 return false; | 1420 return false; |
1334 } | 1421 } |
1335 uint32_t send_ssrc = 0; | 1422 uint32_t send_ssrc = 0; |
1336 if (!VERIFY(GetAudioSsrcByTrackId(base_local_description(), | 1423 if (!VERIFY(local_desc_ && GetAudioSsrcByTrackId(local_desc_->description(), |
1337 track_id, &send_ssrc))) { | 1424 track_id, &send_ssrc))) { |
1338 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; | 1425 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; |
1339 return false; | 1426 return false; |
1340 } | 1427 } |
1341 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration, | 1428 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration, |
1342 cricket::DF_SEND)) { | 1429 cricket::DF_SEND)) { |
1343 LOG(LS_ERROR) << "Failed to insert DTMF to channel."; | 1430 LOG(LS_ERROR) << "Failed to insert DTMF to channel."; |
1344 return false; | 1431 return false; |
1345 } | 1432 } |
1346 return true; | 1433 return true; |
1347 } | 1434 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 bool WebRtcSession::IceRestartPending() const { | 1501 bool WebRtcSession::IceRestartPending() const { |
1415 return ice_restart_latch_->Get(); | 1502 return ice_restart_latch_->Get(); |
1416 } | 1503 } |
1417 | 1504 |
1418 void WebRtcSession::ResetIceRestartLatch() { | 1505 void WebRtcSession::ResetIceRestartLatch() { |
1419 ice_restart_latch_->Reset(); | 1506 ice_restart_latch_->Reset(); |
1420 } | 1507 } |
1421 | 1508 |
1422 void WebRtcSession::OnCertificateReady( | 1509 void WebRtcSession::OnCertificateReady( |
1423 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | 1510 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
1424 transport_controller()->SetLocalCertificate(certificate); | 1511 transport_controller_->SetLocalCertificate(certificate); |
1425 } | 1512 } |
1426 | 1513 |
1427 bool WebRtcSession::waiting_for_certificate_for_testing() const { | 1514 bool WebRtcSession::waiting_for_certificate_for_testing() const { |
1428 return webrtc_session_desc_factory_->waiting_for_certificate_for_testing(); | 1515 return webrtc_session_desc_factory_->waiting_for_certificate_for_testing(); |
1429 } | 1516 } |
1430 | 1517 |
1431 const rtc::scoped_refptr<rtc::RTCCertificate>& | 1518 const rtc::scoped_refptr<rtc::RTCCertificate>& |
1432 WebRtcSession::certificate_for_testing() { | 1519 WebRtcSession::certificate_for_testing() { |
1433 return transport_controller()->certificate_for_testing(); | 1520 return transport_controller_->certificate_for_testing(); |
1434 } | 1521 } |
1435 | 1522 |
1436 void WebRtcSession::SetIceConnectionState( | 1523 void WebRtcSession::SetIceConnectionState( |
1437 PeerConnectionInterface::IceConnectionState state) { | 1524 PeerConnectionInterface::IceConnectionState state) { |
1438 if (ice_connection_state_ == state) { | 1525 if (ice_connection_state_ == state) { |
1439 return; | 1526 return; |
1440 } | 1527 } |
1441 | 1528 |
1442 // ASSERT that the requested transition is allowed. Note that | 1529 // ASSERT that the requested transition is allowed. Note that |
1443 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled | 1530 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 if (video_channel_ && !video_channel_->enabled()) | 1663 if (video_channel_ && !video_channel_->enabled()) |
1577 video_channel_->Enable(true); | 1664 video_channel_->Enable(true); |
1578 | 1665 |
1579 if (data_channel_ && !data_channel_->enabled()) | 1666 if (data_channel_ && !data_channel_->enabled()) |
1580 data_channel_->Enable(true); | 1667 data_channel_->Enable(true); |
1581 } | 1668 } |
1582 | 1669 |
1583 // Returns the media index for a local ice candidate given the content name. | 1670 // Returns the media index for a local ice candidate given the content name. |
1584 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, | 1671 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, |
1585 int* sdp_mline_index) { | 1672 int* sdp_mline_index) { |
1586 if (!base_local_description() || !sdp_mline_index) | 1673 if (!local_desc_ || !sdp_mline_index) { |
1587 return false; | 1674 return false; |
| 1675 } |
1588 | 1676 |
1589 bool content_found = false; | 1677 bool content_found = false; |
1590 const ContentInfos& contents = base_local_description()->contents(); | 1678 const ContentInfos& contents = local_desc_->description()->contents(); |
1591 for (size_t index = 0; index < contents.size(); ++index) { | 1679 for (size_t index = 0; index < contents.size(); ++index) { |
1592 if (contents[index].name == content_name) { | 1680 if (contents[index].name == content_name) { |
1593 *sdp_mline_index = static_cast<int>(index); | 1681 *sdp_mline_index = static_cast<int>(index); |
1594 content_found = true; | 1682 content_found = true; |
1595 break; | 1683 break; |
1596 } | 1684 } |
1597 } | 1685 } |
1598 return content_found; | 1686 return content_found; |
1599 } | 1687 } |
1600 | 1688 |
1601 bool WebRtcSession::UseCandidatesInSessionDescription( | 1689 bool WebRtcSession::UseCandidatesInSessionDescription( |
1602 const SessionDescriptionInterface* remote_desc) { | 1690 const SessionDescriptionInterface* remote_desc) { |
1603 if (!remote_desc) | 1691 if (!remote_desc) { |
1604 return true; | 1692 return true; |
| 1693 } |
1605 bool ret = true; | 1694 bool ret = true; |
1606 | 1695 |
1607 for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) { | 1696 for (size_t m = 0; m < remote_desc->number_of_mediasections(); ++m) { |
1608 const IceCandidateCollection* candidates = remote_desc->candidates(m); | 1697 const IceCandidateCollection* candidates = remote_desc->candidates(m); |
1609 for (size_t n = 0; n < candidates->count(); ++n) { | 1698 for (size_t n = 0; n < candidates->count(); ++n) { |
1610 const IceCandidateInterface* candidate = candidates->at(n); | 1699 const IceCandidateInterface* candidate = candidates->at(n); |
1611 bool valid = false; | 1700 bool valid = false; |
1612 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) { | 1701 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) { |
1613 if (valid) { | 1702 if (valid) { |
1614 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Candidate saved."; | 1703 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Not ready to use " |
1615 saved_candidates_.push_back( | 1704 << "candidate."; |
1616 new JsepIceCandidate(candidate->sdp_mid(), | |
1617 candidate->sdp_mline_index(), | |
1618 candidate->candidate())); | |
1619 } | 1705 } |
1620 continue; | 1706 continue; |
1621 } | 1707 } |
1622 ret = UseCandidate(candidate); | 1708 ret = UseCandidate(candidate); |
1623 if (!ret) | 1709 if (!ret) { |
1624 break; | 1710 break; |
| 1711 } |
1625 } | 1712 } |
1626 } | 1713 } |
1627 return ret; | 1714 return ret; |
1628 } | 1715 } |
1629 | 1716 |
1630 bool WebRtcSession::UseCandidate( | 1717 bool WebRtcSession::UseCandidate( |
1631 const IceCandidateInterface* candidate) { | 1718 const IceCandidateInterface* candidate) { |
1632 | 1719 |
1633 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); | 1720 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
1634 size_t remote_content_size = base_remote_description()->contents().size(); | 1721 size_t remote_content_size = remote_desc_->description()->contents().size(); |
1635 if (mediacontent_index >= remote_content_size) { | 1722 if (mediacontent_index >= remote_content_size) { |
1636 LOG(LS_ERROR) | 1723 LOG(LS_ERROR) |
1637 << "UseRemoteCandidateInSession: Invalid candidate media index."; | 1724 << "UseRemoteCandidateInSession: Invalid candidate media index."; |
1638 return false; | 1725 return false; |
1639 } | 1726 } |
1640 | 1727 |
1641 cricket::ContentInfo content = | 1728 cricket::ContentInfo content = |
1642 base_remote_description()->contents()[mediacontent_index]; | 1729 remote_desc_->description()->contents()[mediacontent_index]; |
1643 std::vector<cricket::Candidate> candidates; | 1730 std::vector<cricket::Candidate> candidates; |
1644 candidates.push_back(candidate->candidate()); | 1731 candidates.push_back(candidate->candidate()); |
1645 // Invoking BaseSession method to handle remote candidates. | 1732 // Invoking BaseSession method to handle remote candidates. |
1646 std::string error; | 1733 std::string error; |
1647 if (transport_controller()->AddRemoteCandidates(content.name, candidates, | 1734 if (transport_controller_->AddRemoteCandidates(content.name, candidates, |
1648 &error)) { | 1735 &error)) { |
1649 // Candidates successfully submitted for checking. | 1736 // Candidates successfully submitted for checking. |
1650 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || | 1737 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
1651 ice_connection_state_ == | 1738 ice_connection_state_ == |
1652 PeerConnectionInterface::kIceConnectionDisconnected) { | 1739 PeerConnectionInterface::kIceConnectionDisconnected) { |
1653 // If state is New, then the session has just gotten its first remote ICE | 1740 // If state is New, then the session has just gotten its first remote ICE |
1654 // candidates, so go to Checking. | 1741 // candidates, so go to Checking. |
1655 // If state is Disconnected, the session is re-using old candidates or | 1742 // If state is Disconnected, the session is re-using old candidates or |
1656 // receiving additional ones, so go to Checking. | 1743 // receiving additional ones, so go to Checking. |
1657 // If state is Connected, stay Connected. | 1744 // If state is Connected, stay Connected. |
1658 // TODO(bemasc): If state is Connected, and the new candidates are for a | 1745 // TODO(bemasc): If state is Connected, and the new candidates are for a |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 LOG(LS_WARNING) << "max-bundle failed to enable bundling."; | 1837 LOG(LS_WARNING) << "max-bundle failed to enable bundling."; |
1751 return false; | 1838 return false; |
1752 } | 1839 } |
1753 } | 1840 } |
1754 | 1841 |
1755 return true; | 1842 return true; |
1756 } | 1843 } |
1757 | 1844 |
1758 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { | 1845 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { |
1759 voice_channel_.reset(channel_manager_->CreateVoiceChannel( | 1846 voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
1760 media_controller_.get(), transport_controller(), content->name, true, | 1847 media_controller_.get(), transport_controller_.get(), content->name, true, |
1761 audio_options_)); | 1848 audio_options_)); |
1762 if (!voice_channel_) { | 1849 if (!voice_channel_) { |
1763 return false; | 1850 return false; |
1764 } | 1851 } |
1765 | 1852 |
1766 voice_channel_->SignalDtlsSetupFailure.connect( | 1853 voice_channel_->SignalDtlsSetupFailure.connect( |
1767 this, &WebRtcSession::OnDtlsSetupFailure); | 1854 this, &WebRtcSession::OnDtlsSetupFailure); |
1768 | 1855 |
1769 SignalVoiceChannelCreated(); | 1856 SignalVoiceChannelCreated(); |
1770 return true; | 1857 return true; |
1771 } | 1858 } |
1772 | 1859 |
1773 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { | 1860 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { |
1774 video_channel_.reset(channel_manager_->CreateVideoChannel( | 1861 video_channel_.reset(channel_manager_->CreateVideoChannel( |
1775 media_controller_.get(), transport_controller(), content->name, true, | 1862 media_controller_.get(), transport_controller_.get(), content->name, true, |
1776 video_options_)); | 1863 video_options_)); |
1777 if (!video_channel_) { | 1864 if (!video_channel_) { |
1778 return false; | 1865 return false; |
1779 } | 1866 } |
1780 | 1867 |
1781 video_channel_->SignalDtlsSetupFailure.connect( | 1868 video_channel_->SignalDtlsSetupFailure.connect( |
1782 this, &WebRtcSession::OnDtlsSetupFailure); | 1869 this, &WebRtcSession::OnDtlsSetupFailure); |
1783 | 1870 |
1784 SignalVideoChannelCreated(); | 1871 SignalVideoChannelCreated(); |
1785 return true; | 1872 return true; |
1786 } | 1873 } |
1787 | 1874 |
1788 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { | 1875 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { |
1789 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); | 1876 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
1790 data_channel_.reset(channel_manager_->CreateDataChannel( | 1877 data_channel_.reset(channel_manager_->CreateDataChannel( |
1791 transport_controller(), content->name, !sctp, data_channel_type_)); | 1878 transport_controller_.get(), content->name, !sctp, data_channel_type_)); |
1792 if (!data_channel_) { | 1879 if (!data_channel_) { |
1793 return false; | 1880 return false; |
1794 } | 1881 } |
1795 | 1882 |
1796 if (sctp) { | 1883 if (sctp) { |
1797 data_channel_->SignalDataReceived.connect( | 1884 data_channel_->SignalDataReceived.connect( |
1798 this, &WebRtcSession::OnDataChannelMessageReceived); | 1885 this, &WebRtcSession::OnDataChannelMessageReceived); |
1799 } | 1886 } |
1800 | 1887 |
1801 data_channel_->SignalDtlsSetupFailure.connect( | 1888 data_channel_->SignalDtlsSetupFailure.connect( |
1802 this, &WebRtcSession::OnDtlsSetupFailure); | 1889 this, &WebRtcSession::OnDtlsSetupFailure); |
1803 | 1890 |
1804 SignalDataChannelCreated(); | 1891 SignalDataChannelCreated(); |
1805 return true; | 1892 return true; |
1806 } | 1893 } |
1807 | 1894 |
1808 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { | 1895 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { |
1809 SetError(BaseSession::ERROR_TRANSPORT, rtcp ? kDtlsSetupFailureRtcp : | 1896 SetError(ERROR_TRANSPORT, |
1810 kDtlsSetupFailureRtp); | 1897 rtcp ? kDtlsSetupFailureRtcp : kDtlsSetupFailureRtp); |
1811 } | |
1812 | |
1813 void WebRtcSession::CopySavedCandidates( | |
1814 SessionDescriptionInterface* dest_desc) { | |
1815 if (!dest_desc) { | |
1816 ASSERT(false); | |
1817 return; | |
1818 } | |
1819 for (size_t i = 0; i < saved_candidates_.size(); ++i) { | |
1820 dest_desc->AddCandidate(saved_candidates_[i]); | |
1821 delete saved_candidates_[i]; | |
1822 } | |
1823 saved_candidates_.clear(); | |
1824 } | 1898 } |
1825 | 1899 |
1826 void WebRtcSession::OnDataChannelMessageReceived( | 1900 void WebRtcSession::OnDataChannelMessageReceived( |
1827 cricket::DataChannel* channel, | 1901 cricket::DataChannel* channel, |
1828 const cricket::ReceiveDataParams& params, | 1902 const cricket::ReceiveDataParams& params, |
1829 const rtc::Buffer& payload) { | 1903 const rtc::Buffer& payload) { |
1830 RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); | 1904 RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); |
1831 if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { | 1905 if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { |
1832 // Received OPEN message; parse and signal that a new data channel should | 1906 // Received OPEN message; parse and signal that a new data channel should |
1833 // be created. | 1907 // be created. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 const cricket::ContentInfo* content) { | 1948 const cricket::ContentInfo* content) { |
1875 const cricket::MediaContentDescription* description = | 1949 const cricket::MediaContentDescription* description = |
1876 static_cast<cricket::MediaContentDescription*>(content->description); | 1950 static_cast<cricket::MediaContentDescription*>(content->description); |
1877 return description->rtcp_mux(); | 1951 return description->rtcp_mux(); |
1878 } | 1952 } |
1879 | 1953 |
1880 bool WebRtcSession::ValidateSessionDescription( | 1954 bool WebRtcSession::ValidateSessionDescription( |
1881 const SessionDescriptionInterface* sdesc, | 1955 const SessionDescriptionInterface* sdesc, |
1882 cricket::ContentSource source, std::string* err_desc) { | 1956 cricket::ContentSource source, std::string* err_desc) { |
1883 std::string type; | 1957 std::string type; |
1884 if (error() != cricket::BaseSession::ERROR_NONE) { | 1958 if (error() != ERROR_NONE) { |
1885 return BadSdp(source, type, GetSessionErrorMsg(), err_desc); | 1959 return BadSdp(source, type, GetSessionErrorMsg(), err_desc); |
1886 } | 1960 } |
1887 | 1961 |
1888 if (!sdesc || !sdesc->description()) { | 1962 if (!sdesc || !sdesc->description()) { |
1889 return BadSdp(source, type, kInvalidSdp, err_desc); | 1963 return BadSdp(source, type, kInvalidSdp, err_desc); |
1890 } | 1964 } |
1891 | 1965 |
1892 type = sdesc->type(); | 1966 type = sdesc->type(); |
1893 Action action = GetAction(sdesc->type()); | 1967 Action action = GetAction(sdesc->type()); |
1894 if (source == cricket::CS_LOCAL) { | 1968 if (source == cricket::CS_LOCAL) { |
(...skipping 17 matching lines...) Expand all Loading... |
1912 return BadSdp(source, type, kSdpWithoutIceUfragPwd, err_desc); | 1986 return BadSdp(source, type, kSdpWithoutIceUfragPwd, err_desc); |
1913 } | 1987 } |
1914 | 1988 |
1915 if (!ValidateBundleSettings(sdesc->description())) { | 1989 if (!ValidateBundleSettings(sdesc->description())) { |
1916 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc); | 1990 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc); |
1917 } | 1991 } |
1918 | 1992 |
1919 // Verify m-lines in Answer when compared against Offer. | 1993 // Verify m-lines in Answer when compared against Offer. |
1920 if (action == kAnswer) { | 1994 if (action == kAnswer) { |
1921 const cricket::SessionDescription* offer_desc = | 1995 const cricket::SessionDescription* offer_desc = |
1922 (source == cricket::CS_LOCAL) ? remote_description()->description() : | 1996 (source == cricket::CS_LOCAL) ? remote_desc_->description() |
1923 local_description()->description(); | 1997 : local_desc_->description(); |
1924 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) { | 1998 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) { |
1925 return BadAnswerSdp(source, kMlineMismatch, err_desc); | 1999 return BadAnswerSdp(source, kMlineMismatch, err_desc); |
1926 } | 2000 } |
1927 } | 2001 } |
1928 | 2002 |
1929 return true; | 2003 return true; |
1930 } | 2004 } |
1931 | 2005 |
1932 bool WebRtcSession::ExpectSetLocalDescription(Action action) { | 2006 bool WebRtcSession::ExpectSetLocalDescription(Action action) { |
1933 return ((action == kOffer && state() == STATE_INIT) || | 2007 return ((action == kOffer && state() == STATE_INIT) || |
1934 // update local offer | 2008 // update local offer |
1935 (action == kOffer && state() == STATE_SENTINITIATE) || | 2009 (action == kOffer && state() == STATE_SENTOFFER) || |
1936 // update the current ongoing session. | 2010 // update the current ongoing session. |
1937 (action == kOffer && state() == STATE_RECEIVEDACCEPT) || | |
1938 (action == kOffer && state() == STATE_SENTACCEPT) || | |
1939 (action == kOffer && state() == STATE_INPROGRESS) || | 2011 (action == kOffer && state() == STATE_INPROGRESS) || |
1940 // accept remote offer | 2012 // accept remote offer |
1941 (action == kAnswer && state() == STATE_RECEIVEDINITIATE) || | 2013 (action == kAnswer && state() == STATE_RECEIVEDOFFER) || |
1942 (action == kAnswer && state() == STATE_SENTPRACCEPT) || | 2014 (action == kAnswer && state() == STATE_SENTPRANSWER) || |
1943 (action == kPrAnswer && state() == STATE_RECEIVEDINITIATE) || | 2015 (action == kPrAnswer && state() == STATE_RECEIVEDOFFER) || |
1944 (action == kPrAnswer && state() == STATE_SENTPRACCEPT)); | 2016 (action == kPrAnswer && state() == STATE_SENTPRANSWER)); |
1945 } | 2017 } |
1946 | 2018 |
1947 bool WebRtcSession::ExpectSetRemoteDescription(Action action) { | 2019 bool WebRtcSession::ExpectSetRemoteDescription(Action action) { |
1948 return ((action == kOffer && state() == STATE_INIT) || | 2020 return ((action == kOffer && state() == STATE_INIT) || |
1949 // update remote offer | 2021 // update remote offer |
1950 (action == kOffer && state() == STATE_RECEIVEDINITIATE) || | 2022 (action == kOffer && state() == STATE_RECEIVEDOFFER) || |
1951 // update the current ongoing session | 2023 // update the current ongoing session |
1952 (action == kOffer && state() == STATE_RECEIVEDACCEPT) || | |
1953 (action == kOffer && state() == STATE_SENTACCEPT) || | |
1954 (action == kOffer && state() == STATE_INPROGRESS) || | 2024 (action == kOffer && state() == STATE_INPROGRESS) || |
1955 // accept local offer | 2025 // accept local offer |
1956 (action == kAnswer && state() == STATE_SENTINITIATE) || | 2026 (action == kAnswer && state() == STATE_SENTOFFER) || |
1957 (action == kAnswer && state() == STATE_RECEIVEDPRACCEPT) || | 2027 (action == kAnswer && state() == STATE_RECEIVEDPRANSWER) || |
1958 (action == kPrAnswer && state() == STATE_SENTINITIATE) || | 2028 (action == kPrAnswer && state() == STATE_SENTOFFER) || |
1959 (action == kPrAnswer && state() == STATE_RECEIVEDPRACCEPT)); | 2029 (action == kPrAnswer && state() == STATE_RECEIVEDPRANSWER)); |
1960 } | 2030 } |
1961 | 2031 |
1962 std::string WebRtcSession::GetSessionErrorMsg() { | 2032 std::string WebRtcSession::GetSessionErrorMsg() { |
1963 std::ostringstream desc; | 2033 std::ostringstream desc; |
1964 desc << kSessionError << GetErrorCodeString(error()) << ". "; | 2034 desc << kSessionError << GetErrorCodeString(error()) << ". "; |
1965 desc << kSessionErrorDesc << error_desc() << "."; | 2035 desc << kSessionErrorDesc << error_desc() << "."; |
1966 return desc.str(); | 2036 return desc.str(); |
1967 } | 2037 } |
1968 | 2038 |
1969 // We need to check the local/remote description for the Transport instead of | 2039 // We need to check the local/remote description for the Transport instead of |
1970 // the session, because a new Transport added during renegotiation may have | 2040 // the session, because a new Transport added during renegotiation may have |
1971 // them unset while the session has them set from the previous negotiation. | 2041 // them unset while the session has them set from the previous negotiation. |
1972 // Not doing so may trigger the auto generation of transport description and | 2042 // Not doing so may trigger the auto generation of transport description and |
1973 // mess up DTLS identity information, ICE credential, etc. | 2043 // mess up DTLS identity information, ICE credential, etc. |
1974 bool WebRtcSession::ReadyToUseRemoteCandidate( | 2044 bool WebRtcSession::ReadyToUseRemoteCandidate( |
1975 const IceCandidateInterface* candidate, | 2045 const IceCandidateInterface* candidate, |
1976 const SessionDescriptionInterface* remote_desc, | 2046 const SessionDescriptionInterface* remote_desc, |
1977 bool* valid) { | 2047 bool* valid) { |
1978 *valid = true;; | 2048 *valid = true;; |
1979 | 2049 |
1980 const SessionDescriptionInterface* current_remote_desc = | 2050 const SessionDescriptionInterface* current_remote_desc = |
1981 remote_desc ? remote_desc : remote_description(); | 2051 remote_desc ? remote_desc : remote_desc_.get(); |
1982 | 2052 |
1983 if (!current_remote_desc) | 2053 if (!current_remote_desc) { |
1984 return false; | 2054 return false; |
| 2055 } |
1985 | 2056 |
1986 size_t mediacontent_index = | 2057 size_t mediacontent_index = |
1987 static_cast<size_t>(candidate->sdp_mline_index()); | 2058 static_cast<size_t>(candidate->sdp_mline_index()); |
1988 size_t remote_content_size = | 2059 size_t remote_content_size = |
1989 current_remote_desc->description()->contents().size(); | 2060 current_remote_desc->description()->contents().size(); |
1990 if (mediacontent_index >= remote_content_size) { | 2061 if (mediacontent_index >= remote_content_size) { |
1991 LOG(LS_ERROR) | 2062 LOG(LS_ERROR) |
1992 << "ReadyToUseRemoteCandidate: Invalid candidate media index."; | 2063 << "ReadyToUseRemoteCandidate: Invalid candidate media index."; |
1993 | 2064 |
1994 *valid = false; | 2065 *valid = false; |
1995 return false; | 2066 return false; |
1996 } | 2067 } |
1997 | 2068 |
1998 cricket::ContentInfo content = | 2069 cricket::ContentInfo content = |
1999 current_remote_desc->description()->contents()[mediacontent_index]; | 2070 current_remote_desc->description()->contents()[mediacontent_index]; |
2000 cricket::BaseChannel* channel = GetChannel(content.name); | 2071 cricket::BaseChannel* channel = GetChannel(content.name); |
2001 if (!channel) { | 2072 if (!channel) { |
2002 return false; | 2073 return false; |
2003 } | 2074 } |
2004 | 2075 |
2005 return transport_controller()->ReadyForRemoteCandidates( | 2076 return transport_controller_->ReadyForRemoteCandidates( |
2006 channel->transport_name()); | 2077 channel->transport_name()); |
2007 } | 2078 } |
2008 | 2079 |
2009 void WebRtcSession::OnTransportControllerGatheringState( | 2080 void WebRtcSession::OnTransportControllerGatheringState( |
2010 cricket::IceGatheringState state) { | 2081 cricket::IceGatheringState state) { |
2011 ASSERT(signaling_thread()->IsCurrent()); | 2082 ASSERT(signaling_thread()->IsCurrent()); |
2012 if (state == cricket::kIceGatheringGathering) { | 2083 if (state == cricket::kIceGatheringGathering) { |
2013 if (ice_observer_) { | 2084 if (ice_observer_) { |
2014 ice_observer_->OnIceGatheringChange( | 2085 ice_observer_->OnIceGatheringChange( |
2015 PeerConnectionInterface::kIceGatheringGathering); | 2086 PeerConnectionInterface::kIceGatheringGathering); |
(...skipping 15 matching lines...) Expand all Loading... |
2031 transport_names.insert(voice_channel()->transport_name()); | 2102 transport_names.insert(voice_channel()->transport_name()); |
2032 } | 2103 } |
2033 if (video_channel()) { | 2104 if (video_channel()) { |
2034 transport_names.insert(video_channel()->transport_name()); | 2105 transport_names.insert(video_channel()->transport_name()); |
2035 } | 2106 } |
2036 if (data_channel()) { | 2107 if (data_channel()) { |
2037 transport_names.insert(data_channel()->transport_name()); | 2108 transport_names.insert(data_channel()->transport_name()); |
2038 } | 2109 } |
2039 for (const auto& name : transport_names) { | 2110 for (const auto& name : transport_names) { |
2040 cricket::TransportStats stats; | 2111 cricket::TransportStats stats; |
2041 if (transport_controller()->GetStats(name, &stats)) { | 2112 if (transport_controller_->GetStats(name, &stats)) { |
2042 ReportBestConnectionState(stats); | 2113 ReportBestConnectionState(stats); |
2043 ReportNegotiatedCiphers(stats); | 2114 ReportNegotiatedCiphers(stats); |
2044 } | 2115 } |
2045 } | 2116 } |
2046 } | 2117 } |
2047 // Walk through the ConnectionInfos to gather best connection usage | 2118 // Walk through the ConnectionInfos to gather best connection usage |
2048 // for IPv4 and IPv6. | 2119 // for IPv4 and IPv6. |
2049 void WebRtcSession::ReportBestConnectionState( | 2120 void WebRtcSession::ReportBestConnectionState( |
2050 const cricket::TransportStats& stats) { | 2121 const cricket::TransportStats& stats) { |
2051 RTC_DCHECK(metrics_observer_ != NULL); | 2122 RTC_DCHECK(metrics_observer_ != NULL); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 if (!srtp_cipher.empty()) { | 2199 if (!srtp_cipher.empty()) { |
2129 metrics_observer_->IncrementSparseEnumCounter( | 2200 metrics_observer_->IncrementSparseEnumCounter( |
2130 srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); | 2201 srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); |
2131 } | 2202 } |
2132 if (ssl_cipher) { | 2203 if (ssl_cipher) { |
2133 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); | 2204 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); |
2134 } | 2205 } |
2135 } | 2206 } |
2136 | 2207 |
2137 } // namespace webrtc | 2208 } // namespace webrtc |
OLD | NEW |