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

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

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

Powered by Google App Engine
This is Rietveld 408576698