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

Side by Side Diff: webrtc/api/webrtcsession.cc

Issue 2590753002: Implement current/pending session description methods. (Closed)
Patch Set: Fixing null pointer deref. Created 4 years 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 | « webrtc/api/webrtcsession.h ('k') | no next file » | 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 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 616 }
617 return nullptr; 617 return nullptr;
618 } 618 }
619 619
620 cricket::SecurePolicy WebRtcSession::SdesPolicy() const { 620 cricket::SecurePolicy WebRtcSession::SdesPolicy() const {
621 return webrtc_session_desc_factory_->SdesPolicy(); 621 return webrtc_session_desc_factory_->SdesPolicy();
622 } 622 }
623 623
624 bool WebRtcSession::GetSslRole(const std::string& transport_name, 624 bool WebRtcSession::GetSslRole(const std::string& transport_name,
625 rtc::SSLRole* role) { 625 rtc::SSLRole* role) {
626 if (!local_desc_ || !remote_desc_) { 626 if (!local_description() || !remote_description()) {
627 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get " 627 LOG(LS_INFO) << "Local and Remote descriptions must be applied to get "
628 << "SSL Role of the session."; 628 << "SSL Role of the session.";
629 return false; 629 return false;
630 } 630 }
631 631
632 return transport_controller_->GetSslRole(transport_name, role); 632 return transport_controller_->GetSslRole(transport_name, role);
633 } 633 }
634 634
635 bool WebRtcSession::GetSslRole(const cricket::BaseChannel* channel, 635 bool WebRtcSession::GetSslRole(const cricket::BaseChannel* channel,
636 rtc::SSLRole* role) { 636 rtc::SSLRole* role) {
(...skipping 25 matching lines...) Expand all
662 return false; 662 return false;
663 } 663 }
664 664
665 // Update the initial_offerer flag if this session is the initial_offerer. 665 // Update the initial_offerer flag if this session is the initial_offerer.
666 Action action = GetAction(desc->type()); 666 Action action = GetAction(desc->type());
667 if (state() == STATE_INIT && action == kOffer) { 667 if (state() == STATE_INIT && action == kOffer) {
668 initial_offerer_ = true; 668 initial_offerer_ = true;
669 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING); 669 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLING);
670 } 670 }
671 671
672 local_desc_.reset(desc_temp.release()); 672 if (action == kAnswer) {
673 current_local_description_.reset(desc_temp.release());
674 pending_local_description_.reset(nullptr);
675 current_remote_description_.reset(pending_remote_description_.release());
676 } else {
677 pending_local_description_.reset(desc_temp.release());
678 }
673 679
674 // Transport and Media channels will be created only when offer is set. 680 // Transport and Media channels will be created only when offer is set.
675 if (action == kOffer && !CreateChannels(local_desc_->description())) { 681 if (action == kOffer && !CreateChannels(local_description()->description())) {
676 // TODO(mallinath) - Handle CreateChannel failure, as new local description 682 // TODO(mallinath) - Handle CreateChannel failure, as new local description
677 // is applied. Restore back to old description. 683 // is applied. Restore back to old description.
678 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc); 684 return BadLocalSdp(desc->type(), kCreateChannelFailed, err_desc);
679 } 685 }
680 686
681 // Remove unused channels if MediaContentDescription is rejected. 687 // Remove unused channels if MediaContentDescription is rejected.
682 RemoveUnusedChannels(local_desc_->description()); 688 RemoveUnusedChannels(local_description()->description());
683 689
684 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) { 690 if (!UpdateSessionState(action, cricket::CS_LOCAL, err_desc)) {
685 return false; 691 return false;
686 } 692 }
687 693
688 if (remote_desc_) { 694 if (remote_description()) {
689 // Now that we have a local description, we can push down remote candidates. 695 // Now that we have a local description, we can push down remote candidates.
690 UseCandidatesInSessionDescription(remote_desc_.get()); 696 UseCandidatesInSessionDescription(remote_description());
691 } 697 }
692 698
693 pending_ice_restarts_.clear(); 699 pending_ice_restarts_.clear();
694 700
695 if (error() != ERROR_NONE) { 701 if (error() != ERROR_NONE) {
696 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc); 702 return BadLocalSdp(desc->type(), GetSessionErrorMsg(), err_desc);
697 } 703 }
698 return true; 704 return true;
699 } 705 }
700 706
701 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc, 707 bool WebRtcSession::SetRemoteDescription(SessionDescriptionInterface* desc,
702 std::string* err_desc) { 708 std::string* err_desc) {
703 ASSERT(signaling_thread()->IsCurrent()); 709 ASSERT(signaling_thread()->IsCurrent());
704 710
705 // Takes the ownership of |desc| regardless of the result. 711 // Takes the ownership of |desc| regardless of the result.
706 std::unique_ptr<SessionDescriptionInterface> desc_temp(desc); 712 std::unique_ptr<SessionDescriptionInterface> desc_temp(desc);
707 713
708 // Validate SDP. 714 // Validate SDP.
709 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) { 715 if (!ValidateSessionDescription(desc, cricket::CS_REMOTE, err_desc)) {
710 return false; 716 return false;
711 } 717 }
712 718
713 std::unique_ptr<SessionDescriptionInterface> old_remote_desc( 719 const SessionDescriptionInterface* old_remote_description =
714 remote_desc_.release()); 720 remote_description();
715 remote_desc_.reset(desc_temp.release()); 721 // Grab ownership of the description being replaced for the remainder of this
722 // method, since it's used below.
723 std::unique_ptr<SessionDescriptionInterface> replaced_remote_description;
724 Action action = GetAction(desc->type());
725 if (action == kAnswer) {
726 replaced_remote_description.reset(
727 pending_remote_description_ ? pending_remote_description_.release()
728 : current_remote_description_.release());
729 current_remote_description_.reset(desc_temp.release());
730 pending_remote_description_.reset(nullptr);
731 current_local_description_.reset(pending_local_description_.release());
732 } else {
733 replaced_remote_description.reset(pending_remote_description_.release());
734 pending_remote_description_.reset(desc_temp.release());
735 }
716 736
717 // Transport and Media channels will be created only when offer is set. 737 // Transport and Media channels will be created only when offer is set.
718 Action action = GetAction(desc->type());
719 if (action == kOffer && !CreateChannels(desc->description())) { 738 if (action == kOffer && !CreateChannels(desc->description())) {
720 // TODO(mallinath) - Handle CreateChannel failure, as new local description 739 // TODO(mallinath) - Handle CreateChannel failure, as new local description
721 // is applied. Restore back to old description. 740 // is applied. Restore back to old description.
722 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc); 741 return BadRemoteSdp(desc->type(), kCreateChannelFailed, err_desc);
723 } 742 }
724 743
725 // Remove unused channels if MediaContentDescription is rejected. 744 // Remove unused channels if MediaContentDescription is rejected.
726 RemoveUnusedChannels(desc->description()); 745 RemoveUnusedChannels(desc->description());
727 746
728 // NOTE: Candidates allocation will be initiated only when SetLocalDescription 747 // NOTE: Candidates allocation will be initiated only when SetLocalDescription
729 // is called. 748 // is called.
730 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) { 749 if (!UpdateSessionState(action, cricket::CS_REMOTE, err_desc)) {
731 return false; 750 return false;
732 } 751 }
733 752
734 if (local_desc_ && !UseCandidatesInSessionDescription(desc)) { 753 if (local_description() && !UseCandidatesInSessionDescription(desc)) {
735 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc); 754 return BadRemoteSdp(desc->type(), kInvalidCandidates, err_desc);
736 } 755 }
737 756
738 if (old_remote_desc) { 757 if (old_remote_description) {
739 for (const cricket::ContentInfo& content : 758 for (const cricket::ContentInfo& content :
740 old_remote_desc->description()->contents()) { 759 old_remote_description->description()->contents()) {
741 // Check if this new SessionDescription contains new ICE ufrag and 760 // Check if this new SessionDescription contains new ICE ufrag and
742 // password that indicates the remote peer requests an ICE restart. 761 // password that indicates the remote peer requests an ICE restart.
743 // TODO(deadbeef): When we start storing both the current and pending 762 // TODO(deadbeef): When we start storing both the current and pending
744 // remote description, this should reset pending_ice_restarts and compare 763 // remote description, this should reset pending_ice_restarts and compare
745 // against the current description. 764 // against the current description.
746 if (CheckForRemoteIceRestart(old_remote_desc.get(), desc, content.name)) { 765 if (CheckForRemoteIceRestart(old_remote_description, desc,
766 content.name)) {
747 if (action == kOffer) { 767 if (action == kOffer) {
748 pending_ice_restarts_.insert(content.name); 768 pending_ice_restarts_.insert(content.name);
749 } 769 }
750 } else { 770 } else {
751 // We retain all received candidates only if ICE is not restarted. 771 // We retain all received candidates only if ICE is not restarted.
752 // When ICE is restarted, all previous candidates belong to an old 772 // When ICE is restarted, all previous candidates belong to an old
753 // generation and should not be kept. 773 // generation and should not be kept.
754 // TODO(deadbeef): This goes against the W3C spec which says the remote 774 // TODO(deadbeef): This goes against the W3C spec which says the remote
755 // description should only contain candidates from the last set remote 775 // description should only contain candidates from the last set remote
756 // description plus any candidates added since then. We should remove 776 // description plus any candidates added since then. We should remove
757 // this once we're sure it won't break anything. 777 // this once we're sure it won't break anything.
758 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( 778 WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
759 old_remote_desc.get(), content.name, desc); 779 old_remote_description, content.name, desc);
760 } 780 }
761 } 781 }
762 } 782 }
763 783
764 if (error() != ERROR_NONE) { 784 if (error() != ERROR_NONE) {
765 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc); 785 return BadRemoteSdp(desc->type(), GetSessionErrorMsg(), err_desc);
766 } 786 }
767 787
768 // Set the the ICE connection state to connecting since the connection may 788 // Set the the ICE connection state to connecting since the connection may
769 // become writable with peer reflexive candidates before any remote candidate 789 // become writable with peer reflexive candidates before any remote candidate
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 SetState(source == cricket::CS_LOCAL ? STATE_SENTPRANSWER 852 SetState(source == cricket::CS_LOCAL ? STATE_SENTPRANSWER
833 : STATE_RECEIVEDPRANSWER); 853 : STATE_RECEIVEDPRANSWER);
834 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) { 854 if (!PushdownMediaDescription(cricket::CA_PRANSWER, source, err_desc)) {
835 SetError(ERROR_CONTENT, *err_desc); 855 SetError(ERROR_CONTENT, *err_desc);
836 } 856 }
837 if (error() != ERROR_NONE) { 857 if (error() != ERROR_NONE) {
838 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc); 858 return BadPranswerSdp(source, GetSessionErrorMsg(), err_desc);
839 } 859 }
840 } else if (action == kAnswer) { 860 } else if (action == kAnswer) {
841 const cricket::ContentGroup* local_bundle = 861 const cricket::ContentGroup* local_bundle =
842 local_desc_->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); 862 local_description()->description()->GetGroupByName(
863 cricket::GROUP_TYPE_BUNDLE);
843 const cricket::ContentGroup* remote_bundle = 864 const cricket::ContentGroup* remote_bundle =
844 remote_desc_->description()->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); 865 remote_description()->description()->GetGroupByName(
866 cricket::GROUP_TYPE_BUNDLE);
845 if (local_bundle && remote_bundle) { 867 if (local_bundle && remote_bundle) {
846 // The answerer decides the transport to bundle on. 868 // The answerer decides the transport to bundle on.
847 const cricket::ContentGroup* answer_bundle = 869 const cricket::ContentGroup* answer_bundle =
848 (source == cricket::CS_LOCAL ? local_bundle : remote_bundle); 870 (source == cricket::CS_LOCAL ? local_bundle : remote_bundle);
849 if (!EnableBundle(*answer_bundle)) { 871 if (!EnableBundle(*answer_bundle)) {
850 LOG(LS_WARNING) << "Failed to enable BUNDLE."; 872 LOG(LS_WARNING) << "Failed to enable BUNDLE.";
851 return BadAnswerSdp(source, kEnableBundleFailed, err_desc); 873 return BadAnswerSdp(source, kEnableBundleFailed, err_desc);
852 } 874 }
853 } 875 }
854 // Only push down the transport description after enabling BUNDLE; we don't 876 // Only push down the transport description after enabling BUNDLE; we don't
(...skipping 26 matching lines...) Expand all
881 } 903 }
882 904
883 bool WebRtcSession::PushdownMediaDescription( 905 bool WebRtcSession::PushdownMediaDescription(
884 cricket::ContentAction action, 906 cricket::ContentAction action,
885 cricket::ContentSource source, 907 cricket::ContentSource source,
886 std::string* err) { 908 std::string* err) {
887 auto set_content = [this, action, source, err](cricket::BaseChannel* ch) { 909 auto set_content = [this, action, source, err](cricket::BaseChannel* ch) {
888 if (!ch) { 910 if (!ch) {
889 return true; 911 return true;
890 } else if (source == cricket::CS_LOCAL) { 912 } else if (source == cricket::CS_LOCAL) {
891 return ch->PushdownLocalDescription(local_desc_->description(), action, 913 return ch->PushdownLocalDescription(local_description()->description(),
892 err); 914 action, err);
893 } else { 915 } else {
894 return ch->PushdownRemoteDescription(remote_desc_->description(), action, 916 return ch->PushdownRemoteDescription(remote_description()->description(),
895 err); 917 action, err);
896 } 918 }
897 }; 919 };
898 920
899 return (set_content(voice_channel()) && 921 return (set_content(voice_channel()) &&
900 set_content(video_channel()) && 922 set_content(video_channel()) &&
901 set_content(data_channel())); 923 set_content(data_channel()));
902 } 924 }
903 925
904 bool WebRtcSession::PushdownTransportDescription(cricket::ContentSource source, 926 bool WebRtcSession::PushdownTransportDescription(cricket::ContentSource source,
905 cricket::ContentAction action, 927 cricket::ContentAction action,
906 std::string* error_desc) { 928 std::string* error_desc) {
907 RTC_DCHECK(signaling_thread()->IsCurrent()); 929 RTC_DCHECK(signaling_thread()->IsCurrent());
908 930
909 if (source == cricket::CS_LOCAL) { 931 if (source == cricket::CS_LOCAL) {
910 return PushdownLocalTransportDescription(local_desc_->description(), action, 932 return PushdownLocalTransportDescription(local_description()->description(),
911 error_desc); 933 action, error_desc);
912 } 934 }
913 return PushdownRemoteTransportDescription(remote_desc_->description(), action, 935 return PushdownRemoteTransportDescription(remote_description()->description(),
914 error_desc); 936 action, error_desc);
915 } 937 }
916 938
917 bool WebRtcSession::PushdownLocalTransportDescription( 939 bool WebRtcSession::PushdownLocalTransportDescription(
918 const SessionDescription* sdesc, 940 const SessionDescription* sdesc,
919 cricket::ContentAction action, 941 cricket::ContentAction action,
920 std::string* err) { 942 std::string* err) {
921 RTC_DCHECK(signaling_thread()->IsCurrent()); 943 RTC_DCHECK(signaling_thread()->IsCurrent());
922 944
923 if (!sdesc) { 945 if (!sdesc) {
924 return false; 946 return false;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 if (!maybe_set_transport(voice_channel()) || 1074 if (!maybe_set_transport(voice_channel()) ||
1053 !maybe_set_transport(video_channel()) || 1075 !maybe_set_transport(video_channel()) ||
1054 !maybe_set_transport(data_channel())) { 1076 !maybe_set_transport(data_channel())) {
1055 return false; 1077 return false;
1056 } 1078 }
1057 1079
1058 return true; 1080 return true;
1059 } 1081 }
1060 1082
1061 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { 1083 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) {
1062 if (!remote_desc_) { 1084 if (!remote_description()) {
1063 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " 1085 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added "
1064 << "without any remote session description."; 1086 << "without any remote session description.";
1065 return false; 1087 return false;
1066 } 1088 }
1067 1089
1068 if (!candidate) { 1090 if (!candidate) {
1069 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; 1091 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL.";
1070 return false; 1092 return false;
1071 } 1093 }
1072 1094
1073 bool valid = false; 1095 bool valid = false;
1074 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); 1096 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid);
1075 if (!valid) { 1097 if (!valid) {
1076 return false; 1098 return false;
1077 } 1099 }
1078 1100
1079 // Add this candidate to the remote session description. 1101 // Add this candidate to the remote session description.
1080 if (!remote_desc_->AddCandidate(candidate)) { 1102 if (!mutable_remote_description()->AddCandidate(candidate)) {
1081 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; 1103 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used.";
1082 return false; 1104 return false;
1083 } 1105 }
1084 1106
1085 if (ready) { 1107 if (ready) {
1086 return UseCandidate(candidate); 1108 return UseCandidate(candidate);
1087 } else { 1109 } else {
1088 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; 1110 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate.";
1089 return true; 1111 return true;
1090 } 1112 }
1091 } 1113 }
1092 1114
1093 bool WebRtcSession::RemoveRemoteIceCandidates( 1115 bool WebRtcSession::RemoveRemoteIceCandidates(
1094 const std::vector<cricket::Candidate>& candidates) { 1116 const std::vector<cricket::Candidate>& candidates) {
1095 if (!remote_desc_) { 1117 if (!remote_description()) {
1096 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: ICE candidates can't be " 1118 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: ICE candidates can't be "
1097 << "removed without any remote session description."; 1119 << "removed without any remote session description.";
1098 return false; 1120 return false;
1099 } 1121 }
1100 1122
1101 if (candidates.empty()) { 1123 if (candidates.empty()) {
1102 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: candidates are empty."; 1124 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: candidates are empty.";
1103 return false; 1125 return false;
1104 } 1126 }
1105 1127
1106 size_t number_removed = remote_desc_->RemoveCandidates(candidates); 1128 size_t number_removed =
1129 mutable_remote_description()->RemoveCandidates(candidates);
1107 if (number_removed != candidates.size()) { 1130 if (number_removed != candidates.size()) {
1108 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Failed to remove candidates. " 1131 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Failed to remove candidates. "
1109 << "Requested " << candidates.size() << " but only " 1132 << "Requested " << candidates.size() << " but only "
1110 << number_removed << " are removed."; 1133 << number_removed << " are removed.";
1111 } 1134 }
1112 1135
1113 // Remove the candidates from the transport controller. 1136 // Remove the candidates from the transport controller.
1114 std::string error; 1137 std::string error;
1115 bool res = transport_controller_->RemoveRemoteCandidates(candidates, &error); 1138 bool res = transport_controller_->RemoveRemoteCandidates(candidates, &error);
1116 if (!res && !error.empty()) { 1139 if (!res && !error.empty()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 void WebRtcSession::SetIceConfig(const cricket::IceConfig& config) { 1173 void WebRtcSession::SetIceConfig(const cricket::IceConfig& config) {
1151 transport_controller_->SetIceConfig(config); 1174 transport_controller_->SetIceConfig(config);
1152 } 1175 }
1153 1176
1154 void WebRtcSession::MaybeStartGathering() { 1177 void WebRtcSession::MaybeStartGathering() {
1155 transport_controller_->MaybeStartGathering(); 1178 transport_controller_->MaybeStartGathering();
1156 } 1179 }
1157 1180
1158 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc, 1181 bool WebRtcSession::GetLocalTrackIdBySsrc(uint32_t ssrc,
1159 std::string* track_id) { 1182 std::string* track_id) {
1160 if (!local_desc_) { 1183 if (!local_description()) {
1161 return false; 1184 return false;
1162 } 1185 }
1163 return webrtc::GetTrackIdBySsrc(local_desc_->description(), ssrc, track_id); 1186 return webrtc::GetTrackIdBySsrc(local_description()->description(), ssrc,
1187 track_id);
1164 } 1188 }
1165 1189
1166 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc, 1190 bool WebRtcSession::GetRemoteTrackIdBySsrc(uint32_t ssrc,
1167 std::string* track_id) { 1191 std::string* track_id) {
1168 if (!remote_desc_) { 1192 if (!remote_description()) {
1169 return false; 1193 return false;
1170 } 1194 }
1171 return webrtc::GetTrackIdBySsrc(remote_desc_->description(), ssrc, track_id); 1195 return webrtc::GetTrackIdBySsrc(remote_description()->description(), ssrc,
1196 track_id);
1172 } 1197 }
1173 1198
1174 std::string WebRtcSession::BadStateErrMsg(State state) { 1199 std::string WebRtcSession::BadStateErrMsg(State state) {
1175 std::ostringstream desc; 1200 std::ostringstream desc;
1176 desc << "Called in wrong state: " << GetStateString(state); 1201 desc << "Called in wrong state: " << GetStateString(state);
1177 return desc.str(); 1202 return desc.str();
1178 } 1203 }
1179 1204
1180 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) { 1205 bool WebRtcSession::CanInsertDtmf(const std::string& track_id) {
1181 ASSERT(signaling_thread()->IsCurrent()); 1206 ASSERT(signaling_thread()->IsCurrent());
1182 if (!voice_channel_) { 1207 if (!voice_channel_) {
1183 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; 1208 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists.";
1184 return false; 1209 return false;
1185 } 1210 }
1186 uint32_t send_ssrc = 0; 1211 uint32_t send_ssrc = 0;
1187 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc 1212 // The Dtmf is negotiated per channel not ssrc, so we only check if the ssrc
1188 // exists. 1213 // exists.
1189 if (!local_desc_ || 1214 if (!local_description() ||
1190 !GetAudioSsrcByTrackId(local_desc_->description(), track_id, 1215 !GetAudioSsrcByTrackId(local_description()->description(), track_id,
1191 &send_ssrc)) { 1216 &send_ssrc)) {
1192 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id; 1217 LOG(LS_ERROR) << "CanInsertDtmf: Track does not exist: " << track_id;
1193 return false; 1218 return false;
1194 } 1219 }
1195 return voice_channel_->CanInsertDtmf(); 1220 return voice_channel_->CanInsertDtmf();
1196 } 1221 }
1197 1222
1198 bool WebRtcSession::InsertDtmf(const std::string& track_id, 1223 bool WebRtcSession::InsertDtmf(const std::string& track_id,
1199 int code, int duration) { 1224 int code, int duration) {
1200 ASSERT(signaling_thread()->IsCurrent()); 1225 ASSERT(signaling_thread()->IsCurrent());
1201 if (!voice_channel_) { 1226 if (!voice_channel_) {
1202 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists."; 1227 LOG(LS_ERROR) << "InsertDtmf: No audio channel exists.";
1203 return false; 1228 return false;
1204 } 1229 }
1205 uint32_t send_ssrc = 0; 1230 uint32_t send_ssrc = 0;
1206 if (!VERIFY(local_desc_ && GetAudioSsrcByTrackId(local_desc_->description(), 1231 if (!VERIFY(local_description() &&
1207 track_id, &send_ssrc))) { 1232 GetAudioSsrcByTrackId(local_description()->description(),
1233 track_id, &send_ssrc))) {
1208 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id; 1234 LOG(LS_ERROR) << "InsertDtmf: Track does not exist: " << track_id;
1209 return false; 1235 return false;
1210 } 1236 }
1211 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration)) { 1237 if (!voice_channel_->InsertDtmf(send_ssrc, code, duration)) {
1212 LOG(LS_ERROR) << "Failed to insert DTMF to channel."; 1238 LOG(LS_ERROR) << "Failed to insert DTMF to channel.";
1213 return false; 1239 return false;
1214 } 1240 }
1215 return true; 1241 return true;
1216 } 1242 }
1217 1243
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 return; 1421 return;
1396 } 1422 }
1397 1423
1398 for (cricket::Candidates::const_iterator citer = candidates.begin(); 1424 for (cricket::Candidates::const_iterator citer = candidates.begin();
1399 citer != candidates.end(); ++citer) { 1425 citer != candidates.end(); ++citer) {
1400 // Use transport_name as the candidate media id. 1426 // Use transport_name as the candidate media id.
1401 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); 1427 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer);
1402 if (ice_observer_) { 1428 if (ice_observer_) {
1403 ice_observer_->OnIceCandidate(&candidate); 1429 ice_observer_->OnIceCandidate(&candidate);
1404 } 1430 }
1405 if (local_desc_) { 1431 if (local_description()) {
1406 local_desc_->AddCandidate(&candidate); 1432 mutable_local_description()->AddCandidate(&candidate);
1407 } 1433 }
1408 } 1434 }
1409 } 1435 }
1410 1436
1411 void WebRtcSession::OnTransportControllerCandidatesRemoved( 1437 void WebRtcSession::OnTransportControllerCandidatesRemoved(
1412 const std::vector<cricket::Candidate>& candidates) { 1438 const std::vector<cricket::Candidate>& candidates) {
1413 ASSERT(signaling_thread()->IsCurrent()); 1439 ASSERT(signaling_thread()->IsCurrent());
1414 // Sanity check. 1440 // Sanity check.
1415 for (const cricket::Candidate& candidate : candidates) { 1441 for (const cricket::Candidate& candidate : candidates) {
1416 if (candidate.transport_name().empty()) { 1442 if (candidate.transport_name().empty()) {
1417 LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: " 1443 LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: "
1418 << "empty content name in candidate " 1444 << "empty content name in candidate "
1419 << candidate.ToString(); 1445 << candidate.ToString();
1420 return; 1446 return;
1421 } 1447 }
1422 } 1448 }
1423 1449
1424 if (local_desc_) { 1450 if (local_description()) {
1425 local_desc_->RemoveCandidates(candidates); 1451 mutable_local_description()->RemoveCandidates(candidates);
1426 } 1452 }
1427 if (ice_observer_) { 1453 if (ice_observer_) {
1428 ice_observer_->OnIceCandidatesRemoved(candidates); 1454 ice_observer_->OnIceCandidatesRemoved(candidates);
1429 } 1455 }
1430 } 1456 }
1431 1457
1432 // Enabling voice and video channel. 1458 // Enabling voice and video channel.
1433 void WebRtcSession::EnableChannels() { 1459 void WebRtcSession::EnableChannels() {
1434 if (voice_channel_ && !voice_channel_->enabled()) 1460 if (voice_channel_ && !voice_channel_->enabled())
1435 voice_channel_->Enable(true); 1461 voice_channel_->Enable(true);
1436 1462
1437 if (video_channel_ && !video_channel_->enabled()) 1463 if (video_channel_ && !video_channel_->enabled())
1438 video_channel_->Enable(true); 1464 video_channel_->Enable(true);
1439 1465
1440 if (data_channel_ && !data_channel_->enabled()) 1466 if (data_channel_ && !data_channel_->enabled())
1441 data_channel_->Enable(true); 1467 data_channel_->Enable(true);
1442 } 1468 }
1443 1469
1444 // Returns the media index for a local ice candidate given the content name. 1470 // Returns the media index for a local ice candidate given the content name.
1445 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name, 1471 bool WebRtcSession::GetLocalCandidateMediaIndex(const std::string& content_name,
1446 int* sdp_mline_index) { 1472 int* sdp_mline_index) {
1447 if (!local_desc_ || !sdp_mline_index) { 1473 if (!local_description() || !sdp_mline_index) {
1448 return false; 1474 return false;
1449 } 1475 }
1450 1476
1451 bool content_found = false; 1477 bool content_found = false;
1452 const ContentInfos& contents = local_desc_->description()->contents(); 1478 const ContentInfos& contents = local_description()->description()->contents();
1453 for (size_t index = 0; index < contents.size(); ++index) { 1479 for (size_t index = 0; index < contents.size(); ++index) {
1454 if (contents[index].name == content_name) { 1480 if (contents[index].name == content_name) {
1455 *sdp_mline_index = static_cast<int>(index); 1481 *sdp_mline_index = static_cast<int>(index);
1456 content_found = true; 1482 content_found = true;
1457 break; 1483 break;
1458 } 1484 }
1459 } 1485 }
1460 return content_found; 1486 return content_found;
1461 } 1487 }
1462 1488
(...skipping 20 matching lines...) Expand all
1483 if (!ret) { 1509 if (!ret) {
1484 break; 1510 break;
1485 } 1511 }
1486 } 1512 }
1487 } 1513 }
1488 return ret; 1514 return ret;
1489 } 1515 }
1490 1516
1491 bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) { 1517 bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) {
1492 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); 1518 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index());
1493 size_t remote_content_size = remote_desc_->description()->contents().size(); 1519 size_t remote_content_size =
1520 remote_description()->description()->contents().size();
1494 if (mediacontent_index >= remote_content_size) { 1521 if (mediacontent_index >= remote_content_size) {
1495 LOG(LS_ERROR) << "UseCandidate: Invalid candidate media index."; 1522 LOG(LS_ERROR) << "UseCandidate: Invalid candidate media index.";
1496 return false; 1523 return false;
1497 } 1524 }
1498 1525
1499 cricket::ContentInfo content = 1526 cricket::ContentInfo content =
1500 remote_desc_->description()->contents()[mediacontent_index]; 1527 remote_description()->description()->contents()[mediacontent_index];
1501 std::vector<cricket::Candidate> candidates; 1528 std::vector<cricket::Candidate> candidates;
1502 candidates.push_back(candidate->candidate()); 1529 candidates.push_back(candidate->candidate());
1503 // Invoking BaseSession method to handle remote candidates. 1530 // Invoking BaseSession method to handle remote candidates.
1504 std::string error; 1531 std::string error;
1505 if (transport_controller_->AddRemoteCandidates(content.name, candidates, 1532 if (transport_controller_->AddRemoteCandidates(content.name, candidates,
1506 &error)) { 1533 &error)) {
1507 // Candidates successfully submitted for checking. 1534 // Candidates successfully submitted for checking.
1508 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || 1535 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew ||
1509 ice_connection_state_ == 1536 ice_connection_state_ ==
1510 PeerConnectionInterface::kIceConnectionDisconnected) { 1537 PeerConnectionInterface::kIceConnectionDisconnected) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 if (!ValidateBundleSettings(sdesc->description())) { 1855 if (!ValidateBundleSettings(sdesc->description())) {
1829 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc); 1856 return BadSdp(source, type, kBundleWithoutRtcpMux, err_desc);
1830 } 1857 }
1831 1858
1832 // TODO(skvlad): When the local rtcp-mux policy is Require, reject any 1859 // TODO(skvlad): When the local rtcp-mux policy is Require, reject any
1833 // m-lines that do not rtcp-mux enabled. 1860 // m-lines that do not rtcp-mux enabled.
1834 1861
1835 // Verify m-lines in Answer when compared against Offer. 1862 // Verify m-lines in Answer when compared against Offer.
1836 if (action == kAnswer) { 1863 if (action == kAnswer) {
1837 const cricket::SessionDescription* offer_desc = 1864 const cricket::SessionDescription* offer_desc =
1838 (source == cricket::CS_LOCAL) ? remote_desc_->description() 1865 (source == cricket::CS_LOCAL) ? remote_description()->description()
1839 : local_desc_->description(); 1866 : local_description()->description();
1840 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) { 1867 if (!VerifyMediaDescriptions(sdesc->description(), offer_desc)) {
1841 return BadAnswerSdp(source, kMlineMismatch, err_desc); 1868 return BadAnswerSdp(source, kMlineMismatch, err_desc);
1842 } 1869 }
1843 } 1870 }
1844 1871
1845 return true; 1872 return true;
1846 } 1873 }
1847 1874
1848 bool WebRtcSession::ExpectSetLocalDescription(Action action) { 1875 bool WebRtcSession::ExpectSetLocalDescription(Action action) {
1849 return ((action == kOffer && state() == STATE_INIT) || 1876 return ((action == kOffer && state() == STATE_INIT) ||
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 // them unset while the session has them set from the previous negotiation. 1910 // them unset while the session has them set from the previous negotiation.
1884 // Not doing so may trigger the auto generation of transport description and 1911 // Not doing so may trigger the auto generation of transport description and
1885 // mess up DTLS identity information, ICE credential, etc. 1912 // mess up DTLS identity information, ICE credential, etc.
1886 bool WebRtcSession::ReadyToUseRemoteCandidate( 1913 bool WebRtcSession::ReadyToUseRemoteCandidate(
1887 const IceCandidateInterface* candidate, 1914 const IceCandidateInterface* candidate,
1888 const SessionDescriptionInterface* remote_desc, 1915 const SessionDescriptionInterface* remote_desc,
1889 bool* valid) { 1916 bool* valid) {
1890 *valid = true; 1917 *valid = true;
1891 1918
1892 const SessionDescriptionInterface* current_remote_desc = 1919 const SessionDescriptionInterface* current_remote_desc =
1893 remote_desc ? remote_desc : remote_desc_.get(); 1920 remote_desc ? remote_desc : remote_description();
1894 1921
1895 if (!current_remote_desc) { 1922 if (!current_remote_desc) {
1896 return false; 1923 return false;
1897 } 1924 }
1898 1925
1899 size_t mediacontent_index = 1926 size_t mediacontent_index =
1900 static_cast<size_t>(candidate->sdp_mline_index()); 1927 static_cast<size_t>(candidate->sdp_mline_index());
1901 size_t remote_content_size = 1928 size_t remote_content_size =
1902 current_remote_desc->description()->contents().size(); 1929 current_remote_desc->description()->contents().size();
1903 if (mediacontent_index >= remote_content_size) { 1930 if (mediacontent_index >= remote_content_size) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 } 2101 }
2075 2102
2076 void WebRtcSession::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { 2103 void WebRtcSession::OnDtlsHandshakeError(rtc::SSLHandshakeError error) {
2077 if (metrics_observer_) { 2104 if (metrics_observer_) {
2078 metrics_observer_->IncrementEnumCounter( 2105 metrics_observer_->IncrementEnumCounter(
2079 webrtc::kEnumCounterDtlsHandshakeError, static_cast<int>(error), 2106 webrtc::kEnumCounterDtlsHandshakeError, static_cast<int>(error),
2080 static_cast<int>(rtc::SSLHandshakeError::MAX_VALUE)); 2107 static_cast<int>(rtc::SSLHandshakeError::MAX_VALUE));
2081 } 2108 }
2082 } 2109 }
2083 } // namespace webrtc 2110 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698