Chromium Code Reviews| 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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 metrics_observer_(NULL) { | 547 metrics_observer_(NULL) { |
| 548 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 548 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 549 transport_controller_->SignalConnectionState.connect( | 549 transport_controller_->SignalConnectionState.connect( |
| 550 this, &WebRtcSession::OnTransportControllerConnectionState); | 550 this, &WebRtcSession::OnTransportControllerConnectionState); |
| 551 transport_controller_->SignalReceiving.connect( | 551 transport_controller_->SignalReceiving.connect( |
| 552 this, &WebRtcSession::OnTransportControllerReceiving); | 552 this, &WebRtcSession::OnTransportControllerReceiving); |
| 553 transport_controller_->SignalGatheringState.connect( | 553 transport_controller_->SignalGatheringState.connect( |
| 554 this, &WebRtcSession::OnTransportControllerGatheringState); | 554 this, &WebRtcSession::OnTransportControllerGatheringState); |
| 555 transport_controller_->SignalCandidatesGathered.connect( | 555 transport_controller_->SignalCandidatesGathered.connect( |
| 556 this, &WebRtcSession::OnTransportControllerCandidatesGathered); | 556 this, &WebRtcSession::OnTransportControllerCandidatesGathered); |
| 557 transport_controller_->SignalCandidatesRemoved.connect( | |
| 558 this, &WebRtcSession::OnTransportControllerCandidatesRemoved); | |
| 557 } | 559 } |
| 558 | 560 |
| 559 WebRtcSession::~WebRtcSession() { | 561 WebRtcSession::~WebRtcSession() { |
| 560 ASSERT(signaling_thread()->IsCurrent()); | 562 ASSERT(signaling_thread()->IsCurrent()); |
| 561 // Destroy video_channel_ first since it may have a pointer to the | 563 // Destroy video_channel_ first since it may have a pointer to the |
| 562 // voice_channel_. | 564 // voice_channel_. |
| 563 if (video_channel_) { | 565 if (video_channel_) { |
| 564 SignalVideoChannelDestroyed(); | 566 SignalVideoChannelDestroyed(); |
| 565 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 567 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 566 } | 568 } |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1144 return false; | 1146 return false; |
| 1145 } | 1147 } |
| 1146 | 1148 |
| 1147 return true; | 1149 return true; |
| 1148 } | 1150 } |
| 1149 | 1151 |
| 1150 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { | 1152 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
| 1151 if (!remote_desc_) { | 1153 if (!remote_desc_) { |
| 1152 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " | 1154 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " |
| 1153 << "without any remote session description."; | 1155 << "without any remote session description."; |
| 1154 return false; | 1156 return false; |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 if (!candidate) { | 1159 if (!candidate) { |
| 1158 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; | 1160 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; |
| 1159 return false; | 1161 return false; |
| 1160 } | 1162 } |
| 1161 | 1163 |
| 1162 bool valid = false; | 1164 bool valid = false; |
| 1163 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); | 1165 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); |
| 1164 if (!valid) { | 1166 if (!valid) { |
| 1165 return false; | 1167 return false; |
| 1166 } | 1168 } |
| 1167 | 1169 |
| 1168 // Add this candidate to the remote session description. | 1170 // Add this candidate to the remote session description. |
| 1169 if (!remote_desc_->AddCandidate(candidate)) { | 1171 if (!remote_desc_->AddCandidate(candidate)) { |
| 1170 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; | 1172 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; |
| 1171 return false; | 1173 return false; |
| 1172 } | 1174 } |
| 1173 | 1175 |
| 1174 if (ready) { | 1176 if (ready) { |
| 1175 return UseCandidate(candidate); | 1177 return UseCandidate(candidate); |
| 1176 } else { | 1178 } else { |
| 1177 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; | 1179 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; |
| 1178 return true; | 1180 return true; |
| 1179 } | 1181 } |
| 1180 } | 1182 } |
| 1181 | 1183 |
| 1184 bool WebRtcSession::RemoveRemoteIceCandidates( | |
| 1185 const std::vector<IceCandidateInterfaceRefPtr>& candidates) { | |
| 1186 if (!remote_desc_) { | |
| 1187 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: ICE candidates can't be " | |
| 1188 << "removed without any remote session description."; | |
| 1189 return false; | |
| 1190 } | |
| 1191 | |
| 1192 if (candidates.empty()) { | |
| 1193 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Candidates is empty."; | |
| 1194 return false; | |
| 1195 } | |
| 1196 | |
| 1197 int number_removed = remote_desc_->RemoveCandidates(candidates); | |
| 1198 if (number_removed != candidates.size()) { | |
| 1199 LOG(LS_ERROR) << "RemoveRemoteIceCandidates: Failed to remove candidates. " | |
| 1200 << "Requested " << candidates.size() << " only " | |
| 1201 << number_removed << " are removed."; | |
| 1202 } | |
| 1203 return CeaseRemoteCandidates(candidates); | |
| 1204 } | |
| 1205 | |
| 1182 bool WebRtcSession::SetIceTransports( | 1206 bool WebRtcSession::SetIceTransports( |
| 1183 PeerConnectionInterface::IceTransportsType type) { | 1207 PeerConnectionInterface::IceTransportsType type) { |
| 1184 return port_allocator()->set_candidate_filter( | 1208 return port_allocator()->set_candidate_filter( |
| 1185 ConvertIceTransportTypeToCandidateFilter(type)); | 1209 ConvertIceTransportTypeToCandidateFilter(type)); |
| 1186 } | 1210 } |
| 1187 | 1211 |
| 1188 cricket::IceConfig WebRtcSession::ParseIceConfig( | 1212 cricket::IceConfig WebRtcSession::ParseIceConfig( |
| 1189 const PeerConnectionInterface::RTCConfiguration& config) const { | 1213 const PeerConnectionInterface::RTCConfiguration& config) const { |
| 1190 cricket::IceConfig ice_config; | 1214 cricket::IceConfig ice_config; |
| 1191 ice_config.receiving_timeout_ms = config.ice_connection_receiving_timeout; | 1215 ice_config.receiving_timeout_ms = config.ice_connection_receiving_timeout; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1582 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); | 1606 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); |
| 1583 if (ice_observer_) { | 1607 if (ice_observer_) { |
| 1584 ice_observer_->OnIceCandidate(&candidate); | 1608 ice_observer_->OnIceCandidate(&candidate); |
| 1585 } | 1609 } |
| 1586 if (local_desc_) { | 1610 if (local_desc_) { |
| 1587 local_desc_->AddCandidate(&candidate); | 1611 local_desc_->AddCandidate(&candidate); |
| 1588 } | 1612 } |
| 1589 } | 1613 } |
| 1590 } | 1614 } |
| 1591 | 1615 |
| 1616 void WebRtcSession::OnTransportControllerCandidatesRemoved( | |
| 1617 const std::string& transport_name, | |
| 1618 const cricket::Candidates& candidates) { | |
| 1619 ASSERT(signaling_thread()->IsCurrent()); | |
| 1620 int sdp_mline_index; | |
| 1621 if (!GetLocalCandidateMediaIndex(transport_name, &sdp_mline_index)) { | |
| 1622 LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: content name " | |
| 1623 << transport_name << " not found"; | |
| 1624 return; | |
| 1625 } | |
| 1626 | |
| 1627 std::vector<IceCandidateInterfaceRefPtr> ice_candidates; | |
| 1628 for (const cricket::Candidate& cand : candidates) { | |
| 1629 // Use transport_name as the candidate media id. | |
| 1630 JsepIceCandidate* candidate = | |
| 1631 new JsepIceCandidate(transport_name, sdp_mline_index, cand); | |
| 1632 ice_candidates.push_back(candidate); | |
| 1633 } | |
| 1634 | |
| 1635 if (local_desc_) { | |
| 1636 local_desc_->RemoveCandidates(ice_candidates); | |
| 1637 } | |
| 1638 if (ice_observer_) { | |
| 1639 ice_observer_->OnIceCandidatesRemoved(ice_candidates); | |
| 1640 } | |
| 1641 } | |
| 1642 | |
| 1592 // Enabling voice and video channel. | 1643 // Enabling voice and video channel. |
| 1593 void WebRtcSession::EnableChannels() { | 1644 void WebRtcSession::EnableChannels() { |
| 1594 if (voice_channel_ && !voice_channel_->enabled()) | 1645 if (voice_channel_ && !voice_channel_->enabled()) |
| 1595 voice_channel_->Enable(true); | 1646 voice_channel_->Enable(true); |
| 1596 | 1647 |
| 1597 if (video_channel_ && !video_channel_->enabled()) | 1648 if (video_channel_ && !video_channel_->enabled()) |
| 1598 video_channel_->Enable(true); | 1649 video_channel_->Enable(true); |
| 1599 | 1650 |
| 1600 if (data_channel_ && !data_channel_->enabled()) | 1651 if (data_channel_ && !data_channel_->enabled()) |
| 1601 data_channel_->Enable(true); | 1652 data_channel_->Enable(true); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1641 } | 1692 } |
| 1642 ret = UseCandidate(candidate); | 1693 ret = UseCandidate(candidate); |
| 1643 if (!ret) { | 1694 if (!ret) { |
| 1644 break; | 1695 break; |
| 1645 } | 1696 } |
| 1646 } | 1697 } |
| 1647 } | 1698 } |
| 1648 return ret; | 1699 return ret; |
| 1649 } | 1700 } |
| 1650 | 1701 |
| 1651 bool WebRtcSession::UseCandidate( | 1702 const cricket::ContentInfo* WebRtcSession::GetRemoteMediaContent( |
| 1652 const IceCandidateInterface* candidate) { | 1703 const IceCandidateInterface* candidate) const { |
| 1653 | |
| 1654 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); | 1704 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
| 1655 size_t remote_content_size = remote_desc_->description()->contents().size(); | 1705 size_t remote_content_size = remote_desc_->description()->contents().size(); |
| 1656 if (mediacontent_index >= remote_content_size) { | 1706 if (mediacontent_index >= remote_content_size) { |
| 1657 LOG(LS_ERROR) | 1707 return nullptr; |
| 1658 << "UseRemoteCandidateInSession: Invalid candidate media index."; | 1708 } |
| 1709 return &(remote_desc_->description()->contents()[mediacontent_index]); | |
| 1710 } | |
| 1711 | |
| 1712 bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) { | |
| 1713 const cricket::ContentInfo* content = GetRemoteMediaContent(candidate); | |
| 1714 if (content == nullptr) { | |
| 1715 LOG(LS_ERROR) << "UseCandidate: media content not found"; | |
| 1659 return false; | 1716 return false; |
| 1660 } | 1717 } |
| 1661 | 1718 std::vector<cricket::Candidate> candidates(1, candidate->candidate()); |
| 1662 cricket::ContentInfo content = | |
| 1663 remote_desc_->description()->contents()[mediacontent_index]; | |
| 1664 std::vector<cricket::Candidate> candidates; | |
| 1665 candidates.push_back(candidate->candidate()); | |
| 1666 // Invoking BaseSession method to handle remote candidates. | 1719 // Invoking BaseSession method to handle remote candidates. |
| 1667 std::string error; | 1720 std::string error; |
| 1668 if (transport_controller_->AddRemoteCandidates(content.name, candidates, | 1721 if (transport_controller_->AddRemoteCandidates(content->name, candidates, |
| 1669 &error)) { | 1722 &error)) { |
| 1670 // Candidates successfully submitted for checking. | 1723 // Candidates successfully submitted for checking. |
| 1671 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || | 1724 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
| 1672 ice_connection_state_ == | 1725 ice_connection_state_ == |
| 1673 PeerConnectionInterface::kIceConnectionDisconnected) { | 1726 PeerConnectionInterface::kIceConnectionDisconnected) { |
| 1674 // If state is New, then the session has just gotten its first remote ICE | 1727 // If state is New, then the session has just gotten its first remote ICE |
| 1675 // candidates, so go to Checking. | 1728 // candidates, so go to Checking. |
| 1676 // If state is Disconnected, the session is re-using old candidates or | 1729 // If state is Disconnected, the session is re-using old candidates or |
| 1677 // receiving additional ones, so go to Checking. | 1730 // receiving additional ones, so go to Checking. |
| 1678 // If state is Connected, stay Connected. | 1731 // If state is Connected, stay Connected. |
| 1679 // TODO(bemasc): If state is Connected, and the new candidates are for a | 1732 // TODO(bemasc): If state is Connected, and the new candidates are for a |
| 1680 // newly added transport, then the state actually _should_ move to | 1733 // newly added transport, then the state actually _should_ move to |
| 1681 // checking. Add a way to distinguish that case. | 1734 // checking. Add a way to distinguish that case. |
| 1682 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); | 1735 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
| 1683 } | 1736 } |
| 1684 // TODO(bemasc): If state is Completed, go back to Connected. | 1737 // TODO(bemasc): If state is Completed, go back to Connected. |
| 1685 } else { | 1738 } else { |
| 1686 if (!error.empty()) { | 1739 if (!error.empty()) { |
| 1687 LOG(LS_WARNING) << error; | 1740 LOG(LS_WARNING) << error; |
| 1688 } | 1741 } |
| 1689 } | 1742 } |
| 1690 return true; | 1743 return true; |
| 1691 } | 1744 } |
| 1692 | 1745 |
| 1746 bool WebRtcSession::CeaseRemoteCandidates( | |
|
pthatcher1
2016/03/01 23:51:54
Why is this a separate method from RemoveRemoteCan
honghaiz3
2016/03/02 19:06:40
I tried to make it symmetric to the process of add
pthatcher1
2016/03/02 20:37:58
Then please call it RemoveRemoteCandidatesFromTran
honghaiz3
2016/03/03 01:17:40
Done.
| |
| 1747 const std::vector<IceCandidateInterfaceRefPtr>& ice_candidates) { | |
| 1748 const cricket::ContentInfo* content = nullptr; | |
| 1749 cricket::Candidates candidates; | |
| 1750 for (auto ice_candidate : ice_candidates) { | |
| 1751 const cricket::ContentInfo* new_content = | |
| 1752 GetRemoteMediaContent(ice_candidate); | |
| 1753 if (!new_content) { | |
| 1754 LOG(LS_ERROR) << "CeaseRemoteCandidates: media content not found"; | |
| 1755 return false; | |
| 1756 } | |
| 1757 if (!content) { | |
| 1758 content = new_content; | |
| 1759 } else if (content != new_content) { | |
| 1760 LOG(LS_ERROR) << "CeaseRemoteCandidates: media content is different"; | |
| 1761 return false; | |
| 1762 } | |
| 1763 candidates.push_back(ice_candidate->candidate()); | |
| 1764 } | |
| 1765 std::string error; | |
| 1766 bool res = transport_controller_->RemoveRemoteCandidates(content->name, | |
| 1767 candidates, &error); | |
| 1768 if (!res) { | |
| 1769 LOG(LS_WARNING) << "Error when Removing remote candidate: " << error; | |
| 1770 } | |
| 1771 return res; | |
| 1772 } | |
| 1773 | |
| 1693 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { | 1774 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { |
| 1694 // Destroy video_channel_ first since it may have a pointer to the | 1775 // Destroy video_channel_ first since it may have a pointer to the |
| 1695 // voice_channel_. | 1776 // voice_channel_. |
| 1696 const cricket::ContentInfo* video_info = | 1777 const cricket::ContentInfo* video_info = |
| 1697 cricket::GetFirstVideoContent(desc); | 1778 cricket::GetFirstVideoContent(desc); |
| 1698 if ((!video_info || video_info->rejected) && video_channel_) { | 1779 if ((!video_info || video_info->rejected) && video_channel_) { |
| 1699 SignalVideoChannelDestroyed(); | 1780 SignalVideoChannelDestroyed(); |
| 1700 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 1781 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 1701 } | 1782 } |
| 1702 | 1783 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2143 } | 2224 } |
| 2144 } | 2225 } |
| 2145 | 2226 |
| 2146 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, | 2227 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, |
| 2147 const rtc::SentPacket& sent_packet) { | 2228 const rtc::SentPacket& sent_packet) { |
| 2148 RTC_DCHECK(worker_thread()->IsCurrent()); | 2229 RTC_DCHECK(worker_thread()->IsCurrent()); |
| 2149 media_controller_->call_w()->OnSentPacket(sent_packet); | 2230 media_controller_->call_w()->OnSentPacket(sent_packet); |
| 2150 } | 2231 } |
| 2151 | 2232 |
| 2152 } // namespace webrtc | 2233 } // namespace webrtc |
| OLD | NEW |