Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: talk/app/webrtc/webrtcsession.cc

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

Powered by Google App Engine
This is Rietveld 408576698