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