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

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

Issue 1648813004: Remove candidates when doing continual gathering (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 10 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
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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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) {
pthatcher1 2016/02/10 00:01:41 I'll need to think about this more to think if thi
honghaiz3 2016/02/10 19:22:43 Looking at the code, I think there are two possibl
pthatcher1 2016/02/11 20:25:51 I think having removals come out of the "added" ev
1198 if (!remote_desc_->RemoveCandidate(candidate)) {
1199 LOG(LS_ERROR) << "ProcessIceMessage: Candidate not found";
1200 }
1201 return StopUsingCandidate(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;
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Use transport_name as the candidate media id.
1646 JsepIceCandidate candidate(transport_name, sdp_mline_index, cand);
1647 // It will be nicer if we can signal multiple candidates in one message.
1648 if (ice_observer_) {
1649 ice_observer_->OnIceCandidate(&candidate);
pthatcher1 2016/02/10 00:01:40 I think having an event of OnIceCandidateRemoved m
honghaiz3 2016/02/10 19:22:43 See my reply above.
1650 }
1651 if (local_desc_) {
1652 local_desc_->RemoveCandidate(&candidate);
1653 }
1654 }
1655 }
1656
1624 // Enabling voice and video channel. 1657 // Enabling voice and video channel.
1625 void WebRtcSession::EnableChannels() { 1658 void WebRtcSession::EnableChannels() {
1626 if (voice_channel_ && !voice_channel_->enabled()) 1659 if (voice_channel_ && !voice_channel_->enabled())
1627 voice_channel_->Enable(true); 1660 voice_channel_->Enable(true);
1628 1661
1629 if (video_channel_ && !video_channel_->enabled()) 1662 if (video_channel_ && !video_channel_->enabled())
1630 video_channel_->Enable(true); 1663 video_channel_->Enable(true);
1631 1664
1632 if (data_channel_ && !data_channel_->enabled()) 1665 if (data_channel_ && !data_channel_->enabled())
1633 data_channel_->Enable(true); 1666 data_channel_->Enable(true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1706 }
1674 ret = UseCandidate(candidate); 1707 ret = UseCandidate(candidate);
1675 if (!ret) { 1708 if (!ret) {
1676 break; 1709 break;
1677 } 1710 }
1678 } 1711 }
1679 } 1712 }
1680 return ret; 1713 return ret;
1681 } 1714 }
1682 1715
1683 bool WebRtcSession::UseCandidate( 1716 const cricket::ContentInfo* WebRtcSession::GetRemoteMediaContent(
1684 const IceCandidateInterface* candidate) { 1717 const IceCandidateInterface* candidate) const {
1685
1686 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index()); 1718 size_t mediacontent_index = static_cast<size_t>(candidate->sdp_mline_index());
1687 size_t remote_content_size = remote_desc_->description()->contents().size(); 1719 size_t remote_content_size = remote_desc_->description()->contents().size();
1688 if (mediacontent_index >= remote_content_size) { 1720 if (mediacontent_index >= remote_content_size) {
1689 LOG(LS_ERROR) 1721 return nullptr;
1690 << "UseRemoteCandidateInSession: Invalid candidate media index."; 1722 }
1723 return &(remote_desc_->description()->contents()[mediacontent_index]);
1724 }
1725
1726 bool WebRtcSession::UseCandidate(const IceCandidateInterface* candidate) {
1727 const cricket::ContentInfo* content = GetRemoteMediaContent(candidate);
1728 if (content == nullptr) {
1729 LOG(LS_ERROR) << "UseCandidate: media content not found";
1691 return false; 1730 return false;
1692 } 1731 }
1693 1732 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. 1733 // Invoking BaseSession method to handle remote candidates.
1699 std::string error; 1734 std::string error;
1700 if (transport_controller_->AddRemoteCandidates(content.name, candidates, 1735 if (transport_controller_->AddRemoteCandidates(content->name, candidates,
1701 &error)) { 1736 &error)) {
1702 // Candidates successfully submitted for checking. 1737 // Candidates successfully submitted for checking.
1703 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew || 1738 if (ice_connection_state_ == PeerConnectionInterface::kIceConnectionNew ||
1704 ice_connection_state_ == 1739 ice_connection_state_ ==
1705 PeerConnectionInterface::kIceConnectionDisconnected) { 1740 PeerConnectionInterface::kIceConnectionDisconnected) {
1706 // If state is New, then the session has just gotten its first remote ICE 1741 // If state is New, then the session has just gotten its first remote ICE
1707 // candidates, so go to Checking. 1742 // candidates, so go to Checking.
1708 // If state is Disconnected, the session is re-using old candidates or 1743 // If state is Disconnected, the session is re-using old candidates or
1709 // receiving additional ones, so go to Checking. 1744 // receiving additional ones, so go to Checking.
1710 // If state is Connected, stay Connected. 1745 // If state is Connected, stay Connected.
1711 // TODO(bemasc): If state is Connected, and the new candidates are for a 1746 // TODO(bemasc): If state is Connected, and the new candidates are for a
1712 // newly added transport, then the state actually _should_ move to 1747 // newly added transport, then the state actually _should_ move to
1713 // checking. Add a way to distinguish that case. 1748 // checking. Add a way to distinguish that case.
1714 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking); 1749 SetIceConnectionState(PeerConnectionInterface::kIceConnectionChecking);
1715 } 1750 }
1716 // TODO(bemasc): If state is Completed, go back to Connected. 1751 // TODO(bemasc): If state is Completed, go back to Connected.
1717 } else { 1752 } else {
1718 if (!error.empty()) { 1753 if (!error.empty()) {
1719 LOG(LS_WARNING) << error; 1754 LOG(LS_WARNING) << error;
1720 } 1755 }
1721 } 1756 }
1722 return true; 1757 return true;
1723 } 1758 }
1724 1759
1760 bool WebRtcSession::StopUsingCandidate(const IceCandidateInterface* candidate) {
1761 const cricket::ContentInfo* content = GetRemoteMediaContent(candidate);
1762 if (!content) {
1763 LOG(LS_ERROR) << "StopUsingCandidate: media content not found";
1764 return false;
1765 }
1766 cricket::Candidates candidates(1, candidate->candidate());
1767 std::string error;
1768 bool res = transport_controller_->RemoveRemoteCandidates(content->name,
1769 candidates, &error);
1770 if (!res) {
1771 LOG(LS_WARNING) << "Error when Removing remote candidate: " << error;
1772 }
1773 return res;
1774 }
1775
1725 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) { 1776 void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) {
1726 // Destroy video_channel_ first since it may have a pointer to the 1777 // Destroy video_channel_ first since it may have a pointer to the
1727 // voice_channel_. 1778 // voice_channel_.
1728 const cricket::ContentInfo* video_info = 1779 const cricket::ContentInfo* video_info =
1729 cricket::GetFirstVideoContent(desc); 1780 cricket::GetFirstVideoContent(desc);
1730 if ((!video_info || video_info->rejected) && video_channel_) { 1781 if ((!video_info || video_info->rejected) && video_channel_) {
1731 SignalVideoChannelDestroyed(); 1782 SignalVideoChannelDestroyed();
1732 channel_manager_->DestroyVideoChannel(video_channel_.release()); 1783 channel_manager_->DestroyVideoChannel(video_channel_.release());
1733 } 1784 }
1734 1785
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 } 2227 }
2177 } 2228 }
2178 2229
2179 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel, 2230 void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel,
2180 const rtc::SentPacket& sent_packet) { 2231 const rtc::SentPacket& sent_packet) {
2181 RTC_DCHECK(worker_thread()->IsCurrent()); 2232 RTC_DCHECK(worker_thread()->IsCurrent());
2182 media_controller_->call_w()->OnSentPacket(sent_packet); 2233 media_controller_->call_w()->OnSentPacket(sent_packet);
2183 } 2234 }
2184 2235
2185 } // namespace webrtc 2236 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698