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

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

Issue 2513063003: Add the OnAddTrack callback for Objective-C wrapper.
Patch Set: Remove the stream entry from the dictionary when the stream is removed. 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
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 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];
143 [peer_connection removeObjcStream: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(
tkchin_webrtc 2017/02/15 23:43:48 strange that the method is OnAddTrack but it gives
Taylor Brandstetter 2017/02/16 01:07:06 That's what's in the spec (it's called "ontrack" t
204 rtc::scoped_refptr<RtpReceiverInterface> receiver,
205 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
206 RTCRtpReceiver *rtpReceiver =
tkchin_webrtc 2017/02/15 23:43:47 use C++ style in C++ methods
Zhi Huang 2017/02/21 04:55:50 Done.
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 getOrCreateObjcStream:stream];
215 [mediaStreams addObject:mediaStream];
216 }
217 [peer_connection.delegate peerConnection:peer_connection
218 didAddTrack:rtpReceiver
tkchin_webrtc 2017/02/15 23:43:48 ObjC naming usually follows type (so I'd expect pe
Zhi Huang 2017/02/21 04:55:50 Done.
219 attachedStreams:mediaStreams];
220 }
221
203 } // namespace webrtc 222 } // namespace webrtc
204 223
205 224
206 @implementation RTCPeerConnection { 225 @implementation RTCPeerConnection {
207 NSMutableArray<RTCMediaStream *> *_localStreams; 226 NSMutableArray<RTCMediaStream *> *_localStreams;
208 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; 227 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer;
209 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; 228 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection;
210 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; 229 std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints;
211 BOOL _hasStartedRtcEventLog; 230 BOOL _hasStartedRtcEventLog;
231 NSMutableDictionary *_nativeToObjcMediaStream;
tkchin_webrtc 2017/02/15 23:43:48 NSMutableDictionary<NSNumber, RTCMediaStream *> *_
Zhi Huang 2017/02/21 04:55:50 Done.
212 } 232 }
213 233
214 @synthesize delegate = _delegate; 234 @synthesize delegate = _delegate;
215 235
216 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory 236 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
217 configuration:(RTCConfiguration *)configuration 237 configuration:(RTCConfiguration *)configuration
218 constraints:(RTCMediaConstraints *)constraints 238 constraints:(RTCMediaConstraints *)constraints
219 delegate:(id<RTCPeerConnectionDelegate>)delegate { 239 delegate:(id<RTCPeerConnectionDelegate>)delegate {
220 NSParameterAssert(factory); 240 NSParameterAssert(factory);
221 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( 241 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
222 [configuration createNativeConfiguration]); 242 [configuration createNativeConfiguration]);
223 if (!config) { 243 if (!config) {
224 return nil; 244 return nil;
225 } 245 }
226 if (self = [super init]) { 246 if (self = [super init]) {
227 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); 247 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
228 _nativeConstraints = constraints.nativeConstraints; 248 _nativeConstraints = constraints.nativeConstraints;
229 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), 249 CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(),
230 config.get()); 250 config.get());
231 _peerConnection = 251 _peerConnection =
232 factory.nativeFactory->CreatePeerConnection(*config, 252 factory.nativeFactory->CreatePeerConnection(*config,
233 nullptr, 253 nullptr,
234 nullptr, 254 nullptr,
235 _observer.get()); 255 _observer.get());
236 if (!_peerConnection) { 256 if (!_peerConnection) {
237 return nil; 257 return nil;
238 } 258 }
239 _localStreams = [[NSMutableArray alloc] init]; 259 _localStreams = [[NSMutableArray alloc] init];
240 _delegate = delegate; 260 _delegate = delegate;
261 _nativeToObjcMediaStream = [NSMutableDictionary dictionary];
241 } 262 }
242 return self; 263 return self;
243 } 264 }
244 265
245 - (NSArray<RTCMediaStream *> *)localStreams { 266 - (NSArray<RTCMediaStream *> *)localStreams {
246 return [_localStreams copy]; 267 return [_localStreams copy];
247 } 268 }
248 269
249 - (RTCSessionDescription *)localDescription { 270 - (RTCSessionDescription *)localDescription {
250 const webrtc::SessionDescriptionInterface *description = 271 const webrtc::SessionDescriptionInterface *description =
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 + (webrtc::PeerConnectionInterface::StatsOutputLevel) 602 + (webrtc::PeerConnectionInterface::StatsOutputLevel)
582 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { 603 nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level {
583 switch (level) { 604 switch (level) {
584 case RTCStatsOutputLevelStandard: 605 case RTCStatsOutputLevelStandard:
585 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; 606 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard;
586 case RTCStatsOutputLevelDebug: 607 case RTCStatsOutputLevelDebug:
587 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; 608 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug;
588 } 609 }
589 } 610 }
590 611
612 - (RTCMediaStream *)getOrCreateObjcStream:
tkchin_webrtc 2017/02/15 23:43:48 "get" prefix is forbidden in ObjC style - (RTCMed
Zhi Huang 2017/02/21 04:55:50 Done.
613 (rtc::scoped_refptr<webrtc::MediaStreamInterface>)stream {
614 RTCMediaStream *mediaStream =
615 _nativeToObjcMediaStream[[NSNumber numberWithLong:(long)stream.get()]];
tkchin_webrtc 2017/02/15 23:43:48 Is there anything better than pointer value to use
Taylor Brandstetter 2017/02/16 01:07:06 They have an ID field which should be unique withi
616 if (!mediaStream) {
617 mediaStream =
618 [[RTCMediaStream alloc] initWithNativeMediaStream:stream.get()];
619 _nativeToObjcMediaStream[[NSNumber numberWithLong:(long)stream.get()]] =
620 mediaStream;
621 }
622 return mediaStream;
623 }
624
625 - (void)removeObjcStream:(rtc::scoped_refptr<webrtc::MediaStreamInterface>)strea m {
tkchin_webrtc 2017/02/15 23:43:47 nit: - (void)removeNativeMediaStream:(rtc::scoped_
Zhi Huang 2017/02/21 04:55:50 Done.
626 [_nativeToObjcMediaStream removeObjectForKey:[NSNumber numberWithLong:(long)st ream.get()]];
627 }
628
591 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { 629 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection {
592 return _peerConnection; 630 return _peerConnection;
593 } 631 }
594 632
595 @end 633 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698