OLD | NEW |
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 metrics_observer_(NULL) { | 494 metrics_observer_(NULL) { |
495 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 495 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
496 transport_controller_->SignalConnectionState.connect( | 496 transport_controller_->SignalConnectionState.connect( |
497 this, &WebRtcSession::OnTransportControllerConnectionState); | 497 this, &WebRtcSession::OnTransportControllerConnectionState); |
498 transport_controller_->SignalReceiving.connect( | 498 transport_controller_->SignalReceiving.connect( |
499 this, &WebRtcSession::OnTransportControllerReceiving); | 499 this, &WebRtcSession::OnTransportControllerReceiving); |
500 transport_controller_->SignalGatheringState.connect( | 500 transport_controller_->SignalGatheringState.connect( |
501 this, &WebRtcSession::OnTransportControllerGatheringState); | 501 this, &WebRtcSession::OnTransportControllerGatheringState); |
502 transport_controller_->SignalCandidatesGathered.connect( | 502 transport_controller_->SignalCandidatesGathered.connect( |
503 this, &WebRtcSession::OnTransportControllerCandidatesGathered); | 503 this, &WebRtcSession::OnTransportControllerCandidatesGathered); |
| 504 transport_controller_->SignalCandidatesRemoved.connect( |
| 505 this, &WebRtcSession::OnTransportControllerCandidatesRemoved); |
504 } | 506 } |
505 | 507 |
506 WebRtcSession::~WebRtcSession() { | 508 WebRtcSession::~WebRtcSession() { |
507 ASSERT(signaling_thread()->IsCurrent()); | 509 ASSERT(signaling_thread()->IsCurrent()); |
508 // Destroy video_channel_ first since it may have a pointer to the | 510 // Destroy video_channel_ first since it may have a pointer to the |
509 // voice_channel_. | 511 // voice_channel_. |
510 if (video_channel_) { | 512 if (video_channel_) { |
511 SignalVideoChannelDestroyed(); | 513 SignalVideoChannelDestroyed(); |
512 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 514 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
513 } | 515 } |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 return false; | 1081 return false; |
1080 } | 1082 } |
1081 | 1083 |
1082 return true; | 1084 return true; |
1083 } | 1085 } |
1084 | 1086 |
1085 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { | 1087 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
1086 if (!remote_desc_) { | 1088 if (!remote_desc_) { |
1087 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " | 1089 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
1088 << "without any remote session description."; | 1090 << "without any remote session description."; |
1089 return false; | 1091 return false; |
1090 } | 1092 } |
1091 | 1093 |
1092 if (!candidate) { | 1094 if (!candidate) { |
1093 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; | 1095 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; |
1094 return false; | 1096 return false; |
1095 } | 1097 } |
1096 | 1098 |
1097 bool valid = false; | 1099 bool valid = false; |
1098 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); | 1100 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); |
1099 if (!valid) { | 1101 if (!valid) { |
1100 return false; | 1102 return false; |
1101 } | 1103 } |
1102 | 1104 |
1103 // Add this candidate to the remote session description. | 1105 // Add this candidate to the remote session description. |
1104 if (!remote_desc_->AddCandidate(candidate)) { | 1106 if (!remote_desc_->AddCandidate(candidate)) { |
1105 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; | 1107 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; |
1106 return false; | 1108 return false; |
1107 } | 1109 } |
1108 | 1110 |
1109 if (ready) { | 1111 if (ready) { |
1110 return UseCandidate(candidate); | 1112 return UseCandidate(candidate); |
1111 } else { | 1113 } else { |
1112 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; | 1114 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; |
1113 return true; | 1115 return true; |
1114 } | 1116 } |
1115 } | 1117 } |
1116 | 1118 |
| 1119 bool WebRtcSession::RemoveRemoteIceCandidates( |
| 1120 const std::vector<cricket::Candidate>& candidates) { |
| 1121 if (!remote_desc_) { |
| 1122 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: ICE candidates can't be " |
| 1123 << "removed without any remote session description."; |
| 1124 return false; |
| 1125 } |
| 1126 |
| 1127 if (candidates.empty()) { |
| 1128 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: candidates are empty."; |
| 1129 return false; |
| 1130 } |
| 1131 |
| 1132 size_t number_removed = remote_desc_->RemoveCandidates(candidates); |
| 1133 if (number_removed != candidates.size()) { |
| 1134 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Failed to remove candidates. " |
| 1135 << "Requested " << candidates.size() << " but only " |
| 1136 << number_removed << " are removed."; |
| 1137 } |
| 1138 |
| 1139 // Remove the candidates from the transport controller. |
| 1140 std::string error; |
| 1141 bool res = transport_controller_->RemoveRemoteCandidates(candidates, &error); |
| 1142 if (!res && !error.empty()) { |
| 1143 LOG(LS_ERROR) << "Error when removing remote candidates: " << error; |
| 1144 } |
| 1145 return true; |
| 1146 } |
| 1147 |
1117 bool WebRtcSession::SetIceTransports( | 1148 bool WebRtcSession::SetIceTransports( |
1118 PeerConnectionInterface::IceTransportsType type) { | 1149 PeerConnectionInterface::IceTransportsType type) { |
1119 return port_allocator()->set_candidate_filter( | 1150 return port_allocator()->set_candidate_filter( |
1120 ConvertIceTransportTypeToCandidateFilter(type)); | 1151 ConvertIceTransportTypeToCandidateFilter(type)); |
1121 } | 1152 } |
1122 | 1153 |
1123 cricket::IceConfig WebRtcSession::ParseIceConfig( | 1154 cricket::IceConfig WebRtcSession::ParseIceConfig( |
1124 const PeerConnectionInterface::RTCConfiguration& config) const { | 1155 const PeerConnectionInterface::RTCConfiguration& config) const { |
1125 cricket::IceConfig ice_config; | 1156 cricket::IceConfig ice_config; |
1126 ice_config.receiving_timeout = config.ice_connection_receiving_timeout; | 1157 ice_config.receiving_timeout = config.ice_connection_receiving_timeout; |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); | 1547 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); |
1517 if (ice_observer_) { | 1548 if (ice_observer_) { |
1518 ice_observer_->OnIceCandidate(&candidate); | 1549 ice_observer_->OnIceCandidate(&candidate); |
1519 } | 1550 } |
1520 if (local_desc_) { | 1551 if (local_desc_) { |
1521 local_desc_->AddCandidate(&candidate); | 1552 local_desc_->AddCandidate(&candidate); |
1522 } | 1553 } |
1523 } | 1554 } |
1524 } | 1555 } |
1525 | 1556 |
| 1557 void WebRtcSession::OnTransportControllerCandidatesRemoved( |
| 1558 const std::vector<cricket::Candidate>& candidates) { |
| 1559 ASSERT(signaling_thread()->IsCurrent()); |
| 1560 // Sanity check. |
| 1561 for (const cricket::Candidate& candidate : candidates) { |
| 1562 if (candidate.transport_name().empty()) { |
| 1563 LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: " |
| 1564 << "empty content name in candidate " |
| 1565 << candidate.ToString(); |
| 1566 return; |
| 1567 } |
| 1568 } |
| 1569 |
| 1570 if (local_desc_) { |
| 1571 local_desc_->RemoveCandidates(candidates); |
| 1572 } |
| 1573 if (ice_observer_) { |
| 1574 ice_observer_->OnIceCandidatesRemoved(candidates); |
| 1575 } |
| 1576 } |
| 1577 |
1526 // Enabling voice and video channel. | 1578 // Enabling voice and video channel. |
1527 void WebRtcSession::EnableChannels() { | 1579 void WebRtcSession::EnableChannels() { |
1528 if (voice_channel_ && !voice_channel_->enabled()) | 1580 if (voice_channel_ && !voice_channel_->enabled()) |
1529 voice_channel_->Enable(true); | 1581 voice_channel_->Enable(true); |
1530 | 1582 |
1531 if (video_channel_ && !video_channel_->enabled()) | 1583 if (video_channel_ && !video_channel_->enabled()) |
1532 video_channel_->Enable(true); | 1584 video_channel_->Enable(true); |
1533 | 1585 |
1534 if (data_channel_ && !data_channel_->enabled()) | 1586 if (data_channel_ && !data_channel_->enabled()) |
1535 data_channel_->Enable(true); | 1587 data_channel_->Enable(true); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 } | 1627 } |
1576 ret = UseCandidate(candidate); | 1628 ret = UseCandidate(candidate); |
1577 if (!ret) { | 1629 if (!ret) { |
1578 break; | 1630 break; |
1579 } | 1631 } |
1580 } | 1632 } |
1581 } | 1633 } |
1582 return ret; | 1634 return ret; |
1583 } | 1635 } |
1584 | 1636 |
1585 bool WebRtcSession::UseCandidate( | 1637 bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) { |
1586 const IceCandidateInterface* candidate) { | |
1587 | |
1588 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); | 1638 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
1589 size_t remote_content_size = remote_desc_->description()->contents().size(); | 1639 size_t remote_content_size = remote_desc_->description()->contents().size(); |
1590 if (mediacontent_index >= remote_content_size) { | 1640 if (mediacontent_index >= remote_content_size) { |
1591 LOG(LS_ERROR) | 1641 LOG(LS_ERROR) << "UseCandidate: Invalid candidate media index."; |
1592 << "UseRemoteCandidateInSession: Invalid candidate media index."; | |
1593 return false; | 1642 return false; |
1594 } | 1643 } |
1595 | 1644 |
1596 cricket::ContentInfo content = | 1645 cricket::ContentInfo content = |
1597 remote_desc_->description()->contents()[mediacontent_index]; | 1646 remote_desc_->description()->contents()[mediacontent_index]; |
1598 std::vector<cricket::Candidate> candidates; | 1647 std::vector<cricket::Candidate> candidates; |
1599 candidates.push_back(candidate->candidate()); | 1648 candidates.push_back(candidate->candidate()); |
1600 // Invoking BaseSession method to handle remote candidates. | 1649 // Invoking BaseSession method to handle remote candidates. |
1601 std::string error; | 1650 std::string error; |
1602 if (transport_controller_->AddRemoteCandidates(content.name, candidates, | 1651 if (transport_controller_->AddRemoteCandidates(content.name, candidates, |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 | 1972 |
1924 if (!current_remote_desc) { | 1973 if (!current_remote_desc) { |
1925 return false; | 1974 return false; |
1926 } | 1975 } |
1927 | 1976 |
1928 size_t mediacontent_index = | 1977 size_t mediacontent_index = |
1929 static_cast<size_t>(candidate->sdp_mline_index()); | 1978 static_cast<size_t>(candidate->sdp_mline_index()); |
1930 size_t remote_content_size = | 1979 size_t remote_content_size = |
1931 current_remote_desc->description()->contents().size(); | 1980 current_remote_desc->description()->contents().size(); |
1932 if (mediacontent_index >= remote_content_size) { | 1981 if (mediacontent_index >= remote_content_size) { |
1933 LOG(LS_ERROR) | 1982 LOG(LS_ERROR) << "ReadyToUseRemoteCandidate: Invalid candidate media index " |
1934 << "ReadyToUseRemoteCandidate: Invalid candidate media index."; | 1983 << mediacontent_index; |
1935 | 1984 |
1936 *valid = false; | 1985 *valid = false; |
1937 return false; | 1986 return false; |
1938 } | 1987 } |
1939 | 1988 |
1940 cricket::ContentInfo content = | 1989 cricket::ContentInfo content = |
1941 current_remote_desc->description()->contents()[mediacontent_index]; | 1990 current_remote_desc->description()->contents()[mediacontent_index]; |
1942 cricket::BaseChannel* channel = GetChannel(content.name); | 1991 cricket::BaseChannel* channel = GetChannel(content.name); |
1943 if (!channel) { | 1992 if (!channel) { |
1944 return false; | 1993 return false; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 } | 2126 } |
2078 } | 2127 } |
2079 | 2128 |
2080 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, | 2129 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, |
2081 const rtc::SentPacket& sent_packet) { | 2130 const rtc::SentPacket& sent_packet) { |
2082 RTC_DCHECK(worker_thread()->IsCurrent()); | 2131 RTC_DCHECK(worker_thread()->IsCurrent()); |
2083 media_controller_->call_w()->OnSentPacket(sent_packet); | 2132 media_controller_->call_w()->OnSentPacket(sent_packet); |
2084 } | 2133 } |
2085 | 2134 |
2086 } // namespace webrtc | 2135 } // namespace webrtc |
OLD | NEW |