Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm

Issue 2513063003: Add the OnAddTrack callback for Objective-C wrapper.
Patch Set: Add optional method check. Use the stream->label() as the Key Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 mediaStreamForNativeStream:stre am];
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];
143 [peer_connection removeNativeMediaStream:stream];
144 } 144 }
145 145
146 void PeerConnectionDelegateAdapter::OnDataChannel( 146 void PeerConnectionDelegateAdapter::OnDataChannel(
147 rtc::scoped_refptr<DataChannelInterface> data_channel) { 147 rtc::scoped_refptr<DataChannelInterface> data_channel) {
148 RTCDataChannel *dataChannel = 148 RTCDataChannel *dataChannel =
149 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel]; 149 [[RTCDataChannel alloc] initWithNativeDataChannel:data_channel];
150 RTCPeerConnection *peer_connection = peer_connection_; 150 RTCPeerConnection *peer_connection = peer_connection_;
151 [peer_connection.delegate peerConnection:peer_connection 151 [peer_connection.delegate peerConnection:peer_connection
152 didOpenDataChannel:dataChannel]; 152 didOpenDataChannel:dataChannel];
153 } 153 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 new JsepIceCandidate(candidate.transport_name(), -1, candidate)); 193 new JsepIceCandidate(candidate.transport_name(), -1, candidate));
194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc] 194 RTCIceCandidate* ice_candidate = [[RTCIceCandidate alloc]
195 initWithNativeCandidate:candidate_wrapper.get()]; 195 initWithNativeCandidate:candidate_wrapper.get()];
196 [ice_candidates addObject:ice_candidate]; 196 [ice_candidates addObject:ice_candidate];
197 } 197 }
198 RTCPeerConnection* peer_connection = peer_connection_; 198 RTCPeerConnection* peer_connection = peer_connection_;
199 [peer_connection.delegate peerConnection:peer_connection 199 [peer_connection.delegate peerConnection:peer_connection
200 didRemoveIceCandidates:ice_candidates]; 200 didRemoveIceCandidates:ice_candidates];
201 } 201 }
202 202
203 void PeerConnectionDelegateAdapter::OnAddTrack(
204 rtc::scoped_refptr<RtpReceiverInterface> receiver,
205 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
206 RTCRtpReceiver* rtpReceiver =
207 [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:receiver];
208 NSMutableArray* mediaStreams =
209 [NSMutableArray arrayWithCapacity:streams.size()];
210
211 RTCPeerConnection* peer_connection = peer_connection_;
212 for (const auto stream : streams) {
213 RTCMediaStream* mediaStream =
214 [peer_connection mediaStreamForNativeStream:stream];
215 [mediaStreams addObject:mediaStream];
216 }
217 if ([peer_connection.delegate
218 respondsToSelector:@selector(peerConnection:didAddTrack:streams:)]) {
219 [peer_connection.delegate peerConnection:peer_connection
220 didAddTrack:rtpReceiver
221 streams:mediaStreams];
222 }
223 }
224
203 } // namespace webrtc 225 } // namespace webrtc
204 226
205 227
206 @implementation RTCPeerConnection { 228 @implementation RTCPeerConnection {
207 NSMutableArray<RTCMediaStream *> *_localStreams; 229 NSMutableArray<RTCMediaStream *> *_localStreams;
208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; 230 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer;
209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; 231 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection;
210 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; 232 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints;
211 BOOL _hasStartedRtcEventLog; 233 BOOL _hasStartedRtcEventLog;
234 NSMutableDictionary<NSString *, RTCMediaStream *> *_mediaStreamsByStreamId;
212 } 235 }
213 236
214 @synthesize delegate = _delegate; 237 @synthesize delegate = _delegate;
215 238
216 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory 239 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
217 configuration:(RTCConfiguration *)configuration 240 configuration:(RTCConfiguration *)configuration
218 constraints:(RTCMediaConstraints *)constraints 241 constraints:(RTCMediaConstraints *)constraints
219 delegate:(id<RTCPeerConnectionDelegate>)delegate { 242 delegate:(id<RTCPeerConnectionDelegate>)delegate {
220 NSParameterAssert(factory); 243 NSParameterAssert(factory);
221 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( 244 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
222 [configuration createNativeConfiguration]); 245 [configuration createNativeConfiguration]);
223 if (!config) { 246 if (!config) {
224 return nil; 247 return nil;
225 } 248 }
226 if (self = [super init]) { 249 if (self = [super init]) {
227 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); 250 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
228 _nativeConstraints = constraints.nativeConstraints; 251 _nativeConstraints = constraints.nativeConstraints;
229 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), 252 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(),
230 config.get()); 253 config.get());
231 _peerConnection = 254 _peerConnection =
232 factory.nativeFactory->CreatePeerConnection(*config, 255 factory.nativeFactory->CreatePeerConnection(*config,
233 nullptr, 256 nullptr,
234 nullptr, 257 nullptr,
235 _observer.get()); 258 _observer.get());
236 if (!_peerConnection) { 259 if (!_peerConnection) {
237 return nil; 260 return nil;
238 } 261 }
239 _localStreams = [[NSMutableArray alloc] init]; 262 _localStreams = [[NSMutableArray alloc] init];
240 _delegate = delegate; 263 _delegate = delegate;
264 _mediaStreamsByStreamId = [NSMutableDictionary dictionary];
241 } 265 }
242 return self; 266 return self;
243 } 267 }
244 268
245 - (NSArray<RTCMediaStream *> *)localStreams { 269 - (NSArray<RTCMediaStream *> *)localStreams {
246 return [_localStreams copy]; 270 return [_localStreams copy];
247 } 271 }
248 272
249 - (RTCSessionDescription *)localDescription { 273 - (RTCSessionDescription *)localDescription {
250 const webrtc::SessionDescriptionInterface *description = 274 const webrtc::SessionDescriptionInterface *description =
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 + (webrtc::PeerConnectionInterface::StatsOutputLevel) 605 + (webrtc::PeerConnectionInterface::StatsOutputLevel)
582 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { 606 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level {
583 switch (level) { 607 switch (level) {
584 case RTCStatsOutputLevelStandard: 608 case RTCStatsOutputLevelStandard:
585 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; 609 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard;
586 case RTCStatsOutputLevelDebug: 610 case RTCStatsOutputLevelDebug:
587 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; 611 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug;
588 } 612 }
589 } 613 }
590 614
615 - (RTCMediaStream *)mediaStreamForNativeStream:
616 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)stream {
617 RTCMediaStream *mediaStream = _mediaStreamsByStreamId[@(stream->label().c_str( ))];
tkchin_webrtc 2017/02/23 19:23:36 might need to use NSStringFromStdString unless th
618 if (!mediaStream) {
619 mediaStream =
620 [[RTCMediaStream alloc] initWithNativeMediaStream:stream.get()];
621 _mediaStreamsByStreamId[@(stream->label().c_str())] = mediaStream;
622 }
623 return mediaStream;
624 }
625
626 - (void)removeNativeMediaStream:(rtc::scoped_refptr<webrtc::MediaStreamInterface >)stream {
627 [_mediaStreamsByStreamId removeObjectForKey:@(stream->label().c_str())];
628 }
629
591 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { 630 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection {
592 return _peerConnection; 631 return _peerConnection;
593 } 632 }
594 633
595 @end 634 @end
OLDNEW
« no previous file with comments | « no previous file | webrtc/sdk/objc/Framework/Classes/RTCPeerConnection+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698