Chromium Code Reviews| 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 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 PeerConnectionInterface::SignalingState new_state) { | 120 PeerConnectionInterface::SignalingState new_state) { |
| 121 RTCSignalingState state = | 121 RTCSignalingState state = |
| 122 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; | 122 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; |
| 123 RTCPeerConnection *peer_connection = peer_connection_; | 123 RTCPeerConnection *peer_connection = peer_connection_; |
| 124 [peer_connection.delegate peerConnection:peer_connection | 124 [peer_connection.delegate peerConnection:peer_connection |
| 125 didChangeSignalingState:state]; | 125 didChangeSignalingState:state]; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void PeerConnectionDelegateAdapter::OnAddStream( | 128 void PeerConnectionDelegateAdapter::OnAddStream( |
| 129 rtc::scoped_refptr<MediaStreamInterface> stream) { | 129 rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 130 RTCMediaStream *mediaStream = | |
| 131 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; | |
| 132 RTCPeerConnection *peer_connection = peer_connection_; | 130 RTCPeerConnection *peer_connection = peer_connection_; |
| 131 RTCMediaStream *mediaStream = [peer_connection GetOrCreateObjcStream:stream]; | |
| 133 [peer_connection.delegate peerConnection:peer_connection | 132 [peer_connection.delegate peerConnection:peer_connection |
| 134 didAddStream:mediaStream]; | 133 didAddStream:mediaStream]; |
| 135 } | 134 } |
| 136 | 135 |
| 137 void PeerConnectionDelegateAdapter::OnRemoveStream( | 136 void PeerConnectionDelegateAdapter::OnRemoveStream( |
| 138 rtc::scoped_refptr<MediaStreamInterface> stream) { | 137 rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 139 RTCMediaStream *mediaStream = | 138 RTCMediaStream *mediaStream = |
| 140 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; | 139 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; |
| 141 RTCPeerConnection *peer_connection = peer_connection_; | 140 RTCPeerConnection *peer_connection = peer_connection_; |
| 142 [peer_connection.delegate peerConnection:peer_connection | 141 [peer_connection.delegate peerConnection:peer_connection |
| 143 didRemoveStream:mediaStream]; | 142 didRemoveStream:mediaStream]; |
|
Taylor Brandstetter
2017/02/15 21:34:45
The stream's entry in _nativeToObjcMediaStream sho
Zhi Huang
2017/02/15 22:41:13
Done.
| |
| 144 } | 143 } |
| 145 | 144 |
| 146 void PeerConnectionDelegateAdapter::OnDataChannel( | 145 void PeerConnectionDelegateAdapter::OnDataChannel( |
| 147 rtc::scoped_refptr<DataChannelInterface> data_channel) { | 146 rtc::scoped_refptr<DataChannelInterface> data_channel) { |
| 148 RTCDataChannel *dataChannel = | 147 RTCDataChannel *dataChannel = |
| 149 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; | 148 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; |
| 150 RTCPeerConnection *peer_connection = peer_connection_; | 149 RTCPeerConnection *peer_connection = peer_connection_; |
| 151 [peer_connection.delegate peerConnection:peer_connection | 150 [peer_connection.delegate peerConnection:peer_connection |
| 152 didOpenDataChannel:dataChannel]; | 151 didOpenDataChannel:dataChannel]; |
| 153 } | 152 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); | 192 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
| 194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] | 193 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] |
| 195 initWithNativeCandidate:candidate_wrapper.get()]; | 194 initWithNativeCandidate:candidate_wrapper.get()]; |
| 196 [ice_candidates addObject:ice_candidate]; | 195 [ice_candidates addObject:ice_candidate]; |
| 197 } | 196 } |
| 198 RTCPeerConnection* peer_connection = peer_connection_; | 197 RTCPeerConnection* peer_connection = peer_connection_; |
| 199 [peer_connection.delegate peerConnection:peer_connection | 198 [peer_connection.delegate peerConnection:peer_connection |
| 200 didRemoveIceCandidates:ice_candidates]; | 199 didRemoveIceCandidates:ice_candidates]; |
| 201 } | 200 } |
| 202 | 201 |
| 202 void PeerConnectionDelegateAdapter::OnAddTrack( | |
| 203 rtc::scoped_refptr<RtpReceiverInterface> receiver, | |
| 204 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams) { | |
| 205 RTCRtpReceiver *rtpReceiver = | |
| 206 [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:receiver]; | |
| 207 NSMutableArray *mediaStreams = | |
| 208 [NSMutableArray arrayWithCapacity:streams.size()]; | |
| 209 | |
| 210 RTCPeerConnection *peer_connection = peer_connection_; | |
| 211 for (const auto stream : streams) { | |
| 212 RTCMediaStream *mediaStream = | |
| 213 [peer_connection GetOrCreateObjcStream:stream]; | |
| 214 [mediaStreams addObject:mediaStream]; | |
| 215 } | |
| 216 [peer_connection.delegate peerConnection:peer_connection | |
| 217 didAddTrack:rtpReceiver | |
| 218 attachedStreams:mediaStreams]; | |
| 219 } | |
| 220 | |
| 203 } // namespace webrtc | 221 } // namespace webrtc |
| 204 | 222 |
| 205 | 223 |
| 206 @implementation RTCPeerConnection { | 224 @implementation RTCPeerConnection { |
| 207 NSMutableArray<RTCMediaStream *> *_localStreams; | 225 NSMutableArray<RTCMediaStream *> *_localStreams; |
| 208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; | 226 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
| 209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; | 227 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
| 210 BOOL _hasStartedRtcEventLog; | 228 BOOL _hasStartedRtcEventLog; |
| 229 NSMutableDictionary *_nativeToObjcMediaStream; | |
| 211 } | 230 } |
| 212 | 231 |
| 213 @synthesize delegate = _delegate; | 232 @synthesize delegate = _delegate; |
| 214 | 233 |
| 215 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory | 234 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 216 configuration:(RTCConfiguration *)configuration | 235 configuration:(RTCConfiguration *)configuration |
| 217 constraints:(RTCMediaConstraints *)constraints | 236 constraints:(RTCMediaConstraints *)constraints |
| 218 delegate:(id<RTCPeerConnectionDelegate>)delegate { | 237 delegate:(id<RTCPeerConnectionDelegate>)delegate { |
| 219 NSParameterAssert(factory); | 238 NSParameterAssert(factory); |
| 220 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( | 239 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
| 221 [configuration createNativeConfiguration]); | 240 [configuration createNativeConfiguration]); |
| 222 if (!config) { | 241 if (!config) { |
| 223 return nil; | 242 return nil; |
| 224 } | 243 } |
| 225 if (self = [super init]) { | 244 if (self = [super init]) { |
| 226 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); | 245 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
| 227 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = | 246 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = |
| 228 constraints.nativeConstraints; | 247 constraints.nativeConstraints; |
| 229 _peerConnection = | 248 _peerConnection = |
| 230 factory.nativeFactory->CreatePeerConnection(*config, | 249 factory.nativeFactory->CreatePeerConnection(*config, |
| 231 nativeConstraints.get(), | 250 nativeConstraints.get(), |
| 232 nullptr, | 251 nullptr, |
| 233 nullptr, | 252 nullptr, |
| 234 _observer.get()); | 253 _observer.get()); |
| 235 if (!_peerConnection) { | 254 if (!_peerConnection) { |
| 236 return nil; | 255 return nil; |
| 237 } | 256 } |
| 238 _localStreams = [[NSMutableArray alloc] init]; | 257 _localStreams = [[NSMutableArray alloc] init]; |
| 239 _delegate = delegate; | 258 _delegate = delegate; |
| 259 _nativeToObjcMediaStream = [NSMutableDictionary dictionary]; | |
| 240 } | 260 } |
| 241 return self; | 261 return self; |
| 242 } | 262 } |
| 243 | 263 |
| 244 - (NSArray<RTCMediaStream *> *)localStreams { | 264 - (NSArray<RTCMediaStream *> *)localStreams { |
| 245 return [_localStreams copy]; | 265 return [_localStreams copy]; |
| 246 } | 266 } |
| 247 | 267 |
| 248 - (RTCSessionDescription *)localDescription { | 268 - (RTCSessionDescription *)localDescription { |
| 249 const webrtc::SessionDescriptionInterface *description = | 269 const webrtc::SessionDescriptionInterface *description = |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 + (webrtc::PeerConnectionInterface::StatsOutputLevel) | 598 + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
| 579 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { | 599 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
| 580 switch (level) { | 600 switch (level) { |
| 581 case RTCStatsOutputLevelStandard: | 601 case RTCStatsOutputLevelStandard: |
| 582 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; | 602 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
| 583 case RTCStatsOutputLevelDebug: | 603 case RTCStatsOutputLevelDebug: |
| 584 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; | 604 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
| 585 } | 605 } |
| 586 } | 606 } |
| 587 | 607 |
| 608 - (RTCMediaStream *)GetOrCreateObjcStream: | |
| 609 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)stream { | |
| 610 RTCMediaStream *mediaStream = | |
| 611 _nativeToObjcMediaStream[[NSNumber numberWithLong:(long)stream.get()]]; | |
| 612 if (!mediaStream) { | |
| 613 mediaStream = | |
| 614 [[RTCMediaStream alloc] initWithNativeMediaStream:stream.get()]; | |
| 615 _nativeToObjcMediaStream[[NSNumber numberWithLong:(long)stream.get()]] = | |
| 616 mediaStream; | |
| 617 } | |
| 618 return mediaStream; | |
| 619 } | |
| 620 | |
| 588 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { | 621 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
| 589 return _peerConnection; | 622 return _peerConnection; |
| 590 } | 623 } |
| 591 | 624 |
| 592 @end | 625 @end |
| OLD | NEW |