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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 #include <algorithm> | 32 #include <algorithm> |
33 #include <vector> | 33 #include <vector> |
34 #include <set> | 34 #include <set> |
35 | 35 |
36 #include "talk/app/webrtc/jsepicecandidate.h" | 36 #include "talk/app/webrtc/jsepicecandidate.h" |
37 #include "talk/app/webrtc/jsepsessiondescription.h" | 37 #include "talk/app/webrtc/jsepsessiondescription.h" |
38 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 38 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
39 #include "talk/app/webrtc/mediastreamsignaling.h" | 39 #include "talk/app/webrtc/mediastreamsignaling.h" |
40 #include "talk/app/webrtc/peerconnectioninterface.h" | 40 #include "talk/app/webrtc/peerconnectioninterface.h" |
41 #include "talk/app/webrtc/sctputils.h" | |
42 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" | 41 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
43 #include "talk/media/base/constants.h" | 42 #include "talk/media/base/constants.h" |
44 #include "talk/media/base/videocapturer.h" | 43 #include "talk/media/base/videocapturer.h" |
45 #include "talk/session/media/channel.h" | 44 #include "talk/session/media/channel.h" |
46 #include "talk/session/media/channelmanager.h" | 45 #include "talk/session/media/channelmanager.h" |
47 #include "talk/session/media/mediasession.h" | 46 #include "talk/session/media/mediasession.h" |
48 #include "webrtc/base/basictypes.h" | 47 #include "webrtc/base/basictypes.h" |
49 #include "webrtc/base/checks.h" | 48 #include "webrtc/base/checks.h" |
50 #include "webrtc/base/helpers.h" | 49 #include "webrtc/base/helpers.h" |
51 #include "webrtc/base/logging.h" | 50 #include "webrtc/base/logging.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return true; | 529 return true; |
531 } | 530 } |
532 } | 531 } |
533 return false; | 532 return false; |
534 } | 533 } |
535 | 534 |
536 private: | 535 private: |
537 bool ice_restart_; | 536 bool ice_restart_; |
538 }; | 537 }; |
539 | 538 |
540 WebRtcSession::WebRtcSession(cricket::ChannelManager* channel_manager, | 539 WebRtcSession::WebRtcSession( |
541 rtc::Thread* signaling_thread, | 540 cricket::ChannelManager* channel_manager, |
542 rtc::Thread* worker_thread, | 541 rtc::Thread* signaling_thread, |
543 cricket::PortAllocator* port_allocator) | 542 rtc::Thread* worker_thread, |
| 543 cricket::PortAllocator* port_allocator, |
| 544 MediaStreamSignaling* mediastream_signaling) |
544 : cricket::BaseSession(signaling_thread, | 545 : cricket::BaseSession(signaling_thread, |
545 worker_thread, | 546 worker_thread, |
546 port_allocator, | 547 port_allocator, |
547 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX), | 548 rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX), |
548 false), | 549 false), |
549 // RFC 3264: The numeric value of the session id and version in the | 550 // 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". | 551 // 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. | 552 // Due to this constraint session id |sid_| is max limited to LLONG_MAX. |
552 channel_manager_(channel_manager), | 553 channel_manager_(channel_manager), |
| 554 mediastream_signaling_(mediastream_signaling), |
553 ice_observer_(NULL), | 555 ice_observer_(NULL), |
554 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), | 556 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
555 ice_connection_receiving_(true), | 557 ice_connection_receiving_(true), |
556 older_version_remote_peer_(false), | 558 older_version_remote_peer_(false), |
557 dtls_enabled_(false), | 559 dtls_enabled_(false), |
558 data_channel_type_(cricket::DCT_NONE), | 560 data_channel_type_(cricket::DCT_NONE), |
559 ice_restart_latch_(new IceRestartAnswerLatch), | 561 ice_restart_latch_(new IceRestartAnswerLatch), |
560 metrics_observer_(NULL) { | 562 metrics_observer_(NULL) { |
561 transport_controller()->SignalConnectionState.connect( | 563 transport_controller()->SignalConnectionState.connect( |
562 this, &WebRtcSession::OnTransportControllerConnectionState); | 564 this, &WebRtcSession::OnTransportControllerConnectionState); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 &value, NULL) && value) { | 636 &value, NULL) && value) { |
635 LOG(LS_INFO) << "Allowing RTP data engine."; | 637 LOG(LS_INFO) << "Allowing RTP data engine."; |
636 data_channel_type_ = cricket::DCT_RTP; | 638 data_channel_type_ = cricket::DCT_RTP; |
637 } else { | 639 } else { |
638 // DTLS has to be enabled to use SCTP. | 640 // DTLS has to be enabled to use SCTP. |
639 if (!options.disable_sctp_data_channels && dtls_enabled_) { | 641 if (!options.disable_sctp_data_channels && dtls_enabled_) { |
640 LOG(LS_INFO) << "Allowing SCTP data engine."; | 642 LOG(LS_INFO) << "Allowing SCTP data engine."; |
641 data_channel_type_ = cricket::DCT_SCTP; | 643 data_channel_type_ = cricket::DCT_SCTP; |
642 } | 644 } |
643 } | 645 } |
| 646 if (data_channel_type_ != cricket::DCT_NONE) { |
| 647 mediastream_signaling_->SetDataChannelFactory(this); |
| 648 } |
644 | 649 |
645 // Find DSCP constraint. | 650 // Find DSCP constraint. |
646 if (FindConstraint( | 651 if (FindConstraint( |
647 constraints, | 652 constraints, |
648 MediaConstraintsInterface::kEnableDscp, | 653 MediaConstraintsInterface::kEnableDscp, |
649 &value, NULL)) { | 654 &value, NULL)) { |
650 audio_options_.dscp.Set(value); | 655 audio_options_.dscp.Set(value); |
651 video_options_.dscp.Set(value); | 656 video_options_.dscp.Set(value); |
652 } | 657 } |
653 | 658 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 JsepSessionDescription::kMaxVideoCodecWidth, | 736 JsepSessionDescription::kMaxVideoCodecWidth, |
732 JsepSessionDescription::kMaxVideoCodecHeight, | 737 JsepSessionDescription::kMaxVideoCodecHeight, |
733 JsepSessionDescription::kDefaultVideoCodecFramerate, | 738 JsepSessionDescription::kDefaultVideoCodecFramerate, |
734 JsepSessionDescription::kDefaultVideoCodecPreference); | 739 JsepSessionDescription::kDefaultVideoCodecPreference); |
735 channel_manager_->SetDefaultVideoEncoderConfig( | 740 channel_manager_->SetDefaultVideoEncoderConfig( |
736 cricket::VideoEncoderConfig(default_codec)); | 741 cricket::VideoEncoderConfig(default_codec)); |
737 | 742 |
738 if (!dtls_enabled_) { | 743 if (!dtls_enabled_) { |
739 // Construct with DTLS disabled. | 744 // Construct with DTLS disabled. |
740 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | 745 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
741 signaling_thread(), channel_manager_, this, id())); | 746 signaling_thread(), channel_manager_, mediastream_signaling_, this, |
| 747 id(), data_channel_type_)); |
742 } else { | 748 } else { |
743 // Construct with DTLS enabled. | 749 // Construct with DTLS enabled. |
744 if (!certificate) { | 750 if (!certificate) { |
745 // Use the |dtls_identity_store| to generate a certificate. | 751 // Use the |dtls_identity_store| to generate a certificate. |
746 RTC_DCHECK(dtls_identity_store); | 752 RTC_DCHECK(dtls_identity_store); |
747 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | 753 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
748 signaling_thread(), channel_manager_, dtls_identity_store.Pass(), | 754 signaling_thread(), channel_manager_, mediastream_signaling_, |
749 this, id())); | 755 dtls_identity_store.Pass(), this, id(), data_channel_type_)); |
750 } else { | 756 } else { |
751 // Use the already generated certificate. | 757 // Use the already generated certificate. |
752 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( | 758 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory( |
753 signaling_thread(), channel_manager_, certificate, this, id())); | 759 signaling_thread(), channel_manager_, mediastream_signaling_, |
| 760 certificate, this, id(), data_channel_type_)); |
754 } | 761 } |
755 } | 762 } |
756 | 763 |
757 webrtc_session_desc_factory_->SignalCertificateReady.connect( | 764 webrtc_session_desc_factory_->SignalCertificateReady.connect( |
758 this, &WebRtcSession::OnCertificateReady); | 765 this, &WebRtcSession::OnCertificateReady); |
759 | 766 |
760 if (options.disable_encryption) { | 767 if (options.disable_encryption) { |
761 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); | 768 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED); |
762 } | 769 } |
763 port_allocator()->set_candidate_filter( | 770 port_allocator()->set_candidate_filter( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " | 812 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " |
806 << "SSL Role of the session."; | 813 << "SSL Role of the session."; |
807 return false; | 814 return false; |
808 } | 815 } |
809 | 816 |
810 return transport_controller()->GetSslRole(role); | 817 return transport_controller()->GetSslRole(role); |
811 } | 818 } |
812 | 819 |
813 void WebRtcSession::CreateOffer( | 820 void WebRtcSession::CreateOffer( |
814 CreateSessionDescriptionObserver* observer, | 821 CreateSessionDescriptionObserver* observer, |
815 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | 822 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
816 const cricket::MediaSessionOptions& session_options) { | 823 webrtc_session_desc_factory_->CreateOffer(observer, options); |
817 webrtc_session_desc_factory_->CreateOffer(observer, options, session_options); | |
818 } | 824 } |
819 | 825 |
820 void WebRtcSession::CreateAnswer( | 826 void WebRtcSession::CreateAnswer(CreateSessionDescriptionObserver* observer, |
821 CreateSessionDescriptionObserver* observer, | 827 const MediaConstraintsInterface* constraints) { |
822 const MediaConstraintsInterface* constraints, | 828 webrtc_session_desc_factory_->CreateAnswer(observer, constraints); |
823 const cricket::MediaSessionOptions& session_options) { | |
824 webrtc_session_desc_factory_->CreateAnswer(observer, constraints, | |
825 session_options); | |
826 } | 829 } |
827 | 830 |
828 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, | 831 bool WebRtcSession::SetLocalDescription(SessionDescriptionInterface* desc, |
829 std::string* err_desc) { | 832 std::string* err_desc) { |
830 ASSERT(signaling_thread()->IsCurrent()); | 833 ASSERT(signaling_thread()->IsCurrent()); |
831 | 834 |
832 // Takes the ownership of |desc| regardless of the result. | 835 // Takes the ownership of |desc| regardless of the result. |
833 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); | 836 rtc::scoped_ptr<SessionDescriptionInterface> desc_temp(desc); |
834 | 837 |
835 // Validate SDP. | 838 // Validate SDP. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 // that we stored, and those from the remote description. | 876 // that we stored, and those from the remote description. |
874 if (!saved_candidates_.empty()) { | 877 if (!saved_candidates_.empty()) { |
875 // If there are saved candidates which arrived before the local | 878 // If there are saved candidates which arrived before the local |
876 // description was set, copy those to the remote description. | 879 // description was set, copy those to the remote description. |
877 CopySavedCandidates(remote_desc_.get()); | 880 CopySavedCandidates(remote_desc_.get()); |
878 } | 881 } |
879 // Push remote candidates in remote description to transport channels. | 882 // Push remote candidates in remote description to transport channels. |
880 UseCandidatesInSessionDescription(remote_desc_.get()); | 883 UseCandidatesInSessionDescription(remote_desc_.get()); |
881 } | 884 } |
882 | 885 |
| 886 // Update state and SSRC of local MediaStreams and DataChannels based on the |
| 887 // local session description. |
| 888 mediastream_signaling_->OnLocalDescriptionChanged(local_desc_.get()); |
| 889 |
| 890 rtc::SSLRole role; |
| 891 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { |
| 892 mediastream_signaling_->OnDtlsRoleReadyForSctp(role); |
| 893 } |
883 if (error() != cricket::BaseSession::ERROR_NONE) { | 894 if (error() != cricket::BaseSession::ERROR_NONE) { |
884 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); | 895 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
885 } | 896 } |
886 return true; | 897 return true; |
887 } | 898 } |
888 | 899 |
889 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, | 900 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, |
890 std::string* err_desc) { | 901 std::string* err_desc) { |
891 ASSERT(signaling_thread()->IsCurrent()); | 902 ASSERT(signaling_thread()->IsCurrent()); |
892 | 903 |
(...skipping 16 matching lines...) Expand all Loading... |
909 // Remove unused channels if MediaContentDescription is rejected. | 920 // Remove unused channels if MediaContentDescription is rejected. |
910 RemoveUnusedChannels(desc->description()); | 921 RemoveUnusedChannels(desc->description()); |
911 | 922 |
912 // NOTE: Candidates allocation will be initiated only when SetLocalDescription | 923 // NOTE: Candidates allocation will be initiated only when SetLocalDescription |
913 // is called. | 924 // is called. |
914 set_remote_description(desc->description()->Copy()); | 925 set_remote_description(desc->description()->Copy()); |
915 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { | 926 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { |
916 return false; | 927 return false; |
917 } | 928 } |
918 | 929 |
| 930 // Update remote MediaStreams. |
| 931 mediastream_signaling_->OnRemoteDescriptionChanged(desc); |
919 if (local_description() && !UseCandidatesInSessionDescription(desc)) { | 932 if (local_description() && !UseCandidatesInSessionDescription(desc)) { |
920 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); | 933 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); |
921 } | 934 } |
922 | 935 |
923 // Copy all saved candidates. | 936 // Copy all saved candidates. |
924 CopySavedCandidates(desc); | 937 CopySavedCandidates(desc); |
925 | 938 |
926 // Check if this new SessionDescription contains new ice ufrag and password | 939 // Check if this new SessionDescription contains new ice ufrag and password |
927 // that indicates the remote peer requests ice restart. | 940 // that indicates the remote peer requests ice restart. |
928 bool ice_restart = | 941 bool ice_restart = |
929 ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(), desc); | 942 ice_restart_latch_->CheckForRemoteIceRestart(remote_desc_.get(), desc); |
930 // We retain all received candidates only if ICE is not restarted. | 943 // We retain all received candidates only if ICE is not restarted. |
931 // When ICE is restarted, all previous candidates belong to an old generation | 944 // When ICE is restarted, all previous candidates belong to an old generation |
932 // and should not be kept. | 945 // and should not be kept. |
933 if (!ice_restart) { | 946 if (!ice_restart) { |
934 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( | 947 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
935 remote_desc_.get(), desc); | 948 remote_desc_.get(), desc); |
936 } | 949 } |
937 | 950 |
938 remote_desc_.reset(desc_temp.release()); | 951 remote_desc_.reset(desc_temp.release()); |
939 | 952 |
| 953 rtc::SSLRole role; |
| 954 if (data_channel_type_ == cricket::DCT_SCTP && GetSslRole(&role)) { |
| 955 mediastream_signaling_->OnDtlsRoleReadyForSctp(role); |
| 956 } |
| 957 |
940 if (error() != cricket::BaseSession::ERROR_NONE) { | 958 if (error() != cricket::BaseSession::ERROR_NONE) { |
941 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); | 959 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); |
942 } | 960 } |
943 | 961 |
944 // Set the the ICE connection state to connecting since the connection may | 962 // Set the the ICE connection state to connecting since the connection may |
945 // become writable with peer reflexive candidates before any remote candidate | 963 // become writable with peer reflexive candidates before any remote candidate |
946 // is signaled. | 964 // is signaled. |
947 // TODO(pthatcher): This is a short-term solution for crbug/446908. A real fix | 965 // 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 | 966 // 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 | 967 // transport and expose a new checking() member from transport that can be |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 | 1380 |
1363 bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) { | 1381 bool WebRtcSession::ConnectDataChannel(DataChannel* webrtc_data_channel) { |
1364 if (!data_channel_) { | 1382 if (!data_channel_) { |
1365 LOG(LS_ERROR) << "ConnectDataChannel called when data_channel_ is NULL."; | 1383 LOG(LS_ERROR) << "ConnectDataChannel called when data_channel_ is NULL."; |
1366 return false; | 1384 return false; |
1367 } | 1385 } |
1368 data_channel_->SignalReadyToSendData.connect(webrtc_data_channel, | 1386 data_channel_->SignalReadyToSendData.connect(webrtc_data_channel, |
1369 &DataChannel::OnChannelReady); | 1387 &DataChannel::OnChannelReady); |
1370 data_channel_->SignalDataReceived.connect(webrtc_data_channel, | 1388 data_channel_->SignalDataReceived.connect(webrtc_data_channel, |
1371 &DataChannel::OnDataReceived); | 1389 &DataChannel::OnDataReceived); |
1372 data_channel_->SignalStreamClosedRemotely.connect( | |
1373 webrtc_data_channel, &DataChannel::OnStreamClosedRemotely); | |
1374 return true; | 1390 return true; |
1375 } | 1391 } |
1376 | 1392 |
1377 void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) { | 1393 void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) { |
1378 if (!data_channel_) { | 1394 if (!data_channel_) { |
1379 LOG(LS_ERROR) << "DisconnectDataChannel called when data_channel_ is NULL."; | 1395 LOG(LS_ERROR) << "DisconnectDataChannel called when data_channel_ is NULL."; |
1380 return; | 1396 return; |
1381 } | 1397 } |
1382 data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel); | 1398 data_channel_->SignalReadyToSendData.disconnect(webrtc_data_channel); |
1383 data_channel_->SignalDataReceived.disconnect(webrtc_data_channel); | 1399 data_channel_->SignalDataReceived.disconnect(webrtc_data_channel); |
1384 data_channel_->SignalStreamClosedRemotely.disconnect(webrtc_data_channel); | |
1385 } | 1400 } |
1386 | 1401 |
1387 void WebRtcSession::AddSctpDataStream(int sid) { | 1402 void WebRtcSession::AddSctpDataStream(int sid) { |
1388 if (!data_channel_) { | 1403 if (!data_channel_) { |
1389 LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL."; | 1404 LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL."; |
1390 return; | 1405 return; |
1391 } | 1406 } |
1392 data_channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(sid)); | 1407 data_channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(sid)); |
1393 data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(sid)); | 1408 data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(sid)); |
1394 } | 1409 } |
1395 | 1410 |
1396 void WebRtcSession::RemoveSctpDataStream(int sid) { | 1411 void WebRtcSession::RemoveSctpDataStream(int sid) { |
| 1412 mediastream_signaling_->RemoveSctpDataChannel(sid); |
| 1413 |
1397 if (!data_channel_) { | 1414 if (!data_channel_) { |
1398 LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is " | 1415 LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is " |
1399 << "NULL."; | 1416 << "NULL."; |
1400 return; | 1417 return; |
1401 } | 1418 } |
1402 data_channel_->RemoveRecvStream(sid); | 1419 data_channel_->RemoveRecvStream(sid); |
1403 data_channel_->RemoveSendStream(sid); | 1420 data_channel_->RemoveSendStream(sid); |
1404 } | 1421 } |
1405 | 1422 |
1406 bool WebRtcSession::ReadyToSendData() const { | 1423 bool WebRtcSession::ReadyToSendData() const { |
1407 return data_channel_ && data_channel_->ready_to_send_data(); | 1424 return data_channel_ && data_channel_->ready_to_send_data(); |
1408 } | 1425 } |
1409 | 1426 |
| 1427 rtc::scoped_refptr<DataChannel> WebRtcSession::CreateDataChannel( |
| 1428 const std::string& label, |
| 1429 const InternalDataChannelInit* config) { |
| 1430 if (state() == STATE_RECEIVEDTERMINATE) { |
| 1431 return NULL; |
| 1432 } |
| 1433 if (data_channel_type_ == cricket::DCT_NONE) { |
| 1434 LOG(LS_ERROR) << "CreateDataChannel: Data is not supported in this call."; |
| 1435 return NULL; |
| 1436 } |
| 1437 InternalDataChannelInit new_config = |
| 1438 config ? (*config) : InternalDataChannelInit(); |
| 1439 if (data_channel_type_ == cricket::DCT_SCTP) { |
| 1440 if (new_config.id < 0) { |
| 1441 rtc::SSLRole role; |
| 1442 if (GetSslRole(&role) && |
| 1443 !mediastream_signaling_->AllocateSctpSid(role, &new_config.id)) { |
| 1444 LOG(LS_ERROR) << "No id can be allocated for the SCTP data channel."; |
| 1445 return NULL; |
| 1446 } |
| 1447 } else if (!mediastream_signaling_->IsSctpSidAvailable(new_config.id)) { |
| 1448 LOG(LS_ERROR) << "Failed to create a SCTP data channel " |
| 1449 << "because the id is already in use or out of range."; |
| 1450 return NULL; |
| 1451 } |
| 1452 } |
| 1453 |
| 1454 rtc::scoped_refptr<DataChannel> channel(DataChannel::Create( |
| 1455 this, data_channel_type_, label, new_config)); |
| 1456 if (channel && !mediastream_signaling_->AddDataChannel(channel)) |
| 1457 return NULL; |
| 1458 |
| 1459 return channel; |
| 1460 } |
| 1461 |
1410 cricket::DataChannelType WebRtcSession::data_channel_type() const { | 1462 cricket::DataChannelType WebRtcSession::data_channel_type() const { |
1411 return data_channel_type_; | 1463 return data_channel_type_; |
1412 } | 1464 } |
1413 | 1465 |
1414 bool WebRtcSession::IceRestartPending() const { | 1466 bool WebRtcSession::IceRestartPending() const { |
1415 return ice_restart_latch_->Get(); | 1467 return ice_restart_latch_->Get(); |
1416 } | 1468 } |
1417 | 1469 |
1418 void WebRtcSession::ResetIceRestartLatch() { | 1470 void WebRtcSession::ResetIceRestartLatch() { |
1419 ice_restart_latch_->Reset(); | 1471 ice_restart_latch_->Reset(); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 } | 1720 } |
1669 return true; | 1721 return true; |
1670 } | 1722 } |
1671 | 1723 |
1672 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { | 1724 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { |
1673 // Destroy video_channel_ first since it may have a pointer to the | 1725 // Destroy video_channel_ first since it may have a pointer to the |
1674 // voice_channel_. | 1726 // voice_channel_. |
1675 const cricket::ContentInfo* video_info = | 1727 const cricket::ContentInfo* video_info = |
1676 cricket::GetFirstVideoContent(desc); | 1728 cricket::GetFirstVideoContent(desc); |
1677 if ((!video_info || video_info->rejected) && video_channel_) { | 1729 if ((!video_info || video_info->rejected) && video_channel_) { |
| 1730 mediastream_signaling_->OnVideoChannelClose(); |
1678 SignalVideoChannelDestroyed(); | 1731 SignalVideoChannelDestroyed(); |
1679 const std::string content_name = video_channel_->content_name(); | 1732 const std::string content_name = video_channel_->content_name(); |
1680 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 1733 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
1681 } | 1734 } |
1682 | 1735 |
1683 const cricket::ContentInfo* voice_info = | 1736 const cricket::ContentInfo* voice_info = |
1684 cricket::GetFirstAudioContent(desc); | 1737 cricket::GetFirstAudioContent(desc); |
1685 if ((!voice_info || voice_info->rejected) && voice_channel_) { | 1738 if ((!voice_info || voice_info->rejected) && voice_channel_) { |
| 1739 mediastream_signaling_->OnAudioChannelClose(); |
1686 SignalVoiceChannelDestroyed(); | 1740 SignalVoiceChannelDestroyed(); |
1687 const std::string content_name = voice_channel_->content_name(); | 1741 const std::string content_name = voice_channel_->content_name(); |
1688 channel_manager_->DestroyVoiceChannel(voice_channel_.release()); | 1742 channel_manager_->DestroyVoiceChannel(voice_channel_.release()); |
1689 } | 1743 } |
1690 | 1744 |
1691 const cricket::ContentInfo* data_info = | 1745 const cricket::ContentInfo* data_info = |
1692 cricket::GetFirstDataContent(desc); | 1746 cricket::GetFirstDataContent(desc); |
1693 if ((!data_info || data_info->rejected) && data_channel_) { | 1747 if ((!data_info || data_info->rejected) && data_channel_) { |
| 1748 mediastream_signaling_->OnDataChannelClose(); |
1694 SignalDataChannelDestroyed(); | 1749 SignalDataChannelDestroyed(); |
1695 const std::string content_name = data_channel_->content_name(); | 1750 const std::string content_name = data_channel_->content_name(); |
1696 channel_manager_->DestroyDataChannel(data_channel_.release()); | 1751 channel_manager_->DestroyDataChannel(data_channel_.release()); |
1697 } | 1752 } |
1698 } | 1753 } |
1699 | 1754 |
1700 // TODO(mallinath) - Add a correct error code if the channels are not created | 1755 // TODO(mallinath) - Add a correct error code if the channels are not created |
1701 // due to BUNDLE is enabled but rtcp-mux is disabled. | 1756 // due to BUNDLE is enabled but rtcp-mux is disabled. |
1702 bool WebRtcSession::CreateChannels(const SessionDescription* desc) { | 1757 bool WebRtcSession::CreateChannels(const SessionDescription* desc) { |
1703 // Creating the media channels and transport proxies. | 1758 // Creating the media channels and transport proxies. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { | 1813 bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { |
1759 voice_channel_.reset(channel_manager_->CreateVoiceChannel( | 1814 voice_channel_.reset(channel_manager_->CreateVoiceChannel( |
1760 media_controller_.get(), transport_controller(), content->name, true, | 1815 media_controller_.get(), transport_controller(), content->name, true, |
1761 audio_options_)); | 1816 audio_options_)); |
1762 if (!voice_channel_) { | 1817 if (!voice_channel_) { |
1763 return false; | 1818 return false; |
1764 } | 1819 } |
1765 | 1820 |
1766 voice_channel_->SignalDtlsSetupFailure.connect( | 1821 voice_channel_->SignalDtlsSetupFailure.connect( |
1767 this, &WebRtcSession::OnDtlsSetupFailure); | 1822 this, &WebRtcSession::OnDtlsSetupFailure); |
1768 | |
1769 SignalVoiceChannelCreated(); | |
1770 return true; | 1823 return true; |
1771 } | 1824 } |
1772 | 1825 |
1773 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { | 1826 bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { |
1774 video_channel_.reset(channel_manager_->CreateVideoChannel( | 1827 video_channel_.reset(channel_manager_->CreateVideoChannel( |
1775 media_controller_.get(), transport_controller(), content->name, true, | 1828 media_controller_.get(), transport_controller(), content->name, true, |
1776 video_options_)); | 1829 video_options_)); |
1777 if (!video_channel_) { | 1830 if (!video_channel_) { |
1778 return false; | 1831 return false; |
1779 } | 1832 } |
1780 | 1833 |
1781 video_channel_->SignalDtlsSetupFailure.connect( | 1834 video_channel_->SignalDtlsSetupFailure.connect( |
1782 this, &WebRtcSession::OnDtlsSetupFailure); | 1835 this, &WebRtcSession::OnDtlsSetupFailure); |
1783 | |
1784 SignalVideoChannelCreated(); | |
1785 return true; | 1836 return true; |
1786 } | 1837 } |
1787 | 1838 |
1788 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { | 1839 bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { |
1789 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); | 1840 bool sctp = (data_channel_type_ == cricket::DCT_SCTP); |
1790 data_channel_.reset(channel_manager_->CreateDataChannel( | 1841 data_channel_.reset(channel_manager_->CreateDataChannel( |
1791 transport_controller(), content->name, !sctp, data_channel_type_)); | 1842 transport_controller(), content->name, !sctp, data_channel_type_)); |
1792 if (!data_channel_) { | 1843 if (!data_channel_) { |
1793 return false; | 1844 return false; |
1794 } | 1845 } |
1795 | 1846 |
1796 if (sctp) { | 1847 if (sctp) { |
| 1848 mediastream_signaling_->OnDataTransportCreatedForSctp(); |
1797 data_channel_->SignalDataReceived.connect( | 1849 data_channel_->SignalDataReceived.connect( |
1798 this, &WebRtcSession::OnDataChannelMessageReceived); | 1850 this, &WebRtcSession::OnDataChannelMessageReceived); |
| 1851 data_channel_->SignalStreamClosedRemotely.connect( |
| 1852 mediastream_signaling_, |
| 1853 &MediaStreamSignaling::OnRemoteSctpDataChannelClosed); |
1799 } | 1854 } |
1800 | 1855 |
1801 data_channel_->SignalDtlsSetupFailure.connect( | 1856 data_channel_->SignalDtlsSetupFailure.connect( |
1802 this, &WebRtcSession::OnDtlsSetupFailure); | 1857 this, &WebRtcSession::OnDtlsSetupFailure); |
1803 | |
1804 SignalDataChannelCreated(); | |
1805 return true; | 1858 return true; |
1806 } | 1859 } |
1807 | 1860 |
1808 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { | 1861 void WebRtcSession::OnDtlsSetupFailure(cricket::BaseChannel*, bool rtcp) { |
1809 SetError(BaseSession::ERROR_TRANSPORT, rtcp ? kDtlsSetupFailureRtcp : | 1862 SetError(BaseSession::ERROR_TRANSPORT, rtcp ? kDtlsSetupFailureRtcp : |
1810 kDtlsSetupFailureRtp); | 1863 kDtlsSetupFailureRtp); |
1811 } | 1864 } |
1812 | 1865 |
1813 void WebRtcSession::CopySavedCandidates( | 1866 void WebRtcSession::CopySavedCandidates( |
1814 SessionDescriptionInterface* dest_desc) { | 1867 SessionDescriptionInterface* dest_desc) { |
1815 if (!dest_desc) { | 1868 if (!dest_desc) { |
1816 ASSERT(false); | 1869 ASSERT(false); |
1817 return; | 1870 return; |
1818 } | 1871 } |
1819 for (size_t i = 0; i < saved_candidates_.size(); ++i) { | 1872 for (size_t i = 0; i < saved_candidates_.size(); ++i) { |
1820 dest_desc->AddCandidate(saved_candidates_[i]); | 1873 dest_desc->AddCandidate(saved_candidates_[i]); |
1821 delete saved_candidates_[i]; | 1874 delete saved_candidates_[i]; |
1822 } | 1875 } |
1823 saved_candidates_.clear(); | 1876 saved_candidates_.clear(); |
1824 } | 1877 } |
1825 | 1878 |
1826 void WebRtcSession::OnDataChannelMessageReceived( | 1879 void WebRtcSession::OnDataChannelMessageReceived( |
1827 cricket::DataChannel* channel, | 1880 cricket::DataChannel* channel, |
1828 const cricket::ReceiveDataParams& params, | 1881 const cricket::ReceiveDataParams& params, |
1829 const rtc::Buffer& payload) { | 1882 const rtc::Buffer& payload) { |
1830 RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); | 1883 ASSERT(data_channel_type_ == cricket::DCT_SCTP); |
1831 if (params.type == cricket::DMT_CONTROL && IsOpenMessage(payload)) { | 1884 if (params.type == cricket::DMT_CONTROL && |
1832 // Received OPEN message; parse and signal that a new data channel should | 1885 mediastream_signaling_->IsSctpSidAvailable(params.ssrc)) { |
1833 // be created. | 1886 // Received CONTROL on unused sid, process as an OPEN message. |
1834 std::string label; | 1887 mediastream_signaling_->AddDataChannelFromOpenMessage(params, payload); |
1835 InternalDataChannelInit config; | |
1836 config.id = params.ssrc; | |
1837 if (!ParseDataChannelOpenMessage(payload, &label, &config)) { | |
1838 LOG(LS_WARNING) << "Failed to parse the OPEN message for sid " | |
1839 << params.ssrc; | |
1840 return; | |
1841 } | |
1842 config.open_handshake_role = InternalDataChannelInit::kAcker; | |
1843 SignalDataChannelOpenMessage(label, config); | |
1844 } | 1888 } |
1845 // Otherwise ignore the message. | 1889 // otherwise ignore the message. |
1846 } | 1890 } |
1847 | 1891 |
1848 // Returns false if bundle is enabled and rtcp_mux is disabled. | 1892 // Returns false if bundle is enabled and rtcp_mux is disabled. |
1849 bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) { | 1893 bool WebRtcSession::ValidateBundleSettings(const SessionDescription* desc) { |
1850 bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE); | 1894 bool bundle_enabled = desc->HasGroup(cricket::GROUP_TYPE_BUNDLE); |
1851 if (!bundle_enabled) | 1895 if (!bundle_enabled) |
1852 return true; | 1896 return true; |
1853 | 1897 |
1854 const cricket::ContentGroup* bundle_group = | 1898 const cricket::ContentGroup* bundle_group = |
1855 desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); | 1899 desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 if (!srtp_cipher.empty()) { | 2172 if (!srtp_cipher.empty()) { |
2129 metrics_observer_->IncrementSparseEnumCounter( | 2173 metrics_observer_->IncrementSparseEnumCounter( |
2130 srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); | 2174 srtp_counter_type, rtc::GetSrtpCryptoSuiteFromName(srtp_cipher)); |
2131 } | 2175 } |
2132 if (ssl_cipher) { | 2176 if (ssl_cipher) { |
2133 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); | 2177 metrics_observer_->IncrementSparseEnumCounter(ssl_counter_type, ssl_cipher); |
2134 } | 2178 } |
2135 } | 2179 } |
2136 | 2180 |
2137 } // namespace webrtc | 2181 } // namespace webrtc |
OLD | NEW |