OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 |
11 #import "RTCPeerConnection+Private.h" | 11 #import "RTCPeerConnection+Private.h" |
12 | 12 |
13 #import "NSString+StdString.h" | 13 #import "NSString+StdString.h" |
14 #import "RTCConfiguration+Private.h" | 14 #import "RTCConfiguration+Private.h" |
15 #import "RTCDataChannel+Private.h" | 15 #import "RTCDataChannel+Private.h" |
16 #import "RTCIceCandidate+Private.h" | 16 #import "RTCIceCandidate+Private.h" |
17 #import "RTCMediaConstraints+Private.h" | 17 #import "RTCMediaConstraints+Private.h" |
18 #import "RTCMediaStream+Private.h" | 18 #import "RTCMediaStream+Private.h" |
19 #import "RTCPeerConnectionFactory+Private.h" | 19 #import "RTCPeerConnectionFactory+Private.h" |
20 #import "RTCRtpReceiver+Private.h" | 20 #import "RTCRtpReceiver+Private.h" |
21 #import "RTCRtpSender+Private.h" | 21 #import "RTCRtpSender+Private.h" |
22 #import "RTCSessionDescription+Private.h" | 22 #import "RTCSessionDescription+Private.h" |
23 #import "RTCStatsReport+Private.h" | 23 #import "RTCStatsReport+Private.h" |
24 #import "WebRTC/RTCLogging.h" | 24 #import "WebRTC/RTCLogging.h" |
25 | 25 |
26 #include <memory> | 26 #include <memory> |
27 | 27 |
| 28 #include "webrtc/api/jsepicecandidate.h" |
28 #include "webrtc/base/checks.h" | 29 #include "webrtc/base/checks.h" |
29 | 30 |
30 NSString * const kRTCPeerConnectionErrorDomain = | 31 NSString * const kRTCPeerConnectionErrorDomain = |
31 @"org.webrtc.RTCPeerConnection"; | 32 @"org.webrtc.RTCPeerConnection"; |
32 int const kRTCPeerConnnectionSessionDescriptionError = -1; | 33 int const kRTCPeerConnnectionSessionDescriptionError = -1; |
33 | 34 |
34 namespace webrtc { | 35 namespace webrtc { |
35 | 36 |
36 class CreateSessionDescriptionObserverAdapter | 37 class CreateSessionDescriptionObserverAdapter |
37 : public CreateSessionDescriptionObserver { | 38 : public CreateSessionDescriptionObserver { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 176 } |
176 | 177 |
177 void PeerConnectionDelegateAdapter::OnIceCandidate( | 178 void PeerConnectionDelegateAdapter::OnIceCandidate( |
178 const IceCandidateInterface *candidate) { | 179 const IceCandidateInterface *candidate) { |
179 RTCIceCandidate *iceCandidate = | 180 RTCIceCandidate *iceCandidate = |
180 [[RTCIceCandidate alloc] initWithNativeCandidate:candidate]; | 181 [[RTCIceCandidate alloc] initWithNativeCandidate:candidate]; |
181 RTCPeerConnection *peer_connection = peer_connection_; | 182 RTCPeerConnection *peer_connection = peer_connection_; |
182 [peer_connection.delegate peerConnection:peer_connection | 183 [peer_connection.delegate peerConnection:peer_connection |
183 didGenerateIceCandidate:iceCandidate]; | 184 didGenerateIceCandidate:iceCandidate]; |
184 } | 185 } |
| 186 |
| 187 void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( |
| 188 const std::vector<cricket::Candidate>& candidates) { |
| 189 NSMutableArray* ice_candidates = |
| 190 [NSMutableArray arrayWithCapacity:candidates.size()]; |
| 191 for (const auto& candidate : candidates) { |
| 192 std::unique_ptr<JsepIceCandidate> candidate_wrapper( |
| 193 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
| 194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] |
| 195 initWithNativeCandidate:candidate_wrapper.get()]; |
| 196 [ice_candidates addObject:ice_candidate]; |
| 197 } |
| 198 RTCPeerConnection* peer_connection = peer_connection_; |
| 199 [peer_connection.delegate peerConnection:peer_connection |
| 200 didRemoveIceCandidates:ice_candidates]; |
| 201 } |
| 202 |
185 } // namespace webrtc | 203 } // namespace webrtc |
186 | 204 |
187 | 205 |
188 @implementation RTCPeerConnection { | 206 @implementation RTCPeerConnection { |
189 NSMutableArray *_localStreams; | 207 NSMutableArray *_localStreams; |
190 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; | 208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
191 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; | 209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
192 } | 210 } |
193 | 211 |
194 @synthesize delegate = _delegate; | 212 @synthesize delegate = _delegate; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 - (void)close { | 284 - (void)close { |
267 _peerConnection->Close(); | 285 _peerConnection->Close(); |
268 } | 286 } |
269 | 287 |
270 - (void)addIceCandidate:(RTCIceCandidate *)candidate { | 288 - (void)addIceCandidate:(RTCIceCandidate *)candidate { |
271 std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( | 289 std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( |
272 candidate.nativeCandidate); | 290 candidate.nativeCandidate); |
273 _peerConnection->AddIceCandidate(iceCandidate.get()); | 291 _peerConnection->AddIceCandidate(iceCandidate.get()); |
274 } | 292 } |
275 | 293 |
| 294 - (void)removeIceCandidates:(NSArray<RTCIceCandidate *> *)iceCandidates { |
| 295 std::vector<cricket::Candidate> candidates; |
| 296 for (RTCIceCandidate *iceCandidate in iceCandidates) { |
| 297 std::unique_ptr<const webrtc::IceCandidateInterface> candidate( |
| 298 iceCandidate.nativeCandidate); |
| 299 if (candidate) { |
| 300 candidates.push_back(candidate->candidate()); |
| 301 // Need to fill the transport name from the sdp_mid. |
| 302 candidates.back().set_transport_name(candidate->sdp_mid()); |
| 303 } |
| 304 } |
| 305 if (!candidates.empty()) { |
| 306 _peerConnection->RemoveIceCandidates(candidates); |
| 307 } |
| 308 } |
| 309 |
276 - (void)addStream:(RTCMediaStream *)stream { | 310 - (void)addStream:(RTCMediaStream *)stream { |
277 if (!_peerConnection->AddStream(stream.nativeMediaStream)) { | 311 if (!_peerConnection->AddStream(stream.nativeMediaStream)) { |
278 RTCLogError(@"Failed to add stream: %@", stream); | 312 RTCLogError(@"Failed to add stream: %@", stream); |
279 return; | 313 return; |
280 } | 314 } |
281 [_localStreams addObject:stream]; | 315 [_localStreams addObject:stream]; |
282 } | 316 } |
283 | 317 |
284 - (void)removeStream:(RTCMediaStream *)stream { | 318 - (void)removeStream:(RTCMediaStream *)stream { |
285 _peerConnection->RemoveStream(stream.nativeMediaStream); | 319 _peerConnection->RemoveStream(stream.nativeMediaStream); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 case RTCStatsOutputLevelDebug: | 554 case RTCStatsOutputLevelDebug: |
521 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; | 555 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
522 } | 556 } |
523 } | 557 } |
524 | 558 |
525 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { | 559 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
526 return _peerConnection; | 560 return _peerConnection; |
527 } | 561 } |
528 | 562 |
529 @end | 563 @end |
OLD | NEW |