Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 metrics_observer_(NULL) { | 564 metrics_observer_(NULL) { |
| 565 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 565 transport_controller_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 566 transport_controller_->SignalConnectionState.connect( | 566 transport_controller_->SignalConnectionState.connect( |
| 567 this, &WebRtcSession::OnTransportControllerConnectionState); | 567 this, &WebRtcSession::OnTransportControllerConnectionState); |
| 568 transport_controller_->SignalReceiving.connect( | 568 transport_controller_->SignalReceiving.connect( |
| 569 this, &WebRtcSession::OnTransportControllerReceiving); | 569 this, &WebRtcSession::OnTransportControllerReceiving); |
| 570 transport_controller_->SignalGatheringState.connect( | 570 transport_controller_->SignalGatheringState.connect( |
| 571 this, &WebRtcSession::OnTransportControllerGatheringState); | 571 this, &WebRtcSession::OnTransportControllerGatheringState); |
| 572 transport_controller_->SignalCandidatesGathered.connect( | 572 transport_controller_->SignalCandidatesGathered.connect( |
| 573 this, &WebRtcSession::OnTransportControllerCandidatesGathered); | 573 this, &WebRtcSession::OnTransportControllerCandidatesGathered); |
| 574 transport_controller_->SignalCandidatesRemoved.connect( | |
| 575 this, &WebRtcSession::OnTransportControllerCandidatesRemoved); | |
| 574 } | 576 } |
| 575 | 577 |
| 576 WebRtcSession::~WebRtcSession() { | 578 WebRtcSession::~WebRtcSession() { |
| 577 ASSERT(signaling_thread()->IsCurrent()); | 579 ASSERT(signaling_thread()->IsCurrent()); |
| 578 // Destroy video_channel_ first since it may have a pointer to the | 580 // Destroy video_channel_ first since it may have a pointer to the |
| 579 // voice_channel_. | 581 // voice_channel_. |
| 580 if (video_channel_) { | 582 if (video_channel_) { |
| 581 SignalVideoChannelDestroyed(); | 583 SignalVideoChannelDestroyed(); |
| 582 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 584 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 583 } | 585 } |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 !maybe_set_transport(video_channel()) || | 1177 !maybe_set_transport(video_channel()) || |
| 1176 !maybe_set_transport(data_channel())) { | 1178 !maybe_set_transport(data_channel())) { |
| 1177 return false; | 1179 return false; |
| 1178 } | 1180 } |
| 1179 | 1181 |
| 1180 return true; | 1182 return true; |
| 1181 } | 1183 } |
| 1182 | 1184 |
| 1183 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { | 1185 bool WebRtcSession::ProcessIceMessage(const IceCandidateInterface* candidate) { |
| 1184 if (!remote_desc_) { | 1186 if (!remote_desc_) { |
| 1185 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be added " | 1187 LOG(LS_ERROR) << "ProcessIceMessage: ICE candidates can't be processed " |
| 1186 << "without any remote session description."; | 1188 << "without any remote session description."; |
| 1187 return false; | 1189 return false; |
| 1188 } | 1190 } |
| 1189 | 1191 |
| 1190 if (!candidate) { | 1192 if (!candidate) { |
| 1191 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; | 1193 LOG(LS_ERROR) << "ProcessIceMessage: Candidate is NULL."; |
| 1192 return false; | 1194 return false; |
| 1193 } | 1195 } |
| 1194 | 1196 |
| 1197 if (candidate->candidate().priority() == 0) { | |
|
Taylor Brandstetter
2016/02/10 21:58:08
Using a priority of 0 doesn't seem like an ideal l
pthatcher1
2016/02/11 20:25:51
I agree.
| |
| 1198 if (!remote_desc_->RemoveCandidate(candidate)) { | |
| 1199 LOG(LS_ERROR) << "ProcessIceMessage: Candidate not found"; | |
| 1200 } | |
| 1201 return RemoveRemoteCandidate(candidate); | |
| 1202 } | |
| 1203 | |
| 1195 bool valid = false; | 1204 bool valid = false; |
| 1196 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); | 1205 bool ready = ReadyToUseRemoteCandidate(candidate, NULL, &valid); |
| 1197 if (!valid) { | 1206 if (!valid) { |
| 1198 return false; | 1207 return false; |
| 1199 } | 1208 } |
| 1200 | 1209 |
| 1201 // Add this candidate to the remote session description. | 1210 // Add this candidate to the remote session description. |
| 1202 if (!remote_desc_->AddCandidate(candidate)) { | 1211 if (!remote_desc_->AddCandidate(candidate)) { |
| 1203 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; | 1212 LOG(LS_ERROR) << "ProcessIceMessage: Candidate cannot be used."; |
| 1204 return false; | 1213 return false; |
| 1205 } | 1214 } |
| 1206 | 1215 |
| 1207 if (ready) { | 1216 if (ready) { |
| 1208 return UseCandidate(candidate); | 1217 return AddRemoteCandidate(candidate); |
| 1209 } else { | 1218 } else { |
| 1210 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; | 1219 LOG(LS_INFO) << "ProcessIceMessage: Not ready to use candidate."; |
| 1211 return true; | 1220 return true; |
| 1212 } | 1221 } |
| 1213 } | 1222 } |
| 1214 | 1223 |
| 1215 bool WebRtcSession::SetIceTransports( | 1224 bool WebRtcSession::SetIceTransports( |
| 1216 PeerConnectionInterface::IceTransportsType type) { | 1225 PeerConnectionInterface::IceTransportsType type) { |
| 1217 return port_allocator()->set_candidate_filter( | 1226 return port_allocator()->set_candidate_filter( |
| 1218 ConvertIceTransportTypeToCandidateFilter(type)); | 1227 ConvertIceTransportTypeToCandidateFilter(type)); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1614 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); | 1623 JsepIceCandidate candidate(transport_name, sdp_mline_index, *citer); |
| 1615 if (ice_observer_) { | 1624 if (ice_observer_) { |
| 1616 ice_observer_->OnIceCandidate(&candidate); | 1625 ice_observer_->OnIceCandidate(&candidate); |
| 1617 } | 1626 } |
| 1618 if (local_desc_) { | 1627 if (local_desc_) { |
| 1619 local_desc_->AddCandidate(&candidate); | 1628 local_desc_->AddCandidate(&candidate); |
| 1620 } | 1629 } |
| 1621 } | 1630 } |
| 1622 } | 1631 } |
| 1623 | 1632 |
| 1633 void WebRtcSession::OnTransportControllerCandidatesRemoved( | |
| 1634 const std::string& transport_name, | |
| 1635 const cricket::Candidates& candidates) { | |
| 1636 ASSERT(signaling_thread()->IsCurrent()); | |
| 1637 int sdp_mline_index; | |
| 1638 if (!GetLocalCandidateMediaIndex(transport_name, &sdp_mline_index)) { | |
| 1639 LOG(LS_ERROR) << "OnTransportControllerCandidatesRemoved: content name " | |
| 1640 << transport_name << " not found"; | |
| 1641 return; | |
| 1642 } | |
| 1643 | |
| 1644 for (const cricket::Candidate& cand : candidates) { | |
| 1645 ASSERT(cand.priority() == 0); | |
| 1646 // Use transport_name as the candidate media id. | |
| 1647 JsepIceCandidate candidate(transport_name, sdp_mline_index, cand); | |
| 1648 // It will be nicer if we can signal multiple candidates in one message. | |
| 1649 if (ice_observer_) { | |
| 1650 ice_observer_->OnIceCandidate(&candidate); | |
| 1651 } | |
| 1652 if (local_desc_) { | |
| 1653 local_desc_->RemoveCandidate(&candidate); | |
| 1654 } | |
| 1655 } | |
| 1656 } | |
| 1657 | |
| 1624 // Enabling voice and video channel. | 1658 // Enabling voice and video channel. |
| 1625 void WebRtcSession::EnableChannels() { | 1659 void WebRtcSession::EnableChannels() { |
| 1626 if (voice_channel_ && !voice_channel_->enabled()) | 1660 if (voice_channel_ && !voice_channel_->enabled()) |
| 1627 voice_channel_->Enable(true); | 1661 voice_channel_->Enable(true); |
| 1628 | 1662 |
| 1629 if (video_channel_ && !video_channel_->enabled()) | 1663 if (video_channel_ && !video_channel_->enabled()) |
| 1630 video_channel_->Enable(true); | 1664 video_channel_->Enable(true); |
| 1631 | 1665 |
| 1632 if (data_channel_ && !data_channel_->enabled()) | 1666 if (data_channel_ && !data_channel_->enabled()) |
| 1633 data_channel_->Enable(true); | 1667 data_channel_->Enable(true); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1664 for (size_t n = 0; n < candidates->count(); ++n) { | 1698 for (size_t n = 0; n < candidates->count(); ++n) { |
| 1665 const IceCandidateInterface* candidate = candidates->at(n); | 1699 const IceCandidateInterface* candidate = candidates->at(n); |
| 1666 bool valid = false; | 1700 bool valid = false; |
| 1667 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) { | 1701 if (!ReadyToUseRemoteCandidate(candidate, remote_desc, &valid)) { |
| 1668 if (valid) { | 1702 if (valid) { |
| 1669 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Not ready to use " | 1703 LOG(LS_INFO) << "UseCandidatesInSessionDescription: Not ready to use " |
| 1670 << "candidate."; | 1704 << "candidate."; |
| 1671 } | 1705 } |
| 1672 continue; | 1706 continue; |
| 1673 } | 1707 } |
| 1674 ret = UseCandidate(candidate); | 1708 ret = AddRemoteCandidate(candidate); |
| 1675 if (!ret) { | 1709 if (!ret) { |
| 1676 break; | 1710 break; |
| 1677 } | 1711 } |
| 1678 } | 1712 } |
| 1679 } | 1713 } |
| 1680 return ret; | 1714 return ret; |
| 1681 } | 1715 } |
| 1682 | 1716 |
| 1683 bool WebRtcSession::UseCandidate( | 1717 const cricket::ContentInfo* WebRtcSession::GetRemoteMediaContent( |
|
Taylor Brandstetter
2016/02/10 21:58:08
As long as you're making this a standalone method,
honghaiz3
2016/02/12 00:56:55
How do you know if sdp_mline_index is set or not?
Taylor Brandstetter
2016/02/12 02:30:38
Extremely unfortunately, the default value appears
| |
| 1684 const IceCandidateInterface* candidate) { | 1718 const IceCandidateInterface* candidate) const { |
| 1685 | |
| 1686 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); | 1719 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); |
| 1687 size_t remote_content_size = remote_desc_->description()->contents().size(); | 1720 size_t remote_content_size = remote_desc_->description()->contents().size(); |
| 1688 if (mediacontent_index >= remote_content_size) { | 1721 if (mediacontent_index >= remote_content_size) { |
| 1689 LOG(LS_ERROR) | 1722 return nullptr; |
| 1690 << "UseRemoteCandidateInSession: Invalid candidate media index."; | 1723 } |
| 1724 return &(remote_desc_->description()->contents()[mediacontent_index]); | |
| 1725 } | |
| 1726 | |
| 1727 bool WebRtcSession::AddRemoteCandidate(const IceCandidateInterface* candidate) { | |
| 1728 const cricket::ContentInfo* content = GetRemoteMediaContent(candidate); | |
| 1729 if (content == nullptr) { | |
| 1730 LOG(LS_ERROR) << "AddRemoteCandidate: media content not found"; | |
| 1691 return false; | 1731 return false; |
| 1692 } | 1732 } |
| 1693 | 1733 std::vector<cricket::Candidate> candidates(1, candidate->candidate()); |
| 1694 cricket::ContentInfo content = | |
| 1695 remote_desc_->description()->contents()[mediacontent_index]; | |
| 1696 std::vector<cricket::Candidate> candidates; | |
| 1697 candidates.push_back(candidate->candidate()); | |
| 1698 // Invoking BaseSession method to handle remote candidates. | 1734 // Invoking BaseSession method to handle remote candidates. |
| 1699 std::string error; | 1735 std::string error; |
| 1700 if (transport_controller_->AddRemoteCandidates(content.name, candidates, | 1736 if (transport_controller_->AddRemoteCandidates(content->name, candidates, |
| 1701 &error)) { | 1737 &error)) { |
| 1702 // Candidates successfully submitted for checking. | 1738 // Candidates successfully submitted for checking. |
| 1703 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || | 1739 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || |
| 1704 ice_connection_state_ == | 1740 ice_connection_state_ == |
| 1705 PeerConnectionInterface::kIceConnectionDisconnected) { | 1741 PeerConnectionInterface::kIceConnectionDisconnected) { |
| 1706 // If state is New, then the session has just gotten its first remote ICE | 1742 // If state is New, then the session has just gotten its first remote ICE |
| 1707 // candidates, so go to Checking. | 1743 // candidates, so go to Checking. |
| 1708 // If state is Disconnected, the session is re-using old candidates or | 1744 // If state is Disconnected, the session is re-using old candidates or |
| 1709 // receiving additional ones, so go to Checking. | 1745 // receiving additional ones, so go to Checking. |
| 1710 // If state is Connected, stay Connected. | 1746 // If state is Connected, stay Connected. |
| 1711 // TODO(bemasc): If state is Connected, and the new candidates are for a | 1747 // TODO(bemasc): If state is Connected, and the new candidates are for a |
| 1712 // newly added transport, then the state actually _should_ move to | 1748 // newly added transport, then the state actually _should_ move to |
| 1713 // checking. Add a way to distinguish that case. | 1749 // checking. Add a way to distinguish that case. |
| 1714 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); | 1750 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); |
| 1715 } | 1751 } |
| 1716 // TODO(bemasc): If state is Completed, go back to Connected. | 1752 // TODO(bemasc): If state is Completed, go back to Connected. |
| 1717 } else { | 1753 } else { |
| 1718 if (!error.empty()) { | 1754 if (!error.empty()) { |
| 1719 LOG(LS_WARNING) << error; | 1755 LOG(LS_WARNING) << error; |
| 1720 } | 1756 } |
| 1721 } | 1757 } |
| 1722 return true; | 1758 return true; |
| 1723 } | 1759 } |
| 1724 | 1760 |
| 1761 bool WebRtcSession::RemoveRemoteCandidate( | |
| 1762 const IceCandidateInterface* candidate) { | |
| 1763 const cricket::ContentInfo* content = GetRemoteMediaContent(candidate); | |
| 1764 if (!content) { | |
| 1765 LOG(LS_ERROR) << "RemoveRemoteCandidate: media content not found"; | |
| 1766 return false; | |
| 1767 } | |
| 1768 cricket::Candidates candidates(1, candidate->candidate()); | |
| 1769 std::string error; | |
| 1770 bool res = transport_controller_->RemoveRemoteCandidates(content->name, | |
| 1771 candidates, &error); | |
| 1772 if (!res) { | |
| 1773 LOG(LS_WARNING) << "Error when Removing remote candidate: " << error; | |
| 1774 } | |
| 1775 return res; | |
| 1776 } | |
| 1777 | |
| 1725 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { | 1778 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { |
| 1726 // Destroy video_channel_ first since it may have a pointer to the | 1779 // Destroy video_channel_ first since it may have a pointer to the |
| 1727 // voice_channel_. | 1780 // voice_channel_. |
| 1728 const cricket::ContentInfo* video_info = | 1781 const cricket::ContentInfo* video_info = |
| 1729 cricket::GetFirstVideoContent(desc); | 1782 cricket::GetFirstVideoContent(desc); |
| 1730 if ((!video_info || video_info->rejected) && video_channel_) { | 1783 if ((!video_info || video_info->rejected) && video_channel_) { |
| 1731 SignalVideoChannelDestroyed(); | 1784 SignalVideoChannelDestroyed(); |
| 1732 channel_manager_->DestroyVideoChannel(video_channel_.release()); | 1785 channel_manager_->DestroyVideoChannel(video_channel_.release()); |
| 1733 } | 1786 } |
| 1734 | 1787 |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2176 } | 2229 } |
| 2177 } | 2230 } |
| 2178 | 2231 |
| 2179 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, | 2232 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, |
| 2180 const rtc::SentPacket& sent_packet) { | 2233 const rtc::SentPacket& sent_packet) { |
| 2181 RTC_DCHECK(worker_thread()->IsCurrent()); | 2234 RTC_DCHECK(worker_thread()->IsCurrent()); |
| 2182 media_controller_->call_w()->OnSentPacket(sent_packet); | 2235 media_controller_->call_w()->OnSentPacket(sent_packet); |
| 2183 } | 2236 } |
| 2184 | 2237 |
| 2185 } // namespace webrtc | 2238 } // namespace webrtc |
| OLD | NEW |