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" | |
tkchin_webrtc
2017/02/24 20:54:15
you don't need this include, NSString+StdString ha
| |
30 | 31 |
31 NSString * const kRTCPeerConnectionErrorDomain = | 32 NSString * const kRTCPeerConnectionErrorDomain = |
32 @"org.webrtc.RTCPeerConnection"; | 33 @"org.webrtc.RTCPeerConnection"; |
33 int const kRTCPeerConnnectionSessionDescriptionError = -1; | 34 int const kRTCPeerConnnectionSessionDescriptionError = -1; |
34 | 35 |
35 namespace webrtc { | 36 namespace webrtc { |
36 | 37 |
37 class CreateSessionDescriptionObserverAdapter | 38 class CreateSessionDescriptionObserverAdapter |
38 : public CreateSessionDescriptionObserver { | 39 : public CreateSessionDescriptionObserver { |
39 public: | 40 public: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 PeerConnectionInterface::SignalingState new_state) { | 121 PeerConnectionInterface::SignalingState new_state) { |
121 RTCSignalingState state = | 122 RTCSignalingState state = |
122 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; | 123 [[RTCPeerConnection class] signalingStateForNativeState:new_state]; |
123 RTCPeerConnection *peer_connection = peer_connection_; | 124 RTCPeerConnection *peer_connection = peer_connection_; |
124 [peer_connection.delegate peerConnection:peer_connection | 125 [peer_connection.delegate peerConnection:peer_connection |
125 didChangeSignalingState:state]; | 126 didChangeSignalingState:state]; |
126 } | 127 } |
127 | 128 |
128 void PeerConnectionDelegateAdapter::OnAddStream( | 129 void PeerConnectionDelegateAdapter::OnAddStream( |
129 rtc::scoped_refptr<MediaStreamInterface> stream) { | 130 rtc::scoped_refptr<MediaStreamInterface> stream) { |
130 RTCMediaStream *mediaStream = | |
131 [[RTCMediaStream alloc] initWithNativeMediaStream:stream]; | |
132 RTCPeerConnection *peer_connection = peer_connection_; | 131 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]; | |
144 } | 145 } |
145 | 146 |
146 void PeerConnectionDelegateAdapter::OnDataChannel( | 147 void PeerConnectionDelegateAdapter::OnDataChannel( |
147 rtc::scoped_refptr<DataChannelInterface> data_channel) { | 148 rtc::scoped_refptr<DataChannelInterface> data_channel) { |
148 RTCDataChannel *dataChannel = | 149 RTCDataChannel *dataChannel = |
149 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; | 150 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; |
150 RTCPeerConnection *peer_connection = peer_connection_; | 151 RTCPeerConnection *peer_connection = peer_connection_; |
151 [peer_connection.delegate peerConnection:peer_connection | 152 [peer_connection.delegate peerConnection:peer_connection |
152 didOpenDataChannel:dataChannel]; | 153 didOpenDataChannel:dataChannel]; |
153 } | 154 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); | 194 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] | 195 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] |
195 initWithNativeCandidate:candidate_wrapper.get()]; | 196 initWithNativeCandidate:candidate_wrapper.get()]; |
196 [ice_candidates addObject:ice_candidate]; | 197 [ice_candidates addObject:ice_candidate]; |
197 } | 198 } |
198 RTCPeerConnection* peer_connection = peer_connection_; | 199 RTCPeerConnection* peer_connection = peer_connection_; |
199 [peer_connection.delegate peerConnection:peer_connection | 200 [peer_connection.delegate peerConnection:peer_connection |
200 didRemoveIceCandidates:ice_candidates]; | 201 didRemoveIceCandidates:ice_candidates]; |
201 } | 202 } |
202 | 203 |
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 | |
203 } // namespace webrtc | 226 } // namespace webrtc |
204 | 227 |
205 | 228 |
206 @implementation RTCPeerConnection { | 229 @implementation RTCPeerConnection { |
207 NSMutableArray<RTCMediaStream *> *_localStreams; | 230 NSMutableArray<RTCMediaStream *> *_localStreams; |
208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; | 231 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; | 232 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
210 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; | 233 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; |
211 BOOL _hasStartedRtcEventLog; | 234 BOOL _hasStartedRtcEventLog; |
235 NSMutableDictionary<NSString *, RTCMediaStream *> *_mediaStreamsByStreamId; | |
212 } | 236 } |
213 | 237 |
214 @synthesize delegate = _delegate; | 238 @synthesize delegate = _delegate; |
215 | 239 |
216 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory | 240 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
217 configuration:(RTCConfiguration *)configuration | 241 configuration:(RTCConfiguration *)configuration |
218 constraints:(RTCMediaConstraints *)constraints | 242 constraints:(RTCMediaConstraints *)constraints |
219 delegate:(id<RTCPeerConnectionDelegate>)delegate { | 243 delegate:(id<RTCPeerConnectionDelegate>)delegate { |
220 NSParameterAssert(factory); | 244 NSParameterAssert(factory); |
221 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( | 245 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
222 [configuration createNativeConfiguration]); | 246 [configuration createNativeConfiguration]); |
223 if (!config) { | 247 if (!config) { |
224 return nil; | 248 return nil; |
225 } | 249 } |
226 if (self = [super init]) { | 250 if (self = [super init]) { |
227 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); | 251 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
228 _nativeConstraints = constraints.nativeConstraints; | 252 _nativeConstraints = constraints.nativeConstraints; |
229 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), | 253 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), |
230 config.get()); | 254 config.get()); |
231 _peerConnection = | 255 _peerConnection = |
232 factory.nativeFactory->CreatePeerConnection(*config, | 256 factory.nativeFactory->CreatePeerConnection(*config, |
233 nullptr, | 257 nullptr, |
234 nullptr, | 258 nullptr, |
235 _observer.get()); | 259 _observer.get()); |
236 if (!_peerConnection) { | 260 if (!_peerConnection) { |
237 return nil; | 261 return nil; |
238 } | 262 } |
239 _localStreams = [[NSMutableArray alloc] init]; | 263 _localStreams = [[NSMutableArray alloc] init]; |
240 _delegate = delegate; | 264 _delegate = delegate; |
265 _mediaStreamsByStreamId = [NSMutableDictionary dictionary]; | |
241 } | 266 } |
242 return self; | 267 return self; |
243 } | 268 } |
244 | 269 |
245 - (NSArray<RTCMediaStream *> *)localStreams { | 270 - (NSArray<RTCMediaStream *> *)localStreams { |
246 return [_localStreams copy]; | 271 return [_localStreams copy]; |
247 } | 272 } |
248 | 273 |
249 - (RTCSessionDescription *)localDescription { | 274 - (RTCSessionDescription *)localDescription { |
250 const webrtc::SessionDescriptionInterface *description = | 275 const webrtc::SessionDescriptionInterface *description = |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 + (webrtc::PeerConnectionInterface::StatsOutputLevel) | 606 + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
582 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { | 607 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
583 switch (level) { | 608 switch (level) { |
584 case RTCStatsOutputLevelStandard: | 609 case RTCStatsOutputLevelStandard: |
585 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; | 610 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
586 case RTCStatsOutputLevelDebug: | 611 case RTCStatsOutputLevelDebug: |
587 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; | 612 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
588 } | 613 } |
589 } | 614 } |
590 | 615 |
616 - (RTCMediaStream *)mediaStreamForNativeStream: | |
617 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)stream { | |
618 RTCMediaStream *mediaStream = | |
619 _mediaStreamsByStreamId[[NSString stringForStdString:stream->label()]]; | |
tkchin_webrtc
2017/02/24 20:54:15
nit: pull this out into a local so you're not crea
| |
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 | |
591 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { | 631 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
592 return _peerConnection; | 632 return _peerConnection; |
593 } | 633 } |
594 | 634 |
595 @end | 635 @end |
OLD | NEW |