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 "RTCMediaConstraints+Private.h" | 17 #import "RTCMediaConstraints+Private.h" |
18 #import "RTCMediaStream+Private.h" | 18 #import "RTCMediaStream+Private.h" |
19 #import "RTCPeerConnectionFactory+Private.h" | 19 #import "RTCPeerConnectionFactory+Private.h" |
20 #import "RTCRtpSender+Private.h" | 20 #import "RTCRtpSender+Private.h" |
21 #import "RTCSessionDescription+Private.h" | 21 #import "RTCSessionDescription+Private.h" |
22 #import "RTCStatsReport+Private.h" | 22 #import "RTCStatsReport+Private.h" |
23 #import "WebRTC/RTCLogging.h" | 23 #import "WebRTC/RTCLogging.h" |
24 | 24 |
| 25 #include <memory> |
| 26 |
25 #include "webrtc/base/checks.h" | 27 #include "webrtc/base/checks.h" |
26 | 28 |
27 NSString * const kRTCPeerConnectionErrorDomain = | 29 NSString * const kRTCPeerConnectionErrorDomain = |
28 @"org.webrtc.RTCPeerConnection"; | 30 @"org.webrtc.RTCPeerConnection"; |
29 int const kRTCPeerConnnectionSessionDescriptionError = -1; | 31 int const kRTCPeerConnnectionSessionDescriptionError = -1; |
30 | 32 |
31 namespace webrtc { | 33 namespace webrtc { |
32 | 34 |
33 class CreateSessionDescriptionObserverAdapter | 35 class CreateSessionDescriptionObserverAdapter |
34 : public CreateSessionDescriptionObserver { | 36 : public CreateSessionDescriptionObserver { |
35 public: | 37 public: |
36 CreateSessionDescriptionObserverAdapter( | 38 CreateSessionDescriptionObserverAdapter( |
37 void (^completionHandler)(RTCSessionDescription *sessionDescription, | 39 void (^completionHandler)(RTCSessionDescription *sessionDescription, |
38 NSError *error)) { | 40 NSError *error)) { |
39 completion_handler_ = completionHandler; | 41 completion_handler_ = completionHandler; |
40 } | 42 } |
41 | 43 |
42 ~CreateSessionDescriptionObserverAdapter() { | 44 ~CreateSessionDescriptionObserverAdapter() { |
43 completion_handler_ = nil; | 45 completion_handler_ = nil; |
44 } | 46 } |
45 | 47 |
46 void OnSuccess(SessionDescriptionInterface *desc) override { | 48 void OnSuccess(SessionDescriptionInterface *desc) override { |
47 RTC_DCHECK(completion_handler_); | 49 RTC_DCHECK(completion_handler_); |
48 rtc::scoped_ptr<webrtc::SessionDescriptionInterface> description = | 50 std::unique_ptr<webrtc::SessionDescriptionInterface> description = |
49 rtc::scoped_ptr<webrtc::SessionDescriptionInterface>(desc); | 51 std::unique_ptr<webrtc::SessionDescriptionInterface>(desc); |
50 RTCSessionDescription* session = | 52 RTCSessionDescription* session = |
51 [[RTCSessionDescription alloc] initWithNativeDescription: | 53 [[RTCSessionDescription alloc] initWithNativeDescription: |
52 description.get()]; | 54 description.get()]; |
53 completion_handler_(session, nil); | 55 completion_handler_(session, nil); |
54 completion_handler_ = nil; | 56 completion_handler_ = nil; |
55 } | 57 } |
56 | 58 |
57 void OnFailure(const std::string& error) override { | 59 void OnFailure(const std::string& error) override { |
58 RTC_DCHECK(completion_handler_); | 60 RTC_DCHECK(completion_handler_); |
59 NSString* str = [NSString stringForStdString:error]; | 61 NSString* str = [NSString stringForStdString:error]; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 [[RTCIceCandidate alloc] initWithNativeCandidate:candidate]; | 179 [[RTCIceCandidate alloc] initWithNativeCandidate:candidate]; |
178 RTCPeerConnection *peer_connection = peer_connection_; | 180 RTCPeerConnection *peer_connection = peer_connection_; |
179 [peer_connection.delegate peerConnection:peer_connection | 181 [peer_connection.delegate peerConnection:peer_connection |
180 didGenerateIceCandidate:iceCandidate]; | 182 didGenerateIceCandidate:iceCandidate]; |
181 } | 183 } |
182 } // namespace webrtc | 184 } // namespace webrtc |
183 | 185 |
184 | 186 |
185 @implementation RTCPeerConnection { | 187 @implementation RTCPeerConnection { |
186 NSMutableArray *_localStreams; | 188 NSMutableArray *_localStreams; |
187 rtc::scoped_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; | 189 std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
188 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; | 190 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
189 } | 191 } |
190 | 192 |
191 @synthesize delegate = _delegate; | 193 @synthesize delegate = _delegate; |
192 | 194 |
193 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory | 195 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
194 configuration:(RTCConfiguration *)configuration | 196 configuration:(RTCConfiguration *)configuration |
195 constraints:(RTCMediaConstraints *)constraints | 197 constraints:(RTCMediaConstraints *)constraints |
196 delegate:(id<RTCPeerConnectionDelegate>)delegate { | 198 delegate:(id<RTCPeerConnectionDelegate>)delegate { |
197 NSParameterAssert(factory); | 199 NSParameterAssert(factory); |
198 if (self = [super init]) { | 200 if (self = [super init]) { |
199 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); | 201 _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
200 webrtc::PeerConnectionInterface::RTCConfiguration config = | 202 webrtc::PeerConnectionInterface::RTCConfiguration config = |
201 configuration.nativeConfiguration; | 203 configuration.nativeConfiguration; |
202 rtc::scoped_ptr<webrtc::MediaConstraints> nativeConstraints = | 204 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = |
203 constraints.nativeConstraints; | 205 constraints.nativeConstraints; |
204 _peerConnection = | 206 _peerConnection = |
205 factory.nativeFactory->CreatePeerConnection(config, | 207 factory.nativeFactory->CreatePeerConnection(config, |
206 nativeConstraints.get(), | 208 nativeConstraints.get(), |
207 nullptr, | 209 nullptr, |
208 nullptr, | 210 nullptr, |
209 _observer.get()); | 211 _observer.get()); |
210 _localStreams = [[NSMutableArray alloc] init]; | 212 _localStreams = [[NSMutableArray alloc] init]; |
211 _delegate = delegate; | 213 _delegate = delegate; |
212 } | 214 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 252 |
251 - (BOOL)setConfiguration:(RTCConfiguration *)configuration { | 253 - (BOOL)setConfiguration:(RTCConfiguration *)configuration { |
252 return _peerConnection->SetConfiguration(configuration.nativeConfiguration); | 254 return _peerConnection->SetConfiguration(configuration.nativeConfiguration); |
253 } | 255 } |
254 | 256 |
255 - (void)close { | 257 - (void)close { |
256 _peerConnection->Close(); | 258 _peerConnection->Close(); |
257 } | 259 } |
258 | 260 |
259 - (void)addIceCandidate:(RTCIceCandidate *)candidate { | 261 - (void)addIceCandidate:(RTCIceCandidate *)candidate { |
260 rtc::scoped_ptr<const webrtc::IceCandidateInterface> iceCandidate( | 262 std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( |
261 candidate.nativeCandidate); | 263 candidate.nativeCandidate); |
262 _peerConnection->AddIceCandidate(iceCandidate.get()); | 264 _peerConnection->AddIceCandidate(iceCandidate.get()); |
263 } | 265 } |
264 | 266 |
265 - (void)addStream:(RTCMediaStream *)stream { | 267 - (void)addStream:(RTCMediaStream *)stream { |
266 if (!_peerConnection->AddStream(stream.nativeMediaStream)) { | 268 if (!_peerConnection->AddStream(stream.nativeMediaStream)) { |
267 RTCLogError(@"Failed to add stream: %@", stream); | 269 RTCLogError(@"Failed to add stream: %@", stream); |
268 return; | 270 return; |
269 } | 271 } |
270 [_localStreams addObject:stream]; | 272 [_localStreams addObject:stream]; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 case RTCStatsOutputLevelDebug: | 499 case RTCStatsOutputLevelDebug: |
498 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; | 500 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
499 } | 501 } |
500 } | 502 } |
501 | 503 |
502 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { | 504 - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
503 return _peerConnection; | 505 return _peerConnection; |
504 } | 506 } |
505 | 507 |
506 @end | 508 @end |
OLD | NEW |