Pass around the candidate removals events in IOS clients

When local candidates are removed, signal to RTCPeerConnection
and eventually send to the remote client.
When a candidate-removal message is received, notify the native PeerConnection.

BUG=
R=tkchin@webrtc.org

Review URL: https://codereview.webrtc.org/1972483002 .

Cr-Commit-Position: refs/heads/master@{#12852}
This commit is contained in:
Honghai Zhang
2016-05-23 11:53:14 -07:00
parent 3ebb3efd13
commit da2ba4dcba
9 changed files with 153 additions and 1 deletions

View File

@ -45,6 +45,9 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
void OnIceCandidate(const IceCandidateInterface *candidate) override;
void OnIceCandidatesRemoved(
const std::vector<cricket::Candidate>& candidates) override;
private:
__weak RTCPeerConnection *peer_connection_;
};

View File

@ -25,6 +25,7 @@
#include <memory>
#include "webrtc/api/jsepicecandidate.h"
#include "webrtc/base/checks.h"
NSString * const kRTCPeerConnectionErrorDomain =
@ -182,6 +183,23 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
[peer_connection.delegate peerConnection:peer_connection
didGenerateIceCandidate:iceCandidate];
}
void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved(
const std::vector<cricket::Candidate>& candidates) {
NSMutableArray* ice_candidates =
[NSMutableArray arrayWithCapacity:candidates.size()];
for (const auto& candidate : candidates) {
std::unique_ptr<JsepIceCandidate> candidate_wrapper(
new JsepIceCandidate(candidate.transport_name(), -1, candidate));
RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc]
initWithNativeCandidate:candidate_wrapper.get()];
[ice_candidates addObject:ice_candidate];
}
RTCPeerConnection* peer_connection = peer_connection_;
[peer_connection.delegate peerConnection:peer_connection
didRemoveIceCandidates:ice_candidates];
}
} // namespace webrtc
@ -273,6 +291,22 @@ void PeerConnectionDelegateAdapter::OnIceCandidate(
_peerConnection->AddIceCandidate(iceCandidate.get());
}
- (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)iceCandidates {
std::vector<cricket::Candidate> candidates;
for (RTCIceCandidate *iceCandidate in iceCandidates) {
std::unique_ptr<const webrtc::IceCandidateInterface> candidate(
iceCandidate.nativeCandidate);
if (candidate) {
candidates.push_back(candidate->candidate());
// Need to fill the transport name from the sdp_mid.
candidates.back().set_transport_name(candidate->sdp_mid());
}
}
if (!candidates.empty()) {
_peerConnection->RemoveIceCandidates(candidates);
}
}
- (void)addStream:(RTCMediaStream *)stream {
if (!_peerConnection->AddStream(stream.nativeMediaStream)) {
RTCLogError(@"Failed to add stream: %@", stream);