| 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 "RTCLegacyStatsReport+Private.h" | 17 #import "RTCLegacyStatsReport+Private.h" |
| 18 #import "RTCMediaConstraints+Private.h" | 18 #import "RTCMediaConstraints+Private.h" |
| 19 #import "RTCMediaStream+Private.h" | 19 #import "RTCMediaStream+Private.h" |
| 20 #import "RTCPeerConnectionFactory+Private.h" | 20 #import "RTCPeerConnectionFactory+Private.h" |
| 21 #import "RTCRtpReceiver+Private.h" | 21 #import "RTCRtpReceiver+Private.h" |
| 22 #import "RTCRtpSender+Private.h" | 22 #import "RTCRtpSender+Private.h" |
| 23 #import "RTCSessionDescription+Private.h" | 23 #import "RTCSessionDescription+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/api/jsepicecandidate.h" |
| 29 #include "webrtc/base/checks.h" | 29 #include "webrtc/base/checks.h" |
| 30 #include "webrtc/sdk/objc/Framework/Classes/helpers.h" | |
| 31 | 30 |
| 32 NSString * const kRTCPeerConnectionErrorDomain = | 31 NSString * const kRTCPeerConnectionErrorDomain = |
| 33 @"org.webrtc.RTCPeerConnection"; | 32 @"org.webrtc.RTCPeerConnection"; |
| 34 int const kRTCPeerConnnectionSessionDescriptionError = -1; | 33 int const kRTCPeerConnnectionSessionDescriptionError = -1; |
| 35 | 34 |
| 36 namespace webrtc { | 35 namespace webrtc { |
| 37 | 36 |
| 38 class CreateSessionDescriptionObserverAdapter | 37 class CreateSessionDescriptionObserverAdapter |
| 39 : public CreateSessionDescriptionObserver { | 38 : public CreateSessionDescriptionObserver { |
| 40 public: | 39 public: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 PeerConnectionInterface::SignalingState new_state) { | 120 PeerConnectionInterface::SignalingState new_state) { |
| 122 RTCSignalingState state = | 121 RTCSignalingState state = |
| 123 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; | 122 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; |
| 124 RTCPeerConnection *peer_connection = peer_connection_; | 123 RTCPeerConnection *peer_connection = peer_connection_; |
| 125 [peer_connection.delegate peerConnection:peer_connection | 124 [peer_connection.delegate peerConnection:peer_connection |
| 126 didChangeSignalingState:state]; | 125 didChangeSignalingState:state]; |
| 127 } | 126 } |
| 128 | 127 |
| 129 void PeerConnectionDelegateAdapter::OnAddStream( | 128 void PeerConnectionDelegateAdapter::OnAddStream( |
| 130 rtc::scoped_refptr<MediaStreamInterface> stream) { | 129 rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 130 RTCMediaStream *mediaStream = |
| 131 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; |
| 131 RTCPeerConnection *peer_connection = peer_connection_; | 132 RTCPeerConnection *peer_connection = peer_connection_; |
| 132 RTCMediaStream *mediaStream = [peer_connection mediaStreamForNativeStream:stre
am]; | |
| 133 [peer_connection.delegate peerConnection:peer_connection | 133 [peer_connection.delegate peerConnection:peer_connection |
| 134 didAddStream:mediaStream]; | 134 didAddStream:mediaStream]; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void PeerConnectionDelegateAdapter::OnRemoveStream( | 137 void PeerConnectionDelegateAdapter::OnRemoveStream( |
| 138 rtc::scoped_refptr<MediaStreamInterface> stream) { | 138 rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 139 RTCMediaStream *mediaStream = | 139 RTCMediaStream *mediaStream = |
| 140 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; | 140 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; |
| 141 RTCPeerConnection *peer_connection = peer_connection_; | 141 RTCPeerConnection *peer_connection = peer_connection_; |
| 142 [peer_connection.delegate peerConnection:peer_connection | 142 [peer_connection.delegate peerConnection:peer_connection |
| 143 didRemoveStream:mediaStream]; | 143 didRemoveStream:mediaStream]; |
| 144 [peer_connection removeNativeMediaStream:stream]; | |
| 145 } | 144 } |
| 146 | 145 |
| 147 void PeerConnectionDelegateAdapter::OnDataChannel( | 146 void PeerConnectionDelegateAdapter::OnDataChannel( |
| 148 rtc::scoped_refptr<DataChannelInterface> data_channel) { | 147 rtc::scoped_refptr<DataChannelInterface> data_channel) { |
| 149 RTCDataChannel *dataChannel = | 148 RTCDataChannel *dataChannel = |
| 150 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; | 149 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; |
| 151 RTCPeerConnection *peer_connection = peer_connection_; | 150 RTCPeerConnection *peer_connection = peer_connection_; |
| 152 [peer_connection.delegate peerConnection:peer_connection | 151 [peer_connection.delegate peerConnection:peer_connection |
| 153 didOpenDataChannel:dataChannel]; | 152 didOpenDataChannel:dataChannel]; |
| 154 } | 153 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); | 193 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
| 195 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] | 194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] |
| 196 initWithNativeCandidate:candidate_wrapper.get()]; | 195 initWithNativeCandidate:candidate_wrapper.get()]; |
| 197 [ice_candidates addObject:ice_candidate]; | 196 [ice_candidates addObject:ice_candidate]; |
| 198 } | 197 } |
| 199 RTCPeerConnection* peer_connection = peer_connection_; | 198 RTCPeerConnection* peer_connection = peer_connection_; |
| 200 [peer_connection.delegate peerConnection:peer_connection | 199 [peer_connection.delegate peerConnection:peer_connection |
| 201 didRemoveIceCandidates:ice_candidates]; | 200 didRemoveIceCandidates:ice_candidates]; |
| 202 } | 201 } |
| 203 | 202 |
| 204 void PeerConnectionDelegateAdapter::OnAddTrack( | |
| 205 rtc::scoped_refptr<RtpReceiverInterface> receiver, | |
| 206 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) { | |
| 207 RTCRtpReceiver* rtpReceiver = | |
| 208 [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:receiver]; | |
| 209 NSMutableArray* mediaStreams = | |
| 210 [NSMutableArray arrayWithCapacity:streams.size()]; | |
| 211 | |
| 212 RTCPeerConnection* peer_connection = peer_connection_; | |
| 213 for (const auto stream : streams) { | |
| 214 RTCMediaStream* mediaStream = | |
| 215 [peer_connection mediaStreamForNativeStream:stream]; | |
| 216 [mediaStreams addObject:mediaStream]; | |
| 217 } | |
| 218 if ([peer_connection.delegate | |
| 219 respondsToSelector:@selector(peerConnection:didAddTrack:streams:)]) { | |
| 220 [peer_connection.delegate peerConnection:peer_connection | |
| 221 didAddTrack:rtpReceiver | |
| 222 streams:mediaStreams]; | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 } // namespace webrtc | 203 } // namespace webrtc |
| 227 | 204 |
| 228 | 205 |
| 229 @implementation RTCPeerConnection { | 206 @implementation RTCPeerConnection { |
| 230 NSMutableArray<RTCMediaStream *> *_localStreams; | 207 NSMutableArray<RTCMediaStream *> *_localStreams; |
| 231 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; | 208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
| 232 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; | 209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
| 233 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; | 210 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; |
| 234 BOOL _hasStartedRtcEventLog; | 211 BOOL _hasStartedRtcEventLog; |
| 235 NSMutableDictionary<NSString *, RTCMediaStream *> *_mediaStreamsByStreamId; | |
| 236 } | 212 } |
| 237 | 213 |
| 238 @synthesize delegate = _delegate; | 214 @synthesize delegate = _delegate; |
| 239 | 215 |
| 240 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory | 216 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 241 configuration:(RTCConfiguration *)configuration | 217 configuration:(RTCConfiguration *)configuration |
| 242 constraints:(RTCMediaConstraints *)constraints | 218 constraints:(RTCMediaConstraints *)constraints |
| 243 delegate:(id<RTCPeerConnectionDelegate>)delegate { | 219 delegate:(id<RTCPeerConnectionDelegate>)delegate { |
| 244 NSParameterAssert(factory); | 220 NSParameterAssert(factory); |
| 245 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( | 221 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
| 246 [configuration createNativeConfiguration]); | 222 [configuration createNativeConfiguration]); |
| 247 if (!config) { | 223 if (!config) { |
| 248 return nil; | 224 return nil; |
| 249 } | 225 } |
| 250 if (self = [super init]) { | 226 if (self = [super init]) { |
| 251 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); | 227 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
| 252 _nativeConstraints = constraints.nativeConstraints; | 228 _nativeConstraints = constraints.nativeConstraints; |
| 253 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), | 229 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), |
| 254 config.get()); | 230 config.get()); |
| 255 _peerConnection = | 231 _peerConnection = |
| 256 factory.nativeFactory->CreatePeerConnection(*config, | 232 factory.nativeFactory->CreatePeerConnection(*config, |
| 257 nullptr, | 233 nullptr, |
| 258 nullptr, | 234 nullptr, |
| 259 _observer.get()); | 235 _observer.get()); |
| 260 if (!_peerConnection) { | 236 if (!_peerConnection) { |
| 261 return nil; | 237 return nil; |
| 262 } | 238 } |
| 263 _localStreams = [[NSMutableArray alloc] init]; | 239 _localStreams = [[NSMutableArray alloc] init]; |
| 264 _delegate = delegate; | 240 _delegate = delegate; |
| 265 _mediaStreamsByStreamId = [NSMutableDictionary dictionary]; | |
| 266 } | 241 } |
| 267 return self; | 242 return self; |
| 268 } | 243 } |
| 269 | 244 |
| 270 - (NSArray<RTCMediaStream *> *)localStreams { | 245 - (NSArray<RTCMediaStream *> *)localStreams { |
| 271 return [_localStreams copy]; | 246 return [_localStreams copy]; |
| 272 } | 247 } |
| 273 | 248 |
| 274 - (RTCSessionDescription *)localDescription { | 249 - (RTCSessionDescription *)localDescription { |
| 275 const webrtc::SessionDescriptionInterface *description = | 250 const webrtc::SessionDescriptionInterface *description = |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 + (webrtc::PeerConnectionInterface::StatsOutputLevel) | 581 + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
| 607 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { | 582 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
| 608 switch (level) { | 583 switch (level) { |
| 609 case RTCStatsOutputLevelStandard: | 584 case RTCStatsOutputLevelStandard: |
| 610 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; | 585 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
| 611 case RTCStatsOutputLevelDebug: | 586 case RTCStatsOutputLevelDebug: |
| 612 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; | 587 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
| 613 } | 588 } |
| 614 } | 589 } |
| 615 | 590 |
| 616 - (RTCMediaStream *)mediaStreamForNativeStream: | |
| 617 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)stream { | |
| 618 RTCMediaStream *mediaStream = | |
| 619 _mediaStreamsByStreamId[[NSString stringForStdString:stream->label()]]; | |
| 620 if (!mediaStream) { | |
| 621 mediaStream = [[RTCMediaStream alloc] initWithNativeMediaStream:stream.get()
]; | |
| 622 _mediaStreamsByStreamId[[NSString stringForStdString:stream->label()]] = med
iaStream; | |
| 623 } | |
| 624 return mediaStream; | |
| 625 } | |
| 626 | |
| 627 - (void)removeNativeMediaStream:(rtc::scoped_refptr<webrtc::MediaStreamInterface
>)stream { | |
| 628 [_mediaStreamsByStreamId removeObjectForKey:[NSString stringForStdString:strea
m->label()]]; | |
| 629 } | |
| 630 | |
| 631 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { | 591 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
| 632 return _peerConnection; | 592 return _peerConnection; |
| 633 } | 593 } |
| 634 | 594 |
| 635 @end | 595 @end |
| OLD | NEW |